summaryrefslogtreecommitdiff
path: root/src/operator-list.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/operator-list.cc')
-rw-r--r--src/operator-list.cc60
1 files changed, 25 insertions, 35 deletions
diff --git a/src/operator-list.cc b/src/operator-list.cc
index baa8107..7ee66f3 100644
--- a/src/operator-list.cc
+++ b/src/operator-list.cc
@@ -2,13 +2,6 @@
* @file operator-list.cc
* @brief Implementation of the LIST command.
* ----------------------------------------------------------------- **/
-#include <sys/types.h>
-#include <dirent.h>
-#include <sys/stat.h>
-
-#include <string>
-#include <iostream>
-
#include "convert.h"
#include "depot.h"
#include "iodevice.h"
@@ -19,6 +12,13 @@
#include "regmatch.h"
#include "session.h"
+#include <iostream>
+#include <string>
+
+#include <dirent.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
using namespace ::std;
using namespace Binc;
@@ -33,9 +33,7 @@ ListOperator::ListOperator(void)
}
//----------------------------------------------------------------------
-ListOperator::~ListOperator(void)
-{
-}
+ListOperator::~ListOperator(void) {}
//----------------------------------------------------------------------
const string ListOperator::getName(void) const
@@ -50,8 +48,7 @@ int ListOperator::getState(void) const
}
//------------------------------------------------------------------------
-Operator::ProcessResult ListOperator::process(Depot &depot,
- Request &command)
+Operator::ProcessResult ListOperator::process(Depot &depot, Request &command)
{
Session &session = Session::getInstance();
const char delim = depot.getDelimiter();
@@ -71,16 +68,14 @@ Operator::ProcessResult ListOperator::process(Depot &depot,
string regex = toRegex(wildcard, depot.getDelimiter());
string wildcardLower = regex;
lowercase(wildcardLower);
- if (wildcardLower.substr(0, 6) == "^inbox")
- regex = "^[iI][nN][bB][oO][xX]" + regex.substr(6);
+ if (wildcardLower.substr(0, 6) == "^inbox") regex = "^[iI][nN][bB][oO][xX]" + regex.substr(6);
// remove leading or trailing delimiter in reference
string ref = command.getMailbox();
trim(ref, string(&delim, 1));
wildcardLower = ref;
lowercase(wildcardLower);
- if (wildcardLower.substr(0, 6) == "^inbox")
- ref = "^[iI][nN][bB][oO][xX]" + ref.substr(6);
+ 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);
@@ -88,8 +83,7 @@ Operator::ProcessResult ListOperator::process(Depot &depot,
// a map from mailbox name to flags
map<string, unsigned int> mailboxes;
- if (cacheTimeout == 0 || cacheTimeout < time(0) - LIST_CACHE_TIMEOUT
- || session.mailboxchanges) {
+ if (cacheTimeout == 0 || cacheTimeout < time(0) - LIST_CACHE_TIMEOUT || session.mailboxchanges) {
session.mailboxchanges = false;
// read through all entries in depository.
@@ -99,16 +93,16 @@ Operator::ProcessResult ListOperator::process(Depot &depot,
Mailbox *m = 0;
// skip entries that are not identified as mailboxes
- if ((m = depot.get(mpath)) == 0)
- continue;
+ if ((m = depot.get(mpath)) == 0) 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 == "") continue;
+ if (tmp == "")
+ continue;
else {
- // inherit flags that were already set for this mailbox.
+ // inherit flags that were already set for this mailbox.
int flags = DIR_SELECT;
if (m->isMarked(path)) flags |= DIR_MARKED;
if (mailboxes.find(tmp) != mailboxes.end()) flags |= mailboxes[tmp];
@@ -119,13 +113,12 @@ Operator::ProcessResult ListOperator::process(Depot &depot,
// added already.
string::size_type pos = tmp.rfind(delim);
while (pos != string::npos) {
- tmp = tmp.substr(0, pos);
- trim(tmp, string(&delim, 1));
+ tmp = tmp.substr(0, pos);
+ trim(tmp, string(&delim, 1));
- if (mailboxes.find(tmp) == mailboxes.end())
- mailboxes[tmp] = 0;
+ if (mailboxes.find(tmp) == mailboxes.end()) mailboxes[tmp] = 0;
- pos = tmp.rfind(delim);
+ pos = tmp.rfind(delim);
}
}
@@ -163,12 +156,11 @@ Operator::ProcessResult ListOperator::process(Depot &depot,
cacheTimeout = time(0);
}
- // finally, print all mailbox entries with flags.
+ // 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())))
+ 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 = "";
@@ -196,12 +188,10 @@ Operator::ProcessResult ListOperator::process(Depot &depot,
bincClient << sep << "\\HasChildren";
sep = " ";
- if (flags & DIR_NOINFERIORS)
- bincClient << sep << "\\Noinferiors";
+ if (flags & DIR_NOINFERIORS) bincClient << sep << "\\Noinferiors";
- bincClient << ") \"" << depot.getDelimiter() << "\" "
- << toImapString(i->first) << endl;
- }
+ bincClient << ") \"" << depot.getDelimiter() << "\" " << toImapString(i->first) << endl;
+ }
}
return OK;