Package com.logicaldoc.core.communication

# Class MailUtil

java.lang.Object
com.logicaldoc.core.communication.MailUtil

public class MailUtil extends Object
Utility methods for handling emails

Since:
  7.6.4
Author:
  Marco Meschieri - LogicalDOC

## Field Summary

Fields
Modifier and Type
Field
Description
`static final String`
`NO_BODY`
`static final String`
`NO_SUBJECT`

## Constructor Summary

Constructors
Constructor
Description
`MailUtil()`

## Method Summary

Modifier and Type
Method
Description
`static int`
`countEmlAttachments(File emlFile)`
`static int`
`countEmlAttachments(InputStream is)`
`static int`
`countMsgAttachments(File msgFile)`
`static int`
`countMsgAttachments(InputStream is)`
`static boolean`
`emlContainsAttachments(File emlFile)`
`static boolean`
`emlContainsAttachments(InputStream is)`
`static String`
`extractMessageText(jakarta.mail.Message message)`
Extracts just the body of texts parts in the given email message
`static String`
`getAddressEmail(jakarta.mail.Address a)`
Extracts the address email
`static String`
`getAddressName(jakarta.mail.Address a)`
Extracts the address name
`static EMail`
`messageToMail(jakarta.mail.Message msg, boolean extractAttachmentContent)`
Builds an EMail from a Message.
`static EMail`
`messageToMail(File emlFile, boolean extractAttachmentContent)`
Builds an EMail from a .eml file.
`static EMail`
`messageToMail(InputStream is, boolean extractAttachmentContent)`
Builds an EMail from a stream
`static boolean`
`msgContainsAttachments(File msgFile)`
`static boolean`
`msgContainsAttachments(InputStream is)`
`static EMail`
`msgToMail(File msgFile, boolean extractAttachmentContent)`
Builds an EMail from a .msg file.
`static EMail`
`msgToMail(InputStream is, boolean extractAttachmentContent)`
Builds an EMail from a .msg file
`static jakarta.mail.internet.MimeMessage`
`readMime(InputStream is)`
Constructs a MimeMessage from a stream

### Methods inherited from class java.lang.Object

`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### NO_SUBJECT

public static final String NO_SUBJECT

See Also:
  - Constant Field Values

### NO_BODY

public static final String NO_BODY

See Also:
  - Constant Field Values

## Constructor Details

### MailUtil

public MailUtil()

## Method Details

### emlContainsAttachments

public static boolean emlContainsAttachments(InputStream is)

### countEmlAttachments

public static int countEmlAttachments(InputStream is)

### msgToMail

public static EMail msgToMail(InputStream is, boolean extractAttachmentContent) throws IOException, jakarta.mail.MessagingException, org.bouncycastle.cms.CMSException
Builds an EMail from a .msg file

Parameters:
  `is` - the input stream
  `extractAttachmentContent` - if the attachments have to be extracted
Returns:
  the EMail object
Throws:
  `IOException` - I/O error
  `jakarta.mail.MessagingException` - error reading the contents
  `org.bouncycastle.cms.CMSException` - error reading the contents

### msgToMail

public static EMail msgToMail(File msgFile, boolean extractAttachmentContent) throws IOException, jakarta.mail.MessagingException, org.bouncycastle.cms.CMSException
Builds an EMail from a .msg file.

Parameters:
  `msgFile` - the input file
  `extractAttachmentContent` - if you want to extract the attachment files
Returns:
  the EMail object
Throws:
  `IOException` - I/O error
  `org.bouncycastle.cms.CMSException` - cannot read the content
  `jakarta.mail.MessagingException` - cannot read the content

### messageToMail

public static EMail messageToMail(InputStream is, boolean extractAttachmentContent) throws jakarta.mail.MessagingException, IOException
Builds an EMail from a stream

Parameters:
  `is` - the stream to read
  `extractAttachmentContent` - if you want to extract the attachment files
Returns:
  the EMail object
Throws:
  `jakarta.mail.MessagingException` - raised if the message cannot be read
  `IOException` - raised if case of I/O errors

### readMime

public static jakarta.mail.internet.MimeMessage readMime(InputStream is) throws jakarta.mail.MessagingException
Constructs a MimeMessage from a stream

Parameters:
  `is` - the input stream
Returns:
  the creaed message
Throws:
  `jakarta.mail.MessagingException` - the contents are invalid

### messageToMail

public static EMail messageToMail(File emlFile, boolean extractAttachmentContent) throws jakarta.mail.MessagingException, IOException
Builds an EMail from a .eml file.

Parameters:
  `emlFile` - the input file
  `extractAttachmentContent` - if you want to extract the attachment files
Returns:
  the EMail object
Throws:
  `jakarta.mail.MessagingException` - if the source file cannot be read
  `IOException` - raised if case of I/O errors

### messageToMail

public static EMail messageToMail(jakarta.mail.Message msg, boolean extractAttachmentContent) throws jakarta.mail.MessagingException, IOException
Builds an EMail from a Message.

Parameters:
  `msg` - the source message
  `extractAttachmentContent` - if the binary of the attachments has to be extracted
Returns:
  The EMail instance
Throws:
  `jakarta.mail.MessagingException` - error reading the message
  `IOException` - error in I/O operations

### getAddressName

public static String getAddressName(jakarta.mail.Address a)
Extracts the address name

Parameters:
  `a` - the address
Returns:
  the name

### getAddressEmail

public static String getAddressEmail(jakarta.mail.Address a)
Extracts the address email

Parameters:
  `a` - the address
Returns:
  the email

### countMsgAttachments

public static int countMsgAttachments(File msgFile)

### msgContainsAttachments

public static boolean msgContainsAttachments(File msgFile)

### countMsgAttachments

public static int countMsgAttachments(InputStream is)

### msgContainsAttachments

public static boolean msgContainsAttachments(InputStream is)

### countEmlAttachments

public static int countEmlAttachments(File emlFile)

### emlContainsAttachments

public static boolean emlContainsAttachments(File emlFile)

### extractMessageText

public static String extractMessageText(jakarta.mail.Message message) throws jakarta.mail.MessagingException, IOException
Extracts just the body of texts parts in the given email message

Parameters:
  `message` - the email message
Returns:
  the message text
Throws:
  `jakarta.mail.MessagingException` - Error in traversing the part
  `IOException` - generic I/O error