summaryrefslogtreecommitdiff
authoralwin <alwin>2004-01-12 14:36:22 (UTC)
committer alwin <alwin>2004-01-12 14:36:22 (UTC)
commit713a845a0d2ad3aba8230a5ba743a1c7b1622ef1 (patch) (unidiff)
tree99b6072598bbac82a5beaf22aa432d808c1ad9b3
parent2a0686efdcce2c6bd572468d0f340f3188d00c8c (diff)
downloadopie-713a845a0d2ad3aba8230a5ba743a1c7b1622ef1.zip
opie-713a845a0d2ad3aba8230a5ba743a1c7b1622ef1.tar.gz
opie-713a845a0d2ad3aba8230a5ba743a1c7b1622ef1.tar.bz2
generating clean failuremessages
bugfix - smtp without login was resolved as wrong when sending enqueued mails login will asked when starting flush not on every mail.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/libmailwrapper/smtpwrapper.cpp108
1 files changed, 67 insertions, 41 deletions
diff --git a/noncore/net/mail/libmailwrapper/smtpwrapper.cpp b/noncore/net/mail/libmailwrapper/smtpwrapper.cpp
index 7671133..e8db9ca 100644
--- a/noncore/net/mail/libmailwrapper/smtpwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/smtpwrapper.cpp
@@ -1,786 +1,812 @@
1#include <stdlib.h> 1#include <stdlib.h>
2#include <sys/stat.h> 2#include <sys/stat.h>
3#include <sys/types.h> 3#include <sys/types.h>
4#include <unistd.h> 4#include <unistd.h>
5#include <fcntl.h> 5#include <fcntl.h>
6#include <string.h> 6#include <string.h>
7#include <qdir.h> 7#include <qdir.h>
8#include <qt.h> 8#include <qt.h>
9#include <qmessagebox.h> 9#include <qmessagebox.h>
10 10
11#include <qpe/config.h> 11#include <qpe/config.h>
12#include <qpe/qcopenvelope_qws.h> 12#include <qpe/qcopenvelope_qws.h>
13 13
14#include <libetpan/libetpan.h> 14#include <libetpan/libetpan.h>
15 15
16#include "smtpwrapper.h" 16#include "smtpwrapper.h"
17#include "mailwrapper.h" 17#include "mailwrapper.h"
18#include "abstractmail.h" 18#include "abstractmail.h"
19#include "logindialog.h" 19#include "logindialog.h"
20#include "mailtypes.h" 20#include "mailtypes.h"
21//#include "defines.h"
22#include "sendmailprogress.h" 21#include "sendmailprogress.h"
23 22
24const char* SMTPwrapper::USER_AGENT="OpieMail v0.3"; 23const char* SMTPwrapper::USER_AGENT="OpieMail v0.4";
25 24
26progressMailSend*SMTPwrapper::sendProgress = 0; 25progressMailSend*SMTPwrapper::sendProgress = 0;
27 26
28SMTPwrapper::SMTPwrapper( Settings *s ) 27SMTPwrapper::SMTPwrapper( Settings *s )
29: QObject() { 28: QObject() {
30 settings = s; 29 settings = s;
31 Config cfg( "mail" ); 30 Config cfg( "mail" );
32 cfg.setGroup( "Status" ); 31 cfg.setGroup( "Status" );
33 m_queuedMail = cfg.readNumEntry( "outgoing", 0 ); 32 m_queuedMail = cfg.readNumEntry( "outgoing", 0 );
34 emit queuedMails( m_queuedMail ); 33 emit queuedMails( m_queuedMail );
35 connect( this, SIGNAL( queuedMails( int ) ), this, SLOT( emitQCop( int ) ) ); 34 connect( this, SIGNAL( queuedMails( int ) ), this, SLOT( emitQCop( int ) ) );
36} 35}
37 36
38void SMTPwrapper::emitQCop( int queued ) { 37void SMTPwrapper::emitQCop( int queued ) {
39 QCopEnvelope env( "QPE/Pim", "outgoingMails(int)" ); 38 QCopEnvelope env( "QPE/Pim", "outgoingMails(int)" );
40 env << queued; 39 env << queued;
41} 40}
42 41
43QString SMTPwrapper::mailsmtpError( int errnum ) { 42QString SMTPwrapper::mailsmtpError( int errnum ) {
44 switch ( errnum ) { 43 switch ( errnum ) {
45 case MAILSMTP_NO_ERROR: 44 case MAILSMTP_NO_ERROR:
46 return tr( "No error" ); 45 return tr( "No error" );
47 case MAILSMTP_ERROR_UNEXPECTED_CODE: 46 case MAILSMTP_ERROR_UNEXPECTED_CODE:
48 return tr( "Unexpected error code" ); 47 return tr( "Unexpected error code" );
49 case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE: 48 case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE:
50 return tr( "Service not available" ); 49 return tr( "Service not available" );
51 case MAILSMTP_ERROR_STREAM: 50 case MAILSMTP_ERROR_STREAM:
52 return tr( "Stream error" ); 51 return tr( "Stream error" );
53 case MAILSMTP_ERROR_HOSTNAME: 52 case MAILSMTP_ERROR_HOSTNAME:
54 return tr( "gethostname() failed" ); 53 return tr( "gethostname() failed" );
55 case MAILSMTP_ERROR_NOT_IMPLEMENTED: 54 case MAILSMTP_ERROR_NOT_IMPLEMENTED:
56 return tr( "Not implemented" ); 55 return tr( "Not implemented" );
57 case MAILSMTP_ERROR_ACTION_NOT_TAKEN: 56 case MAILSMTP_ERROR_ACTION_NOT_TAKEN:
58 return tr( "Error, action not taken" ); 57 return tr( "Error, action not taken" );
59 case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION: 58 case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION:
60 return tr( "Data exceeds storage allocation" ); 59 return tr( "Data exceeds storage allocation" );
61 case MAILSMTP_ERROR_IN_PROCESSING: 60 case MAILSMTP_ERROR_IN_PROCESSING:
62 return tr( "Error in processing" ); 61 return tr( "Error in processing" );
63 // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE: 62 // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE:
64 // return tr( "Insufficient system storage" ); 63 // return tr( "Insufficient system storage" );
65 case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE: 64 case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE:
66 return tr( "Mailbox unavailable" ); 65 return tr( "Mailbox unavailable" );
67 case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED: 66 case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED:
68 return tr( "Mailbox name not allowed" ); 67 return tr( "Mailbox name not allowed" );
69 case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND: 68 case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND:
70 return tr( "Bad command sequence" ); 69 return tr( "Bad command sequence" );
71 case MAILSMTP_ERROR_USER_NOT_LOCAL: 70 case MAILSMTP_ERROR_USER_NOT_LOCAL:
72 return tr( "User not local" ); 71 return tr( "User not local" );
73 case MAILSMTP_ERROR_TRANSACTION_FAILED: 72 case MAILSMTP_ERROR_TRANSACTION_FAILED:
74 return tr( "Transaction failed" ); 73 return tr( "Transaction failed" );
75 case MAILSMTP_ERROR_MEMORY: 74 case MAILSMTP_ERROR_MEMORY:
76 return tr( "Memory error" ); 75 return tr( "Memory error" );
77 case MAILSMTP_ERROR_CONNECTION_REFUSED: 76 case MAILSMTP_ERROR_CONNECTION_REFUSED:
78 return tr( "Connection refused" ); 77 return tr( "Connection refused" );
79 default: 78 default:
80 return tr( "Unknown error code" ); 79 return tr( "Unknown error code" );
81 } 80 }
82} 81}
83 82
84mailimf_mailbox *SMTPwrapper::newMailbox(const QString&name, const QString&mail ) { 83mailimf_mailbox *SMTPwrapper::newMailbox(const QString&name, const QString&mail ) {
85 return mailimf_mailbox_new( strdup( name.latin1() ), 84 return mailimf_mailbox_new( strdup( name.latin1() ),
86 strdup( mail.latin1() ) ); 85 strdup( mail.latin1() ) );
87} 86}
88 87
89mailimf_address_list *SMTPwrapper::parseAddresses(const QString&addr ) { 88mailimf_address_list *SMTPwrapper::parseAddresses(const QString&addr ) {
90 mailimf_address_list *addresses; 89 mailimf_address_list *addresses;
91 90
92 if ( addr.isEmpty() ) 91 if ( addr.isEmpty() )
93 return NULL; 92 return NULL;
94 93
95 addresses = mailimf_address_list_new_empty(); 94 addresses = mailimf_address_list_new_empty();
96 95
97 bool literal_open = false; 96 bool literal_open = false;
98 unsigned int startpos = 0; 97 unsigned int startpos = 0;
99 QStringList list; 98 QStringList list;
100 QString s; 99 QString s;
101 unsigned int i = 0; 100 unsigned int i = 0;
102 for (; i < addr.length();++i) { 101 for (; i < addr.length();++i) {
103 switch (addr[i]) { 102 switch (addr[i]) {
104 case '\"': 103 case '\"':
105 literal_open = !literal_open; 104 literal_open = !literal_open;
106 break; 105 break;
107 case ',': 106 case ',':
108 if (!literal_open) { 107 if (!literal_open) {
109 s = addr.mid(startpos,i-startpos); 108 s = addr.mid(startpos,i-startpos);
110 if (!s.isEmpty()) { 109 if (!s.isEmpty()) {
111 list.append(s); 110 list.append(s);
112 qDebug("Appended %s",s.latin1()); 111 qDebug("Appended %s",s.latin1());
113 } 112 }
114 // !!!! this is a MUST BE! 113 // !!!! this is a MUST BE!
115 startpos = ++i; 114 startpos = ++i;
116 } 115 }
117 break; 116 break;
118 default: 117 default:
119 break; 118 break;
120 } 119 }
121 } 120 }
122 s = addr.mid(startpos,i-startpos); 121 s = addr.mid(startpos,i-startpos);
123 if (!s.isEmpty()) { 122 if (!s.isEmpty()) {
124 list.append(s); 123 list.append(s);
125 qDebug("Appended %s",s.latin1()); 124 qDebug("Appended %s",s.latin1());
126 } 125 }
127 QStringList::Iterator it; 126 QStringList::Iterator it;
128 for ( it = list.begin(); it != list.end(); it++ ) { 127 for ( it = list.begin(); it != list.end(); it++ ) {
129 int err = mailimf_address_list_add_parse( addresses, (char*)(*it).latin1() ); 128 int err = mailimf_address_list_add_parse( addresses, (char*)(*it).latin1() );
130 if ( err != MAILIMF_NO_ERROR ) { 129 if ( err != MAILIMF_NO_ERROR ) {
131 qDebug( "Error parsing" ); 130 qDebug( "Error parsing" );
132 qDebug( *it ); 131 qDebug( *it );
133 } else { 132 } else {
134 qDebug( "Parse success! %s",(*it).latin1()); 133 qDebug( "Parse success! %s",(*it).latin1());
135 } 134 }
136 } 135 }
137 return addresses; 136 return addresses;
138} 137}
139 138
140mailimf_fields *SMTPwrapper::createImfFields(const Mail&mail ) { 139mailimf_fields *SMTPwrapper::createImfFields(const Mail&mail ) {
141 mailimf_fields *fields; 140 mailimf_fields *fields;
142 mailimf_field *xmailer; 141 mailimf_field *xmailer;
143 mailimf_mailbox *sender=0,*fromBox=0; 142 mailimf_mailbox *sender=0,*fromBox=0;
144 mailimf_mailbox_list *from=0; 143 mailimf_mailbox_list *from=0;
145 mailimf_address_list *to=0, *cc=0, *bcc=0, *reply=0; 144 mailimf_address_list *to=0, *cc=0, *bcc=0, *reply=0;
146 char *subject = strdup( mail.getSubject().latin1() ); 145 char *subject = strdup( mail.getSubject().latin1() );
147 int err; 146 int err;
148 147
149 sender = newMailbox( mail.getName(), mail.getMail() ); 148 sender = newMailbox( mail.getName(), mail.getMail() );
150 if ( sender == NULL ) 149 if ( sender == NULL )
151 goto err_free; 150 goto err_free;
152 151
153 fromBox = newMailbox( mail.getName(), mail.getMail() ); 152 fromBox = newMailbox( mail.getName(), mail.getMail() );
154 if ( fromBox == NULL ) 153 if ( fromBox == NULL )
155 goto err_free_sender; 154 goto err_free_sender;
156 155
157 from = mailimf_mailbox_list_new_empty(); 156 from = mailimf_mailbox_list_new_empty();
158 if ( from == NULL ) 157 if ( from == NULL )
159 goto err_free_fromBox; 158 goto err_free_fromBox;
160 159
161 err = mailimf_mailbox_list_add( from, fromBox ); 160 err = mailimf_mailbox_list_add( from, fromBox );
162 if ( err != MAILIMF_NO_ERROR ) 161 if ( err != MAILIMF_NO_ERROR )
163 goto err_free_from; 162 goto err_free_from;
164 163
165 to = parseAddresses( mail.getTo() ); 164 to = parseAddresses( mail.getTo() );
166 if ( to == NULL ) 165 if ( to == NULL )
167 goto err_free_from; 166 goto err_free_from;
168 167
169 cc = parseAddresses( mail.getCC() ); 168 cc = parseAddresses( mail.getCC() );
170 bcc = parseAddresses( mail.getBCC() ); 169 bcc = parseAddresses( mail.getBCC() );
171 reply = parseAddresses( mail.getReply() ); 170 reply = parseAddresses( mail.getReply() );
172 171
173 fields = mailimf_fields_new_with_data( from, sender, reply, to, cc, bcc, 172 fields = mailimf_fields_new_with_data( from, sender, reply, to, cc, bcc,
174 NULL, NULL, subject ); 173 NULL, NULL, subject );
175 if ( fields == NULL ) 174 if ( fields == NULL )
176 goto err_free_reply; 175 goto err_free_reply;
177 176
178 xmailer = mailimf_field_new_custom( strdup( "User-Agent" ), 177 xmailer = mailimf_field_new_custom( strdup( "User-Agent" ),
179 strdup( USER_AGENT ) ); 178 strdup( USER_AGENT ) );
180 if ( xmailer == NULL ) 179 if ( xmailer == NULL )
181 goto err_free_fields; 180 goto err_free_fields;
182 181
183 err = mailimf_fields_add( fields, xmailer ); 182 err = mailimf_fields_add( fields, xmailer );
184 if ( err != MAILIMF_NO_ERROR ) 183 if ( err != MAILIMF_NO_ERROR )
185 goto err_free_xmailer; 184 goto err_free_xmailer;
186 185
187 return fields; // Success :) 186 return fields; // Success :)
188 187
189err_free_xmailer: 188err_free_xmailer:
190 if (xmailer) 189 if (xmailer)
191 mailimf_field_free( xmailer ); 190 mailimf_field_free( xmailer );
192err_free_fields: 191err_free_fields:
193 if (fields) 192 if (fields)
194 mailimf_fields_free( fields ); 193 mailimf_fields_free( fields );
195err_free_reply: 194err_free_reply:
196 if (reply) 195 if (reply)
197 mailimf_address_list_free( reply ); 196 mailimf_address_list_free( reply );
198 if (bcc) 197 if (bcc)
199 mailimf_address_list_free( bcc ); 198 mailimf_address_list_free( bcc );
200 if (cc) 199 if (cc)
201 mailimf_address_list_free( cc ); 200 mailimf_address_list_free( cc );
202 if (to) 201 if (to)
203 mailimf_address_list_free( to ); 202 mailimf_address_list_free( to );
204err_free_from: 203err_free_from:
205 if (from) 204 if (from)
206 mailimf_mailbox_list_free( from ); 205 mailimf_mailbox_list_free( from );
207err_free_fromBox: 206err_free_fromBox:
208 mailimf_mailbox_free( fromBox ); 207 mailimf_mailbox_free( fromBox );
209err_free_sender: 208err_free_sender:
210 if (sender) 209 if (sender)
211 mailimf_mailbox_free( sender ); 210 mailimf_mailbox_free( sender );
212err_free: 211err_free:
213 if (subject) 212 if (subject)
214 free( subject ); 213 free( subject );
215 qDebug( "createImfFields - error" ); 214 qDebug( "createImfFields - error" );
216 215
217 return NULL; // Error :( 216 return NULL; // Error :(
218} 217}
219 218
220mailmime *SMTPwrapper::buildTxtPart(const QString&str ) { 219mailmime *SMTPwrapper::buildTxtPart(const QString&str ) {
221 mailmime *txtPart; 220 mailmime *txtPart;
222 mailmime_fields *fields; 221 mailmime_fields *fields;
223 mailmime_content *content; 222 mailmime_content *content;
224 mailmime_parameter *param; 223 mailmime_parameter *param;
225 int err; 224 int err;
226 225
227 param = mailmime_parameter_new( strdup( "charset" ), 226 param = mailmime_parameter_new( strdup( "charset" ),
228 strdup( "iso-8859-1" ) ); 227 strdup( "iso-8859-1" ) );
229 if ( param == NULL ) 228 if ( param == NULL )
230 goto err_free; 229 goto err_free;
231 230
232 content = mailmime_content_new_with_str( "text/plain" ); 231 content = mailmime_content_new_with_str( "text/plain" );
233 if ( content == NULL ) 232 if ( content == NULL )
234 goto err_free_param; 233 goto err_free_param;
235 234
236 err = clist_append( content->ct_parameters, param ); 235 err = clist_append( content->ct_parameters, param );
237 if ( err != MAILIMF_NO_ERROR ) 236 if ( err != MAILIMF_NO_ERROR )
238 goto err_free_content; 237 goto err_free_content;
239 238
240 fields = mailmime_fields_new_encoding(MAILMIME_MECHANISM_8BIT); 239 fields = mailmime_fields_new_encoding(MAILMIME_MECHANISM_8BIT);
241 if ( fields == NULL ) 240 if ( fields == NULL )
242 goto err_free_content; 241 goto err_free_content;
243 242
244 txtPart = mailmime_new_empty( content, fields ); 243 txtPart = mailmime_new_empty( content, fields );
245 if ( txtPart == NULL ) 244 if ( txtPart == NULL )
246 goto err_free_fields; 245 goto err_free_fields;
247 246
248 err = mailmime_set_body_text( txtPart, (char*)str.data(), str.length() ); 247 err = mailmime_set_body_text( txtPart, (char*)str.data(), str.length() );
249 if ( err != MAILIMF_NO_ERROR ) 248 if ( err != MAILIMF_NO_ERROR )
250 goto err_free_txtPart; 249 goto err_free_txtPart;
251 250
252 return txtPart; // Success :) 251 return txtPart; // Success :)
253 252
254err_free_txtPart: 253err_free_txtPart:
255 mailmime_free( txtPart ); 254 mailmime_free( txtPart );
256err_free_fields: 255err_free_fields:
257 mailmime_fields_free( fields ); 256 mailmime_fields_free( fields );
258err_free_content: 257err_free_content:
259 mailmime_content_free( content ); 258 mailmime_content_free( content );
260err_free_param: 259err_free_param:
261 mailmime_parameter_free( param ); 260 mailmime_parameter_free( param );
262err_free: 261err_free:
263 qDebug( "buildTxtPart - error" ); 262 qDebug( "buildTxtPart - error" );
264 263
265 return NULL; // Error :( 264 return NULL; // Error :(
266} 265}
267 266
268mailmime *SMTPwrapper::buildFilePart(const QString&filename,const QString&mimetype,const QString&TextContent ) { 267mailmime *SMTPwrapper::buildFilePart(const QString&filename,const QString&mimetype,const QString&TextContent ) {
269 mailmime * filePart = 0; 268 mailmime * filePart = 0;
270 mailmime_fields * fields = 0; 269 mailmime_fields * fields = 0;
271 mailmime_content * content = 0; 270 mailmime_content * content = 0;
272 mailmime_parameter * param = 0; 271 mailmime_parameter * param = 0;
273 char*name = 0; 272 char*name = 0;
274 char*file = 0; 273 char*file = 0;
275 int err; 274 int err;
276 275
277 int pos = filename.findRev( '/' ); 276 int pos = filename.findRev( '/' );
278 277
279 if (filename.length()>0) { 278 if (filename.length()>0) {
280 QString tmp = filename.right( filename.length() - ( pos + 1 ) ); 279 QString tmp = filename.right( filename.length() - ( pos + 1 ) );
281 name = strdup( tmp.latin1() ); // just filename 280 name = strdup( tmp.latin1() ); // just filename
282 file = strdup( filename.latin1() ); // full name with path 281 file = strdup( filename.latin1() ); // full name with path
283 } 282 }
284 283
285 int disptype = MAILMIME_DISPOSITION_TYPE_ATTACHMENT; 284 int disptype = MAILMIME_DISPOSITION_TYPE_ATTACHMENT;
286 int mechanism = MAILMIME_MECHANISM_BASE64; 285 int mechanism = MAILMIME_MECHANISM_BASE64;
287 286
288 if ( mimetype.startsWith( "text/" ) ) { 287 if ( mimetype.startsWith( "text/" ) ) {
289 param = mailmime_parameter_new( strdup( "charset" ), 288 param = mailmime_parameter_new( strdup( "charset" ),
290 strdup( "iso-8859-1" ) ); 289 strdup( "iso-8859-1" ) );
291 mechanism = MAILMIME_MECHANISM_QUOTED_PRINTABLE; 290 mechanism = MAILMIME_MECHANISM_QUOTED_PRINTABLE;
292 } 291 }
293 292
294 fields = mailmime_fields_new_filename( 293 fields = mailmime_fields_new_filename(
295 disptype, name, 294 disptype, name,
296 mechanism ); 295 mechanism );
297 content = mailmime_content_new_with_str( (char*)mimetype.latin1() ); 296 content = mailmime_content_new_with_str( (char*)mimetype.latin1() );
298 if (content!=0 && fields != 0) { 297 if (content!=0 && fields != 0) {
299 if (param) { 298 if (param) {
300 clist_append(content->ct_parameters,param); 299 clist_append(content->ct_parameters,param);
301 param = 0; 300 param = 0;
302 } 301 }
303 if (filename.length()>0) { 302 if (filename.length()>0) {
304 QFileInfo f(filename); 303 QFileInfo f(filename);
305 param = mailmime_parameter_new(strdup("name"),strdup(f.fileName().latin1())); 304 param = mailmime_parameter_new(strdup("name"),strdup(f.fileName().latin1()));
306 clist_append(content->ct_parameters,param); 305 clist_append(content->ct_parameters,param);
307 param = 0; 306 param = 0;
308 } 307 }
309 filePart = mailmime_new_empty( content, fields ); 308 filePart = mailmime_new_empty( content, fields );
310 } 309 }
311 if (filePart) { 310 if (filePart) {
312 if (filename.length()>0) { 311 if (filename.length()>0) {
313 err = mailmime_set_body_file( filePart, file ); 312 err = mailmime_set_body_file( filePart, file );
314 } else { 313 } else {
315 err = mailmime_set_body_text(filePart,strdup(TextContent.data()),TextContent.length()); 314 err = mailmime_set_body_text(filePart,strdup(TextContent.data()),TextContent.length());
316 } 315 }
317 if (err != MAILIMF_NO_ERROR) { 316 if (err != MAILIMF_NO_ERROR) {
318 qDebug("Error setting body with file %s",file); 317 qDebug("Error setting body with file %s",file);
319 mailmime_free( filePart ); 318 mailmime_free( filePart );
320 filePart = 0; 319 filePart = 0;
321 } 320 }
322 } 321 }
323 322
324 if (!filePart) { 323 if (!filePart) {
325 if ( param != NULL ) { 324 if ( param != NULL ) {
326 mailmime_parameter_free( param ); 325 mailmime_parameter_free( param );
327 } 326 }
328 if (content) { 327 if (content) {
329 mailmime_content_free( content ); 328 mailmime_content_free( content );
330 } 329 }
331 if (fields) { 330 if (fields) {
332 mailmime_fields_free( fields ); 331 mailmime_fields_free( fields );
333 } else { 332 } else {
334 if (name) { 333 if (name) {
335 free( name ); 334 free( name );
336 } 335 }
337 if (file) { 336 if (file) {
338 free( file ); 337 free( file );
339 } 338 }
340 } 339 }
341 } 340 }
342 return filePart; // Success :) 341 return filePart; // Success :)
343 342
344} 343}
345 344
346void SMTPwrapper::addFileParts( mailmime *message,const QList<Attachment>&files ) { 345void SMTPwrapper::addFileParts( mailmime *message,const QList<Attachment>&files ) {
347 const Attachment *it; 346 const Attachment *it;
348 unsigned int count = files.count(); 347 unsigned int count = files.count();
349 qDebug("List contains %i values",count); 348 qDebug("List contains %i values",count);
350 for ( unsigned int i = 0; i < count; ++i ) { 349 for ( unsigned int i = 0; i < count; ++i ) {
351 qDebug( "Adding file" ); 350 qDebug( "Adding file" );
352 mailmime *filePart; 351 mailmime *filePart;
353 int err; 352 int err;
354 it = ((QList<Attachment>)files).at(i); 353 it = ((QList<Attachment>)files).at(i);
355 354
356 filePart = buildFilePart( it->getFileName(), it->getMimeType(),"" ); 355 filePart = buildFilePart( it->getFileName(), it->getMimeType(),"" );
357 if ( filePart == NULL ) { 356 if ( filePart == NULL ) {
358 qDebug( "addFileParts: error adding file:" ); 357 qDebug( "addFileParts: error adding file:" );
359 qDebug( it->getFileName() ); 358 qDebug( it->getFileName() );
360 continue; 359 continue;
361 } 360 }
362 err = mailmime_smart_add_part( message, filePart ); 361 err = mailmime_smart_add_part( message, filePart );
363 if ( err != MAILIMF_NO_ERROR ) { 362 if ( err != MAILIMF_NO_ERROR ) {
364 mailmime_free( filePart ); 363 mailmime_free( filePart );
365 qDebug("error smart add"); 364 qDebug("error smart add");
366 } 365 }
367 } 366 }
368} 367}
369 368
370mailmime *SMTPwrapper::createMimeMail(const Mail &mail ) { 369mailmime *SMTPwrapper::createMimeMail(const Mail &mail ) {
371 mailmime *message, *txtPart; 370 mailmime *message, *txtPart;
372 mailimf_fields *fields; 371 mailimf_fields *fields;
373 int err; 372 int err;
374 373
375 fields = createImfFields( mail ); 374 fields = createImfFields( mail );
376 if ( fields == NULL ) 375 if ( fields == NULL )
377 goto err_free; 376 goto err_free;
378 377
379 message = mailmime_new_message_data( NULL ); 378 message = mailmime_new_message_data( NULL );
380 if ( message == NULL ) 379 if ( message == NULL )
381 goto err_free_fields; 380 goto err_free_fields;
382 381
383 mailmime_set_imf_fields( message, fields ); 382 mailmime_set_imf_fields( message, fields );
384 383
385 txtPart = buildTxtPart( mail.getMessage() ); 384 txtPart = buildTxtPart( mail.getMessage() );
386 385
387 if ( txtPart == NULL ) 386 if ( txtPart == NULL )
388 goto err_free_message; 387 goto err_free_message;
389 388
390 err = mailmime_smart_add_part( message, txtPart ); 389 err = mailmime_smart_add_part( message, txtPart );
391 if ( err != MAILIMF_NO_ERROR ) 390 if ( err != MAILIMF_NO_ERROR )
392 goto err_free_txtPart; 391 goto err_free_txtPart;
393 392
394 addFileParts( message, mail.getAttachments() ); 393 addFileParts( message, mail.getAttachments() );
395 394
396 return message; // Success :) 395 return message; // Success :)
397 396
398err_free_txtPart: 397err_free_txtPart:
399 mailmime_free( txtPart ); 398 mailmime_free( txtPart );
400err_free_message: 399err_free_message:
401 mailmime_free( message ); 400 mailmime_free( message );
402err_free_fields: 401err_free_fields:
403 mailimf_fields_free( fields ); 402 mailimf_fields_free( fields );
404err_free: 403err_free:
405 qDebug( "createMimeMail: error" ); 404 qDebug( "createMimeMail: error" );
406 405
407 return NULL; // Error :( 406 return NULL; // Error :(
408} 407}
409 408
410mailimf_field *SMTPwrapper::getField( mailimf_fields *fields, int type ) { 409mailimf_field *SMTPwrapper::getField( mailimf_fields *fields, int type ) {
411 mailimf_field *field; 410 mailimf_field *field;
412 clistiter *it; 411 clistiter *it;
413 412
414 it = clist_begin( fields->fld_list ); 413 it = clist_begin( fields->fld_list );
415 while ( it ) { 414 while ( it ) {
416 field = (mailimf_field *) it->data; 415 field = (mailimf_field *) it->data;
417 if ( field->fld_type == type ) { 416 if ( field->fld_type == type ) {
418 return field; 417 return field;
419 } 418 }
420 it = it->next; 419 it = it->next;
421 } 420 }
422 421
423 return NULL; 422 return NULL;
424} 423}
425 424
426void SMTPwrapper::addRcpts( clist *list, mailimf_address_list *addr_list ) { 425void SMTPwrapper::addRcpts( clist *list, mailimf_address_list *addr_list ) {
427 clistiter *it, *it2; 426 clistiter *it, *it2;
428 427
429 for ( it = clist_begin( addr_list->ad_list ); it; it = it->next ) { 428 for ( it = clist_begin( addr_list->ad_list ); it; it = it->next ) {
430 mailimf_address *addr; 429 mailimf_address *addr;
431 addr = (mailimf_address *) it->data; 430 addr = (mailimf_address *) it->data;
432 431
433 if ( addr->ad_type == MAILIMF_ADDRESS_MAILBOX ) { 432 if ( addr->ad_type == MAILIMF_ADDRESS_MAILBOX ) {
434 esmtp_address_list_add( list, addr->ad_data.ad_mailbox->mb_addr_spec, 0, NULL ); 433 esmtp_address_list_add( list, addr->ad_data.ad_mailbox->mb_addr_spec, 0, NULL );
435 } else if ( addr->ad_type == MAILIMF_ADDRESS_GROUP ) { 434 } else if ( addr->ad_type == MAILIMF_ADDRESS_GROUP ) {
436 clist *l = addr->ad_data.ad_group->grp_mb_list->mb_list; 435 clist *l = addr->ad_data.ad_group->grp_mb_list->mb_list;
437 for ( it2 = clist_begin( l ); it2; it2 = it2->next ) { 436 for ( it2 = clist_begin( l ); it2; it2 = it2->next ) {
438 mailimf_mailbox *mbox; 437 mailimf_mailbox *mbox;
439 mbox = (mailimf_mailbox *) it2->data; 438 mbox = (mailimf_mailbox *) it2->data;
440 esmtp_address_list_add( list, mbox->mb_addr_spec, 0, NULL ); 439 esmtp_address_list_add( list, mbox->mb_addr_spec, 0, NULL );
441 } 440 }
442 } 441 }
443 } 442 }
444} 443}
445 444
446clist *SMTPwrapper::createRcptList( mailimf_fields *fields ) { 445clist *SMTPwrapper::createRcptList( mailimf_fields *fields ) {
447 clist *rcptList; 446 clist *rcptList;
448 mailimf_field *field; 447 mailimf_field *field;
449 448
450 rcptList = esmtp_address_list_new(); 449 rcptList = esmtp_address_list_new();
451 450
452 field = getField( fields, MAILIMF_FIELD_TO ); 451 field = getField( fields, MAILIMF_FIELD_TO );
453 if ( field && (field->fld_type == MAILIMF_FIELD_TO) 452 if ( field && (field->fld_type == MAILIMF_FIELD_TO)
454 && field->fld_data.fld_to->to_addr_list ) { 453 && field->fld_data.fld_to->to_addr_list ) {
455 addRcpts( rcptList, field->fld_data.fld_to->to_addr_list ); 454 addRcpts( rcptList, field->fld_data.fld_to->to_addr_list );
456 } 455 }
457 456
458 field = getField( fields, MAILIMF_FIELD_CC ); 457 field = getField( fields, MAILIMF_FIELD_CC );
459 if ( field && (field->fld_type == MAILIMF_FIELD_CC) 458 if ( field && (field->fld_type == MAILIMF_FIELD_CC)
460 && field->fld_data.fld_cc->cc_addr_list ) { 459 && field->fld_data.fld_cc->cc_addr_list ) {
461 addRcpts( rcptList, field->fld_data.fld_cc->cc_addr_list ); 460 addRcpts( rcptList, field->fld_data.fld_cc->cc_addr_list );
462 } 461 }
463 462
464 field = getField( fields, MAILIMF_FIELD_BCC ); 463 field = getField( fields, MAILIMF_FIELD_BCC );
465 if ( field && (field->fld_type == MAILIMF_FIELD_BCC) 464 if ( field && (field->fld_type == MAILIMF_FIELD_BCC)
466 && field->fld_data.fld_bcc->bcc_addr_list ) { 465 && field->fld_data.fld_bcc->bcc_addr_list ) {
467 addRcpts( rcptList, field->fld_data.fld_bcc->bcc_addr_list ); 466 addRcpts( rcptList, field->fld_data.fld_bcc->bcc_addr_list );
468 } 467 }
469 468
470 return rcptList; 469 return rcptList;
471} 470}
472 471
473char *SMTPwrapper::getFrom( mailimf_field *ffrom) { 472char *SMTPwrapper::getFrom( mailimf_field *ffrom) {
474 char *from = NULL; 473 char *from = NULL;
475 if ( ffrom && (ffrom->fld_type == MAILIMF_FIELD_FROM) 474 if ( ffrom && (ffrom->fld_type == MAILIMF_FIELD_FROM)
476 && ffrom->fld_data.fld_from->frm_mb_list && ffrom->fld_data.fld_from->frm_mb_list->mb_list ) { 475 && ffrom->fld_data.fld_from->frm_mb_list && ffrom->fld_data.fld_from->frm_mb_list->mb_list ) {
477 clist *cl = ffrom->fld_data.fld_from->frm_mb_list->mb_list; 476 clist *cl = ffrom->fld_data.fld_from->frm_mb_list->mb_list;
478 clistiter *it; 477 clistiter *it;
479 for ( it = clist_begin( cl ); it; it = it->next ) { 478 for ( it = clist_begin( cl ); it; it = it->next ) {
480 mailimf_mailbox *mb = (mailimf_mailbox *) it->data; 479 mailimf_mailbox *mb = (mailimf_mailbox *) it->data;
481 from = strdup( mb->mb_addr_spec ); 480 from = strdup( mb->mb_addr_spec );
482 } 481 }
483 } 482 }
484 483
485 return from; 484 return from;
486} 485}
487 486
488char *SMTPwrapper::getFrom( mailmime *mail ) { 487char *SMTPwrapper::getFrom( mailmime *mail ) {
489 /* no need to delete - its just a pointer to structure content */ 488 /* no need to delete - its just a pointer to structure content */
490 mailimf_field *ffrom = 0; 489 mailimf_field *ffrom = 0;
491 ffrom = getField( mail->mm_data.mm_message.mm_fields, MAILIMF_FIELD_FROM ); 490 ffrom = getField( mail->mm_data.mm_message.mm_fields, MAILIMF_FIELD_FROM );
492 return getFrom(ffrom); 491 return getFrom(ffrom);
493} 492}
494 493
495void SMTPwrapper::progress( size_t current, size_t maximum ) { 494void SMTPwrapper::progress( size_t current, size_t maximum ) {
496 if (SMTPwrapper::sendProgress) { 495 if (SMTPwrapper::sendProgress) {
497 SMTPwrapper::sendProgress->setSingleMail(current, maximum ); 496 SMTPwrapper::sendProgress->setSingleMail(current, maximum );
498 qApp->processEvents(); 497 qApp->processEvents();
499 } 498 }
500} 499}
501 500
502void SMTPwrapper::storeMail(const char*mail, size_t length, const QString&box) { 501void SMTPwrapper::storeMail(const char*mail, size_t length, const QString&box) {
503 if (!mail) 502 if (!mail)
504 return; 503 return;
505 QString localfolders = AbstractMail::defaultLocalfolder(); 504 QString localfolders = AbstractMail::defaultLocalfolder();
506 AbstractMail*wrap = AbstractMail::getWrapper(localfolders); 505 AbstractMail*wrap = AbstractMail::getWrapper(localfolders);
507 wrap->createMbox(box); 506 wrap->createMbox(box);
508 wrap->storeMessage(mail,length,box); 507 wrap->storeMessage(mail,length,box);
509 delete wrap; 508 delete wrap;
510} 509}
511 510
512void SMTPwrapper::smtpSend( mailmime *mail,bool later, SMTPaccount *smtp ) { 511void SMTPwrapper::smtpSend( mailmime *mail,bool later, SMTPaccount *smtp ) {
513 clist *rcpts = 0; 512 clist *rcpts = 0;
514 char *from, *data; 513 char *from, *data;
515 size_t size; 514 size_t size;
516 515
517 if ( smtp == NULL ) { 516 if ( smtp == NULL ) {
518 return; 517 return;
519 } 518 }
520 from = data = 0; 519 from = data = 0;
521 520
522 mailmessage * msg = 0; 521 mailmessage * msg = 0;
523 msg = mime_message_init(mail); 522 msg = mime_message_init(mail);
524 mime_message_set_tmpdir(msg,getenv( "HOME" )); 523 mime_message_set_tmpdir(msg,getenv( "HOME" ));
525 int r = mailmessage_fetch(msg,&data,&size); 524 int r = mailmessage_fetch(msg,&data,&size);
526 mime_message_detach_mime(msg); 525 mime_message_detach_mime(msg);
527 mailmessage_free(msg); 526 mailmessage_free(msg);
528 if (r != MAIL_NO_ERROR || !data) { 527 if (r != MAIL_NO_ERROR || !data) {
529 if (data) 528 if (data)
530 free(data); 529 free(data);
531 qDebug("Error fetching mime..."); 530 qDebug("Error fetching mime...");
532 return; 531 return;
533 } 532 }
534 msg = 0; 533 msg = 0;
535 if (later) { 534 if (later) {
536 storeMail(data,size,"Outgoing"); 535 storeMail(data,size,"Outgoing");
537 if (data) 536 if (data)
538 free( data ); 537 free( data );
539 Config cfg( "mail" ); 538 Config cfg( "mail" );
540 cfg.setGroup( "Status" ); 539 cfg.setGroup( "Status" );
541 cfg.writeEntry( "outgoing", ++m_queuedMail ); 540 cfg.writeEntry( "outgoing", ++m_queuedMail );
542 emit queuedMails( m_queuedMail ); 541 emit queuedMails( m_queuedMail );
543 return; 542 return;
544 } 543 }
545 from = getFrom( mail ); 544 from = getFrom( mail );
546 rcpts = createRcptList( mail->mm_data.mm_message.mm_fields ); 545 rcpts = createRcptList( mail->mm_data.mm_message.mm_fields );
547 smtpSend(from,rcpts,data,size,smtp); 546 smtpSend(from,rcpts,data,size,smtp);
548 if (data) { 547 if (data) {
549 free(data); 548 free(data);
550 } 549 }
551 if (from) { 550 if (from) {
552 free(from); 551 free(from);
553 } 552 }
554 if (rcpts) 553 if (rcpts)
555 smtp_address_list_free( rcpts ); 554 smtp_address_list_free( rcpts );
556} 555}
557 556
558void SMTPwrapper::storeFailedMail(const char*data,unsigned int size, const char*failuremessage) 557void SMTPwrapper::storeFailedMail(const char*data,unsigned int size, const char*failuremessage)
559{ 558{
560 if (data) { 559 if (data) {
561 storeMail(data,size,"Sendfailed"); 560 storeMail(data,size,"Sendfailed");
562 } 561 }
563 if (failuremessage) { 562 if (failuremessage) {
564 QMessageBox::critical(0,tr("Error sending mail"), 563 QMessageBox::critical(0,tr("Error sending mail"),
565 tr("<center>%1</center>").arg(failuremessage)); 564 tr("<center>%1</center>").arg(failuremessage));
566 } 565 }
567} 566}
568 567
569int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size, SMTPaccount *smtp ) { 568int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size, SMTPaccount *smtp ) {
570 const char *server, *user, *pass; 569 const char *server, *user, *pass;
571 bool ssl; 570 bool ssl;
572 uint16_t port; 571 uint16_t port;
573 mailsmtp *session; 572 mailsmtp *session;
574 int err,result; 573 int err,result;
574 QString failuretext = "";
575 575
576 result = 1; 576 result = 1;
577 server = user = pass = 0; 577 server = user = pass = 0;
578 server = smtp->getServer().latin1(); 578 server = smtp->getServer().latin1();
579 579
580 // FIXME: currently only TLS and Plain work. 580 // FIXME: currently only TLS and Plain work.
581 581
582 ssl = false; 582 ssl = false;
583 583
584 if ( smtp->ConnectionType() == 2 ) { 584 if ( smtp->ConnectionType() == 2 ) {
585 ssl = true; 585 ssl = true;
586 } 586 }
587 587
588 port = smtp->getPort().toUInt(); 588 port = smtp->getPort().toUInt();
589 589
590 session = mailsmtp_new( 20, &progress ); 590 session = mailsmtp_new( 20, &progress );
591 if ( session == NULL ) 591 if ( session == NULL ) {
592 goto free_mem; 592 /* no failure message cause this happens when problems with memory - than we
593 we can not display any messagebox */
594 return 0;
595 }
593 596
594 qDebug( "Servername %s at port %i", server, port ); 597 qDebug( "Servername %s at port %i", server, port );
595 if ( ssl ) { 598 if ( ssl ) {
596 qDebug( "SSL session" ); 599 qDebug( "SSL session" );
597 err = mailsmtp_ssl_connect( session, server, port ); 600 err = mailsmtp_ssl_connect( session, server, port );
598 } else { 601 } else {
599 qDebug( "No SSL session" ); 602 qDebug( "No SSL session" );
600 err = mailsmtp_socket_connect( session, server, port ); 603 err = mailsmtp_socket_connect( session, server, port );
601 } 604 }
602 if ( err != MAILSMTP_NO_ERROR ) { 605 if ( err != MAILSMTP_NO_ERROR ) {
603 qDebug("Error init connection"); 606 qDebug("Error init connection");
604 storeFailedMail(data,size,mailsmtpError(err)); 607 failuretext = tr("Error init SMTP connection: %1").arg(mailsmtpError(err));
605 result = 0; 608 result = 0;
606 goto free_mem_session;
607 } 609 }
608 610
609 err = mailsmtp_init( session ); 611 if (result) {
610 if ( err != MAILSMTP_NO_ERROR ) { 612 err = mailsmtp_init( session );
611 storeFailedMail(data,size,mailsmtpError(err)); 613 if (err != MAILSMTP_NO_ERROR) {
612 result = 0; 614 result = 0;
613 goto free_con_session; 615 failuretext = tr("Error init SMTP connection: %1").arg(mailsmtpError(err));
616 }
614 } 617 }
615 618
616 qDebug( "INIT OK" ); 619 if (result==1 && smtp->getLogin() ) {
617
618 if ( smtp->getLogin() ) {
619 qDebug("smtp with auth"); 620 qDebug("smtp with auth");
620 if ( smtp->getUser().isEmpty() || smtp->getPassword().isEmpty() ) { 621 if ( smtp->getUser().isEmpty() || smtp->getPassword().isEmpty() ) {
621 // get'em 622 // get'em
622 LoginDialog login( smtp->getUser(), smtp->getPassword(), NULL, 0, true ); 623 LoginDialog login( smtp->getUser(), smtp->getPassword(), NULL, 0, true );
623 login.show(); 624 login.show();
624 if ( QDialog::Accepted == login.exec() ) { 625 if ( QDialog::Accepted == login.exec() ) {
625 // ok 626 // ok
626 user = login.getUser().latin1(); 627 user = login.getUser().latin1();
627 pass = login.getPassword().latin1(); 628 pass = login.getPassword().latin1();
628 } else { 629 } else {
629 result = 0; 630 result = 0;
630 goto free_con_session; 631 failuretext=tr("Login aborted - storing mail to localfolder");
631 } 632 }
632 } else { 633 } else {
633 user = smtp->getUser().latin1(); 634 user = smtp->getUser().latin1();
634 pass = smtp->getPassword().latin1(); 635 pass = smtp->getPassword().latin1();
635 } 636 }
636 qDebug( "session->auth: %i", session->auth); 637 qDebug( "session->auth: %i", session->auth);
637 err = mailsmtp_auth( session, (char*)user, (char*)pass ); 638 if (result) {
638 if ( err == MAILSMTP_NO_ERROR ) { 639 err = mailsmtp_auth( session, (char*)user, (char*)pass );
639 qDebug("auth ok"); 640 if ( err == MAILSMTP_NO_ERROR ) {
640 } else { 641 qDebug("auth ok");
641 storeFailedMail(data,size,tr("Authentification failed")); 642 } else {
642 result = 0; 643 failuretext = tr("Authentification failed");
643 goto free_con_session; 644 result = 0;
645 }
644 } 646 }
645 qDebug( "Done auth!" );
646 } else {
647 qDebug("SMTP without auth");
648 result = 0;
649 goto free_con_session;
650 } 647 }
651 648
652 err = mailsmtp_send( session, from, rcpts, data, size ); 649 if (result) {
653 if ( err != MAILSMTP_NO_ERROR ) { 650 err = mailsmtp_send( session, from, rcpts, data, size );
654 storeFailedMail(data,size,mailsmtpError(err)); 651 if ( err != MAILSMTP_NO_ERROR ) {
655 qDebug("Error sending mail: %s",mailsmtpError(err).latin1()); 652 failuretext=tr("Error sending mail: %1").arg(mailsmtpError(err));
656 result = 0; 653 result = 0;
657 goto free_con_session; 654 }
658 } 655 }
659 656
660 qDebug( "Mail sent." ); 657 if (!result) {
661 storeMail(data,size,"Sent"); 658 storeFailedMail(data,size,failuretext);
662 659 } else {
663free_con_session: 660 qDebug( "Mail sent." );
664 mailsmtp_quit( session ); 661 storeMail(data,size,"Sent");
665free_mem_session: 662 }
666 mailsmtp_free( session ); 663 if (session) {
667free_mem: 664 mailsmtp_quit( session );
665 mailsmtp_free( session );
666 }
668 return result; 667 return result;
669} 668}
670 669
671void SMTPwrapper::sendMail(const Mail&mail,SMTPaccount*aSmtp,bool later ) { 670void SMTPwrapper::sendMail(const Mail&mail,SMTPaccount*aSmtp,bool later ) {
672 mailmime * mimeMail; 671 mailmime * mimeMail;
673 672
674 SMTPaccount *smtp = aSmtp; 673 SMTPaccount *smtp = aSmtp;
675 674
676 if (!later && !smtp) { 675 if (!later && !smtp) {
677 qDebug("Didn't get any send method - giving up"); 676 qDebug("Didn't get any send method - giving up");
678 return; 677 return;
679 } 678 }
680 mimeMail = createMimeMail(mail ); 679 mimeMail = createMimeMail(mail );
681 if ( mimeMail == NULL ) { 680 if ( mimeMail == NULL ) {
682 qDebug( "sendMail: error creating mime mail" ); 681 qDebug( "sendMail: error creating mime mail" );
683 } else { 682 } else {
684 sendProgress = new progressMailSend(); 683 sendProgress = new progressMailSend();
685 sendProgress->show(); 684 sendProgress->show();
686 sendProgress->setMaxMails(1); 685 sendProgress->setMaxMails(1);
687 smtpSend( mimeMail,later,smtp); 686 smtpSend( mimeMail,later,smtp);
688 qDebug("Clean up done"); 687 qDebug("Clean up done");
689 sendProgress->hide(); 688 sendProgress->hide();
690 delete sendProgress; 689 delete sendProgress;
691 sendProgress = 0; 690 sendProgress = 0;
692 mailmime_free( mimeMail ); 691 mailmime_free( mimeMail );
693 } 692 }
694} 693}
695 694
696int SMTPwrapper::sendQueuedMail(AbstractMail*wrap,SMTPaccount*smtp,RecMail*which) { 695int SMTPwrapper::sendQueuedMail(AbstractMail*wrap,SMTPaccount*smtp,RecMail*which) {
697 size_t curTok = 0; 696 size_t curTok = 0;
698 mailimf_fields *fields = 0; 697 mailimf_fields *fields = 0;
699 mailimf_field*ffrom = 0; 698 mailimf_field*ffrom = 0;
700 clist *rcpts = 0; 699 clist *rcpts = 0;
701 char*from = 0; 700 char*from = 0;
702 int res = 0; 701 int res = 0;
703 702
704 encodedString * data = wrap->fetchRawBody(*which); 703 encodedString * data = wrap->fetchRawBody(*which);
705 if (!data) 704 if (!data)
706 return 0; 705 return 0;
707 int err = mailimf_fields_parse( data->Content(), data->Length(), &curTok, &fields ); 706 int err = mailimf_fields_parse( data->Content(), data->Length(), &curTok, &fields );
708 if (err != MAILIMF_NO_ERROR) { 707 if (err != MAILIMF_NO_ERROR) {
709 delete data; 708 delete data;
710 delete wrap; 709 delete wrap;
711 return 0; 710 return 0;
712 } 711 }
713 712
714 rcpts = createRcptList( fields ); 713 rcpts = createRcptList( fields );
715 ffrom = getField(fields, MAILIMF_FIELD_FROM ); 714 ffrom = getField(fields, MAILIMF_FIELD_FROM );
716 from = getFrom(ffrom); 715 from = getFrom(ffrom);
717 716
718 if (rcpts && from) { 717 if (rcpts && from) {
719 res = smtpSend(from,rcpts,data->Content(),data->Length(),smtp ); 718 res = smtpSend(from,rcpts,data->Content(),data->Length(),smtp );
720 } 719 }
721 if (fields) { 720 if (fields) {
722 mailimf_fields_free(fields); 721 mailimf_fields_free(fields);
723 fields = 0; 722 fields = 0;
724 } 723 }
725 if (data) { 724 if (data) {
726 delete data; 725 delete data;
727 } 726 }
728 if (from) { 727 if (from) {
729 free(from); 728 free(from);
730 } 729 }
731 if (rcpts) { 730 if (rcpts) {
732 smtp_address_list_free( rcpts ); 731 smtp_address_list_free( rcpts );
733 } 732 }
734 return res; 733 return res;
735} 734}
736 735
737/* this is a special fun */ 736/* this is a special fun */
738bool SMTPwrapper::flushOutbox(SMTPaccount*smtp) { 737bool SMTPwrapper::flushOutbox(SMTPaccount*smtp) {
739 bool returnValue = true; 738 bool returnValue = true;
740 739
741 if (!smtp) 740 if (!smtp)
742 return false; 741 return false;
743 742
743 bool reset_user_value = false;
744 QString localfolders = AbstractMail::defaultLocalfolder(); 744 QString localfolders = AbstractMail::defaultLocalfolder();
745 AbstractMail*wrap = AbstractMail::getWrapper(localfolders); 745 AbstractMail*wrap = AbstractMail::getWrapper(localfolders);
746 if (!wrap) { 746 if (!wrap) {
747 qDebug("memory error"); 747 qDebug("memory error");
748 return false; 748 return false;
749 } 749 }
750 QString oldPw, oldUser;
750 QList<RecMail> mailsToSend; 751 QList<RecMail> mailsToSend;
751 QList<RecMail> mailsToRemove; 752 QList<RecMail> mailsToRemove;
752 QString mbox("Outgoing"); 753 QString mbox("Outgoing");
753 wrap->listMessages(mbox,mailsToSend); 754 wrap->listMessages(mbox,mailsToSend);
754 if (mailsToSend.count()==0) { 755 if (mailsToSend.count()==0) {
755 delete wrap; 756 delete wrap;
756 return false; 757 return false;
757 } 758 }
759
760 oldPw = smtp->getPassword();
761 oldUser = smtp->getUser();
762 if (smtp->getLogin() && (smtp->getUser().isEmpty() || smtp->getPassword().isEmpty()) ) {
763 // get'em
764 QString user,pass;
765 LoginDialog login( smtp->getUser(), smtp->getPassword(), NULL, 0, true );
766 login.show();
767 if ( QDialog::Accepted == login.exec() ) {
768 // ok
769 user = login.getUser().latin1();
770 pass = login.getPassword().latin1();
771 reset_user_value = true;
772 smtp->setUser(user);
773 smtp->setPassword(pass);
774 } else {
775 return true;
776 }
777 }
778
779
758 mailsToSend.setAutoDelete(false); 780 mailsToSend.setAutoDelete(false);
759 sendProgress = new progressMailSend(); 781 sendProgress = new progressMailSend();
760 sendProgress->show(); 782 sendProgress->show();
761 sendProgress->setMaxMails(mailsToSend.count()); 783 sendProgress->setMaxMails(mailsToSend.count());
762 784
763 while (mailsToSend.count()>0) { 785 while (mailsToSend.count()>0) {
764 if (sendQueuedMail(wrap,smtp,mailsToSend.at(0))==0) { 786 if (sendQueuedMail(wrap,smtp,mailsToSend.at(0))==0) {
765 QMessageBox::critical(0,tr("Error sending mail"), 787 QMessageBox::critical(0,tr("Error sending mail"),
766 tr("Error sending queued mail - breaking")); 788 tr("Error sending queued mail - breaking"));
767 returnValue = false; 789 returnValue = false;
768 break; 790 break;
769 } 791 }
770 mailsToRemove.append(mailsToSend.at(0)); 792 mailsToRemove.append(mailsToSend.at(0));
771 mailsToSend.removeFirst(); 793 mailsToSend.removeFirst();
772 sendProgress->setCurrentMails(mailsToRemove.count()); 794 sendProgress->setCurrentMails(mailsToRemove.count());
773 } 795 }
796 if (reset_user_value) {
797 smtp->setUser(oldUser);
798 smtp->setPassword(oldPw);
799 }
774 Config cfg( "mail" ); 800 Config cfg( "mail" );
775 cfg.setGroup( "Status" ); 801 cfg.setGroup( "Status" );
776 m_queuedMail = 0; 802 m_queuedMail = 0;
777 cfg.writeEntry( "outgoing", m_queuedMail ); 803 cfg.writeEntry( "outgoing", m_queuedMail );
778 emit queuedMails( m_queuedMail ); 804 emit queuedMails( m_queuedMail );
779 sendProgress->hide(); 805 sendProgress->hide();
780 delete sendProgress; 806 delete sendProgress;
781 sendProgress = 0; 807 sendProgress = 0;
782 wrap->deleteMails(mbox,mailsToRemove); 808 wrap->deleteMails(mbox,mailsToRemove);
783 mailsToSend.setAutoDelete(true); 809 mailsToSend.setAutoDelete(true);
784 delete wrap; 810 delete wrap;
785 return returnValue; 811 return returnValue;
786} 812}