Class Messages

java.lang.Object
ch.tocco.nice2.messaging.mail.spi.Messages

public final class Messages extends Object
  • Field Details

  • Method Details

    • toEmailAddress

      public static Function<jakarta.mail.internet.InternetAddress,String> toEmailAddress()
      Returns a function that converts InternetAddresses to strings, while returning only the address part. Groups are resolved to a comma separated list of addresses. Returns null, if input is null. The function may throw an IllegalArgumentException if group parsing fails.
    • toNameAndEmailAddress

      public static Function<jakarta.mail.internet.InternetAddress,String> toNameAndEmailAddress()
    • toInternetAddresses

      @Nullable public static @Nullable Iterable<jakarta.mail.internet.InternetAddress> toInternetAddresses(@Nullable @Nullable Iterable<jakarta.mail.Address> addresses)
      Filters the specified iterable of Addresses and returns a iterable that contains all elements from the argument that are of type InternetAddress.
    • toInternetAddresses

      @Nullable public static @Nullable Iterable<jakarta.mail.internet.InternetAddress> toInternetAddresses(@Nullable @Nullable jakarta.mail.Address[] addresses)
      Filters the specified iterable of Addresses and returns a iterable that contains all elements from the argument that are of type InternetAddress.
    • getFirstEmailAddress

      @Nullable public static @Nullable String getFirstEmailAddress(@Nullable @Nullable jakarta.mail.Address[] addresses)
    • joinEmailAddresses

      @Nullable public static @Nullable String joinEmailAddresses(@Nullable @Nullable jakarta.mail.Address[] addresses, String split)
    • joinEmailAddresses

      @Nullable public static @Nullable String joinEmailAddresses(@Nullable @Nullable Iterable<jakarta.mail.internet.InternetAddress> addresses, String split)
    • getFrom

      public static jakarta.mail.internet.InternetAddress getFrom(jakarta.mail.Message message) throws jakarta.mail.MessagingException
      Returns the single InternetAddress in the from header.
      Throws:
      jakarta.mail.MessagingException
    • getRecipients

      public static Iterable<jakarta.mail.internet.InternetAddress> getRecipients(jakarta.mail.Message message, @Nullable jakarta.mail.Message.RecipientType type)
      Returns an iterable over the recipients addresses of the given type.

      If type is null all recipients are returned.

    • getReplyTos

      public static Iterable<jakarta.mail.internet.InternetAddress> getReplyTos(jakarta.mail.Message message)
    • getAllHeaders

      public static Map<String,Iterable<String>> getAllHeaders(jakarta.mail.Message message) throws jakarta.mail.MessagingException
      Transforms all headers of the message into a map. Empty header lines will be skipped such that the mapped iterable only contains not-null and non-empty strings.
      Throws:
      jakarta.mail.MessagingException
    • getHeaders

      public static Map<String,Iterable<String>> getHeaders(Enumeration headers)
      Transforms the given enumeration of header objects into a map. Empty header lines will be skipped such that the mapped iterable only contains not-null and non-empty strings.
    • parseHeaderLines

      public static Map<String,Iterable<String>> parseHeaderLines(List<String> headerLines)
      Transforms the given string list into a map header map. Splits the line at the first colon followed by a space. The part before the first ": " is used as key, the rest as value. If a line does not contain ": " it is ignored.
    • ensureFolderOpen

      public static void ensureFolderOpen(jakarta.mail.Message message, int mode) throws jakarta.mail.MessagingException
      Opens the folder of the given message if it's not already open.

      If the message has no folder (message.getFolder() == null ), this method does nothing.

      Parameters:
      mode - the open mode, one of Folder.READ_ONLY, Folder.READ_WRITE
      Throws:
      IllegalArgumentException - if message has no folder
      jakarta.mail.MessagingException
    • closeFolder

      public static void closeFolder(jakarta.mail.Message message, boolean expunge)
    • toInternetAddress

      public static Function<jakarta.mail.Address,jakarta.mail.internet.InternetAddress> toInternetAddress()