Diffstat (limited to 'noncore/unsupported/mailit/popclient.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/unsupported/mailit/popclient.cpp | 57 |
1 files changed, 29 insertions, 28 deletions
diff --git a/noncore/unsupported/mailit/popclient.cpp b/noncore/unsupported/mailit/popclient.cpp index 5da3bcb..1df6b2b 100644 --- a/noncore/unsupported/mailit/popclient.cpp +++ b/noncore/unsupported/mailit/popclient.cpp | |||
@@ -28,20 +28,21 @@ extern "C" { | |||
28 | #include <qcstring.h> | 28 | #include <qcstring.h> |
29 | 29 | ||
30 | PopClient::PopClient() | 30 | PopClient::PopClient() |
31 | { | 31 | { |
32 | 32 | ||
33 | socket = new QSocket(this, "popClient"); | 33 | socket = new QSocket(this, "popClient"); |
34 | connect(socket, SIGNAL(error(int)), this, SLOT(errorHandling(int))); | 34 | connect(socket, SIGNAL(error(int)), this, SLOT(errorHandling(int))); |
35 | connect(socket, SIGNAL(connected()), this, SLOT(connectionEstablished())); | 35 | connect(socket, SIGNAL(connected()), this, SLOT(connectionEstablished())); |
36 | connect(socket, SIGNAL(readyRead()), this, SLOT(incomingData())); | 36 | connect(socket, SIGNAL(readyRead()), this, SLOT(incomingData())); |
37 | 37 | ||
38 | stream = new QTextStream(socket); | 38 | stream = new QTextStream(socket); |
39 | 39 | ||
40 | receiving = FALSE; | 40 | receiving = FALSE; |
41 | synchronize = FALSE; | 41 | synchronize = FALSE; |
42 | lastSync = 0; | 42 | lastSync = 0; |
43 | headerLimit = 0; | 43 | headerLimit = 0; |
44 | mailList = 0; | ||
44 | preview = FALSE; | 45 | preview = FALSE; |
45 | } | 46 | } |
46 | 47 | ||
47 | PopClient::~PopClient() | 48 | PopClient::~PopClient() |
@@ -55,23 +56,23 @@ void PopClient::newConnection(const QString &target, int port) | |||
55 | if (receiving) { | 56 | if (receiving) { |
56 | qWarning("socket in use, connection refused"); | 57 | qWarning("socket in use, connection refused"); |
57 | return; | 58 | return; |
58 | } | 59 | } |
59 | 60 | ||
60 | status = Init; | 61 | status = Init; |
61 | 62 | ||
62 | socket->connectToHost(target, port); | 63 | socket->connectToHost(target, port); |
63 | receiving = TRUE; | 64 | receiving = TRUE; |
64 | //selected = FALSE; | 65 | //selected = FALSE; |
65 | 66 | ||
66 | emit updateStatus(tr("DNS lookup")); | 67 | emit updateStatus(tr("DNS lookup")); |
67 | } | 68 | } |
68 | 69 | ||
69 | void PopClient::setAccount(const QString &popUser, const QString &popPasswd) | 70 | void PopClient::setAccount(const QString &popUser, const QString &popPasswd) |
70 | { | 71 | { |
71 | popUserName = popUser; | 72 | popUserName = popUser; |
72 | popPassword = popPasswd; | 73 | popPassword = popPasswd; |
73 | } | 74 | } |
74 | 75 | ||
75 | void PopClient::setSynchronize(int lastCount) | 76 | void PopClient::setSynchronize(int lastCount) |
76 | { | 77 | { |
77 | synchronize = TRUE; | 78 | synchronize = TRUE; |
@@ -122,11 +123,11 @@ void PopClient::incomingData() | |||
122 | char md5Digest[16]; | 123 | char md5Digest[16]; |
123 | // if ( !socket->canReadLine() ) | 124 | // if ( !socket->canReadLine() ) |
124 | // return; | 125 | // return; |
125 | 126 | ||
126 | 127 | ||
127 | response = socket->readLine(); | 128 | response = socket->readLine(); |
128 | 129 | ||
129 | switch(status) { | 130 | switch(status) { |
130 | //logging in | 131 | //logging in |
131 | case Init: { | 132 | case Init: { |
132 | #ifdef APOP_TEST | 133 | #ifdef APOP_TEST |
@@ -135,16 +136,16 @@ void PopClient::incomingData() | |||
135 | if( start >= 0 && end > start ) | 136 | if( start >= 0 && end > start ) |
136 | { | 137 | { |
137 | timeStamp = response.mid( start , end - start + 1); | 138 | timeStamp = response.mid( start , end - start + 1); |
138 | md5Source = timeStamp + popPassword; | 139 | md5Source = timeStamp + popPassword; |
139 | 140 | ||
140 | md5_buffer( (char const *)md5Source, md5Source.length(),&md5Digest[0]); | 141 | md5_buffer( (char const *)md5Source, md5Source.length(),&md5Digest[0]); |
141 | 142 | ||
142 | for(int j =0;j < MD5_DIGEST_LENGTH ;j++) | 143 | for(int j =0;j < MD5_DIGEST_LENGTH ;j++) |
143 | { | 144 | { |
144 | printf("%x", md5Digest[j]); | 145 | printf("%x", md5Digest[j]); |
145 | } | 146 | } |
146 | printf("\n"); | 147 | printf("\n"); |
147 | // qDebug(md5Digest); | 148 | // qDebug(md5Digest); |
148 | *stream << "APOP " << popUserName << " " << md5Digest << "\r\n"; | 149 | *stream << "APOP " << popUserName << " " << md5Digest << "\r\n"; |
149 | // qDebug("%s", stream); | 150 | // qDebug("%s", stream); |
150 | status = Stat; | 151 | status = Stat; |
@@ -155,23 +156,23 @@ void PopClient::incomingData() | |||
155 | timeStamp = ""; | 156 | timeStamp = ""; |
156 | *stream << "USER " << popUserName << "\r\n"; | 157 | *stream << "USER " << popUserName << "\r\n"; |
157 | status = Pass; | 158 | status = Pass; |
158 | } | 159 | } |
159 | 160 | ||
160 | break; | 161 | break; |
161 | } | 162 | } |
162 | 163 | ||
163 | case Pass: { | 164 | case Pass: { |
164 | *stream << "PASS " << popPassword << "\r\n"; | 165 | *stream << "PASS " << popPassword << "\r\n"; |
165 | status = Stat; | 166 | status = Stat; |
166 | 167 | ||
167 | break; | 168 | break; |
168 | } | 169 | } |
169 | //ask for number of messages | 170 | //ask for number of messages |
170 | case Stat: { | 171 | case Stat: { |
171 | if (response[0] == '+') { | 172 | if (response[0] == '+') { |
172 | *stream << "STAT" << "\r\n"; | 173 | *stream << "STAT" << "\r\n"; |
173 | status = Mcnt; | 174 | status = Mcnt; |
174 | } else errorHandlingWithMsg(ErrLoginFailed, response); | 175 | } else errorHandlingWithMsg(ErrLoginFailed, response); |
175 | break; | 176 | break; |
176 | } | 177 | } |
177 | //get count of messages, eg "+OK 4 900.." -> int 4 | 178 | //get count of messages, eg "+OK 4 900.." -> int 4 |
@@ -182,22 +183,22 @@ void PopClient::incomingData() | |||
182 | temp.truncate((uint) x); | 183 | temp.truncate((uint) x); |
183 | newMessages = temp.toInt(); | 184 | newMessages = temp.toInt(); |
184 | messageCount = 1; | 185 | messageCount = 1; |
185 | status = List; | 186 | status = List; |
186 | 187 | ||
187 | if (synchronize) { | 188 | if (synchronize) { |
188 | //messages deleted from server, reload all | 189 | //messages deleted from server, reload all |
189 | if (newMessages < lastSync) | 190 | if (newMessages < lastSync) |
190 | lastSync = 0; | 191 | lastSync = 0; |
191 | messageCount = 1; | 192 | messageCount = 1; |
192 | } | 193 | } |
193 | 194 | ||
194 | if (selected) { | 195 | if (selected && mailList ) { |
195 | int *ptr = mailList->first(); | 196 | int *ptr = mailList->first(); |
196 | if (ptr != 0) { | 197 | if (ptr != 0) { |
197 | newMessages++; //to ensure no early jumpout | 198 | newMessages++; //to ensure no early jumpout |
198 | messageCount = *ptr; | 199 | messageCount = *ptr; |
199 | } else newMessages = 0; | 200 | } else newMessages = 0; |
200 | } | 201 | } |
201 | 202 | ||
202 | } else errorHandlingWithMsg(ErrUnknownResponse, response); | 203 | } else errorHandlingWithMsg(ErrUnknownResponse, response); |
203 | } | 204 | } |
@@ -223,9 +224,9 @@ void PopClient::incomingData() | |||
223 | } else { | 224 | } else { |
224 | emit updateStatus(tr("No new Messages")); | 225 | emit updateStatus(tr("No new Messages")); |
225 | status = Quit; | 226 | status = Quit; |
226 | } | 227 | } |
227 | } | 228 | } |
228 | //get size of message, eg "500 characters in message.." -> int 500 | 229 | //get size of message, eg "500 characters in message.." -> int 500 |
229 | case Size: { | 230 | case Size: { |
230 | if (status != Quit) { //because of idiotic switch | 231 | if (status != Quit) { //because of idiotic switch |
231 | if (response[0] == '+') { | 232 | if (response[0] == '+') { |
@@ -233,29 +234,29 @@ void PopClient::incomingData() | |||
233 | int x = temp.find(" ", 0); | 234 | int x = temp.find(" ", 0); |
234 | temp = temp.right(temp.length() - ((uint) x + 1) ); | 235 | temp = temp.right(temp.length() - ((uint) x + 1) ); |
235 | mailSize = temp.toInt(); | 236 | mailSize = temp.toInt(); |
236 | emit currentMailSize(mailSize); | 237 | emit currentMailSize(mailSize); |
237 | 238 | ||
238 | status = Retr; | 239 | status = Retr; |
239 | } else { | 240 | } else { |
240 | //qWarning(response); | 241 | //qWarning(response); |
241 | errorHandlingWithMsg(ErrUnknownResponse, response); | 242 | errorHandlingWithMsg(ErrUnknownResponse, response); |
242 | } | 243 | } |
243 | } | 244 | } |
244 | } | 245 | } |
245 | //Read message number x, count upwards to messageCount | 246 | //Read message number x, count upwards to messageCount |
246 | case Retr: { | 247 | case Retr: { |
247 | if (status != Quit) { | 248 | if (status != Quit) { |
248 | if ((selected)||(mailSize <= headerLimit)) | 249 | if ((selected)||(mailSize <= headerLimit)) |
249 | { | 250 | { |
250 | *stream << "RETR " << messageCount << "\r\n"; | 251 | *stream << "RETR " << messageCount << "\r\n"; |
251 | } else { //only header | 252 | } else { //only header |
252 | *stream << "TOP " << messageCount << " 0\r\n"; | 253 | *stream << "TOP " << messageCount << " 0\r\n"; |
253 | } | 254 | } |
254 | messageCount++; | 255 | messageCount++; |
255 | status = Ignore; | 256 | status = Ignore; |
256 | break; | 257 | break; |
257 | } } | 258 | } } |
258 | case Ignore: { | 259 | case Ignore: { |
259 | if (status != Quit) { //because of idiotic switch | 260 | if (status != Quit) { //because of idiotic switch |
260 | if (response[0] == '+') { | 261 | if (response[0] == '+') { |
261 | message = ""; | 262 | message = ""; |
@@ -285,25 +286,25 @@ void PopClient::incomingData() | |||
285 | emit newMessage(message, messageCount-1, mailSize, TRUE); | 286 | emit newMessage(message, messageCount-1, mailSize, TRUE); |
286 | } else { //incomplete mail downloaded | 287 | } else { //incomplete mail downloaded |
287 | emit newMessage(message, messageCount-1, mailSize, FALSE); | 288 | emit newMessage(message, messageCount-1, mailSize, FALSE); |
288 | } | 289 | } |
289 | 290 | ||
290 | if ((messageCount > newMessages)||(selected)) //last message ? | 291 | if ((messageCount > newMessages)||(selected)) //last message ? |
291 | { | 292 | { |
292 | status = Quit; | 293 | status = Quit; |
293 | if (selected) { //grab next from queue | 294 | if (selected) { //grab next from queue |
294 | newMessages--; | 295 | newMessages--; |
295 | status = Quit; | 296 | status = Quit; |
296 | } | 297 | } |
297 | } | 298 | } |
298 | else | 299 | else |
299 | { | 300 | { |
300 | *stream << "LIST " << messageCount << "\r\n"; | 301 | *stream << "LIST " << messageCount << "\r\n"; |
301 | status = Size; | 302 | status = Size; |
302 | temp2.setNum(newMessages - lastSync); | 303 | temp2.setNum(newMessages - lastSync); |
303 | temp.setNum(messageCount - lastSync); | 304 | temp.setNum(messageCount - lastSync); |
304 | emit updateStatus(tr("Retrieving ") + temp + "/" + temp2); | 305 | emit updateStatus(tr("Retrieving ") + temp + "/" + temp2); |
305 | 306 | ||
306 | break; | 307 | break; |
307 | } | 308 | } |
308 | } | 309 | } |
309 | } | 310 | } |
@@ -319,9 +320,9 @@ void PopClient::incomingData() | |||
319 | emit updateStatus(temp + tr(" new messages")); | 320 | emit updateStatus(temp + tr(" new messages")); |
320 | } else { | 321 | } else { |
321 | emit updateStatus(tr("No new messages")); | 322 | emit updateStatus(tr("No new messages")); |
322 | } | 323 | } |
323 | 324 | ||
324 | socket->close(); | 325 | socket->close(); |
325 | receiving = FALSE; | 326 | receiving = FALSE; |
326 | emit mailTransfered(newM); | 327 | emit mailTransfered(newM); |
327 | break; | 328 | break; |