Class IMAPExportMbox


  • public final class IMAPExportMbox
    extends java.lang.Object
    This is an example program demonstrating how to use the IMAP[S]Client class. This program connects to a IMAP[S] server and exports selected messages from a folder into an mbox file.

    Usage: IMAPExportMbox imap[s]://user:password@host[:port]/folder/path [sequence-set] [item-names]

    An example sequence-set might be:

    • 11,2,3:10,20:*
    • 1:* - this is the default

    Some example item-names might be:

    • BODY.PEEK[HEADER]
    • 'BODY.PEEK[HEADER.FIELDS (SUBJECT)]'
    • ALL - macro equivalent to '(FLAGS INTERNALDATE RFC822.SIZE ENVELOPE)'
    • FAST - macro equivalent to '(FLAGS INTERNALDATE RFC822.SIZE)'
    • FULL - macro equivalent to '(FLAGS INTERNALDATE RFC822.SIZE ENVELOPE BODY)'
    • ENVELOPE X-GM-LABELS
    • '(INTERNALDATE BODY.PEEK[])' - this is the default

    Macro names cannot be combined with anything else; they must be used alone.
    Note that using BODY will set the \Seen flag. This is why the default uses BODY.PEEK[].
    The item name X-GM-LABELS is a Google Mail extension; it shows the labels for a message.
    For example:
    IMAPExportMbox imaps://username:password@imap.googlemail.com/messages_for_export exported.mbox 1:10,20
    IMAPExportMbox imaps://username:password@imap.googlemail.com/messages_for_export exported.mbox 3 ENVELOPE X-GM-LABELS

    The sequence-set is passed unmodified to the FETCH command.
    The item names are wrapped in parentheses if more than one is provided. Otherwise, the parameter is assumed to be wrapped if necessary.
    Parameters with spaces must be quoted otherwise the OS shell will normally treat them as separate parameters.
    Also the listener that writes the mailbox only captures the multi-line responses (e.g. ones that include BODY references). It does not capture the output from FETCH commands using item names such as ENVELOPE or FLAGS that return a single line response.

    • Constructor Summary

      Constructors 
      Constructor Description
      IMAPExportMbox()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void main​(java.lang.String[] args)  
      private static java.lang.String matches​(java.lang.String input, java.util.regex.Pattern pat, int index)  
      private static boolean startsWith​(java.lang.String input, java.util.regex.Pattern pat)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • EOL_DEFAULT

        private static final java.lang.String EOL_DEFAULT
      • PATFROM

        private static final java.util.regex.Pattern PATFROM
      • PATID

        private static final java.util.regex.Pattern PATID
      • PATSEQ

        private static final java.util.regex.Pattern PATSEQ
      • PATEXISTS

        private static final java.util.regex.Pattern PATEXISTS
      • PATTEMPFAIL

        private static final java.util.regex.Pattern PATTEMPFAIL
    • Constructor Detail

      • IMAPExportMbox

        public IMAPExportMbox()
    • Method Detail

      • main

        public static void main​(java.lang.String[] args)
                         throws java.io.IOException,
                                java.net.URISyntaxException
        Throws:
        java.io.IOException
        java.net.URISyntaxException
      • matches

        private static java.lang.String matches​(java.lang.String input,
                                                java.util.regex.Pattern pat,
                                                int index)
      • startsWith

        private static boolean startsWith​(java.lang.String input,
                                          java.util.regex.Pattern pat)