This class started off as just a way to add the ability to append an email containing a file attachment generated by the FPE to a particular IMAP mail box. The initial version just used libcurl to connect to the server and issue the command too attach the email. Out of this grew a fully fledged class that provides the ability to connect to an IMAP server and issue commands and receive the raw text results. The transport and connection are again provided by libcurl as with CMailSMTP and all IMAP4 commands are supported along with the IDLE and NOOP which enable a mailbox to be interrogated to see if its state has changed (e.g. new mail has arrived).
This was all that was really needed for the FPE functionality but the decision was made to extend the work with two more support classes that would enable a higher level program interface than that provided by CMailIMAP.CMailIMAPParse originally began as part of CMailIMAP contains all static methods and data and is used to parse the text response provided by CMailIMAP. It takes the raw text response returned by a command, parses it into a command specific structure; a pointer to which is returned. The structure contains a group of common fields per command that include returned status and also any error message that may have been sent. The decoded information provided as part of these structures allows a high level language to gather information and process further IMAP commands. For example a program may search a selected mailbox given certain criteria, receive, parse the response and then issue further commands based on the structure containing the UIDs of the found email.
All the above enabled the creation of a simple IMAP command terminal example program that enables a connection to an IMAP server and commands to be issued. This provides the ability to manipulate email and mailboxes but does not give a way to download/upload email content such as attachments. The in depth map of an emails structure is provided by its BODYSTRUCTURE which can be requested through a FETCH command; other structures exist that describe email details such as its ENVELOPE but the BODYSTRUCTURE is the most detailed. An IMAP list structure that represents this can be returned by CMailIMAPParse and in order to parse and read this CIMAPBodyStruct was born.
This parses the BODYSTRUCTURE list into a tree structure and enables this tree to be walked and a user provided function (with data) called on the tree nodes (individual body parts). The provided function can then interrogate the node for data to use in any way. The class contains an example built-in that extracts information on all attachments and places this information inits local data (i.e. attachment type, encoding, file name etc). This built in provided the functionality needed to create another example program that searches for all attachments in emails within a given mailbox and downloads them to a local directory.
I have spent al ot of time of this IMAP functionality during January and February and its still a work in progress as learn more about IMAP .