summaryrefslogtreecommitdiff
path: root/src/operator-search.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/operator-search.cc')
-rw-r--r--src/operator-search.cc140
1 files changed, 49 insertions, 91 deletions
diff --git a/src/operator-search.cc b/src/operator-search.cc
index 08f51c1..aca9f1f 100644
--- a/src/operator-search.cc
+++ b/src/operator-search.cc
@@ -1,9 +1,10 @@
-/** --------------------------------------------------------------------
+/**
* @file operator-search.cc
* @brief Implementation of the SEARCH command.
* @author Andreas Aardal Hanssen
* @date 2002-2005
- * ----------------------------------------------------------------- **/
+ */
+
#include "convert.h"
#include "depot.h"
#include "imapparser.h"
@@ -21,10 +22,11 @@
#include <ctype.h>
-using namespace ::std;
using namespace Binc;
+using std::endl;
+using std::string;
+using std::vector;
-//----------------------------------------------------------------------
bool SearchOperator::SearchNode::convertDate(const string &date, time_t &t, const string &delim)
{
vector<string> parts;
@@ -32,7 +34,7 @@ bool SearchOperator::SearchNode::convertDate(const string &date, time_t &t, cons
if (parts.size() < 3) return false;
struct tm mold;
- memset((char *)&mold, 0, sizeof(struct tm));
+ memset(&mold, 0, sizeof(struct tm));
mold.tm_mday = atoi(parts[0].c_str());
mold.tm_year = atoi(parts[2].c_str()) - 1900;
@@ -70,7 +72,6 @@ bool SearchOperator::SearchNode::convertDate(const string &date, time_t &t, cons
return true;
}
-//----------------------------------------------------------------------
bool SearchOperator::SearchNode::convertDateHeader(const string &d_in, time_t &t)
{
string date = d_in;
@@ -82,22 +83,18 @@ bool SearchOperator::SearchNode::convertDateHeader(const string &d_in, time_t &t
return result;
}
-//----------------------------------------------------------------------
SearchOperator::SearchNode::SearchNode(void) {}
-//----------------------------------------------------------------------
SearchOperator::SearchNode::SearchNode(const BincImapParserSearchKey &a)
{
init(a);
}
-//----------------------------------------------------------------------
int SearchOperator::SearchNode::getType(void) const
{
return type;
}
-//----------------------------------------------------------------------
bool SearchOperator::SearchNode::match(Mailbox *mailbox,
Message *m,
unsigned int seqnr,
@@ -108,16 +105,12 @@ bool SearchOperator::SearchNode::match(Mailbox *mailbox,
string tmp;
switch (type) {
- //--------------------------------------------------------------------
case S_ALL:
return true;
- //--------------------------------------------------------------------
case S_ANSWERED:
return (m->getStdFlags() & Message::F_ANSWERED);
- //--------------------------------------------------------------------
case S_BCC:
return m->headerContains("bcc", astring);
- //--------------------------------------------------------------------
case S_BEFORE: {
time_t mtime = m->getInternalDate();
struct tm *mtime_ = localtime(&mtime);
@@ -136,32 +129,24 @@ bool SearchOperator::SearchNode::match(Mailbox *mailbox,
}
return mtime < atime;
- } //--------------------------------------------------------------------
+ }
case S_BODY:
return m->bodyContains(astring);
- //--------------------------------------------------------------------
case S_CC:
return m->headerContains("cc", astring);
- //--------------------------------------------------------------------
case S_DELETED:
return (m->getStdFlags() & Message::F_DELETED);
- //--------------------------------------------------------------------
case S_FLAGGED:
return (m->getStdFlags() & Message::F_FLAGGED);
- //--------------------------------------------------------------------
case S_FROM:
return m->headerContains("from", astring);
- //--------------------------------------------------------------------
case S_KEYWORD:
// the server does not support keywords
return false;
- //--------------------------------------------------------------------
case S_NEW:
return (m->getStdFlags() & Message::F_RECENT) && !(m->getStdFlags() & Message::F_SEEN);
- //--------------------------------------------------------------------
case S_OLD:
return !(m->getStdFlags() & Message::F_RECENT);
- //--------------------------------------------------------------------
case S_ON: {
time_t mtime = m->getInternalDate();
struct tm *mtime_ = localtime(&mtime);
@@ -180,13 +165,11 @@ bool SearchOperator::SearchNode::match(Mailbox *mailbox,
}
return mtime == atime;
- } //--------------------------------------------------------------------
+ }
case S_RECENT:
return (m->getStdFlags() & Message::F_RECENT);
- //--------------------------------------------------------------------
case S_SEEN:
return (m->getStdFlags() & Message::F_SEEN);
- //--------------------------------------------------------------------
case S_SINCE: {
time_t mtime = m->getInternalDate();
struct tm *mtime_ = localtime(&mtime);
@@ -205,52 +188,39 @@ bool SearchOperator::SearchNode::match(Mailbox *mailbox,
}
return mtime >= atime;
- } //--------------------------------------------------------------------
+ }
case S_SUBJECT:
return m->headerContains("subject", astring);
- //--------------------------------------------------------------------
case S_TEXT:
return m->textContains(astring);
- //--------------------------------------------------------------------
case S_TO:
return m->headerContains("to", astring);
- //--------------------------------------------------------------------
case S_UNANSWERED:
return !(m->getStdFlags() & Message::F_ANSWERED);
- //--------------------------------------------------------------------
case S_UNDELETED:
return !(m->getStdFlags() & Message::F_DELETED);
- //--------------------------------------------------------------------
case S_UNFLAGGED:
return !(m->getStdFlags() & Message::F_FLAGGED);
- //--------------------------------------------------------------------
case S_UNKEYWORD:
// the server does not support keywords
return true;
- //--------------------------------------------------------------------
case S_UNSEEN:
return !(m->getStdFlags() & Message::F_SEEN);
- //--------------------------------------------------------------------
case S_DRAFT:
return (m->getStdFlags() & Message::F_DRAFT);
- //--------------------------------------------------------------------
case S_HEADER:
return m->headerContains(astring, bstring);
- //--------------------------------------------------------------------
case S_LARGER: {
return (m->getSize(true) > number);
}
- //--------------------------------------------------------------------
case S_NOT:
- for (vector<SearchNode>::const_iterator i = children.begin(); i != children.end(); ++i)
- if ((*i).match(mailbox, m, seqnr, lastmessage, lastuid)) return false;
+ for (const auto &i : children)
+ if (i.match(mailbox, m, seqnr, lastmessage, lastuid)) return false;
return true;
- //--------------------------------------------------------------------
case S_OR:
- for (vector<SearchNode>::const_iterator i = children.begin(); i != children.end(); ++i)
- if ((*i).match(mailbox, m, seqnr, lastmessage, lastuid)) return true;
+ for (const auto &i : children)
+ if (i.match(mailbox, m, seqnr, lastmessage, lastuid)) return true;
return false;
- //--------------------------------------------------------------------
case S_SENTBEFORE: {
string tmp = m->getHeader("date");
if (tmp == "") return false;
@@ -269,7 +239,7 @@ bool SearchOperator::SearchNode::match(Mailbox *mailbox,
}
return mtime < atime;
- } //--------------------------------------------------------------------
+ }
case S_SENTON: {
string tmp = m->getHeader("date");
if (tmp == "") return false;
@@ -288,7 +258,7 @@ bool SearchOperator::SearchNode::match(Mailbox *mailbox,
}
return mtime == atime;
- } //--------------------------------------------------------------------
+ }
case S_SENTSINCE: {
string tmp = m->getHeader("date");
if (tmp == "") return false;
@@ -307,33 +277,30 @@ bool SearchOperator::SearchNode::match(Mailbox *mailbox,
}
return mtime >= atime;
- } //--------------------------------------------------------------------
+ }
case S_SMALLER:
return (m->getSize(true) < number);
- //--------------------------------------------------------------------
case S_UID:
- if (!bset->isInSet(m->getUID()))
+ if (!bset->isInSet(m->getUID())) {
if (!(m->getUID() == lastuid && !bset->isLimited())) return false;
+ }
return true;
- //--------------------------------------------------------------------
case S_UNDRAFT:
return !(m->getStdFlags() & Message::F_DRAFT);
- //--------------------------------------------------------------------
case S_SET:
- if (!bset->isInSet(seqnr))
+ if (!bset->isInSet(seqnr)) {
if (!(seqnr == lastmessage && !bset->isLimited())) return false;
+ }
return true;
- //--------------------------------------------------------------------
case S_AND:
- for (vector<SearchNode>::const_iterator i = children.begin(); i != children.end(); ++i)
- if (!(*i).match(mailbox, m, seqnr, lastmessage, lastuid)) return false;
+ for (const auto &i : children)
+ if (!i.match(mailbox, m, seqnr, lastmessage, lastuid)) return false;
return true;
}
return false;
}
-//----------------------------------------------------------------------
void SearchOperator::SearchNode::init(const BincImapParserSearchKey &a)
{
astring = a.astring;
@@ -490,45 +457,37 @@ void SearchOperator::SearchNode::init(const BincImapParserSearchKey &a)
}
}
-//----------------------------------------------------------------------
int SearchOperator::SearchNode::getWeight(void) const
{
return weight;
}
-//----------------------------------------------------------------------
void SearchOperator::SearchNode::setWeight(int i)
{
weight = i;
}
-//----------------------------------------------------------------------
void SearchOperator::SearchNode::order(void)
{
- for (vector<SearchNode>::iterator i = children.begin(); i != children.end(); ++i)
- (*i).order();
- ::stable_sort(children.begin(), children.end(), compareNodes);
+ for (auto &i : children)
+ i.order();
+ stable_sort(children.begin(), children.end(), compareNodes);
}
-//----------------------------------------------------------------------
SearchOperator::SearchOperator(void) {}
-//----------------------------------------------------------------------
SearchOperator::~SearchOperator(void) {}
-//----------------------------------------------------------------------
const string SearchOperator::getName(void) const
{
return "SEARCH";
}
-//----------------------------------------------------------------------
int SearchOperator::getState(void) const
{
return Session::SELECTED;
}
-//------------------------------------------------------------------------
Operator::ProcessResult SearchOperator::process(Depot &depot, Request &command)
{
Session &session = Session::getInstance();
@@ -566,7 +525,6 @@ Operator::ProcessResult SearchOperator::process(Depot &depot, Request &command)
return OK;
}
-//------------------------------------------------------------------------
Operator::ParseResult SearchOperator::parse(Request &c_in) const
{
Session &session = Session::getInstance();
@@ -627,18 +585,17 @@ Operator::ParseResult SearchOperator::parse(Request &c_in) const
return ACCEPT;
}
-//----------------------------------------------------------------------
Operator::ParseResult SearchOperator::expectSearchKey(BincImapParserSearchKey &s_in) const
{
Session &session = Session::getInstance();
Operator::ParseResult res;
s_in.type = BincImapParserSearchKey::KEY_OTHER;
- if ((res = expectThisString("ALL")) == ACCEPT)
+ if ((res = expectThisString("ALL")) == ACCEPT) {
s_in.name = "ALL";
- else if ((res = expectThisString("ANSWERED")) == ACCEPT)
+ } else if ((res = expectThisString("ANSWERED")) == ACCEPT) {
s_in.name = "ANSWERED";
- else if ((res = expectThisString("BCC")) == ACCEPT) {
+ } else if ((res = expectThisString("BCC")) == ACCEPT) {
s_in.name = "BCC";
if ((res = expectSPACE()) != ACCEPT) {
session.setLastError("Expected SPACE");
@@ -683,11 +640,11 @@ Operator::ParseResult SearchOperator::expectSearchKey(BincImapParserSearchKey &s
session.setLastError("Expected astring");
return res;
}
- } else if ((res = expectThisString("DELETED")) == ACCEPT)
+ } else if ((res = expectThisString("DELETED")) == ACCEPT) {
s_in.name = "DELETED";
- else if ((res = expectThisString("FLAGGED")) == ACCEPT)
+ } else if ((res = expectThisString("FLAGGED")) == ACCEPT) {
s_in.name = "FLAGGED";
- else if ((res = expectThisString("FROM")) == ACCEPT) {
+ } else if ((res = expectThisString("FROM")) == ACCEPT) {
s_in.name = "FROM";
if ((res = expectSPACE()) != ACCEPT) {
session.setLastError("Expected SPACE");
@@ -709,11 +666,11 @@ Operator::ParseResult SearchOperator::expectSearchKey(BincImapParserSearchKey &s
session.setLastError("Expected flag_keyword");
return res;
}
- } else if ((res = expectThisString("NEW")) == ACCEPT)
+ } else if ((res = expectThisString("NEW")) == ACCEPT) {
s_in.name = "NEW";
- else if ((res = expectThisString("OLD")) == ACCEPT)
+ } else if ((res = expectThisString("OLD")) == ACCEPT) {
s_in.name = "OLD";
- else if ((res = expectThisString("ON")) == ACCEPT) {
+ } else if ((res = expectThisString("ON")) == ACCEPT) {
s_in.name = "ON";
if ((res = expectSPACE()) != ACCEPT) {
@@ -725,11 +682,11 @@ Operator::ParseResult SearchOperator::expectSearchKey(BincImapParserSearchKey &s
session.setLastError("Expected date");
return res;
}
- } else if ((res = expectThisString("RECENT")) == ACCEPT)
+ } else if ((res = expectThisString("RECENT")) == ACCEPT) {
s_in.name = "RECENT";
- else if ((res = expectThisString("SEEN")) == ACCEPT)
+ } else if ((res = expectThisString("SEEN")) == ACCEPT) {
s_in.name = "SEEN";
- else if ((res = expectThisString("SINCE")) == ACCEPT) {
+ } else if ((res = expectThisString("SINCE")) == ACCEPT) {
s_in.name = "SINCE";
if ((res = expectSPACE()) != ACCEPT) {
@@ -774,13 +731,13 @@ Operator::ParseResult SearchOperator::expectSearchKey(BincImapParserSearchKey &s
session.setLastError("Expected astring");
return res;
}
- } else if ((res = expectThisString("UNANSWERED")) == ACCEPT)
+ } else if ((res = expectThisString("UNANSWERED")) == ACCEPT) {
s_in.name = "UNANSWERED";
- else if ((res = expectThisString("UNDELETED")) == ACCEPT)
+ } else if ((res = expectThisString("UNDELETED")) == ACCEPT) {
s_in.name = "UNDELETED";
- else if ((res = expectThisString("UNFLAGGED")) == ACCEPT)
+ } else if ((res = expectThisString("UNFLAGGED")) == ACCEPT) {
s_in.name = "UNFLAGGED";
- else if ((res = expectThisString("UNKEYWORD")) == ACCEPT) {
+ } else if ((res = expectThisString("UNKEYWORD")) == ACCEPT) {
s_in.name = "UNKEYWORD";
if ((res = expectSPACE()) != ACCEPT) {
session.setLastError("Expected SPACE");
@@ -791,11 +748,11 @@ Operator::ParseResult SearchOperator::expectSearchKey(BincImapParserSearchKey &s
session.setLastError("Expected flag_keyword");
return res;
}
- } else if ((res = expectThisString("UNSEEN")) == ACCEPT)
+ } else if ((res = expectThisString("UNSEEN")) == ACCEPT) {
s_in.name = "UNSEEN";
- else if ((res = expectThisString("DRAFT")) == ACCEPT)
+ } else if ((res = expectThisString("DRAFT")) == ACCEPT) {
s_in.name = "DRAFT";
- else if ((res = expectThisString("HEADER")) == ACCEPT) {
+ } else if ((res = expectThisString("HEADER")) == ACCEPT) {
s_in.name = "HEADER";
if ((res = expectSPACE()) != ACCEPT) {
@@ -929,9 +886,9 @@ Operator::ParseResult SearchOperator::expectSearchKey(BincImapParserSearchKey &s
session.setLastError("Expected number");
return res;
}
- } else if ((res = expectThisString("UNDRAFT")) == ACCEPT)
+ } else if ((res = expectThisString("UNDRAFT")) == ACCEPT) {
s_in.name = "UNDRAFT";
- else if ((res = expectSet(s_in.bset)) == ACCEPT) {
+ } else if ((res = expectSet(s_in.bset)) == ACCEPT) {
s_in.name = "";
s_in.type = BincImapParserSearchKey::KEY_SET;
} else if ((res = expectThisString("(")) == ACCEPT) {
@@ -953,8 +910,9 @@ Operator::ParseResult SearchOperator::expectSearchKey(BincImapParserSearchKey &s
session.setLastError("Expected )");
return res;
}
- } else
+ } else {
return REJECT;
+ }
return ACCEPT;
}