Bincimap 2.0.16
Easy Imapping
Loading...
Searching...
No Matches
operator-select.cc
Go to the documentation of this file.
1
7#include <string>
8
9#include "depot.h"
10#include "iodevice.h"
11#include "iofactory.h"
12#include "mailbox.h"
13#include "operators.h"
14#include "recursivedescent.h"
15#include "pendingupdates.h"
16#include "session.h"
17#include "convert.h"
18
19using namespace ::std;
20using namespace Binc;
21
22//----------------------------------------------------------------------
24{
25}
26
27//----------------------------------------------------------------------
29{
30}
31
32//----------------------------------------------------------------------
33const string SelectOperator::getName(void) const
34{
35 return "SELECT";
36}
37
38//----------------------------------------------------------------------
40{
44}
45
46//------------------------------------------------------------------------
48 Request &command)
49{
50 Session &session = Session::getInstance();
51
52 const bool examine = (command.getName() == "EXAMINE");
53 const string &srcmailbox = command.getMailbox();
54 const string &canonmailbox = toCanonMailbox(srcmailbox);
55
56 Mailbox *mailbox = depot.getSelected();
57 if (mailbox != 0) {
58 mailbox->closeMailbox();
59 depot.resetSelected();
60 mailbox = 0;
61 }
62
63 mailbox = depot.get(canonmailbox);
64 if (mailbox == 0) {
65 session.setLastError(depot.getLastError());
66 return NO;
67 }
68
69 mailbox->setReadOnly(examine);
70
71 if (!mailbox->selectMailbox(canonmailbox,
72 depot.mailboxToFilename(canonmailbox))) {
73 bincWarning << "selecting mailbox failed: "
74 << mailbox->getLastError() << endl;
75 session.setLastError(mailbox->getLastError());
76 return NO;
77 }
78
79 // find first unseen
80 int unseen = -1;
83 for (; i != mailbox->end(); ++i) {
84 Message &message = *i;
85
86 if (unseen == -1 && ((message.getStdFlags() & Message::F_SEEN) == 0)) {
87 unseen = i.getSqnr();
88 break;
89 }
90 }
91
92 // show pending updates with only exists and recent response. do not
93 // re-scan.
95 | PendingUpdates::RECENT, false, true);
96
97 // unseen
98 if (unseen != -1)
99 bincClient << "*" << " OK [UNSEEN " << unseen << "] Message "
100 << unseen << " is first unseen" << endl;
101
102 // uidvalidity
103 bincClient << "*" << " OK [UIDVALIDITY " << mailbox->getUidValidity() << "]"
104 << endl;
105
106 // uidnext
107 bincClient << "*" << " OK [UIDNEXT " << toString(mailbox->getUidNext()) << "] "
108 << toString(mailbox->getUidNext()) << " is the next UID" << endl;
109
110 // flags
111 bincClient << "*"
112 << " FLAGS (\\Answered \\Flagged \\Deleted \\Recent \\Seen \\Draft \\*)"
113 << endl;
114
115 // permanentflags
116 bincClient << "*"
117 << " OK [PERMANENTFLAGS (\\Answered \\Flagged \\Deleted "
118 << "\\Seen \\Draft \\*)] Limited"
119 << endl;
120
122 depot.setSelected(mailbox);
123
124 session.setResponseCode(examine ? "READ-ONLY" : "READ-WRITE");
125 return OK;
126}
127
128//----------------------------------------------------------------------
130{
131 Session &session = Session::getInstance();
132
133 if (c_in.getUidMode())
134 return REJECT;
135
137 if ((res = expectSPACE()) != ACCEPT) {
138 session.setLastError("Expected SPACE after" + c_in.getName());
139 return res;
140 }
141
142 string mailbox;
143 if ((res = expectMailbox(mailbox)) != ACCEPT) {
144 session.setLastError("Expected mailbox after " + c_in.getName()
145 + " SPACE");
146 return res;
147 }
148
149 if ((res = expectCRLF()) != ACCEPT) {
150 session.setLastError("Expected CRLF after " + c_in.getName()
151 + " SPACE mailbox");
152 return res;
153 }
154
155 c_in.setMailbox(mailbox);
156
157 return ACCEPT;
158}
virtual Mailbox * get(const std::string &path) const
Definition: depot.cc:107
void resetSelected(void)
Definition: depot.cc:189
virtual bool setSelected(Mailbox *)
Definition: depot.cc:119
const std::string & getLastError(void) const
Definition: depot.cc:85
virtual std::string mailboxToFilename(const std::string &m) const =0
virtual Mailbox * getSelected(void) const
Definition: depot.cc:183
unsigned int getSqnr() const
Definition: mailbox.cc:85
virtual bool selectMailbox(const std::string &name, const std::string &s_in)=0
const std::string & getLastError(void) const
Definition: mailbox.cc:103
virtual void closeMailbox(void)=0
virtual iterator begin(const SequenceSet &bset, unsigned int mod=INCLUDE_EXPUNGED|SQNR_MODE) const =0
virtual unsigned int getUidValidity(void) const =0
virtual iterator end(void) const =0
@ SKIP_EXPUNGED
Definition: mailbox.h:69
virtual unsigned int getUidNext(void) const =0
void setReadOnly(bool readOnly)
Definition: mailbox.cc:43
The Message class provides an interface for IMAP messages.
Definition: message.h:31
virtual unsigned char getStdFlags(void) const =0
const std::string & getName(void) const
Definition: imapparser.cc:76
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
virtual ParseResult parse(Request &) const
int getState(void) const
ProcessResult process(Depot &, Request &)
const std::string getName(void) const
static SequenceSet & all(void)
Definition: imapparser.cc:261
void setLastError(const std::string &error) const
Definition: session.cc:185
void setState(int n)
Definition: session.cc:46
@ NONAUTHENTICATED
Definition: session.h:36
@ AUTHENTICATED
Definition: session.h:37
void setResponseCode(const std::string &error) const
Definition: session.cc:197
static Session & getInstance(void)
Definition: session.cc:33
Declaration of miscellaneous convertion functions.
Declaration of the IODevice class.
Declaration of the IOFactory class.
#define bincWarning
Definition: iofactory.h:44
#define bincClient
Definition: iofactory.h:31
Declaration of the Mailbox class (Mailbox is logical container)
Definition: bincimapd.cc:9
std::string toString(int i_in)
Definition: convert.h:25
Operator::ParseResult expectSPACE(void)
std::string toCanonMailbox(const std::string &s_in)
Definition: convert.h:216
bool pendingUpdates(Mailbox *, int type, bool rescan, bool showAll=false, bool forceScan=false, bool uidfetchflags=false)
Operator::ParseResult expectCRLF(void)
Operator::ParseResult expectMailbox(std::string &s_in)
Declaration of all operators.
Declaration of a recursive descent IMAP command parser.