author | sandman <sandman> | 2002-08-06 00:55:56 (UTC) |
---|---|---|
committer | sandman <sandman> | 2002-08-06 00:55:56 (UTC) |
commit | b980135ff5ce5447ca41411b6ace74ce2803fadb (patch) (unidiff) | |
tree | c02cdd16e1435855bff16e2c2707f5d5484d43f4 /noncore/unsupported/mail2/libmail/imapresponse.cpp | |
parent | d96244956f42782f987acc2b5efb32dc1f1dd70a (diff) | |
download | opie-b980135ff5ce5447ca41411b6ace74ce2803fadb.zip opie-b980135ff5ce5447ca41411b6ace74ce2803fadb.tar.gz opie-b980135ff5ce5447ca41411b6ace74ce2803fadb.tar.bz2 |
mail2 should display (most) mails now with these workarounds. imap handling
is still buggy by design though.
Diffstat (limited to 'noncore/unsupported/mail2/libmail/imapresponse.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/unsupported/mail2/libmail/imapresponse.cpp | 224 |
1 files changed, 151 insertions, 73 deletions
diff --git a/noncore/unsupported/mail2/libmail/imapresponse.cpp b/noncore/unsupported/mail2/libmail/imapresponse.cpp index 06dca33..ce5b18b 100644 --- a/noncore/unsupported/mail2/libmail/imapresponse.cpp +++ b/noncore/unsupported/mail2/libmail/imapresponse.cpp | |||
@@ -2,56 +2,86 @@ | |||
2 | 2 | ||
3 | static QString _previousData; | ||
4 | static unsigned int _neededData; | ||
5 | 3 | ||
6 | IMAPResponseParser::IMAPResponseParser(const QString &data) | 4 | IMAPResponseParser::IMAPResponseParser() |
5 | { | ||
6 | } | ||
7 | |||
8 | void IMAPResponseParser::parse ( const QString &_data ) | ||
7 | { | 9 | { |
8 | QString _data = data, more; | 10 | QString data = _data; |
9 | _data.replace((QString)"\r\n", "\n"); | 11 | |
10 | 12 | int pos = 0; | |
11 | QStringList lines = QStringList::split('\n', _data); | 13 | int len = data. length ( ); |
12 | QStringList::Iterator it; | 14 | |
13 | for (it = lines.begin(); it != lines.end(); it++) { | 15 | |
14 | QString tag, lineData; | 16 | while ( pos < len ) { |
15 | 17 | pos = data. find ( QRegExp ( "[^\\s]" ), pos ); | |
16 | if (!_previousData.isNull()) { | 18 | |
17 | qDebug(QString("IMAPResponseParser: got additional data. (%1/%2)").arg(_previousData.length()).arg(_neededData)); | 19 | if (( pos < 0 ) || ( pos >= len )) |
18 | _previousData += *it + "\n"; | 20 | break; |
19 | if (_previousData.length() >= _neededData) { | 21 | |
20 | _previousData += ")"; | 22 | switch ( data [pos]. latin1 ( )) { |
21 | qDebug("IMAPResponseParser: got ALL additional data."); | 23 | case '*': { |
22 | qDebug("Data is: " + _previousData); | 24 | qDebug ( "* ASTERIX\n" ); |
23 | parseResponse(_previousData); | 25 | |
24 | _previousData = QString(0); | 26 | int eol = data. find ( '\n', pos ); |
25 | _neededData = 0; | 27 | int bracket = data. findRev ( '{', eol ); |
26 | } | 28 | int rest = data. find ( QRegExp ( "[^\\s]" ), pos + 1 ); |
27 | } else { | 29 | |
28 | splitTagData(*it, tag, lineData); | 30 | qDebug ( "pos=%d, rest=%d, bracket=%d, eol=%d\n", pos, rest, bracket, eol ); |
29 | if (tag == "*") { | 31 | |
30 | int pos; | 32 | if ( bracket > pos ) { |
31 | if ((pos = data.find(QRegExp("\\{\\d*\\}"))) != -1) { | 33 | uint needdata = data. mid ( bracket + 1, data. find ( '}', bracket + 1 ) - bracket - 1 ). toUInt ( ); |
32 | qDebug("IMAPResponseParser: waiting for additional data..."); | 34 | |
33 | _previousData = lineData + "\n"; | 35 | if ( needdata ) { |
34 | 36 | qDebug ( "nd=%d - hd=%d\n", needdata, ( len - eol - 1 )); | |
35 | QString tmp = data.right(data.length() - pos - 1).stripWhiteSpace(); | 37 | |
36 | tmp.truncate(tmp.length() - 1); | 38 | while ( needdata > ( len - eol - 1 )) { |
37 | 39 | qDebug ( "emitting need more...\n" ); | |
38 | _neededData = tmp.toUInt(); | 40 | emit needMoreData ( data ); |
39 | if (_previousData.length() >= _neededData) { | 41 | len = data. length ( ); |
40 | qDebug("IMAPResponseParser: got ALL additional data. (1st)"); | 42 | } |
41 | parseResponse(_previousData); | 43 | qDebug ( "Got all data...\n" ); |
42 | _previousData = QString(0); | 44 | |
43 | _neededData = 0; | 45 | QString tmp = data. mid ( rest, eol - rest + 1 + needdata ); |
44 | } else { | 46 | |
47 | int tail = 0; | ||
48 | |||
49 | while ( data [eol - rest + 1 + needdata + tail] != ')' ) | ||
50 | tail++; | ||
51 | tmp. append ( data. mid ( eol - rest + 1 + needdata, tail + 1 )); | ||
52 | |||
53 | |||
54 | qDebug ( "Complete parse = |%s|\n", tmp.latin1()); | ||
55 | |||
56 | parseResponse ( tmp ); | ||
57 | |||
58 | pos = rest + needdata + tail + 1; | ||
45 | break; | 59 | break; |
46 | } | 60 | } |
47 | } else { | ||
48 | parseResponse(lineData); | ||
49 | } | 61 | } |
50 | } else if (tag == "+") { | 62 | |
51 | emit needMoreData(_data); | 63 | parseResponse ( data. mid ( rest, eol - rest + 1 ). stripWhiteSpace ( )); |
52 | } else { | 64 | break; |
53 | _iresponse.setTag(tag); | 65 | } |
54 | parseResponse(_data, true); | 66 | case '+': { |
67 | qDebug ( "+ PLUS\n" ); | ||
68 | |||
69 | emit needMoreData ( data ); | ||
70 | len = data. length ( ); | ||
71 | break; | ||
72 | } | ||
73 | default : { | ||
74 | qDebug ( "OTHER: '%s...'\n", data. mid ( pos, 20 ). latin1 ( )); | ||
75 | |||
76 | uint rest = data. find ( ' ', pos + 1 ); | ||
77 | rest = data. find ( QRegExp ( "[^\\s]" ), rest + 1 ); | ||
78 | _iresponse. setTag ( data. mid ( pos, rest - pos ). stripWhiteSpace ( )); | ||
79 | parseResponse ( data. mid ( rest, data. find ( '\n', rest )). stripWhiteSpace ( ), true ); | ||
80 | break; | ||
55 | } | 81 | } |
56 | } | 82 | } |
83 | |||
84 | // skip to end-of-line | ||
85 | while (( pos < len ) && ( data [pos] != '\n' )) | ||
86 | pos++; | ||
57 | } | 87 | } |
@@ -59,2 +89,3 @@ IMAPResponseParser::IMAPResponseParser(const QString &data) | |||
59 | 89 | ||
90 | |||
60 | IMAPResponse IMAPResponseParser::response() | 91 | IMAPResponse IMAPResponseParser::response() |
@@ -69,2 +100,6 @@ void IMAPResponseParser::parseResponse(const QString &data, bool tagged) | |||
69 | bool isNum = false; | 100 | bool isNum = false; |
101 | |||
102 | |||
103 | //qDebug ( "\n\n#### PRD #### : #%s#\n\n", data.latin1()); | ||
104 | |||
70 | if ((pos = data.find(' ')) != -1) { | 105 | if ((pos = data.find(' ')) != -1) { |
@@ -74,3 +109,3 @@ void IMAPResponseParser::parseResponse(const QString &data, bool tagged) | |||
74 | } else { | 109 | } else { |
75 | qWarning("IMAPResponseParser: parseResponse: No response found."); | 110 | qWarning("IMAPResponseParser: parseResponse: No response found."); |
76 | return; | 111 | return; |
@@ -147,3 +182,3 @@ void IMAPResponseParser::parseResponse(const QString &data, bool tagged) | |||
147 | else if (*it == "UNSEEN") status.setUnseen(*(++it)); | 182 | else if (*it == "UNSEEN") status.setUnseen(*(++it)); |
148 | else qWarning("IMAPResponseParser: parseResponse: Unknown status data: " + *(it++) + "|"); | 183 | else qWarning((QString("IMAPResponseParser: parseResponse: Unknown status data: " )+ *(it++) + "|").latin1()); |
149 | } | 184 | } |
@@ -174,4 +209,9 @@ void IMAPResponseParser::parseResponse(const QString &data, bool tagged) | |||
174 | 209 | ||
210 | qDebug ( "Got FETCH\n" ); | ||
211 | |||
175 | QStringList fetchList = splitData(line, true); | 212 | QStringList fetchList = splitData(line, true); |
176 | QStringList list; | 213 | QStringList list; |
214 | |||
215 | qDebug ( "fl [0]=%s, fl [1]=%s, fl[2]=%s\n", fetchList[0].latin1(),fetchList[1].latin1(),fetchList[2].latin1()); | ||
216 | |||
177 | parseParenthesizedList(fetchList[1], list); | 217 | parseParenthesizedList(fetchList[1], list); |
@@ -179,2 +219,4 @@ void IMAPResponseParser::parseResponse(const QString &data, bool tagged) | |||
179 | for (it = list.begin(); it != list.end(); it++) { | 219 | for (it = list.begin(); it != list.end(); it++) { |
220 | qDebug ( "Checking list[] == %s\n", (*it).latin1()); | ||
221 | |||
180 | if (*it == "BODY") { | 222 | if (*it == "BODY") { |
@@ -182,21 +224,25 @@ void IMAPResponseParser::parseResponse(const QString &data, bool tagged) | |||
182 | // XXX | 224 | // XXX |
183 | } else if ((*it).find(QRegExp("BODY\\[\\d+\\]")) != -1) { | 225 | } else if ((*it).find(QRegExp("^BODY\\[\\d+\\]")) != -1) { |
184 | QString bodydata = *(++it); | ||
185 | qDebug("IMAPResponseParser: responseParser: got FETCH::BODY[x]"); | 226 | qDebug("IMAPResponseParser: responseParser: got FETCH::BODY[x]"); |
186 | 227 | ||
187 | QStringList blist; | 228 | QString number = ( *it ). mid ( 5, ( *it ). length ( ) - 6 ); |
188 | parseParenthesizedList(bodydata, blist); | 229 | QString bodydata = *(++it); |
230 | |||
231 | // QStringList blist; | ||
232 | // parseParenthesizedList(bodydata, blist); | ||
189 | 233 | ||
190 | IMAPResponseBodyPart bodypart; | 234 | IMAPResponseBodyPart bodypart; |
191 | QString tmp; | 235 | // QString tmp; |
192 | for (unsigned int i = 2; i < blist.count(); i++) { | 236 | // for (unsigned int i = 2; i < blist.count(); i++) { |
193 | if (i != 2) tmp += " " + blist[i]; | 237 | // if (i != 2) tmp += " " + blist[i]; |
194 | else tmp += blist[i]; | 238 | // else tmp += blist[i]; |
195 | } | 239 | // } |
196 | bodypart.setData(tmp); | 240 | bodypart.setData(bodydata); |
241 | |||
242 | // QString tmp = list[0]; | ||
243 | // tmp.replace(0, 5, ""); | ||
244 | // tmp.truncate(blist[0].length() - 1); | ||
245 | bodypart.setPart(number); | ||
197 | 246 | ||
198 | tmp = list[0]; | 247 | qDebug("added bodypart [%s]: '%s'\n\n", number.latin1(), bodydata.latin1()); |
199 | tmp.replace(0, 5, ""); | ||
200 | tmp.truncate(blist[0].length() - 1); | ||
201 | bodypart.setPart(tmp); | ||
202 | 248 | ||
@@ -339,3 +385,4 @@ void IMAPResponseParser::parseResponse(const QString &data, bool tagged) | |||
339 | } | 385 | } |
340 | } else qWarning("IMAPResponseParser: parseResponse: Unknown response: " + response + "|"); | 386 | } else qWarning((QString("IMAPResponseParser: parseResponse: Unknown response: ") + response + "|").latin1()); |
387 | |||
341 | } | 388 | } |
@@ -349,2 +396,4 @@ QStringList IMAPResponseParser::splitData(const QString &data, bool withBrackets | |||
349 | 396 | ||
397 | qDebug ( "sd: '%s'\n", data.latin1()); | ||
398 | |||
350 | for (unsigned int i = 0; i <= data.length(); i++) { | 399 | for (unsigned int i = 0; i <= data.length(); i++) { |
@@ -353,6 +402,34 @@ QStringList IMAPResponseParser::splitData(const QString &data, bool withBrackets | |||
353 | 402 | ||
354 | if (data[i] == '"' && !escaped) a = !a; | 403 | if (data[i] == '{' && !escaped && !a ) { |
404 | qDebug ( "sd: found a {\n" ); | ||
405 | |||
406 | int p = data. find ( '}', i + 1 ); | ||
407 | int eol = data. find ( '\n', i + 1 ); | ||
408 | |||
409 | if ( p > int( i )) { | ||
410 | int len = data. mid ( i + 1, p - i - 1 ). toInt ( ); | ||
411 | |||
412 | qDebug ( "sd: skipping %d bytes\n", len ); | ||
413 | |||
414 | if ( b == 0 ) { | ||
415 | temp = data. mid ( eol + 1, len ); | ||
416 | noappend = false; | ||
417 | i = eol + len; | ||
418 | continue; | ||
419 | } | ||
420 | else { | ||
421 | temp. append ( '{' ); | ||
422 | temp. append ( QString::number ( len )); | ||
423 | temp. append ( "}\r\n" ); | ||
424 | temp. append ( data. mid ( eol + 1, len )); | ||
425 | i = eol + len; | ||
426 | continue; | ||
427 | } | ||
428 | } | ||
429 | } | ||
430 | |||
431 | if (data[i] == '\"' && !escaped) a = !a; | ||
355 | else escaped = false; | 432 | else escaped = false; |
356 | 433 | ||
357 | if (data[i] == '\\' && data[i + 1] == '"') escaped = true; | 434 | if (data[i] == '\\' && data[i + 1] == '\"') escaped = true; |
358 | 435 | ||
@@ -360,3 +437,3 @@ QStringList IMAPResponseParser::splitData(const QString &data, bool withBrackets | |||
360 | list.append(temp); | 437 | list.append(temp); |
361 | temp = QString(0); | 438 | temp = QString::null; |
362 | if (data[i] == ' ') noappend = true; | 439 | if (data[i] == ' ') noappend = true; |
@@ -384,3 +461,3 @@ void IMAPResponseParser::splitTagData(const QString &line, QString &tag, QString | |||
384 | data = line.right(line.length() - pos - 1); | 461 | data = line.right(line.length() - pos - 1); |
385 | } else qWarning("IMAPResponseParser: splitTagData: tag not found. Line was " + line + "|"); | 462 | } else qWarning((QString("IMAPResponseParser: splitTagData: tag not found. Line was ") + line + "|").latin1()); |
386 | } | 463 | } |
@@ -390,2 +467,4 @@ QString IMAPResponseParser::removeLimiters(QString &string, const QChar &sl, con | |||
390 | QString tmpString; | 467 | QString tmpString; |
468 | string = string. stripWhiteSpace ( ); | ||
469 | |||
391 | if (string[0] == sl && string[string.length() - 1] == el) { | 470 | if (string[0] == sl && string[string.length() - 1] == el) { |
@@ -395,3 +474,3 @@ QString IMAPResponseParser::removeLimiters(QString &string, const QChar &sl, con | |||
395 | for (unsigned int i = 1; i <= string.length(); i++) { | 474 | for (unsigned int i = 1; i <= string.length(); i++) { |
396 | if (string[i - 1] == '\\' && sl == '"') ++i; | 475 | if (string[i - 1] == '\\' && sl == '\"') ++i; |
397 | tmpString += string[i - 1]; | 476 | tmpString += string[i - 1]; |
@@ -399,3 +478,2 @@ QString IMAPResponseParser::removeLimiters(QString &string, const QChar &sl, con | |||
399 | } | 478 | } |
400 | |||
401 | return tmpString; | 479 | return tmpString; |
@@ -419,3 +497,3 @@ IMAPResponseEnums::IMAPResponseCode IMAPResponseParser::getResponseCode(const QS | |||
419 | else { | 497 | else { |
420 | qWarning("IMAPResponseParser: getResponseCode: Unknown code: " + code + "|"); | 498 | qWarning((QString("IMAPResponseParser: getResponseCode: Unknown code: ") + code + "|").latin1()); |
421 | return UnknownCode; | 499 | return UnknownCode; |
@@ -443,3 +521,3 @@ QValueList<IMAPResponseEnums::IMAPResponseFlags> IMAPResponseParser::parseFlagLi | |||
443 | else if (flag.isEmpty()) { } | 521 | else if (flag.isEmpty()) { } |
444 | else qWarning("IMAPResponseParser: parseFlagList: Unknown flag: " + *it + "|"); | 522 | else qWarning((QString("IMAPResponseParser: parseFlagList: Unknown flag: ") + *it + "|").latin1()); |
445 | } | 523 | } |