author | leseb <leseb> | 2002-06-15 19:26:09 (UTC) |
---|---|---|
committer | leseb <leseb> | 2002-06-15 19:26:09 (UTC) |
commit | a041cfe9806d7089d469e14da125adab4a93a5ab (patch) (unidiff) | |
tree | 0a9700e49dd1be1fa67df4f8bd429a9aed1c1dec | |
parent | f797160d879c74652b27bca3df8a74243465d65c (diff) | |
download | opie-a041cfe9806d7089d469e14da125adab4a93a5ab.zip opie-a041cfe9806d7089d469e14da125adab4a93a5ab.tar.gz opie-a041cfe9806d7089d469e14da125adab4a93a5ab.tar.bz2 |
Fix
-rw-r--r-- | noncore/unsupported/mail2/libmail/smtphandler.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/noncore/unsupported/mail2/libmail/smtphandler.cpp b/noncore/unsupported/mail2/libmail/smtphandler.cpp index 1bbad8b..d0a505d 100644 --- a/noncore/unsupported/mail2/libmail/smtphandler.cpp +++ b/noncore/unsupported/mail2/libmail/smtphandler.cpp | |||
@@ -1,172 +1,172 @@ | |||
1 | #warning "TODO: XXX This class needs to be rewritten. XXX" | 1 | #warning "TODO: XXX This class needs to be rewritten. XXX" |
2 | 2 | ||
3 | #include <qsocket.h> | 3 | #include <qsocket.h> |
4 | #include <qtimer.h> | 4 | #include <qtimer.h> |
5 | #include <qfile.h> | 5 | #include <qfile.h> |
6 | #include <qdatetime.h> | 6 | #include <qdatetime.h> |
7 | #include <qdir.h> | 7 | #include <qdir.h> |
8 | #include <qregexp.h> | 8 | #include <qregexp.h> |
9 | 9 | ||
10 | #include <qpe/mimetype.h> | 10 | #include <qpe/mimetype.h> |
11 | #include <qpe/config.h> | 11 | #include <qpe/config.h> |
12 | 12 | ||
13 | #include <stdlib.h> | 13 | #include <stdlib.h> |
14 | 14 | ||
15 | #include "smtphandler.h" | 15 | #include "smtphandler.h" |
16 | #include "miscfunctions.h" | 16 | #include "miscfunctions.h" |
17 | 17 | ||
18 | SmtpHandler::SmtpHandler(const QString &header, const QString &message, Account &account, const QString &to) | 18 | SmtpHandler::SmtpHandler(const QString &header, const QString &message, Account &account, const QString &to) |
19 | : QObject(), _header(header), _message(message), _account(account), _to(to) | 19 | : QObject(), _header(header), _message(message), _account(account), _to(to) |
20 | { | 20 | { |
21 | _header.replace(QRegExp("\\n"), "\r\n"); | 21 | _header.replace(QRegExp("\\n"), "\r\n"); |
22 | _message.replace(QRegExp("\\n"), "\r\n"); | 22 | _message.replace(QRegExp("\\n"), "\r\n"); |
23 | _message.replace(QRegExp("\\r\\n\\.\\r\\n"), "\r\n..\r\n"); | 23 | _message.replace(QRegExp("\\r\\n\\.\\r\\n"), "\r\n..\r\n"); |
24 | 24 | ||
25 | //_state = account.esmtpAuth() ? Ehlo : Helo; | 25 | //_state = account.esmtpAuth() ? Ehlo : Helo; |
26 | _state = Helo; | 26 | _state = Helo; |
27 | 27 | ||
28 | _socket = new QSocket(this); | 28 | _socket = new QSocket(this); |
29 | connect(_socket, SIGNAL(hostFound()), this, SLOT(hostFound())); | 29 | connect(_socket, SIGNAL(hostFound()), this, SLOT(hostFound())); |
30 | connect(_socket, SIGNAL(connected()), this, SLOT(connected())); | 30 | connect(_socket, SIGNAL(connected()), this, SLOT(connected())); |
31 | connect(_socket, SIGNAL(readyRead()), this, SLOT(readyRead())); | 31 | connect(_socket, SIGNAL(readyRead()), this, SLOT(readyRead())); |
32 | connect(_socket, SIGNAL(error(int)), this, SLOT(errorHandling(int))); | 32 | connect(_socket, SIGNAL(error(int)), this, SLOT(errorHandling(int))); |
33 | 33 | ||
34 | _socket->connectToHost(account.smtpServer(), account.smtpPort().toUInt()); | 34 | _socket->connectToHost(account.smtpServer(), account.smtpPort().toUInt()); |
35 | emit status(tr("Looking up host...")); | 35 | emit status(tr("Looking up host...")); |
36 | } | 36 | } |
37 | 37 | ||
38 | void SmtpHandler::errorHandling(int err) | 38 | void SmtpHandler::errorHandling(int err) |
39 | { | 39 | { |
40 | if (err == QSocket::ErrConnectionRefused) { | 40 | if (err == QSocket::ErrConnectionRefused) { |
41 | emit error(tr("The server refused the connection.")); | 41 | emit error(tr("The server refused the connection.")); |
42 | } else if (err == QSocket::ErrHostNotFound) { | 42 | } else if (err == QSocket::ErrHostNotFound) { |
43 | emit error(tr("Host lookup failed.")); | 43 | emit error(tr("Host lookup failed.")); |
44 | } else if (err == QSocket::ErrSocketRead) { | 44 | } else if (err == QSocket::ErrSocketRead) { |
45 | emit error(tr("The read from the socket failed for an unknown reason.")); | 45 | emit error(tr("The read from the socket failed for an unknown reason.")); |
46 | } else { | 46 | } else { |
47 | emit error(tr("The sending failed for an unknown reason.")); | 47 | emit error(tr("The sending failed for an unknown reason.")); |
48 | } | 48 | } |
49 | stop(); | 49 | stop(); |
50 | } | 50 | } |
51 | 51 | ||
52 | void SmtpHandler::hostFound() | 52 | void SmtpHandler::hostFound() |
53 | { | 53 | { |
54 | emit status(tr("Host found.")); | 54 | emit status(tr("Host found.")); |
55 | } | 55 | } |
56 | 56 | ||
57 | void SmtpHandler::connected() | 57 | void SmtpHandler::connected() |
58 | { | 58 | { |
59 | emit status(tr("Connected to %1").arg(_socket->peerName())); | 59 | emit status(tr("Connected to %1").arg(_socket->peerName())); |
60 | } | 60 | } |
61 | 61 | ||
62 | void SmtpHandler::readyRead() | 62 | void SmtpHandler::readyRead() |
63 | { | 63 | { |
64 | if (!_socket->canReadLine()) return; | 64 | if (!_socket->canReadLine()) return; |
65 | if (_state == Close) stop(); | 65 | if (_state == Close) stop(); |
66 | 66 | ||
67 | QString response = _socket->readLine(); | 67 | QString response = _socket->readLine(); |
68 | QString temp = response; | 68 | QString temp = response; |
69 | temp.truncate(3); | 69 | temp.truncate(3); |
70 | int responseCode = temp.toInt(); | 70 | int responseCode = temp.toInt(); |
71 | 71 | ||
72 | #ifndef QT_NO_DEBUG | 72 | #ifndef QT_NO_DEBUG |
73 | qDebug(tr("SMTP > %3").arg(response.stripWhiteSpace())); | 73 | qDebug(tr("SMTP > %3").arg(response.stripWhiteSpace())); |
74 | #endif | 74 | #endif |
75 | 75 | ||
76 | response.replace(0, 4, ""); | 76 | response.replace(0, 4, ""); |
77 | response.stripWhiteSpace(); | 77 | response.stripWhiteSpace(); |
78 | 78 | ||
79 | if (_state == Ehlo && responseCode == 220) { | 79 | if (_state == Ehlo && responseCode == 220) { |
80 | QString hostname = getenv("HOSTNAME"); | 80 | QString hostname = getenv("HOSTNAME"); |
81 | if (hostname.stripWhiteSpace().isEmpty()) | 81 | if (hostname.stripWhiteSpace().isEmpty()) |
82 | hostname = "opiemail"; | 82 | hostname = "opiemail"; |
83 | 83 | ||
84 | emit status(tr("SMTP> EHLO *")); | 84 | emit status(tr("SMTP> EHLO *")); |
85 | sendToSocket(QString("EHLO %1\r\n").arg(hostname)); | 85 | sendToSocket(QString("EHLO %1\r\n").arg(hostname)); |
86 | _state = Auth; | 86 | _state = Auth; |
87 | } else if (_state == Auth && responseCode == 250) { | 87 | } else if (_state == Auth && responseCode == 250) { |
88 | QStringList capabilities; | 88 | QStringList capabilities; |
89 | while (_socket->canReadLine()) { | 89 | while (_socket->canReadLine()) { |
90 | QString line = _socket->readLine().stripWhiteSpace(); | 90 | QString line = _socket->readLine().stripWhiteSpace(); |
91 | capabilities.append(line); | 91 | capabilities.append(line); |
92 | } | 92 | } |
93 | 93 | ||
94 | // FIXME: Dirty, quick hack! | 94 | // FIXME: Dirty, quick hack! |
95 | if (!capabilities.grep(QRegExp("^250-AUTH=LOGIN.*CRAM-MD5.*$")).isEmpty()) { | 95 | if (!capabilities.grep(QRegExp("^250-AUTH=LOGIN.*CRAM-MD5.*$")).isEmpty()) { |
96 | // emit errorOccourred(ErrAuthNotSupported); | 96 | // emit errorOccourred(ErrAuthNotSupported); |
97 | _state = Mail; | 97 | _state = Mail; |
98 | } else { | 98 | } else { |
99 | emit status(tr("SMTP> AUTH CRAM-MD5")); | 99 | emit status(tr("SMTP> AUTH CRAM-MD5")); |
100 | sendToSocket("AUTH CRAM-MD5\r\n"); | 100 | sendToSocket("AUTH CRAM-MD5\r\n"); |
101 | _state = ReadAuth; | 101 | _state = ReadAuth; |
102 | } | 102 | } |
103 | } else if (_state == ReadAuth && responseCode == 334) { | 103 | } else if (_state == ReadAuth && responseCode == 334) { |
104 | QString msgId = MiscFunctions::decodeBase64(response); | 104 | QString msgId = MiscFunctions::decodeBase64(response); |
105 | 105 | ||
106 | QString authString; | 106 | QString authString; |
107 | authString = _account.user() + " " + | 107 | authString = _account.user() + " " + |
108 | MiscFunctions::smtpAuthCramMd5(msgId, _account.pass()); | 108 | MiscFunctions::smtpAuthCramMd5(msgId, _account.pass()); |
109 | authString = MiscFunctions::encodeBase64(authString); | 109 | authString = MiscFunctions::encodeBase64(authString); |
110 | 110 | ||
111 | emit status(tr("SMTP> Authenticating")); | 111 | emit status(tr("SMTP> Authenticating")); |
112 | sendToSocket(authString + "\r\n"); | 112 | sendToSocket(authString + "\r\n"); |
113 | 113 | ||
114 | _state = Mail; | 114 | _state = Mail; |
115 | } else if (_state == Helo && responseCode == 220) { | 115 | } else if (_state == Helo && responseCode == 220) { |
116 | QString hostname = getenv("HOSTNAME"); | 116 | QString hostname = getenv("HOSTNAME"); |
117 | if (hostname.stripWhiteSpace().isEmpty()) | 117 | if (hostname.stripWhiteSpace().isEmpty()) |
118 | hostname = "opiemail"; | 118 | hostname = "opiemail"; |
119 | 119 | ||
120 | emit status(tr("SMTP> HELO *")); | 120 | emit status(tr("SMTP> HELO *")); |
121 | sendToSocket(QString("HELO %1\r\n").arg(hostname)); | 121 | sendToSocket(QString("HELO %1\r\n").arg(hostname)); |
122 | _state = Mail; | 122 | _state = Mail; |
123 | } else if (_state == Mail && responseCode == 250) { | 123 | } else if (_state == Mail && responseCode == 250) { |
124 | emit status(tr("SMTP> MAIL FROM: *")); | 124 | emit status(tr("SMTP> MAIL FROM: *")); |
125 | sendToSocket("MAIL FROM: " + _account.email() + "\r\n"); | 125 | sendToSocket("MAIL FROM: <" + _account.email() + ">\r\n"); |
126 | _state = Rcpt; | 126 | _state = Rcpt; |
127 | } else if (_state == Rcpt && responseCode == 250) { | 127 | } else if (_state == Rcpt && responseCode == 250) { |
128 | emit status(tr("SMTP> RCPT TO: *")); | 128 | emit status(tr("SMTP> RCPT TO: *")); |
129 | sendToSocket("RCPT TO: " + _to + "\r\n"); | 129 | sendToSocket("RCPT TO: <" + _to + ">\r\n"); |
130 | _state = Data; | 130 | _state = Data; |
131 | } else if (_state == Data && responseCode == 250) { | 131 | } else if (_state == Data && responseCode == 250) { |
132 | emit status(tr("SMTP> DATA")); | 132 | emit status(tr("SMTP> DATA")); |
133 | sendToSocket("DATA\r\n"); | 133 | sendToSocket("DATA\r\n"); |
134 | _state = Body; | 134 | _state = Body; |
135 | } else if (_state == Body && responseCode == 354) { | 135 | } else if (_state == Body && responseCode == 354) { |
136 | emit status(tr("SMTP> Sending data...")); | 136 | emit status(tr("SMTP> Sending data...")); |
137 | sendToSocket(_header + "\r\n" + _message + "\r\n.\r\n", false); | 137 | sendToSocket(_header + "\r\n" + _message + "\r\n.\r\n", false); |
138 | _state = Quit; | 138 | _state = Quit; |
139 | } else if (_state == Quit) { | 139 | } else if (_state == Quit) { |
140 | emit status(tr("SMTP> QUIT (Done)")); | 140 | emit status(tr("SMTP> QUIT (Done)")); |
141 | sendToSocket("QUIT\r\n"); | 141 | sendToSocket("QUIT\r\n"); |
142 | _state = Close; | 142 | _state = Close; |
143 | } else if (_state == Close) { | 143 | } else if (_state == Close) { |
144 | 144 | ||
145 | } else { | 145 | } else { |
146 | emit error(tr("The server returned an error. This is the message:<br>%1").arg(response)); | 146 | emit error(tr("The server returned an error. This is the message:<br>%1").arg(response)); |
147 | stop(); | 147 | stop(); |
148 | } | 148 | } |
149 | } | 149 | } |
150 | 150 | ||
151 | void SmtpHandler::sendToSocket(const QString &text, bool log) | 151 | void SmtpHandler::sendToSocket(const QString &text, bool log) |
152 | { | 152 | { |
153 | _socket->writeBlock(text.latin1(), text.length()); | 153 | _socket->writeBlock(text.latin1(), text.length()); |
154 | 154 | ||
155 | if (log) { | 155 | if (log) { |
156 | #ifndef QT_NO_DEBUG | 156 | #ifndef QT_NO_DEBUG |
157 | qDebug(tr("SMTP < %3").arg(text.stripWhiteSpace())); | 157 | qDebug(tr("SMTP < %3").arg(text.stripWhiteSpace())); |
158 | #endif | 158 | #endif |
159 | } | 159 | } |
160 | } | 160 | } |
161 | 161 | ||
162 | void SmtpHandler::stop() | 162 | void SmtpHandler::stop() |
163 | { | 163 | { |
164 | emit finished(); | 164 | emit finished(); |
165 | QTimer::singleShot(0, this, SLOT(deleteMe())); | 165 | QTimer::singleShot(0, this, SLOT(deleteMe())); |
166 | } | 166 | } |
167 | 167 | ||
168 | void SmtpHandler::deleteMe() | 168 | void SmtpHandler::deleteMe() |
169 | { | 169 | { |
170 | delete this; | 170 | delete this; |
171 | } | 171 | } |
172 | 172 | ||