summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mailit/popclient.cpp22
-rw-r--r--noncore/net/mailit/smtpclient.cpp8
-rw-r--r--noncore/unsupported/mailit/popclient.cpp22
-rw-r--r--noncore/unsupported/mailit/smtpclient.cpp8
4 files changed, 30 insertions, 30 deletions
diff --git a/noncore/net/mailit/popclient.cpp b/noncore/net/mailit/popclient.cpp
index a406af2..2f14ed2 100644
--- a/noncore/net/mailit/popclient.cpp
+++ b/noncore/net/mailit/popclient.cpp
@@ -1,375 +1,375 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved. 2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qt Palmtop Environment. 4** This file is part of Qt Palmtop Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#include "popclient.h" 20#include "popclient.h"
21#include "emailhandler.h" 21#include "emailhandler.h"
22//#define APOP_TEST 22//#define APOP_TEST
23 23
24extern "C" { 24extern "C" {
25#include "md5.h" 25#include "md5.h"
26} 26}
27 27
28#include <qcstring.h> 28#include <qcstring.h>
29 29
30PopClient::PopClient() 30PopClient::PopClient()
31{ 31{
32 socket = new QSocket(this, "popClient"); 32 socket = new QSocket(this, "popClient");
33 connect(socket, SIGNAL(error(int)), this, SLOT(errorHandling(int))); 33 connect(socket, SIGNAL(error(int)), this, SLOT(errorHandling(int)));
34 connect(socket, SIGNAL(connected()), this, SLOT(connectionEstablished())); 34 connect(socket, SIGNAL(connected()), this, SLOT(connectionEstablished()));
35 connect(socket, SIGNAL(readyRead()), this, SLOT(incomingData())); 35 connect(socket, SIGNAL(readyRead()), this, SLOT(incomingData()));
36 36
37 stream = new QTextStream(socket); 37 stream = new QTextStream(socket);
38 38
39 receiving = FALSE; 39 receiving = FALSE;
40 synchronize = FALSE; 40 synchronize = FALSE;
41 lastSync = 0; 41 lastSync = 0;
42 headerLimit = 0; 42 headerLimit = 0;
43 preview = FALSE; 43 preview = FALSE;
44} 44}
45 45
46PopClient::~PopClient() 46PopClient::~PopClient()
47{ 47{
48 delete socket; 48 delete socket;
49 delete stream; 49 delete stream;
50} 50}
51 51
52void PopClient::newConnection(QString target, int port) 52void 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
68void PopClient::setAccount(QString popUser, QString popPasswd) 68void PopClient::setAccount(QString popUser, QString popPasswd)
69{ 69{
70 popUserName = popUser; 70 popUserName = popUser;
71 popPassword = popPasswd; 71 popPassword = popPasswd;
72} 72}
73 73
74void PopClient::setSynchronize(int lastCount) 74void PopClient::setSynchronize(int lastCount)
75{ 75{
76 synchronize = TRUE; 76 synchronize = TRUE;
77 lastSync = lastCount; 77 lastSync = lastCount;
78} 78}
79 79
80void PopClient::removeSynchronize() 80void PopClient::removeSynchronize()
81{ 81{
82 synchronize = FALSE; 82 synchronize = FALSE;
83 lastSync = 0; 83 lastSync = 0;
84} 84}
85 85
86void PopClient::headersOnly(bool headers, int limit) 86void PopClient::headersOnly(bool headers, int limit)
87{ 87{
88 preview = headers; 88 preview = headers;
89 headerLimit = limit; 89 headerLimit = limit;
90} 90}
91 91
92void PopClient::setSelectedMails(MailList *list) 92void PopClient::setSelectedMails(MailList *list)
93{ 93{
94 selected = TRUE; 94 selected = TRUE;
95 mailList = list; 95 mailList = list;
96} 96}
97 97
98void PopClient::connectionEstablished() 98void PopClient::connectionEstablished()
99{ 99{
100 emit updateStatus("Connection established"); 100 emit updateStatus(tr("Connection established"));
101} 101}
102 102
103void PopClient::errorHandling(int status) 103void PopClient::errorHandling(int status)
104{ 104{
105 emit updateStatus("Error Occured"); 105 emit updateStatus(tr("Error Occured"));
106 emit errorOccurred(status); 106 emit errorOccurred(status);
107 socket->close(); 107 socket->close();
108 receiving = FALSE; 108 receiving = FALSE;
109} 109}
110 110
111void PopClient::incomingData() 111void PopClient::incomingData()
112{ 112{
113 QString response, temp, temp2, timeStamp; 113 QString response, temp, temp2, timeStamp;
114 QString md5Source; 114 QString md5Source;
115 int start, end; 115 int start, end;
116// char *md5Digest; 116// char *md5Digest;
117 char md5Digest[16]; 117 char md5Digest[16];
118// if ( !socket->canReadLine() ) 118// if ( !socket->canReadLine() )
119// return; 119// return;
120 120
121 response = socket->readLine(); 121 response = socket->readLine();
122 qDebug(response +" %d", status); 122 qDebug(response +" %d", status);
123 123
124 switch(status) { 124 switch(status) {
125 //logging in 125 //logging in
126 case Init: { 126 case Init: {
127#ifdef APOP_TEST 127#ifdef APOP_TEST
128 start = response.find('<',0); 128 start = response.find('<',0);
129 end = response.find('>', start); 129 end = response.find('>', start);
130 if( start >= 0 && end > start ) 130 if( start >= 0 && end > start )
131 { 131 {
132 timeStamp = response.mid( start , end - start + 1); 132 timeStamp = response.mid( start , end - start + 1);
133 md5Source = timeStamp + popPassword; 133 md5Source = timeStamp + popPassword;
134 qDebug( md5Source); 134 qDebug( md5Source);
135// for( int i = 0; i < md5Source.length(); i++) { 135// for( int i = 0; i < md5Source.length(); i++) {
136// buff[i] = (QChar)md5Source[i]; 136// buff[i] = (QChar)md5Source[i];
137// } 137// }
138 138
139 md5_buffer( (char const *)md5Source, md5Source.length(),&md5Digest[0]); 139 md5_buffer( (char const *)md5Source, md5Source.length(),&md5Digest[0]);
140// md5_buffer(char const *buffer, unsigned int len, char *digest); 140// md5_buffer(char const *buffer, unsigned int len, char *digest);
141 141
142// MD5_Init( &ctx); 142// MD5_Init( &ctx);
143// MD5_Update( &ctx, buff, sizeof( buff) ); 143// MD5_Update( &ctx, buff, sizeof( buff) );
144// MD5_Final( md5Digest, &ctx); 144// MD5_Final( md5Digest, &ctx);
145// MD5( buff, md5Source.length(), md5Digest); 145// MD5( buff, md5Source.length(), md5Digest);
146 146
147 for(int j =0;j < MD5_DIGEST_LENGTH ;j++) 147 for(int j =0;j < MD5_DIGEST_LENGTH ;j++)
148 { 148 {
149 printf("%x", md5Digest[j]); 149 printf("%x", md5Digest[j]);
150 } 150 }
151 printf("\n"); 151 printf("\n");
152// qDebug(md5Digest); 152// qDebug(md5Digest);
153 *stream << "APOP " << popUserName << " " << md5Digest << "\r\n"; 153 *stream << "APOP " << popUserName << " " << md5Digest << "\r\n";
154 // qDebug("%s", stream); 154 // qDebug("%s", stream);
155 status = Stat; 155 status = Stat;
156 } 156 }
157 else 157 else
158#endif 158#endif
159 { 159 {
160 timeStamp = ""; 160 timeStamp = "";
161 *stream << "USER " << popUserName << "\r\n"; 161 *stream << "USER " << popUserName << "\r\n";
162 status = Pass; 162 status = Pass;
163 } 163 }
164 164
165 break; 165 break;
166 } 166 }
167 //password shhh. don't tell anyone (implement APOP...) 167 //password shhh. don't tell anyone (implement APOP...)
168 case Pass: { 168 case Pass: {
169 *stream << "PASS " << popPassword << "\r\n"; 169 *stream << "PASS " << popPassword << "\r\n";
170 status = Stat; 170 status = Stat;
171 break; 171 break;
172 } 172 }
173 //ask for number of messages 173 //ask for number of messages
174 case Stat: { 174 case Stat: {
175 if (response[0] == '+') { 175 if (response[0] == '+') {
176 *stream << "STAT" << "\r\n"; 176 *stream << "STAT" << "\r\n";
177 status = Mcnt; 177 status = Mcnt;
178 } else errorHandling(ErrLoginFailed); 178 } else errorHandling(ErrLoginFailed);
179 break; 179 break;
180 } 180 }
181 //get count of messages, eg "+OK 4 900.." -> int 4 181 //get count of messages, eg "+OK 4 900.." -> int 4
182 case Mcnt: { 182 case Mcnt: {
183 if (response[0] == '+') { 183 if (response[0] == '+') {
184 temp = response.replace(0, 4, ""); 184 temp = response.replace(0, 4, "");
185 int x = temp.find(" ", 0); 185 int x = temp.find(" ", 0);
186 temp.truncate((uint) x); 186 temp.truncate((uint) x);
187 newMessages = temp.toInt(); 187 newMessages = temp.toInt();
188 messageCount = 1; 188 messageCount = 1;
189 status = List; 189 status = List;
190 190
191 if (synchronize) { 191 if (synchronize) {
192 //messages deleted from server, reload all 192 //messages deleted from server, reload all
193 if (newMessages < lastSync) 193 if (newMessages < lastSync)
194 lastSync = 0; 194 lastSync = 0;
195 messageCount = lastSync + 1; 195 messageCount = lastSync + 1;
196 } 196 }
197 197
198 if (selected) { 198 if (selected) {
199 int *ptr = mailList->first(); 199 int *ptr = mailList->first();
200 if (ptr != 0) { 200 if (ptr != 0) {
201 newMessages++; //to ensure no early jumpout 201 newMessages++; //to ensure no early jumpout
202 messageCount = *(mailList->first()); 202 messageCount = *(mailList->first());
203 } else newMessages = 0; 203 } else newMessages = 0;
204 } 204 }
205 } else errorHandling(ErrUnknownResponse); 205 } else errorHandling(ErrUnknownResponse);
206 } 206 }
207 //Read message number x, count upwards to messageCount 207 //Read message number x, count upwards to messageCount
208 case List: { 208 case List: {
209 if (messageCount <= newMessages) { 209 if (messageCount <= newMessages) {
210 *stream << "LIST " << messageCount << "\r\n"; 210 *stream << "LIST " << messageCount << "\r\n";
211 status = Size; 211 status = Size;
212 temp2.setNum(newMessages - lastSync); 212 temp2.setNum(newMessages - lastSync);
213 temp.setNum(messageCount - lastSync); 213 temp.setNum(messageCount - lastSync);
214 if (!selected) { 214 if (!selected) {
215 emit updateStatus("Retrieving " + temp + "/" + temp2); 215 emit updateStatus(tr("Retrieving ") + temp + "/" + temp2);
216 } else { 216 } else {
217 //completing a previously closed transfer 217 //completing a previously closed transfer
218 if ( (messageCount - lastSync) <= 0) { 218 if ( (messageCount - lastSync) <= 0) {
219 temp.setNum(messageCount); 219 temp.setNum(messageCount);
220 emit updateStatus("Previous message " + temp); 220 emit updateStatus(tr("Previous message ") + temp);
221 } else { 221 } else {
222 emit updateStatus("Completing message " + temp); 222 emit updateStatus(tr("Completing message ") + temp);
223 } 223 }
224 } 224 }
225 break; 225 break;
226 } else { 226 } else {
227 emit updateStatus("No new Messages"); 227 emit updateStatus(tr("No new Messages"));
228 status = Quit; 228 status = Quit;
229 } 229 }
230 } 230 }
231 //get size of message, eg "500 characters in message.." -> int 500 231 //get size of message, eg "500 characters in message.." -> int 500
232 case Size: { 232 case Size: {
233 if (status != Quit) { //because of idiotic switch 233 if (status != Quit) { //because of idiotic switch
234 if (response[0] == '+') { 234 if (response[0] == '+') {
235 temp = response.replace(0, 4, ""); 235 temp = response.replace(0, 4, "");
236 int x = temp.find(" ", 0); 236 int x = temp.find(" ", 0);
237 temp = temp.right(temp.length() - ((uint) x + 1) ); 237 temp = temp.right(temp.length() - ((uint) x + 1) );
238 mailSize = temp.toInt(); 238 mailSize = temp.toInt();
239 emit currentMailSize(mailSize); 239 emit currentMailSize(mailSize);
240 240
241 status = Retr; 241 status = Retr;
242 } else { 242 } else {
243 qWarning(response); 243 qWarning(response);
244 errorHandling(ErrUnknownResponse); 244 errorHandling(ErrUnknownResponse);
245 } 245 }
246 } 246 }
247 } 247 }
248 //Read message number x, count upwards to messageCount 248 //Read message number x, count upwards to messageCount
249 case Retr: { 249 case Retr: {
250 if (status != Quit) { 250 if (status != Quit) {
251 if (!preview || mailSize <= headerLimit) { 251 if (!preview || mailSize <= headerLimit) {
252 *stream << "RETR " << messageCount << "\r\n"; 252 *stream << "RETR " << messageCount << "\r\n";
253 } else { //only header 253 } else { //only header
254 *stream << "TOP " << messageCount << " 0\r\n"; 254 *stream << "TOP " << messageCount << " 0\r\n";
255 } 255 }
256 messageCount++; 256 messageCount++;
257 status = Ignore; 257 status = Ignore;
258 break; 258 break;
259 } } 259 } }
260 case Ignore: { 260 case Ignore: {
261 if (status != Quit) { //because of idiotic switch 261 if (status != Quit) { //because of idiotic switch
262 if (response[0] == '+') { 262 if (response[0] == '+') {
263 message = ""; 263 message = "";
264 status = Read; 264 status = Read;
265 if (!socket->canReadLine()) //sync. problems 265 if (!socket->canReadLine()) //sync. problems
266 break; 266 break;
267 response = socket->readLine(); 267 response = socket->readLine();
268 } else errorHandling(ErrUnknownResponse); 268 } else errorHandling(ErrUnknownResponse);
269 } 269 }
270 } 270 }
271 //add all incoming lines to body. When size is reached, send 271 //add all incoming lines to body. When size is reached, send
272 //message, and go back to read new message 272 //message, and go back to read new message
273 case Read: { 273 case Read: {
274 if (status != Quit) { //because of idiotic switch 274 if (status != Quit) { //because of idiotic switch
275 message += response; 275 message += response;
276 while ( socket->canReadLine() ) { 276 while ( socket->canReadLine() ) {
277 response = socket->readLine(); 277 response = socket->readLine();
278 message += response; 278 message += response;
279 } 279 }
280 emit downloadedSize(message.length()); 280 emit downloadedSize(message.length());
281 int x = message.find("\r\n.\r\n",-5); 281 int x = message.find("\r\n.\r\n",-5);
282 if (x == -1) { 282 if (x == -1) {
283 break; 283 break;
284 } else { //message reach entire size 284 } else { //message reach entire size
285 //complete mail downloaded 285 //complete mail downloaded
286 if ( (!preview ) || ((preview) && (mailSize <= headerLimit)) ){ 286 if ( (!preview ) || ((preview) && (mailSize <= headerLimit)) ){
287 emit newMessage(message, messageCount-1, mailSize, TRUE); 287 emit newMessage(message, messageCount-1, mailSize, TRUE);
288 } else { //incomplete mail downloaded 288 } else { //incomplete mail downloaded
289 emit newMessage(message, messageCount-1, mailSize, FALSE); 289 emit newMessage(message, messageCount-1, mailSize, FALSE);
290 } 290 }
291 if (messageCount > newMessages) //that was the last message 291 if (messageCount > newMessages) //that was the last message
292 status = Quit; 292 status = Quit;
293 else { //ask for new message 293 else { //ask for new message
294 if (selected) { //grab next from queue 294 if (selected) { //grab next from queue
295 int *ptr = mailList->next(); 295 int *ptr = mailList->next();
296 if (ptr != 0) { 296 if (ptr != 0) {
297 messageCount = *ptr; 297 messageCount = *ptr;
298 *stream << "LIST " << messageCount << "\r\n"; 298 *stream << "LIST " << messageCount << "\r\n";
299 status = Size; 299 status = Size;
300 //completing a previously closed transfer 300 //completing a previously closed transfer
301 if ( (messageCount - lastSync) <= 0) { 301 if ( (messageCount - lastSync) <= 0) {
302 temp.setNum(messageCount); 302 temp.setNum(messageCount);
303 emit updateStatus("Previous message " + temp); 303 emit updateStatus(tr("Previous message ") + temp);
304 } else { 304 } else {
305 temp.setNum(messageCount - lastSync); 305 temp.setNum(messageCount - lastSync);
306 emit updateStatus("Completing message " + temp); 306 emit updateStatus(tr("Completing message ") + temp);
307 } 307 }
308 break; 308 break;
309 } else { 309 } else {
310 newMessages--; 310 newMessages--;
311 status = Quit; 311 status = Quit;
312 } 312 }
313 } else { 313 } else {
314 *stream << "LIST " << messageCount << "\r\n"; 314 *stream << "LIST " << messageCount << "\r\n";
315 status = Size; 315 status = Size;
316 temp2.setNum(newMessages - lastSync); 316 temp2.setNum(newMessages - lastSync);
317 temp.setNum(messageCount - lastSync); 317 temp.setNum(messageCount - lastSync);
318 emit updateStatus("Retrieving " + temp + "/" + temp2); 318 emit updateStatus(tr("Retrieving ") + temp + "/" + temp2);
319 319
320 break; 320 break;
321 } 321 }
322 } 322 }
323 } 323 }
324 if (status != Quit) 324 if (status != Quit)
325 break; 325 break;
326 } 326 }
327 } 327 }
328 case Quit: { 328 case Quit: {
329 *stream << "Quit\r\n"; 329 *stream << "Quit\r\n";
330 status = Done; 330 status = Done;
331 int newM = newMessages - lastSync; 331 int newM = newMessages - lastSync;
332 if (newM > 0) { 332 if (newM > 0) {
333 temp.setNum(newM); 333 temp.setNum(newM);
334 emit updateStatus(temp + " new messages"); 334 emit updateStatus(temp + tr(" new messages"));
335 } else { 335 } else {
336 emit updateStatus("No new messages"); 336 emit updateStatus(tr("No new messages"));
337 } 337 }
338 338
339 socket->close(); 339 socket->close();
340 receiving = FALSE; 340 receiving = FALSE;
341 emit mailTransfered(newM); 341 emit mailTransfered(newM);
342 break; 342 break;
343 } 343 }
344 } 344 }
345 345
346} 346}
347 347
348// if( bAPOPAuthentication ) 348// if( bAPOPAuthentication )
349// { 349// {
350// if( m_strTimeStamp.IsEmpty() ) 350// if( m_strTimeStamp.IsEmpty() )
351// { 351// {
352// SetLastError("Apop error!"); 352// SetLastError("Apop error!");
353// return false; 353// return false;
354// } 354// }
355// strMD5Source = m_strTimeStamp+pszPassword; 355// strMD5Source = m_strTimeStamp+pszPassword;
356// strMD5Dst = MD5_GetMD5( (BYTE*)(const char*)strMD5Source , strMD5Source.GetLength() ); 356// strMD5Dst = MD5_GetMD5( (BYTE*)(const char*)strMD5Source , strMD5Source.GetLength() );
357// sprintf(msg , "apop %s %s\r\n" , pszUser , strMD5Dst); 357// sprintf(msg , "apop %s %s\r\n" , pszUser , strMD5Dst);
358// ret = send(m_sPop3Socket , msg , strlen(msg) , NULL); 358// ret = send(m_sPop3Socket , msg , strlen(msg) , NULL);
359// if(ret == SOCKET_ERROR) 359// if(ret == SOCKET_ERROR)
360// { 360// {
361// SetLastError("Socket error!"); 361// SetLastError("Socket error!");
362// m_bSocketOK = false; 362// m_bSocketOK = false;
363// m_bConnected = false; 363// m_bConnected = false;
364// return false; 364// return false;
365// } 365// }
366// if( !GetSocketResult(&strResult , COMMAND_END_FLAG) ) 366// if( !GetSocketResult(&strResult , COMMAND_END_FLAG) )
367// return false; 367// return false;
368// if( 0 == strResult.Find('-' , 0) ) 368// if( 0 == strResult.Find('-' , 0) )
369// { 369// {
370// SetLastError("Username or Password error!"); 370// SetLastError("Username or Password error!");
371// return false; 371// return false;
372// } 372// }
373// m_bConnected = true; 373// m_bConnected = true;
374 374
375// } 375// }
diff --git a/noncore/net/mailit/smtpclient.cpp b/noncore/net/mailit/smtpclient.cpp
index 7bb7933..3bdc072 100644
--- a/noncore/net/mailit/smtpclient.cpp
+++ b/noncore/net/mailit/smtpclient.cpp
@@ -1,163 +1,163 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved. 2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qt Palmtop Environment. 4** This file is part of Qt Palmtop Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#include "smtpclient.h" 20#include "smtpclient.h"
21#include "emailhandler.h" 21#include "emailhandler.h"
22 22
23SmtpClient::SmtpClient() 23SmtpClient::SmtpClient()
24{ 24{
25 socket = new QSocket(this, "smtpClient"); 25 socket = new QSocket(this, "smtpClient");
26 stream = new QTextStream(socket); 26 stream = new QTextStream(socket);
27 mailList.setAutoDelete(TRUE); 27 mailList.setAutoDelete(TRUE);
28 28
29 connect(socket, SIGNAL(error(int)), this, SLOT(errorHandling(int))); 29 connect(socket, SIGNAL(error(int)), this, SLOT(errorHandling(int)));
30 connect(socket, SIGNAL(connected()), this, SLOT(connectionEstablished())); 30 connect(socket, SIGNAL(connected()), this, SLOT(connectionEstablished()));
31 connect(socket, SIGNAL(readyRead()), this, SLOT(incomingData())); 31 connect(socket, SIGNAL(readyRead()), this, SLOT(incomingData()));
32 32
33 sending = FALSE; 33 sending = FALSE;
34} 34}
35 35
36SmtpClient::~SmtpClient() 36SmtpClient::~SmtpClient()
37{ 37{
38 delete socket; 38 delete socket;
39 delete stream; 39 delete stream;
40} 40}
41 41
42void SmtpClient::newConnection(QString target, int port) 42void SmtpClient::newConnection(QString target, int port)
43{ 43{
44 if (sending) { 44 if (sending) {
45 qWarning("socket in use, connection refused"); 45 qWarning("socket in use, connection refused");
46 return; 46 return;
47 } 47 }
48 48
49 status = Init; 49 status = Init;
50 sending = TRUE; 50 sending = TRUE;
51 socket->connectToHost(target, port); 51 socket->connectToHost(target, port);
52 52
53 emit updateStatus("DNS lookup"); 53 emit updateStatus(tr("DNS lookup"));
54} 54}
55 55
56void SmtpClient::addMail(QString from, QString subject, QStringList to, QString body) 56void SmtpClient::addMail(QString from, QString subject, QStringList to, QString body)
57{ 57{
58 RawEmail *mail = new RawEmail; 58 RawEmail *mail = new RawEmail;
59 59
60 mail->from = from; 60 mail->from = from;
61 mail->subject = subject; 61 mail->subject = subject;
62 mail->to = to; 62 mail->to = to;
63 mail->body = body; 63 mail->body = body;
64 64
65 mailList.append(mail); 65 mailList.append(mail);
66} 66}
67 67
68void SmtpClient::connectionEstablished() 68void SmtpClient::connectionEstablished()
69{ 69{
70 emit updateStatus("Connection established"); 70 emit updateStatus(tr("Connection established"));
71 71
72} 72}
73 73
74void SmtpClient::errorHandling(int status) 74void SmtpClient::errorHandling(int status)
75{ 75{
76 emit errorOccurred(status); 76 emit errorOccurred(status);
77 socket->close(); 77 socket->close();
78 mailList.clear(); 78 mailList.clear();
79 sending = FALSE; 79 sending = FALSE;
80} 80}
81 81
82void SmtpClient::incomingData() 82void SmtpClient::incomingData()
83{ 83{
84 QString response; 84 QString response;
85 85
86 if (!socket->canReadLine()) 86 if (!socket->canReadLine())
87 return; 87 return;
88 88
89 response = socket->readLine(); 89 response = socket->readLine();
90 90
91 switch(status) { 91 switch(status) {
92 case Init: { 92 case Init: {
93 if (response[0] == '2') { 93 if (response[0] == '2') {
94 status = From; 94 status = From;
95 mailPtr = mailList.first(); 95 mailPtr = mailList.first();
96 *stream << "HELO there\r\n"; 96 *stream << "HELO there\r\n";
97 } else errorHandling(ErrUnknownResponse); 97 } else errorHandling(ErrUnknownResponse);
98 break; 98 break;
99 } 99 }
100 case From: { 100 case From: {
101 if (response[0] == '2') { 101 if (response[0] == '2') {
102 *stream << "MAIL FROM: <" << mailPtr->from << ">\r\n"; 102 *stream << "MAIL FROM: <" << mailPtr->from << ">\r\n";
103 status = Recv; 103 status = Recv;
104 } else errorHandling(ErrUnknownResponse); 104 } else errorHandling(ErrUnknownResponse);
105 break; 105 break;
106 } 106 }
107 case Recv: { 107 case Recv: {
108 if (response[0] == '2') { 108 if (response[0] == '2') {
109 it = mailPtr->to.begin(); 109 it = mailPtr->to.begin();
110 if (it == NULL) 110 if (it == NULL)
111 errorHandling(ErrUnknownResponse); 111 errorHandling(ErrUnknownResponse);
112 *stream << "RCPT TO: <" << *it << ">\r\n"; 112 *stream << "RCPT TO: <" << *it << ">\r\n";
113 status = MRcv; 113 status = MRcv;
114 } else errorHandling(ErrUnknownResponse); 114 } else errorHandling(ErrUnknownResponse);
115 break; 115 break;
116 } 116 }
117 case MRcv: { 117 case MRcv: {
118 if (response[0] == '2') { 118 if (response[0] == '2') {
119 it++; 119 it++;
120 if ( it != mailPtr->to.end() ) { 120 if ( it != mailPtr->to.end() ) {
121 *stream << "RCPT TO: <" << *it << ">\r\n"; 121 *stream << "RCPT TO: <" << *it << ">\r\n";
122 break; 122 break;
123 } else { 123 } else {
124 status = Data; 124 status = Data;
125 } 125 }
126 } else errorHandling(ErrUnknownResponse); 126 } else errorHandling(ErrUnknownResponse);
127 } 127 }
128 case Data: { 128 case Data: {
129 if (response[0] == '2') { 129 if (response[0] == '2') {
130 *stream << "DATA\r\n"; 130 *stream << "DATA\r\n";
131 status = Body; 131 status = Body;
132 emit updateStatus("Sending: " + mailPtr->subject); 132 emit updateStatus(tr("Sending: ") + mailPtr->subject);
133 } else errorHandling(ErrUnknownResponse); 133 } else errorHandling(ErrUnknownResponse);
134 break; 134 break;
135 } 135 }
136 case Body: { 136 case Body: {
137 if (response[0] == '3') { 137 if (response[0] == '3') {
138 *stream << mailPtr->body << "\r\n.\r\n"; 138 *stream << mailPtr->body << "\r\n.\r\n";
139 mailPtr = mailList.next(); 139 mailPtr = mailList.next();
140 if (mailPtr != NULL) { 140 if (mailPtr != NULL) {
141 status = From; 141 status = From;
142 } else { 142 } else {
143 status = Quit; 143 status = Quit;
144 } 144 }
145 } else errorHandling(ErrUnknownResponse); 145 } else errorHandling(ErrUnknownResponse);
146 break; 146 break;
147 } 147 }
148 case Quit: { 148 case Quit: {
149 if (response[0] == '2') { 149 if (response[0] == '2') {
150 *stream << "QUIT\r\n"; 150 *stream << "QUIT\r\n";
151 status = Done; 151 status = Done;
152 QString temp; 152 QString temp;
153 temp.setNum(mailList.count()); 153 temp.setNum(mailList.count());
154 emit updateStatus("Sent " + temp + " messages"); 154 emit updateStatus(tr("Sent ") + temp + tr(" messages"));
155 emit mailSent(); 155 emit mailSent();
156 mailList.clear(); 156 mailList.clear();
157 sending = FALSE; 157 sending = FALSE;
158 socket->close(); 158 socket->close();
159 } else errorHandling(ErrUnknownResponse); 159 } else errorHandling(ErrUnknownResponse);
160 break; 160 break;
161 } 161 }
162 } 162 }
163} 163}
diff --git a/noncore/unsupported/mailit/popclient.cpp b/noncore/unsupported/mailit/popclient.cpp
index a406af2..2f14ed2 100644
--- a/noncore/unsupported/mailit/popclient.cpp
+++ b/noncore/unsupported/mailit/popclient.cpp
@@ -1,375 +1,375 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved. 2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qt Palmtop Environment. 4** This file is part of Qt Palmtop Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#include "popclient.h" 20#include "popclient.h"
21#include "emailhandler.h" 21#include "emailhandler.h"
22//#define APOP_TEST 22//#define APOP_TEST
23 23
24extern "C" { 24extern "C" {
25#include "md5.h" 25#include "md5.h"
26} 26}
27 27
28#include <qcstring.h> 28#include <qcstring.h>
29 29
30PopClient::PopClient() 30PopClient::PopClient()
31{ 31{
32 socket = new QSocket(this, "popClient"); 32 socket = new QSocket(this, "popClient");
33 connect(socket, SIGNAL(error(int)), this, SLOT(errorHandling(int))); 33 connect(socket, SIGNAL(error(int)), this, SLOT(errorHandling(int)));
34 connect(socket, SIGNAL(connected()), this, SLOT(connectionEstablished())); 34 connect(socket, SIGNAL(connected()), this, SLOT(connectionEstablished()));
35 connect(socket, SIGNAL(readyRead()), this, SLOT(incomingData())); 35 connect(socket, SIGNAL(readyRead()), this, SLOT(incomingData()));
36 36
37 stream = new QTextStream(socket); 37 stream = new QTextStream(socket);
38 38
39 receiving = FALSE; 39 receiving = FALSE;
40 synchronize = FALSE; 40 synchronize = FALSE;
41 lastSync = 0; 41 lastSync = 0;
42 headerLimit = 0; 42 headerLimit = 0;
43 preview = FALSE; 43 preview = FALSE;
44} 44}
45 45
46PopClient::~PopClient() 46PopClient::~PopClient()
47{ 47{
48 delete socket; 48 delete socket;
49 delete stream; 49 delete stream;
50} 50}
51 51
52void PopClient::newConnection(QString target, int port) 52void 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
68void PopClient::setAccount(QString popUser, QString popPasswd) 68void PopClient::setAccount(QString popUser, QString popPasswd)
69{ 69{
70 popUserName = popUser; 70 popUserName = popUser;
71 popPassword = popPasswd; 71 popPassword = popPasswd;
72} 72}
73 73
74void PopClient::setSynchronize(int lastCount) 74void PopClient::setSynchronize(int lastCount)
75{ 75{
76 synchronize = TRUE; 76 synchronize = TRUE;
77 lastSync = lastCount; 77 lastSync = lastCount;
78} 78}
79 79
80void PopClient::removeSynchronize() 80void PopClient::removeSynchronize()
81{ 81{
82 synchronize = FALSE; 82 synchronize = FALSE;
83 lastSync = 0; 83 lastSync = 0;
84} 84}
85 85
86void PopClient::headersOnly(bool headers, int limit) 86void PopClient::headersOnly(bool headers, int limit)
87{ 87{
88 preview = headers; 88 preview = headers;
89 headerLimit = limit; 89 headerLimit = limit;
90} 90}
91 91
92void PopClient::setSelectedMails(MailList *list) 92void PopClient::setSelectedMails(MailList *list)
93{ 93{
94 selected = TRUE; 94 selected = TRUE;
95 mailList = list; 95 mailList = list;
96} 96}
97 97
98void PopClient::connectionEstablished() 98void PopClient::connectionEstablished()
99{ 99{
100 emit updateStatus("Connection established"); 100 emit updateStatus(tr("Connection established"));
101} 101}
102 102
103void PopClient::errorHandling(int status) 103void PopClient::errorHandling(int status)
104{ 104{
105 emit updateStatus("Error Occured"); 105 emit updateStatus(tr("Error Occured"));
106 emit errorOccurred(status); 106 emit errorOccurred(status);
107 socket->close(); 107 socket->close();
108 receiving = FALSE; 108 receiving = FALSE;
109} 109}
110 110
111void PopClient::incomingData() 111void PopClient::incomingData()
112{ 112{
113 QString response, temp, temp2, timeStamp; 113 QString response, temp, temp2, timeStamp;
114 QString md5Source; 114 QString md5Source;
115 int start, end; 115 int start, end;
116// char *md5Digest; 116// char *md5Digest;
117 char md5Digest[16]; 117 char md5Digest[16];
118// if ( !socket->canReadLine() ) 118// if ( !socket->canReadLine() )
119// return; 119// return;
120 120
121 response = socket->readLine(); 121 response = socket->readLine();
122 qDebug(response +" %d", status); 122 qDebug(response +" %d", status);
123 123
124 switch(status) { 124 switch(status) {
125 //logging in 125 //logging in
126 case Init: { 126 case Init: {
127#ifdef APOP_TEST 127#ifdef APOP_TEST
128 start = response.find('<',0); 128 start = response.find('<',0);
129 end = response.find('>', start); 129 end = response.find('>', start);
130 if( start >= 0 && end > start ) 130 if( start >= 0 && end > start )
131 { 131 {
132 timeStamp = response.mid( start , end - start + 1); 132 timeStamp = response.mid( start , end - start + 1);
133 md5Source = timeStamp + popPassword; 133 md5Source = timeStamp + popPassword;
134 qDebug( md5Source); 134 qDebug( md5Source);
135// for( int i = 0; i < md5Source.length(); i++) { 135// for( int i = 0; i < md5Source.length(); i++) {
136// buff[i] = (QChar)md5Source[i]; 136// buff[i] = (QChar)md5Source[i];
137// } 137// }
138 138
139 md5_buffer( (char const *)md5Source, md5Source.length(),&md5Digest[0]); 139 md5_buffer( (char const *)md5Source, md5Source.length(),&md5Digest[0]);
140// md5_buffer(char const *buffer, unsigned int len, char *digest); 140// md5_buffer(char const *buffer, unsigned int len, char *digest);
141 141
142// MD5_Init( &ctx); 142// MD5_Init( &ctx);
143// MD5_Update( &ctx, buff, sizeof( buff) ); 143// MD5_Update( &ctx, buff, sizeof( buff) );
144// MD5_Final( md5Digest, &ctx); 144// MD5_Final( md5Digest, &ctx);
145// MD5( buff, md5Source.length(), md5Digest); 145// MD5( buff, md5Source.length(), md5Digest);
146 146
147 for(int j =0;j < MD5_DIGEST_LENGTH ;j++) 147 for(int j =0;j < MD5_DIGEST_LENGTH ;j++)
148 { 148 {
149 printf("%x", md5Digest[j]); 149 printf("%x", md5Digest[j]);
150 } 150 }
151 printf("\n"); 151 printf("\n");
152// qDebug(md5Digest); 152// qDebug(md5Digest);
153 *stream << "APOP " << popUserName << " " << md5Digest << "\r\n"; 153 *stream << "APOP " << popUserName << " " << md5Digest << "\r\n";
154 // qDebug("%s", stream); 154 // qDebug("%s", stream);
155 status = Stat; 155 status = Stat;
156 } 156 }
157 else 157 else
158#endif 158#endif
159 { 159 {
160 timeStamp = ""; 160 timeStamp = "";
161 *stream << "USER " << popUserName << "\r\n"; 161 *stream << "USER " << popUserName << "\r\n";
162 status = Pass; 162 status = Pass;
163 } 163 }
164 164
165 break; 165 break;
166 } 166 }
167 //password shhh. don't tell anyone (implement APOP...) 167 //password shhh. don't tell anyone (implement APOP...)
168 case Pass: { 168 case Pass: {
169 *stream << "PASS " << popPassword << "\r\n"; 169 *stream << "PASS " << popPassword << "\r\n";
170 status = Stat; 170 status = Stat;
171 break; 171 break;
172 } 172 }
173 //ask for number of messages 173 //ask for number of messages
174 case Stat: { 174 case Stat: {
175 if (response[0] == '+') { 175 if (response[0] == '+') {
176 *stream << "STAT" << "\r\n"; 176 *stream << "STAT" << "\r\n";
177 status = Mcnt; 177 status = Mcnt;
178 } else errorHandling(ErrLoginFailed); 178 } else errorHandling(ErrLoginFailed);
179 break; 179 break;
180 } 180 }
181 //get count of messages, eg "+OK 4 900.." -> int 4 181 //get count of messages, eg "+OK 4 900.." -> int 4
182 case Mcnt: { 182 case Mcnt: {
183 if (response[0] == '+') { 183 if (response[0] == '+') {
184 temp = response.replace(0, 4, ""); 184 temp = response.replace(0, 4, "");
185 int x = temp.find(" ", 0); 185 int x = temp.find(" ", 0);
186 temp.truncate((uint) x); 186 temp.truncate((uint) x);
187 newMessages = temp.toInt(); 187 newMessages = temp.toInt();
188 messageCount = 1; 188 messageCount = 1;
189 status = List; 189 status = List;
190 190
191 if (synchronize) { 191 if (synchronize) {
192 //messages deleted from server, reload all 192 //messages deleted from server, reload all
193 if (newMessages < lastSync) 193 if (newMessages < lastSync)
194 lastSync = 0; 194 lastSync = 0;
195 messageCount = lastSync + 1; 195 messageCount = lastSync + 1;
196 } 196 }
197 197
198 if (selected) { 198 if (selected) {
199 int *ptr = mailList->first(); 199 int *ptr = mailList->first();
200 if (ptr != 0) { 200 if (ptr != 0) {
201 newMessages++; //to ensure no early jumpout 201 newMessages++; //to ensure no early jumpout
202 messageCount = *(mailList->first()); 202 messageCount = *(mailList->first());
203 } else newMessages = 0; 203 } else newMessages = 0;
204 } 204 }
205 } else errorHandling(ErrUnknownResponse); 205 } else errorHandling(ErrUnknownResponse);
206 } 206 }
207 //Read message number x, count upwards to messageCount 207 //Read message number x, count upwards to messageCount
208 case List: { 208 case List: {
209 if (messageCount <= newMessages) { 209 if (messageCount <= newMessages) {
210 *stream << "LIST " << messageCount << "\r\n"; 210 *stream << "LIST " << messageCount << "\r\n";
211 status = Size; 211 status = Size;
212 temp2.setNum(newMessages - lastSync); 212 temp2.setNum(newMessages - lastSync);
213 temp.setNum(messageCount - lastSync); 213 temp.setNum(messageCount - lastSync);
214 if (!selected) { 214 if (!selected) {
215 emit updateStatus("Retrieving " + temp + "/" + temp2); 215 emit updateStatus(tr("Retrieving ") + temp + "/" + temp2);
216 } else { 216 } else {
217 //completing a previously closed transfer 217 //completing a previously closed transfer
218 if ( (messageCount - lastSync) <= 0) { 218 if ( (messageCount - lastSync) <= 0) {
219 temp.setNum(messageCount); 219 temp.setNum(messageCount);
220 emit updateStatus("Previous message " + temp); 220 emit updateStatus(tr("Previous message ") + temp);
221 } else { 221 } else {
222 emit updateStatus("Completing message " + temp); 222 emit updateStatus(tr("Completing message ") + temp);
223 } 223 }
224 } 224 }
225 break; 225 break;
226 } else { 226 } else {
227 emit updateStatus("No new Messages"); 227 emit updateStatus(tr("No new Messages"));
228 status = Quit; 228 status = Quit;
229 } 229 }
230 } 230 }
231 //get size of message, eg "500 characters in message.." -> int 500 231 //get size of message, eg "500 characters in message.." -> int 500
232 case Size: { 232 case Size: {
233 if (status != Quit) { //because of idiotic switch 233 if (status != Quit) { //because of idiotic switch
234 if (response[0] == '+') { 234 if (response[0] == '+') {
235 temp = response.replace(0, 4, ""); 235 temp = response.replace(0, 4, "");
236 int x = temp.find(" ", 0); 236 int x = temp.find(" ", 0);
237 temp = temp.right(temp.length() - ((uint) x + 1) ); 237 temp = temp.right(temp.length() - ((uint) x + 1) );
238 mailSize = temp.toInt(); 238 mailSize = temp.toInt();
239 emit currentMailSize(mailSize); 239 emit currentMailSize(mailSize);
240 240
241 status = Retr; 241 status = Retr;
242 } else { 242 } else {
243 qWarning(response); 243 qWarning(response);
244 errorHandling(ErrUnknownResponse); 244 errorHandling(ErrUnknownResponse);
245 } 245 }
246 } 246 }
247 } 247 }
248 //Read message number x, count upwards to messageCount 248 //Read message number x, count upwards to messageCount
249 case Retr: { 249 case Retr: {
250 if (status != Quit) { 250 if (status != Quit) {
251 if (!preview || mailSize <= headerLimit) { 251 if (!preview || mailSize <= headerLimit) {
252 *stream << "RETR " << messageCount << "\r\n"; 252 *stream << "RETR " << messageCount << "\r\n";
253 } else { //only header 253 } else { //only header
254 *stream << "TOP " << messageCount << " 0\r\n"; 254 *stream << "TOP " << messageCount << " 0\r\n";
255 } 255 }
256 messageCount++; 256 messageCount++;
257 status = Ignore; 257 status = Ignore;
258 break; 258 break;
259 } } 259 } }
260 case Ignore: { 260 case Ignore: {
261 if (status != Quit) { //because of idiotic switch 261 if (status != Quit) { //because of idiotic switch
262 if (response[0] == '+') { 262 if (response[0] == '+') {
263 message = ""; 263 message = "";
264 status = Read; 264 status = Read;
265 if (!socket->canReadLine()) //sync. problems 265 if (!socket->canReadLine()) //sync. problems
266 break; 266 break;
267 response = socket->readLine(); 267 response = socket->readLine();
268 } else errorHandling(ErrUnknownResponse); 268 } else errorHandling(ErrUnknownResponse);
269 } 269 }
270 } 270 }
271 //add all incoming lines to body. When size is reached, send 271 //add all incoming lines to body. When size is reached, send
272 //message, and go back to read new message 272 //message, and go back to read new message
273 case Read: { 273 case Read: {
274 if (status != Quit) { //because of idiotic switch 274 if (status != Quit) { //because of idiotic switch
275 message += response; 275 message += response;
276 while ( socket->canReadLine() ) { 276 while ( socket->canReadLine() ) {
277 response = socket->readLine(); 277 response = socket->readLine();
278 message += response; 278 message += response;
279 } 279 }
280 emit downloadedSize(message.length()); 280 emit downloadedSize(message.length());
281 int x = message.find("\r\n.\r\n",-5); 281 int x = message.find("\r\n.\r\n",-5);
282 if (x == -1) { 282 if (x == -1) {
283 break; 283 break;
284 } else { //message reach entire size 284 } else { //message reach entire size
285 //complete mail downloaded 285 //complete mail downloaded
286 if ( (!preview ) || ((preview) && (mailSize <= headerLimit)) ){ 286 if ( (!preview ) || ((preview) && (mailSize <= headerLimit)) ){
287 emit newMessage(message, messageCount-1, mailSize, TRUE); 287 emit newMessage(message, messageCount-1, mailSize, TRUE);
288 } else { //incomplete mail downloaded 288 } else { //incomplete mail downloaded
289 emit newMessage(message, messageCount-1, mailSize, FALSE); 289 emit newMessage(message, messageCount-1, mailSize, FALSE);
290 } 290 }
291 if (messageCount > newMessages) //that was the last message 291 if (messageCount > newMessages) //that was the last message
292 status = Quit; 292 status = Quit;
293 else { //ask for new message 293 else { //ask for new message
294 if (selected) { //grab next from queue 294 if (selected) { //grab next from queue
295 int *ptr = mailList->next(); 295 int *ptr = mailList->next();
296 if (ptr != 0) { 296 if (ptr != 0) {
297 messageCount = *ptr; 297 messageCount = *ptr;
298 *stream << "LIST " << messageCount << "\r\n"; 298 *stream << "LIST " << messageCount << "\r\n";
299 status = Size; 299 status = Size;
300 //completing a previously closed transfer 300 //completing a previously closed transfer
301 if ( (messageCount - lastSync) <= 0) { 301 if ( (messageCount - lastSync) <= 0) {
302 temp.setNum(messageCount); 302 temp.setNum(messageCount);
303 emit updateStatus("Previous message " + temp); 303 emit updateStatus(tr("Previous message ") + temp);
304 } else { 304 } else {
305 temp.setNum(messageCount - lastSync); 305 temp.setNum(messageCount - lastSync);
306 emit updateStatus("Completing message " + temp); 306 emit updateStatus(tr("Completing message ") + temp);
307 } 307 }
308 break; 308 break;
309 } else { 309 } else {
310 newMessages--; 310 newMessages--;
311 status = Quit; 311 status = Quit;
312 } 312 }
313 } else { 313 } else {
314 *stream << "LIST " << messageCount << "\r\n"; 314 *stream << "LIST " << messageCount << "\r\n";
315 status = Size; 315 status = Size;
316 temp2.setNum(newMessages - lastSync); 316 temp2.setNum(newMessages - lastSync);
317 temp.setNum(messageCount - lastSync); 317 temp.setNum(messageCount - lastSync);
318 emit updateStatus("Retrieving " + temp + "/" + temp2); 318 emit updateStatus(tr("Retrieving ") + temp + "/" + temp2);
319 319
320 break; 320 break;
321 } 321 }
322 } 322 }
323 } 323 }
324 if (status != Quit) 324 if (status != Quit)
325 break; 325 break;
326 } 326 }
327 } 327 }
328 case Quit: { 328 case Quit: {
329 *stream << "Quit\r\n"; 329 *stream << "Quit\r\n";
330 status = Done; 330 status = Done;
331 int newM = newMessages - lastSync; 331 int newM = newMessages - lastSync;
332 if (newM > 0) { 332 if (newM > 0) {
333 temp.setNum(newM); 333 temp.setNum(newM);
334 emit updateStatus(temp + " new messages"); 334 emit updateStatus(temp + tr(" new messages"));
335 } else { 335 } else {
336 emit updateStatus("No new messages"); 336 emit updateStatus(tr("No new messages"));
337 } 337 }
338 338
339 socket->close(); 339 socket->close();
340 receiving = FALSE; 340 receiving = FALSE;
341 emit mailTransfered(newM); 341 emit mailTransfered(newM);
342 break; 342 break;
343 } 343 }
344 } 344 }
345 345
346} 346}
347 347
348// if( bAPOPAuthentication ) 348// if( bAPOPAuthentication )
349// { 349// {
350// if( m_strTimeStamp.IsEmpty() ) 350// if( m_strTimeStamp.IsEmpty() )
351// { 351// {
352// SetLastError("Apop error!"); 352// SetLastError("Apop error!");
353// return false; 353// return false;
354// } 354// }
355// strMD5Source = m_strTimeStamp+pszPassword; 355// strMD5Source = m_strTimeStamp+pszPassword;
356// strMD5Dst = MD5_GetMD5( (BYTE*)(const char*)strMD5Source , strMD5Source.GetLength() ); 356// strMD5Dst = MD5_GetMD5( (BYTE*)(const char*)strMD5Source , strMD5Source.GetLength() );
357// sprintf(msg , "apop %s %s\r\n" , pszUser , strMD5Dst); 357// sprintf(msg , "apop %s %s\r\n" , pszUser , strMD5Dst);
358// ret = send(m_sPop3Socket , msg , strlen(msg) , NULL); 358// ret = send(m_sPop3Socket , msg , strlen(msg) , NULL);
359// if(ret == SOCKET_ERROR) 359// if(ret == SOCKET_ERROR)
360// { 360// {
361// SetLastError("Socket error!"); 361// SetLastError("Socket error!");
362// m_bSocketOK = false; 362// m_bSocketOK = false;
363// m_bConnected = false; 363// m_bConnected = false;
364// return false; 364// return false;
365// } 365// }
366// if( !GetSocketResult(&strResult , COMMAND_END_FLAG) ) 366// if( !GetSocketResult(&strResult , COMMAND_END_FLAG) )
367// return false; 367// return false;
368// if( 0 == strResult.Find('-' , 0) ) 368// if( 0 == strResult.Find('-' , 0) )
369// { 369// {
370// SetLastError("Username or Password error!"); 370// SetLastError("Username or Password error!");
371// return false; 371// return false;
372// } 372// }
373// m_bConnected = true; 373// m_bConnected = true;
374 374
375// } 375// }
diff --git a/noncore/unsupported/mailit/smtpclient.cpp b/noncore/unsupported/mailit/smtpclient.cpp
index 7bb7933..3bdc072 100644
--- a/noncore/unsupported/mailit/smtpclient.cpp
+++ b/noncore/unsupported/mailit/smtpclient.cpp
@@ -1,163 +1,163 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved. 2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qt Palmtop Environment. 4** This file is part of Qt Palmtop Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#include "smtpclient.h" 20#include "smtpclient.h"
21#include "emailhandler.h" 21#include "emailhandler.h"
22 22
23SmtpClient::SmtpClient() 23SmtpClient::SmtpClient()
24{ 24{
25 socket = new QSocket(this, "smtpClient"); 25 socket = new QSocket(this, "smtpClient");
26 stream = new QTextStream(socket); 26 stream = new QTextStream(socket);
27 mailList.setAutoDelete(TRUE); 27 mailList.setAutoDelete(TRUE);
28 28
29 connect(socket, SIGNAL(error(int)), this, SLOT(errorHandling(int))); 29 connect(socket, SIGNAL(error(int)), this, SLOT(errorHandling(int)));
30 connect(socket, SIGNAL(connected()), this, SLOT(connectionEstablished())); 30 connect(socket, SIGNAL(connected()), this, SLOT(connectionEstablished()));
31 connect(socket, SIGNAL(readyRead()), this, SLOT(incomingData())); 31 connect(socket, SIGNAL(readyRead()), this, SLOT(incomingData()));
32 32
33 sending = FALSE; 33 sending = FALSE;
34} 34}
35 35
36SmtpClient::~SmtpClient() 36SmtpClient::~SmtpClient()
37{ 37{
38 delete socket; 38 delete socket;
39 delete stream; 39 delete stream;
40} 40}
41 41
42void SmtpClient::newConnection(QString target, int port) 42void SmtpClient::newConnection(QString target, int port)
43{ 43{
44 if (sending) { 44 if (sending) {
45 qWarning("socket in use, connection refused"); 45 qWarning("socket in use, connection refused");
46 return; 46 return;
47 } 47 }
48 48
49 status = Init; 49 status = Init;
50 sending = TRUE; 50 sending = TRUE;
51 socket->connectToHost(target, port); 51 socket->connectToHost(target, port);
52 52
53 emit updateStatus("DNS lookup"); 53 emit updateStatus(tr("DNS lookup"));
54} 54}
55 55
56void SmtpClient::addMail(QString from, QString subject, QStringList to, QString body) 56void SmtpClient::addMail(QString from, QString subject, QStringList to, QString body)
57{ 57{
58 RawEmail *mail = new RawEmail; 58 RawEmail *mail = new RawEmail;
59 59
60 mail->from = from; 60 mail->from = from;
61 mail->subject = subject; 61 mail->subject = subject;
62 mail->to = to; 62 mail->to = to;
63 mail->body = body; 63 mail->body = body;
64 64
65 mailList.append(mail); 65 mailList.append(mail);
66} 66}
67 67
68void SmtpClient::connectionEstablished() 68void SmtpClient::connectionEstablished()
69{ 69{
70 emit updateStatus("Connection established"); 70 emit updateStatus(tr("Connection established"));
71 71
72} 72}
73 73
74void SmtpClient::errorHandling(int status) 74void SmtpClient::errorHandling(int status)
75{ 75{
76 emit errorOccurred(status); 76 emit errorOccurred(status);
77 socket->close(); 77 socket->close();
78 mailList.clear(); 78 mailList.clear();
79 sending = FALSE; 79 sending = FALSE;
80} 80}
81 81
82void SmtpClient::incomingData() 82void SmtpClient::incomingData()
83{ 83{
84 QString response; 84 QString response;
85 85
86 if (!socket->canReadLine()) 86 if (!socket->canReadLine())
87 return; 87 return;
88 88
89 response = socket->readLine(); 89 response = socket->readLine();
90 90
91 switch(status) { 91 switch(status) {
92 case Init: { 92 case Init: {
93 if (response[0] == '2') { 93 if (response[0] == '2') {
94 status = From; 94 status = From;
95 mailPtr = mailList.first(); 95 mailPtr = mailList.first();
96 *stream << "HELO there\r\n"; 96 *stream << "HELO there\r\n";
97 } else errorHandling(ErrUnknownResponse); 97 } else errorHandling(ErrUnknownResponse);
98 break; 98 break;
99 } 99 }
100 case From: { 100 case From: {
101 if (response[0] == '2') { 101 if (response[0] == '2') {
102 *stream << "MAIL FROM: <" << mailPtr->from << ">\r\n"; 102 *stream << "MAIL FROM: <" << mailPtr->from << ">\r\n";
103 status = Recv; 103 status = Recv;
104 } else errorHandling(ErrUnknownResponse); 104 } else errorHandling(ErrUnknownResponse);
105 break; 105 break;
106 } 106 }
107 case Recv: { 107 case Recv: {
108 if (response[0] == '2') { 108 if (response[0] == '2') {
109 it = mailPtr->to.begin(); 109 it = mailPtr->to.begin();
110 if (it == NULL) 110 if (it == NULL)
111 errorHandling(ErrUnknownResponse); 111 errorHandling(ErrUnknownResponse);
112 *stream << "RCPT TO: <" << *it << ">\r\n"; 112 *stream << "RCPT TO: <" << *it << ">\r\n";
113 status = MRcv; 113 status = MRcv;
114 } else errorHandling(ErrUnknownResponse); 114 } else errorHandling(ErrUnknownResponse);
115 break; 115 break;
116 } 116 }
117 case MRcv: { 117 case MRcv: {
118 if (response[0] == '2') { 118 if (response[0] == '2') {
119 it++; 119 it++;
120 if ( it != mailPtr->to.end() ) { 120 if ( it != mailPtr->to.end() ) {
121 *stream << "RCPT TO: <" << *it << ">\r\n"; 121 *stream << "RCPT TO: <" << *it << ">\r\n";
122 break; 122 break;
123 } else { 123 } else {
124 status = Data; 124 status = Data;
125 } 125 }
126 } else errorHandling(ErrUnknownResponse); 126 } else errorHandling(ErrUnknownResponse);
127 } 127 }
128 case Data: { 128 case Data: {
129 if (response[0] == '2') { 129 if (response[0] == '2') {
130 *stream << "DATA\r\n"; 130 *stream << "DATA\r\n";
131 status = Body; 131 status = Body;
132 emit updateStatus("Sending: " + mailPtr->subject); 132 emit updateStatus(tr("Sending: ") + mailPtr->subject);
133 } else errorHandling(ErrUnknownResponse); 133 } else errorHandling(ErrUnknownResponse);
134 break; 134 break;
135 } 135 }
136 case Body: { 136 case Body: {
137 if (response[0] == '3') { 137 if (response[0] == '3') {
138 *stream << mailPtr->body << "\r\n.\r\n"; 138 *stream << mailPtr->body << "\r\n.\r\n";
139 mailPtr = mailList.next(); 139 mailPtr = mailList.next();
140 if (mailPtr != NULL) { 140 if (mailPtr != NULL) {
141 status = From; 141 status = From;
142 } else { 142 } else {
143 status = Quit; 143 status = Quit;
144 } 144 }
145 } else errorHandling(ErrUnknownResponse); 145 } else errorHandling(ErrUnknownResponse);
146 break; 146 break;
147 } 147 }
148 case Quit: { 148 case Quit: {
149 if (response[0] == '2') { 149 if (response[0] == '2') {
150 *stream << "QUIT\r\n"; 150 *stream << "QUIT\r\n";
151 status = Done; 151 status = Done;
152 QString temp; 152 QString temp;
153 temp.setNum(mailList.count()); 153 temp.setNum(mailList.count());
154 emit updateStatus("Sent " + temp + " messages"); 154 emit updateStatus(tr("Sent ") + temp + tr(" messages"));
155 emit mailSent(); 155 emit mailSent();
156 mailList.clear(); 156 mailList.clear();
157 sending = FALSE; 157 sending = FALSE;
158 socket->close(); 158 socket->close();
159 } else errorHandling(ErrUnknownResponse); 159 } else errorHandling(ErrUnknownResponse);
160 break; 160 break;
161 } 161 }
162 } 162 }
163} 163}