Skip to content

Commit

Permalink
migration to jakarata-mail and angus mail impl
Browse files Browse the repository at this point in the history
Issue #198
  • Loading branch information
rsoika committed Dec 8, 2023
1 parent 4e73e1b commit 80b3bcc
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 81 deletions.
44 changes: 23 additions & 21 deletions imixs-archive-importer/pom.xml
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.imixs.workflow</groupId>
<artifactId>imixs-archive</artifactId>
<version>3.0.1-SNAPSHOT</version>
</parent>
<artifactId>imixs-archive-importer</artifactId>

<dependencies>
<!-- JEE Dependencies -->
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>8.0</version>
<scope>provided</scope>
</dependency>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.imixs.workflow</groupId>
<artifactId>imixs-archive</artifactId>
<version>3.0.1-SNAPSHOT</version>
</parent>
<artifactId>imixs-archive-importer</artifactId>

<dependencies>
<dependency>
<groupId>org.imixs.workflow</groupId>
<artifactId>imixs-workflow-core</artifactId>
Expand All @@ -23,15 +18,22 @@
<groupId>org.imixs.workflow</groupId>
<artifactId>imixs-workflow-engine</artifactId>
</dependency>


<!-- Eclipse Angus Mail -->
<dependency>
<groupId>org.eclipse.angus</groupId>
<artifactId>jakarta.mail</artifactId>
<version>2.0.2</version>
</dependency>

<!-- Apache Commons FTP Client -->
<dependency>
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>
<scope>compile</scope>
</dependency>

</dependencies>
<name>Imixs-Archive Importer</name>

<name>Imixs-Archive Importer</name>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@

import java.util.Properties;

import javax.mail.MessagingException;
import javax.mail.Store;

import org.imixs.workflow.ItemCollection;

import jakarta.mail.MessagingException;
import jakarta.mail.Store;

/**
* The IMAPAuthenticator defines the interface to authenticate against a Mail
* Store. Depending on the Mail system authentication can be very different.
Expand All @@ -55,6 +55,6 @@ public interface IMAPAuthenticator {
* @return
* @throws MessagingException
*/
public Store openMessageStore(ItemCollection sourceConfig, Properties sourceOptions) throws MessagingException;
public Store openMessageStore(ItemCollection sourceConfig, Properties sourceOptions) throws MessagingException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,13 @@
import java.util.Properties;
import java.util.logging.Logger;

import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Store;

import org.imixs.archive.importer.DocumentImportService;
import org.imixs.workflow.ItemCollection;

import jakarta.inject.Named;
import jakarta.mail.MessagingException;
import jakarta.mail.Session;
import jakarta.mail.Store;

/**
* The IMAPBasicAuthenticator authenticates against an Mail store using BASIC
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import java.io.InputStream;
import java.util.logging.Logger;

import javax.ws.rs.core.MediaType;
import jakarta.ws.rs.core.MediaType;

/**
* A helper bean with static methods
Expand All @@ -44,36 +44,34 @@
public class IMAPImportHelper {
private static Logger logger = Logger.getLogger(IMAPImportHelper.class.getName());


/**
* This method returns true if the mediaType of a file attachment is
* This method returns true if the mediaType of a file attachment is
* <p>
* "application/octet-stream"
* <p>
* In some cases we have a situation where the contentType is "application/octet" which is not a valid content type.
* In some cases we have a situation where the contentType is
* "application/octet" which is not a valid content type.
* Also in this case we return true!
*
* @param contentType
* @return
*/
public static boolean isMediaTypeOctet(String contentType, String filename) {

if (contentType.contains(MediaType.APPLICATION_OCTET_STREAM)) {
return true;
}

if (contentType.toLowerCase().startsWith("application/octet")) {
// print a warning for later analysis
logger.warning("Unknow ContentType: " + contentType + " - in " + filename);
// Issue #167
return true;
}

// no octet type
return false;
}



/**
* Read inputstream into a byte array.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,7 @@
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;

import javax.mail.Address;
import javax.mail.BodyPart;
import javax.mail.Folder;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.Part;
import javax.mail.Store;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;

import org.eclipse.angus.mail.imap.IMAPFolder;
import org.imixs.archive.importer.DocumentImportEvent;
import org.imixs.archive.importer.DocumentImportService;
import org.imixs.workflow.FileData;
Expand All @@ -59,14 +49,22 @@
import org.imixs.workflow.exceptions.PluginException;
import org.imixs.workflow.exceptions.ProcessingErrorException;

import com.sun.mail.imap.IMAPFolder;

import jakarta.ejb.EJB;
import jakarta.ejb.Stateless;
import jakarta.enterprise.event.Observes;
import jakarta.enterprise.inject.Any;
import jakarta.enterprise.inject.Instance;
import jakarta.inject.Inject;
import jakarta.mail.Address;
import jakarta.mail.BodyPart;
import jakarta.mail.Folder;
import jakarta.mail.Message;
import jakarta.mail.MessagingException;
import jakarta.mail.Multipart;
import jakarta.mail.Part;
import jakarta.mail.Store;
import jakarta.mail.internet.InternetAddress;
import jakarta.mail.internet.MimeBodyPart;

/**
* The EmailImportAdapter scans a IMAP account
Expand Down Expand Up @@ -176,15 +174,17 @@ public void onEvent(@Observes DocumentImportEvent event) {
}
try {
Store store = null;
// depending on the option "imap.authenticator" we use the corresponding IMAPAuthenticator
// depending on the option "imap.authenticator" we use the corresponding
// IMAPAuthenticator
// to open the mail store
IMAPAuthenticator imapAuthenticator=null;
String authenticatorClass = sourceOptions.getProperty(OPTION_IMAP_AUTHENTICATOR, "org.imixs.archive.importer.mail.IMAPBasicAuthenticator");
IMAPAuthenticator imapAuthenticator = null;
String authenticatorClass = sourceOptions.getProperty(OPTION_IMAP_AUTHENTICATOR,
"org.imixs.archive.importer.mail.IMAPBasicAuthenticator");
for (IMAPAuthenticator _imapAuthenticator : this.imapAuthenticators) {
// find the matching authenticator....
if (authenticatorClass.equals(_imapAuthenticator.getClass().getName() )) {
documentImportService.logMessage("...IMAPAuthenticator = "+authenticatorClass, event);
imapAuthenticator=_imapAuthenticator;
if (authenticatorClass.equals(_imapAuthenticator.getClass().getName())) {
documentImportService.logMessage("...IMAPAuthenticator = " + authenticatorClass, event);
imapAuthenticator = _imapAuthenticator;
break;
}
}
Expand Down Expand Up @@ -296,7 +296,7 @@ public void onEvent(@Observes DocumentImportEvent event) {
logger.info("mimetype=" + contentType);
}
if (IMAPImportHelper.isMediaTypeOctet(contentType, fileName)
&& fileName.toLowerCase().endsWith(".pdf")) {
&& fileName.toLowerCase().endsWith(".pdf")) {
logger.info("...converting mimetype '" + contentType + "' to application/pdf");
contentType = "application/pdf";
}
Expand Down Expand Up @@ -370,8 +370,7 @@ public void onEvent(@Observes DocumentImportEvent event) {
}

}



/**
* This method opens the IMAP archive folder. If the folder does not exist, the
* method creates the folder. The folder name can be configured by the property
Expand Down Expand Up @@ -428,5 +427,4 @@ public ItemCollection createWorkitem(ItemCollection source)
return workitem;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,18 @@
import java.util.Properties;
import java.util.logging.Logger;

import javax.json.Json;
import javax.json.JsonObject;
import javax.json.JsonReader;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Store;
import javax.net.ssl.HttpsURLConnection;

import org.imixs.archive.importer.DocumentImportService;
import org.imixs.workflow.ItemCollection;

import jakarta.inject.Named;
import jakarta.json.Json;
import jakarta.json.JsonObject;
import jakarta.json.JsonReader;
import jakarta.mail.MessagingException;
import jakarta.mail.Session;
import jakarta.mail.Store;

/**
* The IMAPOutlookAuthenticator authenticates against Microsoft Outlook using
Expand Down Expand Up @@ -83,7 +83,7 @@ public Store openMessageStore(ItemCollection sourceConfig, Properties sourceOpti
String imapPassword = sourceConfig.getItemValueString(DocumentImportService.SOURCE_ITEM_PASSWORD);

boolean debug = Boolean.getBoolean(sourceOptions.getProperty(IMAPImportService.OPTION_DEBUG, "false"));

// create an empty properties object...
// Properties props = System.getProperties();
Properties imapProperties = new Properties();
Expand Down Expand Up @@ -152,7 +152,7 @@ public Store openMessageStore(ItemCollection sourceConfig, Properties sourceOpti
*/
public String getAuthToken(String tenantId, String clientId, String client_secret) throws IOException {
String sURL = "https://login.microsoftonline.com/" + tenantId + "/oauth2/v2.0/token";
logger.finest("...oauth login url="+sURL);
logger.finest("...oauth login url=" + sURL);
HttpsURLConnection httpClient = (HttpsURLConnection) new URL(sURL).openConnection();

// add request header
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,16 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.mail.BodyPart;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.Part;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeUtility;

import jakarta.ejb.LocalBean;
import jakarta.ejb.Stateless;
import jakarta.mail.BodyPart;
import jakarta.mail.Message;
import jakarta.mail.MessagingException;
import jakarta.mail.Multipart;
import jakarta.mail.Part;
import jakarta.mail.internet.MimeBodyPart;
import jakarta.mail.internet.MimeMessage;
import jakarta.mail.internet.MimeUtility;

/**
* The MailConverterService provides methods to convert a Mail Message object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,14 @@
import java.nio.charset.StandardCharsets;
import java.util.logging.Logger;

import javax.mail.Message;
import javax.mail.MessagingException;

import org.imixs.workflow.FileData;
import org.imixs.workflow.ItemCollection;

import jakarta.ejb.EJB;
import jakarta.ejb.LocalBean;
import jakarta.ejb.Stateless;
import jakarta.mail.Message;
import jakarta.mail.MessagingException;

/**
* The MessageService provides methods attach Message objects as a file to a
Expand Down

0 comments on commit 80b3bcc

Please sign in to comment.