Class MailUtils


  • public class MailUtils
    extends Object
    Static methods for interacting with email messages.
    • Constructor Detail

      • MailUtils

        public MailUtils()
    • Method Detail

      • getPrefixedSubject

        public static String getPrefixedSubject​(String subject)
      • getBody

        @Deprecated
        public static String getBody​(javax.mail.internet.MimeMessage smtpMessage)
        Deprecated.
        since 7.6.0, use MailUtils.getBody(Message)
      • getFirstRecipient

        public static String getFirstRecipient​(javax.mail.internet.MimeMessage smtpMessage)
      • getSender

        @Deprecated
        public static String getSender​(javax.mail.internet.MimeMessage smtpMessage)
                                throws javax.mail.MessagingException
        Deprecated.
        since 7.6.0, use MailUtils.getSenders(Message)) instead
        Throws:
        javax.mail.MessagingException
      • getLinksInElementWithId

        public static List<SimpleLink> getLinksInElementWithId​(javax.mail.internet.MimeMessage message,
                                                               String id)
        Locates all links inside a container with the specified id and returns them as an ordered list of SimpleLinks. Will fail with a null-pointer exception if no matching node is found.
        Parameters:
        message - the mime message
        id - the id to search for links within
        Returns:
        a list of SimpleLink objects
      • getFooterLinks

        public static List<SimpleLink> getFooterLinks​(javax.mail.internet.MimeMessage message,
                                                      String footerId)
      • getLinkWithId

        public static SimpleLink getLinkWithId​(javax.mail.internet.MimeMessage message,
                                               String id)
        Locates a link with the specified id and returns it as a SimpleLink. Will fail with a null-pointer exception if no matching node is found. ) content; }
        Parameters:
        message - the mime message to search within
        id - the id of the link to return
        Returns:
        a SimpleLink object
      • getLinkWithText

        public static SimpleLink getLinkWithText​(javax.mail.internet.MimeMessage message,
                                                 String linkText)
        Returns the first link that matches the provided link text
        Parameters:
        message - the mime message to search within
        linkText - the text of the link to match against to determine which link to return
        Returns:
        a SimpleLink object if found, otherwise null
      • getSoup

        public static JSoupTester getSoup​(javax.mail.internet.MimeMessage message)
        JSoup for you! Ask Fabian why this is better than using a DOM, or the plain text of the message body :)
        Parameters:
        message - the message to get the HTML body from
        Returns:
        a Jsoup test helper object
      • getDocument

        public static Document getDocument​(javax.mail.internet.MimeMessage message)
      • getEmailAddressedToUser

        public static Iterable<javax.mail.internet.MimeMessage> getEmailAddressedToUser​(User user,
                                                                                        List<javax.mail.internet.MimeMessage> allMessages)
      • toDiagnosticString

        public static com.google.common.base.Function<javax.mail.internet.MimeMessage,​String> toDiagnosticString()
      • toDiagnosticString

        public static String toDiagnosticString​(javax.mail.internet.MimeMessage mimeMessage)
                                         throws javax.mail.MessagingException
        Throws:
        javax.mail.MessagingException
      • extractFirstEmailAddressedTo

        public static javax.mail.internet.MimeMessage extractFirstEmailAddressedTo​(User user,
                                                                                   List<javax.mail.internet.MimeMessage> allMessages)
      • filterBySubject

        public static Collection<javax.mail.internet.MimeMessage> filterBySubject​(Collection<javax.mail.internet.MimeMessage> messages,
                                                                                  String subject)