Show IMAPParser.h syntax highlighted
#ifndef IMAP_PARSER
#define IMAP_PARSER
#ifdef CWDEBUG
#include "sys.h"
#include "debug.h"
#endif
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include <string>
#include <map>
#include <iostream>
#include <exception>
#include <sstream>
#include <IMAPTypes.h>
namespace IMAP
{
/**
* This class represents a generic IMAP parser as needed by IMAPFolder.
*/
class IMAPParser
{
public:
// Parser state values
typedef u_int32_t ParsingState;
// Command has completed (does not specify state, just complete)
static const ParsingState CommandComplete;
// Server sent a disconnect notice, or connection dropped
static const ParsingState ServerDisconnected;
// Mailbox counts changed
static const ParsingState MailboxChanged;
// Request completion had an OK status
static const ParsingState RequestOK;
// Request completion had an NO status
static const ParsingState RequestDenied;
// Request completion had an BAD status
static const ParsingState RequestFailed;
// Request completion had an BAD status
static const ParsingState ValidityExpired;
IMAPParser() { }
virtual ~IMAPParser() {}
/**
* Parse the results of an IMAP fetch command, and store the important
* attributes in the provided message map, keyed by message UID.
*
* @param i The stream from which the data is to be parsed.
* @param mm A pointer to an existing MessageMap into which the
* relevant data will be stored.
* @param thread_levels A pointer to a ThreadLevelMap which has
* already been populated with uid->level indications.
* @see parseMailboxThreads() below.
* @returns A set of parsing state flags that indicate the result.
*/
virtual ParsingState parseAttributeFetch(std::iostream &i, MessageMap *mm, ThreadLevelMap *thread_levels, const UIDList &wanted) = 0;
/**
* Parse the results of an IMAP threading command, and store the
* thread levels in the provided map, Also put the UIDs of the
* messages in sorted order into the MessageList.
*
* @param i The stream from which the data is to be parsed.
* @param tmap A pointer to an existing ThreadLevelMap. This map will
* be emptied and re-filled.
* @param uidlist A pointer to a UIDList that will hold the proper
* order for the threaded messages.
* @returns The parsing state flags
*/
virtual ParsingState parseMailboxThreads(std::iostream &i,
ThreadLevelMap *thread_levels, UIDList *uidlist) = 0;
virtual ParsingState parseSorting(std::iostream &i, const char *key,
UIDList *mlist) = 0;
virtual ParsingState processLogin(std::iostream &i,
const std::string &user, const std::string &password,
const std::string &folder, bool create_folder = false) = 0;
virtual ParsingState parseUnseen(std::iostream &i,
UIDList *unseenMessages) = 0;
/**
* Given a base folder name, send an IMAP command to list the folders
* at that base (non-recursive) and place the entries in the
* FolderList object. The resutling list items are simply strings of
* the form "[f|d] <length> string", as needed by the RequestProcessor
* response. TODO: It may be useful to change this into a more
* structured type.
* @param i The connected stream for communications with IMAP
* @param base The base location of the folders to list. Should
* typically end in /, or be empty.
* @param list A pointer to the FolderList object that will hold the
* resulting list.
* @param all A boolean indicating if you want all, or just subscribed
* @returns The IMAP parsing state
*/
virtual ParsingState parseFolderList(std::iostream &i,
const std::string &base,
FolderList *list,
bool all = true) = 0;
virtual ParsingState parseSubscribe(std::iostream &i,
const std::string &folder,
bool add = true) = 0;
virtual ParsingState parseMessageFetch(std::iostream &i,
IMAP::IMAPUID uid,
std::ostream &stream) = 0;
virtual ParsingState parseMessageAppend(std::iostream &imap,
const std::string &folder,
int size,
std::istream &source) = 0;
/**
* Run through a noop and check for server updates.
*/
virtual ParsingState parseNOOP(std::iostream &i) = 0;
/**
* Run a flag store command on the given flag. It will only process
* the flag if the current uid validity on the imap connection
* matches.
*
* @param i The iostream connected to the IMAP server
* @param flag The IMAP flag to add (i.e. \Deleted)
* @param uidv The UIDValidity that was used to generate the UID you
* are using.
* @param uid The UID of the message to delete.
*/
virtual ParsingState parseFlagChange(std::iostream &i,
const char *flag,
IMAPUID uidv,
IMAPUID uid,
bool set) = 0;
/**
* Parse an expunge command.
* @param i The connection to the IMAP server (in a selected state)
*/
virtual ParsingState parseExpunge(std::iostream &i) = 0;
virtual ParsingState parseCopy(std::iostream &i, IMAPUID uidv,
IMAPUID uid, const char *destfolder) = 0;
virtual ParsingState parseDeleteFolder(std::iostream &i,
const char *folder) = 0;
virtual ParsingState parseRenameFolder(std::iostream &i,
const char *folder,
const char *destfolder) = 0;
virtual ParsingState parseCreateFolder(std::iostream &i,
const char *folder) = 0;
virtual int getExistsCount() = 0;
virtual int getRecentCount() = 0;
virtual IMAP::IMAPUID getUIDValidity() = 0;
const static std::string uidSelector;
const static std::string flagsSelector;
const static std::string sizeSelector;
const static std::string snippetSelector;
const static std::string bodySelector;
const static std::string subjectSelector;
const static std::string toSelector;
const static std::string dateSelector;
const static std::string fromSelector;
const static std::string messageidSelector;
const static std::string replytoSelector;
const static std::string inreplytoSelector;
const static std::string threadlevelSelector;
const static std::string charsetSelector;
protected:
std::string field_to_selector(const std::string &s);
};
};
#endif
See more files for this project here