/** * @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() : uidmode(false) , extra(nullptr) , flags() , statuses() , bset() , searchkey() , fatt() {} Request::~Request() { if (extra != nullptr) delete extra; } void Request::setUidMode() { uidmode = true; } bool Request::getUidMode() const { return uidmode; } void Request::setTag(string &t_in) { tag = t_in; } const string &Request::getTag() const { return tag; } void Request::setMode(const string &m_in) { mode = m_in; } const string &Request::getMode() const { return mode; } void Request::setName(const string &s_in) { name = s_in; } const string &Request::getName() const { return name; } void Request::setAuthType(const string &s_in) { authtype = s_in; } const string &Request::getAuthType() const { return authtype; } void Request::setLiteral(const string &s_in) { literal = s_in; } const string &Request::getLiteral() const { return literal; } void Request::setDate(const string &s_in) { date = s_in; } const string &Request::getDate() const { return date; } void Request::setCharSet(const string &s_in) { charset = s_in; uppercase(charset); } const string &Request::getCharSet() const { return charset; } void Request::setUserID(const string &s_in) { userid = s_in; } const string &Request::getUserID() const { return userid; } void Request::setPassword(const string &s_in) { password = s_in; } const string &Request::getPassword() const { return password; } void Request::setMailbox(const string &s_in) { mailbox = s_in; } const string &Request::getMailbox() const { return mailbox; } void Request::setListMailbox(const string &s_in) { listmailbox = s_in; } const string &Request::getListMailbox() const { return listmailbox; } void Request::setContextInfo(const string &s_in) { contextInfo = s_in; } const string &Request::getContextInfo() const { return contextInfo; } void Request::setNewMailbox(const string &s_in) { newmailbox = s_in; } const string &Request::getNewMailbox() const { return newmailbox; } SequenceSet &Request::getSet() { return bset; } std::vector &Request::getStatuses() { return statuses; } std::vector &Request::getFlags() { return flags; } SequenceSet::SequenceSet() : 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() {} SequenceSet &SequenceSet::null() { static SequenceSet nil; nil.nullSet = true; return nil; } bool SequenceSet::isNull() const { return nullSet; } SequenceSet &SequenceSet::all() { 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() { 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() { type = 0; number = 0; } const SequenceSet &BincImapParserSearchKey::getSet() const { return bset; }