Bincimap 2.0.16
Easy Imapping
Loading...
Searching...
No Matches
imapparser.cc
Go to the documentation of this file.
1
7#include "imapparser.h"
8#include "convert.h"
9
10#include <stdio.h>
11#include <map>
12#include <iostream>
13#include <vector>
14#include <string>
15#include <exception>
16
17using namespace ::std;
18using namespace Binc;
19
20//------------------------------------------------------------------------
22 : extra(0), flags(), statuses(), bset(), searchkey(), fatt()
23{
24 uidmode = false;
25}
26
28{
29 if (extra != 0)
30 delete extra;
31}
32
33//------------------------------------------------------------------------
35{
36 uidmode = true;
37}
38
39//------------------------------------------------------------------------
40bool Request::getUidMode(void) const
41{
42 return uidmode;
43}
44
45//------------------------------------------------------------------------
46void Request::setTag(string &t_in)
47{
48 tag = t_in;
49}
50
51//------------------------------------------------------------------------
52const string &Request::getTag(void) const
53{
54 return tag;
55}
56
57//------------------------------------------------------------------------
58void Request::setMode(const string &m_in)
59{
60 mode = m_in;
61}
62
63//------------------------------------------------------------------------
64const string &Request::getMode(void) const
65{
66 return mode;
67}
68
69//------------------------------------------------------------------------
70void Request::setName(const string &s_in)
71{
72 name = s_in;
73}
74
75//------------------------------------------------------------------------
76const string &Request::getName(void) const
77{
78 return name;
79}
80
81//------------------------------------------------------------------------
82void Request::setAuthType(const string &s_in)
83{
84 authtype = s_in;
85}
86
87//------------------------------------------------------------------------
88const string &Request::getAuthType(void) const
89{
90 return authtype;
91}
92
93//------------------------------------------------------------------------
94void Request::setLiteral(const string &s_in)
95{
96 literal = s_in;
97}
98
99//------------------------------------------------------------------------
100const string &Request::getLiteral(void) const
101{
102 return literal;
103}
104
105//------------------------------------------------------------------------
106void Request::setDate(const string &s_in)
107{
108 date = s_in;
109}
110
111//------------------------------------------------------------------------
112const string &Request::getDate(void) const
113{
114 return date;
115}
116
117//------------------------------------------------------------------------
118void Request::setCharSet(const string &s_in)
119{
120 charset = s_in;
121 uppercase(charset);
122}
123
124//------------------------------------------------------------------------
125const string &Request::getCharSet(void) const
126{
127 return charset;
128}
129
130//------------------------------------------------------------------------
131void Request::setUserID(const string &s_in)
132{
133 userid = s_in;
134}
135
136//------------------------------------------------------------------------
137const string &Request::getUserID(void) const
138{
139 return userid;
140}
141
142//------------------------------------------------------------------------
143void Request::setPassword(const string &s_in)
144{
145 password = s_in;
146}
147
148//------------------------------------------------------------------------
149const string &Request::getPassword(void) const
150{
151 return password;
152}
153
154//------------------------------------------------------------------------
155void Request::setMailbox(const string &s_in)
156{
157 mailbox = s_in;
158}
159
160//------------------------------------------------------------------------
161const string &Request::getMailbox(void) const
162{
163 return mailbox;
164}
165
166//------------------------------------------------------------------------
167void Request::setListMailbox(const string &s_in)
168{
169 listmailbox = s_in;
170}
171
172//------------------------------------------------------------------------
173const string &Request::getListMailbox(void) const
174{
175 return listmailbox;
176}
177
178//------------------------------------------------------------------------
179void Request::setContextInfo(const string &s_in)
180{
181 contextInfo = s_in;
182}
183
184//------------------------------------------------------------------------
185const string &Request::getContextInfo(void) const
186{
187 return contextInfo;
188}
189
190//------------------------------------------------------------------------
191void Request::setNewMailbox(const string &s_in)
192{
193 newmailbox = s_in;
194}
195
196//------------------------------------------------------------------------
197const string &Request::getNewMailbox(void) const
198{
199 return newmailbox;
200}
201
202//------------------------------------------------------------------------
204{
205 return bset;
206}
207
208//------------------------------------------------------------------------
209vector<string> &Request::getStatuses(void)
210{
211 return statuses;
212}
213
214//------------------------------------------------------------------------
215vector<string> &Request::getFlags(void)
216{
217 return flags;
218}
219
220//------------------------------------------------------------------------
221SequenceSet::SequenceSet(void) : limited(true), nullSet(false)
222{
223}
224
225//------------------------------------------------------------------------
227 : limited(copy.limited), nullSet(copy.nullSet), internal(copy.internal)
228{
229}
230
231//------------------------------------------------------------------------
233{
234 limited = copy.limited;
235 nullSet = copy.nullSet;
236 internal = copy.internal;
237
238 return *this;
239}
240
241//------------------------------------------------------------------------
243{
244}
245
246//------------------------------------------------------------------------
248{
249 static SequenceSet nil;
250 nil.nullSet = true;
251 return nil;
252}
253
254//------------------------------------------------------------------------
255bool SequenceSet::isNull(void) const
256{
257 return nullSet;
258}
259
260//------------------------------------------------------------------------
262{
263 static bool initialized = false;
264 static SequenceSet all;
265
266 if (!initialized) {
267 all.addRange(1, (unsigned int)-1);
268 initialized = true;
269 }
270
271 return all;
272}
273
274//------------------------------------------------------------------------
275SequenceSet::Range::Range(unsigned int a, unsigned int b)
276{
277 if (a > b) {
278 from = b;
279 to = a;
280 } else {
281 from = a;
282 to = b;
283 }
284}
285
286//------------------------------------------------------------------------
287void SequenceSet::addRange(unsigned int a, unsigned int b)
288{
289 if (a == (unsigned int)-1 || b == (unsigned int)-1) limited = false;
290 internal.push_back(Range(a, b));
291}
292
293//------------------------------------------------------------------------
294void SequenceSet::addNumber(unsigned int a)
295{
296 if (a == (unsigned int)-1) limited = false;
297 internal.push_back(Range(a, a));
298}
299
300//------------------------------------------------------------------------
301bool SequenceSet::isInSet(unsigned int n) const
302{
303 unsigned int maxvalue = 0;
304 for (vector<Range>::const_iterator i = internal.begin();
305 i != internal.end(); ++i) {
306 const Range &r = *i;
307 if (r.from > maxvalue) maxvalue = r.from;
308 else if (r.to > maxvalue) maxvalue = r.to;
309
310 if (n >= (*i).from && n <= (*i).to) {
311 return true;
312 }
313 }
314
315 return (n > maxvalue && !limited);
316}
317
318//------------------------------------------------------------------------
320 : type(typeName)
321{
322 offsetstart = 0;
323 offsetlength = (unsigned int) -1;
324 hassection = false;
325}
326
327//------------------------------------------------------------------------
329{
330 string tmp;
331 if (type == "BODY.PEEK")
332 tmp = "BODY";
333 else
334 tmp = type;
335
336 if (type == "BODY" || type == "BODY.PEEK") {
337 if (hassection) {
338 tmp += "[";
339 tmp += section;
340 if (sectiontext != "") {
341 if (section != "")
342 tmp += ".";
343 tmp += sectiontext;
344
345 if (headerlist.size() > 0) {
346 tmp += " (";
347 for (vector<string>::iterator i = headerlist.begin();
348 i != headerlist.end(); ++i) {
349 if (i != headerlist.begin())
350 tmp += " ";
351 tmp += Binc::toImapString(*i);
352 }
353 tmp += ")";
354 }
355 }
356 tmp += "]";
357
358 if (offsetstart == 0 && offsetlength == (unsigned int) -1)
359 tmp += " ";
360 else
361 tmp += "<" + Binc::toString(offsetstart) + "> ";
362 }
363 }
364
365 return tmp;
366}
367
368//------------------------------------------------------------------------
370{
371 type = 0;
372 number = 0;
373}
374
375//------------------------------------------------------------------------
377{
378 return bset;
379}
std::vector< std::string > headerlist
Definition: imapparser.h:57
BincImapParserFetchAtt(const std::string &typeName="")
Definition: imapparser.cc:319
std::string toString(void)
Definition: imapparser.cc:328
const SequenceSet & getSet(void) const
Definition: imapparser.cc:376
const std::string & getTag(void) const
Definition: imapparser.cc:52
const std::string & getDate(void) const
Definition: imapparser.cc:112
const std::string & getName(void) const
Definition: imapparser.cc:76
void setNewMailbox(const std::string &s_in)
Definition: imapparser.cc:191
void setCharSet(const std::string &s_in)
Definition: imapparser.cc:118
void setDate(const std::string &s_in)
Definition: imapparser.cc:106
void setMailbox(const std::string &s_in)
Definition: imapparser.cc:155
void setTag(std::string &t_in)
Definition: imapparser.cc:46
std::vector< std::string > & getFlags(void)
Definition: imapparser.cc:215
const std::string & getUserID(void) const
Definition: imapparser.cc:137
void setPassword(const std::string &s_in)
Definition: imapparser.cc:143
const std::string & getMode(void) const
Definition: imapparser.cc:64
SequenceSet bset
Definition: imapparser.h:115
void setName(const std::string &s_in)
Definition: imapparser.cc:70
void setUidMode(void)
Definition: imapparser.cc:34
~Request(void)
Definition: imapparser.cc:27
void setLiteral(const std::string &s_in)
Definition: imapparser.cc:94
const std::string & getListMailbox(void) const
Definition: imapparser.cc:173
const std::string & getMailbox(void) const
Definition: imapparser.cc:161
void setMode(const std::string &m_in)
Definition: imapparser.cc:58
const std::string & getPassword(void) const
Definition: imapparser.cc:149
void setUserID(const std::string &s_in)
Definition: imapparser.cc:131
std::vector< std::string > flags
Definition: imapparser.h:112
BincImapParserData * extra
Definition: imapparser.h:111
bool getUidMode(void) const
Definition: imapparser.cc:40
const std::string & getContextInfo(void) const
Definition: imapparser.cc:185
std::vector< std::string > statuses
Definition: imapparser.h:113
void setContextInfo(const std::string &s_in)
Definition: imapparser.cc:179
void setAuthType(const std::string &s_in)
Definition: imapparser.cc:82
std::vector< std::string > & getStatuses(void)
Definition: imapparser.cc:209
void setListMailbox(const std::string &s_in)
Definition: imapparser.cc:167
SequenceSet & getSet(void)
Definition: imapparser.cc:203
const std::string & getNewMailbox(void) const
Definition: imapparser.cc:197
const std::string & getAuthType(void) const
Definition: imapparser.cc:88
const std::string & getLiteral(void) const
Definition: imapparser.cc:100
const std::string & getCharSet(void) const
Definition: imapparser.cc:125
static SequenceSet & all(void)
Definition: imapparser.cc:261
SequenceSet & operator=(const SequenceSet &copy)
Definition: imapparser.cc:232
void addRange(unsigned int a_in, unsigned int b_in)
Definition: imapparser.cc:287
bool isNull(void) const
Definition: imapparser.cc:255
bool isInSet(unsigned int n) const
Definition: imapparser.cc:301
void addNumber(unsigned int a_in)
Definition: imapparser.cc:294
static SequenceSet & null(void)
Definition: imapparser.cc:247
Declaration of miscellaneous convertion functions.
Declaration of the common items for parsing IMAP input.
Definition: bincimapd.cc:9
std::string toImapString(const std::string &s_in)
Definition: convert.h:103
std::string toString(int i_in)
Definition: convert.h:25
void uppercase(std::string &input)
Definition: convert.h:115