summaryrefslogtreecommitdiff
authorsandman <sandman>2002-08-06 00:55:56 (UTC)
committer sandman <sandman>2002-08-06 00:55:56 (UTC)
commitb980135ff5ce5447ca41411b6ace74ce2803fadb (patch) (unidiff)
treec02cdd16e1435855bff16e2c2707f5d5484d43f4
parentd96244956f42782f987acc2b5efb32dc1f1dd70a (diff)
downloadopie-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 (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/unsupported/mail2/libmail/configfile.cpp4
-rw-r--r--noncore/unsupported/mail2/libmail/imapbase.cpp36
-rw-r--r--noncore/unsupported/mail2/libmail/imapbase.h3
-rw-r--r--noncore/unsupported/mail2/libmail/imaphandler.cpp7
-rw-r--r--noncore/unsupported/mail2/libmail/imapresponse.cpp224
-rw-r--r--noncore/unsupported/mail2/libmail/imapresponse.h5
-rw-r--r--noncore/unsupported/mail2/viewmail.cpp4
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
@@ -1,112 +1,112 @@
1#include <qdir.h> 1#include <qdir.h>
2 2
3#include <qpe/config.h> 3#include <qpe/config.h>
4 4
5#include <stdlib.h> 5#include <stdlib.h>
6 6
7#include "configfile.h" 7#include "configfile.h"
8 8
9ConfigFile::ConfigFile() : QObject() 9ConfigFile::ConfigFile() : QObject()
10{ 10{
11 checkDirectory(); 11 checkDirectory();
12 12
13 QDir dir((QString) getenv("HOME") + "/Applications/mail/accounts"); 13 QDir dir((QString) getenv("HOME") + "/Applications/mail/accounts");
14 QStringList entries = dir.entryList("account-*"); 14 QStringList entries = dir.entryList("account-*");
15 15
16 QStringList::Iterator it; 16 QStringList::Iterator it;
17 for (it = entries.begin(); it != entries.end(); it++) { 17 for (it = entries.begin(); it != entries.end(); it++) {
18 Account account; 18 Account account;
19 19
20 Config *config = new Config((QString) getenv("HOME") + "/Applications/mail/accounts/" + *it, Config::File); 20 Config *config = new Config((QString) getenv("HOME") + "/Applications/mail/accounts/" + *it, Config::File);
21 config->setGroup("Account"); 21 config->setGroup("Account");
22 account.setAccountName((*it).replace(0, 8, "")); 22 account.setAccountName((*it).replace(0, 8, ""));
23 account.setRealName(config->readEntry("RealName")); 23 account.setRealName(config->readEntry("RealName"));
24 account.setEmail(config->readEntry("Email")); 24 account.setEmail(config->readEntry("Email"));
25 account.setOrg(config->readEntry("Organization")); 25 account.setOrg(config->readEntry("Organization"));
26 account.setImapServer(config->readEntry("ImapServer")); 26 account.setImapServer(config->readEntry("ImapServer"));
27 account.setImapPort(config->readEntry("ImapPort")); 27 account.setImapPort(config->readEntry("ImapPort"));
28 account.setSmtpServer(config->readEntry("SmtpServer")); 28 account.setSmtpServer(config->readEntry("SmtpServer"));
29 account.setSmtpPort(config->readEntry("SmtpPort")); 29 account.setSmtpPort(config->readEntry("SmtpPort"));
30 account.setUser(config->readEntry("User")); 30 account.setUser(config->readEntry("User"));
31 account.setPass(rot13(config->readEntryCrypt("Pass"))); 31 account.setPass(rot13(config->readEntryCrypt("Pass")));
32 account.setSmtpSsl(config->readBoolEntry("SmtpSsl")); 32 account.setSmtpSsl(config->readBoolEntry("SmtpSsl"));
33 account.setSmtpSslPort(config->readEntry("SmtpSslPort")); 33 account.setSmtpSslPort(config->readEntry("SmtpSslPort"));
34 account.setImapSsl(config->readBoolEntry("ImapSsl")); 34 account.setImapSsl(config->readBoolEntry("ImapSsl"));
35 account.setImapSslPort(config->readEntry("ImapSslPort")); 35 account.setImapSslPort(config->readEntry("ImapSslPort"));
36 account.setDefaultCc(config->readBoolEntry("DefaultCc")); 36 account.setDefaultCc(config->readBoolEntry("DefaultCc"));
37 account.setDefaultBcc(config->readBoolEntry("DefaultBcc")); 37 account.setDefaultBcc(config->readBoolEntry("DefaultBcc"));
38 account.setDefaultReplyTo(config->readBoolEntry("DefaultReplyTo")); 38 account.setDefaultReplyTo(config->readBoolEntry("DefaultReplyTo"));
39 account.setCc(config->readEntry("Cc")); 39 account.setCc(config->readEntry("Cc"));
40 account.setBcc(config->readEntry("Bcc")); 40 account.setBcc(config->readEntry("Bcc"));
41 account.setReplyTo(config->readEntry("ReplyTo")); 41 account.setReplyTo(config->readEntry("ReplyTo"));
42 account.setSignature(config->readEntry("Signature").replace(QRegExp("<br>"), "\n")); 42 account.setSignature(config->readEntry("Signature").replace(QRegExp("<br>"), "\n"));
43 43
44 _accounts.append(account); 44 _accounts.append(account);
45 } 45 }
46} 46}
47 47
48QValueList<Account> ConfigFile::getAccounts() 48QValueList<Account> ConfigFile::getAccounts()
49{ 49{
50 ConfigFile *configFile = new ConfigFile(); 50 ConfigFile *configFile = new ConfigFile();
51 return configFile->_accounts; 51 return configFile->_accounts;
52} 52}
53 53
54void ConfigFile::updateAccount(Account account) 54void ConfigFile::updateAccount(Account account)
55{ 55{
56 checkDirectory(); 56 checkDirectory();
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
84void ConfigFile::deleteAccount(Account account) 84void 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
90void ConfigFile::checkDirectory() 90void 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
98QString ConfigFile::rot13(const QString &input) 98QString 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
@@ -1,110 +1,132 @@
1#include <qsocket.h> 1#include <qsocket.h>
2#include <qtimer.h> 2#include <qtimer.h>
3 3
4#include "imapbase.h" 4#include "imapbase.h"
5 5
6IMAPBase::IMAPBase(const Account &account) 6IMAPBase::IMAPBase(const Account &account)
7 : QObject(), _account(account) 7 : QObject(), _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
24void IMAPBase::sendCommand(const QString &command) 24void 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
30void IMAPBase::disconnect() 30void 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
37void IMAPBase::makeConnect() 37void 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
46void IMAPBase::writeCommands() 46void 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
66void IMAPBase::slotError(int err) 70void 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
79void IMAPBase::slotHostFound() 83void IMAPBase::slotHostFound()
80{ 84{
81 emit hostFound(); 85 emit hostFound();
82} 86}
83 87
84void IMAPBase::slotConnected() 88void IMAPBase::slotConnected()
85{ 89{
86 _connected = true; 90 _connected = true;
87 emit connected(); 91 emit connected();
88} 92}
89 93
90void IMAPBase::slotDisconnected() 94void 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
96void IMAPBase::slotDataAvailiable() 102void 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
126void 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
8class QSocket; 8class QSocket;
9 9
10class IMAPBase : public QObject 10class IMAPBase : public QObject
11{ 11{
12 Q_OBJECT 12 Q_OBJECT
13 13
14public: 14public:
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
24signals: 24signals:
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
32protected: 32protected:
33 void makeConnect(); 33 void makeConnect();
34 34
35protected slots: 35protected 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
43private: 44private:
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
@@ -1,343 +1,346 @@
1#include "imapresponse.h" 1#include "imapresponse.h"
2#include "imaphandler.h" 2#include "imaphandler.h"
3#include "imapbase.h" 3#include "imapbase.h"
4 4
5IMAPHandler::IMAPHandler(const Account &account) 5IMAPHandler::IMAPHandler(const Account &account)
6 : QObject(), _account(account) 6 : QObject(), _account(account)
7{ 7{
8 _ready = false; 8 _ready = false;
9 _loggingin = false; 9 _loggingin = false;
10 _loggedin = false; 10 _loggedin = false;
11 _tag = 0; 11 _tag = 0;
12 _ibase = new IMAPBase(account); 12 _ibase = new IMAPBase(account);
13 13
14 connect(_ibase, SIGNAL(dataReceived(const QString &)), SLOT(slotDataReceived(const QString &))); 14 connect(_ibase, SIGNAL(dataReceived(const QString &)), SLOT(slotDataReceived(const QString &)));
15 connect(_ibase, SIGNAL(lookingUpHost()), SLOT(slotLookingUpHost())); 15 connect(_ibase, SIGNAL(lookingUpHost()), SLOT(slotLookingUpHost()));
16 connect(_ibase, SIGNAL(hostFound()), SLOT(slotHostFound())); 16 connect(_ibase, SIGNAL(hostFound()), SLOT(slotHostFound()));
17 connect(_ibase, SIGNAL(connected()), SLOT(slotConnected())); 17 connect(_ibase, SIGNAL(connected()), SLOT(slotConnected()));
18 connect(_ibase, SIGNAL(disconnected()), SLOT(slotDisconnected())); 18 connect(_ibase, SIGNAL(disconnected()), SLOT(slotDisconnected()));
19 connect(_ibase, SIGNAL(error(int)), SLOT(slotError(int))); 19 connect(_ibase, SIGNAL(error(int)), SLOT(slotError(int)));
20} 20}
21 21
22void IMAPHandler::doLogin() 22void IMAPHandler::doLogin()
23{ 23{
24 if (_loggedin) return; 24 if (_loggedin) return;
25 if (_loggingin) return; 25 if (_loggingin) return;
26 26
27 _loggingin = true; 27 _loggingin = true;
28 iLogin(_account.user(), _account.pass()); 28 iLogin(_account.user(), _account.pass());
29} 29}
30 30
31QString IMAPHandler::iCapability() 31QString IMAPHandler::iCapability()
32{ 32{
33 _ibase->sendCommand(QString("%1 CAPABILITY\r\n") 33 _ibase->sendCommand(QString("%1 CAPABILITY\r\n")
34 .arg(tag())); 34 .arg(tag()));
35 return tag(false); 35 return tag(false);
36} 36}
37 37
38QString IMAPHandler::iNoop() 38QString IMAPHandler::iNoop()
39{ 39{
40 _ibase->sendCommand(QString("%1 NOOP\r\n") 40 _ibase->sendCommand(QString("%1 NOOP\r\n")
41 .arg(tag())); 41 .arg(tag()));
42 return tag(false); 42 return tag(false);
43} 43}
44 44
45QString IMAPHandler::iLogout() 45QString IMAPHandler::iLogout()
46{ 46{
47 _ibase->sendCommand(QString("%1 LOGOUT\r\n") 47 _ibase->sendCommand(QString("%1 LOGOUT\r\n")
48 .arg(tag())); 48 .arg(tag()));
49 return tag(false); 49 return tag(false);
50} 50}
51 51
52QString IMAPHandler::iAuthenticate(const QString &mechanism) 52QString IMAPHandler::iAuthenticate(const QString &mechanism)
53{ 53{
54 _ibase->sendCommand(QString("%1 AUTHENTICATE \"%2\"\r\n") 54 _ibase->sendCommand(QString("%1 AUTHENTICATE \"%2\"\r\n")
55 .arg(tag()) 55 .arg(tag())
56 .arg(escape(mechanism))); 56 .arg(escape(mechanism)));
57 return tag(false); 57 return tag(false);
58} 58}
59 59
60QString IMAPHandler::iLogin(const QString &user, const QString &pass) 60QString IMAPHandler::iLogin(const QString &user, const QString &pass)
61{ 61{
62 _ibase->sendCommand(QString("%1 LOGIN \"%2\" \"%3\"\r\n") 62 _ibase->sendCommand(QString("%1 LOGIN \"%2\" \"%3\"\r\n")
63 .arg(tag()) 63 .arg(tag())
64 .arg(escape(user)) 64 .arg(escape(user))
65 .arg(escape(pass))); 65 .arg(escape(pass)));
66 return tag(false); 66 return tag(false);
67} 67}
68 68
69QString IMAPHandler::iSelect(const QString &mailbox) 69QString IMAPHandler::iSelect(const QString &mailbox)
70{ 70{
71 doLogin(); 71 doLogin();
72 72
73 _ibase->sendCommand(QString("%1 SELECT \"%2\"\r\n") 73 _ibase->sendCommand(QString("%1 SELECT \"%2\"\r\n")
74 .arg(tag()) 74 .arg(tag())
75 .arg(escape(mailbox))); 75 .arg(escape(mailbox)));
76 return tag(false); 76 return tag(false);
77} 77}
78 78
79QString IMAPHandler::iExamine(const QString &mailbox) 79QString IMAPHandler::iExamine(const QString &mailbox)
80{ 80{
81 doLogin(); 81 doLogin();
82 82
83 _ibase->sendCommand(QString("%1 EXAMINE \"%2\"\r\n") 83 _ibase->sendCommand(QString("%1 EXAMINE \"%2\"\r\n")
84 .arg(tag()) 84 .arg(tag())
85 .arg(escape(mailbox))); 85 .arg(escape(mailbox)));
86 return tag(false); 86 return tag(false);
87} 87}
88 88
89QString IMAPHandler::iCreate(const QString &mailbox) 89QString IMAPHandler::iCreate(const QString &mailbox)
90{ 90{
91 doLogin(); 91 doLogin();
92 92
93 _ibase->sendCommand(QString("%1 CREATE \"%2\"\r\n") 93 _ibase->sendCommand(QString("%1 CREATE \"%2\"\r\n")
94 .arg(tag()) 94 .arg(tag())
95 .arg(escape(mailbox))); 95 .arg(escape(mailbox)));
96 return tag(false); 96 return tag(false);
97} 97}
98 98
99QString IMAPHandler::iDelete(const QString &mailbox) 99QString IMAPHandler::iDelete(const QString &mailbox)
100{ 100{
101 doLogin(); 101 doLogin();
102 102
103 _ibase->sendCommand(QString("%1 DELETE \"%2\"\r\n") 103 _ibase->sendCommand(QString("%1 DELETE \"%2\"\r\n")
104 .arg(tag()) 104 .arg(tag())
105 .arg(escape(mailbox))); 105 .arg(escape(mailbox)));
106 return tag(false); 106 return tag(false);
107} 107}
108 108
109QString IMAPHandler::iRename(const QString &mailbox, const QString &newMailbox) 109QString IMAPHandler::iRename(const QString &mailbox, const QString &newMailbox)
110{ 110{
111 doLogin(); 111 doLogin();
112 112
113 _ibase->sendCommand(QString("%1 RENAME \"%2\" \"%3\"\r\n") 113 _ibase->sendCommand(QString("%1 RENAME \"%2\" \"%3\"\r\n")
114 .arg(tag()) 114 .arg(tag())
115 .arg(escape(mailbox)) 115 .arg(escape(mailbox))
116 .arg(escape(newMailbox))); 116 .arg(escape(newMailbox)));
117 return tag(false); 117 return tag(false);
118} 118}
119 119
120QString IMAPHandler::iSubscribe(const QString &mailbox) 120QString IMAPHandler::iSubscribe(const QString &mailbox)
121{ 121{
122 doLogin(); 122 doLogin();
123 123
124 _ibase->sendCommand(QString("%1 SUBSCRIBE \"%2\"\r\n") 124 _ibase->sendCommand(QString("%1 SUBSCRIBE \"%2\"\r\n")
125 .arg(tag()) 125 .arg(tag())
126 .arg(escape(mailbox))); 126 .arg(escape(mailbox)));
127 return tag(false); 127 return tag(false);
128} 128}
129 129
130QString IMAPHandler::iUnsubscribe(const QString &mailbox) 130QString IMAPHandler::iUnsubscribe(const QString &mailbox)
131{ 131{
132 doLogin(); 132 doLogin();
133 133
134 _ibase->sendCommand(QString("%1 UNSUBSCRIBE \"%2\"\r\n") 134 _ibase->sendCommand(QString("%1 UNSUBSCRIBE \"%2\"\r\n")
135 .arg(tag()) 135 .arg(tag())
136 .arg(escape(mailbox))); 136 .arg(escape(mailbox)));
137 return tag(false); 137 return tag(false);
138} 138}
139 139
140QString IMAPHandler::iList(const QString &reference, const QString &mailbox) 140QString IMAPHandler::iList(const QString &reference, const QString &mailbox)
141{ 141{
142 doLogin(); 142 doLogin();
143 143
144 _ibase->sendCommand(QString("%1 LIST \"%2\" \"%3\"\r\n") 144 _ibase->sendCommand(QString("%1 LIST \"%2\" \"%3\"\r\n")
145 .arg(tag()) 145 .arg(tag())
146 .arg(escape(reference)) 146 .arg(escape(reference))
147 .arg(escape(mailbox))); 147 .arg(escape(mailbox)));
148 return tag(false); 148 return tag(false);
149} 149}
150 150
151QString IMAPHandler::iLsub(const QString &reference, const QString &mailbox) 151QString IMAPHandler::iLsub(const QString &reference, const QString &mailbox)
152{ 152{
153 doLogin(); 153 doLogin();
154 154
155 _ibase->sendCommand(QString("%1 LSUB \"%2\" \"%3\"\r\n") 155 _ibase->sendCommand(QString("%1 LSUB \"%2\" \"%3\"\r\n")
156 .arg(tag()) 156 .arg(tag())
157 .arg(escape(reference)) 157 .arg(escape(reference))
158 .arg(escape(mailbox))); 158 .arg(escape(mailbox)));
159 return tag(false); 159 return tag(false);
160} 160}
161 161
162QString IMAPHandler::iStatus(const QString &mailbox, const QString &items) 162QString IMAPHandler::iStatus(const QString &mailbox, const QString &items)
163{ 163{
164 doLogin(); 164 doLogin();
165 165
166 _ibase->sendCommand(QString("%1 STATUS \"%2\" (%3)\r\n") 166 _ibase->sendCommand(QString("%1 STATUS \"%2\" (%3)\r\n")
167 .arg(tag()) 167 .arg(tag())
168 .arg(escape(mailbox)) 168 .arg(escape(mailbox))
169 .arg(escape(items))); 169 .arg(escape(items)));
170 return tag(false); 170 return tag(false);
171} 171}
172 172
173QString IMAPHandler::iAppend(const QString &mailbox, const QString &literal, const QString &flags, const QString &datetime) 173QString IMAPHandler::iAppend(const QString &mailbox, const QString &literal, const QString &flags, const QString &datetime)
174{ 174{
175 doLogin(); 175 doLogin();
176 176
177 _ibase->sendCommand(QString("%1 APPEND \"%2\" (%3) \"%4\" {%5}\r\n%6\r\n") 177 _ibase->sendCommand(QString("%1 APPEND \"%2\" (%3) \"%4\" {%5}\r\n%6\r\n")
178 .arg(tag()) 178 .arg(tag())
179 .arg(escape(mailbox)) 179 .arg(escape(mailbox))
180 .arg(flags) 180 .arg(flags)
181 .arg(escape(datetime)) 181 .arg(escape(datetime))
182 .arg(literal.length()) 182 .arg(literal.length())
183 .arg(literal)); 183 .arg(literal));
184 return tag(false); 184 return tag(false);
185} 185}
186 186
187QString IMAPHandler::iCheck() 187QString IMAPHandler::iCheck()
188{ 188{
189 doLogin(); 189 doLogin();
190 190
191 _ibase->sendCommand(QString("%1 CHECK\r\n") 191 _ibase->sendCommand(QString("%1 CHECK\r\n")
192 .arg(tag())); 192 .arg(tag()));
193 return tag(false); 193 return tag(false);
194} 194}
195 195
196QString IMAPHandler::iClose() 196QString IMAPHandler::iClose()
197{ 197{
198 doLogin(); 198 doLogin();
199 199
200 _ibase->sendCommand(QString("%1 CLOSE\r\n") 200 _ibase->sendCommand(QString("%1 CLOSE\r\n")
201 .arg(tag())); 201 .arg(tag()));
202 return tag(false); 202 return tag(false);
203} 203}
204 204
205QString IMAPHandler::iExpunge() 205QString IMAPHandler::iExpunge()
206{ 206{
207 doLogin(); 207 doLogin();
208 208
209 _ibase->sendCommand(QString("%1 EXPUNGE\r\n") 209 _ibase->sendCommand(QString("%1 EXPUNGE\r\n")
210 .arg(tag())); 210 .arg(tag()));
211 return tag(false); 211 return tag(false);
212} 212}
213 213
214QString IMAPHandler::iSearch(const QString &search, const QString &charset) 214QString IMAPHandler::iSearch(const QString &search, const QString &charset)
215{ 215{
216 doLogin(); 216 doLogin();
217 217
218 _ibase->sendCommand(QString("%1 SEARCH %2 %3\r\n") 218 _ibase->sendCommand(QString("%1 SEARCH %2 %3\r\n")
219 .arg(tag()) 219 .arg(tag())
220 .arg(charset.isEmpty() ? QString(0) : escape(charset)) 220 .arg(charset.isEmpty() ? QString(0) : escape(charset))
221 .arg(search)); 221 .arg(search));
222 return tag(false); 222 return tag(false);
223} 223}
224 224
225QString IMAPHandler::iFetch(const QString &message, const QString &items) 225QString IMAPHandler::iFetch(const QString &message, const QString &items)
226{ 226{
227 doLogin(); 227 doLogin();
228 228
229 _ibase->sendCommand(QString("%1 FETCH %2 (%3)\r\n") 229 _ibase->sendCommand(QString("%1 FETCH %2 (%3)\r\n")
230 .arg(tag()) 230 .arg(tag())
231 .arg(message) 231 .arg(message)
232 .arg(items)); 232 .arg(items));
233 return tag(false); 233 return tag(false);
234} 234}
235 235
236QString IMAPHandler::iStore(const QString &message, const QString &items) 236QString IMAPHandler::iStore(const QString &message, const QString &items)
237{ 237{
238 doLogin(); 238 doLogin();
239 239
240 _ibase->sendCommand(QString("%1 STORE %2 %3\r\n") 240 _ibase->sendCommand(QString("%1 STORE %2 %3\r\n")
241 .arg(tag()) 241 .arg(tag())
242 .arg(message) 242 .arg(message)
243 .arg(items)); 243 .arg(items));
244 return tag(false); 244 return tag(false);
245} 245}
246 246
247QString IMAPHandler::iCopy(const QString &message, const QString &mailbox) 247QString IMAPHandler::iCopy(const QString &message, const QString &mailbox)
248{ 248{
249 doLogin(); 249 doLogin();
250 250
251 _ibase->sendCommand(QString("%1 COPY %2 \"%3\"\r\n") 251 _ibase->sendCommand(QString("%1 COPY %2 \"%3\"\r\n")
252 .arg(tag()) 252 .arg(tag())
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
258QString IMAPHandler::iUid(const QString &command, const QString &arguments) 258QString 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
269QString IMAPHandler::iX(const QString &commandAtom, const QString &arguments) 269QString 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
280QString IMAPHandler::escape(const QString &in) 280QString 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
286QString IMAPHandler::tag(bool count) 286QString 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
291void IMAPHandler::slotDataReceived(const QString &data) 291void 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
318void IMAPHandler::slotLookingUpHost() 321void IMAPHandler::slotLookingUpHost()
319{ 322{
320 emit IMAPLookingUpHost(); 323 emit IMAPLookingUpHost();
321} 324}
322 325
323void IMAPHandler::slotHostFound() 326void IMAPHandler::slotHostFound()
324{ 327{
325 emit IMAPHostFound(); 328 emit IMAPHostFound();
326} 329}
327 330
328void IMAPHandler::slotConnected() 331void IMAPHandler::slotConnected()
329{ 332{
330 emit IMAPConnected(); 333 emit IMAPConnected();
331} 334}
332 335
333void IMAPHandler::slotDisconnected() 336void IMAPHandler::slotDisconnected()
334{ 337{
335 _loggedin = false; 338 _loggedin = false;
336 emit IMAPDisconnected(); 339 emit IMAPDisconnected();
337} 340}
338 341
339void IMAPHandler::slotError(int err) 342void 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,448 +1,526 @@
1#include "imapresponse.h" 1#include "imapresponse.h"
2 2
3static QString _previousData;
4static unsigned int _neededData;
5 3
6IMAPResponseParser::IMAPResponseParser(const QString &data) 4IMAPResponseParser::IMAPResponseParser()
5{
6}
7
8void 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
60IMAPResponse IMAPResponseParser::response() 91IMAPResponse IMAPResponseParser::response()
61{ 92{
62 return _iresponse; 93 return _iresponse;
63} 94}
64 95
65void IMAPResponseParser::parseResponse(const QString &data, bool tagged) 96void 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);
250 296
251 QStringList::Iterator it; 297 QStringList::Iterator it;
252 for (it = froml.begin(); it != froml.end(); it++) { 298 for (it = froml.begin(); it != froml.end(); it++) {
253 parseParenthesizedList(*it, froma); 299 parseParenthesizedList(*it, froma);
254 if (froml[0] != "NIL") 300 if (froml[0] != "NIL")
255 envelope.addFrom(IMAPResponseAddress( 301 envelope.addFrom(IMAPResponseAddress(
256 removeLimiters(froma[0]), 302 removeLimiters(froma[0]),
257 removeLimiters(froma[1]), 303 removeLimiters(froma[1]),
258 removeLimiters(froma[2]), 304 removeLimiters(froma[2]),
259 removeLimiters(froma[3]))); 305 removeLimiters(froma[3])));
260 } 306 }
261 307
262 for (it = senderl.begin(); it != senderl.end(); it++) { 308 for (it = senderl.begin(); it != senderl.end(); it++) {
263 parseParenthesizedList(*it, sendera); 309 parseParenthesizedList(*it, sendera);
264 if (senderl[0] != "NIL") 310 if (senderl[0] != "NIL")
265 envelope.addSender(IMAPResponseAddress( 311 envelope.addSender(IMAPResponseAddress(
266 removeLimiters(sendera[0]), 312 removeLimiters(sendera[0]),
267 removeLimiters(sendera[1]), 313 removeLimiters(sendera[1]),
268 removeLimiters(sendera[2]), 314 removeLimiters(sendera[2]),
269 removeLimiters(sendera[3]))); 315 removeLimiters(sendera[3])));
270 } 316 }
271 317
272 for (it = replytol.begin(); it != replytol.end(); it++) { 318 for (it = replytol.begin(); it != replytol.end(); it++) {
273 parseParenthesizedList(*it, replytoa); 319 parseParenthesizedList(*it, replytoa);
274 if (replytol[0] != "NIL") 320 if (replytol[0] != "NIL")
275 envelope.addReplyTo(IMAPResponseAddress( 321 envelope.addReplyTo(IMAPResponseAddress(
276 removeLimiters(replytoa[0]), 322 removeLimiters(replytoa[0]),
277 removeLimiters(replytoa[1]), 323 removeLimiters(replytoa[1]),
278 removeLimiters(replytoa[2]), 324 removeLimiters(replytoa[2]),
279 removeLimiters(replytoa[3]))); 325 removeLimiters(replytoa[3])));
280 } 326 }
281 327
282 for (it = tol.begin(); it != tol.end(); it++) { 328 for (it = tol.begin(); it != tol.end(); it++) {
283 parseParenthesizedList(*it, toa); 329 parseParenthesizedList(*it, toa);
284 if (tol[0] != "NIL") 330 if (tol[0] != "NIL")
285 envelope.addTo(IMAPResponseAddress( 331 envelope.addTo(IMAPResponseAddress(
286 removeLimiters(toa[0]), 332 removeLimiters(toa[0]),
287 removeLimiters(toa[1]), 333 removeLimiters(toa[1]),
288 removeLimiters(toa[2]), 334 removeLimiters(toa[2]),
289 removeLimiters(toa[3]))); 335 removeLimiters(toa[3])));
290 } 336 }
291 337
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
343QStringList IMAPResponseParser::splitData(const QString &data, bool withBrackets) 390QStringList 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
372void IMAPResponseParser::parseParenthesizedList(const QString &data, QStringList &parsed) 449void 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
379void IMAPResponseParser::splitTagData(const QString &line, QString &tag, QString &data) 456void 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
388QString IMAPResponseParser::removeLimiters(QString &string, const QChar &sl, const QChar &el) 465QString 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
404IMAPResponseEnums::IMAPResponseCode IMAPResponseParser::getResponseCode(const QString &line) 482IMAPResponseEnums::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
427QValueList<IMAPResponseEnums::IMAPResponseFlags> IMAPResponseParser::parseFlagList(const QStringList &flagList) 505QValueList<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
@@ -1,531 +1,532 @@
1#ifndef IMAPRESPONSE_H 1#ifndef IMAPRESPONSE_H
2#define IMAPRESPONSE_H 2#define IMAPRESPONSE_H
3 3
4#include <qobject.h> 4#include <qobject.h>
5 5
6 #define MAX_BODYPARTS 50 6 #define MAX_BODYPARTS 50
7 7
8class IMAPHandler; 8class IMAPHandler;
9 9
10class IMAPResponseEnums 10class IMAPResponseEnums
11{ 11{
12public: 12public:
13 enum IMAPResponseStatus { 13 enum IMAPResponseStatus {
14 OK, NO, BAD, PREAUTH, BYE, UnknownStatus = 0 14 OK, NO, BAD, PREAUTH, BYE, UnknownStatus = 0
15 }; 15 };
16 16
17 enum IMAPResponseFlags { 17 enum IMAPResponseFlags {
18 Seen, Answered, Flagged, Deleted, Draft, Recent, 18 Seen, Answered, Flagged, Deleted, Draft, Recent,
19 Noinferiors, Noselect, Marked, Unmarked, UnknownFlag = 0 19 Noinferiors, Noselect, Marked, Unmarked, UnknownFlag = 0
20 }; 20 };
21 21
22 enum IMAPResponseCode { 22 enum IMAPResponseCode {
23 ALERT, NEWNAME, PARSE, PERMANENTFLAGS, READONLY, READWRITE, 23 ALERT, NEWNAME, PARSE, PERMANENTFLAGS, READONLY, READWRITE,
24 TRYCREATE, UIDVALIDITY, UNSEEN, NoCode, UnknownCode = 0 24 TRYCREATE, UIDVALIDITY, UNSEEN, NoCode, UnknownCode = 0
25 }; 25 };
26 26
27}; 27};
28 28
29class IMAPResponseAddress 29class IMAPResponseAddress
30{ 30{
31public: 31public:
32 IMAPResponseAddress(QString name = 0, QString adl = 0, QString mailbox = 0, QString host = 0) 32 IMAPResponseAddress(QString name = 0, QString adl = 0, QString mailbox = 0, QString host = 0)
33 { 33 {
34 _name = name; 34 _name = name;
35 _adl = adl; 35 _adl = adl;
36 _mailbox = mailbox; 36 _mailbox = mailbox;
37 _host = host; 37 _host = host;
38 } 38 }
39 39
40 void setName(QString name) { _name = name; } 40 void setName(QString name) { _name = name; }
41 QString name() { return _name; } 41 QString name() { return _name; }
42 void setAdl(QString adl) { _adl = adl; } 42 void setAdl(QString adl) { _adl = adl; }
43 QString adl() { return _adl; } 43 QString adl() { return _adl; }
44 void setMailbox(QString mailbox) { _mailbox = mailbox; } 44 void setMailbox(QString mailbox) { _mailbox = mailbox; }
45 QString mailbox() { return _mailbox; } 45 QString mailbox() { return _mailbox; }
46 void setHost(QString host) { _host = host; } 46 void setHost(QString host) { _host = host; }
47 QString host() { return _host; } 47 QString host() { return _host; }
48 48
49 QString toString() 49 QString toString()
50 { 50 {
51 if (_name.isNull() && _mailbox.isNull() && _host.isNull()) 51 if (_name.isNull() && _mailbox.isNull() && _host.isNull())
52 return QString(0); 52 return QString(0);
53 if (_name != _mailbox + "@" + _host) 53 if (_name != _mailbox + "@" + _host)
54 return _name + " <" + _mailbox + "@" + _host + ">"; 54 return _name + " <" + _mailbox + "@" + _host + ">";
55 else 55 else
56 return _name; 56 return _name;
57 } 57 }
58 58
59 QString email() 59 QString email()
60 { 60 {
61 if (_host.isEmpty()) return _mailbox; 61 if (_host.isEmpty()) return _mailbox;
62 else return _mailbox + "@" + _host; 62 else return _mailbox + "@" + _host;
63 } 63 }
64 64
65private: 65private:
66 QString _name, _adl, _mailbox, _host; 66 QString _name, _adl, _mailbox, _host;
67 67
68}; 68};
69 69
70class IMAPResponseAddressList : public QValueList<IMAPResponseAddress> 70class IMAPResponseAddressList : public QValueList<IMAPResponseAddress>
71{ 71{
72public: 72public:
73 IMAPResponseAddressList() 73 IMAPResponseAddressList()
74 : QValueList<IMAPResponseAddress>() 74 : QValueList<IMAPResponseAddress>()
75 { 75 {
76 76
77 } 77 }
78 78
79 QString toString() 79 QString toString()
80 { 80 {
81 QString string; 81 QString string;
82 IMAPResponseAddressList::Iterator it; 82 IMAPResponseAddressList::Iterator it;
83 for (it = this->begin(); it != this->end(); it++) { 83 for (it = this->begin(); it != this->end(); it++) {
84 QString tmp = (*it).toString(); 84 QString tmp = (*it).toString();
85 if (!tmp.isNull() && string.isEmpty()) string = tmp; 85 if (!tmp.isNull() && string.isEmpty()) string = tmp;
86 else if (!tmp.isNull()) string += ", " + tmp; 86 else if (!tmp.isNull()) string += ", " + tmp;
87 } 87 }
88 return string; 88 return string;
89 } 89 }
90 90
91}; 91};
92 92
93class IMAPResponseBody 93class IMAPResponseBody
94{ 94{
95public: 95public:
96 void setData(QString data) { _data = data; } 96 void setData(QString data) { _data = data; }
97 QString data() { return _data; } 97 QString data() { return _data; }
98 98
99private: 99private:
100 QString _data; 100 QString _data;
101 101
102}; 102};
103 103
104class IMAPResponseBodyPart : public IMAPResponseBody 104class IMAPResponseBodyPart : public IMAPResponseBody
105{ 105{
106public: 106public:
107 void setPart(QString part) { _part = part; } 107 void setPart(QString part) { _part = part; }
108 QString part() { return _part; } 108 QString part() { return _part; }
109 109
110private: 110private:
111 QString _part; 111 QString _part;
112 112
113}; 113};
114 114
115class IMAPResponseEnvelope 115class IMAPResponseEnvelope
116{ 116{
117public: 117public:
118 void setMailDate(QString date) { _date = date; } 118 void setMailDate(QString date) { _date = date; }
119 QString mailDate() { return _date; } 119 QString mailDate() { return _date; }
120 void setSubject(QString subject) { _subject = subject; } 120 void setSubject(QString subject) { _subject = subject; }
121 QString subject() { return _subject; } 121 QString subject() { return _subject; }
122 void addFrom(IMAPResponseAddress from) { _from.append(from); } 122 void addFrom(IMAPResponseAddress from) { _from.append(from); }
123 IMAPResponseAddressList from() { return _from; } 123 IMAPResponseAddressList from() { return _from; }
124 void addSender(IMAPResponseAddress sender) { _sender.append(sender); } 124 void addSender(IMAPResponseAddress sender) { _sender.append(sender); }
125 IMAPResponseAddressList sender() { return _sender; } 125 IMAPResponseAddressList sender() { return _sender; }
126 void addReplyTo(IMAPResponseAddress replyTo) { _replyTo.append(replyTo); } 126 void addReplyTo(IMAPResponseAddress replyTo) { _replyTo.append(replyTo); }
127 IMAPResponseAddressList replyTo() { return _replyTo; } 127 IMAPResponseAddressList replyTo() { return _replyTo; }
128 void addTo(IMAPResponseAddress to) { _to.append(to); } 128 void addTo(IMAPResponseAddress to) { _to.append(to); }
129 IMAPResponseAddressList to() { return _to; } 129 IMAPResponseAddressList to() { return _to; }
130 void addCc(IMAPResponseAddress cc) { _cc.append(cc); } 130 void addCc(IMAPResponseAddress cc) { _cc.append(cc); }
131 IMAPResponseAddressList cc() { return _cc; } 131 IMAPResponseAddressList cc() { return _cc; }
132 void addBcc(IMAPResponseAddress bcc) { _bcc.append(bcc); } 132 void addBcc(IMAPResponseAddress bcc) { _bcc.append(bcc); }
133 IMAPResponseAddressList bcc() { return _bcc; } 133 IMAPResponseAddressList bcc() { return _bcc; }
134 void setInReplyTo(QString inReplyTo) { _inReplyTo = inReplyTo; } 134 void setInReplyTo(QString inReplyTo) { _inReplyTo = inReplyTo; }
135 QString inReplyTo() { return _inReplyTo; } 135 QString inReplyTo() { return _inReplyTo; }
136 void setMessageId(QString messageId) { _messageId = messageId; } 136 void setMessageId(QString messageId) { _messageId = messageId; }
137 QString messageId() { return _messageId; } 137 QString messageId() { return _messageId; }
138 138
139private: 139private:
140 QString _date, _subject, _inReplyTo, _messageId; 140 QString _date, _subject, _inReplyTo, _messageId;
141 IMAPResponseAddressList _from, _sender, _replyTo, _to, _cc, _bcc; 141 IMAPResponseAddressList _from, _sender, _replyTo, _to, _cc, _bcc;
142 142
143}; 143};
144 144
145class IMAPResponseStatusResponse : public IMAPResponseEnums 145class IMAPResponseStatusResponse : public IMAPResponseEnums
146{ 146{
147public: 147public:
148 IMAPResponseStatusResponse(IMAPResponseStatus status = (IMAPResponseStatus)0, QString comment = 0, IMAPResponseCode code = (IMAPResponseCode)0) 148 IMAPResponseStatusResponse(IMAPResponseStatus status = (IMAPResponseStatus)0, QString comment = 0, IMAPResponseCode code = (IMAPResponseCode)0)
149 { 149 {
150 _status = status; 150 _status = status;
151 _comment = comment; 151 _comment = comment;
152 _code = code; 152 _code = code;
153 } 153 }
154 154
155 void setStatus(IMAPResponseStatus status) { _status = status; } 155 void setStatus(IMAPResponseStatus status) { _status = status; }
156 IMAPResponseStatus status() { return _status; } 156 IMAPResponseStatus status() { return _status; }
157 void setComment(QString comment) { _comment = comment; } 157 void setComment(QString comment) { _comment = comment; }
158 QString comment() { return _comment; } 158 QString comment() { return _comment; }
159 void setResponseCode(IMAPResponseCode code) { _code = code; } 159 void setResponseCode(IMAPResponseCode code) { _code = code; }
160 IMAPResponseCode responseCode() { return _code; } 160 IMAPResponseCode responseCode() { return _code; }
161 161
162 void setExitedUnexpected(bool exitu) { _exitu = exitu; } 162 void setExitedUnexpected(bool exitu) { _exitu = exitu; }
163 bool exitedUnexpected() { return _exitu; } 163 bool exitedUnexpected() { return _exitu; }
164 164
165private: 165private:
166 IMAPResponseStatus _status; 166 IMAPResponseStatus _status;
167 QString _comment; 167 QString _comment;
168 IMAPResponseCode _code; 168 IMAPResponseCode _code;
169 bool _exitu; 169 bool _exitu;
170 170
171}; 171};
172 172
173class IMAPResponseOK : public IMAPResponseEnums 173class IMAPResponseOK : public IMAPResponseEnums
174{ 174{
175public: 175public:
176 IMAPResponseOK(QString comment = 0, IMAPResponseCode code = (IMAPResponseCode)0) 176 IMAPResponseOK(QString comment = 0, IMAPResponseCode code = (IMAPResponseCode)0)
177 { 177 {
178 _comment = comment; 178 _comment = comment;
179 _code = code; 179 _code = code;
180 } 180 }
181 181
182 void setComment(QString comment) { _comment = comment; } 182 void setComment(QString comment) { _comment = comment; }
183 QString comment() { return _comment; } 183 QString comment() { return _comment; }
184 void setResponseCode(IMAPResponseCode code) { _code = code; } 184 void setResponseCode(IMAPResponseCode code) { _code = code; }
185 IMAPResponseCode responseCode() { return _code; } 185 IMAPResponseCode responseCode() { return _code; }
186 186
187private: 187private:
188 QString _comment; 188 QString _comment;
189 IMAPResponseCode _code; 189 IMAPResponseCode _code;
190 190
191}; 191};
192 192
193class IMAPResponseNO : public IMAPResponseEnums 193class IMAPResponseNO : public IMAPResponseEnums
194{ 194{
195public: 195public:
196 IMAPResponseNO(QString comment = 0, IMAPResponseCode code = (IMAPResponseCode)0) 196 IMAPResponseNO(QString comment = 0, IMAPResponseCode code = (IMAPResponseCode)0)
197 { 197 {
198 _comment = comment; 198 _comment = comment;
199 _code = code; 199 _code = code;
200 } 200 }
201 201
202 void setComment(QString comment) { _comment = comment; } 202 void setComment(QString comment) { _comment = comment; }
203 QString comment() { return _comment; } 203 QString comment() { return _comment; }
204 void setResponseCode(IMAPResponseCode code) { _code = code; } 204 void setResponseCode(IMAPResponseCode code) { _code = code; }
205 IMAPResponseCode responseCode() { return _code; } 205 IMAPResponseCode responseCode() { return _code; }
206 206
207private: 207private:
208 QString _comment; 208 QString _comment;
209 IMAPResponseCode _code; 209 IMAPResponseCode _code;
210 210
211}; 211};
212 212
213class IMAPResponseBAD : public IMAPResponseEnums 213class IMAPResponseBAD : public IMAPResponseEnums
214{ 214{
215public: 215public:
216 IMAPResponseBAD(QString comment = 0, IMAPResponseCode code = (IMAPResponseCode)0) 216 IMAPResponseBAD(QString comment = 0, IMAPResponseCode code = (IMAPResponseCode)0)
217 { 217 {
218 _comment = comment; 218 _comment = comment;
219 _code = code; 219 _code = code;
220 } 220 }
221 221
222 void setComment(QString comment) { _comment = comment; } 222 void setComment(QString comment) { _comment = comment; }
223 QString comment() { return _comment; } 223 QString comment() { return _comment; }
224 void setResponseCode(IMAPResponseCode code) { _code = code; } 224 void setResponseCode(IMAPResponseCode code) { _code = code; }
225 IMAPResponseCode responseCode() { return _code; } 225 IMAPResponseCode responseCode() { return _code; }
226 226
227private: 227private:
228 QString _comment; 228 QString _comment;
229 IMAPResponseCode _code; 229 IMAPResponseCode _code;
230 230
231}; 231};
232 232
233class IMAPResponseCAPABILITY 233class IMAPResponseCAPABILITY
234{ 234{
235public: 235public:
236 IMAPResponseCAPABILITY(QStringList capabilities = 0) 236 IMAPResponseCAPABILITY(QStringList capabilities = 0)
237 { 237 {
238 _capabilities = capabilities; 238 _capabilities = capabilities;
239 } 239 }
240 240
241 void setCapabilities(QStringList capabilities) { _capabilities = capabilities; } 241 void setCapabilities(QStringList capabilities) { _capabilities = capabilities; }
242 QStringList capabilities() { return _capabilities; } 242 QStringList capabilities() { return _capabilities; }
243 243
244private: 244private:
245 QStringList _capabilities; 245 QStringList _capabilities;
246 246
247}; 247};
248 248
249class IMAPResponseLIST : public IMAPResponseEnums 249class IMAPResponseLIST : public IMAPResponseEnums
250{ 250{
251public: 251public:
252 IMAPResponseLIST(QValueList<IMAPResponseFlags> flags = QValueList<IMAPResponseFlags>(), QString folderSeparator = 0, QString folder = 0) 252 IMAPResponseLIST(QValueList<IMAPResponseFlags> flags = QValueList<IMAPResponseFlags>(), QString folderSeparator = 0, QString folder = 0)
253 { 253 {
254 _flags = flags; 254 _flags = flags;
255 _folderSeparator = folderSeparator; 255 _folderSeparator = folderSeparator;
256 _folder = folder; 256 _folder = folder;
257 } 257 }
258 258
259 void setFlags(QValueList<IMAPResponseFlags> flags) { _flags = flags; } 259 void setFlags(QValueList<IMAPResponseFlags> flags) { _flags = flags; }
260 QValueList<IMAPResponseFlags> flags() { return _flags; } 260 QValueList<IMAPResponseFlags> flags() { return _flags; }
261 void setFolderSeparator(QString folderSeparator) { _folderSeparator = folderSeparator; } 261 void setFolderSeparator(QString folderSeparator) { _folderSeparator = folderSeparator; }
262 QString folderSeparator() { return _folderSeparator; } 262 QString folderSeparator() { return _folderSeparator; }
263 void setFolder(QString folder) { _folder = folder; } 263 void setFolder(QString folder) { _folder = folder; }
264 QString folder() { return _folder; } 264 QString folder() { return _folder; }
265 265
266private: 266private:
267 QValueList<IMAPResponseFlags> _flags; 267 QValueList<IMAPResponseFlags> _flags;
268 QString _folderSeparator, _folder; 268 QString _folderSeparator, _folder;
269 269
270}; 270};
271 271
272class IMAPResponseLSUB : public IMAPResponseEnums 272class IMAPResponseLSUB : public IMAPResponseEnums
273{ 273{
274public: 274public:
275 IMAPResponseLSUB(QValueList<IMAPResponseFlags> flags = QValueList<IMAPResponseFlags>(), QString folderSeperator = 0, QString folder = 0) 275 IMAPResponseLSUB(QValueList<IMAPResponseFlags> flags = QValueList<IMAPResponseFlags>(), QString folderSeperator = 0, QString folder = 0)
276 { 276 {
277 _flags = flags; 277 _flags = flags;
278 _folderSeperator = folderSeperator; 278 _folderSeperator = folderSeperator;
279 _folder = folder; 279 _folder = folder;
280 } 280 }
281 281
282 void setFlags(QValueList<IMAPResponseFlags> flags) { _flags = flags; } 282 void setFlags(QValueList<IMAPResponseFlags> flags) { _flags = flags; }
283 QValueList<IMAPResponseFlags> flags() { return _flags; } 283 QValueList<IMAPResponseFlags> flags() { return _flags; }
284 void setFolderSeperator(QString folderSeperator) { _folderSeperator = folderSeperator; } 284 void setFolderSeperator(QString folderSeperator) { _folderSeperator = folderSeperator; }
285 QString folderSeperator() { return _folderSeperator; } 285 QString folderSeperator() { return _folderSeperator; }
286 void setFolder(QString folder) { _folder = folder; } 286 void setFolder(QString folder) { _folder = folder; }
287 QString folder() { return _folder; } 287 QString folder() { return _folder; }
288 288
289private: 289private:
290 QValueList<IMAPResponseFlags> _flags; 290 QValueList<IMAPResponseFlags> _flags;
291 QString _folderSeperator, _folder; 291 QString _folderSeperator, _folder;
292 292
293}; 293};
294 294
295class IMAPResponseSTATUS 295class IMAPResponseSTATUS
296{ 296{
297public: 297public:
298 IMAPResponseSTATUS(QString mailbox = 0, QString messages = 0, QString recent = 0, QString uidnext = 0, QString uidvalidity = 0, QString unseen = 0) 298 IMAPResponseSTATUS(QString mailbox = 0, QString messages = 0, QString recent = 0, QString uidnext = 0, QString uidvalidity = 0, QString unseen = 0)
299 { 299 {
300 _mailbox = mailbox; 300 _mailbox = mailbox;
301 _messages = messages; 301 _messages = messages;
302 _recent = recent; 302 _recent = recent;
303 _uidnext = uidnext; 303 _uidnext = uidnext;
304 _uidvalidity = uidvalidity; 304 _uidvalidity = uidvalidity;
305 _unseen = unseen; 305 _unseen = unseen;
306 } 306 }
307 307
308 void setMailbox(QString &mailbox) { _mailbox = mailbox; } 308 void setMailbox(QString &mailbox) { _mailbox = mailbox; }
309 QString mailbox() { return _mailbox; } 309 QString mailbox() { return _mailbox; }
310 void setMessages(QString &messages) { _messages = messages; } 310 void setMessages(QString &messages) { _messages = messages; }
311 QString messages() { return _messages; } 311 QString messages() { return _messages; }
312 void setRecent(QString &recent) { _recent = recent; } 312 void setRecent(QString &recent) { _recent = recent; }
313 QString recent() { return _recent; } 313 QString recent() { return _recent; }
314 void setUidnext(QString &uidnext) { _uidnext = uidnext; } 314 void setUidnext(QString &uidnext) { _uidnext = uidnext; }
315 QString uidnext() { return _uidnext; } 315 QString uidnext() { return _uidnext; }
316 void setUidvalidity(QString &uidvalidity) { _uidvalidity = uidvalidity; } 316 void setUidvalidity(QString &uidvalidity) { _uidvalidity = uidvalidity; }
317 QString uidvalidity() { return _uidvalidity; } 317 QString uidvalidity() { return _uidvalidity; }
318 void setUnseen(QString &unseen) { _unseen = unseen; } 318 void setUnseen(QString &unseen) { _unseen = unseen; }
319 QString unseen() { return _unseen; } 319 QString unseen() { return _unseen; }
320 320
321private: 321private:
322 QString _mailbox, _messages, _recent, _uidnext, _uidvalidity, _unseen; 322 QString _mailbox, _messages, _recent, _uidnext, _uidvalidity, _unseen;
323 323
324}; 324};
325 325
326class IMAPResponseSEARCH 326class IMAPResponseSEARCH
327{ 327{
328public: 328public:
329 IMAPResponseSEARCH(QStringList mails = 0) 329 IMAPResponseSEARCH(QStringList mails = 0)
330 { 330 {
331 _mails = mails; 331 _mails = mails;
332 } 332 }
333 333
334 void setMails(QStringList mails) { _mails = mails; } 334 void setMails(QStringList mails) { _mails = mails; }
335 QStringList mails() { return _mails; } 335 QStringList mails() { return _mails; }
336 336
337private: 337private:
338 QStringList _mails; 338 QStringList _mails;
339 339
340}; 340};
341 341
342class IMAPResponseFLAGS : public IMAPResponseEnums 342class IMAPResponseFLAGS : public IMAPResponseEnums
343{ 343{
344public: 344public:
345 IMAPResponseFLAGS(QValueList<IMAPResponseFlags> flags = QValueList<IMAPResponseFlags>()) 345 IMAPResponseFLAGS(QValueList<IMAPResponseFlags> flags = QValueList<IMAPResponseFlags>())
346 { 346 {
347 _flags = flags; 347 _flags = flags;
348 } 348 }
349 349
350 void setFlags(QValueList<IMAPResponseFlags> flags) { _flags = flags; } 350 void setFlags(QValueList<IMAPResponseFlags> flags) { _flags = flags; }
351 QValueList<IMAPResponseFlags> flags() { return _flags; } 351 QValueList<IMAPResponseFlags> flags() { return _flags; }
352 352
353private: 353private:
354 QValueList<IMAPResponseFlags> _flags; 354 QValueList<IMAPResponseFlags> _flags;
355 355
356}; 356};
357 357
358class IMAPResponseEXISTS 358class IMAPResponseEXISTS
359{ 359{
360public: 360public:
361 IMAPResponseEXISTS(QString mails = 0) 361 IMAPResponseEXISTS(QString mails = 0)
362 { 362 {
363 _mails = mails; 363 _mails = mails;
364 } 364 }
365 365
366 void setMails(QString mails) { _mails = mails; } 366 void setMails(QString mails) { _mails = mails; }
367 QString mails() { return _mails; } 367 QString mails() { return _mails; }
368 368
369private: 369private:
370 QString _mails; 370 QString _mails;
371 371
372}; 372};
373 373
374class IMAPResponseRECENT 374class IMAPResponseRECENT
375{ 375{
376public: 376public:
377 IMAPResponseRECENT(QString mails = 0) 377 IMAPResponseRECENT(QString mails = 0)
378 { 378 {
379 _mails = mails; 379 _mails = mails;
380 } 380 }
381 381
382 void setMails(QString mails) { _mails = mails; } 382 void setMails(QString mails) { _mails = mails; }
383 QString mails() { return _mails; } 383 QString mails() { return _mails; }
384 384
385private: 385private:
386 QString _mails; 386 QString _mails;
387 387
388}; 388};
389 389
390class IMAPResponseEXPUNGE 390class IMAPResponseEXPUNGE
391{ 391{
392public: 392public:
393 IMAPResponseEXPUNGE(QString mails = 0) 393 IMAPResponseEXPUNGE(QString mails = 0)
394 { 394 {
395 _mails = mails; 395 _mails = mails;
396 } 396 }
397 397
398 void setMails(QString mails) { _mails = mails; } 398 void setMails(QString mails) { _mails = mails; }
399 QString mails() { return _mails; } 399 QString mails() { return _mails; }
400 400
401private: 401private:
402 QString _mails; 402 QString _mails;
403 403
404}; 404};
405 405
406class IMAPResponseFETCH : public IMAPResponseEnums 406class IMAPResponseFETCH : public IMAPResponseEnums
407{ 407{
408public: 408public:
409 void setEnvelope(IMAPResponseEnvelope envelope) { _envelope = envelope; } 409 void setEnvelope(IMAPResponseEnvelope envelope) { _envelope = envelope; }
410 IMAPResponseEnvelope envelope() { return _envelope; } 410 IMAPResponseEnvelope envelope() { return _envelope; }
411 void setFlags(QValueList<IMAPResponseFlags> flags) { _flags = flags; } 411 void setFlags(QValueList<IMAPResponseFlags> flags) { _flags = flags; }
412 QValueList<IMAPResponseFlags> flags() { return _flags; } 412 QValueList<IMAPResponseFlags> flags() { return _flags; }
413 void setInternalDate(QString idate) { _idate = idate; } 413 void setInternalDate(QString idate) { _idate = idate; }
414 QString internalDate() { return _idate; } 414 QString internalDate() { return _idate; }
415 void setRFC822Size(QString rfc822size) { _rfc822size = rfc822size; } 415 void setRFC822Size(QString rfc822size) { _rfc822size = rfc822size; }
416 QString RFC822Size() { return _rfc822size; } 416 QString RFC822Size() { return _rfc822size; }
417 void setUid(QString uid) { _uid = uid; } 417 void setUid(QString uid) { _uid = uid; }
418 QString uid() { return _uid; } 418 QString uid() { return _uid; }
419 419
420 void setBody(QString body) { _body = body; } 420 void setBody(QString body) { _body = body; }
421 QString body() { return _body; } 421 QString body() { return _body; }
422 void addBodyPart(IMAPResponseBodyPart part) { _bodyParts.append(part); } 422 void addBodyPart(IMAPResponseBodyPart part) { _bodyParts.append(part); }
423 void setBodyParts(QValueList<IMAPResponseBodyPart> parts) { _bodyParts = parts; } 423 void setBodyParts(QValueList<IMAPResponseBodyPart> parts) { _bodyParts = parts; }
424 QValueList<IMAPResponseBodyPart> bodyParts() { return _bodyParts; } 424 QValueList<IMAPResponseBodyPart> bodyParts() { return _bodyParts; }
425 IMAPResponseBodyPart bodyPart(int part) { return _bodyParts[part]; } 425 IMAPResponseBodyPart bodyPart(int part) { return _bodyParts[part]; }
426 void setRfc822(QString rfc822) { _rfc822 = rfc822; } 426 void setRfc822(QString rfc822) { _rfc822 = rfc822; }
427 QString rfc822() { return _rfc822; } 427 QString rfc822() { return _rfc822; }
428 void setRfc822Header(QString rfc822Header) { _rfc822Header = rfc822Header; } 428 void setRfc822Header(QString rfc822Header) { _rfc822Header = rfc822Header; }
429 QString rfc822Header() { return _rfc822Header; } 429 QString rfc822Header() { return _rfc822Header; }
430 void setRfc822Text(QString rfc822Text) { _rfc822Text = rfc822Text; } 430 void setRfc822Text(QString rfc822Text) { _rfc822Text = rfc822Text; }
431 QString rfc822Text() { return _rfc822Text; } 431 QString rfc822Text() { return _rfc822Text; }
432 432
433private: 433private:
434 IMAPResponseEnvelope _envelope; 434 IMAPResponseEnvelope _envelope;
435 QValueList<IMAPResponseFlags> _flags; 435 QValueList<IMAPResponseFlags> _flags;
436 QString _idate, _rfc822size, _uid, _body, _rfc822, _rfc822Header, _rfc822Text; 436 QString _idate, _rfc822size, _uid, _body, _rfc822, _rfc822Header, _rfc822Text;
437 QValueList<IMAPResponseBodyPart> _bodyParts; 437 QValueList<IMAPResponseBodyPart> _bodyParts;
438 438
439}; 439};
440 440
441class IMAPResponse : public IMAPResponseEnums 441class IMAPResponse : public IMAPResponseEnums
442{ 442{
443public: 443public:
444 void setTag(QString tag) { _tag = tag; } 444 void setTag(QString tag) { _tag = tag; }
445 QString tag() { return _tag; } 445 QString tag() { return _tag; }
446 446
447 void setImapHandler(IMAPHandler *handler) { _handler = handler; } 447 void setImapHandler(IMAPHandler *handler) { _handler = handler; }
448 IMAPHandler *imapHandler() { return _handler; } 448 IMAPHandler *imapHandler() { return _handler; }
449 449
450 void setStatusResponse(IMAPResponseStatusResponse response) { _response = response; } 450 void setStatusResponse(IMAPResponseStatusResponse response) { _response = response; }
451 IMAPResponseStatusResponse statusResponse() { return _response; } 451 IMAPResponseStatusResponse statusResponse() { return _response; }
452 452
453 void addOK(IMAPResponseOK ok) { _okl.append(ok); } 453 void addOK(IMAPResponseOK ok) { _okl.append(ok); }
454 void addNO(IMAPResponseNO no) { _nol.append(no); } 454 void addNO(IMAPResponseNO no) { _nol.append(no); }
455 void addBAD(IMAPResponseBAD bad) { _badl.append(bad); } 455 void addBAD(IMAPResponseBAD bad) { _badl.append(bad); }
456 void addCAPABILITY(IMAPResponseCAPABILITY capability) { _capabilityl.append(capability); } 456 void addCAPABILITY(IMAPResponseCAPABILITY capability) { _capabilityl.append(capability); }
457 void addLIST(IMAPResponseLIST list) { _listl.append(list); } 457 void addLIST(IMAPResponseLIST list) { _listl.append(list); }
458 void addLSUB(IMAPResponseLSUB lsub) { _lsubl.append(lsub); } 458 void addLSUB(IMAPResponseLSUB lsub) { _lsubl.append(lsub); }
459 void addSTATUS(IMAPResponseSTATUS status) { _statusl.append(status); } 459 void addSTATUS(IMAPResponseSTATUS status) { _statusl.append(status); }
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
481private: 481private:
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
503class IMAPResponseParser : public QObject, public IMAPResponseEnums 503class IMAPResponseParser : public QObject, public IMAPResponseEnums
504{ 504{
505 Q_OBJECT 505 Q_OBJECT
506 506
507public: 507public:
508 IMAPResponseParser(const QString &data); 508 IMAPResponseParser();
509 void parse ( const QString &data);
509 510
510 IMAPResponse response(); 511 IMAPResponse response();
511 512
512signals: 513signals:
513 void needMoreData(const QString &comment); 514 void needMoreData(QString &data);
514 515
515protected: 516protected:
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
525private: 526private:
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
@@ -1,198 +1,198 @@
1#include <qtextbrowser.h> 1#include <qtextbrowser.h>
2#include <qmessagebox.h> 2#include <qmessagebox.h>
3#include <qaction.h> 3#include <qaction.h>
4#include <qapplication.h> 4#include <qapplication.h>
5 5
6#include "mailfactory.h" 6#include "mailfactory.h"
7#include "composer.h" 7#include "composer.h"
8#include "viewmail.h" 8#include "viewmail.h"
9 9
10AttachItem::AttachItem(QListView *parent, AttachItemStore &attachItemStore) 10AttachItem::AttachItem(QListView *parent, AttachItemStore &attachItemStore)
11 : QListViewItem(parent), _attachItemStore(attachItemStore) 11 : QListViewItem(parent), _attachItemStore(attachItemStore)
12{ 12{
13 setText(0, _attachItemStore.mimeType()); 13 setText(0, _attachItemStore.mimeType());
14 setText(1, _attachItemStore.fileName()); 14 setText(1, _attachItemStore.fileName());
15 setText(2, _attachItemStore.description()); 15 setText(2, _attachItemStore.description());
16} 16}
17 17
18AttachItem::AttachItem(QListViewItem *parent, AttachItemStore &attachItemStore) 18AttachItem::AttachItem(QListViewItem *parent, AttachItemStore &attachItemStore)
19 : QListViewItem(parent), _attachItemStore(attachItemStore) 19 : QListViewItem(parent), _attachItemStore(attachItemStore)
20{ 20{
21 setText(0, _attachItemStore.mimeType()); 21 setText(0, _attachItemStore.mimeType());
22 setText(1, _attachItemStore.fileName()); 22 setText(1, _attachItemStore.fileName());
23 setText(2, _attachItemStore.description()); 23 setText(2, _attachItemStore.description());
24} 24}
25 25
26ViewMail::ViewMail(IMAPResponseFETCH &mail, IMAPHandler *handler, QWidget *parent, const char *name, WFlags fl) 26ViewMail::ViewMail(IMAPResponseFETCH &mail, IMAPHandler *handler, QWidget *parent, const char *name, WFlags fl)
27 : ViewMailBase(parent, name, fl), _inLoop(false), _mail(mail), _handler(handler) 27 : ViewMailBase(parent, name, fl), _inLoop(false), _mail(mail), _handler(handler)
28{ 28{
29 setCaption(caption().arg(mail.envelope().from()[0].name())); 29 setCaption(caption().arg(mail.envelope().from()[0].name()));
30 30
31 _gotBody = false; 31 _gotBody = false;
32 _mailHtml = tr( 32 _mailHtml = tr(
33 "<html><body>" 33 "<html><body>"
34 "<div align=center><b>%1</b></div>" 34 "<div align=center><b>%1</b></div>"
35 "<b>From:</b> %2<br>" 35 "<b>From:</b> %2<br>"
36 "<b>To:</b> %3<br>" 36 "<b>To:</b> %3<br>"
37 "%4" 37 "%4"
38 "%5" 38 "%5"
39 "<b>Date:</b> %6<hr>" 39 "<b>Date:</b> %6<hr>"
40 "<font face=fixed>%7</font>") 40 "<font face=fixed>%7</font>")
41 .arg(deHtml(mail.envelope().subject().isNull() ? tr("(no subject)") 41 .arg(deHtml(mail.envelope().subject().isNull() ? tr("(no subject)")
42 : deHtml(mail.envelope().subject()))) 42 : deHtml(mail.envelope().subject())))
43 .arg(deHtml(mail.envelope().from().toString().isNull() ? tr("(no from)") 43 .arg(deHtml(mail.envelope().from().toString().isNull() ? tr("(no from)")
44 : mail.envelope().from().toString())) 44 : mail.envelope().from().toString()))
45 .arg(deHtml(mail.envelope().to().toString().isNull() ? tr("(no recipient)") 45 .arg(deHtml(mail.envelope().to().toString().isNull() ? tr("(no recipient)")
46 : mail.envelope().to().toString())) 46 : mail.envelope().to().toString()))
47 .arg(mail.envelope().cc().toString().isNull() ? QString(0) 47 .arg(mail.envelope().cc().toString().isNull() ? QString(0)
48 : tr("<b>Cc:</b> %1<br>").arg(deHtml(mail.envelope().cc().toString()))) 48 : tr("<b>Cc:</b> %1<br>").arg(deHtml(mail.envelope().cc().toString())))
49 .arg(mail.envelope().bcc().toString().isNull() ? QString(0) 49 .arg(mail.envelope().bcc().toString().isNull() ? QString(0)
50 : tr("<b>Bcc:</b> %1<br>").arg(deHtml(mail.envelope().bcc().toString()))) 50 : tr("<b>Bcc:</b> %1<br>").arg(deHtml(mail.envelope().bcc().toString())))
51 .arg(mail.envelope().mailDate().isNull() ? tr("(no date)") 51 .arg(mail.envelope().mailDate().isNull() ? tr("(no date)")
52 : mail.envelope().mailDate()) 52 : mail.envelope().mailDate())
53 .arg("%1"); 53 .arg("%1");
54 54
55 connect(reply, SIGNAL(activated()), SLOT(slotReply())); 55 connect(reply, SIGNAL(activated()), SLOT(slotReply()));
56 connect(forward, SIGNAL(activated()), SLOT(slotForward())); 56 connect(forward, SIGNAL(activated()), SLOT(slotForward()));
57 57
58 attachments->setEnabled(_gotBody); 58 attachments->setEnabled(_gotBody);
59 browser->setText(QString(_mailHtml).arg(tr("Getting mail body from server. Please wait..."))); 59 browser->setText(QString(_mailHtml).arg(tr("Getting mail body from server. Please wait...")));
60 60
61 _handler->iUid("FETCH", QString("%1 (BODY[1])").arg(mail.uid())); 61 _handler->iUid("FETCH", QString("%1 (BODY[1])").arg(mail.uid()));
62 connect(_handler, SIGNAL(gotResponse(IMAPResponse &)), SLOT(slotIMAPUid(IMAPResponse &))); 62 connect(_handler, SIGNAL(gotResponse(IMAPResponse &)), SLOT(slotIMAPUid(IMAPResponse &)));
63} 63}
64 64
65ViewMail::~ViewMail() 65ViewMail::~ViewMail()
66{ 66{
67 hide(); 67 hide();
68} 68}
69 69
70void ViewMail::hide() 70void ViewMail::hide()
71{ 71{
72 QWidget::hide(); 72 QWidget::hide();
73 73
74 if (_inLoop) { 74 if (_inLoop) {
75 _inLoop = false; 75 _inLoop = false;
76 qApp->exit_loop(); 76 qApp->exit_loop();
77 } 77 }
78} 78}
79 79
80void ViewMail::exec() 80void ViewMail::exec()
81{ 81{
82 show(); 82 show();
83 83
84 if (!_inLoop) { 84 if (!_inLoop) {
85 _inLoop = true; 85 _inLoop = true;
86 qApp->enter_loop(); 86 qApp->enter_loop();
87 } 87 }
88} 88}
89 89
90QString ViewMail::deHtml(const QString &string) 90QString ViewMail::deHtml(const QString &string)
91{ 91{
92 QString string_ = string; 92 QString string_ = string;
93 string_.replace(QRegExp("&"), "&amp;"); 93 string_.replace(QRegExp("&"), "&amp;");
94 string_.replace(QRegExp("<"), "&lt;"); 94 string_.replace(QRegExp("<"), "&lt;");
95 string_.replace(QRegExp(">"), "&gt;"); 95 string_.replace(QRegExp(">"), "&gt;");
96 string_.replace(QRegExp("\\n"), "<br>"); 96 string_.replace(QRegExp("\\n"), "<br>");
97 return string_; 97 return string_;
98} 98}
99 99
100void ViewMail::slotReply() 100void ViewMail::slotReply()
101{ 101{
102 if (!_gotBody) { 102 if (!_gotBody) {
103 QMessageBox::information(this, tr("Error"), tr("<p>The mail body is not yet downloaded, so you cannot reply yet."), tr("Ok")); 103 QMessageBox::information(this, tr("Error"), tr("<p>The mail body is not yet downloaded, so you cannot reply yet."), tr("Ok"));
104 return; 104 return;
105 } 105 }
106 106
107 QString rtext; 107 QString rtext;
108 rtext += QString("* %1 wrote on %2:\n") // no i18n on purpose 108 rtext += QString("* %1 wrote on %2:\n") // no i18n on purpose
109 .arg(_mail.envelope().from()[0].toString()) 109 .arg(_mail.envelope().from()[0].toString())
110 .arg(_mail.envelope().mailDate()); 110 .arg(_mail.envelope().mailDate());
111 111
112 QString text = _mail.bodyPart(1).data(); 112 QString text = _mail.bodyPart(1).data();
113 QStringList lines = QStringList::split(QRegExp("\\n"), text); 113 QStringList lines = QStringList::split(QRegExp("\\n"), text);
114 QStringList::Iterator it; 114 QStringList::Iterator it;
115 for (it = lines.begin(); it != lines.end(); it++) { 115 for (it = lines.begin(); it != lines.end(); it++) {
116 rtext += "> " + *it + "\n"; 116 rtext += "> " + *it + "\n";
117 } 117 }
118 rtext += "\n"; 118 rtext += "\n";
119 119
120 QString prefix; 120 QString prefix;
121 if (_mail.envelope().subject().find(QRegExp("^Re: *$")) != -1) prefix = ""; 121 if (_mail.envelope().subject().find(QRegExp("^Re: *$")) != -1) prefix = "";
122 else prefix = "Re: "; // no i18n on purpose 122 else prefix = "Re: "; // no i18n on purpose
123 123
124 SendMail sendMail; 124 SendMail sendMail;
125 sendMail.setTo(_mail.envelope().from()[0].toString()); 125 sendMail.setTo(_mail.envelope().from()[0].toString());
126 sendMail.setSubject(prefix + _mail.envelope().subject()); 126 sendMail.setSubject(prefix + _mail.envelope().subject());
127 sendMail.setInReplyTo(_mail.envelope().messageId()); 127 sendMail.setInReplyTo(_mail.envelope().messageId());
128 sendMail.setMessage(rtext); 128 sendMail.setMessage(rtext);
129 129
130 Composer composer(this, 0, true); 130 Composer composer(this, 0, true);
131 composer.setSendMail(sendMail); 131 composer.setSendMail(sendMail);
132 composer.showMaximized(); 132 composer.showMaximized();
133 composer.exec(); 133 composer.exec();
134} 134}
135 135
136void ViewMail::slotForward() 136void ViewMail::slotForward()
137{ 137{
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
180void ViewMail::slotIMAPUid(IMAPResponse &response) 180void 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