Package org.compiere.util
Class EmailSrv
java.lang.Object
org.compiere.util.EmailSrv
Provide function for sent, receive email in imap protocol.
Current only support receive email, for sent email refer
In case internet line is slow, handling error during analysis of message by fetching message in part can have complication.
Consider to add flag to fetch all message at one time (with retry when error) and after fetching, analysis fetched message offline. http://www.oracle.com/technetwork/java/javamail/faq/index.html#imapserverbug
Current only support receive email, for sent email refer
EMail
.In case internet line is slow, handling error during analysis of message by fetching message in part can have complication.
Consider to add flag to fetch all message at one time (with retry when error) and after fetching, analysis fetched message offline. http://www.oracle.com/technetwork/java/javamail/faq/index.html#imapserverbug
- Author:
- hieplq base in RequestEMailProcessor
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
manipulate fromMessage
separate attach file to embed, attach, un-know liststatic class
../../.. this class implement source of image from attach of emailstatic interface
this class inject to email reading process of functionprocessMessage(Message, ProcessEmailHandle, Store, Folder)
static interface
when process an email content sometimes we wish embed image as base64 string to mail. -
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
analysisEmailStructure
(javax.mail.Part msg, EmailSrv.EmailContent emailContent) static void
analysisEmailStructure
(javax.mail.Part msg, EmailSrv.EmailContent emailContent, boolean isRoot) AnalysisPart
object get content in plan or html text.void
static String
embedImgToEmail
(String mailContent, EmailSrv.ProvideBase64Data provideBase64Data) embedImgToEmail(String, ProvideBase64Data, String)
use default pattern for embed image is "\\s+src\\s*=\\s*\"cid:(.*?)static String
embedImgToEmail
(String mailContent, EmailSrv.ProvideBase64Data provideBase64Data, String embedPattern) find in mailContent every pattern of embed image with each replace cid by base64 data.static String
getBinaryAsBASE64
(javax.mail.BodyPart mailPart) download attach file and convert to base64 encodingstatic byte[]
getBinaryData
(javax.mail.Part binaryPart) read binary from a multi-partstatic String
getContentID
(javax.mail.Part attachPart) get contentID from header, with each inline attach, will have a contentID value in case value at contentID difference value at X-Attachment-Id, must manual recheck to add processstatic ArrayList<javax.mail.BodyPart>
getEmbededImages
(String mailContent, EmailSrv.ProvideBase64Data provideBase64Data, String embedPattern) static javax.mail.Folder
getFolder
(javax.mail.Store mailStore, String folderName, Boolean isNestInbox, boolean createWhenNonExists) open a folder in read/write mode.protected javax.mail.Session
javax.mail.Store
static String[]
getPartHeader
(javax.mail.Part msg, String headerName) static String
getTextFromMailPart
(javax.mail.Part txtPart) http://www.oracle.com/technetwork/java/javamail/faq/index.html#unsupenstatic boolean
isBinaryPart
(javax.mail.Part binaryPart) static void
logMailPartInfo
(javax.mail.Part msg, CLogger log) static EmailSrv.EmailContent
processMessage
(javax.mail.Message msg) static EmailSrv.EmailContent
processMessage
(javax.mail.Message msg, EmailSrv.ProcessEmailHandle evaluateEmailHead, javax.mail.Store mailStore, javax.mail.Folder mailFolder) static boolean
readEmailFolder
(EmailSrv emailSrv, String folderName, Boolean isNestInbox, EmailSrv.ProcessEmailHandle processEmailHandle) read an email folder, with each email inject object processEmail to processing in case error close folder or close session (by disconnect) with retry 3 times when error with 5 continue message, with stop process
-
Field Details
-
log
-
imapHost
-
imapUser
-
imapPass
-
imapPort
protected int imapPort -
isSSL
protected boolean isSSL -
mailSession
protected javax.mail.Session mailSession -
mailStore
protected javax.mail.Store mailStore
-
-
Constructor Details
-
EmailSrv
-
EmailSrv
Deprecated.working only with gmail host.- Parameters:
imapHost
-imapUser
-imapPass
-
-
-
Method Details
-
logMailPartInfo
public static void logMailPartInfo(javax.mail.Part msg, CLogger log) throws javax.mail.MessagingException - Throws:
javax.mail.MessagingException
-
getMailSession
- Throws:
Exception
-
getMailStore
- Throws:
Exception
-
clearResource
public void clearResource() -
getFolder
public static javax.mail.Folder getFolder(javax.mail.Store mailStore, String folderName, Boolean isNestInbox, boolean createWhenNonExists) throws javax.mail.MessagingException open a folder in read/write mode.- Parameters:
mailStore
-folderName
- open nest folder by use format folder1/folder2/folder3isNestInbox
- in case true, open folder start from default inbox, other open from root foldercreateWhenNonExists
- in case true, create folder by hierarchy if not exists, other not exists will make exception- Returns:
- folder opened in r/w model
- Throws:
javax.mail.MessagingException
-
readEmailFolder
public static boolean readEmailFolder(EmailSrv emailSrv, String folderName, Boolean isNestInbox, EmailSrv.ProcessEmailHandle processEmailHandle) read an email folder, with each email inject object processEmail to processing in case error close folder or close session (by disconnect) with retry 3 times when error with 5 continue message, with stop process- Parameters:
emailSrv
-folderName
- folder name can hierarchy by use "\"isNestInbox
- true in case start folder from inboxprocessEmailHandle
-- Returns:
-
processMessage
public static EmailSrv.EmailContent processMessage(javax.mail.Message msg) throws javax.mail.MessagingException, IOException - Parameters:
msg
-- Returns:
- Throws:
javax.mail.MessagingException
IOException
- See Also:
-
processMessage
public static EmailSrv.EmailContent processMessage(javax.mail.Message msg, EmailSrv.ProcessEmailHandle evaluateEmailHead, javax.mail.Store mailStore, javax.mail.Folder mailFolder) throws javax.mail.MessagingException, IOException - Parameters:
msg
-evaluateEmailHead
-- Returns:
- return EmailInfo contain info of email, in case evaluateEmailHead make cancel, return null
- Throws:
javax.mail.MessagingException
IOException
-
analysisEmailStructure
public static void analysisEmailStructure(javax.mail.Part msg, EmailSrv.EmailContent emailContent) throws javax.mail.MessagingException, IOException - Parameters:
msg
-emailContent
-- Throws:
javax.mail.MessagingException
IOException
- See Also:
-
analysisEmailStructure
public static void analysisEmailStructure(javax.mail.Part msg, EmailSrv.EmailContent emailContent, boolean isRoot) throws javax.mail.MessagingException, IOException AnalysisPart
object get content in plan or html text. detect type of attach file and put in toEmailSrv.EmailContent
for late process- Parameters:
msg
- mime part to analysisemailContent
- object contain result analysisisRoot
- true when part isMessage
- Throws:
javax.mail.MessagingException
IOException
-
getTextFromMailPart
public static String getTextFromMailPart(javax.mail.Part txtPart) throws javax.mail.MessagingException, IOException http://www.oracle.com/technetwork/java/javamail/faq/index.html#unsupen- Parameters:
txtPart
-- Returns:
- Throws:
javax.mail.MessagingException
IOException
-
getBinaryData
public static byte[] getBinaryData(javax.mail.Part binaryPart) throws IOException, javax.mail.MessagingException read binary from a multi-part- Parameters:
binaryPart
-- Returns:
- Throws:
IOException
javax.mail.MessagingException
-
getBinaryAsBASE64
public static String getBinaryAsBASE64(javax.mail.BodyPart mailPart) throws IOException, javax.mail.MessagingException download attach file and convert to base64 encoding- Parameters:
mailPart
-- Returns:
- Throws:
IOException
javax.mail.MessagingException
-
embedImgToEmail
public static String embedImgToEmail(String mailContent, EmailSrv.ProvideBase64Data provideBase64Data) throws Exception embedImgToEmail(String, ProvideBase64Data, String)
use default pattern for embed image is "\\s+src\\s*=\\s*\"cid:(.*?)\"");- Parameters:
mailContent
-provideBase64Data
-- Returns:
- Throws:
Exception
-
embedImgToEmail
public static String embedImgToEmail(String mailContent, EmailSrv.ProvideBase64Data provideBase64Data, String embedPattern) throws javax.mail.MessagingException, IOException find in mailContent every pattern of embed image with each replace cid by base64 data. preview in cfEditor pattern is "\\s+src\\s*=\\s*\"cid:(.*?)\"" with embed image in gmail, pattern is "\\s+src\\s*=\\s*3D\\s*\"cid:(.*?)\"" with embed image in other server (nmicoud), pattern is "\\s+src\\s*=\\s*\"cid:(.*?)\"" REMEMBER:cid:(.*?) must in group 1- Parameters:
mailContent
-provideBase64Data
-embedPattern
-- Returns:
- Throws:
Exception
javax.mail.MessagingException
IOException
-
getEmbededImages
public static ArrayList<javax.mail.BodyPart> getEmbededImages(String mailContent, EmailSrv.ProvideBase64Data provideBase64Data, String embedPattern) throws javax.mail.MessagingException, IOException - Throws:
javax.mail.MessagingException
IOException
-
isBinaryPart
public static boolean isBinaryPart(javax.mail.Part binaryPart) throws javax.mail.MessagingException - Throws:
javax.mail.MessagingException
-
getContentID
get contentID from header, with each inline attach, will have a contentID value in case value at contentID difference value at X-Attachment-Id, must manual recheck to add process- Parameters:
attachPart
-- Returns:
- Throws:
javax.mail.MessagingException
-
getPartHeader
public static String[] getPartHeader(javax.mail.Part msg, String headerName) throws javax.mail.MessagingException - Throws:
javax.mail.MessagingException
-