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 | |
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.
-rw-r--r-- | noncore/unsupported/mail2/libmail/configfile.cpp | 4 | ||||
-rw-r--r-- | noncore/unsupported/mail2/libmail/imapbase.cpp | 36 | ||||
-rw-r--r-- | noncore/unsupported/mail2/libmail/imapbase.h | 3 | ||||
-rw-r--r-- | noncore/unsupported/mail2/libmail/imaphandler.cpp | 7 | ||||
-rw-r--r-- | noncore/unsupported/mail2/libmail/imapresponse.cpp | 224 | ||||
-rw-r--r-- | noncore/unsupported/mail2/libmail/imapresponse.h | 5 | ||||
-rw-r--r-- | noncore/unsupported/mail2/viewmail.cpp | 4 |
7 files changed, 194 insertions, 89 deletions
diff --git a/noncore/unsupported/mail2/libmail/configfile.cpp b/noncore/unsupported/mail2/libmail/configfile.cpp index a5c2b49..082b330 100644 --- a/noncore/unsupported/mail2/libmail/configfile.cpp +++ b/noncore/unsupported/mail2/libmail/configfile.cpp | |||
@@ -57,56 +57,56 @@ void ConfigFile::updateAccount(Account account) | |||
57 | Config *config = new Config((QString) getenv("HOME") + "/Applications/mail/accounts/account-" + account.accountName(), Config::File); | 57 | Config *config = new Config((QString) getenv("HOME") + "/Applications/mail/accounts/account-" + account.accountName(), Config::File); |
58 | 58 | ||
59 | config->setGroup("Account"); | 59 | config->setGroup("Account"); |
60 | config->writeEntry("RealName", account.realName()); | 60 | config->writeEntry("RealName", account.realName()); |
61 | config->writeEntry("Email", account.email()); | 61 | config->writeEntry("Email", account.email()); |
62 | config->writeEntry("Organization", account.org()); | 62 | config->writeEntry("Organization", account.org()); |
63 | config->writeEntry("ImapServer", account.imapServer()); | 63 | config->writeEntry("ImapServer", account.imapServer()); |
64 | config->writeEntry("ImapPort", account.imapPort()); | 64 | config->writeEntry("ImapPort", account.imapPort()); |
65 | config->writeEntry("SmtpServer", account.smtpServer()); | 65 | config->writeEntry("SmtpServer", account.smtpServer()); |
66 | config->writeEntry("SmtpPort", account.smtpPort()); | 66 | config->writeEntry("SmtpPort", account.smtpPort()); |
67 | config->writeEntry("User", account.user()); | 67 | config->writeEntry("User", account.user()); |
68 | config->writeEntryCrypt("Pass", rot13(account.pass())); | 68 | config->writeEntryCrypt("Pass", rot13(account.pass())); |
69 | config->writeEntry("SmtpSsl", account.smtpSsl()); | 69 | config->writeEntry("SmtpSsl", account.smtpSsl()); |
70 | config->writeEntry("SmtpSslPort", account.smtpSslPort()); | 70 | config->writeEntry("SmtpSslPort", account.smtpSslPort()); |
71 | config->writeEntry("ImapSsl", account.imapSsl()); | 71 | config->writeEntry("ImapSsl", account.imapSsl()); |
72 | config->writeEntry("ImapSslPort", account.imapSslPort()); | 72 | config->writeEntry("ImapSslPort", account.imapSslPort()); |
73 | config->writeEntry("DefaultCc", account.defaultCc()); | 73 | config->writeEntry("DefaultCc", account.defaultCc()); |
74 | config->writeEntry("DefaultBcc", account.defaultBcc()); | 74 | config->writeEntry("DefaultBcc", account.defaultBcc()); |
75 | config->writeEntry("DefaultReplyTo", account.defaultReplyTo()); | 75 | config->writeEntry("DefaultReplyTo", account.defaultReplyTo()); |
76 | config->writeEntry("Cc", account.cc()); | 76 | config->writeEntry("Cc", account.cc()); |
77 | config->writeEntry("Bcc", account.bcc()); | 77 | config->writeEntry("Bcc", account.bcc()); |
78 | config->writeEntry("ReplyTo", account.replyTo()); | 78 | config->writeEntry("ReplyTo", account.replyTo()); |
79 | config->writeEntry("Signature", account.signature().replace(QRegExp("\\n"), "<br>")); | 79 | config->writeEntry("Signature", account.signature().replace(QRegExp("\\n"), "<br>")); |
80 | 80 | ||
81 | config->write(); | 81 | config->write(); |
82 | } | 82 | } |
83 | 83 | ||
84 | void ConfigFile::deleteAccount(Account account) | 84 | void ConfigFile::deleteAccount(Account account) |
85 | { | 85 | { |
86 | QFile f((QString) getenv("HOME") + "/Applications/mail/accounts/account-" + account.accountName()); | 86 | QFile f((QString) getenv("HOME") + "/Applications/mail/accounts/account-" + account.accountName()); |
87 | f.remove(); | 87 | f.remove(); |
88 | } | 88 | } |
89 | 89 | ||
90 | void ConfigFile::checkDirectory() | 90 | void ConfigFile::checkDirectory() |
91 | { | 91 | { |
92 | if (!QDir((QString) getenv("HOME") + "/Applications/mail/accounts").exists()) { | 92 | if (!QDir((QString) getenv("HOME") + "/Applications/mail/accounts").exists()) { |
93 | system("mkdir -p $HOME/Applications/mail/accounts"); | 93 | system("mkdir -p $HOME/Applications/mail/accounts"); |
94 | qWarning("mail: $HOME/Applications/mail/accounts created"); | 94 | qWarning("mail: $HOME/Applications/mail/accounts created"); |
95 | } | 95 | } |
96 | } | 96 | } |
97 | 97 | ||
98 | QString ConfigFile::rot13(const QString &input) | 98 | QString ConfigFile::rot13(const QString &input) |
99 | { | 99 | { |
100 | QString i = input; | 100 | QString i = input; |
101 | int l = i.length(); | 101 | int l = i.length(); |
102 | while(l--) { | 102 | while(l--) { |
103 | if (i[l] >= QChar('A') && i[l] <= QChar('M') || | 103 | if (i[l] >= QChar('A') && i[l] <= QChar('M') || |
104 | i[l] >= QChar('a') && i[l] <= QChar('m')) | 104 | i[l] >= QChar('a') && i[l] <= QChar('m')) |
105 | i[l] = (char)((int)QChar(l[i])+13); | 105 | i[l] = QChar(i[l].unicode()+13); |
106 | else if (i[l] >= QChar('N') && i[l] <= QChar('Z') || | 106 | else if (i[l] >= QChar('N') && i[l] <= QChar('Z') || |
107 | i[l] >= QChar('n') && i[l] <= QChar('z')) | 107 | i[l] >= QChar('n') && i[l] <= QChar('z')) |
108 | i[l] = (char)((int)QChar(l[i])-13); | 108 | i[l] = QChar(i[l].unicode()-13); |
109 | } | 109 | } |
110 | return i; | 110 | return i; |
111 | } | 111 | } |
112 | 112 | ||
diff --git a/noncore/unsupported/mail2/libmail/imapbase.cpp b/noncore/unsupported/mail2/libmail/imapbase.cpp index 9a2ba47..4753f43 100644 --- a/noncore/unsupported/mail2/libmail/imapbase.cpp +++ b/noncore/unsupported/mail2/libmail/imapbase.cpp | |||
@@ -8,103 +8,125 @@ IMAPBase::IMAPBase(const Account &account) | |||
8 | { | 8 | { |
9 | _connected = false; | 9 | _connected = false; |
10 | _writingAllowed = false; | 10 | _writingAllowed = false; |
11 | _socket = new QSocket(this); | 11 | _socket = new QSocket(this); |
12 | 12 | ||
13 | connect(_socket, SIGNAL(readyRead()), SLOT(slotDataAvailiable())); | 13 | connect(_socket, SIGNAL(readyRead()), SLOT(slotDataAvailiable())); |
14 | connect(_socket, SIGNAL(hostFound()), SLOT(slotHostFound())); | 14 | connect(_socket, SIGNAL(hostFound()), SLOT(slotHostFound())); |
15 | connect(_socket, SIGNAL(connected()), SLOT(slotConnected())); | 15 | connect(_socket, SIGNAL(connected()), SLOT(slotConnected())); |
16 | connect(_socket, SIGNAL(connectionClosed()), SLOT(slotDisconnected())); | 16 | connect(_socket, SIGNAL(connectionClosed()), SLOT(slotDisconnected())); |
17 | connect(_socket, SIGNAL(error(int)), SLOT(slotError(int))); | 17 | connect(_socket, SIGNAL(error(int)), SLOT(slotError(int))); |
18 | 18 | ||
19 | QTimer *commandTimer = new QTimer(this); | 19 | QTimer *commandTimer = new QTimer(this); |
20 | commandTimer->start(200); | 20 | commandTimer->start(200); |
21 | connect(commandTimer, SIGNAL(timeout()), SLOT(writeCommands())); | 21 | connect(commandTimer, SIGNAL(timeout()), SLOT(writeCommands())); |
22 | } | 22 | } |
23 | 23 | ||
24 | void IMAPBase::sendCommand(const QString &command) | 24 | void IMAPBase::sendCommand(const QString &command) |
25 | { | 25 | { |
26 | if (!_connected) makeConnect(); | 26 | if (!_connected) makeConnect(); |
27 | _commandQueue.append(command); | 27 | _commandQueue.append(command); |
28 | } | 28 | } |
29 | 29 | ||
30 | void IMAPBase::disconnect() | 30 | void IMAPBase::disconnect() |
31 | { | 31 | { |
32 | _connected = false; | 32 | _connected = false; |
33 | delete _socket; | 33 | delete _socket; |
34 | emit disconnected(); | 34 | emit disconnected(); |
35 | } | 35 | } |
36 | 36 | ||
37 | void IMAPBase::makeConnect() | 37 | void IMAPBase::makeConnect() |
38 | { | 38 | { |
39 | emit lookingUpHost(); | 39 | emit lookingUpHost(); |
40 | if (_socket == NULL) _socket = new QSocket(this); | 40 | if (_socket == NULL) _socket = new QSocket(this); |
41 | 41 | ||
42 | Q_UINT16 port = _account.imapPort().toUInt(); | 42 | Q_UINT16 port = _account.imapPort().toUInt(); |
43 | _socket->connectToHost(_account.imapServer(), port); | 43 | _socket->connectToHost(_account.imapServer(), port); |
44 | } | 44 | } |
45 | 45 | ||
46 | void IMAPBase::writeCommands() | 46 | void IMAPBase::writeCommands() |
47 | { | 47 | { |
48 | if (!_connected) return; | 48 | if (!_connected) return; |
49 | if (_commandQueue.isEmpty()) return; | 49 | if (_commandQueue.isEmpty()) return; |
50 | if (!_writingAllowed) return; | 50 | if (!_writingAllowed) return; |
51 | 51 | ||
52 | QStringList::Iterator it; | 52 | QStringList::Iterator it; |
53 | for (it = _commandQueue.begin(); it != _commandQueue.end(); it++) { | 53 | for (it = _commandQueue.begin(); it != _commandQueue.end(); it++) { |
54 | if (!(*it).isEmpty() && _writingAllowed) { | 54 | if (!(*it).isEmpty() && _writingAllowed) { |
55 | #ifndef QT_NO_DEBUG | 55 | #ifndef QT_NO_DEBUG |
56 | qDebug("IMAP > " + (*it).stripWhiteSpace()); | 56 | qDebug("IMAP > " + (*it).stripWhiteSpace().local8Bit ()); |
57 | #endif | 57 | #endif |
58 | _socket->writeBlock((*it).latin1(), (*it).length()); | 58 | _socket->writeBlock((*it).latin1(), (*it).length()); |
59 | _writingAllowed = false; | 59 | _writingAllowed = false; |
60 | if (( *it ). find ( QRegExp ( "^[a-z][0-9]+ " )) == 0 ) | ||
61 | _lasttag = (*it).left(2); | ||
62 | |||
63 | connect(_socket, SIGNAL(readyRead()), SLOT(slotDataAvailiable())); | ||
60 | _commandQueue.remove(it); | 64 | _commandQueue.remove(it); |
61 | break; | 65 | break; |
62 | } | 66 | } |
63 | } | 67 | } |
64 | } | 68 | } |
65 | 69 | ||
66 | void IMAPBase::slotError(int err) | 70 | void IMAPBase::slotError(int err) |
67 | { | 71 | { |
68 | if (err == QSocket::ErrConnectionRefused) { | 72 | if (err == QSocket::ErrConnectionRefused) { |
69 | emit error(IMAPErrConnectionRefused); | 73 | emit error(IMAPErrConnectionRefused); |
70 | } else if (err == QSocket::ErrHostNotFound) { | 74 | } else if (err == QSocket::ErrHostNotFound) { |
71 | emit error(IMAPErrHostNotFound); | 75 | emit error(IMAPErrHostNotFound); |
72 | } else if (err == QSocket::ErrSocketRead) { | 76 | } else if (err == QSocket::ErrSocketRead) { |
73 | emit error(IMAPErrSocketRead); | 77 | emit error(IMAPErrSocketRead); |
74 | } else { | 78 | } else { |
75 | emit error(IMAPErrUnknownError); | 79 | emit error(IMAPErrUnknownError); |
76 | } | 80 | } |
77 | } | 81 | } |
78 | 82 | ||
79 | void IMAPBase::slotHostFound() | 83 | void IMAPBase::slotHostFound() |
80 | { | 84 | { |
81 | emit hostFound(); | 85 | emit hostFound(); |
82 | } | 86 | } |
83 | 87 | ||
84 | void IMAPBase::slotConnected() | 88 | void IMAPBase::slotConnected() |
85 | { | 89 | { |
86 | _connected = true; | 90 | _connected = true; |
87 | emit connected(); | 91 | emit connected(); |
88 | } | 92 | } |
89 | 93 | ||
90 | void IMAPBase::slotDisconnected() | 94 | void IMAPBase::slotDisconnected() |
91 | { | 95 | { |
92 | _connected = false; | 96 | _connected = false; |
93 | emit disconnected(); | 97 | emit disconnected(); |
94 | } | 98 | } |
95 | 99 | ||
100 | #include <unistd.h> | ||
101 | |||
96 | void IMAPBase::slotDataAvailiable() | 102 | void IMAPBase::slotDataAvailiable() |
97 | { | 103 | { |
104 | static bool firstline = true; | ||
105 | |||
98 | while (_socket->canReadLine()) { | 106 | while (_socket->canReadLine()) { |
99 | _data += _socket->readLine(); | 107 | QString tmp = _socket-> readLine ( ); |
100 | if (_socket->atEnd()) { | 108 | |
101 | #ifndef QT_NO_DEBUG | 109 | _data += tmp; |
102 | qDebug("IMAP < " + _data.stripWhiteSpace()); | 110 | qDebug ( "New Line [%d]: '%s'\n", _connected ? 1 : 0, tmp.latin1( )); |
103 | #endif | 111 | |
112 | if ( firstline || tmp. left(2) == _lasttag ) { | ||
113 | firstline = false; | ||
114 | |||
115 | // if ( _socket-> atEnd ( )) | ||
116 | qDebug ( "at end -> emitting\n" ); | ||
117 | |||
118 | QObject::disconnect(_socket, SIGNAL(readyRead()), this, SLOT(slotDataAvailiable())); | ||
104 | emit dataReceived(_data); | 119 | emit dataReceived(_data); |
120 | _data = QString::null; | ||
105 | _writingAllowed = true; | 121 | _writingAllowed = true; |
106 | _data = QString(0); | ||
107 | } | 122 | } |
108 | } | 123 | } |
109 | } | 124 | } |
110 | 125 | ||
126 | void IMAPBase::tryRead ( QString &data ) | ||
127 | { | ||
128 | qDebug ( "Trying to read...\n" ); | ||
129 | |||
130 | while ( _socket-> canReadLine ( )) | ||
131 | data += _socket-> readLine ( ); | ||
132 | } | ||
diff --git a/noncore/unsupported/mail2/libmail/imapbase.h b/noncore/unsupported/mail2/libmail/imapbase.h index e4a0b97..7697ffe 100644 --- a/noncore/unsupported/mail2/libmail/imapbase.h +++ b/noncore/unsupported/mail2/libmail/imapbase.h | |||
@@ -1,52 +1,53 @@ | |||
1 | #ifndef IMAPBASE_H | 1 | #ifndef IMAPBASE_H |
2 | #define IMAPBASE_H | 2 | #define IMAPBASE_H |
3 | 3 | ||
4 | #include <qobject.h> | 4 | #include <qobject.h> |
5 | 5 | ||
6 | #include "configfile.h" | 6 | #include "configfile.h" |
7 | 7 | ||
8 | class QSocket; | 8 | class QSocket; |
9 | 9 | ||
10 | class IMAPBase : public QObject | 10 | class IMAPBase : public QObject |
11 | { | 11 | { |
12 | Q_OBJECT | 12 | Q_OBJECT |
13 | 13 | ||
14 | public: | 14 | public: |
15 | IMAPBase(const Account &account); | 15 | IMAPBase(const Account &account); |
16 | 16 | ||
17 | enum Error { IMAPErrConnectionRefused, IMAPErrHostNotFound, | 17 | enum Error { IMAPErrConnectionRefused, IMAPErrHostNotFound, |
18 | IMAPErrSocketRead, IMAPErrUnknownError, | 18 | IMAPErrSocketRead, IMAPErrUnknownError, |
19 | IMAPErrLoginFailed }; | 19 | IMAPErrLoginFailed }; |
20 | 20 | ||
21 | void sendCommand(const QString &command); | 21 | void sendCommand(const QString &command); |
22 | void disconnect(); | 22 | void disconnect(); |
23 | 23 | ||
24 | signals: | 24 | signals: |
25 | void dataReceived(const QString &data); | 25 | void dataReceived(const QString &data); |
26 | void lookingUpHost(); | 26 | void lookingUpHost(); |
27 | void hostFound(); | 27 | void hostFound(); |
28 | void connected(); | 28 | void connected(); |
29 | void disconnected(); | 29 | void disconnected(); |
30 | void error(int err); | 30 | void error(int err); |
31 | 31 | ||
32 | protected: | 32 | protected: |
33 | void makeConnect(); | 33 | void makeConnect(); |
34 | 34 | ||
35 | protected slots: | 35 | protected slots: |
36 | void writeCommands(); | 36 | void writeCommands(); |
37 | void slotError(int error); | 37 | void slotError(int error); |
38 | void slotHostFound(); | 38 | void slotHostFound(); |
39 | void slotConnected(); | 39 | void slotConnected(); |
40 | void slotDisconnected(); | 40 | void slotDisconnected(); |
41 | void slotDataAvailiable(); | 41 | void slotDataAvailiable(); |
42 | void tryRead ( QString & ); | ||
42 | 43 | ||
43 | private: | 44 | private: |
44 | Account _account; | 45 | Account _account; |
45 | QString _data; | 46 | QString _data; |
46 | QSocket *_socket; | 47 | QSocket *_socket; |
47 | QStringList _commandQueue; | 48 | QStringList _commandQueue; |
48 | bool _connected, _writingAllowed; | 49 | bool _connected, _writingAllowed; |
49 | 50 | QString _lasttag; | |
50 | }; | 51 | }; |
51 | 52 | ||
52 | #endif | 53 | #endif |
diff --git a/noncore/unsupported/mail2/libmail/imaphandler.cpp b/noncore/unsupported/mail2/libmail/imaphandler.cpp index 7493240..dc97b28 100644 --- a/noncore/unsupported/mail2/libmail/imaphandler.cpp +++ b/noncore/unsupported/mail2/libmail/imaphandler.cpp | |||
@@ -253,91 +253,94 @@ QString IMAPHandler::iCopy(const QString &message, const QString &mailbox) | |||
253 | .arg(message) | 253 | .arg(message) |
254 | .arg(escape(mailbox))); | 254 | .arg(escape(mailbox))); |
255 | return tag(false); | 255 | return tag(false); |
256 | } | 256 | } |
257 | 257 | ||
258 | QString IMAPHandler::iUid(const QString &command, const QString &arguments) | 258 | QString IMAPHandler::iUid(const QString &command, const QString &arguments) |
259 | { | 259 | { |
260 | doLogin(); | 260 | doLogin(); |
261 | 261 | ||
262 | _ibase->sendCommand(QString("%1 UID %2 %3\r\n") | 262 | _ibase->sendCommand(QString("%1 UID %2 %3\r\n") |
263 | .arg(tag()) | 263 | .arg(tag()) |
264 | .arg(command) | 264 | .arg(command) |
265 | .arg(arguments)); | 265 | .arg(arguments)); |
266 | return tag(false); | 266 | return tag(false); |
267 | } | 267 | } |
268 | 268 | ||
269 | QString IMAPHandler::iX(const QString &commandAtom, const QString &arguments) | 269 | QString IMAPHandler::iX(const QString &commandAtom, const QString &arguments) |
270 | { | 270 | { |
271 | doLogin(); | 271 | doLogin(); |
272 | 272 | ||
273 | _ibase->sendCommand(QString("%1 X%2 %3\r\n") | 273 | _ibase->sendCommand(QString("%1 X%2 %3\r\n") |
274 | .arg(tag()) | 274 | .arg(tag()) |
275 | .arg(commandAtom) | 275 | .arg(commandAtom) |
276 | .arg(arguments)); | 276 | .arg(arguments)); |
277 | return tag(false); | 277 | return tag(false); |
278 | } | 278 | } |
279 | 279 | ||
280 | QString IMAPHandler::escape(const QString &in) | 280 | QString IMAPHandler::escape(const QString &in) |
281 | { | 281 | { |
282 | QString in_ = in; | 282 | QString in_ = in; |
283 | return in_.replace(QRegExp("\""), "\\\""); | 283 | return in_.replace(QRegExp("\""), "\\\""); |
284 | } | 284 | } |
285 | 285 | ||
286 | QString IMAPHandler::tag(bool count) | 286 | QString IMAPHandler::tag(bool count) |
287 | { | 287 | { |
288 | return QString("a%1").arg(count ? _tag++ : _tag); | 288 | return QString("a%1").arg(count ? _tag++ : _tag); |
289 | } | 289 | } |
290 | 290 | ||
291 | void IMAPHandler::slotDataReceived(const QString &data) | 291 | void IMAPHandler::slotDataReceived(const QString &data) |
292 | { | 292 | { |
293 | if (!_ready) { | 293 | if (!_ready) { |
294 | // The first data is always the greeting string. | 294 | // The first data is always the greeting string. |
295 | // We can ignore it. | 295 | // We can ignore it. |
296 | _ready = true; | 296 | _ready = true; |
297 | return; | 297 | return; |
298 | } | 298 | } |
299 | 299 | ||
300 | 300 | ||
301 | IMAPResponseParser parser(data); | 301 | IMAPResponseParser parser; |
302 | //connect ( &parser, SIGNAL( needMoreData ( QString & )), _ibase, SLOT( tryRead ( QString & ))); | ||
303 | parser. parse ( data ); | ||
302 | IMAPResponse response = parser.response(); | 304 | IMAPResponse response = parser.response(); |
305 | //disconnect ( &parser, SIGNAL( needMoreData ( QString & )), _ibase, SLOT( tryRead ( QString & ))); | ||
303 | response.setImapHandler(this); | 306 | response.setImapHandler(this); |
304 | 307 | ||
305 | if (!_loggingin) emit gotResponse(response); | 308 | if (!_loggingin) { qDebug("Emitting gotResponse!\n" ); emit gotResponse(response); } |
306 | else { | 309 | else { |
307 | if (response.statusResponse().status() == IMAPResponseEnums::OK) { | 310 | if (response.statusResponse().status() == IMAPResponseEnums::OK) { |
308 | _loggingin = false; | 311 | _loggingin = false; |
309 | _loggedin = true; | 312 | _loggedin = true; |
310 | qWarning("OK. Logged in. Leaving loggingin state."); | 313 | qWarning("OK. Logged in. Leaving loggingin state."); |
311 | } else { | 314 | } else { |
312 | _loggingin = false; | 315 | _loggingin = false; |
313 | emit IMAPError(IMAPBase::IMAPErrLoginFailed); | 316 | emit IMAPError(IMAPBase::IMAPErrLoginFailed); |
314 | } | 317 | } |
315 | } | 318 | } |
316 | } | 319 | } |
317 | 320 | ||
318 | void IMAPHandler::slotLookingUpHost() | 321 | void IMAPHandler::slotLookingUpHost() |
319 | { | 322 | { |
320 | emit IMAPLookingUpHost(); | 323 | emit IMAPLookingUpHost(); |
321 | } | 324 | } |
322 | 325 | ||
323 | void IMAPHandler::slotHostFound() | 326 | void IMAPHandler::slotHostFound() |
324 | { | 327 | { |
325 | emit IMAPHostFound(); | 328 | emit IMAPHostFound(); |
326 | } | 329 | } |
327 | 330 | ||
328 | void IMAPHandler::slotConnected() | 331 | void IMAPHandler::slotConnected() |
329 | { | 332 | { |
330 | emit IMAPConnected(); | 333 | emit IMAPConnected(); |
331 | } | 334 | } |
332 | 335 | ||
333 | void IMAPHandler::slotDisconnected() | 336 | void IMAPHandler::slotDisconnected() |
334 | { | 337 | { |
335 | _loggedin = false; | 338 | _loggedin = false; |
336 | emit IMAPDisconnected(); | 339 | emit IMAPDisconnected(); |
337 | } | 340 | } |
338 | 341 | ||
339 | void IMAPHandler::slotError(int err) | 342 | void IMAPHandler::slotError(int err) |
340 | { | 343 | { |
341 | emit IMAPError(err); | 344 | emit IMAPError(err); |
342 | } | 345 | } |
343 | 346 | ||
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 | |||
@@ -1,249 +1,295 @@ | |||
1 | #include "imapresponse.h" | 1 | #include "imapresponse.h" |
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 | } |
58 | } | 88 | } |
59 | 89 | ||
90 | |||
60 | IMAPResponse IMAPResponseParser::response() | 91 | IMAPResponse IMAPResponseParser::response() |
61 | { | 92 | { |
62 | return _iresponse; | 93 | return _iresponse; |
63 | } | 94 | } |
64 | 95 | ||
65 | void IMAPResponseParser::parseResponse(const QString &data, bool tagged) | 96 | void IMAPResponseParser::parseResponse(const QString &data, bool tagged) |
66 | { | 97 | { |
67 | QString response, line; | 98 | QString response, line; |
68 | int pos; | 99 | int pos; |
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) { |
71 | response = data.left(pos).upper(); | 106 | response = data.left(pos).upper(); |
72 | response.toInt(&isNum); | 107 | response.toInt(&isNum); |
73 | line = data.right(data.length() - pos - 1); | 108 | line = data.right(data.length() - pos - 1); |
74 | } else { | 109 | } else { |
75 | qWarning("IMAPResponseParser: parseResponse: No response found."); | 110 | qWarning("IMAPResponseParser: parseResponse: No response found."); |
76 | return; | 111 | return; |
77 | } | 112 | } |
78 | 113 | ||
79 | if (response == "OK" && tagged) { | 114 | if (response == "OK" && tagged) { |
80 | IMAPResponseStatusResponse status(OK, line); | 115 | IMAPResponseStatusResponse status(OK, line); |
81 | status.setResponseCode(getResponseCode(status.comment())); | 116 | status.setResponseCode(getResponseCode(status.comment())); |
82 | _iresponse.setStatusResponse(status); | 117 | _iresponse.setStatusResponse(status); |
83 | } else if (response == "OK" && !tagged) { | 118 | } else if (response == "OK" && !tagged) { |
84 | IMAPResponseOK ok(line, getResponseCode(line)); | 119 | IMAPResponseOK ok(line, getResponseCode(line)); |
85 | _iresponse.addOK(ok); | 120 | _iresponse.addOK(ok); |
86 | } else if (response == "NO" && tagged) { | 121 | } else if (response == "NO" && tagged) { |
87 | IMAPResponseStatusResponse status(NO, line); | 122 | IMAPResponseStatusResponse status(NO, line); |
88 | status.setResponseCode(getResponseCode(status.comment())); | 123 | status.setResponseCode(getResponseCode(status.comment())); |
89 | _iresponse.setStatusResponse(status); | 124 | _iresponse.setStatusResponse(status); |
90 | } else if (response == "NO" && !tagged) { | 125 | } else if (response == "NO" && !tagged) { |
91 | IMAPResponseNO no(line, getResponseCode(line)); | 126 | IMAPResponseNO no(line, getResponseCode(line)); |
92 | _iresponse.addNO(no); | 127 | _iresponse.addNO(no); |
93 | } else if (response == "BAD" && tagged) { | 128 | } else if (response == "BAD" && tagged) { |
94 | IMAPResponseStatusResponse status(BAD, line); | 129 | IMAPResponseStatusResponse status(BAD, line); |
95 | status.setResponseCode(getResponseCode(status.comment())); | 130 | status.setResponseCode(getResponseCode(status.comment())); |
96 | _iresponse.setStatusResponse(status); | 131 | _iresponse.setStatusResponse(status); |
97 | } else if (response == "BAD" && !tagged) { | 132 | } else if (response == "BAD" && !tagged) { |
98 | IMAPResponseBAD bad(line, getResponseCode(line)); | 133 | IMAPResponseBAD bad(line, getResponseCode(line)); |
99 | _iresponse.addBAD(bad); | 134 | _iresponse.addBAD(bad); |
100 | } else if (response == "PREAUTH" && tagged) { | 135 | } else if (response == "PREAUTH" && tagged) { |
101 | IMAPResponseStatusResponse status(PREAUTH, line); | 136 | IMAPResponseStatusResponse status(PREAUTH, line); |
102 | _iresponse.setStatusResponse(status); | 137 | _iresponse.setStatusResponse(status); |
103 | } else if (response == "PREAUTH" && !tagged) { | 138 | } else if (response == "PREAUTH" && !tagged) { |
104 | qDebug("IMAPResponseParser: responseParser: got untagged PREAUTH response."); | 139 | qDebug("IMAPResponseParser: responseParser: got untagged PREAUTH response."); |
105 | // XXX | 140 | // XXX |
106 | } else if (response == "BYE") { | 141 | } else if (response == "BYE") { |
107 | IMAPResponseStatusResponse status(BYE, line); | 142 | IMAPResponseStatusResponse status(BYE, line); |
108 | if (!tagged) status.setExitedUnexpected(true); | 143 | if (!tagged) status.setExitedUnexpected(true); |
109 | _iresponse.setStatusResponse(status); | 144 | _iresponse.setStatusResponse(status); |
110 | } else if (response == "CAPABILITY") { | 145 | } else if (response == "CAPABILITY") { |
111 | IMAPResponseCAPABILITY capability(QStringList::split(' ', line)); | 146 | IMAPResponseCAPABILITY capability(QStringList::split(' ', line)); |
112 | _iresponse.addCAPABILITY(capability); | 147 | _iresponse.addCAPABILITY(capability); |
113 | } else if (response == "LIST") { | 148 | } else if (response == "LIST") { |
114 | QStringList list = splitData(line, true); | 149 | QStringList list = splitData(line, true); |
115 | 150 | ||
116 | QStringList flags; | 151 | QStringList flags; |
117 | parseParenthesizedList(list[0], flags); | 152 | parseParenthesizedList(list[0], flags); |
118 | 153 | ||
119 | removeLimiters(list[1]); | 154 | removeLimiters(list[1]); |
120 | removeLimiters(list[2]); | 155 | removeLimiters(list[2]); |
121 | IMAPResponseLIST rlist(parseFlagList(flags), list[1], list[2]); | 156 | IMAPResponseLIST rlist(parseFlagList(flags), list[1], list[2]); |
122 | _iresponse.addLIST(rlist); | 157 | _iresponse.addLIST(rlist); |
123 | } else if (response == "LSUB") { | 158 | } else if (response == "LSUB") { |
124 | QStringList list = splitData(line, true); | 159 | QStringList list = splitData(line, true); |
125 | 160 | ||
126 | QStringList flags; | 161 | QStringList flags; |
127 | parseParenthesizedList(list[0], flags); | 162 | parseParenthesizedList(list[0], flags); |
128 | 163 | ||
129 | removeLimiters(list[1]); | 164 | removeLimiters(list[1]); |
130 | removeLimiters(list[2]); | 165 | removeLimiters(list[2]); |
131 | IMAPResponseLSUB lsub(parseFlagList(flags), list[1], list[2]); | 166 | IMAPResponseLSUB lsub(parseFlagList(flags), list[1], list[2]); |
132 | _iresponse.addLSUB(lsub); | 167 | _iresponse.addLSUB(lsub); |
133 | } else if (response == "STATUS") { | 168 | } else if (response == "STATUS") { |
134 | QStringList list = splitData(line, true); | 169 | QStringList list = splitData(line, true); |
135 | 170 | ||
136 | removeLimiters(list[0]); | 171 | removeLimiters(list[0]); |
137 | IMAPResponseSTATUS status(list[0]); | 172 | IMAPResponseSTATUS status(list[0]); |
138 | 173 | ||
139 | QStringList flags; | 174 | QStringList flags; |
140 | parseParenthesizedList(list[1], flags); | 175 | parseParenthesizedList(list[1], flags); |
141 | QStringList::Iterator it; | 176 | QStringList::Iterator it; |
142 | for (it = flags.begin(); it != flags.end(); it++) { | 177 | for (it = flags.begin(); it != flags.end(); it++) { |
143 | if (*it == "MESSAGES") status.setMessages(*(++it)); | 178 | if (*it == "MESSAGES") status.setMessages(*(++it)); |
144 | else if (*it == "RECENT") status.setRecent(*(++it)); | 179 | else if (*it == "RECENT") status.setRecent(*(++it)); |
145 | else if (*it == "UIDNEXT") status.setUidnext(*(++it)); | 180 | else if (*it == "UIDNEXT") status.setUidnext(*(++it)); |
146 | else if (*it == "UIDVALIDITY") status.setUidvalidity(*(++it)); | 181 | else if (*it == "UIDVALIDITY") status.setUidvalidity(*(++it)); |
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 | } |
150 | _iresponse.addSTATUS(status); | 185 | _iresponse.addSTATUS(status); |
151 | } else if (response == "SEARCH") { | 186 | } else if (response == "SEARCH") { |
152 | IMAPResponseSEARCH search(QStringList::split(' ', line)); | 187 | IMAPResponseSEARCH search(QStringList::split(' ', line)); |
153 | _iresponse.addSEARCH(search); | 188 | _iresponse.addSEARCH(search); |
154 | } else if (response == "FLAGS") { | 189 | } else if (response == "FLAGS") { |
155 | QStringList list; | 190 | QStringList list; |
156 | parseParenthesizedList(line, list); | 191 | parseParenthesizedList(line, list); |
157 | 192 | ||
158 | IMAPResponseFLAGS flags(parseFlagList(list)); | 193 | IMAPResponseFLAGS flags(parseFlagList(list)); |
159 | _iresponse.addFLAGS(flags); | 194 | _iresponse.addFLAGS(flags); |
160 | } else if (isNum) { | 195 | } else if (isNum) { |
161 | QStringList list = QStringList::split(' ', line); | 196 | QStringList list = QStringList::split(' ', line); |
162 | if (list[0] == "EXISTS") { | 197 | if (list[0] == "EXISTS") { |
163 | IMAPResponseEXISTS exists(response); | 198 | IMAPResponseEXISTS exists(response); |
164 | _iresponse.addEXISTS(exists); | 199 | _iresponse.addEXISTS(exists); |
165 | } else if (list[0] == "RECENT") { | 200 | } else if (list[0] == "RECENT") { |
166 | IMAPResponseRECENT recent(response); | 201 | IMAPResponseRECENT recent(response); |
167 | _iresponse.addRECENT(recent); | 202 | _iresponse.addRECENT(recent); |
168 | } else if (list[0] == "EXPUNGE") { | 203 | } else if (list[0] == "EXPUNGE") { |
169 | IMAPResponseEXPUNGE expunge(response); | 204 | IMAPResponseEXPUNGE expunge(response); |
170 | _iresponse.addEXPUNGE(expunge); | 205 | _iresponse.addEXPUNGE(expunge); |
171 | } else if (list[0] == "FETCH") { | 206 | } else if (list[0] == "FETCH") { |
172 | IMAPResponseFETCH fetch; | 207 | IMAPResponseFETCH fetch; |
173 | QStringList::Iterator it; | 208 | QStringList::Iterator it; |
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); |
178 | 218 | ||
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") { |
181 | qDebug("IMAPResponseParser: responseParser: got FETCH::BODY"); | 223 | qDebug("IMAPResponseParser: responseParser: got FETCH::BODY"); |
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 | ||
203 | fetch.addBodyPart(bodypart); | 249 | fetch.addBodyPart(bodypart); |
204 | } else if (*it == "BODYSTRUCTURE") { | 250 | } else if (*it == "BODYSTRUCTURE") { |
205 | qDebug("IMAPResponseParser: responseParser: got FETCH::BODYSTRUCTURE"); | 251 | qDebug("IMAPResponseParser: responseParser: got FETCH::BODYSTRUCTURE"); |
206 | /* | 252 | /* |
207 | QString bsdata = *(++it); | 253 | QString bsdata = *(++it); |
208 | QStringList bsList; | 254 | QStringList bsList; |
209 | parseParenthesizedList(bsdata, bsList); | 255 | parseParenthesizedList(bsdata, bsList); |
210 | 256 | ||
211 | IMAPResponseBodystructure bodystructure; | 257 | IMAPResponseBodystructure bodystructure; |
212 | QStringList attachml; | 258 | QStringList attachml; |
213 | 259 | ||
214 | for (int i = 0; i < bsList.count() - 1; i++) { | 260 | for (int i = 0; i < bsList.count() - 1; i++) { |
215 | parseParenthesizedList(bsList[0], attachml); | 261 | parseParenthesizedList(bsList[0], attachml); |
216 | 262 | ||
217 | IMAPResponseBodypart bodypart; | 263 | IMAPResponseBodypart bodypart; |
218 | bodypart.setMimeTypeMain(attachml[0] == "NIL" ? QString(0) : attachml[0]); | 264 | bodypart.setMimeTypeMain(attachml[0] == "NIL" ? QString(0) : attachml[0]); |
219 | bodypart.setMimeTypeSub(attachml[1] == "NIL" ? QString(0) : attachml[1]); | 265 | bodypart.setMimeTypeSub(attachml[1] == "NIL" ? QString(0) : attachml[1]); |
220 | bodypart.setAddData(attachml[2] == "NIL" ? QString(0) : attachml[2]); | 266 | bodypart.setAddData(attachml[2] == "NIL" ? QString(0) : attachml[2]); |
221 | // 3 (NIL) | 267 | // 3 (NIL) |
222 | // 4 (NIL) | 268 | // 4 (NIL) |
223 | bodypart.setEncoding(attachml[5] == "NIL" ? QString(0) : attachml[5]); | 269 | bodypart.setEncoding(attachml[5] == "NIL" ? QString(0) : attachml[5]); |
224 | bodypart.setSize(attachml[6] == "NIL" ? QString(0) : attachml[6]); | 270 | bodypart.setSize(attachml[6] == "NIL" ? QString(0) : attachml[6]); |
225 | bodypart.setLength(attachml[7] == "NIL" ? QString(0) : attachml[7]); | 271 | bodypart.setLength(attachml[7] == "NIL" ? QString(0) : attachml[7]); |
226 | bodypart.setAttachInfo(attachml[8] == "NIL" ? QString(0) : attachml[8]); | 272 | bodypart.setAttachInfo(attachml[8] == "NIL" ? QString(0) : attachml[8]); |
227 | // 9 (NIL) | 273 | // 9 (NIL) |
228 | // 10 (NIL) | 274 | // 10 (NIL) |
229 | 275 | ||
230 | bodystructure.addBodyPart(bodypart); | 276 | bodystructure.addBodyPart(bodypart); |
231 | } | 277 | } |
232 | */ | 278 | */ |
233 | } else if (*it == "ENVELOPE") { | 279 | } else if (*it == "ENVELOPE") { |
234 | QString envdata = *(++it); | 280 | QString envdata = *(++it); |
235 | QStringList envList; | 281 | QStringList envList; |
236 | parseParenthesizedList(envdata, envList); | 282 | parseParenthesizedList(envdata, envList); |
237 | 283 | ||
238 | IMAPResponseEnvelope envelope; | 284 | IMAPResponseEnvelope envelope; |
239 | envelope.setMailDate(envList[0] == "NIL" ? QString(0) : removeLimiters(envList[0])); | 285 | envelope.setMailDate(envList[0] == "NIL" ? QString(0) : removeLimiters(envList[0])); |
240 | envelope.setSubject(envList[1] == "NIL" ? QString(0) : removeLimiters(envList[1])); | 286 | envelope.setSubject(envList[1] == "NIL" ? QString(0) : removeLimiters(envList[1])); |
241 | 287 | ||
242 | QStringList froml, senderl, replytol, tol, ccl, bccl; | 288 | QStringList froml, senderl, replytol, tol, ccl, bccl; |
243 | QStringList froma, sendera, replytoa, toa, cca, bcca; | 289 | QStringList froma, sendera, replytoa, toa, cca, bcca; |
244 | parseParenthesizedList(envList[2], froml); | 290 | parseParenthesizedList(envList[2], froml); |
245 | parseParenthesizedList(envList[3], senderl); | 291 | parseParenthesizedList(envList[3], senderl); |
246 | parseParenthesizedList(envList[4], replytol); | 292 | parseParenthesizedList(envList[4], replytol); |
247 | parseParenthesizedList(envList[5], tol); | 293 | parseParenthesizedList(envList[5], tol); |
248 | parseParenthesizedList(envList[6], ccl); | 294 | parseParenthesizedList(envList[6], ccl); |
249 | parseParenthesizedList(envList[7], bccl); | 295 | parseParenthesizedList(envList[7], bccl); |
@@ -292,157 +338,189 @@ void IMAPResponseParser::parseResponse(const QString &data, bool tagged) | |||
292 | for (it = ccl.begin(); it != ccl.end(); it++) { | 338 | for (it = ccl.begin(); it != ccl.end(); it++) { |
293 | parseParenthesizedList(*it, cca); | 339 | parseParenthesizedList(*it, cca); |
294 | if (ccl[0] != "NIL") | 340 | if (ccl[0] != "NIL") |
295 | envelope.addCc(IMAPResponseAddress( | 341 | envelope.addCc(IMAPResponseAddress( |
296 | removeLimiters(cca[0]), | 342 | removeLimiters(cca[0]), |
297 | removeLimiters(cca[1]), | 343 | removeLimiters(cca[1]), |
298 | removeLimiters(cca[2]), | 344 | removeLimiters(cca[2]), |
299 | removeLimiters(cca[3]))); | 345 | removeLimiters(cca[3]))); |
300 | } | 346 | } |
301 | 347 | ||
302 | for (it = bccl.begin(); it != bccl.end(); it++) { | 348 | for (it = bccl.begin(); it != bccl.end(); it++) { |
303 | parseParenthesizedList(*it, bcca); | 349 | parseParenthesizedList(*it, bcca); |
304 | if (bccl[0] != "NIL") | 350 | if (bccl[0] != "NIL") |
305 | envelope.addBcc(IMAPResponseAddress( | 351 | envelope.addBcc(IMAPResponseAddress( |
306 | removeLimiters(bcca[0]), | 352 | removeLimiters(bcca[0]), |
307 | removeLimiters(bcca[1]), | 353 | removeLimiters(bcca[1]), |
308 | removeLimiters(bcca[2]), | 354 | removeLimiters(bcca[2]), |
309 | removeLimiters(bcca[3]))); | 355 | removeLimiters(bcca[3]))); |
310 | } | 356 | } |
311 | 357 | ||
312 | envelope.setInReplyTo(envList[7] == "NIL" ? QString(0) : removeLimiters(envList[7])); | 358 | envelope.setInReplyTo(envList[7] == "NIL" ? QString(0) : removeLimiters(envList[7])); |
313 | envelope.setMessageId(envList[8] == "NIL" ? QString(0) : removeLimiters(envList[8])); | 359 | envelope.setMessageId(envList[8] == "NIL" ? QString(0) : removeLimiters(envList[8])); |
314 | 360 | ||
315 | fetch.setEnvelope(envelope); | 361 | fetch.setEnvelope(envelope); |
316 | } else if (*it == "FLAGS") { | 362 | } else if (*it == "FLAGS") { |
317 | QString flagdata = *(++it); | 363 | QString flagdata = *(++it); |
318 | QStringList flags; | 364 | QStringList flags; |
319 | parseParenthesizedList(flagdata, flags); | 365 | parseParenthesizedList(flagdata, flags); |
320 | fetch.setFlags(parseFlagList(flags)); | 366 | fetch.setFlags(parseFlagList(flags)); |
321 | } else if (*it == "INTERNALDATE") { | 367 | } else if (*it == "INTERNALDATE") { |
322 | fetch.setInternalDate(removeLimiters(*(++it))); | 368 | fetch.setInternalDate(removeLimiters(*(++it))); |
323 | } else if (*it == "RFC822" || *it == "BODY[]") { | 369 | } else if (*it == "RFC822" || *it == "BODY[]") { |
324 | qDebug("IMAPResponseParser: responseParser: got FETCH::RFC822"); | 370 | qDebug("IMAPResponseParser: responseParser: got FETCH::RFC822"); |
325 | // XXX | 371 | // XXX |
326 | } else if (*it == "RFC822.HEADER" || *it == "BODY.PEEK[HEADER]") { | 372 | } else if (*it == "RFC822.HEADER" || *it == "BODY.PEEK[HEADER]") { |
327 | qDebug("IMAPResponseParser: responseParser: got FETCH::RFC822.HEADER"); | 373 | qDebug("IMAPResponseParser: responseParser: got FETCH::RFC822.HEADER"); |
328 | // XXX | 374 | // XXX |
329 | } else if (*it == "RFC822.SIZE") { | 375 | } else if (*it == "RFC822.SIZE") { |
330 | fetch.setRFC822Size(*(++it)); | 376 | fetch.setRFC822Size(*(++it)); |
331 | } else if (*it == "RFC822.TEXT" || *it == "BODY[TEXT]") { | 377 | } else if (*it == "RFC822.TEXT" || *it == "BODY[TEXT]") { |
332 | qDebug("IMAPResponseParser: responseParser: got FETCH::RFC822.TEXT"); | 378 | qDebug("IMAPResponseParser: responseParser: got FETCH::RFC822.TEXT"); |
333 | // XXX | 379 | // XXX |
334 | } else if (*it == "UID") { | 380 | } else if (*it == "UID") { |
335 | fetch.setUid(*(++it)); | 381 | fetch.setUid(*(++it)); |
336 | } | 382 | } |
337 | } | 383 | } |
338 | _iresponse.addFETCH(fetch); | 384 | _iresponse.addFETCH(fetch); |
339 | } | 385 | } |
340 | } else qWarning("IMAPResponseParser: parseResponse: Unknown response: " + response + "|"); | 386 | } else qWarning((QString("IMAPResponseParser: parseResponse: Unknown response: ") + response + "|").latin1()); |
387 | |||
341 | } | 388 | } |
342 | 389 | ||
343 | QStringList IMAPResponseParser::splitData(const QString &data, bool withBrackets) | 390 | QStringList IMAPResponseParser::splitData(const QString &data, bool withBrackets) |
344 | { | 391 | { |
345 | int b = 0; | 392 | int b = 0; |
346 | bool a = false, noappend = false, escaped = false; | 393 | bool a = false, noappend = false, escaped = false; |
347 | QString temp; | 394 | QString temp; |
348 | QStringList list; | 395 | QStringList list; |
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++) { |
351 | if (withBrackets && data[i] == '(' && !a) b++; | 400 | if (withBrackets && data[i] == '(' && !a) b++; |
352 | else if (withBrackets && data[i] == ')' && !a) b--; | 401 | else if (withBrackets && data[i] == ')' && !a) b--; |
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 | ||
359 | if ((data[i] == ' ' || i == data.length()) && b == 0 && !a) { | 436 | if ((data[i] == ' ' || i == data.length()) && b == 0 && !a) { |
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; |
363 | } | 440 | } |
364 | 441 | ||
365 | if (!noappend) temp += data[i]; | 442 | if (!noappend) temp += data[i]; |
366 | noappend = false; | 443 | noappend = false; |
367 | } | 444 | } |
368 | 445 | ||
369 | return list; | 446 | return list; |
370 | } | 447 | } |
371 | 448 | ||
372 | void IMAPResponseParser::parseParenthesizedList(const QString &data, QStringList &parsed) | 449 | void IMAPResponseParser::parseParenthesizedList(const QString &data, QStringList &parsed) |
373 | { | 450 | { |
374 | QString data_(data); | 451 | QString data_(data); |
375 | removeLimiters(data_, '(', ')'); | 452 | removeLimiters(data_, '(', ')'); |
376 | parsed = splitData(data_, true); | 453 | parsed = splitData(data_, true); |
377 | } | 454 | } |
378 | 455 | ||
379 | void IMAPResponseParser::splitTagData(const QString &line, QString &tag, QString &data) | 456 | void IMAPResponseParser::splitTagData(const QString &line, QString &tag, QString &data) |
380 | { | 457 | { |
381 | int pos; | 458 | int pos; |
382 | if ((pos = line.find(' ')) != -1) { | 459 | if ((pos = line.find(' ')) != -1) { |
383 | tag = line.left(pos); | 460 | tag = line.left(pos); |
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 | } |
387 | 464 | ||
388 | QString IMAPResponseParser::removeLimiters(QString &string, const QChar &sl, const QChar &el) | 465 | QString IMAPResponseParser::removeLimiters(QString &string, const QChar &sl, const QChar &el) |
389 | { | 466 | { |
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) { |
392 | string.truncate(string.length() - 1); | 471 | string.truncate(string.length() - 1); |
393 | string.replace(0, 1, ""); | 472 | string.replace(0, 1, ""); |
394 | 473 | ||
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]; |
398 | } | 477 | } |
399 | } | 478 | } |
400 | |||
401 | return tmpString; | 479 | return tmpString; |
402 | } | 480 | } |
403 | 481 | ||
404 | IMAPResponseEnums::IMAPResponseCode IMAPResponseParser::getResponseCode(const QString &line) | 482 | IMAPResponseEnums::IMAPResponseCode IMAPResponseParser::getResponseCode(const QString &line) |
405 | { | 483 | { |
406 | if (line.find(QRegExp((QString) "^\\[.*\\]" + ' ' + ".*")) != -1) { | 484 | if (line.find(QRegExp((QString) "^\\[.*\\]" + ' ' + ".*")) != -1) { |
407 | int pos = line.find("] "); | 485 | int pos = line.find("] "); |
408 | QString code = line.left(pos + 1).upper(); | 486 | QString code = line.left(pos + 1).upper(); |
409 | 487 | ||
410 | if (code.find(QRegExp("[ALERT]")) != -1) return ALERT; | 488 | if (code.find(QRegExp("[ALERT]")) != -1) return ALERT; |
411 | else if (code.find(QRegExp("[NEWNAME .* .*]")) != -1) return NEWNAME; // XXX | 489 | else if (code.find(QRegExp("[NEWNAME .* .*]")) != -1) return NEWNAME; // XXX |
412 | else if (code.find(QRegExp("[PARSE]")) != -1) return PARSE; | 490 | else if (code.find(QRegExp("[PARSE]")) != -1) return PARSE; |
413 | else if (code.find(QRegExp("[PERMANENTFLAGS \\d*]")) != -1) return PERMANENTFLAGS; // XXX | 491 | else if (code.find(QRegExp("[PERMANENTFLAGS \\d*]")) != -1) return PERMANENTFLAGS; // XXX |
414 | else if (code.find(QRegExp("[READ-ONLY]")) != -1) return READONLY; | 492 | else if (code.find(QRegExp("[READ-ONLY]")) != -1) return READONLY; |
415 | else if (code.find(QRegExp("[READ-WRITE]")) != -1) return READWRITE; | 493 | else if (code.find(QRegExp("[READ-WRITE]")) != -1) return READWRITE; |
416 | else if (code.find(QRegExp("[TRYCREATE]")) != -1) return TRYCREATE; | 494 | else if (code.find(QRegExp("[TRYCREATE]")) != -1) return TRYCREATE; |
417 | else if (code.find(QRegExp("[UIDVALIDITY \\d*]")) != -1) return UIDVALIDITY; // XXX | 495 | else if (code.find(QRegExp("[UIDVALIDITY \\d*]")) != -1) return UIDVALIDITY; // XXX |
418 | else if (code.find(QRegExp("[UNSEEN \\d*]")) != -1) return UNSEEN; // XXX | 496 | else if (code.find(QRegExp("[UNSEEN \\d*]")) != -1) return UNSEEN; // XXX |
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; |
422 | } | 500 | } |
423 | } | 501 | } |
424 | return NoCode; | 502 | return NoCode; |
425 | } | 503 | } |
426 | 504 | ||
427 | QValueList<IMAPResponseEnums::IMAPResponseFlags> IMAPResponseParser::parseFlagList(const QStringList &flagList) | 505 | QValueList<IMAPResponseEnums::IMAPResponseFlags> IMAPResponseParser::parseFlagList(const QStringList &flagList) |
428 | { | 506 | { |
429 | QValueList<IMAPResponseFlags> flags; | 507 | QValueList<IMAPResponseFlags> flags; |
430 | QStringList::ConstIterator it; | 508 | QStringList::ConstIterator it; |
431 | for (it = flagList.begin(); it != flagList.end(); it++) { | 509 | for (it = flagList.begin(); it != flagList.end(); it++) { |
432 | QString flag = (*it).lower(); | 510 | QString flag = (*it).lower(); |
433 | if (flag == "\\seen") flags.append(Seen); | 511 | if (flag == "\\seen") flags.append(Seen); |
434 | else if (flag == "\\answered") flags.append(Answered); | 512 | else if (flag == "\\answered") flags.append(Answered); |
435 | else if (flag == "\\flagged") flags.append(Flagged); | 513 | else if (flag == "\\flagged") flags.append(Flagged); |
436 | else if (flag == "\\deleted") flags.append(Deleted); | 514 | else if (flag == "\\deleted") flags.append(Deleted); |
437 | else if (flag == "\\draft") flags.append(Draft); | 515 | else if (flag == "\\draft") flags.append(Draft); |
438 | else if (flag == "\\recent") flags.append(Recent); | 516 | else if (flag == "\\recent") flags.append(Recent); |
439 | else if (flag == "\\noinferiors") flags.append(Noinferiors); | 517 | else if (flag == "\\noinferiors") flags.append(Noinferiors); |
440 | else if (flag == "\\noselect") flags.append(Noselect); | 518 | else if (flag == "\\noselect") flags.append(Noselect); |
441 | else if (flag == "\\marked") flags.append(Marked); | 519 | else if (flag == "\\marked") flags.append(Marked); |
442 | else if (flag == "\\unmarked") flags.append(Unmarked); | 520 | else if (flag == "\\unmarked") flags.append(Unmarked); |
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 | } |
446 | return flags; | 524 | return flags; |
447 | } | 525 | } |
448 | 526 | ||
diff --git a/noncore/unsupported/mail2/libmail/imapresponse.h b/noncore/unsupported/mail2/libmail/imapresponse.h index 73435ee..5a19b96 100644 --- a/noncore/unsupported/mail2/libmail/imapresponse.h +++ b/noncore/unsupported/mail2/libmail/imapresponse.h | |||
@@ -460,72 +460,73 @@ public: | |||
460 | void addSEARCH(IMAPResponseSEARCH search) { _searchl.append(search); } | 460 | void addSEARCH(IMAPResponseSEARCH search) { _searchl.append(search); } |
461 | void addFLAGS(IMAPResponseFLAGS flags) { _flagsl.append(flags); } | 461 | void addFLAGS(IMAPResponseFLAGS flags) { _flagsl.append(flags); } |
462 | void addEXISTS(IMAPResponseEXISTS exists) { _existsl.append(exists); } | 462 | void addEXISTS(IMAPResponseEXISTS exists) { _existsl.append(exists); } |
463 | void addRECENT(IMAPResponseRECENT recent) { _recentl.append(recent); } | 463 | void addRECENT(IMAPResponseRECENT recent) { _recentl.append(recent); } |
464 | void addEXPUNGE(IMAPResponseEXPUNGE expunge) { _expungel.append(expunge); } | 464 | void addEXPUNGE(IMAPResponseEXPUNGE expunge) { _expungel.append(expunge); } |
465 | void addFETCH(IMAPResponseFETCH fetch) { _fetchl.append(fetch); } | 465 | void addFETCH(IMAPResponseFETCH fetch) { _fetchl.append(fetch); } |
466 | 466 | ||
467 | QValueList<IMAPResponseOK> OK() { return _okl; } | 467 | QValueList<IMAPResponseOK> OK() { return _okl; } |
468 | QValueList<IMAPResponseNO> NO() { return _nol; } | 468 | QValueList<IMAPResponseNO> NO() { return _nol; } |
469 | QValueList<IMAPResponseBAD> BAD() { return _badl; } | 469 | QValueList<IMAPResponseBAD> BAD() { return _badl; } |
470 | QValueList<IMAPResponseCAPABILITY> CAPABILITY() { return _capabilityl; } | 470 | QValueList<IMAPResponseCAPABILITY> CAPABILITY() { return _capabilityl; } |
471 | QValueList<IMAPResponseLIST> LIST() { return _listl; } | 471 | QValueList<IMAPResponseLIST> LIST() { return _listl; } |
472 | QValueList<IMAPResponseLSUB> LSUB() { return _lsubl; } | 472 | QValueList<IMAPResponseLSUB> LSUB() { return _lsubl; } |
473 | QValueList<IMAPResponseSTATUS> STATUS() { return _statusl; } | 473 | QValueList<IMAPResponseSTATUS> STATUS() { return _statusl; } |
474 | QValueList<IMAPResponseSEARCH> SEARCH() { return _searchl; } | 474 | QValueList<IMAPResponseSEARCH> SEARCH() { return _searchl; } |
475 | QValueList<IMAPResponseFLAGS> FLAGS() { return _flagsl; } | 475 | QValueList<IMAPResponseFLAGS> FLAGS() { return _flagsl; } |
476 | QValueList<IMAPResponseEXISTS> EXISTS() { return _existsl; } | 476 | QValueList<IMAPResponseEXISTS> EXISTS() { return _existsl; } |
477 | QValueList<IMAPResponseRECENT> RECENT() { return _recentl; } | 477 | QValueList<IMAPResponseRECENT> RECENT() { return _recentl; } |
478 | QValueList<IMAPResponseEXPUNGE> EXPUNGE() { return _expungel; } | 478 | QValueList<IMAPResponseEXPUNGE> EXPUNGE() { return _expungel; } |
479 | QValueList<IMAPResponseFETCH> FETCH() { return _fetchl; } | 479 | QValueList<IMAPResponseFETCH> FETCH() { return _fetchl; } |
480 | 480 | ||
481 | private: | 481 | private: |
482 | QString _tag; | 482 | QString _tag; |
483 | IMAPResponseStatusResponse _response; | 483 | IMAPResponseStatusResponse _response; |
484 | 484 | ||
485 | IMAPHandler *_handler; | 485 | IMAPHandler *_handler; |
486 | 486 | ||
487 | QValueList<IMAPResponseOK> _okl; | 487 | QValueList<IMAPResponseOK> _okl; |
488 | QValueList<IMAPResponseNO> _nol; | 488 | QValueList<IMAPResponseNO> _nol; |
489 | QValueList<IMAPResponseBAD> _badl; | 489 | QValueList<IMAPResponseBAD> _badl; |
490 | QValueList<IMAPResponseCAPABILITY> _capabilityl; | 490 | QValueList<IMAPResponseCAPABILITY> _capabilityl; |
491 | QValueList<IMAPResponseLIST> _listl; | 491 | QValueList<IMAPResponseLIST> _listl; |
492 | QValueList<IMAPResponseLSUB> _lsubl; | 492 | QValueList<IMAPResponseLSUB> _lsubl; |
493 | QValueList<IMAPResponseSTATUS> _statusl; | 493 | QValueList<IMAPResponseSTATUS> _statusl; |
494 | QValueList<IMAPResponseSEARCH> _searchl; | 494 | QValueList<IMAPResponseSEARCH> _searchl; |
495 | QValueList<IMAPResponseFLAGS> _flagsl; | 495 | QValueList<IMAPResponseFLAGS> _flagsl; |
496 | QValueList<IMAPResponseEXISTS> _existsl; | 496 | QValueList<IMAPResponseEXISTS> _existsl; |
497 | QValueList<IMAPResponseRECENT> _recentl; | 497 | QValueList<IMAPResponseRECENT> _recentl; |
498 | QValueList<IMAPResponseEXPUNGE> _expungel; | 498 | QValueList<IMAPResponseEXPUNGE> _expungel; |
499 | QValueList<IMAPResponseFETCH> _fetchl; | 499 | QValueList<IMAPResponseFETCH> _fetchl; |
500 | 500 | ||
501 | }; | 501 | }; |
502 | 502 | ||
503 | class IMAPResponseParser : public QObject, public IMAPResponseEnums | 503 | class IMAPResponseParser : public QObject, public IMAPResponseEnums |
504 | { | 504 | { |
505 | Q_OBJECT | 505 | Q_OBJECT |
506 | 506 | ||
507 | public: | 507 | public: |
508 | IMAPResponseParser(const QString &data); | 508 | IMAPResponseParser(); |
509 | void parse ( const QString &data); | ||
509 | 510 | ||
510 | IMAPResponse response(); | 511 | IMAPResponse response(); |
511 | 512 | ||
512 | signals: | 513 | signals: |
513 | void needMoreData(const QString &comment); | 514 | void needMoreData(QString &data); |
514 | 515 | ||
515 | protected: | 516 | protected: |
516 | void parseResponse(const QString &data, bool tagged = false); | 517 | void parseResponse(const QString &data, bool tagged = false); |
517 | 518 | ||
518 | QStringList splitData(const QString &data, bool withBrackets); | 519 | QStringList splitData(const QString &data, bool withBrackets); |
519 | void parseParenthesizedList(const QString &data, QStringList &parsed); | 520 | void parseParenthesizedList(const QString &data, QStringList &parsed); |
520 | void splitTagData(const QString &line, QString &tag, QString &data); | 521 | void splitTagData(const QString &line, QString &tag, QString &data); |
521 | QString removeLimiters(QString &string, const QChar &sl = '"', const QChar &el = '"'); | 522 | QString removeLimiters(QString &string, const QChar &sl = '"', const QChar &el = '"'); |
522 | IMAPResponseCode getResponseCode(const QString &line); | 523 | IMAPResponseCode getResponseCode(const QString &line); |
523 | QValueList<IMAPResponseFlags> parseFlagList(const QStringList &flags); | 524 | QValueList<IMAPResponseFlags> parseFlagList(const QStringList &flags); |
524 | 525 | ||
525 | private: | 526 | private: |
526 | IMAPResponse _iresponse; | 527 | IMAPResponse _iresponse; |
527 | 528 | ||
528 | }; | 529 | }; |
529 | 530 | ||
530 | #endif | 531 | #endif |
531 | 532 | ||
diff --git a/noncore/unsupported/mail2/viewmail.cpp b/noncore/unsupported/mail2/viewmail.cpp index 3c88d99..da6924d 100644 --- a/noncore/unsupported/mail2/viewmail.cpp +++ b/noncore/unsupported/mail2/viewmail.cpp | |||
@@ -138,61 +138,61 @@ void ViewMail::slotForward() | |||
138 | if (!_gotBody) { | 138 | if (!_gotBody) { |
139 | QMessageBox::information(this, tr("Error"), tr("<p>The mail body is not yet downloaded, so you cannot forward yet."), tr("Ok")); | 139 | QMessageBox::information(this, tr("Error"), tr("<p>The mail body is not yet downloaded, so you cannot forward yet."), tr("Ok")); |
140 | return; | 140 | return; |
141 | } | 141 | } |
142 | 142 | ||
143 | QString ftext; | 143 | QString ftext; |
144 | ftext += QString("\n----- Forwarded message from %1 -----\n\n") | 144 | ftext += QString("\n----- Forwarded message from %1 -----\n\n") |
145 | .arg(_mail.envelope().from()[0].toString()); | 145 | .arg(_mail.envelope().from()[0].toString()); |
146 | if (!_mail.envelope().mailDate().isNull()) | 146 | if (!_mail.envelope().mailDate().isNull()) |
147 | ftext += QString("Date: %1\n") | 147 | ftext += QString("Date: %1\n") |
148 | .arg(_mail.envelope().mailDate()); | 148 | .arg(_mail.envelope().mailDate()); |
149 | if (!_mail.envelope().from()[0].toString().isNull()) | 149 | if (!_mail.envelope().from()[0].toString().isNull()) |
150 | ftext += QString("From: %1\n") | 150 | ftext += QString("From: %1\n") |
151 | .arg(_mail.envelope().from()[0].toString()); | 151 | .arg(_mail.envelope().from()[0].toString()); |
152 | if (!_mail.envelope().to().toString().isNull()) | 152 | if (!_mail.envelope().to().toString().isNull()) |
153 | ftext += QString("To: %1\n") | 153 | ftext += QString("To: %1\n") |
154 | .arg(_mail.envelope().to().toString()); | 154 | .arg(_mail.envelope().to().toString()); |
155 | if (!_mail.envelope().cc().toString().isNull()) | 155 | if (!_mail.envelope().cc().toString().isNull()) |
156 | ftext += QString("Cc: %1\n") | 156 | ftext += QString("Cc: %1\n") |
157 | .arg(_mail.envelope().cc().toString()); | 157 | .arg(_mail.envelope().cc().toString()); |
158 | if (!_mail.envelope().bcc().toString().isNull()) | 158 | if (!_mail.envelope().bcc().toString().isNull()) |
159 | ftext += QString("Bcc: %1\n") | 159 | ftext += QString("Bcc: %1\n") |
160 | .arg(_mail.envelope().bcc().toString()); | 160 | .arg(_mail.envelope().bcc().toString()); |
161 | if (!_mail.envelope().subject().isNull()) | 161 | if (!_mail.envelope().subject().isNull()) |
162 | ftext += QString("Subject: %1\n") | 162 | ftext += QString("Subject: %1\n") |
163 | .arg(_mail.envelope().subject()); | 163 | .arg(_mail.envelope().subject()); |
164 | 164 | ||
165 | ftext += QString("\n%1\n") | 165 | ftext += QString("\n%1\n") |
166 | .arg(_mail.bodyPart(1).data()); | 166 | .arg(_mail.bodyPart(1).data()); |
167 | 167 | ||
168 | ftext += QString("----- End forwarded message -----\n"); | 168 | ftext += QString("----- End forwarded message -----\n"); |
169 | 169 | ||
170 | SendMail sendMail; | 170 | SendMail sendMail; |
171 | sendMail.setSubject("Fwd: " + _mail.envelope().subject()); | 171 | sendMail.setSubject("Fwd: " + _mail.envelope().subject()); |
172 | sendMail.setMessage(ftext); | 172 | sendMail.setMessage(ftext); |
173 | 173 | ||
174 | Composer composer(this, 0, true); | 174 | Composer composer(this, 0, true); |
175 | composer.setSendMail(sendMail); | 175 | composer.setSendMail(sendMail); |
176 | composer.showMaximized(); | 176 | composer.showMaximized(); |
177 | composer.exec(); | 177 | composer.exec(); |
178 | } | 178 | } |
179 | 179 | ||
180 | void ViewMail::slotIMAPUid(IMAPResponse &response) | 180 | void ViewMail::slotIMAPUid(IMAPResponse &response) |
181 | { | 181 | { |
182 | disconnect(_handler, SIGNAL(gotResponse(IMAPResponse &)), this, SLOT(slotIMAPUid(IMAPResponse &))); | 182 | disconnect(_handler, SIGNAL(gotResponse(IMAPResponse &)), this, SLOT(slotIMAPUid(IMAPResponse &))); |
183 | 183 | ||
184 | if (response.statusResponse().status() == IMAPResponseEnums::OK) { | 184 | if (response.statusResponse().status() == IMAPResponseEnums::OK) { |
185 | QValueList<IMAPResponseBodyPart> bodyParts; | 185 | QValueList<IMAPResponseBodyPart> bodyParts; |
186 | bodyParts.append(response.FETCH()[0].bodyPart(1)); | 186 | bodyParts.append(response.FETCH()[0].bodyPart(0)); |
187 | _mail.setBodyParts(bodyParts); | 187 | _mail.setBodyParts(bodyParts); |
188 | 188 | ||
189 | browser->setText(QString(_mailHtml).arg(deHtml(response.FETCH()[0].bodyPart(1).data()))); | 189 | browser->setText(QString(_mailHtml).arg(deHtml(response.FETCH()[0].bodyPart(0).data()))); |
190 | 190 | ||
191 | // fillList(response.FETCH()[0].bodyStructure()); | 191 | // fillList(response.FETCH()[0].bodyStructure()); |
192 | 192 | ||
193 | _gotBody = true; | 193 | _gotBody = true; |
194 | } else { | 194 | } else { |
195 | QMessageBox::warning(this, tr("Error"), tr("<p>I was unable to retrieve the mail from the server. You can try again later or give up.</p>"), tr("Ok")); | 195 | QMessageBox::warning(this, tr("Error"), tr("<p>I was unable to retrieve the mail from the server. You can try again later or give up.</p>"), tr("Ok")); |
196 | } | 196 | } |
197 | } | 197 | } |
198 | 198 | ||