diff options
Diffstat (limited to 'src/operator-list.cc')
-rw-r--r-- | src/operator-list.cc | 49 |
1 files changed, 22 insertions, 27 deletions
diff --git a/src/operator-list.cc b/src/operator-list.cc index 7ee66f3..b304e08 100644 --- a/src/operator-list.cc +++ b/src/operator-list.cc @@ -1,7 +1,8 @@ -/** -------------------------------------------------------------------- +/** * @file operator-list.cc * @brief Implementation of the LIST command. - * ----------------------------------------------------------------- **/ + */ + #include "convert.h" #include "depot.h" #include "iodevice.h" @@ -19,35 +20,30 @@ #include <sys/stat.h> #include <sys/types.h> -using namespace ::std; using namespace Binc; +using std::string; namespace { const time_t LIST_CACHE_TIMEOUT = 10; } -//---------------------------------------------------------------------- ListOperator::ListOperator(void) { cacheTimeout = 0; } -//---------------------------------------------------------------------- ListOperator::~ListOperator(void) {} -//---------------------------------------------------------------------- const string ListOperator::getName(void) const { return "LIST"; } -//---------------------------------------------------------------------- int ListOperator::getState(void) const { return Session::AUTHENTICATED | Session::SELECTED; } -//------------------------------------------------------------------------ Operator::ProcessResult ListOperator::process(Depot &depot, Request &command) { Session &session = Session::getInstance(); @@ -57,7 +53,7 @@ Operator::ProcessResult ListOperator::process(Depot &depot, Request &command) // hard coded reply. string wildcard; if ((wildcard = command.getListMailbox()) == "") { - bincClient << "* LIST (\\Noselect) \"" << delim << "\" \"\"" << endl; + bincClient << "* LIST (\\Noselect) \"" << delim << "\" \"\"" << std::endl; return OK; } @@ -78,30 +74,32 @@ Operator::ProcessResult ListOperator::process(Depot &depot, Request &command) if (wildcardLower.substr(0, 6) == "^inbox") ref = "^[iI][nN][bB][oO][xX]" + ref.substr(6); if (wildcardLower.substr(0, 5) == "inbox" && (wildcardLower.length() == 5 || wildcardLower[5] == delim)) + { ref = "INBOX" + ref.substr(5); + } // a map from mailbox name to flags - map<string, unsigned int> mailboxes; + std::map<string, unsigned int> mailboxes; - if (cacheTimeout == 0 || cacheTimeout < time(0) - LIST_CACHE_TIMEOUT || session.mailboxchanges) { + if (cacheTimeout == 0 || cacheTimeout < time(nullptr) - LIST_CACHE_TIMEOUT || session.mailboxchanges) { session.mailboxchanges = false; // read through all entries in depository. for (Depot::iterator i = depot.begin("."); i != depot.end(); ++i) { const string path = *i; const string mpath = depot.filenameToMailbox(path); - Mailbox *m = 0; + Mailbox *m = nullptr; // skip entries that are not identified as mailboxes - if ((m = depot.get(mpath)) == 0) continue; + if ((m = depot.get(mpath)) == nullptr) continue; // convert file name to mailbox name. skip it if there is no // corresponding mailbox name. string tmp = toCanonMailbox(depot.filenameToMailbox(path)); trim(tmp, string(&delim, 1)); - if (tmp == "") + if (tmp == "") { continue; - else { + } else { // inherit flags that were already set for this mailbox. int flags = DIR_SELECT; if (m->isMarked(path)) flags |= DIR_MARKED; @@ -123,14 +121,13 @@ Operator::ProcessResult ListOperator::process(Depot &depot, Request &command) } // find leaf nodes O(N^2) - map<string, unsigned int>::iterator i; - for (i = mailboxes.begin(); i != mailboxes.end(); ++i) { + for (auto i = mailboxes.begin(); i != mailboxes.end(); ++i) { string mailbox = i->first; mailbox += delim; bool leaf = true; - map<string, unsigned int>::const_iterator j = mailboxes.begin(); - for (; j != mailboxes.end(); ++j) { + + for (auto j = mailboxes.begin(); j != mailboxes.end(); ++j) { string::size_type pos = j->first.rfind(delim); if (pos == string::npos) continue; @@ -150,17 +147,15 @@ Operator::ProcessResult ListOperator::process(Depot &depot, Request &command) } cache = mailboxes; - cacheTimeout = time(0); + cacheTimeout = time(nullptr); } else { mailboxes = cache; - cacheTimeout = time(0); + cacheTimeout = time(nullptr); } // finally, print all mailbox entries with flags. - map<string, unsigned int>::iterator i = mailboxes.begin(); - - for (; i != mailboxes.end(); ++i) { - if (ref == "" || (ref.length() <= i->first.length() && ref == i->first.substr(0, ref.length()))) + for (auto i = mailboxes.begin(); i != mailboxes.end(); ++i) { + if (ref == "" || (ref.length() <= i->first.length() && ref == i->first.substr(0, ref.length()))) { if (regexMatch(i->first.substr(ref.length()), regex) == 0) { bincClient << "* LIST ("; string sep = ""; @@ -190,14 +185,14 @@ Operator::ProcessResult ListOperator::process(Depot &depot, Request &command) if (flags & DIR_NOINFERIORS) bincClient << sep << "\\Noinferiors"; - bincClient << ") \"" << depot.getDelimiter() << "\" " << toImapString(i->first) << endl; + bincClient << ") \"" << depot.getDelimiter() << "\" " << toImapString(i->first) << std::endl; } + } } return OK; } -//---------------------------------------------------------------------- Operator::ParseResult ListOperator::parse(Request &c_in) const { Session &session = Session::getInstance(); |