Bincimap 2.0.16
Easy Imapping
Loading...
Searching...
No Matches
operator-status.cc
Go to the documentation of this file.
1
7#include <string>
8#include <iostream>
9
10#include <dirent.h>
11#include <sys/stat.h>
12#include <sys/types.h>
13
14#include "convert.h"
15#include "depot.h"
16#include "iodevice.h"
17#include "iofactory.h"
18#include "mailbox.h"
19#include "operators.h"
20#include "recursivedescent.h"
21#include "session.h"
22#include "status.h"
23
24using namespace ::std;
25using namespace Binc;
26
27//----------------------------------------------------------------------
29{
30}
31
32//----------------------------------------------------------------------
34{
35}
36
37//----------------------------------------------------------------------
38const string StatusOperator::getName(void) const
39{
40 return "STATUS";
41}
42
43//----------------------------------------------------------------------
45{
47}
48
49//------------------------------------------------------------------------
51 Request &command)
52{
53 Session &session = Session::getInstance();
54
55 Status status;
56 if (!depot.getStatus(command.getMailbox(), status)) {
57 session.setLastError(depot.getLastError());
58 return NO;
59 }
60
61 bincClient << "* STATUS " << toImapString(command.getMailbox()) << " (";
62
63 string prefix;
64 for (vector<string>::const_iterator i = command.statuses.begin();
65 i != command.statuses.end(); ++i) {
66 string tmp = *i;
67 uppercase(tmp);
68 if (tmp == "UIDNEXT") {
69 bincClient << prefix << "UIDNEXT " << status.getUidNext();
70 prefix = " ";
71 } else if (tmp == "MESSAGES") {
72 bincClient << prefix << "MESSAGES " << status.getMessages();
73 prefix = " ";
74 } else if (tmp == "RECENT") {
75 bincClient << prefix << "RECENT " << status.getRecent();
76 prefix = " ";
77 } else if (tmp == "UIDVALIDITY") {
78 bincClient << prefix << "UIDVALIDITY " << status.getUidValidity();
79 prefix = " ";
80 } else if (tmp == "UNSEEN") {
81 bincClient << prefix << "UNSEEN " << status.getUnseen();
82 prefix = " ";
83 }
84 }
85 bincClient << ")" << endl;
86
87 return OK;
88}
89
90//----------------------------------------------------------------------
92{
93 Session &session = Session::getInstance();
94
95 if (c_in.getUidMode())
96 return REJECT;
97
99 if ((res = expectSPACE()) != ACCEPT) {
100 session.setLastError("Expected SPACE");
101 return res;
102 }
103
104 string mailbox;
105 if ((res = expectMailbox(mailbox)) != ACCEPT) {
106 session.setLastError("Expected mailbox");
107 return res;
108 }
109
110 c_in.setMailbox(mailbox);
111
112 if ((res = expectSPACE()) != ACCEPT) {
113 session.setLastError("Expected SPACE");
114 return res;
115 }
116
117 if ((res = expectThisString("(")) != ACCEPT) {
118 session.setLastError("Expected (");
119 return res;
120 }
121
122 while (1) {
123 if ((res = expectThisString("MESSAGES")) == ACCEPT)
124 c_in.getStatuses().push_back("MESSAGES");
125 else if ((res = expectThisString("RECENT")) == ACCEPT)
126 c_in.getStatuses().push_back("RECENT");
127 else if ((res = expectThisString("UIDNEXT")) == ACCEPT)
128 c_in.getStatuses().push_back("UIDNEXT");
129 else if ((res = expectThisString("UIDVALIDITY")) == ACCEPT)
130 c_in.getStatuses().push_back("UIDVALIDITY");
131 else if ((res = expectThisString("UNSEEN")) == ACCEPT)
132 c_in.getStatuses().push_back("UNSEEN");
133 else {
134 session.setLastError("Expected status_att");
135 return res;
136 }
137
138 if (expectSPACE() != ACCEPT) break;
139 }
140
141 if ((res = expectThisString(")")) != ACCEPT) {
142 session.setLastError("Expected )");
143 return res;
144 }
145
146 if ((res = expectCRLF()) != ACCEPT) {
147 session.setLastError("Expected CRLF");
148 return ERROR;
149 }
150
151 return ACCEPT;
152}
const std::string & getLastError(void) const
Definition: depot.cc:85
bool getStatus(const std::string &s_in, Status &dest) const
Definition: depot.cc:295
void setMailbox(const std::string &s_in)
Definition: imapparser.cc:155
const std::string & getMailbox(void) const
Definition: imapparser.cc:161
bool getUidMode(void) const
Definition: imapparser.cc:40
std::vector< std::string > statuses
Definition: imapparser.h:113
std::vector< std::string > & getStatuses(void)
Definition: imapparser.cc:209
void setLastError(const std::string &error) const
Definition: session.cc:185
@ AUTHENTICATED
Definition: session.h:37
static Session & getInstance(void)
Definition: session.cc:33
int getUidValidity(void) const
Definition: status.h:40
int getUidNext(void) const
Definition: status.h:41
int getUnseen(void) const
Definition: status.h:39
int getMessages(void) const
Definition: status.h:36
int getRecent(void) const
Definition: status.h:37
virtual ParseResult parse(Request &) const
int getState(void) const
ProcessResult process(Depot &, Request &)
const std::string getName(void) const
Declaration of miscellaneous convertion functions.
Declaration of the IODevice class.
Declaration of the IOFactory class.
#define bincClient
Definition: iofactory.h:31
Declaration of the Mailbox class (Mailbox is logical container)
Definition: bincimapd.cc:9
std::string toImapString(const std::string &s_in)
Definition: convert.h:103
Operator::ParseResult expectSPACE(void)
Operator::ParseResult expectThisString(const std::string &s_in)
void uppercase(std::string &input)
Definition: convert.h:115
Operator::ParseResult expectCRLF(void)
Operator::ParseResult expectMailbox(std::string &s_in)
Declaration of all operators.
Declaration of a recursive descent IMAP command parser.
Declaration of the Status class.