summaryrefslogtreecommitdiff
path: root/noncore/unsupported/mail2/libmail
authorconber <conber>2002-06-15 09:46:14 (UTC)
committer conber <conber>2002-06-15 09:46:14 (UTC)
commit7f2eef29708380844922f34f59ba4e9beefbf7c3 (patch) (unidiff)
treef57125fbaabddecc35d6677f1b9e48a4594165d5 /noncore/unsupported/mail2/libmail
parent0acbdd392814589df303b6e50c79d9822e3db27a (diff)
downloadopie-7f2eef29708380844922f34f59ba4e9beefbf7c3.zip
opie-7f2eef29708380844922f34f59ba4e9beefbf7c3.tar.gz
opie-7f2eef29708380844922f34f59ba4e9beefbf7c3.tar.bz2
initial checkin
Diffstat (limited to 'noncore/unsupported/mail2/libmail') (more/less context) (show whitespace changes)
-rw-r--r--noncore/unsupported/mail2/libmail/configfile.cpp112
-rw-r--r--noncore/unsupported/mail2/libmail/configfile.h97
-rw-r--r--noncore/unsupported/mail2/libmail/defines.h8
-rw-r--r--noncore/unsupported/mail2/libmail/imapbase.cpp110
-rw-r--r--noncore/unsupported/mail2/libmail/imapbase.h52
-rw-r--r--noncore/unsupported/mail2/libmail/imaphandler.cpp334
-rw-r--r--noncore/unsupported/mail2/libmail/imaphandler.h86
-rw-r--r--noncore/unsupported/mail2/libmail/imapresponse.cpp448
-rw-r--r--noncore/unsupported/mail2/libmail/imapresponse.h531
-rw-r--r--noncore/unsupported/mail2/libmail/libmail.pro26
-rw-r--r--noncore/unsupported/mail2/libmail/mailfactory.cpp173
-rw-r--r--noncore/unsupported/mail2/libmail/mailfactory.h109
-rw-r--r--noncore/unsupported/mail2/libmail/md5.cpp242
-rw-r--r--noncore/unsupported/mail2/libmail/md5.h35
-rw-r--r--noncore/unsupported/mail2/libmail/miscfunctions.cpp295
-rw-r--r--noncore/unsupported/mail2/libmail/miscfunctions.h27
-rw-r--r--noncore/unsupported/mail2/libmail/sharp_char.h241
-rw-r--r--noncore/unsupported/mail2/libmail/smtphandler.cpp172
-rw-r--r--noncore/unsupported/mail2/libmail/smtphandler.h55
-rw-r--r--noncore/unsupported/mail2/libmail/zaurusstuff.cpp38
-rw-r--r--noncore/unsupported/mail2/libmail/zaurusstuff.h23
21 files changed, 3214 insertions, 0 deletions
diff --git a/noncore/unsupported/mail2/libmail/configfile.cpp b/noncore/unsupported/mail2/libmail/configfile.cpp
new file mode 100644
index 0000000..a5c2b49
--- a/dev/null
+++ b/noncore/unsupported/mail2/libmail/configfile.cpp
@@ -0,0 +1,112 @@
1#include <qdir.h>
2
3#include <qpe/config.h>
4
5#include <stdlib.h>
6
7#include "configfile.h"
8
9ConfigFile::ConfigFile() : QObject()
10{
11 checkDirectory();
12
13 QDir dir((QString) getenv("HOME") + "/Applications/mail/accounts");
14 QStringList entries = dir.entryList("account-*");
15
16 QStringList::Iterator it;
17 for (it = entries.begin(); it != entries.end(); it++) {
18 Account account;
19
20 Config *config = new Config((QString) getenv("HOME") + "/Applications/mail/accounts/" + *it, Config::File);
21 config->setGroup("Account");
22 account.setAccountName((*it).replace(0, 8, ""));
23 account.setRealName(config->readEntry("RealName"));
24 account.setEmail(config->readEntry("Email"));
25 account.setOrg(config->readEntry("Organization"));
26 account.setImapServer(config->readEntry("ImapServer"));
27 account.setImapPort(config->readEntry("ImapPort"));
28 account.setSmtpServer(config->readEntry("SmtpServer"));
29 account.setSmtpPort(config->readEntry("SmtpPort"));
30 account.setUser(config->readEntry("User"));
31 account.setPass(rot13(config->readEntryCrypt("Pass")));
32 account.setSmtpSsl(config->readBoolEntry("SmtpSsl"));
33 account.setSmtpSslPort(config->readEntry("SmtpSslPort"));
34 account.setImapSsl(config->readBoolEntry("ImapSsl"));
35 account.setImapSslPort(config->readEntry("ImapSslPort"));
36 account.setDefaultCc(config->readBoolEntry("DefaultCc"));
37 account.setDefaultBcc(config->readBoolEntry("DefaultBcc"));
38 account.setDefaultReplyTo(config->readBoolEntry("DefaultReplyTo"));
39 account.setCc(config->readEntry("Cc"));
40 account.setBcc(config->readEntry("Bcc"));
41 account.setReplyTo(config->readEntry("ReplyTo"));
42 account.setSignature(config->readEntry("Signature").replace(QRegExp("<br>"), "\n"));
43
44 _accounts.append(account);
45 }
46}
47
48QValueList<Account> ConfigFile::getAccounts()
49{
50 ConfigFile *configFile = new ConfigFile();
51 return configFile->_accounts;
52}
53
54void ConfigFile::updateAccount(Account account)
55{
56 checkDirectory();
57 Config *config = new Config((QString) getenv("HOME") + "/Applications/mail/accounts/account-" + account.accountName(), Config::File);
58
59 config->setGroup("Account");
60 config->writeEntry("RealName", account.realName());
61 config->writeEntry("Email", account.email());
62 config->writeEntry("Organization", account.org());
63 config->writeEntry("ImapServer", account.imapServer());
64 config->writeEntry("ImapPort", account.imapPort());
65 config->writeEntry("SmtpServer", account.smtpServer());
66 config->writeEntry("SmtpPort", account.smtpPort());
67 config->writeEntry("User", account.user());
68 config->writeEntryCrypt("Pass", rot13(account.pass()));
69 config->writeEntry("SmtpSsl", account.smtpSsl());
70 config->writeEntry("SmtpSslPort", account.smtpSslPort());
71 config->writeEntry("ImapSsl", account.imapSsl());
72 config->writeEntry("ImapSslPort", account.imapSslPort());
73 config->writeEntry("DefaultCc", account.defaultCc());
74 config->writeEntry("DefaultBcc", account.defaultBcc());
75 config->writeEntry("DefaultReplyTo", account.defaultReplyTo());
76 config->writeEntry("Cc", account.cc());
77 config->writeEntry("Bcc", account.bcc());
78 config->writeEntry("ReplyTo", account.replyTo());
79 config->writeEntry("Signature", account.signature().replace(QRegExp("\\n"), "<br>"));
80
81 config->write();
82}
83
84void ConfigFile::deleteAccount(Account account)
85{
86 QFile f((QString) getenv("HOME") + "/Applications/mail/accounts/account-" + account.accountName());
87 f.remove();
88}
89
90void ConfigFile::checkDirectory()
91{
92 if (!QDir((QString) getenv("HOME") + "/Applications/mail/accounts").exists()) {
93 system("mkdir -p $HOME/Applications/mail/accounts");
94 qWarning("mail: $HOME/Applications/mail/accounts created");
95 }
96}
97
98QString ConfigFile::rot13(const QString &input)
99{
100 QString i = input;
101 int l = i.length();
102 while(l--) {
103 if (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);
106 else if (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);
109 }
110 return i;
111}
112
diff --git a/noncore/unsupported/mail2/libmail/configfile.h b/noncore/unsupported/mail2/libmail/configfile.h
new file mode 100644
index 0000000..84b57d5
--- a/dev/null
+++ b/noncore/unsupported/mail2/libmail/configfile.h
@@ -0,0 +1,97 @@
1#ifndef CONFIGFILE_H
2#define CONFIGFILE_H
3
4#include <qobject.h>
5
6class Config;
7
8class Account
9{
10public:
11 Account()
12 {
13 _smtpssl = false;
14 _imapssl = false;
15 _dateField = false;
16 _msgIdField = false;
17 _defaultCc = false;
18 _defaultBcc = false;
19 _defaultRep = false;
20 }
21
22 void setAccountName(QString accountName) { _accountName = accountName; }
23
24 void setRealName(QString name) { _name = name; }
25 void setEmail(QString email) { _email = email; }
26 void setOrg(QString org) { _org = org; }
27 void setImapServer(QString imapServer) { _imapServer = imapServer; }
28 void setImapPort(QString imapPort) { _imapPort = imapPort; }
29 void setSmtpServer(QString smtpServer) { _smtpServer = smtpServer; }
30 void setSmtpPort(QString smtpPort) { _smtpPort = smtpPort; }
31 void setUser(QString user) { _user = user; }
32 void setPass(QString pass) { _pass = pass; }
33 void setSmtpSsl(bool smtpssl) { _smtpssl = smtpssl; }
34 void setSmtpSslPort(QString smtpSslPort) { _smtpSslPort = smtpSslPort; }
35 void setImapSsl(bool imapssl) { _imapssl = imapssl; }
36 void setImapSslPort(QString imapSslPort) { _imapSslPort = imapSslPort; }
37 void setDateField(bool dateField) { _dateField = dateField; }
38 void setMsgIdField(bool msgIdField) { _msgIdField = msgIdField; }
39 void setDefaultCc(bool defaultCc) { _defaultCc = defaultCc; }
40 void setDefaultBcc(bool defaultBcc) { _defaultBcc = defaultBcc; }
41 void setDefaultReplyTo(bool defaultRep) { _defaultRep = defaultRep; }
42 void setCc(QString cc) { _cc = cc; }
43 void setBcc(QString bcc) { _bcc = bcc; }
44 void setReplyTo(QString replyTo) { _replyTo = replyTo; }
45 void setSignature(QString signature) { _signature = signature; }
46
47 QString accountName() { return _accountName; }
48
49 QString realName() { return _name; }
50 QString email() { return _email; }
51 QString org() { return _org; }
52 QString imapServer() { return _imapServer; }
53 QString imapPort() { return _imapPort; }
54 QString smtpServer() { return _smtpServer; }
55 QString smtpPort() { return _smtpPort; }
56 QString user() { return _user; }
57 QString pass() { return _pass; }
58 bool smtpSsl() { return _smtpssl; }
59 QString smtpSslPort() { return _smtpSslPort; }
60 bool imapSsl() { return _imapssl; }
61 QString imapSslPort() { return _imapSslPort; }
62 bool dateField() { return _dateField; }
63 bool msgIdField() { return _msgIdField; }
64 bool defaultCc() { return _defaultCc; }
65 bool defaultBcc() { return _defaultBcc; }
66 bool defaultReplyTo() { return _defaultRep; }
67 QString cc() { return _cc; }
68 QString bcc() { return _bcc; }
69 QString replyTo() { return _replyTo; }
70 QString signature() { return _signature; }
71
72private:
73 QString _accountName, _name, _email, _org, _imapServer, _smtpServer, _user, _pass, _cc, _bcc, _replyTo, _imapPort, _smtpPort, _signature, _smtpSslPort, _imapSslPort;
74 bool _dateField, _msgIdField, _defaultCc, _defaultBcc, _defaultRep, _smtpssl, _imapssl;
75
76};
77
78class ConfigFile : public QObject
79{
80 Q_OBJECT
81
82public:
83 static QValueList<Account> getAccounts();
84 static void updateAccount(Account account);
85 static void deleteAccount(Account account);
86
87protected:
88 static void checkDirectory();
89 static QString rot13(const QString &input);
90
91 ConfigFile();
92
93 QValueList<Account> _accounts;
94
95};
96
97#endif
diff --git a/noncore/unsupported/mail2/libmail/defines.h b/noncore/unsupported/mail2/libmail/defines.h
new file mode 100644
index 0000000..489cb0e
--- a/dev/null
+++ b/noncore/unsupported/mail2/libmail/defines.h
@@ -0,0 +1,8 @@
1#ifndef DEFINES_H
2#define DEFINES_H
3
4#define VERSION "0.0.9"
5
6#define USERAGENT "LISAMail/" + VERSION
7
8#endif
diff --git a/noncore/unsupported/mail2/libmail/imapbase.cpp b/noncore/unsupported/mail2/libmail/imapbase.cpp
new file mode 100644
index 0000000..9a2ba47
--- a/dev/null
+++ b/noncore/unsupported/mail2/libmail/imapbase.cpp
@@ -0,0 +1,110 @@
1#include <qsocket.h>
2#include <qtimer.h>
3
4#include "imapbase.h"
5
6IMAPBase::IMAPBase(const Account &account)
7 : QObject(), _account(account)
8{
9 _connected = false;
10 _writingAllowed = false;
11 _socket = new QSocket(this);
12
13 connect(_socket, SIGNAL(readyRead()), SLOT(slotDataAvailiable()));
14 connect(_socket, SIGNAL(hostFound()), SLOT(slotHostFound()));
15 connect(_socket, SIGNAL(connected()), SLOT(slotConnected()));
16 connect(_socket, SIGNAL(connectionClosed()), SLOT(slotDisconnected()));
17 connect(_socket, SIGNAL(error(int)), SLOT(slotError(int)));
18
19 QTimer *commandTimer = new QTimer(this);
20 commandTimer->start(200);
21 connect(commandTimer, SIGNAL(timeout()), SLOT(writeCommands()));
22}
23
24void IMAPBase::sendCommand(const QString &command)
25{
26 if (!_connected) makeConnect();
27 _commandQueue.append(command);
28}
29
30void IMAPBase::disconnect()
31{
32 _connected = false;
33 delete _socket;
34 emit disconnected();
35}
36
37void IMAPBase::makeConnect()
38{
39 emit lookingUpHost();
40 if (_socket == NULL) _socket = new QSocket(this);
41
42 Q_UINT16 port = _account.imapPort().toUInt();
43 _socket->connectToHost(_account.imapServer(), port);
44}
45
46void IMAPBase::writeCommands()
47{
48 if (!_connected) return;
49 if (_commandQueue.isEmpty()) return;
50 if (!_writingAllowed) return;
51
52 QStringList::Iterator it;
53 for (it = _commandQueue.begin(); it != _commandQueue.end(); it++) {
54 if (!(*it).isEmpty() && _writingAllowed) {
55#ifndef QT_NO_DEBUG
56 qDebug("IMAP > " + (*it).stripWhiteSpace());
57#endif
58 _socket->writeBlock((*it).latin1(), (*it).length());
59 _writingAllowed = false;
60 _commandQueue.remove(it);
61 break;
62 }
63 }
64}
65
66void IMAPBase::slotError(int err)
67{
68 if (err == QSocket::ErrConnectionRefused) {
69 emit error(IMAPErrConnectionRefused);
70 } else if (err == QSocket::ErrHostNotFound) {
71 emit error(IMAPErrHostNotFound);
72 } else if (err == QSocket::ErrSocketRead) {
73 emit error(IMAPErrSocketRead);
74 } else {
75 emit error(IMAPErrUnknownError);
76 }
77}
78
79void IMAPBase::slotHostFound()
80{
81 emit hostFound();
82}
83
84void IMAPBase::slotConnected()
85{
86 _connected = true;
87 emit connected();
88}
89
90void IMAPBase::slotDisconnected()
91{
92 _connected = false;
93 emit disconnected();
94}
95
96void IMAPBase::slotDataAvailiable()
97{
98 while (_socket->canReadLine()) {
99 _data += _socket->readLine();
100 if (_socket->atEnd()) {
101#ifndef QT_NO_DEBUG
102 qDebug("IMAP < " + _data.stripWhiteSpace());
103#endif
104 emit dataReceived(_data);
105 _writingAllowed = true;
106 _data = QString(0);
107 }
108 }
109}
110
diff --git a/noncore/unsupported/mail2/libmail/imapbase.h b/noncore/unsupported/mail2/libmail/imapbase.h
new file mode 100644
index 0000000..e4a0b97
--- a/dev/null
+++ b/noncore/unsupported/mail2/libmail/imapbase.h
@@ -0,0 +1,52 @@
1#ifndef IMAPBASE_H
2#define IMAPBASE_H
3
4#include <qobject.h>
5
6#include "configfile.h"
7
8class QSocket;
9
10class IMAPBase : public QObject
11{
12 Q_OBJECT
13
14public:
15 IMAPBase(const Account &account);
16
17 enum Error { IMAPErrConnectionRefused, IMAPErrHostNotFound,
18 IMAPErrSocketRead, IMAPErrUnknownError,
19 IMAPErrLoginFailed };
20
21 void sendCommand(const QString &command);
22 void disconnect();
23
24signals:
25 void dataReceived(const QString &data);
26 void lookingUpHost();
27 void hostFound();
28 void connected();
29 void disconnected();
30 void error(int err);
31
32protected:
33 void makeConnect();
34
35protected slots:
36 void writeCommands();
37 void slotError(int error);
38 void slotHostFound();
39 void slotConnected();
40 void slotDisconnected();
41 void slotDataAvailiable();
42
43private:
44 Account _account;
45 QString _data;
46 QSocket *_socket;
47 QStringList _commandQueue;
48 bool _connected, _writingAllowed;
49
50};
51
52#endif
diff --git a/noncore/unsupported/mail2/libmail/imaphandler.cpp b/noncore/unsupported/mail2/libmail/imaphandler.cpp
new file mode 100644
index 0000000..66c92c5
--- a/dev/null
+++ b/noncore/unsupported/mail2/libmail/imaphandler.cpp
@@ -0,0 +1,334 @@
1#include "imapresponse.h"
2#include "imaphandler.h"
3#include "imapbase.h"
4
5IMAPHandler::IMAPHandler(const Account &account)
6 : QObject(), _account(account)
7{
8 _loggingin = false;
9 _loggedin = false;
10 _tag = 0;
11 _ibase = new IMAPBase(account);
12
13 connect(_ibase, SIGNAL(dataReceived(const QString &)), SLOT(slotDataReceived(const QString &)));
14 connect(_ibase, SIGNAL(lookingUpHost()), SLOT(slotLookingUpHost()));
15 connect(_ibase, SIGNAL(hostFound()), SLOT(slotHostFound()));
16 connect(_ibase, SIGNAL(connected()), SLOT(slotConnected()));
17 connect(_ibase, SIGNAL(disconnected()), SLOT(slotDisconnected()));
18 connect(_ibase, SIGNAL(error(int)), SLOT(slotError(int)));
19}
20
21void IMAPHandler::doLogin()
22{
23 if (_loggedin) return;
24 if (_loggingin) return;
25
26 _loggingin = true;
27 iLogin(_account.user(), _account.pass());
28}
29
30QString IMAPHandler::iCapability()
31{
32 _ibase->sendCommand(QString("%1 CAPABILITY\r\n")
33 .arg(tag()));
34 return tag(false);
35}
36
37QString IMAPHandler::iNoop()
38{
39 _ibase->sendCommand(QString("%1 NOOP\r\n")
40 .arg(tag()));
41 return tag(false);
42}
43
44QString IMAPHandler::iLogout()
45{
46 _ibase->sendCommand(QString("%1 LOGOUT\r\n")
47 .arg(tag()));
48 return tag(false);
49}
50
51QString IMAPHandler::iAuthenticate(const QString &mechanism)
52{
53 _ibase->sendCommand(QString("%1 AUTHENTICATE \"%2\"\r\n")
54 .arg(tag())
55 .arg(escape(mechanism)));
56 return tag(false);
57}
58
59QString IMAPHandler::iLogin(const QString &user, const QString &pass)
60{
61 _ibase->sendCommand(QString("%1 LOGIN \"%2\" \"%3\"\r\n")
62 .arg(tag())
63 .arg(escape(user))
64 .arg(escape(pass)));
65 return tag(false);
66}
67
68QString IMAPHandler::iSelect(const QString &mailbox)
69{
70 doLogin();
71
72 _ibase->sendCommand(QString("%1 SELECT \"%2\"\r\n")
73 .arg(tag())
74 .arg(escape(mailbox)));
75 return tag(false);
76}
77
78QString IMAPHandler::iExamine(const QString &mailbox)
79{
80 doLogin();
81
82 _ibase->sendCommand(QString("%1 EXAMINE \"%2\"\r\n")
83 .arg(tag())
84 .arg(escape(mailbox)));
85 return tag(false);
86}
87
88QString IMAPHandler::iCreate(const QString &mailbox)
89{
90 doLogin();
91
92 _ibase->sendCommand(QString("%1 CREATE \"%2\"\r\n")
93 .arg(tag())
94 .arg(escape(mailbox)));
95 return tag(false);
96}
97
98QString IMAPHandler::iDelete(const QString &mailbox)
99{
100 doLogin();
101
102 _ibase->sendCommand(QString("%1 DELETE \"%2\"\r\n")
103 .arg(tag())
104 .arg(escape(mailbox)));
105 return tag(false);
106}
107
108QString IMAPHandler::iRename(const QString &mailbox, const QString &newMailbox)
109{
110 doLogin();
111
112 _ibase->sendCommand(QString("%1 RENAME \"%2\" \"%3\"\r\n")
113 .arg(tag())
114 .arg(escape(mailbox))
115 .arg(escape(newMailbox)));
116 return tag(false);
117}
118
119QString IMAPHandler::iSubscribe(const QString &mailbox)
120{
121 doLogin();
122
123 _ibase->sendCommand(QString("%1 SUBSCRIBE \"%2\"\r\n")
124 .arg(tag())
125 .arg(escape(mailbox)));
126 return tag(false);
127}
128
129QString IMAPHandler::iUnsubscribe(const QString &mailbox)
130{
131 doLogin();
132
133 _ibase->sendCommand(QString("%1 UNSUBSCRIBE \"%2\"\r\n")
134 .arg(tag())
135 .arg(escape(mailbox)));
136 return tag(false);
137}
138
139QString IMAPHandler::iList(const QString &reference, const QString &mailbox)
140{
141 doLogin();
142
143 _ibase->sendCommand(QString("%1 LIST \"%2\" \"%3\"\r\n")
144 .arg(tag())
145 .arg(escape(reference))
146 .arg(escape(mailbox)));
147 return tag(false);
148}
149
150QString IMAPHandler::iLsub(const QString &reference, const QString &mailbox)
151{
152 doLogin();
153
154 _ibase->sendCommand(QString("%1 LSUB \"%2\" \"%3\"\r\n")
155 .arg(tag())
156 .arg(escape(reference))
157 .arg(escape(mailbox)));
158 return tag(false);
159}
160
161QString IMAPHandler::iStatus(const QString &mailbox, const QString &items)
162{
163 doLogin();
164
165 _ibase->sendCommand(QString("%1 STATUS \"%2\" (%3)\r\n")
166 .arg(tag())
167 .arg(escape(mailbox))
168 .arg(escape(items)));
169 return tag(false);
170}
171
172QString IMAPHandler::iAppend(const QString &mailbox, const QString &literal, const QString &flags, const QString &datetime = 0)
173{
174 doLogin();
175
176 _ibase->sendCommand(QString("%1 APPEND \"%2\" (%3) \"%4\" {%5}\r\n%6\r\n")
177 .arg(tag())
178 .arg(escape(mailbox))
179 .arg(flags)
180 .arg(escape(datetime))
181 .arg(literal.length())
182 .arg(literal));
183 return tag(false);
184}
185
186QString IMAPHandler::iCheck()
187{
188 doLogin();
189
190 _ibase->sendCommand(QString("%1 CHECK\r\n")
191 .arg(tag()));
192 return tag(false);
193}
194
195QString IMAPHandler::iClose()
196{
197 doLogin();
198
199 _ibase->sendCommand(QString("%1 CLOSE\r\n")
200 .arg(tag()));
201 return tag(false);
202}
203
204QString IMAPHandler::iExpunge()
205{
206 doLogin();
207
208 _ibase->sendCommand(QString("%1 EXPUNGE\r\n")
209 .arg(tag()));
210 return tag(false);
211}
212
213QString IMAPHandler::iSearch(const QString &search, const QString &charset)
214{
215 doLogin();
216
217 _ibase->sendCommand(QString("%1 SEARCH %2 %3\r\n")
218 .arg(tag())
219 .arg(charset.isEmpty() ? QString(0) : escape(charset))
220 .arg(search));
221 return tag(false);
222}
223
224QString IMAPHandler::iFetch(const QString &message, const QString &items)
225{
226 doLogin();
227
228 _ibase->sendCommand(QString("%1 FETCH %2 (%3)\r\n")
229 .arg(tag())
230 .arg(message)
231 .arg(items));
232 return tag(false);
233}
234
235QString IMAPHandler::iStore(const QString &message, const QString &items)
236{
237 doLogin();
238
239 _ibase->sendCommand(QString("%1 STORE %2 %3\r\n")
240 .arg(tag())
241 .arg(message)
242 .arg(items));
243 return tag(false);
244}
245
246QString IMAPHandler::iCopy(const QString &message, const QString &mailbox)
247{
248 doLogin();
249
250 _ibase->sendCommand(QString("%1 COPY %2 \"%3\"\r\n")
251 .arg(tag())
252 .arg(message)
253 .arg(escape(mailbox)));
254 return tag(false);
255}
256
257QString IMAPHandler::iUid(const QString &command, const QString &arguments)
258{
259 doLogin();
260
261 _ibase->sendCommand(QString("%1 UID %2 %3\r\n")
262 .arg(tag())
263 .arg(command)
264 .arg(arguments));
265 return tag(false);
266}
267
268QString IMAPHandler::iX(const QString &commandAtom, const QString &arguments)
269{
270 doLogin();
271
272 _ibase->sendCommand(QString("%1 X%2 %3\r\n")
273 .arg(tag())
274 .arg(commandAtom)
275 .arg(arguments));
276 return tag(false);
277}
278
279QString IMAPHandler::escape(const QString &in)
280{
281 QString in_ = in;
282 return in_.replace(QRegExp("\""), "\\\"");
283}
284
285QString IMAPHandler::tag(bool count)
286{
287 return QString("a%1").arg(count ? _tag++ : _tag);
288}
289
290void IMAPHandler::slotDataReceived(const QString &data)
291{
292 IMAPResponseParser parser(data);
293 IMAPResponse response = parser.response();
294 response.setImapHandler(this);
295
296 if (!_loggingin) emit gotResponse(response);
297 else {
298 if (response.statusResponse().status() == IMAPResponseEnums::OK) {
299 _loggingin = false;
300 _loggedin = true;
301 qWarning("OK. Logged in. Leaving loggingin state.");
302 } else {
303 _loggingin = false;
304 emit IMAPError(IMAPBase::IMAPErrLoginFailed);
305 }
306 }
307}
308
309void IMAPHandler::slotLookingUpHost()
310{
311 emit IMAPLookingUpHost();
312}
313
314void IMAPHandler::slotHostFound()
315{
316 emit IMAPHostFound();
317}
318
319void IMAPHandler::slotConnected()
320{
321 emit IMAPConnected();
322}
323
324void IMAPHandler::slotDisconnected()
325{
326 _loggedin = false;
327 emit IMAPDisconnected();
328}
329
330void IMAPHandler::slotError(int err)
331{
332 emit IMAPError(err);
333}
334
diff --git a/noncore/unsupported/mail2/libmail/imaphandler.h b/noncore/unsupported/mail2/libmail/imaphandler.h
new file mode 100644
index 0000000..8cb42db
--- a/dev/null
+++ b/noncore/unsupported/mail2/libmail/imaphandler.h
@@ -0,0 +1,86 @@
1#ifndef IMAPHANDLER_H
2#define IMAPHANDLER_H
3
4#include <qobject.h>
5
6#include "configfile.h"
7
8class IMAPBase;
9class IMAPResponse;
10
11class IMAPHandler : public QObject
12{
13 Q_OBJECT
14
15public:
16 IMAPHandler(const Account &account);
17
18 QString iCapability();
19 QString iNoop();
20 QString iLogout();
21
22 QString iAuthenticate(const QString &mechanism);
23 QString iLogin(const QString &user, const QString &pass);
24
25 QString iSelect(const QString &mailbox);
26 QString iExamine(const QString &mailbox);
27 QString iCreate(const QString &mailbox);
28 QString iDelete(const QString &mailbox);
29 QString iRename(const QString &mailbox, const QString &newMailbox);
30
31 QString iSubscribe(const QString &mailbox);
32 QString iUnsubscribe(const QString &mailbox);
33
34 QString iList(const QString &reference, const QString &mailbox);
35 QString iLsub(const QString &reference, const QString &mailbox);
36
37 QString iStatus(const QString &mailbox, const QString &items);
38
39 QString iAppend(const QString &mailbox, const QString &literal, const QString &flags = 0, const QString &datetime = 0);
40
41 QString iCheck();
42 QString iClose();
43 QString iExpunge();
44
45 QString iSearch(const QString &search, const QString &charset = 0);
46
47 QString iFetch(const QString &message, const QString &items);
48
49 QString iStore(const QString &message, const QString &items);
50 QString iCopy(const QString &message, const QString &mailbox);
51
52 QString iUid(const QString &command, const QString &arguments);
53
54 QString iX(const QString &commandAtom, const QString &arguments);
55
56signals:
57 void gotResponse(IMAPResponse &response);
58
59 void IMAPLookingUpHost();
60 void IMAPHostFound();
61 void IMAPConnected();
62 void IMAPDisconnected();
63 void IMAPError(int err);
64
65protected:
66 void doLogin();
67 QString escape(const QString &in);
68 QString tag(bool count = true);
69
70protected slots:
71 void slotDataReceived(const QString &data);
72 void slotLookingUpHost();
73 void slotHostFound();
74 void slotConnected();
75 void slotDisconnected();
76 void slotError(int err);
77
78private:
79 Account _account;
80 IMAPBase *_ibase;
81 unsigned int _tag;
82 bool _loggingin, _loggedin;
83
84};
85
86#endif
diff --git a/noncore/unsupported/mail2/libmail/imapresponse.cpp b/noncore/unsupported/mail2/libmail/imapresponse.cpp
new file mode 100644
index 0000000..06dca33
--- a/dev/null
+++ b/noncore/unsupported/mail2/libmail/imapresponse.cpp
@@ -0,0 +1,448 @@
1#include "imapresponse.h"
2
3static QString _previousData;
4static unsigned int _neededData;
5
6IMAPResponseParser::IMAPResponseParser(const QString &data)
7 {
8 QString _data = data, more;
9 _data.replace((QString)"\r\n", "\n");
10
11 QStringList lines = QStringList::split('\n', _data);
12 QStringList::Iterator it;
13 for (it = lines.begin(); it != lines.end(); it++) {
14 QString tag, lineData;
15
16 if (!_previousData.isNull()) {
17 qDebug(QString("IMAPResponseParser: got additional data. (%1/%2)").arg(_previousData.length()).arg(_neededData));
18 _previousData += *it + "\n";
19 if (_previousData.length() >= _neededData) {
20 _previousData += ")";
21 qDebug("IMAPResponseParser: got ALL additional data.");
22 qDebug("Data is: " + _previousData);
23 parseResponse(_previousData);
24 _previousData = QString(0);
25 _neededData = 0;
26 }
27 } else {
28 splitTagData(*it, tag, lineData);
29 if (tag == "*") {
30 int pos;
31 if ((pos = data.find(QRegExp("\\{\\d*\\}"))) != -1) {
32 qDebug("IMAPResponseParser: waiting for additional data...");
33 _previousData = lineData + "\n";
34
35 QString tmp = data.right(data.length() - pos - 1).stripWhiteSpace();
36 tmp.truncate(tmp.length() - 1);
37
38 _neededData = tmp.toUInt();
39 if (_previousData.length() >= _neededData) {
40 qDebug("IMAPResponseParser: got ALL additional data. (1st)");
41 parseResponse(_previousData);
42 _previousData = QString(0);
43 _neededData = 0;
44 } else {
45 break;
46 }
47 } else {
48 parseResponse(lineData);
49 }
50 } else if (tag == "+") {
51 emit needMoreData(_data);
52 } else {
53 _iresponse.setTag(tag);
54 parseResponse(_data, true);
55 }
56 }
57 }
58}
59
60IMAPResponse IMAPResponseParser::response()
61{
62 return _iresponse;
63}
64
65void IMAPResponseParser::parseResponse(const QString &data, bool tagged)
66{
67 QString response, line;
68 int pos;
69 bool isNum = false;
70 if ((pos = data.find(' ')) != -1) {
71 response = data.left(pos).upper();
72 response.toInt(&isNum);
73 line = data.right(data.length() - pos - 1);
74 } else {
75 qWarning("IMAPResponseParser: parseResponse: No response found.");
76 return;
77 }
78
79 if (response == "OK" && tagged) {
80 IMAPResponseStatusResponse status(OK, line);
81 status.setResponseCode(getResponseCode(status.comment()));
82 _iresponse.setStatusResponse(status);
83 } else if (response == "OK" && !tagged) {
84 IMAPResponseOK ok(line, getResponseCode(line));
85 _iresponse.addOK(ok);
86 } else if (response == "NO" && tagged) {
87 IMAPResponseStatusResponse status(NO, line);
88 status.setResponseCode(getResponseCode(status.comment()));
89 _iresponse.setStatusResponse(status);
90 } else if (response == "NO" && !tagged) {
91 IMAPResponseNO no(line, getResponseCode(line));
92 _iresponse.addNO(no);
93 } else if (response == "BAD" && tagged) {
94 IMAPResponseStatusResponse status(BAD, line);
95 status.setResponseCode(getResponseCode(status.comment()));
96 _iresponse.setStatusResponse(status);
97 } else if (response == "BAD" && !tagged) {
98 IMAPResponseBAD bad(line, getResponseCode(line));
99 _iresponse.addBAD(bad);
100 } else if (response == "PREAUTH" && tagged) {
101 IMAPResponseStatusResponse status(PREAUTH, line);
102 _iresponse.setStatusResponse(status);
103 } else if (response == "PREAUTH" && !tagged) {
104 qDebug("IMAPResponseParser: responseParser: got untagged PREAUTH response.");
105 // XXX
106 } else if (response == "BYE") {
107 IMAPResponseStatusResponse status(BYE, line);
108 if (!tagged) status.setExitedUnexpected(true);
109 _iresponse.setStatusResponse(status);
110 } else if (response == "CAPABILITY") {
111 IMAPResponseCAPABILITY capability(QStringList::split(' ', line));
112 _iresponse.addCAPABILITY(capability);
113 } else if (response == "LIST") {
114 QStringList list = splitData(line, true);
115
116 QStringList flags;
117 parseParenthesizedList(list[0], flags);
118
119 removeLimiters(list[1]);
120 removeLimiters(list[2]);
121 IMAPResponseLIST rlist(parseFlagList(flags), list[1], list[2]);
122 _iresponse.addLIST(rlist);
123 } else if (response == "LSUB") {
124 QStringList list = splitData(line, true);
125
126 QStringList flags;
127 parseParenthesizedList(list[0], flags);
128
129 removeLimiters(list[1]);
130 removeLimiters(list[2]);
131 IMAPResponseLSUB lsub(parseFlagList(flags), list[1], list[2]);
132 _iresponse.addLSUB(lsub);
133 } else if (response == "STATUS") {
134 QStringList list = splitData(line, true);
135
136 removeLimiters(list[0]);
137 IMAPResponseSTATUS status(list[0]);
138
139 QStringList flags;
140 parseParenthesizedList(list[1], flags);
141 QStringList::Iterator it;
142 for (it = flags.begin(); it != flags.end(); it++) {
143 if (*it == "MESSAGES") status.setMessages(*(++it));
144 else if (*it == "RECENT") status.setRecent(*(++it));
145 else if (*it == "UIDNEXT") status.setUidnext(*(++it));
146 else if (*it == "UIDVALIDITY") status.setUidvalidity(*(++it));
147 else if (*it == "UNSEEN") status.setUnseen(*(++it));
148 else qWarning("IMAPResponseParser: parseResponse: Unknown status data: " + *(it++) + "|");
149 }
150 _iresponse.addSTATUS(status);
151 } else if (response == "SEARCH") {
152 IMAPResponseSEARCH search(QStringList::split(' ', line));
153 _iresponse.addSEARCH(search);
154 } else if (response == "FLAGS") {
155 QStringList list;
156 parseParenthesizedList(line, list);
157
158 IMAPResponseFLAGS flags(parseFlagList(list));
159 _iresponse.addFLAGS(flags);
160 } else if (isNum) {
161 QStringList list = QStringList::split(' ', line);
162 if (list[0] == "EXISTS") {
163 IMAPResponseEXISTS exists(response);
164 _iresponse.addEXISTS(exists);
165 } else if (list[0] == "RECENT") {
166 IMAPResponseRECENT recent(response);
167 _iresponse.addRECENT(recent);
168 } else if (list[0] == "EXPUNGE") {
169 IMAPResponseEXPUNGE expunge(response);
170 _iresponse.addEXPUNGE(expunge);
171 } else if (list[0] == "FETCH") {
172 IMAPResponseFETCH fetch;
173 QStringList::Iterator it;
174
175 QStringList fetchList = splitData(line, true);
176 QStringList list;
177 parseParenthesizedList(fetchList[1], list);
178
179 for (it = list.begin(); it != list.end(); it++) {
180 if (*it == "BODY") {
181 qDebug("IMAPResponseParser: responseParser: got FETCH::BODY");
182 // XXX
183 } else if ((*it).find(QRegExp("BODY\\[\\d+\\]")) != -1) {
184 QString bodydata = *(++it);
185 qDebug("IMAPResponseParser: responseParser: got FETCH::BODY[x]");
186
187 QStringList blist;
188 parseParenthesizedList(bodydata, blist);
189
190 IMAPResponseBodyPart bodypart;
191 QString tmp;
192 for (unsigned int i = 2; i < blist.count(); i++) {
193 if (i != 2) tmp += " " + blist[i];
194 else tmp += blist[i];
195 }
196 bodypart.setData(tmp);
197
198 tmp = list[0];
199 tmp.replace(0, 5, "");
200 tmp.truncate(blist[0].length() - 1);
201 bodypart.setPart(tmp);
202
203 fetch.addBodyPart(bodypart);
204 } else if (*it == "BODYSTRUCTURE") {
205 qDebug("IMAPResponseParser: responseParser: got FETCH::BODYSTRUCTURE");
206/*
207 QString bsdata = *(++it);
208 QStringList bsList;
209 parseParenthesizedList(bsdata, bsList);
210
211 IMAPResponseBodystructure bodystructure;
212 QStringList attachml;
213
214 for (int i = 0; i < bsList.count() - 1; i++) {
215 parseParenthesizedList(bsList[0], attachml);
216
217 IMAPResponseBodypart bodypart;
218 bodypart.setMimeTypeMain(attachml[0] == "NIL" ? QString(0) : attachml[0]);
219 bodypart.setMimeTypeSub(attachml[1] == "NIL" ? QString(0) : attachml[1]);
220 bodypart.setAddData(attachml[2] == "NIL" ? QString(0) : attachml[2]);
221 // 3 (NIL)
222 // 4 (NIL)
223 bodypart.setEncoding(attachml[5] == "NIL" ? QString(0) : attachml[5]);
224 bodypart.setSize(attachml[6] == "NIL" ? QString(0) : attachml[6]);
225 bodypart.setLength(attachml[7] == "NIL" ? QString(0) : attachml[7]);
226 bodypart.setAttachInfo(attachml[8] == "NIL" ? QString(0) : attachml[8]);
227 // 9 (NIL)
228 // 10 (NIL)
229
230 bodystructure.addBodyPart(bodypart);
231 }
232*/
233 } else if (*it == "ENVELOPE") {
234 QString envdata = *(++it);
235 QStringList envList;
236 parseParenthesizedList(envdata, envList);
237
238 IMAPResponseEnvelope envelope;
239 envelope.setMailDate(envList[0] == "NIL" ? QString(0) : removeLimiters(envList[0]));
240 envelope.setSubject(envList[1] == "NIL" ? QString(0) : removeLimiters(envList[1]));
241
242 QStringList froml, senderl, replytol, tol, ccl, bccl;
243 QStringList froma, sendera, replytoa, toa, cca, bcca;
244 parseParenthesizedList(envList[2], froml);
245 parseParenthesizedList(envList[3], senderl);
246 parseParenthesizedList(envList[4], replytol);
247 parseParenthesizedList(envList[5], tol);
248 parseParenthesizedList(envList[6], ccl);
249 parseParenthesizedList(envList[7], bccl);
250
251 QStringList::Iterator it;
252 for (it = froml.begin(); it != froml.end(); it++) {
253 parseParenthesizedList(*it, froma);
254 if (froml[0] != "NIL")
255 envelope.addFrom(IMAPResponseAddress(
256 removeLimiters(froma[0]),
257 removeLimiters(froma[1]),
258 removeLimiters(froma[2]),
259 removeLimiters(froma[3])));
260 }
261
262 for (it = senderl.begin(); it != senderl.end(); it++) {
263 parseParenthesizedList(*it, sendera);
264 if (senderl[0] != "NIL")
265 envelope.addSender(IMAPResponseAddress(
266 removeLimiters(sendera[0]),
267 removeLimiters(sendera[1]),
268 removeLimiters(sendera[2]),
269 removeLimiters(sendera[3])));
270 }
271
272 for (it = replytol.begin(); it != replytol.end(); it++) {
273 parseParenthesizedList(*it, replytoa);
274 if (replytol[0] != "NIL")
275 envelope.addReplyTo(IMAPResponseAddress(
276 removeLimiters(replytoa[0]),
277 removeLimiters(replytoa[1]),
278 removeLimiters(replytoa[2]),
279 removeLimiters(replytoa[3])));
280 }
281
282 for (it = tol.begin(); it != tol.end(); it++) {
283 parseParenthesizedList(*it, toa);
284 if (tol[0] != "NIL")
285 envelope.addTo(IMAPResponseAddress(
286 removeLimiters(toa[0]),
287 removeLimiters(toa[1]),
288 removeLimiters(toa[2]),
289 removeLimiters(toa[3])));
290 }
291
292 for (it = ccl.begin(); it != ccl.end(); it++) {
293 parseParenthesizedList(*it, cca);
294 if (ccl[0] != "NIL")
295 envelope.addCc(IMAPResponseAddress(
296 removeLimiters(cca[0]),
297 removeLimiters(cca[1]),
298 removeLimiters(cca[2]),
299 removeLimiters(cca[3])));
300 }
301
302 for (it = bccl.begin(); it != bccl.end(); it++) {
303 parseParenthesizedList(*it, bcca);
304 if (bccl[0] != "NIL")
305 envelope.addBcc(IMAPResponseAddress(
306 removeLimiters(bcca[0]),
307 removeLimiters(bcca[1]),
308 removeLimiters(bcca[2]),
309 removeLimiters(bcca[3])));
310 }
311
312 envelope.setInReplyTo(envList[7] == "NIL" ? QString(0) : removeLimiters(envList[7]));
313 envelope.setMessageId(envList[8] == "NIL" ? QString(0) : removeLimiters(envList[8]));
314
315 fetch.setEnvelope(envelope);
316 } else if (*it == "FLAGS") {
317 QString flagdata = *(++it);
318 QStringList flags;
319 parseParenthesizedList(flagdata, flags);
320 fetch.setFlags(parseFlagList(flags));
321 } else if (*it == "INTERNALDATE") {
322 fetch.setInternalDate(removeLimiters(*(++it)));
323 } else if (*it == "RFC822" || *it == "BODY[]") {
324 qDebug("IMAPResponseParser: responseParser: got FETCH::RFC822");
325 // XXX
326 } else if (*it == "RFC822.HEADER" || *it == "BODY.PEEK[HEADER]") {
327 qDebug("IMAPResponseParser: responseParser: got FETCH::RFC822.HEADER");
328 // XXX
329 } else if (*it == "RFC822.SIZE") {
330 fetch.setRFC822Size(*(++it));
331 } else if (*it == "RFC822.TEXT" || *it == "BODY[TEXT]") {
332 qDebug("IMAPResponseParser: responseParser: got FETCH::RFC822.TEXT");
333 // XXX
334 } else if (*it == "UID") {
335 fetch.setUid(*(++it));
336 }
337 }
338 _iresponse.addFETCH(fetch);
339 }
340 } else qWarning("IMAPResponseParser: parseResponse: Unknown response: " + response + "|");
341}
342
343QStringList IMAPResponseParser::splitData(const QString &data, bool withBrackets)
344{
345 int b = 0;
346 bool a = false, noappend = false, escaped = false;
347 QString temp;
348 QStringList list;
349
350 for (unsigned int i = 0; i <= data.length(); i++) {
351 if (withBrackets && data[i] == '(' && !a) b++;
352 else if (withBrackets && data[i] == ')' && !a) b--;
353
354 if (data[i] == '"' && !escaped) a = !a;
355 else escaped = false;
356
357 if (data[i] == '\\' && data[i + 1] == '"') escaped = true;
358
359 if ((data[i] == ' ' || i == data.length()) && b == 0 && !a) {
360 list.append(temp);
361 temp = QString(0);
362 if (data[i] == ' ') noappend = true;
363 }
364
365 if (!noappend) temp += data[i];
366 noappend = false;
367 }
368
369 return list;
370}
371
372void IMAPResponseParser::parseParenthesizedList(const QString &data, QStringList &parsed)
373{
374 QString data_(data);
375 removeLimiters(data_, '(', ')');
376 parsed = splitData(data_, true);
377}
378
379void IMAPResponseParser::splitTagData(const QString &line, QString &tag, QString &data)
380{
381 int pos;
382 if ((pos = line.find(' ')) != -1) {
383 tag = line.left(pos);
384 data = line.right(line.length() - pos - 1);
385 } else qWarning("IMAPResponseParser: splitTagData: tag not found. Line was " + line + "|");
386}
387
388QString IMAPResponseParser::removeLimiters(QString &string, const QChar &sl, const QChar &el)
389{
390 QString tmpString;
391 if (string[0] == sl && string[string.length() - 1] == el) {
392 string.truncate(string.length() - 1);
393 string.replace(0, 1, "");
394
395 for (unsigned int i = 1; i <= string.length(); i++) {
396 if (string[i - 1] == '\\' && sl == '"') ++i;
397 tmpString += string[i - 1];
398 }
399 }
400
401 return tmpString;
402}
403
404IMAPResponseEnums::IMAPResponseCode IMAPResponseParser::getResponseCode(const QString &line)
405{
406 if (line.find(QRegExp((QString) "^\\[.*\\]" + ' ' + ".*")) != -1) {
407 int pos = line.find("] ");
408 QString code = line.left(pos + 1).upper();
409
410 if (code.find(QRegExp("[ALERT]")) != -1) return ALERT;
411 else if (code.find(QRegExp("[NEWNAME .* .*]")) != -1) return NEWNAME; // XXX
412 else if (code.find(QRegExp("[PARSE]")) != -1) return PARSE;
413 else if (code.find(QRegExp("[PERMANENTFLAGS \\d*]")) != -1) return PERMANENTFLAGS; // XXX
414 else if (code.find(QRegExp("[READ-ONLY]")) != -1) return READONLY;
415 else if (code.find(QRegExp("[READ-WRITE]")) != -1) return READWRITE;
416 else if (code.find(QRegExp("[TRYCREATE]")) != -1) return TRYCREATE;
417 else if (code.find(QRegExp("[UIDVALIDITY \\d*]")) != -1) return UIDVALIDITY; // XXX
418 else if (code.find(QRegExp("[UNSEEN \\d*]")) != -1) return UNSEEN; // XXX
419 else {
420 qWarning("IMAPResponseParser: getResponseCode: Unknown code: " + code + "|");
421 return UnknownCode;
422 }
423 }
424 return NoCode;
425}
426
427QValueList<IMAPResponseEnums::IMAPResponseFlags> IMAPResponseParser::parseFlagList(const QStringList &flagList)
428{
429 QValueList<IMAPResponseFlags> flags;
430 QStringList::ConstIterator it;
431 for (it = flagList.begin(); it != flagList.end(); it++) {
432 QString flag = (*it).lower();
433 if (flag == "\\seen") flags.append(Seen);
434 else if (flag == "\\answered") flags.append(Answered);
435 else if (flag == "\\flagged") flags.append(Flagged);
436 else if (flag == "\\deleted") flags.append(Deleted);
437 else if (flag == "\\draft") flags.append(Draft);
438 else if (flag == "\\recent") flags.append(Recent);
439 else if (flag == "\\noinferiors") flags.append(Noinferiors);
440 else if (flag == "\\noselect") flags.append(Noselect);
441 else if (flag == "\\marked") flags.append(Marked);
442 else if (flag == "\\unmarked") flags.append(Unmarked);
443 else if (flag.isEmpty()) { }
444 else qWarning("IMAPResponseParser: parseFlagList: Unknown flag: " + *it + "|");
445 }
446 return flags;
447}
448
diff --git a/noncore/unsupported/mail2/libmail/imapresponse.h b/noncore/unsupported/mail2/libmail/imapresponse.h
new file mode 100644
index 0000000..73435ee
--- a/dev/null
+++ b/noncore/unsupported/mail2/libmail/imapresponse.h
@@ -0,0 +1,531 @@
1#ifndef IMAPRESPONSE_H
2#define IMAPRESPONSE_H
3
4#include <qobject.h>
5
6 #define MAX_BODYPARTS 50
7
8class IMAPHandler;
9
10class IMAPResponseEnums
11{
12public:
13 enum IMAPResponseStatus {
14 OK, NO, BAD, PREAUTH, BYE, UnknownStatus = 0
15 };
16
17 enum IMAPResponseFlags {
18 Seen, Answered, Flagged, Deleted, Draft, Recent,
19 Noinferiors, Noselect, Marked, Unmarked, UnknownFlag = 0
20 };
21
22 enum IMAPResponseCode {
23 ALERT, NEWNAME, PARSE, PERMANENTFLAGS, READONLY, READWRITE,
24 TRYCREATE, UIDVALIDITY, UNSEEN, NoCode, UnknownCode = 0
25 };
26
27};
28
29class IMAPResponseAddress
30{
31public:
32 IMAPResponseAddress(QString name = 0, QString adl = 0, QString mailbox = 0, QString host = 0)
33 {
34 _name = name;
35 _adl = adl;
36 _mailbox = mailbox;
37 _host = host;
38 }
39
40 void setName(QString name) { _name = name; }
41 QString name() { return _name; }
42 void setAdl(QString adl) { _adl = adl; }
43 QString adl() { return _adl; }
44 void setMailbox(QString mailbox) { _mailbox = mailbox; }
45 QString mailbox() { return _mailbox; }
46 void setHost(QString host) { _host = host; }
47 QString host() { return _host; }
48
49 QString toString()
50 {
51 if (_name.isNull() && _mailbox.isNull() && _host.isNull())
52 return QString(0);
53 if (_name != _mailbox + "@" + _host)
54 return _name + " <" + _mailbox + "@" + _host + ">";
55 else
56 return _name;
57 }
58
59 QString email()
60 {
61 if (_host.isEmpty()) return _mailbox;
62 else return _mailbox + "@" + _host;
63 }
64
65private:
66 QString _name, _adl, _mailbox, _host;
67
68};
69
70class IMAPResponseAddressList : public QValueList<IMAPResponseAddress>
71{
72public:
73 IMAPResponseAddressList()
74 : QValueList<IMAPResponseAddress>()
75 {
76
77 }
78
79 QString toString()
80 {
81 QString string;
82 IMAPResponseAddressList::Iterator it;
83 for (it = this->begin(); it != this->end(); it++) {
84 QString tmp = (*it).toString();
85 if (!tmp.isNull() && string.isEmpty()) string = tmp;
86 else if (!tmp.isNull()) string += ", " + tmp;
87 }
88 return string;
89 }
90
91};
92
93class IMAPResponseBody
94{
95public:
96 void setData(QString data) { _data = data; }
97 QString data() { return _data; }
98
99private:
100 QString _data;
101
102};
103
104class IMAPResponseBodyPart : public IMAPResponseBody
105{
106public:
107 void setPart(QString part) { _part = part; }
108 QString part() { return _part; }
109
110private:
111 QString _part;
112
113};
114
115class IMAPResponseEnvelope
116{
117public:
118 void setMailDate(QString date) { _date = date; }
119 QString mailDate() { return _date; }
120 void setSubject(QString subject) { _subject = subject; }
121 QString subject() { return _subject; }
122 void addFrom(IMAPResponseAddress from) { _from.append(from); }
123 IMAPResponseAddressList from() { return _from; }
124 void addSender(IMAPResponseAddress sender) { _sender.append(sender); }
125 IMAPResponseAddressList sender() { return _sender; }
126 void addReplyTo(IMAPResponseAddress replyTo) { _replyTo.append(replyTo); }
127 IMAPResponseAddressList replyTo() { return _replyTo; }
128 void addTo(IMAPResponseAddress to) { _to.append(to); }
129 IMAPResponseAddressList to() { return _to; }
130 void addCc(IMAPResponseAddress cc) { _cc.append(cc); }
131 IMAPResponseAddressList cc() { return _cc; }
132 void addBcc(IMAPResponseAddress bcc) { _bcc.append(bcc); }
133 IMAPResponseAddressList bcc() { return _bcc; }
134 void setInReplyTo(QString inReplyTo) { _inReplyTo = inReplyTo; }
135 QString inReplyTo() { return _inReplyTo; }
136 void setMessageId(QString messageId) { _messageId = messageId; }
137 QString messageId() { return _messageId; }
138
139private:
140 QString _date, _subject, _inReplyTo, _messageId;
141 IMAPResponseAddressList _from, _sender, _replyTo, _to, _cc, _bcc;
142
143};
144
145class IMAPResponseStatusResponse : public IMAPResponseEnums
146{
147public:
148 IMAPResponseStatusResponse(IMAPResponseStatus status = (IMAPResponseStatus)0, QString comment = 0, IMAPResponseCode code = (IMAPResponseCode)0)
149 {
150 _status = status;
151 _comment = comment;
152 _code = code;
153 }
154
155 void setStatus(IMAPResponseStatus status) { _status = status; }
156 IMAPResponseStatus status() { return _status; }
157 void setComment(QString comment) { _comment = comment; }
158 QString comment() { return _comment; }
159 void setResponseCode(IMAPResponseCode code) { _code = code; }
160 IMAPResponseCode responseCode() { return _code; }
161
162 void setExitedUnexpected(bool exitu) { _exitu = exitu; }
163 bool exitedUnexpected() { return _exitu; }
164
165private:
166 IMAPResponseStatus _status;
167 QString _comment;
168 IMAPResponseCode _code;
169 bool _exitu;
170
171};
172
173class IMAPResponseOK : public IMAPResponseEnums
174{
175public:
176 IMAPResponseOK(QString comment = 0, IMAPResponseCode code = (IMAPResponseCode)0)
177 {
178 _comment = comment;
179 _code = code;
180 }
181
182 void setComment(QString comment) { _comment = comment; }
183 QString comment() { return _comment; }
184 void setResponseCode(IMAPResponseCode code) { _code = code; }
185 IMAPResponseCode responseCode() { return _code; }
186
187private:
188 QString _comment;
189 IMAPResponseCode _code;
190
191};
192
193class IMAPResponseNO : public IMAPResponseEnums
194{
195public:
196 IMAPResponseNO(QString comment = 0, IMAPResponseCode code = (IMAPResponseCode)0)
197 {
198 _comment = comment;
199 _code = code;
200 }
201
202 void setComment(QString comment) { _comment = comment; }
203 QString comment() { return _comment; }
204 void setResponseCode(IMAPResponseCode code) { _code = code; }
205 IMAPResponseCode responseCode() { return _code; }
206
207private:
208 QString _comment;
209 IMAPResponseCode _code;
210
211};
212
213class IMAPResponseBAD : public IMAPResponseEnums
214{
215public:
216 IMAPResponseBAD(QString comment = 0, IMAPResponseCode code = (IMAPResponseCode)0)
217 {
218 _comment = comment;
219 _code = code;
220 }
221
222 void setComment(QString comment) { _comment = comment; }
223 QString comment() { return _comment; }
224 void setResponseCode(IMAPResponseCode code) { _code = code; }
225 IMAPResponseCode responseCode() { return _code; }
226
227private:
228 QString _comment;
229 IMAPResponseCode _code;
230
231};
232
233class IMAPResponseCAPABILITY
234{
235public:
236 IMAPResponseCAPABILITY(QStringList capabilities = 0)
237 {
238 _capabilities = capabilities;
239 }
240
241 void setCapabilities(QStringList capabilities) { _capabilities = capabilities; }
242 QStringList capabilities() { return _capabilities; }
243
244private:
245 QStringList _capabilities;
246
247};
248
249class IMAPResponseLIST : public IMAPResponseEnums
250{
251public:
252 IMAPResponseLIST(QValueList<IMAPResponseFlags> flags = QValueList<IMAPResponseFlags>(), QString folderSeparator = 0, QString folder = 0)
253 {
254 _flags = flags;
255 _folderSeparator = folderSeparator;
256 _folder = folder;
257 }
258
259 void setFlags(QValueList<IMAPResponseFlags> flags) { _flags = flags; }
260 QValueList<IMAPResponseFlags> flags() { return _flags; }
261 void setFolderSeparator(QString folderSeparator) { _folderSeparator = folderSeparator; }
262 QString folderSeparator() { return _folderSeparator; }
263 void setFolder(QString folder) { _folder = folder; }
264 QString folder() { return _folder; }
265
266private:
267 QValueList<IMAPResponseFlags> _flags;
268 QString _folderSeparator, _folder;
269
270};
271
272class IMAPResponseLSUB : public IMAPResponseEnums
273{
274public:
275 IMAPResponseLSUB(QValueList<IMAPResponseFlags> flags = QValueList<IMAPResponseFlags>(), QString folderSeperator = 0, QString folder = 0)
276 {
277 _flags = flags;
278 _folderSeperator = folderSeperator;
279 _folder = folder;
280 }
281
282 void setFlags(QValueList<IMAPResponseFlags> flags) { _flags = flags; }
283 QValueList<IMAPResponseFlags> flags() { return _flags; }
284 void setFolderSeperator(QString folderSeperator) { _folderSeperator = folderSeperator; }
285 QString folderSeperator() { return _folderSeperator; }
286 void setFolder(QString folder) { _folder = folder; }
287 QString folder() { return _folder; }
288
289private:
290 QValueList<IMAPResponseFlags> _flags;
291 QString _folderSeperator, _folder;
292
293};
294
295class IMAPResponseSTATUS
296{
297public:
298 IMAPResponseSTATUS(QString mailbox = 0, QString messages = 0, QString recent = 0, QString uidnext = 0, QString uidvalidity = 0, QString unseen = 0)
299 {
300 _mailbox = mailbox;
301 _messages = messages;
302 _recent = recent;
303 _uidnext = uidnext;
304 _uidvalidity = uidvalidity;
305 _unseen = unseen;
306 }
307
308 void setMailbox(QString &mailbox) { _mailbox = mailbox; }
309 QString mailbox() { return _mailbox; }
310 void setMessages(QString &messages) { _messages = messages; }
311 QString messages() { return _messages; }
312 void setRecent(QString &recent) { _recent = recent; }
313 QString recent() { return _recent; }
314 void setUidnext(QString &uidnext) { _uidnext = uidnext; }
315 QString uidnext() { return _uidnext; }
316 void setUidvalidity(QString &uidvalidity) { _uidvalidity = uidvalidity; }
317 QString uidvalidity() { return _uidvalidity; }
318 void setUnseen(QString &unseen) { _unseen = unseen; }
319 QString unseen() { return _unseen; }
320
321private:
322 QString _mailbox, _messages, _recent, _uidnext, _uidvalidity, _unseen;
323
324};
325
326class IMAPResponseSEARCH
327{
328public:
329 IMAPResponseSEARCH(QStringList mails = 0)
330 {
331 _mails = mails;
332 }
333
334 void setMails(QStringList mails) { _mails = mails; }
335 QStringList mails() { return _mails; }
336
337private:
338 QStringList _mails;
339
340};
341
342class IMAPResponseFLAGS : public IMAPResponseEnums
343{
344public:
345 IMAPResponseFLAGS(QValueList<IMAPResponseFlags> flags = QValueList<IMAPResponseFlags>())
346 {
347 _flags = flags;
348 }
349
350 void setFlags(QValueList<IMAPResponseFlags> flags) { _flags = flags; }
351 QValueList<IMAPResponseFlags> flags() { return _flags; }
352
353private:
354 QValueList<IMAPResponseFlags> _flags;
355
356};
357
358class IMAPResponseEXISTS
359{
360public:
361 IMAPResponseEXISTS(QString mails = 0)
362 {
363 _mails = mails;
364 }
365
366 void setMails(QString mails) { _mails = mails; }
367 QString mails() { return _mails; }
368
369private:
370 QString _mails;
371
372};
373
374class IMAPResponseRECENT
375{
376public:
377 IMAPResponseRECENT(QString mails = 0)
378 {
379 _mails = mails;
380 }
381
382 void setMails(QString mails) { _mails = mails; }
383 QString mails() { return _mails; }
384
385private:
386 QString _mails;
387
388};
389
390class IMAPResponseEXPUNGE
391{
392public:
393 IMAPResponseEXPUNGE(QString mails = 0)
394 {
395 _mails = mails;
396 }
397
398 void setMails(QString mails) { _mails = mails; }
399 QString mails() { return _mails; }
400
401private:
402 QString _mails;
403
404};
405
406class IMAPResponseFETCH : public IMAPResponseEnums
407{
408public:
409 void setEnvelope(IMAPResponseEnvelope envelope) { _envelope = envelope; }
410 IMAPResponseEnvelope envelope() { return _envelope; }
411 void setFlags(QValueList<IMAPResponseFlags> flags) { _flags = flags; }
412 QValueList<IMAPResponseFlags> flags() { return _flags; }
413 void setInternalDate(QString idate) { _idate = idate; }
414 QString internalDate() { return _idate; }
415 void setRFC822Size(QString rfc822size) { _rfc822size = rfc822size; }
416 QString RFC822Size() { return _rfc822size; }
417 void setUid(QString uid) { _uid = uid; }
418 QString uid() { return _uid; }
419
420 void setBody(QString body) { _body = body; }
421 QString body() { return _body; }
422 void addBodyPart(IMAPResponseBodyPart part) { _bodyParts.append(part); }
423 void setBodyParts(QValueList<IMAPResponseBodyPart> parts) { _bodyParts = parts; }
424 QValueList<IMAPResponseBodyPart> bodyParts() { return _bodyParts; }
425 IMAPResponseBodyPart bodyPart(int part) { return _bodyParts[part]; }
426 void setRfc822(QString rfc822) { _rfc822 = rfc822; }
427 QString rfc822() { return _rfc822; }
428 void setRfc822Header(QString rfc822Header) { _rfc822Header = rfc822Header; }
429 QString rfc822Header() { return _rfc822Header; }
430 void setRfc822Text(QString rfc822Text) { _rfc822Text = rfc822Text; }
431 QString rfc822Text() { return _rfc822Text; }
432
433private:
434 IMAPResponseEnvelope _envelope;
435 QValueList<IMAPResponseFlags> _flags;
436 QString _idate, _rfc822size, _uid, _body, _rfc822, _rfc822Header, _rfc822Text;
437 QValueList<IMAPResponseBodyPart> _bodyParts;
438
439};
440
441class IMAPResponse : public IMAPResponseEnums
442{
443public:
444 void setTag(QString tag) { _tag = tag; }
445 QString tag() { return _tag; }
446
447 void setImapHandler(IMAPHandler *handler) { _handler = handler; }
448 IMAPHandler *imapHandler() { return _handler; }
449
450 void setStatusResponse(IMAPResponseStatusResponse response) { _response = response; }
451 IMAPResponseStatusResponse statusResponse() { return _response; }
452
453 void addOK(IMAPResponseOK ok) { _okl.append(ok); }
454 void addNO(IMAPResponseNO no) { _nol.append(no); }
455 void addBAD(IMAPResponseBAD bad) { _badl.append(bad); }
456 void addCAPABILITY(IMAPResponseCAPABILITY capability) { _capabilityl.append(capability); }
457 void addLIST(IMAPResponseLIST list) { _listl.append(list); }
458 void addLSUB(IMAPResponseLSUB lsub) { _lsubl.append(lsub); }
459 void addSTATUS(IMAPResponseSTATUS status) { _statusl.append(status); }
460 void addSEARCH(IMAPResponseSEARCH search) { _searchl.append(search); }
461 void addFLAGS(IMAPResponseFLAGS flags) { _flagsl.append(flags); }
462 void addEXISTS(IMAPResponseEXISTS exists) { _existsl.append(exists); }
463 void addRECENT(IMAPResponseRECENT recent) { _recentl.append(recent); }
464 void addEXPUNGE(IMAPResponseEXPUNGE expunge) { _expungel.append(expunge); }
465 void addFETCH(IMAPResponseFETCH fetch) { _fetchl.append(fetch); }
466
467 QValueList<IMAPResponseOK> OK() { return _okl; }
468 QValueList<IMAPResponseNO> NO() { return _nol; }
469 QValueList<IMAPResponseBAD> BAD() { return _badl; }
470 QValueList<IMAPResponseCAPABILITY> CAPABILITY() { return _capabilityl; }
471 QValueList<IMAPResponseLIST> LIST() { return _listl; }
472 QValueList<IMAPResponseLSUB> LSUB() { return _lsubl; }
473 QValueList<IMAPResponseSTATUS> STATUS() { return _statusl; }
474 QValueList<IMAPResponseSEARCH> SEARCH() { return _searchl; }
475 QValueList<IMAPResponseFLAGS> FLAGS() { return _flagsl; }
476 QValueList<IMAPResponseEXISTS> EXISTS() { return _existsl; }
477 QValueList<IMAPResponseRECENT> RECENT() { return _recentl; }
478 QValueList<IMAPResponseEXPUNGE> EXPUNGE() { return _expungel; }
479 QValueList<IMAPResponseFETCH> FETCH() { return _fetchl; }
480
481private:
482 QString _tag;
483 IMAPResponseStatusResponse _response;
484
485 IMAPHandler *_handler;
486
487 QValueList<IMAPResponseOK> _okl;
488 QValueList<IMAPResponseNO> _nol;
489 QValueList<IMAPResponseBAD> _badl;
490 QValueList<IMAPResponseCAPABILITY> _capabilityl;
491 QValueList<IMAPResponseLIST> _listl;
492 QValueList<IMAPResponseLSUB> _lsubl;
493 QValueList<IMAPResponseSTATUS> _statusl;
494 QValueList<IMAPResponseSEARCH> _searchl;
495 QValueList<IMAPResponseFLAGS> _flagsl;
496 QValueList<IMAPResponseEXISTS> _existsl;
497 QValueList<IMAPResponseRECENT> _recentl;
498 QValueList<IMAPResponseEXPUNGE> _expungel;
499 QValueList<IMAPResponseFETCH> _fetchl;
500
501};
502
503class IMAPResponseParser : public QObject, public IMAPResponseEnums
504{
505 Q_OBJECT
506
507public:
508 IMAPResponseParser(const QString &data);
509
510 IMAPResponse response();
511
512signals:
513 void needMoreData(const QString &comment);
514
515protected:
516 void parseResponse(const QString &data, bool tagged = false);
517
518 QStringList splitData(const QString &data, bool withBrackets);
519 void parseParenthesizedList(const QString &data, QStringList &parsed);
520 void splitTagData(const QString &line, QString &tag, QString &data);
521 QString removeLimiters(QString &string, const QChar &sl = '"', const QChar &el = '"');
522 IMAPResponseCode getResponseCode(const QString &line);
523 QValueList<IMAPResponseFlags> parseFlagList(const QStringList &flags);
524
525private:
526 IMAPResponse _iresponse;
527
528};
529
530#endif
531
diff --git a/noncore/unsupported/mail2/libmail/libmail.pro b/noncore/unsupported/mail2/libmail/libmail.pro
new file mode 100644
index 0000000..662af90
--- a/dev/null
+++ b/noncore/unsupported/mail2/libmail/libmail.pro
@@ -0,0 +1,26 @@
1 TEMPLATE =lib
2 CONFIG =qt warn_on release
3 HEADERS =configfile.h \
4 defines.h \
5 imapbase.h \
6 imaphandler.h \
7 imapresponse.h \
8 mailfactory.h \
9 md5.cpp \
10 miscfunctions.h \
11 sharp_char.h \
12 smtphandler.h \
13 zaurusstuff.h
14 SOURCES =configfile.cpp \
15 imapbase.cpp \
16 imaphandler.cpp \
17 imapresponse.cpp \
18 mailfactory.cpp \
19 md5.h \
20 miscfunctions.cpp \
21 smtphandler.cpp \
22 zaurusstuff.cpp
23 INCLUDEPATH +=$(OPIEDIR)/include
24 LIBS +=-L$(OPIEDIR)/lib -lqpe
25 TARGET =mail
26 DESTDIR =$(QTDIR)/lib
diff --git a/noncore/unsupported/mail2/libmail/mailfactory.cpp b/noncore/unsupported/mail2/libmail/mailfactory.cpp
new file mode 100644
index 0000000..58cf5f8
--- a/dev/null
+++ b/noncore/unsupported/mail2/libmail/mailfactory.cpp
@@ -0,0 +1,173 @@
1#include <qmessagebox.h>
2#include <qtextstream.h>
3#include <qfile.h>
4
5#include <qpe/mimetype.h>
6
7#include "miscfunctions.h"
8#include "mailfactory.h"
9#include "defines.h"
10
11MailFactory::MailFactory(SendMail &smail, QWidget *parent)
12 : QObject(), _smail(smail), _parent(parent)
13{
14 _abort = false;
15 Account account = _smail.account();
16
17 if (!_smail.from().isEmpty())
18 _header += "From: " + _smail.from() + "\n";
19 if (!_smail.replyTo().isEmpty())
20 _header += "Reply-To: " + _smail.replyTo() + "\n";
21 if (!_smail.to().isEmpty())
22 _header += "To: " + _smail.to() + "\n";
23 if (!_smail.cc().isEmpty())
24 _header += "Cc: " + _smail.cc() + "\n";
25 if (!_smail.bcc().isEmpty())
26 _header += "Bcc: " + _smail.bcc() + "\n";
27 if (!_smail.subject().isEmpty())
28 _header += "Subject: " + _smail.subject() + "\n";
29 if (!_smail.priority().isEmpty() || (_smail.priority() != "Normal"))
30 _header += "Priority: " + _smail.priority() + "\n";
31 _header += "Date: " + MiscFunctions::rfcDate() + "\n";
32 if (!_smail.account().org().isEmpty())
33 _header += "Organization: " + _smail.account().org() + "\n";
34 if (_smail.needsMime())
35 _header += "Mime-Version: 1.0\n";
36 _header += "Message-Id: <" + MiscFunctions::uniqueString() + "." + account.email() + ">\n";
37 if (!_smail.inReplyTo().isEmpty())
38 _header += "In-Reply-To: " + _smail.inReplyTo() + "\n";
39 if (!QString((QString) USERAGENT).isEmpty())
40 _header += (QString) "User-Agent: " + USERAGENT + "\n";
41
42 if (!_smail.needsMime()) {
43 // if (_smail.encrypt() && !_smail.sign()) {
44 // openPgpEncrypt(_smail.message(), _header, _body);
45 // } else if (!_smail.encrypt() && _smail.sign()) {
46 // openPgpSign(_smail.message(), _header, _body);
47 // } else if (_smail.encrypt() && _smail.sign()) {
48 // openPgpSignEncrypt(_smail.message(), _header, _body);
49 // } else {
50 _body += _smail.message();
51 // }
52 } else {
53 QString boundary = MiscFunctions::uniqueString();
54
55 _header += "Content-Type: multipart/mixed; boundary=\"" + boundary + "\"\n";
56
57 _body += "This is a multi-part message in MIME format.\n\n";
58 _body += "--" + boundary + "\n";
59
60 // if (_smail.encrypt() && !_smail.sign()) {
61 // QString header, body;
62 // openPgpEncrypt(_smail.message(), header, body);
63 // _body += header + "\n" + body + "\n";
64 // } else if (!_smail.encrypt() && _smail.sign()) {
65 // QString header, body;
66 // openPgpSign(_smail.message(), header, body);
67 // _body += header + "\n" + body + "\n";
68 // } else if (_smail.encrypt() && _smail.sign()) {
69 // QString header, body;
70 // openPgpSignEncrypt(_smail.message(), header, body);
71 // _body += header + "\n" + body + "\n";
72 // } else {
73
74 // TODO: Do proper charset handling!
75 _body += "Content-Type: text/plain; charset=\"iso-8859-1\"\n";
76 _body += "Content-Transfer-Encoding: 8bit\n\n";
77 _body += _smail.message() + "\n";
78 // }
79
80 QValueList<Attachment> attachments = _smail.attachments();
81 QValueList<Attachment>::Iterator it;
82 for (it = attachments.begin(); it != attachments.end(); it++) {
83 QFile f((*it).fileName());
84 if (f.open(IO_ReadOnly)) {
85 QTextStream t(&f);
86 QString file;
87 while (!t.atEnd()) file += t.readLine() + "\n";
88 f.close();
89 QString mimetype = (new MimeType(*(*it).docLnk()))->id();
90
91 _body += "\n--" + boundary + "\n";
92 _body += "Content-Type: " + mimetype + "; name=\"" + (*it).newName() + "\"\n";
93
94 // TODO: Decide which content transfer encoding is best. B64 for binary, QP for text.
95 _body += "Content-Transfer-Encoding: base64\n";
96
97 _body += "Content-Disposition: attachment; filename=\"" + (*it).newName() + "\"\n";
98 if (!(*it).description().isEmpty())
99 _body += "Content-Description: " + (*it).description() + "\n";
100
101 _body += "\n" + MiscFunctions::encodeBase64(file) + "\n";
102 } else {
103 int ret = QMessageBox::critical(_parent, tr("Error"), tr("<p>Couldn't attach file '%1'. Continue anyway or abort?</p>"), tr("Continue"), tr("Abort"));
104 if (ret == 1) {
105 it = attachments.end();
106 _abort = true;
107 }
108 }
109 }
110 _body += "\n--" + boundary + "--";
111 }
112
113 if (_abort) {
114 _body = QString(0);
115 _header = QString(0);
116 }
117}
118
119// Unfinished GPG code.
120/*
121void MailFactory::openPgpEncrypt(const QString &text, QString &header, QString &body)
122{
123 QString boundary = MiscFunctions::uniqueString();
124
125 header += "Content-Type: multipart/encrypted; boundary=\"" + boundary + "\"; protocol=\"application/pgp-encrypted\"\n";
126
127 body += "--" + boundary + "\n";
128 body += "Content-Type: application/pgp-encrypted\n\n";
129 body += "Version: 1\n\n";
130 body += "--" + boundary + "\n";
131 body += "Content-Type: application/octet-stream\n\n";
132 body += GpgHandling::encrypt(_smail.gpgReceivers(), text);
133 body += "\n--" + boundary + "--\n";
134}
135
136void MailFactory::openPgpSign(const QString &text, QString &header, QString &body)
137{
138 QString boundary = MiscFunctions::uniqueString();
139
140 header += "Content-Type: multipart/signed; boundary=\"" + boundary + "\"; protocol=\"application/pgp-signature\"\n";
141
142 body += "--" + boundary + "\n";
143
144 QString temp;
145 temp += "Content-Type: text/plain; charset=\"iso-8859-1\"\n";
146 temp += "Content-Transfer-Encoding: quoted-printable\n\n";
147 temp += MiscFunctions::encodeQPrintable(text) + "\n";
148 body += temp;
149
150 temp.replace(QRegExp("\n"), "\r\n");
151 QString signature = GpgHandling::sign(temp, _parent);
152
153 body += "\n--" + boundary + "\n";
154 body += "Content-Type: application/pgp-signature\n\n";
155 body += signature + "\n";
156 body += "\n--" + boundary + "--\n";
157}
158
159void MailFactory::openPgpSignEncrypt(const QString &text, QString &header, QString &message)
160{
161 QString header_, message_;
162 openPgpSign(text, header_, message_);
163 openPgpEncrypt(header_ + "\n" + message_, header, message);
164}
165*/
166void MailFactory::genMail(QString &header, QString &message, SendMail &smail, QWidget *parent)
167{
168 MailFactory factory(smail, parent);
169
170 header = factory._header;
171 message = factory._body;
172}
173
diff --git a/noncore/unsupported/mail2/libmail/mailfactory.h b/noncore/unsupported/mail2/libmail/mailfactory.h
new file mode 100644
index 0000000..8f67447
--- a/dev/null
+++ b/noncore/unsupported/mail2/libmail/mailfactory.h
@@ -0,0 +1,109 @@
1#ifndef MAILFACTORY_H
2#define MAILFACTORY_H
3
4#include <qobject.h>
5
6#include <qpe/applnk.h>
7
8#include "configfile.h"
9
10class Attachment
11{
12public:
13 void setFileName(QString fileName) { _fileName = fileName; }
14 void setNewName(QString newName) { _newName = newName; }
15 void setDescription(QString description) { _description = description; }
16 void setDocLnk(DocLnk *docLnk) { _docLnk = docLnk; }
17
18 QString fileName() { return _fileName; }
19 QString newName() { return _newName; }
20 QString description() { return _description; }
21 DocLnk *docLnk() { return _docLnk; }
22
23protected:
24 QString _fileName, _newName, _description;
25 DocLnk *_docLnk;
26
27};
28
29class SendMail
30{
31public:
32 SendMail() { _needsMime = false; }
33
34 void setAccount(Account account) { _account = account; }
35
36 void setFrom(QString from) { _from = from; }
37 void setReplyTo(QString replyTo) { _replyTo = replyTo; }
38 void setTo(QString to) { _to = to; }
39 void setCc(QString cc) { _cc = cc; }
40 void setBcc(QString bcc) { _bcc = bcc; }
41 void setSubject(QString subject) { _subject = subject; }
42 void setPriority(QString priority) { _priority = priority; }
43 void setMessage(QString message) { _message = message; }
44 void setInReplyTo(QString inReplyTo) { _inReplyTo = inReplyTo; }
45
46 void setNeedsMime(bool needsMime) { _needsMime = needsMime; }
47
48 //void setEncrypt(bool encrypt) { _encrypt = encrypt; }
49 //void setSign(bool sign) { _sign = sign; }
50 //void setGpgReceivers(QValueList<GpgKey> receivers) { _receivers = receivers; }
51 //void setGpgPassphrase(QString passphrase) { _passphrase = passphrase; }
52
53 void setAttachments(QValueList<Attachment> attachments) { _attachments = attachments; }
54 void addAttachment(Attachment attachment) { _attachments.append(attachment); }
55
56 Account account() { return _account; }
57
58 QString from() { return _from; }
59 QString replyTo() { return _replyTo; }
60 QString to() { return _to; }
61 QString cc() { return _cc; }
62 QString bcc() { return _bcc; }
63 QString subject() { return _subject; }
64 QString priority() { return _priority; }
65 QString message() { return _message; }
66 QString inReplyTo() { return _inReplyTo; }
67
68 bool needsMime() { return _needsMime; }
69
70 //bool encrypt() { return _encrypt; }
71 //bool sign() { return _sign; }
72 //QValueList<GpgKey> gpgReceivers() { return _receivers; }
73 //QString gpgPassphrase() { return _passphrase; }
74
75 QValueList<Attachment> attachments() { return _attachments; }
76
77protected:
78 Account _account;
79 QString _from, _replyTo, _to, _cc, _bcc, _subject, _priority, _message, _inReplyTo;
80 bool _needsMime;
81 //bool _encrypt, _sign;
82 //QValueList<GpgKey> _receivers;
83 //QString _passphrase;
84 QValueList<Attachment> _attachments;
85
86};
87
88class MailFactory : public QObject
89{
90 Q_OBJECT
91
92public:
93 static void genMail(QString &header, QString &message, SendMail &smail, QWidget *parent);
94
95protected:
96 MailFactory(SendMail &smail, QWidget *parent);
97
98 //void openPgpEncrypt(const QString &text, QString &header, QString &message);
99 //void openPgpSign(const QString &text, QString &header, QString &message);
100 //void openPgpSignEncrypt(const QString &text, QString &header, QString &message);
101
102 bool _abort;
103 SendMail _smail;
104 QWidget *_parent;
105 QString _header, _body;
106
107};
108
109#endif
diff --git a/noncore/unsupported/mail2/libmail/md5.cpp b/noncore/unsupported/mail2/libmail/md5.cpp
new file mode 100644
index 0000000..4ee2c42
--- a/dev/null
+++ b/noncore/unsupported/mail2/libmail/md5.cpp
@@ -0,0 +1,242 @@
1// This code was written by Colin Plumb. I've made some small changes.
2// (Constantin Bergemann)
3
4#ifdef __cplusplus
5extern "C" {
6#endif
7
8 #include <string.h> /* for memcpy() */
9#include "md5.h"
10
11#if __BYTE_ORDER == 1234
12 #define byteReverse(buf, len)/* Nothing */
13#else
14void byteReverse(unsigned char *buf, unsigned longs);
15
16/*
17 * Note: this code is harmless on little-endian machines.
18 */
19void byteReverse(unsigned char *buf, unsigned longs)
20{
21 u_int32_t t;
22 do {
23 t = (u_int32_t) ((unsigned) buf[3] << 8 | buf[2]) << 16 |
24 ((unsigned) buf[1] << 8 | buf[0]);
25 *(u_int32_t *) buf = t;
26 buf += 4;
27 } while (--longs);
28}
29#endif
30
31/*
32 * Start MD5 accumulation. Set bit count to 0 and buffer to mysterious
33 * initialization constants.
34 */
35void MD5_Init(MD5_CTX *ctx)
36{
37 ctx->buf[0] = 0x67452301;
38 ctx->buf[1] = 0xefcdab89;
39 ctx->buf[2] = 0x98badcfe;
40 ctx->buf[3] = 0x10325476;
41
42 ctx->bits[0] = 0;
43 ctx->bits[1] = 0;
44}
45
46/*
47 * Update context to reflect the concatenation of another buffer full
48 * of bytes.
49 */
50void MD5_Update(MD5_CTX *ctx, unsigned char const *buf, unsigned len)
51{
52 u_int32_t t;
53
54 /* Update bitcount */
55
56 t = ctx->bits[0];
57 if ((ctx->bits[0] = t + ((u_int32_t) len << 3)) < t)
58 ctx->bits[1]++; /* Carry from low to high */
59 ctx->bits[1] += len >> 29;
60
61 t = (t >> 3) & 0x3f;/* Bytes already in shsInfo->data */
62
63 /* Handle any leading odd-sized chunks */
64
65 if (t) {
66 unsigned char *p = (unsigned char *) ctx->in + t;
67
68 t = 64 - t;
69 if (len < t) {
70 memcpy(p, buf, len);
71 return;
72 }
73 memcpy(p, buf, t);
74 byteReverse(ctx->in, 16);
75 MD5Transform(ctx->buf, (u_int32_t *) ctx->in);
76 buf += t;
77 len -= t;
78 }
79 /* Process data in 64-byte chunks */
80
81 while (len >= 64) {
82 memcpy(ctx->in, buf, 64);
83 byteReverse(ctx->in, 16);
84 MD5Transform(ctx->buf, (u_int32_t *) ctx->in);
85 buf += 64;
86 len -= 64;
87 }
88
89 /* Handle any remaining bytes of data. */
90
91 memcpy(ctx->in, buf, len);
92}
93
94/*
95 * Final wrapup - pad to 64-byte boundary with the bit pattern
96 * 1 0* (64-bit count of bits processed, MSB-first)
97 */
98void MD5_Final(unsigned char digest[16], MD5_CTX *ctx)
99{
100 unsigned count;
101 unsigned char *p;
102
103 /* Compute number of bytes mod 64 */
104 count = (ctx->bits[0] >> 3) & 0x3F;
105
106 /* Set the first char of padding to 0x80. This is safe since there is
107 always at least one byte free */
108 p = ctx->in + count;
109 *p++ = 0x80;
110
111 /* Bytes of padding needed to make 64 bytes */
112 count = 64 - 1 - count;
113
114 /* Pad out to 56 mod 64 */
115 if (count < 8) {
116 /* Two lots of padding: Pad the first block to 64 bytes */
117 memset(p, 0, count);
118 byteReverse(ctx->in, 16);
119 MD5Transform(ctx->buf, (u_int32_t *) ctx->in);
120
121 /* Now fill the next block with 56 bytes */
122 memset(ctx->in, 0, 56);
123 } else {
124 /* Pad block to 56 bytes */
125 memset(p, 0, count - 8);
126 }
127 byteReverse(ctx->in, 14);
128
129 /* Append length in bits and transform */
130 ((u_int32_t *) ctx->in)[14] = ctx->bits[0];
131 ((u_int32_t *) ctx->in)[15] = ctx->bits[1];
132
133 MD5Transform(ctx->buf, (u_int32_t *) ctx->in);
134 byteReverse((unsigned char *) ctx->buf, 4);
135 memcpy(digest, ctx->buf, 16);
136 memset((char *) ctx, 0, sizeof(ctx));/* In case it's sensitive */
137}
138
139/* The four core functions - F1 is optimized somewhat */
140
141/* #define F1(x, y, z) (x & y | ~x & z) */
142#define F1(x, y, z) (z ^ (x & (y ^ z)))
143#define F2(x, y, z) F1(z, x, y)
144#define F3(x, y, z) (x ^ y ^ z)
145#define F4(x, y, z) (y ^ (x | ~z))
146
147/* This is the central step in the MD5 algorithm. */
148#define MD5STEP(f, w, x, y, z, data, s) \
149 ( w += f(x, y, z) + data, w = w<<s | w>>(32-s), w += x )
150
151/*
152 * The core of the MD5 algorithm, this alters an existing MD5 hash to
153 * reflect the addition of 16 longwords of new data. MD5Update blocks
154 * the data and converts bytes into longwords for this routine.
155 */
156void MD5Transform(u_int32_t buf[4], u_int32_t const in[16])
157{
158 register u_int32_t a, b, c, d;
159
160 a = buf[0];
161 b = buf[1];
162 c = buf[2];
163 d = buf[3];
164
165 MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7);
166 MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12);
167 MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17);
168 MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22);
169 MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7);
170 MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12);
171 MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17);
172 MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22);
173 MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7);
174 MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12);
175 MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17);
176 MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22);
177 MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7);
178 MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12);
179 MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17);
180 MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22);
181
182 MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5);
183 MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9);
184 MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14);
185 MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20);
186 MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5);
187 MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9);
188 MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14);
189 MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20);
190 MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5);
191 MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9);
192 MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14);
193 MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20);
194 MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5);
195 MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9);
196 MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14);
197 MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20);
198
199 MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4);
200 MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11);
201 MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16);
202 MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23);
203 MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4);
204 MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11);
205 MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16);
206 MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23);
207 MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4);
208 MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11);
209 MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16);
210 MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23);
211 MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4);
212 MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11);
213 MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16);
214 MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23);
215
216 MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6);
217 MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10);
218 MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15);
219 MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21);
220 MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6);
221 MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10);
222 MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15);
223 MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21);
224 MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6);
225 MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10);
226 MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15);
227 MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21);
228 MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6);
229 MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10);
230 MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15);
231 MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21);
232
233 buf[0] += a;
234 buf[1] += b;
235 buf[2] += c;
236 buf[3] += d;
237}
238
239#ifdef __cplusplus
240} // extern "C"
241#endif
242
diff --git a/noncore/unsupported/mail2/libmail/md5.h b/noncore/unsupported/mail2/libmail/md5.h
new file mode 100644
index 0000000..221dd09
--- a/dev/null
+++ b/noncore/unsupported/mail2/libmail/md5.h
@@ -0,0 +1,35 @@
1// This code was written by Colin Plumb. I've made some small changes.
2// (Constantin Bergemann)
3
4#ifndef _MD5_H_
5#define _MD5_H_
6
7#include <sys/types.h>
8
9#ifdef __cplusplus
10extern "C" {
11#endif
12
13#define MD5_HASHBYTES 16
14
15typedef struct MD5Context {
16 u_int32_t buf[4];
17 u_int32_t bits[2];
18 unsigned char in[64];
19} MD5_CTX;
20
21extern void MD5_Init(MD5_CTX *context);
22extern void MD5_Update(MD5_CTX *context, unsigned char const *buf,
23 unsigned len);
24extern void MD5_Final(unsigned char digest[MD5_HASHBYTES], MD5_CTX *context);
25extern void MD5Transform(u_int32_t buf[4], u_int32_t const in[16]);
26extern char * MD5End(MD5_CTX *, char *);
27extern char * MD5File(const char *, char *);
28extern char * MD5Data (const unsigned char *, unsigned int, char *);
29
30#ifdef __cplusplus
31} // extern "C"
32#endif
33
34#endif /* !_MD5_H_ */
35
diff --git a/noncore/unsupported/mail2/libmail/miscfunctions.cpp b/noncore/unsupported/mail2/libmail/miscfunctions.cpp
new file mode 100644
index 0000000..0edbfa8
--- a/dev/null
+++ b/noncore/unsupported/mail2/libmail/miscfunctions.cpp
@@ -0,0 +1,295 @@
1#include <qdatetime.h>
2
3#include <stdlib.h>
4#include <stdio.h>
5#include <time.h>
6
7#include <openssl/md5.h>
8
9#include "miscfunctions.h"
10
11QString MiscFunctions::encodeQPrintable(const QString &src)
12{
13 // TODO: implent encodeQPrintable
14 return src;
15}
16
17QString MiscFunctions::decodeQPrintable(const QString &src)
18{
19 QString out;
20
21 for (unsigned int i = 0; i <= src.length(); i++) {
22 if (src[i] == '=') {
23 if (src[i+1] == "\n") {
24 i += 1;
25 } else {
26 QString temp = QString("%1%2").arg(src[i+1]).arg(src[i+2]);
27 int number = temp.toInt(0, 16);
28
29 out += QChar(number);
30 i += 2;
31 }
32 } else {
33 out += src[i];
34 }
35 }
36 return out;
37}
38
39QString MiscFunctions::encodeBase64(const QString &src)
40{
41 char *dataPtr = (char *) src.latin1();
42 int len = src.length();
43 int count = 0;
44 QString temp = "";
45
46 while (len > 0) {
47 if (len < 3) {
48 encodeBase64Base(dataPtr, &temp, len);
49 len = 0;
50 } else {
51 encodeBase64Base(dataPtr, &temp, 3);
52 len -= 3;
53 dataPtr += 3;
54 count += 4;
55 }
56 if (count > 72) {
57 count = 0;
58 temp += "\n";
59 }
60 }
61
62 return temp;
63}
64
65void MiscFunctions::encodeBase64Base(char *src, QString *dest, int len)
66{
67 QString temp;
68 uchar c;
69 uchar bufOut[4];
70
71 bufOut[0] = src[0];
72 bufOut[0] >>= 2;
73
74 bufOut[1] = src[0];
75 bufOut[1] = bufOut[1] & (1 + 2);
76 bufOut[1] <<= 4;
77 if (len > 1) c = src[1];
78 else c = 0;
79
80 c = c & (16 + 32 + 64 + 128);
81 c >>= 4;
82 bufOut[1] = bufOut[1] | c;
83
84 bufOut[2] = src[1];
85 bufOut[2] = bufOut[2] & (1 + 2 + 4 + 8);
86 bufOut[2] <<= 2;
87 if (len > 2) c = src[2];
88 else c = 0;
89
90 c >>= 6;
91 bufOut[2] = bufOut[2] | c;
92
93 bufOut[3] = src[2];
94 bufOut[3] = bufOut[3] & (1 + 2 + 4 + 8 + 16 + 32);
95
96 if (len == 1) {
97 bufOut[2] = 64;
98 bufOut[3] = 64;
99 }
100 if (len == 2) {
101 bufOut[3] = 64;
102 }
103 for (int x = 0; x < 4; x++) {
104 if (bufOut[x] <= 25)
105 bufOut[x] += (uint) 'A';
106 else if (bufOut[x] >= 26 && bufOut[x] <= 51)
107 bufOut[x] += (uint) 'a' - 26;
108 else if (bufOut[x] >= 52 && bufOut[x] <= 61)
109 bufOut[x] += (uint) '0' - 52;
110 else if (bufOut[x] == 62)
111 bufOut[x] = '+';
112 else if (bufOut[x] == 63)
113 bufOut[x] = '/';
114 else if (bufOut[x] == 64)
115 bufOut[x] = '=';
116
117 dest->append(bufOut[x]);
118 }
119}
120
121QString MiscFunctions::decodeBase64(const QString &src)
122{
123 char plain[4];
124 char *destPtr;
125 QByteArray buffer;
126 uint bufCount = 0, pos = 0, decodedCount, x;
127
128 buffer.resize(src.length() * 3 / 4);
129 destPtr = buffer.data();
130
131 while (pos < src.length()) {
132 decodedCount = 4;
133 x = 0;
134 while ((x < 4) && (pos < src.length())) {
135 plain[x] = src[pos].latin1();
136 pos++;
137 if (plain[x] == '\r' || plain[x] == '\n' || plain[x] == ' ')
138 x--;
139 x++;
140 }
141 if (x > 1) {
142 decodedCount = decodeBase64Base(plain, destPtr);
143 destPtr += decodedCount;
144 bufCount += decodedCount;
145 }
146 }
147
148 buffer.resize(bufCount);
149 return QString(buffer);
150}
151
152int MiscFunctions::decodeBase64Base(char *src, char *bufOut)
153{
154 char c, z;
155 char li[4];
156 int processed;
157
158 for (int x = 0; x < 4; x++) {
159 c = src[x];
160
161 if ( (int) c >= 'A' && (int) c <= 'Z')
162 li[x] = (int) c - (int) 'A';
163 if ( (int) c >= 'a' && (int) c <= 'z')
164 li[x] = (int) c - (int) 'a' + 26;
165 if ( (int) c >= '0' && (int) c <= '9')
166 li[x] = (int) c - (int) '0' + 52;
167 if (c == '+')
168 li[x] = 62;
169 if (c == '/')
170 li[x] = 63;
171 }
172
173 processed = 1;
174 bufOut[0] = (char) li[0] & (32+16+8+4+2+1);
175 bufOut[0] <<= 2;
176 z = li[1] >> 4;
177 bufOut[0] = bufOut[0] | z;
178
179 if (src[2] != '=') {
180 bufOut[1] = (char) li[1] & (8+4+2+1);
181 bufOut[1] <<= 4;
182 z = li[2] >> 2;
183 bufOut[1] = bufOut[1] | z;
184 processed++;
185
186 if (src[3] != '=') {
187 bufOut[2] = (char) li[2] & (2+1);
188 bufOut[2] <<= 6;
189 z = li[3];
190 bufOut[2] = bufOut[2] | z;
191 processed++;
192 }
193 }
194 return processed;
195}
196
197QString MiscFunctions::uniqueString()
198{
199 QString uniqueString = QDate::currentDate().toString();
200 uniqueString += QTime::currentTime().toString();
201 uniqueString += QString("%1").arg(rand());
202
203 unsigned char md[16];
204
205 MD5_CTX ctx;
206 MD5_Init(&ctx);
207 MD5_Update(&ctx, (unsigned char *)uniqueString.latin1(), uniqueString.length());
208 MD5_Final(md, &ctx);
209
210 char hash[16];
211 for (unsigned int i = 0; i < sizeof(md); i++)
212 sprintf(hash + 2 * i, "%02x", md[i]);
213
214 return hash;
215}
216
217QString MiscFunctions::rfcDate()
218{
219 time_t t = time(NULL);
220 tm *time = localtime(&t);
221 QString pm, tzh, tzm, ths, tms, tss;
222
223 time->tm_gmtoff < 0 ? pm = "-" : pm = "+";
224 int h = abs(time->tm_gmtoff) / 3600;
225 int m = (abs(time->tm_gmtoff) - h * 3600) / 60;
226 h < 10 ? tzh = QString("0%1").arg(h) : tzh = QString("%1").arg(h);
227 m < 10 ? tzm = QString("0%1").arg(m) : tzm = QString("%1").arg(m);
228
229 int th = time->tm_hour;
230 int tm = time->tm_min;
231 int ts = time->tm_sec;
232 th < 10 ? ths = QString("0%1").arg(th) : ths = QString("%1").arg(th);
233 tm < 10 ? tms = QString("0%1").arg(tm) : tms = QString("%1").arg(tm);
234 ts < 10 ? tss = QString("0%1").arg(ts) : tss = QString("%1").arg(ts);
235
236 QString month = QDate().monthName(time->tm_mon + 1);
237 QString dayna = QDate().dayName(time->tm_wday);
238 QString tzone = pm + tzh + tzm;
239
240 return QString("%1, %2 %3 %4 %5:%6:%7 %8")
241 .arg(dayna)
242 .arg(time->tm_mday)
243 .arg(month)
244 .arg(time->tm_year + 1900)
245 .arg(ths)
246 .arg(tms)
247 .arg(tss)
248 .arg(tzone);
249}
250
251QString MiscFunctions::smtpAuthCramMd5(const QString &data, const QString &key)
252{
253 MD5_CTX context;
254 unsigned char k_ipad[65];
255 unsigned char k_opad[65];
256 unsigned char tk[16];
257 unsigned char digest[16];
258 unsigned char *key_int = (unsigned char *)key.latin1();
259 char hash[33];
260
261 if (key.length() > 64) {
262 MD5_CTX tctx;
263 MD5_Init(&tctx);
264 MD5_Update(&tctx, key_int, sizeof(key_int));
265 MD5_Final(tk, &tctx);
266
267 key_int = tk;
268 }
269
270 bzero(k_ipad, sizeof k_ipad);
271 bzero(k_opad, sizeof k_opad);
272 bcopy(key_int, k_ipad, sizeof(key_int));
273 bcopy(key_int, k_opad, sizeof(key_int));
274
275 for (int i = 0; i < 64; i++) {
276 k_ipad[i] ^= 0x36;
277 k_opad[i] ^= 0x5c;
278 }
279
280 MD5_Init(&context);
281 MD5_Update(&context, k_ipad, 64);
282 MD5_Update(&context, (unsigned char *)data.latin1(), data.length());
283 MD5_Final(digest, &context);
284
285 MD5_Init(&context);
286 MD5_Update(&context, k_opad, 64);
287 MD5_Update(&context, digest, 16);
288 MD5_Final(digest, &context);
289
290 for (unsigned int i = 0; i < sizeof(digest); i++)
291 sprintf (hash + 2 * i, "%02x", digest[i]);
292
293 return hash;
294}
295
diff --git a/noncore/unsupported/mail2/libmail/miscfunctions.h b/noncore/unsupported/mail2/libmail/miscfunctions.h
new file mode 100644
index 0000000..a13e1e3
--- a/dev/null
+++ b/noncore/unsupported/mail2/libmail/miscfunctions.h
@@ -0,0 +1,27 @@
1#ifndef MISCFUNCTIONS_H
2#define MISCFUNCTIONS_H
3
4#include <qobject.h>
5
6class MiscFunctions : public QObject
7{
8 Q_OBJECT
9
10public:
11 static QString encodeQPrintable(const QString &src);
12 static QString decodeQPrintable(const QString &src);
13 static QString encodeBase64(const QString &src);
14 static QString decodeBase64(const QString &src);
15 static QString uniqueString();
16 static QString rfcDate();
17 static QString smtpAuthCramMd5(const QString &data, const QString &key);
18
19protected:
20 MiscFunctions() : QObject() { }
21
22 static void encodeBase64Base(char *src, QString *dest, int len);
23 static int decodeBase64Base(char *src, char *bufOut);
24
25};
26
27#endif
diff --git a/noncore/unsupported/mail2/libmail/sharp_char.h b/noncore/unsupported/mail2/libmail/sharp_char.h
new file mode 100644
index 0000000..8bd8beb
--- a/dev/null
+++ b/noncore/unsupported/mail2/libmail/sharp_char.h
@@ -0,0 +1,241 @@
1/*
2 * linux/include/asm/sharp_char.h
3 */
4
5#ifndef __ASM_SHARP_CHAR_H_INCLUDED
6#define __ASM_SHARP_CHAR_H_INCLUDED
7
8/*
9 * If SHARPCHAR_USE_MISCDEV defined , misc driver architecture used instead of sharp_char
10 */
11
12#define SHARPCHAR_USE_MISCDEV
13
14/*
15 * devices defines...
16 */
17
18#ifndef SHARP_DEV_MAJOR
19#define SHARP_DEV_MAJOR 11
20#endif
21
22#ifndef SHARP_DEV_MINOR_START
23#define SHARP_DEV_MINOR_START 210
24#endif
25
26#define SHARP_DEV_MINOR_MAX 4 /* defines last minor number of SHARP device */
27
28#define SHARP_LED_MINOR (SHARP_DEV_MINOR_START+0)
29#define SHARP_BUZZER_MINOR (SHARP_DEV_MINOR_START+1)
30#define SHARP_GSM_MINOR (SHARP_DEV_MINOR_START+2)
31#define SHARP_AUDIOCTL_MINOR (SHARP_DEV_MINOR_START+3)
32#define SHARP_KBDCTL_MINOR (SHARP_DEV_MINOR_START+4)
33
34/*
35 * ioctl defines...
36 */
37
38#define SHARP_DEV_IOCTL_COMMAND_START 0x5680
39
40/* --- for SHARP_LED device --- */
41 #defineSHARP_LED_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START)
42#define SHARP_LED_GETSTATUS (SHARP_LED_IOCTL_START)
43#define SHARP_LED_SETSTATUS (SHARP_LED_IOCTL_START+1)
44#define SHARP_LED_ISUPPORTED (SHARP_LED_IOCTL_START+2)
45
46typedef struct sharp_led_status {
47 int which; /* select which LED status is wanted. */
48 int status; /* set new led status if you call SHARP_LED_SETSTATUS */
49} sharp_led_status;
50
51#define SHARP_LED_WHICH_MAX 15 /* last number of LED */
52
53/* parameters for 'which' member */
54#define SHARP_LED_PDA 0 /* PDA status */
55#define SHARP_LED_DALARM 1 /* daily alarm */
56#define SHARP_LED_SALARM 2 /* schedule alarm */
57#define SHARP_LED_BATTERY 3 /* main battery status */
58#define SHARP_LED_ACSTATUS 4 /* AC line status */
59#define SHARP_LED_CHARGER 5 /* charger status */
60#define SHARP_LED_PHONE_RSSI 6 /* phone status (RSSI...) */
61#define SHARP_LED_PHONE_DIAL 7 /* phone status (dialing...) */
62#define SHARP_LED_PHONE_IN 8 /* phone status (incoming..) */
63#define SHARP_LED_MAIL_EXISTS 9 /* mail status (exists or not) */
64#define SHARP_LED_MAIL_SEND 10 /* mail status (sending...) */
65#define SHARP_LED_MAIL_QUEUE 11 /* mail to send is in queue */
66#define SHARP_LED_COLLIE_0 12 /* 1st pri. battery LED control */
67#define SHARP_LED_COLLIE_1 13 /* 1st pri. mail LED control */
68#define SHARP_LED_COLLIE_2 14 /* reserved */
69#define SHARP_LED_COLLIE_3 15 /* reserved */
70
71/* parameters for 'status' member */
72#define LED_PDA_RUNNING 0 /* for SHARP_LED_RUN */
73#define LED_PDA_SUSPENDED 1 /* for SHARP_LED_RUN */
74#define LED_PDA_OFF 2 /* for SHARP_LED_RUN */
75#define LED_PDA_ERROR 3 /* for SHARP_LED_RUN */
76
77#define LED_DALARM_OFF 0 /* for SHARP_LED_DALARM */
78#define LED_DALARM_ON 1 /* for SHARP_LED_DALARM */
79
80#define LED_SALARM_OFF 0 /* for SHARP_LED_SALARM */
81#define LED_SALARM_ON 1 /* for SHARP_LED_SALARM */
82
83#define LED_BATTERY_GOOD 0 /* for SHARP_LED_BATTERY */
84#define LED_BATTERY_LOW 1 /* for SHARP_LED_BATTERY */
85#define LED_BATTERY_VERY_LOW 2 /* for SHARP_LED_BATTERY */
86#define LED_BATTERY_CRITICAL 3 /* for SHARP_LED_BATTERY */
87
88#define LED_CHARGER_OFF 0 /* for SHARP_LED_CHARGER */
89#define LED_CHARGER_CHARGING 1 /* for SHARP_LED_CHARGER */
90#define LED_CHARGER_ERROR 2 /* for SHARP_LED_CHARGER */
91
92#define LED_AC_NOT_CONNECTED 0 /* for SHARP_LED_ACSTATUS */
93#define LED_AC_CONNECTED 1 /* for SHARP_LED_ACSTATUS */
94
95#define LED_RSSI_OUT 0 /* for SHARP_LED_PHONE_RSSI */
96#define LED_RSSI_IN 1 /* for SHARP_LED_PHONE_RSSI */
97
98#define LED_DIAL_OFF 0 /* for SHARP_LED_PHONE_DIAL */
99#define LED_DIAL_DIALING 1 /* for SHARP_LED_PHONE_DIAL */
100#define LED_DIAL_HOLDING 2 /* for SHARP_LED_PHONE_DIAL */
101
102#define LED_PHONE_WAITING 0 /* for SHARP_LED_PHONE_IN */
103#define LED_PHONE_INCOMING 1 /* for SHARP_LED_PHONE_IN */
104
105#define LED_MAIL_NO_UNREAD_MAIL 0 /* for SHARP_LED_MAIL_EXISTS */
106#define LED_MAIL_NEWMAIL_EXISTS 1 /* for SHARP_LED_MAIL_EXISTS */
107#define LED_MAIL_UNREAD_MAIL_EX 2 /* for SHARP_LED_MAIL_EXISTS */
108
109#define LED_SENDMAIL_OFF 0 /* for SHARP_LED_MAIL_SEND */
110#define LED_SENDMAIL_SENDING 1 /* for SHARP_LED_MAIL_SEND */
111#define LED_SENDMAIL_ERROR 2 /* for SHARP_LED_MAIL_SEND */
112
113#define LED_MAILQUEUE_NOUNREAD 0 /* for SHARP_LED_MAIL_QUEUE */
114#define LED_MAILQUEUE_NEWMAIL 1 /* for SHARP_LED_MAIL_QUEUE */
115#define LED_MAILQUEUE_UNREAD 2 /* for SHARP_LED_MAIL_QUEUE */
116
117 #define LED_COLLIE_0_DEFAULT 0 /* for SHARP_LED_COLLIE_0 */
118#define LED_COLLIE_0_OFF 1 /* for SHARP_LED_COLLIE_0 */
119 #define LED_COLLIE_0_ON 2 /* for SHARP_LED_COLLIE_0 */
120 #define LED_COLLIE_0_FASTBLINK 3 /* for SHARP_LED_COLLIE_0 */
121 #define LED_COLLIE_0_SLOWBLINK 4 /* for SHARP_LED_COLLIE_0 */
122
123
124#define LED_COLLIE_1_DEFAULT 0 /* for SHARP_LED_COLLIE_1 */
125#define LED_COLLIE_1_OFF 1 /* for SHARP_LED_COLLIE_1 */
126#define LED_COLLIE_1_ON 2 /* for SHARP_LED_COLLIE_1 */
127#define LED_COLLIE_1_FLASHON 3 /* for SHARP_LED_COLLIE_1 */
128#define LED_COLLIE_1_FLASHOFF 4 /* for SHARP_LED_COLLIE_1 */
129#define LED_COLLIE_1_VFSTBLINK 5 /* for SHARP_LED_COLLIE_1 */
130#define LED_COLLIE_1_FASTBLINK 6 /* for SHARP_LED_COLLIE_1 */
131#define LED_COLLIE_1_NORMBLINK 7 /* for SHARP_LED_COLLIE_1 */
132#define LED_COLLIE_1_SLOWBLINK 8 /* for SHARP_LED_COLLIE_1 */
133#define LED_COLLIE_1_SOFTBLINK 9 /* for SHARP_LED_COLLIE_1 */
134#define LED_COLLIE_1_SOFTFLASH 10 /* for SHARP_LED_COLLIE_1 */
135
136/* --- for SHARP_BUZZER device --- */
137 #defineSHARP_BUZZER_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START)
138#define SHARP_BUZZER_MAKESOUND (SHARP_BUZZER_IOCTL_START)
139#define SHARP_BUZZER_SETVOLUME (SHARP_BUZZER_IOCTL_START+1)
140#define SHARP_BUZZER_GETVOLUME (SHARP_BUZZER_IOCTL_START+2)
141#define SHARP_BUZZER_ISSUPPORTED (SHARP_BUZZER_IOCTL_START+3)
142#define SHARP_BUZZER_SETMUTE (SHARP_BUZZER_IOCTL_START+4)
143#define SHARP_BUZZER_STOPSOUND (SHARP_BUZZER_IOCTL_START+5)
144
145typedef struct sharp_buzzer_status { /* this struct is used for setvolume/getvolume */
146 int which; /* select which LED status is wanted. */
147 int volume; /* set new buzzer volume if you call SHARP_BUZZER_SETVOLUME */
148 int mute; /* set 1 to MUTE if you call SHARP_BUZZER_SETMUTE */
149} sharp_buzzer_status;
150
151#define SHARP_BUZ_WHICH_MAX 14 /* last number of buzzer */
152
153#define SHARP_BUZ_ALL_SOUNDS -1 /* for setting volumes of ALL sounds at a time */
154
155#define SHARP_BUZ_WRITESOUND 0 /* for sound datas through 'write' calls */
156#define SHARP_BUZ_TOUCHSOUND 1 /* touch panel sound */
157#define SHARP_BUZ_KEYSOUND 2 /* key sound */
158#define SHARP_PDA_ILLCLICKSOUND 3 /* illegal click */
159#define SHARP_PDA_WARNSOUND 4 /* warning occurred */
160#define SHARP_PDA_ERRORSOUND 5 /* error occurred */
161#define SHARP_PDA_CRITICALSOUND 6 /* critical error occurred */
162#define SHARP_PDA_SYSSTARTSOUND 7 /* system start */
163#define SHARP_PDA_SYSTEMENDSOUND 8 /* system shutdown */
164#define SHARP_PDA_APPSTART 9 /* application start */
165#define SHARP_PDA_APPQUIT 10 /* application ends */
166#define SHARP_BUZ_SCHEDULE_ALARM 11 /* schedule alarm */
167#define SHARP_BUZ_DAILY_ALARM 12 /* daily alarm */
168#define SHARP_BUZ_GOT_PHONE_CALL 13 /* phone call sound */
169#define SHARP_BUZ_GOT_MAIL 14 /* mail sound */
170
171#define SHARP_BUZ_VOLUME_OFF 0
172#define SHARP_BUZ_VOLUME_LOW 33
173#define SHARP_BUZ_VOLUME_MEDIUM 67
174#define SHARP_BUZ_VOLUME_HIGH 100 /* currentry , this is the maximum ... */
175#define SHARP_BUZ_VOLUME_MAX (SHARP_BUZ_VOLUME_HIGH)
176
177/* --- for SHARP_GSM device --- */
178 #defineSHARP_GSM_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START)
179#define SHARP_GSM_GETEXTSTATUS (SHARP_GSM_IOCTL_START+16)
180#define SHARP_GSM_INFO_TELL_MODE (SHARP_GSM_IOCTL_START+17)
181
182#define GSM_PHONE_NO_POWER 0 /* for SHARP_GSM_INFO_TELL_MODE */
183#define GSM_PHONE_NO_CONNECTION 1 /* for SHARP_GSM_INFO_TELL_MODE */
184#define GSM_PHONE_IN_ANALOG_MODE 2 /* for SHARP_GSM_INFO_TELL_MODE */
185#define GSM_PHONE_IN_DATA_MODE 3 /* for SHARP_GSM_INFO_TELL_MODE */
186
187typedef struct sharp_gsmext_status {
188 int carkit; /* be set as 1 , if car-kit is connected */
189 int headphone_mic; /* be set as 1 , if head-phone-microphone is inserted */
190} sharp_gsmext_status;
191
192/* --- for SHARP_AUDIOCTL device --- */
193 #defineSHARP_AUDIOCTL_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START)
194 #defineSHARP_AUDIOCTL_ARCH_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START+0x10)
195#define SHARP_IRIS_AUFIL_GETVAL (SHARP_AUDIOCTL_ARCH_IOCTL_START+0)
196#define SHARP_IRIS_AUFIL_SETVAL (SHARP_AUDIOCTL_ARCH_IOCTL_START+1)
197#define SHARP_IRIS_AMP_EXT_ON (SHARP_AUDIOCTL_ARCH_IOCTL_START+2)
198#define SHARP_IRIS_AMP_EXT_OFF (SHARP_AUDIOCTL_ARCH_IOCTL_START+3)
199
200
201#define SHARP_IRIS_AUFIL_FILTERON 0x01 /* Iris AudioCtl Specific. Enable Audio Filter */
202
203/* --- for SHARP_AUDIOCTL device --- */
204 #defineSHARP_KBDCTL_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START)
205#define SHARP_KBDCTL_GETMODIFSTAT (SHARP_KBDCTL_IOCTL_START+0)
206#define SHARP_KBDCTL_TOGGLEMODIFSTAT (SHARP_KBDCTL_IOCTL_START+1)
207#define SHARP_KBDCTL_SETHOLDTH (SHARP_KBDCTL_IOCTL_START+2)
208#define SHARP_KBDCTL_SETHOLDTH_GR (SHARP_KBDCTL_IOCTL_START+3)
209#define SHARP_KBDCTL_HOLDINFO_SETHD (SHARP_KBDCTL_IOCTL_START+4)
210#define SHARP_KBDCTL_HOLDINFO_SETSL (SHARP_KBDCTL_IOCTL_START+5)
211#define SHARP_KBDCTL_HOLDINFO_DELHD (SHARP_KBDCTL_IOCTL_START+6)
212#define SHARP_KBDCTL_HOLDINFO_DELSL (SHARP_KBDCTL_IOCTL_START+7)
213#define SHARP_KBDCTL_HOLDINFO_RESTHD (SHARP_KBDCTL_IOCTL_START+8)
214#define SHARP_KBDCTL_HOLDINFO_RESTSL (SHARP_KBDCTL_IOCTL_START+9)
215#define SHARP_KBDCTL_HOLDINFO_RESTFULL (SHARP_KBDCTL_IOCTL_START+10)
216
217typedef struct sharp_kbdctl_modifstat {
218 int which;
219 int stat;
220} sharp_kbdctl_modifstat;
221
222typedef struct sharp_kbdctl_holdstat {
223 int group;
224 int timeout;
225} sharp_kbdctl_holdstat;
226
227typedef struct sharp_kbdctl_holdcustom {
228 int normal_hardcode;
229 int normal_slcode;
230 int hold_slcode;
231} sharp_kbdctl_holdcustom;
232
233#define SHARP_EXTMODIF_2ND 0x01
234#define SHARP_EXTMODIF_CAPS 0x02
235#define SHARP_EXTMODIF_NUMLOCK 0x03
236
237#define HOLDKEY_GROUP_NORMAL 0
238#define HOLDKEY_GROUP_POWER 1
239
240#endif /* __ASM_SHARP_CHAR_H_INCLUDED */
241
diff --git a/noncore/unsupported/mail2/libmail/smtphandler.cpp b/noncore/unsupported/mail2/libmail/smtphandler.cpp
new file mode 100644
index 0000000..1bbad8b
--- a/dev/null
+++ b/noncore/unsupported/mail2/libmail/smtphandler.cpp
@@ -0,0 +1,172 @@
1#warning "TODO: XXX This class needs to be rewritten. XXX"
2
3#include <qsocket.h>
4#include <qtimer.h>
5#include <qfile.h>
6#include <qdatetime.h>
7#include <qdir.h>
8#include <qregexp.h>
9
10#include <qpe/mimetype.h>
11#include <qpe/config.h>
12
13#include <stdlib.h>
14
15#include "smtphandler.h"
16#include "miscfunctions.h"
17
18SmtpHandler::SmtpHandler(const QString &header, const QString &message, Account &account, const QString &to)
19 : QObject(), _header(header), _message(message), _account(account), _to(to)
20{
21 _header.replace(QRegExp("\\n"), "\r\n");
22 _message.replace(QRegExp("\\n"), "\r\n");
23 _message.replace(QRegExp("\\r\\n\\.\\r\\n"), "\r\n..\r\n");
24
25 //_state = account.esmtpAuth() ? Ehlo : Helo;
26 _state = Helo;
27
28 _socket = new QSocket(this);
29 connect(_socket, SIGNAL(hostFound()), this, SLOT(hostFound()));
30 connect(_socket, SIGNAL(connected()), this, SLOT(connected()));
31 connect(_socket, SIGNAL(readyRead()), this, SLOT(readyRead()));
32 connect(_socket, SIGNAL(error(int)), this, SLOT(errorHandling(int)));
33
34 _socket->connectToHost(account.smtpServer(), account.smtpPort().toUInt());
35 emit status(tr("Looking up host..."));
36}
37
38void SmtpHandler::errorHandling(int err)
39{
40 if (err == QSocket::ErrConnectionRefused) {
41 emit error(tr("The server refused the connection."));
42 } else if (err == QSocket::ErrHostNotFound) {
43 emit error(tr("Host lookup failed."));
44 } else if (err == QSocket::ErrSocketRead) {
45 emit error(tr("The read from the socket failed for an unknown reason."));
46 } else {
47 emit error(tr("The sending failed for an unknown reason."));
48 }
49 stop();
50}
51
52void SmtpHandler::hostFound()
53{
54 emit status(tr("Host found."));
55}
56
57void SmtpHandler::connected()
58{
59 emit status(tr("Connected to %1").arg(_socket->peerName()));
60}
61
62void SmtpHandler::readyRead()
63{
64 if (!_socket->canReadLine()) return;
65 if (_state == Close) stop();
66
67 QString response = _socket->readLine();
68 QString temp = response;
69 temp.truncate(3);
70 int responseCode = temp.toInt();
71
72#ifndef QT_NO_DEBUG
73 qDebug(tr("SMTP > %3").arg(response.stripWhiteSpace()));
74#endif
75
76 response.replace(0, 4, "");
77 response.stripWhiteSpace();
78
79 if (_state == Ehlo && responseCode == 220) {
80 QString hostname = getenv("HOSTNAME");
81 if (hostname.stripWhiteSpace().isEmpty())
82 hostname = "opiemail";
83
84 emit status(tr("SMTP> EHLO *"));
85 sendToSocket(QString("EHLO %1\r\n").arg(hostname));
86 _state = Auth;
87 } else if (_state == Auth && responseCode == 250) {
88 QStringList capabilities;
89 while (_socket->canReadLine()) {
90 QString line = _socket->readLine().stripWhiteSpace();
91 capabilities.append(line);
92 }
93
94 // FIXME: Dirty, quick hack!
95 if (!capabilities.grep(QRegExp("^250-AUTH=LOGIN.*CRAM-MD5.*$")).isEmpty()) {
96 // emit errorOccourred(ErrAuthNotSupported);
97 _state = Mail;
98 } else {
99 emit status(tr("SMTP> AUTH CRAM-MD5"));
100 sendToSocket("AUTH CRAM-MD5\r\n");
101 _state = ReadAuth;
102 }
103 } else if (_state == ReadAuth && responseCode == 334) {
104 QString msgId = MiscFunctions::decodeBase64(response);
105
106 QString authString;
107 authString = _account.user() + " " +
108 MiscFunctions::smtpAuthCramMd5(msgId, _account.pass());
109 authString = MiscFunctions::encodeBase64(authString);
110
111 emit status(tr("SMTP> Authenticating"));
112 sendToSocket(authString + "\r\n");
113
114 _state = Mail;
115 } else if (_state == Helo && responseCode == 220) {
116 QString hostname = getenv("HOSTNAME");
117 if (hostname.stripWhiteSpace().isEmpty())
118 hostname = "opiemail";
119
120 emit status(tr("SMTP> HELO *"));
121 sendToSocket(QString("HELO %1\r\n").arg(hostname));
122 _state = Mail;
123 } else if (_state == Mail && responseCode == 250) {
124 emit status(tr("SMTP> MAIL FROM: *"));
125 sendToSocket("MAIL FROM: " + _account.email() + "\r\n");
126 _state = Rcpt;
127 } else if (_state == Rcpt && responseCode == 250) {
128 emit status(tr("SMTP> RCPT TO: *"));
129 sendToSocket("RCPT TO: " + _to + "\r\n");
130 _state = Data;
131 } else if (_state == Data && responseCode == 250) {
132 emit status(tr("SMTP> DATA"));
133 sendToSocket("DATA\r\n");
134 _state = Body;
135 } else if (_state == Body && responseCode == 354) {
136 emit status(tr("SMTP> Sending data..."));
137 sendToSocket(_header + "\r\n" + _message + "\r\n.\r\n", false);
138 _state = Quit;
139 } else if (_state == Quit) {
140 emit status(tr("SMTP> QUIT (Done)"));
141 sendToSocket("QUIT\r\n");
142 _state = Close;
143 } else if (_state == Close) {
144
145 } else {
146 emit error(tr("The server returned an error. This is the message:<br>%1").arg(response));
147 stop();
148 }
149}
150
151void SmtpHandler::sendToSocket(const QString &text, bool log)
152{
153 _socket->writeBlock(text.latin1(), text.length());
154
155 if (log) {
156#ifndef QT_NO_DEBUG
157 qDebug(tr("SMTP < %3").arg(text.stripWhiteSpace()));
158#endif
159 }
160}
161
162void SmtpHandler::stop()
163{
164 emit finished();
165 QTimer::singleShot(0, this, SLOT(deleteMe()));
166}
167
168void SmtpHandler::deleteMe()
169{
170 delete this;
171}
172
diff --git a/noncore/unsupported/mail2/libmail/smtphandler.h b/noncore/unsupported/mail2/libmail/smtphandler.h
new file mode 100644
index 0000000..abbcbcd
--- a/dev/null
+++ b/noncore/unsupported/mail2/libmail/smtphandler.h
@@ -0,0 +1,55 @@
1#ifndef SMTPHANDLER_H
2#define SMTPHANDLER_H
3
4#include <qobject.h>
5#include <qstring.h>
6
7#include "configfile.h"
8
9class QSocket;
10
11class SmtpHandler : public QObject
12{
13 Q_OBJECT
14
15public:
16 SmtpHandler(const QString &header, const QString &message, Account &account, const QString &to);
17
18 enum SmtpError {
19 ErrConnectionRefused,
20 ErrHostNotFound,
21 ErrUnknownResponse,
22 ErrAuthNotSupported
23 };
24
25public slots:
26 void stop();
27
28signals:
29 void finished();
30 void error(const QString &);
31 void status(const QString &);
32
33private slots:
34 void readyRead();
35 void hostFound();
36 void connected();
37 void deleteMe();
38 void errorHandling(int);
39
40private:
41 void sendToSocket(const QString &text, bool log = true);
42
43 enum State { Ehlo, Auth, ReadAuth, Helo, Mail, Rcpt,
44 Data, Body, Quit, Close };
45
46 QString _header, _message;
47 Account _account;
48 QString _to;
49 QSocket *_socket;
50 int _state;
51};
52
53#endif
54
55
diff --git a/noncore/unsupported/mail2/libmail/zaurusstuff.cpp b/noncore/unsupported/mail2/libmail/zaurusstuff.cpp
new file mode 100644
index 0000000..bbf1541
--- a/dev/null
+++ b/noncore/unsupported/mail2/libmail/zaurusstuff.cpp
@@ -0,0 +1,38 @@
1#include <sys/ioctl.h>
2#include <fcntl.h>
3#include <stdio.h>
4
5#include "zaurusstuff.h"
6#include "sharp_char.h"
7
8ZaurusStuff::ZaurusStuff() : QObject()
9{
10
11}
12
13void ZaurusStuff::blinkLedOn()
14{
15 sharp_led_status st;
16 st.which = SHARP_LED_COLLIE_1;
17 st.status = LED_COLLIE_1_FLASHON;
18 ioctl(open("/dev/sharp_led", O_WRONLY), SHARP_LED_SETSTATUS, &st);
19}
20
21void ZaurusStuff::blinkLedOff()
22{
23 sharp_led_status st;
24 st.which = SHARP_LED_COLLIE_1;
25 st.status = LED_COLLIE_1_DEFAULT;
26 ioctl(open("/dev/sharp_led", O_WRONLY), SHARP_LED_SETSTATUS, &st);
27}
28
29void ZaurusStuff::buzzerOn()
30{
31 ioctl(open("/dev/sharp_buz", O_WRONLY), SHARP_BUZZER_MAKESOUND, 4);
32}
33
34void ZaurusStuff::buzzerOff()
35{
36
37}
38
diff --git a/noncore/unsupported/mail2/libmail/zaurusstuff.h b/noncore/unsupported/mail2/libmail/zaurusstuff.h
new file mode 100644
index 0000000..33c65da
--- a/dev/null
+++ b/noncore/unsupported/mail2/libmail/zaurusstuff.h
@@ -0,0 +1,23 @@
1#ifndef ZAURUSSTUFF_H
2#define ZAURUSSTUFF_H
3
4#include <qobject.h>
5
6class ZaurusStuff : public QObject
7{
8 Q_OBJECT
9
10public:
11 static void blinkLedOn();
12 static void blinkLedOff();
13 static void buzzerOn();
14 static void buzzerOff();
15
16protected:
17 ZaurusStuff();
18
19
20};
21
22#endif
23