Bincimap 2.0.16
Easy Imapping
Loading...
Searching...
No Matches
pendingupdates.cc
Go to the documentation of this file.
1
7#include <iostream>
8#include <string>
9#include <vector>
10
11#include "iodevice.h"
12#include "iofactory.h"
13#include "mailbox.h"
14#include "message.h"
15#include "pendingupdates.h"
16#include "session.h"
17
18using namespace ::std;
19using namespace Binc;
20
21//------------------------------------------------------------------------
22PendingUpdates::PendingUpdates(void) : expunges(), flagupdates()
23{
24 recent = 0;
25 exists = 0;
26
27 newrecent = false;
28 newexists = false;
29}
30
31//------------------------------------------------------------------------
33{
34}
35
36//------------------------------------------------------------------------
37void PendingUpdates::addExpunged(unsigned int uid)
38{
39 expunges.push_back(uid);
40}
41
42//------------------------------------------------------------------------
43void PendingUpdates::addFlagUpdates(unsigned int sqnr, unsigned int uid,
44 unsigned int flags, const vector<string> &cflags)
45{
46 flagupdates[sqnr] = flags;
47 sqnrtouid[sqnr] = uid;
48 sqnrtocflags[sqnr] = cflags;
49}
50
51//------------------------------------------------------------------------
52void PendingUpdates::setExists(unsigned int n)
53{
54 exists = n;
55 newexists = true;
56}
57
58//------------------------------------------------------------------------
59void PendingUpdates::setRecent(unsigned int n)
60{
61 recent = n;
62 newrecent = true;
63}
64
65//------------------------------------------------------------------------
66unsigned int PendingUpdates::getExists(void) const
67{
68 return exists;
69}
70
71//------------------------------------------------------------------------
72unsigned int PendingUpdates::getRecent(void) const
73{
74 return recent;
75}
76
77//------------------------------------------------------------------------
79{
80 return newexists;
81}
82
83//------------------------------------------------------------------------
85{
86 return newrecent;
87}
88
89//------------------------------------------------------------------------
91{
92}
93
94//------------------------------------------------------------------------
95PendingUpdates::expunged_const_iterator::expunged_const_iterator(vector<unsigned int>::iterator i) : internal(i)
96{
97}
98
99//------------------------------------------------------------------------
101{
102 return *internal;
103}
104
105//------------------------------------------------------------------------
107{
108 ++internal;
109}
110
111//------------------------------------------------------------------------
113{
114 return internal == i.internal;
115}
116
117//------------------------------------------------------------------------
119{
120 return internal != i.internal;
121}
122
123//------------------------------------------------------------------------
125{
126 return expunged_const_iterator(expunges.begin());
127}
128
129//------------------------------------------------------------------------
131{
132 return expunged_const_iterator(expunges.end());
133}
134
135//------------------------------------------------------------------------
137{
138}
139
140//------------------------------------------------------------------------
142 map<unsigned int, unsigned int>::iterator i,
143 map<unsigned int, vector<string> > *j,
144 map<unsigned int, unsigned int> *sqnrmap) : internal(i), sqnrtocflags(j)
145{
146 sqnrtouid = sqnrmap;
147}
148
149//------------------------------------------------------------------------
151{
152 ++internal;
153}
154
155//------------------------------------------------------------------------
157{
158 return internal != i.internal;
159}
160
161//------------------------------------------------------------------------
163{
164 return flagupdates_const_iterator(flagupdates.begin(), &sqnrtocflags, &sqnrtouid);
165}
166
167//------------------------------------------------------------------------
169{
170 return flagupdates_const_iterator(flagupdates.end(), &sqnrtocflags, &sqnrtouid);
171}
172
173//------------------------------------------------------------------------
175{
176 return internal->first;
177}
178
179//------------------------------------------------------------------------
181{
182 return internal->second;
183}
184
185//------------------------------------------------------------------------
187{
188 return (*sqnrtocflags)[internal->first];
189}
190
191//------------------------------------------------------------------------
193{
194 return (*sqnrtouid)[internal->first];
195}
196
197//--------------------------------------------------------------------
198bool Binc::pendingUpdates(Mailbox *mailbox, int type, bool rescan, bool showAll,
199 bool forceScan, bool uidfetchflags)
200{
201 Session &session = Session::getInstance();
202
203 if (mailbox == 0)
204 return true;
205
207 if (!mailbox->getUpdates(rescan, type, p, forceScan)) {
208 session.setLastError(mailbox->getLastError());
209 return false;
210 }
211
212 if (type & PendingUpdates::EXPUNGE) {
215
216 while (i != e) {
217 bincClient << "* " << *i << " EXPUNGE" << endl;
218 ++i;
219 }
220 }
221
222 if (((type & PendingUpdates::EXISTS) && p.newExists()) || showAll)
223 bincClient << "* " << p.getExists() << " EXISTS" << endl;
224
225 if (((type & PendingUpdates::RECENT) && p.newRecent() || showAll))
226 bincClient << "* " << p.getRecent() << " RECENT" << endl;
227
228 if (type & PendingUpdates::FLAGS) {
231
232 while (i != e) {
233 int flags = i.second();
234
235 vector<string> flagv;
236 if (flags & Message::F_SEEN) flagv.push_back("\\Seen");
237 if (flags & Message::F_ANSWERED) flagv.push_back("\\Answered");
238 if (flags & Message::F_DELETED) flagv.push_back("\\Deleted");
239 if (flags & Message::F_DRAFT) flagv.push_back("\\Draft");
240 if (flags & Message::F_RECENT) flagv.push_back("\\Recent");
241 if (flags & Message::F_FLAGGED) flagv.push_back("\\Flagged");
242
243 bincClient << "* " << i.first() << " FETCH (FLAGS (";
244 for (vector<string>::const_iterator k
245 = flagv.begin(); k != flagv.end(); ++k) {
246 if (k != flagv.begin()) bincClient << " ";
247 bincClient << *k;
248 }
249
250 vector<string> customFlags = i.getCustomFlags();
251 for (vector<string>::const_iterator it = customFlags.begin();
252 it != customFlags.end(); ++it) {
253 if (flagv.size() > 0 || it != customFlags.begin()) bincClient << " ";
254 bincClient << *it;
255 }
256
257 bincClient << ")";
258 if (uidfetchflags) bincClient << " UID " << i.getUID();
259 bincClient << ")" << endl;
260 ++i;
261 }
262 }
263
264 return true;
265}
const std::string & getLastError(void) const
Definition: mailbox.cc:103
virtual bool getUpdates(bool scan, unsigned int type, PendingUpdates &updates, bool forceScan)=0
bool operator!=(expunged_const_iterator) const
bool operator==(expunged_const_iterator) const
std::vector< std::string > getCustomFlags(void) const
bool operator!=(flagupdates_const_iterator) const
expunged_const_iterator beginExpunged(void)
bool newRecent(void) const
void addFlagUpdates(unsigned int sqnr, unsigned int uid, unsigned int flags, const std::vector< std::string > &cflags)
unsigned int getExists(void) const
flagupdates_const_iterator endFlagUpdates(void)
bool newExists(void) const
void setExists(unsigned int n)
void addExpunged(unsigned int uid)
unsigned int getRecent(void) const
void setRecent(unsigned int n)
flagupdates_const_iterator beginFlagUpdates(void)
expunged_const_iterator endExpunged(void)
void setLastError(const std::string &error) const
Definition: session.cc:185
static Session & getInstance(void)
Definition: session.cc:33
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)
Declaration of the Message class.
Definition: bincimapd.cc:9
bool pendingUpdates(Mailbox *, int type, bool rescan, bool showAll=false, bool forceScan=false, bool uidfetchflags=false)