29 time_t &t,
const string &delim)
32 split(date, delim, parts);
33 if (parts.size() < 3)
return false;
36 memset((
char *) &mold, 0,
sizeof(
struct tm));
37 mold.tm_mday =
atoi(parts[0].c_str());
38 mold.tm_year =
atoi(parts[2].c_str()) - 1900;
42 string month = parts[1];
45 if (month ==
"jan") mold.tm_mon = 0;
46 else if (month ==
"feb") mold.tm_mon = 1;
47 else if (month ==
"mar") mold.tm_mon = 2;
48 else if (month ==
"apr") mold.tm_mon = 3;
49 else if (month ==
"may") mold.tm_mon = 4;
50 else if (month ==
"jun") mold.tm_mon = 5;
51 else if (month ==
"jul") mold.tm_mon = 6;
52 else if (month ==
"aug") mold.tm_mon = 7;
53 else if (month ==
"sep") mold.tm_mon = 8;
54 else if (month ==
"oct") mold.tm_mon = 9;
55 else if (month ==
"nov") mold.tm_mon = 10;
56 else if (month ==
"dec") mold.tm_mon = 11;
67 string::size_type n = date.find(
',');
68 if (n != string::npos)
69 date = date.substr(n + 1);
72 bool result = convertDate(date, t,
" ");
96 unsigned int lastmessage,
97 unsigned int lastuid)
const
115 struct tm *mtime_ = localtime(&mtime);
121 mtime_->tm_isdst = 0;
122 mtime = mktime(mtime_);
125 if (!convertDate(date, atime)) {
126 bincWarning <<
"warning, unable to convert " << date <<
127 " to a time_t" << endl;
131 return mtime < atime;
161 struct tm *mtime_ = localtime(&mtime);
167 mtime_->tm_isdst = 0;
168 mtime = mktime(mtime_);
171 if (!convertDate(date, atime)) {
172 bincWarning <<
"warning, unable to convert " << date <<
173 " to a time_t" << endl;
177 return mtime == atime;
187 struct tm *mtime_ = localtime(&mtime);
193 mtime_->tm_isdst = 0;
194 mtime = mktime(mtime_);
197 if (!convertDate(date, atime)) {
198 bincWarning <<
"warning, unable to convert " << date <<
199 " to a time_t" << endl;
203 return mtime >= atime;
237 return (m->
getSize(
true) > number);
241 for (vector<SearchNode>::const_iterator i = children.begin();
242 i != children.end(); ++i)
243 if ((*i).match(mailbox, m, seqnr, lastmessage, lastuid))
return false;
247 for (vector<SearchNode>::const_iterator i = children.begin();
248 i != children.end(); ++i)
249 if ((*i).match(mailbox, m, seqnr, lastmessage, lastuid))
return true;
260 if (!convertDateHeader(tmp, mtime))
return false;
262 if (mtime == (time_t) -1)
return false;
265 if (!convertDate(date, atime)) {
266 bincWarning <<
"warning, unable to convert " << date <<
267 " to a time_t" << endl;
271 return mtime < atime;
275 if (tmp ==
"")
return false;
280 if (!convertDateHeader(tmp, mtime))
return false;
282 if (mtime == (time_t) -1)
return false;
285 if (!convertDate(date, atime)) {
286 bincWarning <<
"warning, unable to convert " << date <<
287 " to a time_t" << endl;
291 return mtime == atime;
295 if (tmp ==
"")
return false;
300 if (!convertDateHeader(tmp, mtime))
return false;
302 if (mtime == (time_t) -1)
return false;
305 if (!convertDate(date, atime)) {
306 bincWarning <<
"warning, unable to convert " << date
307 <<
" to a time_t" << endl;
311 return mtime >= atime;
314 return (m->
getSize(
true) < number);
317 if (!bset->isInSet(m->
getUID()))
318 if (!(m->
getUID() == lastuid && !bset->isLimited()))
return false;
325 if (!bset->isInSet(seqnr))
326 if (!(seqnr == lastmessage && !bset->isLimited()))
return false;
330 for (vector<SearchNode>::const_iterator i = children.begin();
331 i != children.end(); ++i)
332 if (!(*i).match(mailbox, m, seqnr, lastmessage, lastuid))
return false;
350 if (a.
name ==
"ALL") { type = S_ALL; weight = 1; }
351 else if (a.
name ==
"ANSWERED") { type = S_ANSWERED; weight = 1; }
352 else if (a.
name ==
"BCC") { type = S_BCC; weight = 2; }
353 else if (a.
name ==
"BEFORE") { type = S_BEFORE; weight = 2; }
354 else if (a.
name ==
"BODY") { type = S_BODY; weight = 1; }
355 else if (a.
name ==
"CC") { type = S_CC; weight = 2; }
356 else if (a.
name ==
"DELETED") { type = S_DELETED; weight = 1; }
357 else if (a.
name ==
"FLAGGED") { type = S_FLAGGED; weight = 1; }
358 else if (a.
name ==
"FROM") { type = S_FROM; weight = 2; }
359 else if (a.
name ==
"KEYWORD") { type = S_KEYWORD; weight = 3; }
360 else if (a.
name ==
"NEW") { type = S_NEW; weight = 1; }
361 else if (a.
name ==
"OLD") { type = S_OLD; weight = 1; }
362 else if (a.
name ==
"ON") { type = S_ON; weight = 1; }
363 else if (a.
name ==
"RECENT") { type = S_RECENT; weight = 1; }
364 else if (a.
name ==
"SEEN") { type = S_SEEN; weight = 1; }
365 else if (a.
name ==
"SINCE") { type = S_SINCE; weight = 1; }
366 else if (a.
name ==
"SUBJECT") { type = S_SUBJECT; weight = 2; }
367 else if (a.
name ==
"TEXT") { type = S_TEXT; weight = 4; }
368 else if (a.
name ==
"TO") { type = S_TO; weight = 2; }
369 else if (a.
name ==
"UNANSWERED") { type = S_UNANSWERED; weight = 1; }
370 else if (a.
name ==
"UNDELETED") { type = S_UNDELETED; weight = 1; }
371 else if (a.
name ==
"UNFLAGGED") { type = S_UNFLAGGED; weight = 1; }
372 else if (a.
name ==
"UNKEYWORD") { type = S_UNKEYWORD; weight = 1; }
373 else if (a.
name ==
"UNSEEN") { type = S_UNSEEN; weight = 1; }
374 else if (a.
name ==
"DRAFT") { type = S_DRAFT; weight = 1; }
375 else if (a.
name ==
"HEADER") { type = S_HEADER; weight = 3; }
376 else if (a.
name ==
"LARGER") { type = S_LARGER; weight = 4; }
377 else if (a.
name ==
"NOT") {
382 vector<BincImapParserSearchKey>::const_iterator i = a.
children.begin();
386 children.push_back(b);
390 }
else if (a.
name ==
"OR") {
395 vector<BincImapParserSearchKey>::const_iterator i = a.
children.begin();
400 children.push_back(b);
404 }
else if (a.
name ==
"SENTBEFORE") { type = S_SENTBEFORE; weight = 1; }
405 else if (a.
name ==
"SENTON") { type = S_SENTON; weight = 1; }
406 else if (a.
name ==
"SENTSINCE") { type = S_SENTSINCE; weight = 1; }
407 else if (a.
name ==
"SMALLER") { type = S_SMALLER; weight = 4; }
408 else if (a.
name ==
"UID") {
412 }
else if (a.
name ==
"UNDRAFT") { type = S_UNDRAFT; weight = 1; }
422 vector<BincImapParserSearchKey>::const_iterator i = a.
children.begin();
426 children.push_back(b);
447 for (vector<SearchNode>::iterator i = children.begin();
448 i != children.end(); ++i)
450 ::stable_sort(children.begin(), children.end(), compareNodes);
485 +
" charset is not supported");
496 const unsigned int maxsqnr = mailbox->
getMaxSqnr();
497 const unsigned int maxuid = mailbox->
getMaxUid();
501 for (; i != mailbox->
end(); ++i) {
504 if (s.
match(mailbox, &message, i.
getSqnr(), maxsqnr, maxuid)) {
536 session.
setLastError(
"Expected astring after CHARSET SPACE");
543 session.
setLastError(
"Expected SPACE after CHARSET SPACE astring");
563 session.
setLastError(
"Expected search_key after search_key SPACE");
601 s_in.
name =
"BEFORE";
648 s_in.
name =
"KEYWORD";
687 s_in.
name =
"SUBJECT";
720 s_in.
name =
"UNANSWERED";
724 s_in.
name =
"UNKEYWORD";
737 s_in.
name =
"HEADER";
759 s_in.
name =
"LARGER";
812 s_in.
name =
"SENTBEFORE";
824 s_in.
name =
"SENTON";
837 s_in.
name =
"SENTSINCE";
849 s_in.
name =
"SMALLER";
871 s_in.
name =
"UNDRAFT";
std::vector< BincImapParserSearchKey > children
const SequenceSet & getSet(void) const
virtual Mailbox * getSelected(void) const
unsigned int getSqnr() const
virtual unsigned int getMaxSqnr(void) const =0
virtual iterator begin(const SequenceSet &bset, unsigned int mod=INCLUDE_EXPUNGED|SQNR_MODE) const =0
virtual iterator end(void) const =0
virtual unsigned int getMaxUid(void) const =0
The Message class provides an interface for IMAP messages.
virtual time_t getInternalDate(void) const =0
virtual bool textContains(const std::string &text)=0
virtual void close(void)=0
virtual unsigned int getUID(void) const =0
virtual unsigned int getSize(bool render=false) const =0
virtual bool bodyContains(const std::string &text)=0
virtual const std::string & getHeader(const std::string &header)=0
virtual unsigned char getStdFlags(void) const =0
virtual bool headerContains(const std::string &header, const std::string &text)=0
void setCharSet(const std::string &s_in)
void setName(const std::string &s_in)
bool getUidMode(void) const
const std::string & getCharSet(void) const
BincImapParserSearchKey searchkey
bool match(Mailbox *, Message *, unsigned seqnr, unsigned int lastmessage, unsigned int lastuid) const
int getWeight(void) const
static bool convertDate(const std::string &date, time_t &t, const std::string &delim="-")
static bool convertDateHeader(const std::string &d_in, time_t &t)
void init(const BincImapParserSearchKey &a)
virtual ParseResult parse(Request &) const
ProcessResult process(Depot &, Request &)
ParseResult expectSearchKey(BincImapParserSearchKey &s_in) const
const std::string getName(void) const
static SequenceSet & all(void)
void setLastError(const std::string &error) const
void setResponseCode(const std::string &error) const
static Session & getInstance(void)
Declaration of miscellaneous convertion functions.
Declaration of the common items for parsing IMAP input.
Declaration of the IODevice class.
Declaration of the IOFactory class.
Declaration of the Mailbox class (Mailbox is logical container)
Declaration of main mime parser components.
Operator::ParseResult expectNumber(unsigned int &i_in)
Operator::ParseResult expectAstring(std::string &s_in)
Operator::ParseResult expectSPACE(void)
Operator::ParseResult expectThisString(const std::string &s_in)
Operator::ParseResult expectAtom(std::string &s_in)
int atoi(const std::string &s_in)
void split(const std::string &s_in, const std::string &delim, std::vector< std::string > &dest, bool skipempty=true)
void uppercase(std::string &input)
void lowercase(std::string &input)
void trim(std::string &s_in, const std::string &chars=" \t\r\n")
Operator::ParseResult expectDate(std::string &s_in)
Operator::ParseResult expectSet(SequenceSet &s_in)
Operator::ParseResult expectCRLF(void)
Declaration of all operators.
Declaration of a recursive descent IMAP command parser.