Class IMAPExportMbox

java.lang.Object
org.apache.commons.net.examples.mail.IMAPExportMbox

public final class IMAPExportMbox extends 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.