author | groucho <groucho> | 2003-04-28 08:31:24 (UTC) |
---|---|---|
committer | groucho <groucho> | 2003-04-28 08:31:24 (UTC) |
commit | 63d3f7ca039d93612abaa4a65fc00b337c42ec9d (patch) (unidiff) | |
tree | ea4a08e00d5a229f20c3e4150f707a2ac8f9e882 /noncore/net/mailit/popclient.cpp | |
parent | c3b703405fe77fbe16596ebd7d814a6e463f9243 (diff) | |
download | opie-63d3f7ca039d93612abaa4a65fc00b337c42ec9d.zip opie-63d3f7ca039d93612abaa4a65fc00b337c42ec9d.tar.gz opie-63d3f7ca039d93612abaa4a65fc00b337c42ec9d.tar.bz2 |
- bug fixes in the parser (from header)
- bug fixes in address selector (uses cc: now)
- remove now selects next item afterwards (speeds up mass deletion)
- smaller fixes
Diffstat (limited to 'noncore/net/mailit/popclient.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/net/mailit/popclient.cpp | 80 |
1 files changed, 19 insertions, 61 deletions
diff --git a/noncore/net/mailit/popclient.cpp b/noncore/net/mailit/popclient.cpp index 67306be..6105d09 100644 --- a/noncore/net/mailit/popclient.cpp +++ b/noncore/net/mailit/popclient.cpp | |||
@@ -47,33 +47,33 @@ PopClient::~PopClient() | |||
47 | { | 47 | { |
48 | delete socket; | 48 | delete socket; |
49 | delete stream; | 49 | delete stream; |
50 | } | 50 | } |
51 | 51 | ||
52 | void PopClient::newConnection(QString target, int port) | 52 | void PopClient::newConnection(QString target, int port) |
53 | { | 53 | { |
54 | if (receiving) { | 54 | if (receiving) { |
55 | qWarning("socket in use, connection refused"); | 55 | qWarning("socket in use, connection refused"); |
56 | return; | 56 | return; |
57 | } | 57 | } |
58 | 58 | ||
59 | status = Init; | 59 | status = Init; |
60 | 60 | ||
61 | socket->connectToHost(target, port); | 61 | socket->connectToHost(target, port); |
62 | receiving = TRUE; | 62 | receiving = TRUE; |
63 | selected = FALSE; | 63 | //selected = FALSE; |
64 | 64 | ||
65 | emit updateStatus("DNS lookup"); | 65 | emit updateStatus("DNS lookup"); |
66 | } | 66 | } |
67 | 67 | ||
68 | void PopClient::setAccount(QString popUser, QString popPasswd) | 68 | void PopClient::setAccount(QString popUser, QString popPasswd) |
69 | { | 69 | { |
70 | popUserName = popUser; | 70 | popUserName = popUser; |
71 | popPassword = popPasswd; | 71 | popPassword = popPasswd; |
72 | } | 72 | } |
73 | 73 | ||
74 | void PopClient::setSynchronize(int lastCount) | 74 | void PopClient::setSynchronize(int lastCount) |
75 | { | 75 | { |
76 | synchronize = TRUE; | 76 | synchronize = TRUE; |
77 | lastSync = lastCount; | 77 | lastSync = lastCount; |
78 | } | 78 | } |
79 | 79 | ||
@@ -171,86 +171,87 @@ void PopClient::incomingData() | |||
171 | case Mcnt: { | 171 | case Mcnt: { |
172 | if (response[0] == '+') { | 172 | if (response[0] == '+') { |
173 | temp = response.replace(0, 4, ""); | 173 | temp = response.replace(0, 4, ""); |
174 | int x = temp.find(" ", 0); | 174 | int x = temp.find(" ", 0); |
175 | temp.truncate((uint) x); | 175 | temp.truncate((uint) x); |
176 | newMessages = temp.toInt(); | 176 | newMessages = temp.toInt(); |
177 | messageCount = 1; | 177 | messageCount = 1; |
178 | status = List; | 178 | status = List; |
179 | 179 | ||
180 | if (synchronize) { | 180 | if (synchronize) { |
181 | //messages deleted from server, reload all | 181 | //messages deleted from server, reload all |
182 | if (newMessages < lastSync) | 182 | if (newMessages < lastSync) |
183 | lastSync = 0; | 183 | lastSync = 0; |
184 | messageCount = 1; | 184 | messageCount = 1; |
185 | } | 185 | } |
186 | 186 | ||
187 | if (selected) { | 187 | if (selected) { |
188 | int *ptr = mailList->first(); | 188 | int *ptr = mailList->first(); |
189 | if (ptr != 0) { | 189 | if (ptr != 0) { |
190 | newMessages++; //to ensure no early jumpout | 190 | newMessages++; //to ensure no early jumpout |
191 | messageCount = *(mailList->first()); | 191 | messageCount = *ptr; |
192 | } else newMessages = 0; | 192 | } else newMessages = 0; |
193 | } | 193 | } |
194 | |||
194 | } else errorHandling(ErrUnknownResponse); | 195 | } else errorHandling(ErrUnknownResponse); |
195 | } | 196 | } |
196 | //Read message number x, count upwards to messageCount | 197 | //Read message number x, count upwards to messageCount |
197 | case List: { | 198 | case List: { |
198 | if (messageCount <= newMessages) { | 199 | if (messageCount <= newMessages) { |
199 | *stream << "LIST " << messageCount << "\r\n"; | 200 | *stream << "LIST " << messageCount << "\r\n"; |
200 | status = Size; | 201 | status = Size; |
201 | temp2.setNum(newMessages - lastSync); | 202 | temp2.setNum(newMessages - lastSync); |
202 | temp.setNum(messageCount - lastSync); | 203 | temp.setNum(messageCount - lastSync); |
203 | if (!selected) { | 204 | if (!selected) { |
204 | emit updateStatus(tr("Retrieving ") + temp + "/" + temp2); | 205 | emit updateStatus(tr("Retrieving ") + temp + "/" + temp2); |
205 | } else { | 206 | } else { |
206 | //completing a previously closed transfer | 207 | //completing a previously closed transfer |
207 | if ( (messageCount - lastSync) <= 0) { | 208 | /* if ( (messageCount - lastSync) <= 0) { |
208 | temp.setNum(messageCount); | 209 | temp.setNum(messageCount); |
209 | emit updateStatus(tr("Previous message ") + temp); | 210 | emit updateStatus(tr("Previous message ") + temp); |
210 | } else { | 211 | } else {*/ |
211 | emit updateStatus(tr("Completing message ") + temp); | 212 | emit updateStatus(tr("Completing message ") + temp); |
212 | } | 213 | //} |
213 | } | 214 | } |
214 | break; | 215 | break; |
215 | } else { | 216 | } else { |
216 | emit updateStatus(tr("No new Messages")); | 217 | emit updateStatus(tr("No new Messages")); |
217 | status = Quit; | 218 | status = Quit; |
218 | } | 219 | } |
219 | } | 220 | } |
220 | //get size of message, eg "500 characters in message.." -> int 500 | 221 | //get size of message, eg "500 characters in message.." -> int 500 |
221 | case Size: { | 222 | case Size: { |
222 | if (status != Quit) { //because of idiotic switch | 223 | if (status != Quit) { //because of idiotic switch |
223 | if (response[0] == '+') { | 224 | if (response[0] == '+') { |
224 | temp = response.replace(0, 4, ""); | 225 | temp = response.replace(0, 4, ""); |
225 | int x = temp.find(" ", 0); | 226 | int x = temp.find(" ", 0); |
226 | temp = temp.right(temp.length() - ((uint) x + 1) ); | 227 | temp = temp.right(temp.length() - ((uint) x + 1) ); |
227 | mailSize = temp.toInt(); | 228 | mailSize = temp.toInt(); |
228 | emit currentMailSize(mailSize); | 229 | emit currentMailSize(mailSize); |
229 | 230 | ||
230 | status = Retr; | 231 | status = Retr; |
231 | } else { | 232 | } else { |
232 | //qWarning(response); | 233 | //qWarning(response); |
233 | errorHandling(ErrUnknownResponse); | 234 | errorHandling(ErrUnknownResponse); |
234 | } | 235 | } |
235 | } | 236 | } |
236 | } | 237 | } |
237 | //Read message number x, count upwards to messageCount | 238 | //Read message number x, count upwards to messageCount |
238 | case Retr: { | 239 | case Retr: { |
239 | if (status != Quit) { | 240 | if (status != Quit) { |
240 | if (mailSize <= headerLimit) | 241 | if ((selected)||(mailSize <= headerLimit)) |
241 | { | 242 | { |
242 | *stream << "RETR " << messageCount << "\r\n"; | 243 | *stream << "RETR " << messageCount << "\r\n"; |
243 | } else { //only header | 244 | } else { //only header |
244 | *stream << "TOP " << messageCount << " 0\r\n"; | 245 | *stream << "TOP " << messageCount << " 0\r\n"; |
245 | } | 246 | } |
246 | messageCount++; | 247 | messageCount++; |
247 | status = Ignore; | 248 | status = Ignore; |
248 | break; | 249 | break; |
249 | } } | 250 | } } |
250 | case Ignore: { | 251 | case Ignore: { |
251 | if (status != Quit) { //because of idiotic switch | 252 | if (status != Quit) { //because of idiotic switch |
252 | if (response[0] == '+') { | 253 | if (response[0] == '+') { |
253 | message = ""; | 254 | message = ""; |
254 | status = Read; | 255 | status = Read; |
255 | if (!socket->canReadLine()) //sync. problems | 256 | if (!socket->canReadLine()) //sync. problems |
256 | break; | 257 | break; |
@@ -259,109 +260,66 @@ void PopClient::incomingData() | |||
259 | } | 260 | } |
260 | } | 261 | } |
261 | //add all incoming lines to body. When size is reached, send | 262 | //add all incoming lines to body. When size is reached, send |
262 | //message, and go back to read new message | 263 | //message, and go back to read new message |
263 | case Read: { | 264 | case Read: { |
264 | if (status != Quit) { //because of idiotic switch | 265 | if (status != Quit) { //because of idiotic switch |
265 | message += response; | 266 | message += response; |
266 | while ( socket->canReadLine() ) { | 267 | while ( socket->canReadLine() ) { |
267 | response = socket->readLine(); | 268 | response = socket->readLine(); |
268 | message += response; | 269 | message += response; |
269 | } | 270 | } |
270 | emit downloadedSize(message.length()); | 271 | emit downloadedSize(message.length()); |
271 | int x = message.find("\r\n.\r\n",-5); | 272 | int x = message.find("\r\n.\r\n",-5); |
272 | if (x == -1) { | 273 | if (x == -1) { |
273 | break; | 274 | break; |
274 | } else { //message reach entire size | 275 | } else { //message reach entire size |
275 | //complete mail downloaded | 276 | |
276 | //if ( (!preview ) || ((preview) && (mailSize <= headerLimit)) ){ | 277 | if ( (selected)||(mailSize <= headerLimit)) //mail size limit is not used if late download is active |
277 | if ( mailSize <= headerLimit) | ||
278 | { | 278 | { |
279 | emit newMessage(message, messageCount-1, mailSize, TRUE); | 279 | emit newMessage(message, messageCount-1, mailSize, TRUE); |
280 | } else { //incomplete mail downloaded | 280 | } else { //incomplete mail downloaded |
281 | emit newMessage(message, messageCount-1, mailSize, FALSE); | 281 | emit newMessage(message, messageCount-1, mailSize, FALSE); |
282 | } | 282 | } |
283 | if (messageCount > newMessages) //that was the last message | 283 | |
284 | if ((messageCount > newMessages)||(selected)) //last message ? | ||
285 | { | ||
284 | status = Quit; | 286 | status = Quit; |
285 | else { //ask for new message | ||
286 | if (selected) { //grab next from queue | 287 | if (selected) { //grab next from queue |
287 | int *ptr = mailList->next(); | ||
288 | if (ptr != 0) { | ||
289 | messageCount = *ptr; | ||
290 | *stream << "LIST " << messageCount << "\r\n"; | ||
291 | status = Size; | ||
292 | //completing a previously closed transfer | ||
293 | if ( (messageCount - lastSync) <= 0) { | ||
294 | temp.setNum(messageCount); | ||
295 | emit updateStatus(tr("Previous message ") + temp); | ||
296 | } else { | ||
297 | temp.setNum(messageCount - lastSync); | ||
298 | emit updateStatus(tr("Completing message ") + temp); | ||
299 | } | ||
300 | break; | ||
301 | } else { | ||
302 | newMessages--; | 288 | newMessages--; |
303 | status = Quit; | 289 | status = Quit; |
304 | } | 290 | } |
305 | } else { | 291 | } |
292 | else | ||
293 | { | ||
306 | *stream << "LIST " << messageCount << "\r\n"; | 294 | *stream << "LIST " << messageCount << "\r\n"; |
307 | status = Size; | 295 | status = Size; |
308 | temp2.setNum(newMessages - lastSync); | 296 | temp2.setNum(newMessages - lastSync); |
309 | temp.setNum(messageCount - lastSync); | 297 | temp.setNum(messageCount - lastSync); |
310 | emit updateStatus(tr("Retrieving ") + temp + "/" + temp2); | 298 | emit updateStatus(tr("Retrieving ") + temp + "/" + temp2); |
311 | 299 | ||
312 | break; | 300 | break; |
313 | } | 301 | } |
314 | } | 302 | } |
315 | } | 303 | } |
316 | if (status != Quit) | 304 | if (status != Quit) |
317 | break; | 305 | break; |
318 | } | ||
319 | } | 306 | } |
320 | case Quit: { | 307 | case Quit: { |
321 | *stream << "Quit\r\n"; | 308 | *stream << "Quit\r\n"; |
322 | status = Done; | 309 | status = Done; |
323 | int newM = newMessages - lastSync; | 310 | int newM = newMessages - lastSync; |
324 | if (newM > 0) { | 311 | if (newM > 0) { |
325 | temp.setNum(newM); | 312 | temp.setNum(newM); |
326 | emit updateStatus(temp + tr(" new messages")); | 313 | emit updateStatus(temp + tr(" new messages")); |
327 | } else { | 314 | } else { |
328 | emit updateStatus(tr("No new messages")); | 315 | emit updateStatus(tr("No new messages")); |
329 | } | 316 | } |
330 | 317 | ||
331 | socket->close(); | 318 | socket->close(); |
332 | receiving = FALSE; | 319 | receiving = FALSE; |
333 | emit mailTransfered(newM); | 320 | emit mailTransfered(newM); |
334 | break; | 321 | break; |
335 | } | 322 | } |
336 | } | 323 | } |
337 | 324 | ||
338 | } | 325 | } |
339 | |||
340 | // if( bAPOPAuthentication ) | ||
341 | // { | ||
342 | // if( m_strTimeStamp.IsEmpty() ) | ||
343 | // { | ||
344 | // SetLastError("Apop error!"); | ||
345 | // return false; | ||
346 | // } | ||
347 | // strMD5Source = m_strTimeStamp+pszPassword; | ||
348 | // strMD5Dst = MD5_GetMD5( (BYTE*)(const char*)strMD5Source , strMD5Source.GetLength() ); | ||
349 | // sprintf(msg , "apop %s %s\r\n" , pszUser , strMD5Dst); | ||
350 | // ret = send(m_sPop3Socket , msg , strlen(msg) , NULL); | ||
351 | // if(ret == SOCKET_ERROR) | ||
352 | // { | ||
353 | // SetLastError("Socket error!"); | ||
354 | // m_bSocketOK = false; | ||
355 | // m_bConnected = false; | ||
356 | // return false; | ||
357 | // } | ||
358 | // if( !GetSocketResult(&strResult , COMMAND_END_FLAG) ) | ||
359 | // return false; | ||
360 | // if( 0 == strResult.Find('-' , 0) ) | ||
361 | // { | ||
362 | // SetLastError("Username or Password error!"); | ||
363 | // return false; | ||
364 | // } | ||
365 | // m_bConnected = true; | ||
366 | |||
367 | // } | ||