Bincimap 2.0.16
Easy Imapping
Loading...
Searching...
No Matches
operator-store.cc
Go to the documentation of this file.
1
7#include <string>
8#include <iostream>
9
10#include "depot.h"
11#include "imapparser.h"
12#include "mailbox.h"
13#include "operators.h"
14#include "pendingupdates.h"
15#include "recursivedescent.h"
16#include "session.h"
17
18using namespace ::std;
19using namespace Binc;
20
21//----------------------------------------------------------------------
23{
24}
25
26//----------------------------------------------------------------------
28{
29}
30
31//----------------------------------------------------------------------
32const string StoreOperator::getName(void) const
33{
34 return "STORE";
35}
36
37//----------------------------------------------------------------------
39{
40 return Session::SELECTED;
41}
42
43//------------------------------------------------------------------------
45 Request &command)
46{
47 Mailbox *mailbox = depot.getSelected();
48
49 // mask all passed flags together
50 unsigned int newflags = (unsigned int) Message::F_NONE;
51 vector<string> newCustomFlags;
52 vector<string>::const_iterator f_i = command.flags.begin();
53 while (f_i != command.flags.end()) {
54 if (*f_i == "\\Deleted") newflags |= Message::F_DELETED;
55 else if (*f_i == "\\Answered") newflags |= Message::F_ANSWERED;
56 else if (*f_i == "\\Seen") newflags |= Message::F_SEEN;
57 else if (*f_i == "\\Draft") newflags |= Message::F_DRAFT;
58 else if (*f_i == "\\Flagged") newflags |= Message::F_FLAGGED;
59 else newCustomFlags.push_back(*f_i);
60
61 ++f_i;
62 }
63
64 // pass through all messages
65 unsigned int mode
67
69 = mailbox->begin(command.bset, Mailbox::SKIP_EXPUNGED | mode);
70
71 for (; i != mailbox->end(); ++i) {
72 Message &message = *i;
73
74 // get and reset the old flags
75 unsigned int flags = (unsigned int) message.getStdFlags();
76
77 bool recent = (flags & Message::F_RECENT) != 0;
78 flags &= (~Message::F_RECENT);
79
80 // add, remove or set flags
81 switch (command.getMode()[0]) {
82 case '+':
83 flags |= newflags;
84 for (vector<string>::const_iterator it = newCustomFlags.begin();
85 it != newCustomFlags.end(); ++it)
86 message.setCustomFlag(*it);
87 break;
88 case '-':
89 flags &= ~newflags;
90 for (vector<string>::const_iterator it = newCustomFlags.begin();
91 it != newCustomFlags.end(); ++it)
92 message.removeCustomFlag(*it);
93 break;
94 default:
95 flags = newflags;
96 message.resetCustomFlags();
97 for (vector<string>::const_iterator it = newCustomFlags.begin();
98 it != newCustomFlags.end(); ++it)
99 message.setCustomFlag(*it);
100 break;
101 };
102
103 // set new flags, even if they weren't changed.
104 if (recent) flags |= Message::F_RECENT;
105 message.resetStdFlags();
106 message.setStdFlag(flags);
107 }
108
109 // commit flag changes to mailbox (might change mailbox)
110 mailbox->updateFlags();
111
112 // check mailbox for updates, and report them
113 if (command.getMode().find(".SILENT") != string::npos)
115 | PendingUpdates::RECENT, false, false, false,
116 command.getUidMode());
117 else
121 | PendingUpdates::FLAGS, false, false, false,
122 command.getUidMode());
123
124 return OK;
125}
126
127//----------------------------------------------------------------------
129{
130 Session &session = Session::getInstance();
131
133 if ((res = expectSPACE()) != ACCEPT) {
134 session.setLastError("Expected SPACE");
135 return res;
136 }
137
138 if ((res = expectSet(c_in.getSet())) != ACCEPT) {
139 session.setLastError("Expected Set");
140 return res;
141 }
142
143 if ((res = expectSPACE()) != ACCEPT) {
144 session.setLastError("Expected SPACE");
145 return res;
146 }
147
148 string mode;
149 if ((res = expectThisString("+")) == ACCEPT)
150 mode = "+";
151 else if ((res = expectThisString("-")) == ACCEPT)
152 mode = "-";
153
154 if ((res = expectThisString("FLAGS")) != ACCEPT) {
155 session.setLastError("Expected FLAGS");
156 return res;
157 } else
158 mode += "FLAGS";
159
160 if ((res = expectThisString(".SILENT")) == ACCEPT) mode += ".SILENT";
161
162 c_in.setMode(mode);
163
164 if ((res = expectSPACE()) != ACCEPT) {
165 session.setLastError("Expected SPACE");
166 return res;
167 }
168
169 bool paren = false;
170 if ((res = expectThisString("(")) == ACCEPT) paren = true;
171
172 if ((res = expectFlag(c_in.getFlags())) == ACCEPT)
173 while (1) {
174 if ((res = expectSPACE()) != ACCEPT) break;
175
176 if ((res = expectFlag(c_in.getFlags())) != ACCEPT) {
177 session.setLastError("Expected flag after SPACE");
178 return res;
179 }
180 }
181
182 if (paren)
183 if ((res = expectThisString(")")) != ACCEPT) {
184 session.setLastError("Expected )");
185 return res;
186 }
187
188 if ((res = expectCRLF()) != ACCEPT) {
189 session.setLastError("Expected CRLF");
190 return res;
191 }
192
193 return ACCEPT;
194}
virtual Mailbox * getSelected(void) const
Definition: depot.cc:183
virtual void updateFlags(void)=0
virtual iterator begin(const SequenceSet &bset, unsigned int mod=INCLUDE_EXPUNGED|SQNR_MODE) const =0
virtual iterator end(void) const =0
@ SKIP_EXPUNGED
Definition: mailbox.h:69
The Message class provides an interface for IMAP messages.
Definition: message.h:31
virtual void setCustomFlag(const std::string &flag)=0
virtual void resetStdFlags(void)=0
virtual void setStdFlag(unsigned char)=0
virtual unsigned char getStdFlags(void) const =0
virtual void resetCustomFlags(void)=0
virtual void removeCustomFlag(const std::string &flag)=0
std::vector< std::string > & getFlags(void)
Definition: imapparser.cc:215
const std::string & getMode(void) const
Definition: imapparser.cc:64
SequenceSet bset
Definition: imapparser.h:115
void setMode(const std::string &m_in)
Definition: imapparser.cc:58
std::vector< std::string > flags
Definition: imapparser.h:112
bool getUidMode(void) const
Definition: imapparser.cc:40
SequenceSet & getSet(void)
Definition: imapparser.cc:203
void setLastError(const std::string &error) const
Definition: session.cc:185
static Session & getInstance(void)
Definition: session.cc:33
virtual ParseResult parse(Request &) const
int getState(void) const
ProcessResult process(Depot &, Request &)
const std::string getName(void) const
Declaration of the common items for parsing IMAP input.
Declaration of the Mailbox class (Mailbox is logical container)
Definition: bincimapd.cc:9
Operator::ParseResult expectFlag(std::vector< std::string > &v_in)
Operator::ParseResult expectSPACE(void)
Operator::ParseResult expectThisString(const std::string &s_in)
bool pendingUpdates(Mailbox *, int type, bool rescan, bool showAll=false, bool forceScan=false, bool uidfetchflags=false)
Operator::ParseResult expectSet(SequenceSet &s_in)
Operator::ParseResult expectCRLF(void)
Declaration of all operators.
Declaration of a recursive descent IMAP command parser.