/** * @file imapparser.cc * @brief Implementation of the common items for parsing IMAP input * @author Andreas Aardal Hanssen * @date 2002-2005 */ #include "imapparser.h" #include "convert.h" #include #include #include #include #include #include using namespace Binc; using std::string; Request::Request(void) : uidmode(false) , extra(nullptr) , flags() , statuses() , bset() , searchkey() , fatt() {} Request::~Request(void) { if (extra != nullptr) delete extra; } void Request::setUidMode(void) { uidmode = true; } bool Request::getUidMode(void) const { return uidmode; } void Request::setTag(string &t_in) { tag = t_in; } const string &Request::getTag(void) const { return tag; } void Request::setMode(const string &m_in) { mode = m_in; } const string &Request::getMode(void) const { return mode; } void Request::setName(const string &s_in) { name = s_in; } const string &Request::getName(void) const { return name; } void Request::setAuthType(const string &s_in) { authtype = s_in; } const string &Request::getAuthType(void) const { return authtype; } void Request::setLiteral(const string &s_in) { literal = s_in; } const string &Request::getLiteral(void) const { return literal; } void Request::setDate(const string &s_in) { date = s_in; } const string &Request::getDate(void) const { return date; } void Request::setCharSet(const string &s_in) { charset = s_in; uppercase(charset); } const string &Request::getCharSet(void) const { return charset; } void Request::setUserID(const string &s_in) { userid = s_in; } const string &Request::getUserID(void) const { return userid; } void Request::setPassword(const string &s_in) { password = s_in; } const string &Request::getPassword(void) const { return password; } void Request::setMailbox(const string &s_in) { mailbox = s_in; } const string &Request::getMailbox(void) const { return mailbox; } void Request::setListMailbox(const string &s_in) { listmailbox = s_in; } const string &Request::getListMailbox(void) const { return listmailbox; } void Request::setContextInfo(const string &s_in) { contextInfo = s_in; } const string &Request::getContextInfo(void) const { return contextInfo; } void Request::setNewMailbox(const string &s_in) { newmailbox = s_in; } const string &Request::getNewMailbox(void) const { return newmailbox; } SequenceSet &Request::getSet(void) { return bset; } std::vector &Request::getStatuses(void) { return statuses; } std::vector &Request::getFlags(void) { return flags; } SequenceSet::SequenceSet(void) : limited(true), nullSet(false) {} SequenceSet::SequenceSet(const SequenceSet ©) : limited(copy.limited) , nullSet(copy.nullSet) , internal(copy.internal) {} SequenceSet &SequenceSet::operator=(const SequenceSet ©) { limited = copy.limited; nullSet = copy.nullSet; internal = copy.internal; return *this; } SequenceSet::~SequenceSet(void) {} SequenceSet &SequenceSet::null(void) { static SequenceSet nil; nil.nullSet = true; return nil; } bool SequenceSet::isNull(void) const { return nullSet; } SequenceSet &SequenceSet::all(void) { static bool initialized = false; static SequenceSet all; if (!initialized) { all.addRange(1, (unsigned int)-1); initialized = true; } return all; } SequenceSet::Range::Range(unsigned int a, unsigned int b) { if (a > b) { from = b; to = a; } else { from = a; to = b; } } void SequenceSet::addRange(unsigned int a, unsigned int b) { if (a == (unsigned int)-1 || b == (unsigned int)-1) limited = false; internal.push_back(Range(a, b)); } void SequenceSet::addNumber(unsigned int a) { if (a == (unsigned int)-1) limited = false; internal.push_back(Range(a, a)); } bool SequenceSet::isInSet(unsigned int n) const { unsigned int maxvalue = 0; for (const auto &r : internal) { if (r.from > maxvalue) maxvalue = r.from; else if (r.to > maxvalue) maxvalue = r.to; if (n >= r.from && n <= r.to) return true; } return (n > maxvalue && !limited); } BincImapParserFetchAtt::BincImapParserFetchAtt(const std::string &typeName) : type(typeName) { offsetstart = 0; offsetlength = (unsigned int)-1; hassection = false; } string BincImapParserFetchAtt::toString(void) { string tmp; if (type == "BODY.PEEK") tmp = "BODY"; else tmp = type; if (type == "BODY" || type == "BODY.PEEK") { if (hassection) { tmp += "["; tmp += section; if (sectiontext != "") { if (section != "") tmp += "."; tmp += sectiontext; if (headerlist.size() > 0) { tmp += " ("; for (auto i = headerlist.cbegin(); i != headerlist.cend(); ++i) { if (i != headerlist.cbegin()) tmp += " "; tmp += Binc::toImapString(*i); } tmp += ")"; } } tmp += "]"; if (offsetstart == 0 && offsetlength == (unsigned int)-1) tmp += " "; else tmp += "<" + Binc::toString(offsetstart) + "> "; } } return tmp; } BincImapParserSearchKey::BincImapParserSearchKey(void) { type = 0; number = 0; } const SequenceSet &BincImapParserSearchKey::getSet(void) const { return bset; }