Diffstat (limited to 'noncore/net/mail/libmailwrapper/smtpwrapper.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/net/mail/libmailwrapper/smtpwrapper.cpp | 464 |
1 files changed, 10 insertions, 454 deletions
diff --git a/noncore/net/mail/libmailwrapper/smtpwrapper.cpp b/noncore/net/mail/libmailwrapper/smtpwrapper.cpp index 63acfd5..a4e0beb 100644 --- a/noncore/net/mail/libmailwrapper/smtpwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/smtpwrapper.cpp | |||
@@ -1,38 +1,31 @@ | |||
1 | #include <stdlib.h> | ||
2 | #include <sys/stat.h> | ||
3 | #include <sys/types.h> | ||
4 | #include <unistd.h> | ||
5 | #include <fcntl.h> | ||
6 | #include <string.h> | ||
7 | #include <qt.h> | ||
8 | |||
9 | #include <qpe/config.h> | ||
10 | #include <qpe/qcopenvelope_qws.h> | ||
11 | |||
12 | #include <libetpan/libetpan.h> | ||
13 | |||
14 | #include "smtpwrapper.h" | 1 | #include "smtpwrapper.h" |
15 | #include "mailwrapper.h" | 2 | #include "mailwrapper.h" |
16 | #include "abstractmail.h" | 3 | #include "abstractmail.h" |
17 | #include "logindialog.h" | 4 | #include "logindialog.h" |
18 | #include "mailtypes.h" | 5 | #include "mailtypes.h" |
19 | #include "sendmailprogress.h" | 6 | #include "sendmailprogress.h" |
20 | 7 | ||
21 | const char* SMTPwrapper::USER_AGENT="OpieMail v0.4"; | 8 | #include <qt.h> |
9 | |||
10 | #include <qpe/config.h> | ||
11 | #include <qpe/qcopenvelope_qws.h> | ||
12 | |||
13 | #include <libetpan/libetpan.h> | ||
14 | |||
22 | 15 | ||
23 | progressMailSend*SMTPwrapper::sendProgress = 0; | 16 | progressMailSend*SMTPwrapper::sendProgress = 0; |
24 | 17 | ||
25 | SMTPwrapper::SMTPwrapper(SMTPaccount * aSmtp ) | 18 | SMTPwrapper::SMTPwrapper(SMTPaccount * aSmtp ) |
26 | : QObject() | 19 | : Generatemail() |
27 | { | 20 | { |
28 | m_SmtpAccount = aSmtp; | 21 | m_SmtpAccount = aSmtp; |
29 | Config cfg( "mail" ); | 22 | Config cfg( "mail" ); |
30 | cfg.setGroup( "Status" ); | 23 | cfg.setGroup( "Status" ); |
31 | m_queuedMail = cfg.readNumEntry( "outgoing", 0 ); | 24 | m_queuedMail = cfg.readNumEntry( "outgoing", 0 ); |
32 | emit queuedMails( m_queuedMail ); | 25 | emit queuedMails( m_queuedMail ); |
33 | connect( this, SIGNAL( queuedMails(int) ), this, SLOT( emitQCop(int) ) ); | 26 | connect( this, SIGNAL( queuedMails(int) ), this, SLOT( emitQCop(int) ) ); |
34 | m_smtp = 0; | 27 | m_smtp = 0; |
35 | } | 28 | } |
36 | 29 | ||
37 | SMTPwrapper::~SMTPwrapper() | 30 | SMTPwrapper::~SMTPwrapper() |
38 | { | 31 | { |
@@ -78,461 +71,24 @@ QString SMTPwrapper::mailsmtpError( int errnum ) { | |||
78 | return tr( "User not local" ); | 71 | return tr( "User not local" ); |
79 | case MAILSMTP_ERROR_TRANSACTION_FAILED: | 72 | case MAILSMTP_ERROR_TRANSACTION_FAILED: |
80 | return tr( "Transaction failed" ); | 73 | return tr( "Transaction failed" ); |
81 | case MAILSMTP_ERROR_MEMORY: | 74 | case MAILSMTP_ERROR_MEMORY: |
82 | return tr( "Memory error" ); | 75 | return tr( "Memory error" ); |
83 | case MAILSMTP_ERROR_CONNECTION_REFUSED: | 76 | case MAILSMTP_ERROR_CONNECTION_REFUSED: |
84 | return tr( "Connection refused" ); | 77 | return tr( "Connection refused" ); |
85 | default: | 78 | default: |
86 | return tr( "Unknown error code" ); | 79 | return tr( "Unknown error code" ); |
87 | } | 80 | } |
88 | } | 81 | } |
89 | 82 | ||
90 | mailimf_mailbox *SMTPwrapper::newMailbox(const QString&name, const QString&mail ) { | ||
91 | return mailimf_mailbox_new( strdup( name.latin1() ), | ||
92 | strdup( mail.latin1() ) ); | ||
93 | } | ||
94 | |||
95 | mailimf_address_list *SMTPwrapper::parseAddresses(const QString&addr ) { | ||
96 | mailimf_address_list *addresses; | ||
97 | |||
98 | if ( addr.isEmpty() ) | ||
99 | return NULL; | ||
100 | |||
101 | addresses = mailimf_address_list_new_empty(); | ||
102 | |||
103 | bool literal_open = false; | ||
104 | unsigned int startpos = 0; | ||
105 | QStringList list; | ||
106 | QString s; | ||
107 | unsigned int i = 0; | ||
108 | for (; i < addr.length();++i) { | ||
109 | switch (addr[i]) { | ||
110 | case '\"': | ||
111 | literal_open = !literal_open; | ||
112 | break; | ||
113 | case ',': | ||
114 | if (!literal_open) { | ||
115 | s = addr.mid(startpos,i-startpos); | ||
116 | if (!s.isEmpty()) { | ||
117 | list.append(s); | ||
118 | qDebug("Appended %s",s.latin1()); | ||
119 | } | ||
120 | // !!!! this is a MUST BE! | ||
121 | startpos = ++i; | ||
122 | } | ||
123 | break; | ||
124 | default: | ||
125 | break; | ||
126 | } | ||
127 | } | ||
128 | s = addr.mid(startpos,i-startpos); | ||
129 | if (!s.isEmpty()) { | ||
130 | list.append(s); | ||
131 | qDebug("Appended %s",s.latin1()); | ||
132 | } | ||
133 | QStringList::Iterator it; | ||
134 | for ( it = list.begin(); it != list.end(); it++ ) { | ||
135 | int err = mailimf_address_list_add_parse( addresses, (char*)(*it).latin1() ); | ||
136 | if ( err != MAILIMF_NO_ERROR ) { | ||
137 | qDebug( "Error parsing" ); | ||
138 | qDebug( *it ); | ||
139 | } else { | ||
140 | qDebug( "Parse success! %s",(*it).latin1()); | ||
141 | } | ||
142 | } | ||
143 | return addresses; | ||
144 | } | ||
145 | |||
146 | mailimf_fields *SMTPwrapper::createImfFields(const Mail&mail ) { | ||
147 | mailimf_fields *fields; | ||
148 | mailimf_field *xmailer; | ||
149 | mailimf_mailbox *sender=0,*fromBox=0; | ||
150 | mailimf_mailbox_list *from=0; | ||
151 | mailimf_address_list *to=0, *cc=0, *bcc=0, *reply=0; | ||
152 | clist*in_reply_to = 0; | ||
153 | char *subject = strdup( mail.getSubject().latin1() ); | ||
154 | int err; | ||
155 | |||
156 | sender = newMailbox( mail.getName(), mail.getMail() ); | ||
157 | if ( sender == NULL ) | ||
158 | goto err_free; | ||
159 | |||
160 | fromBox = newMailbox( mail.getName(), mail.getMail() ); | ||
161 | if ( fromBox == NULL ) | ||
162 | goto err_free_sender; | ||
163 | |||
164 | from = mailimf_mailbox_list_new_empty(); | ||
165 | if ( from == NULL ) | ||
166 | goto err_free_fromBox; | ||
167 | |||
168 | err = mailimf_mailbox_list_add( from, fromBox ); | ||
169 | if ( err != MAILIMF_NO_ERROR ) | ||
170 | goto err_free_from; | ||
171 | |||
172 | to = parseAddresses( mail.getTo() ); | ||
173 | if ( to == NULL ) | ||
174 | goto err_free_from; | ||
175 | |||
176 | cc = parseAddresses( mail.getCC() ); | ||
177 | bcc = parseAddresses( mail.getBCC() ); | ||
178 | reply = parseAddresses( mail.getReply() ); | ||
179 | |||
180 | if (mail.Inreply().count()>0) { | ||
181 | in_reply_to = clist_new(); | ||
182 | char*c_reply; | ||
183 | unsigned int nsize = 0; | ||
184 | for (QStringList::ConstIterator it=mail.Inreply().begin(); | ||
185 | it != mail.Inreply().end();++it) { | ||
186 | /* yes! must be malloc! */ | ||
187 | if ((*it).isEmpty()) | ||
188 | continue; | ||
189 | QString h((*it)); | ||
190 | while (h.length()>0 && h[0]=='<') { | ||
191 | h.remove(0,1); | ||
192 | } | ||
193 | while (h.length()>0 && h[h.length()-1]=='>') { | ||
194 | h.remove(h.length()-1,1); | ||
195 | } | ||
196 | if (h.isEmpty()) continue; | ||
197 | nsize = strlen(h.latin1()); | ||
198 | c_reply = (char*)malloc( (nsize+1)*sizeof(char)); | ||
199 | memset(c_reply,0,nsize+1); | ||
200 | memcpy(c_reply,h.latin1(),nsize); | ||
201 | clist_append(in_reply_to,c_reply); | ||
202 | qDebug("In reply to: %s",c_reply); | ||
203 | } | ||
204 | } | ||
205 | |||
206 | fields = mailimf_fields_new_with_data( from, sender, reply, to, cc, bcc, | ||
207 | in_reply_to, NULL, subject ); | ||
208 | if ( fields == NULL ) | ||
209 | goto err_free_reply; | ||
210 | |||
211 | xmailer = mailimf_field_new_custom( strdup( "User-Agent" ), | ||
212 | strdup( USER_AGENT ) ); | ||
213 | if ( xmailer == NULL ) | ||
214 | goto err_free_fields; | ||
215 | |||
216 | err = mailimf_fields_add( fields, xmailer ); | ||
217 | if ( err != MAILIMF_NO_ERROR ) | ||
218 | goto err_free_xmailer; | ||
219 | |||
220 | return fields; // Success :) | ||
221 | |||
222 | err_free_xmailer: | ||
223 | if (xmailer) | ||
224 | mailimf_field_free( xmailer ); | ||
225 | err_free_fields: | ||
226 | if (fields) | ||
227 | mailimf_fields_free( fields ); | ||
228 | err_free_reply: | ||
229 | if (reply) | ||
230 | mailimf_address_list_free( reply ); | ||
231 | if (bcc) | ||
232 | mailimf_address_list_free( bcc ); | ||
233 | if (cc) | ||
234 | mailimf_address_list_free( cc ); | ||
235 | if (to) | ||
236 | mailimf_address_list_free( to ); | ||
237 | err_free_from: | ||
238 | if (from) | ||
239 | mailimf_mailbox_list_free( from ); | ||
240 | err_free_fromBox: | ||
241 | mailimf_mailbox_free( fromBox ); | ||
242 | err_free_sender: | ||
243 | if (sender) | ||
244 | mailimf_mailbox_free( sender ); | ||
245 | err_free: | ||
246 | if (subject) | ||
247 | free( subject ); | ||
248 | qDebug( "createImfFields - error" ); | ||
249 | |||
250 | return NULL; // Error :( | ||
251 | } | ||
252 | |||
253 | mailmime *SMTPwrapper::buildTxtPart(const QString&str ) { | ||
254 | mailmime *txtPart; | ||
255 | mailmime_fields *fields; | ||
256 | mailmime_content *content; | ||
257 | mailmime_parameter *param; | ||
258 | int err; | ||
259 | |||
260 | param = mailmime_parameter_new( strdup( "charset" ), | ||
261 | strdup( "iso-8859-1" ) ); | ||
262 | if ( param == NULL ) | ||
263 | goto err_free; | ||
264 | |||
265 | content = mailmime_content_new_with_str( "text/plain" ); | ||
266 | if ( content == NULL ) | ||
267 | goto err_free_param; | ||
268 | |||
269 | err = clist_append( content->ct_parameters, param ); | ||
270 | if ( err != MAILIMF_NO_ERROR ) | ||
271 | goto err_free_content; | ||
272 | |||
273 | fields = mailmime_fields_new_encoding(MAILMIME_MECHANISM_8BIT); | ||
274 | if ( fields == NULL ) | ||
275 | goto err_free_content; | ||
276 | |||
277 | txtPart = mailmime_new_empty( content, fields ); | ||
278 | if ( txtPart == NULL ) | ||
279 | goto err_free_fields; | ||
280 | |||
281 | err = mailmime_set_body_text( txtPart, (char*)str.data(), str.length() ); | ||
282 | if ( err != MAILIMF_NO_ERROR ) | ||
283 | goto err_free_txtPart; | ||
284 | |||
285 | return txtPart; // Success :) | ||
286 | |||
287 | err_free_txtPart: | ||
288 | mailmime_free( txtPart ); | ||
289 | err_free_fields: | ||
290 | mailmime_fields_free( fields ); | ||
291 | err_free_content: | ||
292 | mailmime_content_free( content ); | ||
293 | err_free_param: | ||
294 | mailmime_parameter_free( param ); | ||
295 | err_free: | ||
296 | qDebug( "buildTxtPart - error" ); | ||
297 | |||
298 | return NULL; // Error :( | ||
299 | } | ||
300 | |||
301 | mailmime *SMTPwrapper::buildFilePart(const QString&filename,const QString&mimetype,const QString&TextContent ) { | ||
302 | mailmime * filePart = 0; | ||
303 | mailmime_fields * fields = 0; | ||
304 | mailmime_content * content = 0; | ||
305 | mailmime_parameter * param = 0; | ||
306 | char*name = 0; | ||
307 | char*file = 0; | ||
308 | int err; | ||
309 | |||
310 | int pos = filename.findRev( '/' ); | ||
311 | |||
312 | if (filename.length()>0) { | ||
313 | QString tmp = filename.right( filename.length() - ( pos + 1 ) ); | ||
314 | name = strdup( tmp.latin1() ); // just filename | ||
315 | file = strdup( filename.latin1() ); // full name with path | ||
316 | } | ||
317 | |||
318 | int disptype = MAILMIME_DISPOSITION_TYPE_ATTACHMENT; | ||
319 | int mechanism = MAILMIME_MECHANISM_BASE64; | ||
320 | |||
321 | if ( mimetype.startsWith( "text/" ) ) { | ||
322 | param = mailmime_parameter_new( strdup( "charset" ), | ||
323 | strdup( "iso-8859-1" ) ); | ||
324 | mechanism = MAILMIME_MECHANISM_QUOTED_PRINTABLE; | ||
325 | } | ||
326 | |||
327 | fields = mailmime_fields_new_filename( | ||
328 | disptype, name, | ||
329 | mechanism ); | ||
330 | content = mailmime_content_new_with_str( (char*)mimetype.latin1() ); | ||
331 | if (content!=0 && fields != 0) { | ||
332 | if (param) { | ||
333 | clist_append(content->ct_parameters,param); | ||
334 | param = 0; | ||
335 | } | ||
336 | if (filename.length()>0) { | ||
337 | QFileInfo f(filename); | ||
338 | param = mailmime_parameter_new(strdup("name"),strdup(f.fileName().latin1())); | ||
339 | clist_append(content->ct_parameters,param); | ||
340 | param = 0; | ||
341 | } | ||
342 | filePart = mailmime_new_empty( content, fields ); | ||
343 | } | ||
344 | if (filePart) { | ||
345 | if (filename.length()>0) { | ||
346 | err = mailmime_set_body_file( filePart, file ); | ||
347 | } else { | ||
348 | err = mailmime_set_body_text(filePart,strdup(TextContent.data()),TextContent.length()); | ||
349 | } | ||
350 | if (err != MAILIMF_NO_ERROR) { | ||
351 | qDebug("Error setting body with file %s",file); | ||
352 | mailmime_free( filePart ); | ||
353 | filePart = 0; | ||
354 | } | ||
355 | } | ||
356 | |||
357 | if (!filePart) { | ||
358 | if ( param != NULL ) { | ||
359 | mailmime_parameter_free( param ); | ||
360 | } | ||
361 | if (content) { | ||
362 | mailmime_content_free( content ); | ||
363 | } | ||
364 | if (fields) { | ||
365 | mailmime_fields_free( fields ); | ||
366 | } else { | ||
367 | if (name) { | ||
368 | free( name ); | ||
369 | } | ||
370 | if (file) { | ||
371 | free( file ); | ||
372 | } | ||
373 | } | ||
374 | } | ||
375 | return filePart; // Success :) | ||
376 | |||
377 | } | ||
378 | |||
379 | void SMTPwrapper::addFileParts( mailmime *message,const QList<Attachment>&files ) { | ||
380 | const Attachment *it; | ||
381 | unsigned int count = files.count(); | ||
382 | qDebug("List contains %i values",count); | ||
383 | for ( unsigned int i = 0; i < count; ++i ) { | ||
384 | qDebug( "Adding file" ); | ||
385 | mailmime *filePart; | ||
386 | int err; | ||
387 | it = ((QList<Attachment>)files).at(i); | ||
388 | |||
389 | filePart = buildFilePart( it->getFileName(), it->getMimeType(),"" ); | ||
390 | if ( filePart == NULL ) { | ||
391 | qDebug( "addFileParts: error adding file:" ); | ||
392 | qDebug( it->getFileName() ); | ||
393 | continue; | ||
394 | } | ||
395 | err = mailmime_smart_add_part( message, filePart ); | ||
396 | if ( err != MAILIMF_NO_ERROR ) { | ||
397 | mailmime_free( filePart ); | ||
398 | qDebug("error smart add"); | ||
399 | } | ||
400 | } | ||
401 | } | ||
402 | |||
403 | mailmime *SMTPwrapper::createMimeMail(const Mail &mail ) { | ||
404 | mailmime *message, *txtPart; | ||
405 | mailimf_fields *fields; | ||
406 | int err; | ||
407 | |||
408 | fields = createImfFields( mail ); | ||
409 | if ( fields == NULL ) | ||
410 | goto err_free; | ||
411 | |||
412 | message = mailmime_new_message_data( NULL ); | ||
413 | if ( message == NULL ) | ||
414 | goto err_free_fields; | ||
415 | |||
416 | mailmime_set_imf_fields( message, fields ); | ||
417 | |||
418 | txtPart = buildTxtPart( mail.getMessage() ); | ||
419 | |||
420 | if ( txtPart == NULL ) | ||
421 | goto err_free_message; | ||
422 | |||
423 | err = mailmime_smart_add_part( message, txtPart ); | ||
424 | if ( err != MAILIMF_NO_ERROR ) | ||
425 | goto err_free_txtPart; | ||
426 | |||
427 | addFileParts( message, mail.getAttachments() ); | ||
428 | |||
429 | return message; // Success :) | ||
430 | |||
431 | err_free_txtPart: | ||
432 | mailmime_free( txtPart ); | ||
433 | err_free_message: | ||
434 | mailmime_free( message ); | ||
435 | err_free_fields: | ||
436 | mailimf_fields_free( fields ); | ||
437 | err_free: | ||
438 | qDebug( "createMimeMail: error" ); | ||
439 | |||
440 | return NULL; // Error :( | ||
441 | } | ||
442 | |||
443 | mailimf_field *SMTPwrapper::getField( mailimf_fields *fields, int type ) { | ||
444 | mailimf_field *field; | ||
445 | clistiter *it; | ||
446 | |||
447 | it = clist_begin( fields->fld_list ); | ||
448 | while ( it ) { | ||
449 | field = (mailimf_field *) it->data; | ||
450 | if ( field->fld_type == type ) { | ||
451 | return field; | ||
452 | } | ||
453 | it = it->next; | ||
454 | } | ||
455 | |||
456 | return NULL; | ||
457 | } | ||
458 | |||
459 | void SMTPwrapper::addRcpts( clist *list, mailimf_address_list *addr_list ) { | ||
460 | clistiter *it, *it2; | ||
461 | |||
462 | for ( it = clist_begin( addr_list->ad_list ); it; it = it->next ) { | ||
463 | mailimf_address *addr; | ||
464 | addr = (mailimf_address *) it->data; | ||
465 | |||
466 | if ( addr->ad_type == MAILIMF_ADDRESS_MAILBOX ) { | ||
467 | esmtp_address_list_add( list, addr->ad_data.ad_mailbox->mb_addr_spec, 0, NULL ); | ||
468 | } else if ( addr->ad_type == MAILIMF_ADDRESS_GROUP ) { | ||
469 | clist *l = addr->ad_data.ad_group->grp_mb_list->mb_list; | ||
470 | for ( it2 = clist_begin( l ); it2; it2 = it2->next ) { | ||
471 | mailimf_mailbox *mbox; | ||
472 | mbox = (mailimf_mailbox *) it2->data; | ||
473 | esmtp_address_list_add( list, mbox->mb_addr_spec, 0, NULL ); | ||
474 | } | ||
475 | } | ||
476 | } | ||
477 | } | ||
478 | |||
479 | clist *SMTPwrapper::createRcptList( mailimf_fields *fields ) { | ||
480 | clist *rcptList; | ||
481 | mailimf_field *field; | ||
482 | |||
483 | rcptList = esmtp_address_list_new(); | ||
484 | |||
485 | field = getField( fields, MAILIMF_FIELD_TO ); | ||
486 | if ( field && (field->fld_type == MAILIMF_FIELD_TO) | ||
487 | && field->fld_data.fld_to->to_addr_list ) { | ||
488 | addRcpts( rcptList, field->fld_data.fld_to->to_addr_list ); | ||
489 | } | ||
490 | |||
491 | field = getField( fields, MAILIMF_FIELD_CC ); | ||
492 | if ( field && (field->fld_type == MAILIMF_FIELD_CC) | ||
493 | && field->fld_data.fld_cc->cc_addr_list ) { | ||
494 | addRcpts( rcptList, field->fld_data.fld_cc->cc_addr_list ); | ||
495 | } | ||
496 | |||
497 | field = getField( fields, MAILIMF_FIELD_BCC ); | ||
498 | if ( field && (field->fld_type == MAILIMF_FIELD_BCC) | ||
499 | && field->fld_data.fld_bcc->bcc_addr_list ) { | ||
500 | addRcpts( rcptList, field->fld_data.fld_bcc->bcc_addr_list ); | ||
501 | } | ||
502 | |||
503 | return rcptList; | ||
504 | } | ||
505 | |||
506 | char *SMTPwrapper::getFrom( mailimf_field *ffrom) { | ||
507 | char *from = NULL; | ||
508 | if ( ffrom && (ffrom->fld_type == MAILIMF_FIELD_FROM) | ||
509 | && ffrom->fld_data.fld_from->frm_mb_list && ffrom->fld_data.fld_from->frm_mb_list->mb_list ) { | ||
510 | clist *cl = ffrom->fld_data.fld_from->frm_mb_list->mb_list; | ||
511 | clistiter *it; | ||
512 | for ( it = clist_begin( cl ); it; it = it->next ) { | ||
513 | mailimf_mailbox *mb = (mailimf_mailbox *) it->data; | ||
514 | from = strdup( mb->mb_addr_spec ); | ||
515 | } | ||
516 | } | ||
517 | |||
518 | return from; | ||
519 | } | ||
520 | |||
521 | char *SMTPwrapper::getFrom( mailmime *mail ) { | ||
522 | /* no need to delete - its just a pointer to structure content */ | ||
523 | mailimf_field *ffrom = 0; | ||
524 | ffrom = getField( mail->mm_data.mm_message.mm_fields, MAILIMF_FIELD_FROM ); | ||
525 | return getFrom(ffrom); | ||
526 | } | ||
527 | 83 | ||
528 | void SMTPwrapper::progress( size_t current, size_t maximum ) { | 84 | void SMTPwrapper::progress( size_t current, size_t maximum ) { |
529 | if (SMTPwrapper::sendProgress) { | 85 | if (SMTPwrapper::sendProgress) { |
530 | SMTPwrapper::sendProgress->setSingleMail(current, maximum ); | 86 | SMTPwrapper::sendProgress->setSingleMail(current, maximum ); |
531 | qApp->processEvents(); | 87 | qApp->processEvents(); |
532 | } | 88 | } |
533 | } | 89 | } |
534 | 90 | ||
535 | void SMTPwrapper::storeMail(const char*mail, size_t length, const QString&box) { | 91 | void SMTPwrapper::storeMail(const char*mail, size_t length, const QString&box) { |
536 | if (!mail) | 92 | if (!mail) |
537 | return; | 93 | return; |
538 | QString localfolders = AbstractMail::defaultLocalfolder(); | 94 | QString localfolders = AbstractMail::defaultLocalfolder(); |
@@ -620,25 +176,25 @@ int SMTPwrapper::start_smtp_tls() | |||
620 | } | 176 | } |
621 | 177 | ||
622 | void SMTPwrapper::connect_server() | 178 | void SMTPwrapper::connect_server() |
623 | { | 179 | { |
624 | const char *server, *user, *pass; | 180 | const char *server, *user, *pass; |
625 | bool ssl; | 181 | bool ssl; |
626 | uint16_t port; | 182 | uint16_t port; |
627 | ssl = false; | 183 | ssl = false; |
628 | bool try_tls = true; | 184 | bool try_tls = true; |
629 | bool force_tls=false; | 185 | bool force_tls=false; |
630 | server = user = pass = 0; | 186 | server = user = pass = 0; |
631 | QString failuretext = ""; | 187 | QString failuretext = ""; |
632 | 188 | ||
633 | if (m_smtp || !m_SmtpAccount) { | 189 | if (m_smtp || !m_SmtpAccount) { |
634 | return; | 190 | return; |
635 | } | 191 | } |
636 | server = m_SmtpAccount->getServer().latin1(); | 192 | server = m_SmtpAccount->getServer().latin1(); |
637 | if ( m_SmtpAccount->ConnectionType() == 2 ) { | 193 | if ( m_SmtpAccount->ConnectionType() == 2 ) { |
638 | ssl = true; | 194 | ssl = true; |
639 | try_tls = false; | 195 | try_tls = false; |
640 | } else if (m_SmtpAccount->ConnectionType() == 1) { | 196 | } else if (m_SmtpAccount->ConnectionType() == 1) { |
641 | force_tls = true; | 197 | force_tls = true; |
642 | } | 198 | } |
643 | int result = 1; | 199 | int result = 1; |
644 | port = m_SmtpAccount->getPort().toUInt(); | 200 | port = m_SmtpAccount->getPort().toUInt(); |
@@ -683,25 +239,25 @@ void SMTPwrapper::connect_server() | |||
683 | } | 239 | } |
684 | } | 240 | } |
685 | 241 | ||
686 | if (!try_tls && force_tls) { | 242 | if (!try_tls && force_tls) { |
687 | result = 0; | 243 | result = 0; |
688 | failuretext = tr("Error init SMTP tls: %1").arg(mailsmtpError(err)); | 244 | failuretext = tr("Error init SMTP tls: %1").arg(mailsmtpError(err)); |
689 | } | 245 | } |
690 | 246 | ||
691 | if (result==1 && m_SmtpAccount->getLogin() ) { | 247 | if (result==1 && m_SmtpAccount->getLogin() ) { |
692 | qDebug("smtp with auth"); | 248 | qDebug("smtp with auth"); |
693 | if ( m_SmtpAccount->getUser().isEmpty() || m_SmtpAccount->getPassword().isEmpty() ) { | 249 | if ( m_SmtpAccount->getUser().isEmpty() || m_SmtpAccount->getPassword().isEmpty() ) { |
694 | // get'em | 250 | // get'em |
695 | LoginDialog login( m_SmtpAccount->getUser(), | 251 | LoginDialog login( m_SmtpAccount->getUser(), |
696 | m_SmtpAccount->getPassword(), NULL, 0, true ); | 252 | m_SmtpAccount->getPassword(), NULL, 0, true ); |
697 | login.show(); | 253 | login.show(); |
698 | if ( QDialog::Accepted == login.exec() ) { | 254 | if ( QDialog::Accepted == login.exec() ) { |
699 | // ok | 255 | // ok |
700 | user = login.getUser().latin1(); | 256 | user = login.getUser().latin1(); |
701 | pass = login.getPassword().latin1(); | 257 | pass = login.getPassword().latin1(); |
702 | } else { | 258 | } else { |
703 | result = 0; | 259 | result = 0; |
704 | failuretext=tr("Login aborted - storing mail to localfolder"); | 260 | failuretext=tr("Login aborted - storing mail to localfolder"); |
705 | } | 261 | } |
706 | } else { | 262 | } else { |
707 | user = m_SmtpAccount->getUser().latin1(); | 263 | user = m_SmtpAccount->getUser().latin1(); |