summaryrefslogtreecommitdiff
path: root/noncore/net/mail/libmailwrapper/mailwrapper.cpp
Unidiff
Diffstat (limited to 'noncore/net/mail/libmailwrapper/mailwrapper.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/libmailwrapper/mailwrapper.cpp156
1 files changed, 78 insertions, 78 deletions
diff --git a/noncore/net/mail/libmailwrapper/mailwrapper.cpp b/noncore/net/mail/libmailwrapper/mailwrapper.cpp
index 17bed65..13a3fd9 100644
--- a/noncore/net/mail/libmailwrapper/mailwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/mailwrapper.cpp
@@ -9,31 +9,31 @@
9#include <qtextstream.h> 9#include <qtextstream.h>
10 10
11#include "mailwrapper.h" 11#include "mailwrapper.h"
12#include "logindialog.h" 12#include "logindialog.h"
13#include "mail.h" 13//#include "mail.h"
14#include "defines.h" 14#include "defines.h"
15 15
16Attachment::Attachment( DocLnk lnk ) 16Attachment::Attachment( DocLnk lnk )
17{ 17{
18 doc = lnk; 18 doc = lnk;
19 size = QFileInfo( doc.file() ).size(); 19 size = QFileInfo( doc.file() ).size();
20} 20}
21 21
22Folder::Folder(const QString&tmp_name ) 22Folder::Folder(const QString&tmp_name )
23{ 23{
24 name = tmp_name; 24 name = tmp_name;
25 nameDisplay = name; 25 nameDisplay = name;
26 26
27 for ( int pos = nameDisplay.find( '&' ); pos != -1; 27 for ( int pos = nameDisplay.find( '&' ); pos != -1;
28 pos = nameDisplay.find( '&' ) ) { 28 pos = nameDisplay.find( '&' ) ) {
29 int end = nameDisplay.find( '-' ); 29 int end = nameDisplay.find( '-' );
30 if ( end == -1 || end <= pos ) break; 30 if ( end == -1 || end <= pos ) break;
31 QString str64 = nameDisplay.mid( pos + 1, end - pos - 1 ); 31 QString str64 = nameDisplay.mid( pos + 1, end - pos - 1 );
32 // TODO: do real base64 decoding here ! 32 // TODO: do real base64 decoding here !
33 if ( str64.compare( "APw" ) == 0 ) { 33 if ( str64.compare( "APw" ) == 0 ) {
34 nameDisplay = nameDisplay.replace( pos, end - pos + 1, "ue" ); 34 nameDisplay = nameDisplay.replace( pos, end - pos + 1, "ue" );
35 } else if ( str64.compare( "APY" ) == 0 ) { 35 } else if ( str64.compare( "APY" ) == 0 ) {
36 nameDisplay = nameDisplay.replace( pos, end - pos + 1, "oe" ); 36 nameDisplay = nameDisplay.replace( pos, end - pos + 1, "oe" );
37 } 37 }
38 } 38 }
39 39
@@ -89,20 +89,20 @@ QString MailWrapper::mailsmtpError( int errnum )
89} 89}
90 90
91mailimf_mailbox *MailWrapper::newMailbox(const QString&name, const QString&mail ) 91mailimf_mailbox *MailWrapper::newMailbox(const QString&name, const QString&mail )
92{ 92{
93 return mailimf_mailbox_new( strdup( name.latin1() ), 93 return mailimf_mailbox_new( strdup( name.latin1() ),
94 strdup( mail.latin1() ) ); 94 strdup( mail.latin1() ) );
95} 95}
96 96
97mailimf_address_list *MailWrapper::parseAddresses(const QString&addr ) 97mailimf_address_list *MailWrapper::parseAddresses(const QString&addr )
98{ 98{
99 mailimf_address_list *addresses; 99 mailimf_address_list *addresses;
100 100
101 if ( addr.isEmpty() ) return NULL; 101 if ( addr.isEmpty() ) return NULL;
102 102
103 addresses = mailimf_address_list_new_empty(); 103 addresses = mailimf_address_list_new_empty();
104 104
105 QStringList list = QStringList::split( ',', addr ); 105 QStringList list = QStringList::split( ',', addr );
106 QStringList::Iterator it; 106 QStringList::Iterator it;
107 for ( it = list.begin(); it != list.end(); it++ ) { 107 for ( it = list.begin(); it != list.end(); it++ ) {
108 char *str = strdup( (*it).latin1() ); 108 char *str = strdup( (*it).latin1() );
@@ -114,9 +114,9 @@ mailimf_address_list *MailWrapper::parseAddresses(const QString&addr )
114 } else { 114 } else {
115 qDebug( "Parse success! :)" ); 115 qDebug( "Parse success! :)" );
116 } 116 }
117 } 117 }
118 118
119 return addresses; 119 return addresses;
120} 120}
121 121
122mailimf_fields *MailWrapper::createImfFields( Mail *mail ) 122mailimf_fields *MailWrapper::createImfFields( Mail *mail )
@@ -127,21 +127,21 @@ mailimf_fields *MailWrapper::createImfFields( Mail *mail )
127 mailimf_mailbox_list *from; 127 mailimf_mailbox_list *from;
128 mailimf_address_list *to, *cc, *bcc, *reply; 128 mailimf_address_list *to, *cc, *bcc, *reply;
129 char *subject = strdup( mail->getSubject().latin1() ); 129 char *subject = strdup( mail->getSubject().latin1() );
130 int err; 130 int err;
131 131
132 sender = newMailbox( mail->getName(), mail->getMail() ); 132 sender = newMailbox( mail->getName(), mail->getMail() );
133 if ( sender == NULL ) goto err_free; 133 if ( sender == NULL ) goto err_free;
134 134
135 fromBox = newMailbox( mail->getName(), mail->getMail() ); 135 fromBox = newMailbox( mail->getName(), mail->getMail() );
136 if ( fromBox == NULL ) goto err_free_sender; 136 if ( fromBox == NULL ) goto err_free_sender;
137 137
138 from = mailimf_mailbox_list_new_empty(); 138 from = mailimf_mailbox_list_new_empty();
139 if ( from == NULL ) goto err_free_fromBox; 139 if ( from == NULL ) goto err_free_fromBox;
140 140
141 err = mailimf_mailbox_list_add( from, fromBox ); 141 err = mailimf_mailbox_list_add( from, fromBox );
142 if ( err != MAILIMF_NO_ERROR ) goto err_free_from; 142 if ( err != MAILIMF_NO_ERROR ) goto err_free_from;
143 143
144 to = parseAddresses( mail->getTo() ); 144 to = parseAddresses( mail->getTo() );
145 if ( to == NULL ) goto err_free_from; 145 if ( to == NULL ) goto err_free_from;
146 146
147 cc = parseAddresses( mail->getCC() ); 147 cc = parseAddresses( mail->getCC() );
@@ -150,16 +150,16 @@ mailimf_fields *MailWrapper::createImfFields( Mail *mail )
150 150
151 fields = mailimf_fields_new_with_data( from, sender, reply, to, cc, bcc, 151 fields = mailimf_fields_new_with_data( from, sender, reply, to, cc, bcc,
152 NULL, NULL, subject ); 152 NULL, NULL, subject );
153 if ( fields == NULL ) goto err_free_reply; 153 if ( fields == NULL ) goto err_free_reply;
154 154
155 xmailer = mailimf_field_new_custom( strdup( "User-Agent" ), 155 xmailer = mailimf_field_new_custom( strdup( "User-Agent" ),
156 strdup( USER_AGENT ) ); 156 strdup( USER_AGENT ) );
157 if ( xmailer == NULL ) goto err_free_fields; 157 if ( xmailer == NULL ) goto err_free_fields;
158 158
159 err = mailimf_fields_add( fields, xmailer ); 159 err = mailimf_fields_add( fields, xmailer );
160 if ( err != MAILIMF_NO_ERROR ) goto err_free_xmailer; 160 if ( err != MAILIMF_NO_ERROR ) goto err_free_xmailer;
161 161
162 return fields; // Success :) 162 return fields; // Success :)
163 163
164err_free_xmailer: 164err_free_xmailer:
165 mailimf_field_free( xmailer ); 165 mailimf_field_free( xmailer );
@@ -190,42 +190,42 @@ mailmime *MailWrapper::buildTxtPart( QString str )
190 mailmime_content *content; 190 mailmime_content *content;
191 mailmime_parameter *param; 191 mailmime_parameter *param;
192 char *txt = strdup( str.latin1() ); 192 char *txt = strdup( str.latin1() );
193 int err; 193 int err;
194 194
195 param = mailmime_parameter_new( strdup( "charset" ), 195 param = mailmime_parameter_new( strdup( "charset" ),
196 strdup( "iso-8859-1" ) ); 196 strdup( "iso-8859-1" ) );
197 if ( param == NULL ) goto err_free; 197 if ( param == NULL ) goto err_free;
198 198
199 content = mailmime_content_new_with_str( "text/plain" ); 199 content = mailmime_content_new_with_str( "text/plain" );
200 if ( content == NULL ) goto err_free_param; 200 if ( content == NULL ) goto err_free_param;
201 201
202 err = clist_append( content->parameters, param ); 202 err = clist_append( content->parameters, param );
203 if ( err != MAILIMF_NO_ERROR ) goto err_free_content; 203 if ( err != MAILIMF_NO_ERROR ) goto err_free_content;
204 204
205 fields = mailmime_fields_new_encoding( MAILMIME_MECHANISM_8BIT ); 205 fields = mailmime_fields_new_encoding( MAILMIME_MECHANISM_8BIT );
206 if ( fields == NULL ) goto err_free_content; 206 if ( fields == NULL ) goto err_free_content;
207 207
208 txtPart = mailmime_new_empty( content, fields ); 208 txtPart = mailmime_new_empty( content, fields );
209 if ( txtPart == NULL ) goto err_free_fields; 209 if ( txtPart == NULL ) goto err_free_fields;
210 210
211 err = mailmime_set_body_text( txtPart, txt, strlen( txt ) ); 211 err = mailmime_set_body_text( txtPart, txt, strlen( txt ) );
212 if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; 212 if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart;
213 213
214 return txtPart; // Success :) 214 return txtPart; // Success :)
215 215
216err_free_txtPart: 216err_free_txtPart:
217 mailmime_free( txtPart ); 217 mailmime_free( txtPart );
218err_free_fields: 218err_free_fields:
219 mailmime_fields_free( fields ); 219 mailmime_fields_free( fields );
220err_free_content: 220err_free_content:
221 mailmime_content_free( content ); 221 mailmime_content_free( content );
222err_free_param: 222err_free_param:
223 mailmime_parameter_free( param ); 223 mailmime_parameter_free( param );
224err_free: 224err_free:
225 free( txt ); 225 free( txt );
226 qDebug( "buildTxtPart - error" ); 226 qDebug( "buildTxtPart - error" );
227 227
228 return NULL; // Error :( 228 return NULL; // Error :(
229} 229}
230 230
231mailmime *MailWrapper::buildFilePart( QString filename, QString mimetype ) 231mailmime *MailWrapper::buildFilePart( QString filename, QString mimetype )
@@ -234,38 +234,38 @@ mailmime *MailWrapper::buildFilePart( QString filename, QString mimetype )
234 mailmime_fields * fields; 234 mailmime_fields * fields;
235 mailmime_content * content; 235 mailmime_content * content;
236 mailmime_parameter * param = NULL; 236 mailmime_parameter * param = NULL;
237 int err; 237 int err;
238 238
239 int pos = filename.findRev( '/' ); 239 int pos = filename.findRev( '/' );
240 QString tmp = filename.right( filename.length() - ( pos + 1 ) ); 240 QString tmp = filename.right( filename.length() - ( pos + 1 ) );
241 char *name = strdup( tmp.latin1() ); // just filename 241 char *name = strdup( tmp.latin1() ); // just filename
242 char *file = strdup( filename.latin1() ); // full name with path 242 char *file = strdup( filename.latin1() ); // full name with path
243 char *mime = strdup( mimetype.latin1() ); // mimetype -e.g. text/plain 243 char *mime = strdup( mimetype.latin1() ); // mimetype -e.g. text/plain
244 244
245 fields = mailmime_fields_new_filename( 245 fields = mailmime_fields_new_filename(
246 MAILMIME_DISPOSITION_TYPE_ATTACHMENT, name, 246 MAILMIME_DISPOSITION_TYPE_ATTACHMENT, name,
247 MAILMIME_MECHANISM_BASE64 ); 247 MAILMIME_MECHANISM_BASE64 );
248 if ( fields == NULL ) goto err_free; 248 if ( fields == NULL ) goto err_free;
249 249
250 content = mailmime_content_new_with_str( mime ); 250 content = mailmime_content_new_with_str( mime );
251 if ( content == NULL ) goto err_free_fields; 251 if ( content == NULL ) goto err_free_fields;
252 252
253 if ( mimetype.compare( "text/plain" ) == 0 ) { 253 if ( mimetype.compare( "text/plain" ) == 0 ) {
254 param = mailmime_parameter_new( strdup( "charset" ), 254 param = mailmime_parameter_new( strdup( "charset" ),
255 strdup( "iso-8859-1" ) ); 255 strdup( "iso-8859-1" ) );
256 if ( param == NULL ) goto err_free_content; 256 if ( param == NULL ) goto err_free_content;
257 257
258 err = clist_append( content->parameters, param ); 258 err = clist_append( content->parameters, param );
259 if ( err != MAILIMF_NO_ERROR ) goto err_free_param; 259 if ( err != MAILIMF_NO_ERROR ) goto err_free_param;
260 } 260 }
261 261
262 filePart = mailmime_new_empty( content, fields ); 262 filePart = mailmime_new_empty( content, fields );
263 if ( filePart == NULL ) goto err_free_param; 263 if ( filePart == NULL ) goto err_free_param;
264 264
265 err = mailmime_set_body_file( filePart, file ); 265 err = mailmime_set_body_file( filePart, file );
266 if ( err != MAILIMF_NO_ERROR ) goto err_free_filePart; 266 if ( err != MAILIMF_NO_ERROR ) goto err_free_filePart;
267 267
268 return filePart; // Success :) 268 return filePart; // Success :)
269 269
270err_free_filePart: 270err_free_filePart:
271 mailmime_free( filePart ); 271 mailmime_free( filePart );
@@ -279,28 +279,28 @@ err_free:
279 free( name ); 279 free( name );
280 free( mime ); 280 free( mime );
281 free( file ); 281 free( file );
282 qDebug( "buildFilePart - error" ); 282 qDebug( "buildFilePart - error" );
283 283
284 return NULL; // Error :( 284 return NULL; // Error :(
285} 285}
286 286
287void MailWrapper::addFileParts( mailmime *message, QList<Attachment> files ) 287void MailWrapper::addFileParts( mailmime *message, QList<Attachment> files )
288{ 288{
289 Attachment *it; 289 Attachment *it;
290 for ( it = files.first(); it; it = files.next() ) { 290 for ( it = files.first(); it; it = files.next() ) {
291 qDebug( "Adding file" ); 291 qDebug( "Adding file" );
292 mailmime *filePart; 292 mailmime *filePart;
293 int err; 293 int err;
294 294
295 filePart = buildFilePart( it->getFileName(), it->getMimeType() ); 295 filePart = buildFilePart( it->getFileName(), it->getMimeType() );
296 if ( filePart == NULL ) goto err_free; 296 if ( filePart == NULL ) goto err_free;
297 297
298 err = mailmime_smart_add_part( message, filePart ); 298 err = mailmime_smart_add_part( message, filePart );
299 if ( err != MAILIMF_NO_ERROR ) goto err_free_filePart; 299 if ( err != MAILIMF_NO_ERROR ) goto err_free_filePart;
300 300
301 continue; // Success :) 301 continue; // Success :)
302 302
303 err_free_filePart: 303 err_free_filePart:
304 mailmime_free( filePart ); 304 mailmime_free( filePart );
305 err_free: 305 err_free:
306 qDebug( "addFileParts: error adding file:" ); 306 qDebug( "addFileParts: error adding file:" );
@@ -315,20 +315,20 @@ mailmime *MailWrapper::createMimeMail( Mail *mail )
315 int err; 315 int err;
316 316
317 fields = createImfFields( mail ); 317 fields = createImfFields( mail );
318 if ( fields == NULL ) goto err_free; 318 if ( fields == NULL ) goto err_free;
319 319
320 message = mailmime_new_message_data( NULL ); 320 message = mailmime_new_message_data( NULL );
321 if ( message == NULL ) goto err_free_fields; 321 if ( message == NULL ) goto err_free_fields;
322 322
323 mailmime_set_imf_fields( message, fields ); 323 mailmime_set_imf_fields( message, fields );
324 324
325 txtPart = buildTxtPart( mail->getMessage() ); 325 txtPart = buildTxtPart( mail->getMessage() );
326 if ( txtPart == NULL ) goto err_free_message; 326 if ( txtPart == NULL ) goto err_free_message;
327 327
328 err = mailmime_smart_add_part( message, txtPart ); 328 err = mailmime_smart_add_part( message, txtPart );
329 if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; 329 if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart;
330 330
331 addFileParts( message, mail->getAttachments() ); 331 addFileParts( message, mail->getAttachments() );
332 332
333 return message; // Success :) 333 return message; // Success :)
334 334
@@ -356,20 +356,20 @@ mailimf_field *MailWrapper::getField( mailimf_fields *fields, int type )
356 return field; 356 return field;
357 } 357 }
358 it = it->next; 358 it = it->next;
359 } 359 }
360 360
361 return NULL; 361 return NULL;
362} 362}
363 363
364static void addRcpts( clist *list, mailimf_address_list *addr_list ) 364static void addRcpts( clist *list, mailimf_address_list *addr_list )
365{ 365{
366 clistiter *it, *it2; 366 clistiter *it, *it2;
367 367
368 for ( it = clist_begin( addr_list->list ); it; it = it->next ) { 368 for ( it = clist_begin( addr_list->list ); it; it = it->next ) {
369 mailimf_address *addr; 369 mailimf_address *addr;
370 addr = (mailimf_address *) it->data; 370 addr = (mailimf_address *) it->data;
371 371
372 if ( addr->type == MAILIMF_ADDRESS_MAILBOX ) { 372 if ( addr->type == MAILIMF_ADDRESS_MAILBOX ) {
373 esmtp_address_list_add( list, addr->mailbox->addr_spec, 0, NULL ); 373 esmtp_address_list_add( list, addr->mailbox->addr_spec, 0, NULL );
374 } else if ( addr->type == MAILIMF_ADDRESS_GROUP ) { 374 } else if ( addr->type == MAILIMF_ADDRESS_GROUP ) {
375 clist *l = addr->group->mb_list->list; 375 clist *l = addr->group->mb_list->list;
@@ -387,23 +387,23 @@ clist *MailWrapper::createRcptList( mailimf_fields *fields )
387 clist *rcptList; 387 clist *rcptList;
388 mailimf_field *field; 388 mailimf_field *field;
389 389
390 rcptList = esmtp_address_list_new(); 390 rcptList = esmtp_address_list_new();
391 391
392 field = getField( fields, MAILIMF_FIELD_TO ); 392 field = getField( fields, MAILIMF_FIELD_TO );
393 if ( field && (field->type == MAILIMF_FIELD_TO) 393 if ( field && (field->type == MAILIMF_FIELD_TO)
394 && field->field.to->addr_list ) { 394 && field->field.to->addr_list ) {
395 addRcpts( rcptList, field->field.to->addr_list ); 395 addRcpts( rcptList, field->field.to->addr_list );
396 } 396 }
397 397
398 field = getField( fields, MAILIMF_FIELD_CC ); 398 field = getField( fields, MAILIMF_FIELD_CC );
399 if ( field && (field->type == MAILIMF_FIELD_CC) 399 if ( field && (field->type == MAILIMF_FIELD_CC)
400 && field->field.cc->addr_list ) { 400 && field->field.cc->addr_list ) {
401 addRcpts( rcptList, field->field.cc->addr_list ); 401 addRcpts( rcptList, field->field.cc->addr_list );
402 } 402 }
403 403
404 field = getField( fields, MAILIMF_FIELD_BCC ); 404 field = getField( fields, MAILIMF_FIELD_BCC );
405 if ( field && (field->type == MAILIMF_FIELD_BCC) 405 if ( field && (field->type == MAILIMF_FIELD_BCC)
406 && field->field.bcc->addr_list ) { 406 && field->field.bcc->addr_list ) {
407 addRcpts( rcptList, field->field.bcc->addr_list ); 407 addRcpts( rcptList, field->field.bcc->addr_list );
408 } 408 }
409 409
@@ -415,9 +415,9 @@ char *MailWrapper::getFrom( mailmime *mail )
415 char *from = NULL; 415 char *from = NULL;
416 416
417 mailimf_field *ffrom; 417 mailimf_field *ffrom;
418 ffrom = getField( mail->fields, MAILIMF_FIELD_FROM ); 418 ffrom = getField( mail->fields, MAILIMF_FIELD_FROM );
419 if ( ffrom && (ffrom->type == MAILIMF_FIELD_FROM) 419 if ( ffrom && (ffrom->type == MAILIMF_FIELD_FROM)
420 && ffrom->field.from->mb_list && ffrom->field.from->mb_list->list ) { 420 && ffrom->field.from->mb_list && ffrom->field.from->mb_list->list ) {
421 clist *cl = ffrom->field.from->mb_list->list; 421 clist *cl = ffrom->field.from->mb_list->list;
422 clistiter *it; 422 clistiter *it;
423 for ( it = clist_begin( cl ); it; it = it->next ) { 423 for ( it = clist_begin( cl ); it; it = it->next ) {
@@ -425,15 +425,15 @@ char *MailWrapper::getFrom( mailmime *mail )
425 from = strdup( mb->addr_spec ); 425 from = strdup( mb->addr_spec );
426 } 426 }
427 } 427 }
428 428
429 return from; 429 return from;
430} 430}
431 431
432SMTPaccount *MailWrapper::getAccount( QString from ) 432SMTPaccount *MailWrapper::getAccount( QString from )
433{ 433{
434 SMTPaccount *smtp; 434 SMTPaccount *smtp;
435 435
436 QList<Account> list = settings->getAccounts(); 436 QList<Account> list = settings->getAccounts();
437 Account *it; 437 Account *it;
438 for ( it = list.first(); it; it = list.next() ) { 438 for ( it = list.first(); it; it = list.next() ) {
439 if ( it->getType().compare( "SMTP" ) == 0 ) { 439 if ( it->getType().compare( "SMTP" ) == 0 ) {
@@ -444,24 +444,24 @@ SMTPaccount *MailWrapper::getAccount( QString from )
444 return smtp; 444 return smtp;
445 } 445 }
446 } 446 }
447 } 447 }
448 448
449 return NULL; 449 return NULL;
450} 450}
451 451
452QString MailWrapper::getTmpFile() { 452QString MailWrapper::getTmpFile() {
453 int num = 0; 453 int num = 0;
454 QString unique; 454 QString unique;
455 455
456 QDir dir( "/tmp" ); 456 QDir dir( "/tmp" );
457 QStringList::Iterator it; 457 QStringList::Iterator it;
458 458
459 QStringList list = dir.entryList( "opiemail-tmp-*" ); 459 QStringList list = dir.entryList( "opiemail-tmp-*" );
460 do { 460 do {
461 unique.setNum( num++ ); 461 unique.setNum( num++ );
462 } while ( list.contains( "opiemail-tmp-" + unique ) > 0 ); 462 } while ( list.contains( "opiemail-tmp-" + unique ) > 0 );
463 463
464 return "/tmp/opiemail-tmp-" + unique; 464 return "/tmp/opiemail-tmp-" + unique;
465} 465}
466 466
467void MailWrapper::writeToFile( QString file, mailmime *mail ) 467void MailWrapper::writeToFile( QString file, mailmime *mail )
@@ -489,15 +489,15 @@ void MailWrapper::readFromFile( QString file, char **data, size_t *size )
489{ 489{
490 char *buf; 490 char *buf;
491 struct stat st; 491 struct stat st;
492 int fd, count = 0, total = 0; 492 int fd, count = 0, total = 0;
493 493
494 fd = open( file.latin1(), O_RDONLY, 0 ); 494 fd = open( file.latin1(), O_RDONLY, 0 );
495 if ( fd == -1 ) return; 495 if ( fd == -1 ) return;
496 496
497 if ( fstat( fd, &st ) != 0 ) goto err_close; 497 if ( fstat( fd, &st ) != 0 ) goto err_close;
498 if ( !st.st_size ) goto err_close; 498 if ( !st.st_size ) goto err_close;
499 499
500 buf = (char *) malloc( st.st_size ); 500 buf = (char *) malloc( st.st_size );
501 if ( !buf ) goto err_close; 501 if ( !buf ) goto err_close;
502 502
503 while ( ( total < st.st_size ) && ( count >= 0 ) ) { 503 while ( ( total < st.st_size ) && ( count >= 0 ) ) {
@@ -507,13 +507,13 @@ void MailWrapper::readFromFile( QString file, char **data, size_t *size )
507 if ( count < 0 ) goto err_free; 507 if ( count < 0 ) goto err_free;
508 508
509 *data = buf; 509 *data = buf;
510 *size = st.st_size; 510 *size = st.st_size;
511 511
512 close( fd ); 512 close( fd );
513 513
514 return; // Success :) 514 return; // Success :)
515 515
516err_free: 516err_free:
517 free( buf ); 517 free( buf );
518err_close: 518err_close:
519 close( fd ); 519 close( fd );
@@ -532,9 +532,9 @@ void MailWrapper::smtpSend( mailmime *mail )
532 size_t size; 532 size_t size;
533 int err; 533 int err;
534 bool ssl; 534 bool ssl;
535 uint16_t port; 535 uint16_t port;
536 536
537 537
538 from = getFrom( mail ); 538 from = getFrom( mail );
539 SMTPaccount *smtp = getAccount( from ); 539 SMTPaccount *smtp = getAccount( from );
540 if ( smtp == NULL ) { 540 if ( smtp == NULL ) {
@@ -550,11 +550,11 @@ void MailWrapper::smtpSend( mailmime *mail )
550 writeToFile( file, mail ); 550 writeToFile( file, mail );
551 readFromFile( file, &data, &size ); 551 readFromFile( file, &data, &size );
552 QFile f( file ); 552 QFile f( file );
553 f.remove(); 553 f.remove();
554 554
555 session = mailsmtp_new( 20, &progress ); 555 session = mailsmtp_new( 20, &progress );
556 if ( session == NULL ) goto free_mem; 556 if ( session == NULL ) goto free_mem;
557 557
558 qDebug( "Servername %s at port %i", server, port ); 558 qDebug( "Servername %s at port %i", server, port );
559 if ( ssl ) { 559 if ( ssl ) {
560 qDebug( "SSL session" ); 560 qDebug( "SSL session" );
@@ -566,11 +566,11 @@ void MailWrapper::smtpSend( mailmime *mail )
566 if ( err != MAILSMTP_NO_ERROR ) goto free_mem_session; 566 if ( err != MAILSMTP_NO_ERROR ) goto free_mem_session;
567 567
568 err = mailsmtp_init( session ); 568 err = mailsmtp_init( session );
569 if ( err != MAILSMTP_NO_ERROR ) goto free_con_session; 569 if ( err != MAILSMTP_NO_ERROR ) goto free_con_session;
570 570
571 qDebug( "INIT OK" ); 571 qDebug( "INIT OK" );
572 572
573 if ( smtp->getLogin() ) { 573 if ( smtp->getLogin() ) {
574 if ( smtp->getUser().isEmpty() || smtp->getPassword().isEmpty() ) { 574 if ( smtp->getUser().isEmpty() || smtp->getPassword().isEmpty() ) {
575 // get'em 575 // get'em
576 LoginDialog login( smtp->getUser(), smtp->getPassword(), NULL, 0, true ); 576 LoginDialog login( smtp->getUser(), smtp->getPassword(), NULL, 0, true );
@@ -590,14 +590,14 @@ void MailWrapper::smtpSend( mailmime *mail )
590 err = mailsmtp_auth( session, user, pass ); 590 err = mailsmtp_auth( session, user, pass );
591 if ( err == MAILSMTP_NO_ERROR ) qDebug("auth ok"); 591 if ( err == MAILSMTP_NO_ERROR ) qDebug("auth ok");
592 qDebug( "Done auth!" ); 592 qDebug( "Done auth!" );
593 } 593 }
594 594
595 err = mailsmtp_send( session, from, rcpts, data, size ); 595 err = mailsmtp_send( session, from, rcpts, data, size );
596 if ( err != MAILSMTP_NO_ERROR ) goto free_con_session; 596 if ( err != MAILSMTP_NO_ERROR ) goto free_con_session;
597 597
598 qDebug( "Mail sent." ); 598 qDebug( "Mail sent." );
599 599
600free_con_session: 600free_con_session:
601 mailsmtp_quit( session ); 601 mailsmtp_quit( session );
602free_mem_session: 602free_mem_session:
603 mailsmtp_free( session ); 603 mailsmtp_free( session );
@@ -621,9 +621,9 @@ void MailWrapper::sendMail( Mail mail )
621 qDebug( "sendMail: error creating mime mail" ); 621 qDebug( "sendMail: error creating mime mail" );
622 } else { 622 } else {
623 smtpSend( mimeMail ); 623 smtpSend( mimeMail );
624 mailmime_free( mimeMail ); 624 mailmime_free( mimeMail );
625 } 625 }
626} 626}
627 627
628Mail::Mail() 628Mail::Mail()
629 :name(""), mail(""), to(""), cc(""), bcc(""), reply(""), subject(""), message("") 629 :name(""), mail(""), to(""), cc(""), bcc(""), reply(""), subject(""), message("")