Mailbox access

Since mailbox may have folders, one has to be selected before fetching a message. It can be performed explicitly by

imap conn("imap.server.com", 143);
conn.authenticate("mailio@server.com", "mailiopass", imap::auth_method_t::LOGIN);
message msg;
conn.select("inbox");
conn.fetch(1, msg);
There is an oveerload of imap::fetch which takes as the first parameter the folder, which makes selecting unnecessary. However, explicit selecting is sometimes better approach.

A folder may have subfolders which thmeselves have its own subfolders, constructing a hierarchy of folders (directories). The subfolder names are split by a character delimiter which is usually a dot or slash. To find out which delimiter is used by a concrete IMAP server, there is the method imap::folder_delimiter. Then, the select function can be used to specify more than one directory of the hierarchy, like imap::select("Inbox/Archive") or imap::select("Inbox.Archive"). There is an overload of the select method which takes subfolder names as a list, so one does not have to specify the delimiter: imap::select(list<string>{"Inbox", "Archive"})

Each message has sequence number and unique identifier. The first one can be changed even within a session, while the second remains even between sessions. For that reason, imap::fetch has the third argument the flag whether the first argument of message id should be treated as the sequence number of unique identifier (by default it set to false meaning it is the sequence number). The fourth argument is the flag whether the whole message should be fetched or the header only (by default set for the whole message). Thus, after selecting a folder, fetching message header with the unique id 1234 would be imap::fetch(1234, msg, true, true).