summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/libmailwrapper/generatemail.cpp454
-rw-r--r--noncore/net/mail/libmailwrapper/generatemail.h44
-rw-r--r--noncore/net/mail/libmailwrapper/genericwrapper.cpp52
-rw-r--r--noncore/net/mail/libmailwrapper/genericwrapper.h4
-rw-r--r--noncore/net/mail/libmailwrapper/imapwrapper.cpp49
-rw-r--r--noncore/net/mail/libmailwrapper/libmailwrapper.pro16
-rw-r--r--noncore/net/mail/libmailwrapper/mailtypes.cpp19
-rw-r--r--noncore/net/mail/libmailwrapper/mailtypes.h25
-rw-r--r--noncore/net/mail/libmailwrapper/smtpwrapper.cpp464
-rw-r--r--noncore/net/mail/libmailwrapper/smtpwrapper.h32
10 files changed, 625 insertions, 534 deletions
diff --git a/noncore/net/mail/libmailwrapper/generatemail.cpp b/noncore/net/mail/libmailwrapper/generatemail.cpp
new file mode 100644
index 0000000..9272d0c
--- a/dev/null
+++ b/noncore/net/mail/libmailwrapper/generatemail.cpp
@@ -0,0 +1,454 @@
1#include "generatemail.h"
2#include "mailwrapper.h"
3
4#include <libetpan/libetpan.h>
5
6#include <qt.h>
7
8const char* Generatemail::USER_AGENT="OpieMail v0.5";
9
10Generatemail::Generatemail()
11{
12}
13
14Generatemail::~Generatemail()
15{
16}
17
18void Generatemail::addRcpts( clist *list, mailimf_address_list *addr_list ) {
19 clistiter *it, *it2;
20
21 for ( it = clist_begin( addr_list->ad_list ); it; it = it->next ) {
22 mailimf_address *addr;
23 addr = (mailimf_address *) it->data;
24
25 if ( addr->ad_type == MAILIMF_ADDRESS_MAILBOX ) {
26 esmtp_address_list_add( list, addr->ad_data.ad_mailbox->mb_addr_spec, 0, NULL );
27 } else if ( addr->ad_type == MAILIMF_ADDRESS_GROUP ) {
28 clist *l = addr->ad_data.ad_group->grp_mb_list->mb_list;
29 for ( it2 = clist_begin( l ); it2; it2 = it2->next ) {
30 mailimf_mailbox *mbox;
31 mbox = (mailimf_mailbox *) it2->data;
32 esmtp_address_list_add( list, mbox->mb_addr_spec, 0, NULL );
33 }
34 }
35 }
36}
37
38char *Generatemail::getFrom( mailimf_field *ffrom) {
39 char *from = NULL;
40 if ( ffrom && (ffrom->fld_type == MAILIMF_FIELD_FROM)
41 && ffrom->fld_data.fld_from->frm_mb_list && ffrom->fld_data.fld_from->frm_mb_list->mb_list ) {
42 clist *cl = ffrom->fld_data.fld_from->frm_mb_list->mb_list;
43 clistiter *it;
44 for ( it = clist_begin( cl ); it; it = it->next ) {
45 mailimf_mailbox *mb = (mailimf_mailbox *) it->data;
46 from = strdup( mb->mb_addr_spec );
47 }
48 }
49
50 return from;
51}
52
53char *Generatemail::getFrom( mailmime *mail ) {
54 /* no need to delete - its just a pointer to structure content */
55 mailimf_field *ffrom = 0;
56 ffrom = getField( mail->mm_data.mm_message.mm_fields, MAILIMF_FIELD_FROM );
57 return getFrom(ffrom);
58}
59
60mailimf_field *Generatemail::getField( mailimf_fields *fields, int type ) {
61 mailimf_field *field;
62 clistiter *it;
63
64 it = clist_begin( fields->fld_list );
65 while ( it ) {
66 field = (mailimf_field *) it->data;
67 if ( field->fld_type == type ) {
68 return field;
69 }
70 it = it->next;
71 }
72
73 return NULL;
74}
75
76mailimf_address_list *Generatemail::parseAddresses(const QString&addr ) {
77 mailimf_address_list *addresses;
78
79 if ( addr.isEmpty() )
80 return NULL;
81
82 addresses = mailimf_address_list_new_empty();
83
84 bool literal_open = false;
85 unsigned int startpos = 0;
86 QStringList list;
87 QString s;
88 unsigned int i = 0;
89 for (; i < addr.length();++i) {
90 switch (addr[i]) {
91 case '\"':
92 literal_open = !literal_open;
93 break;
94 case ',':
95 if (!literal_open) {
96 s = addr.mid(startpos,i-startpos);
97 if (!s.isEmpty()) {
98 list.append(s);
99 qDebug("Appended %s",s.latin1());
100 }
101 // !!!! this is a MUST BE!
102 startpos = ++i;
103 }
104 break;
105 default:
106 break;
107 }
108 }
109 s = addr.mid(startpos,i-startpos);
110 if (!s.isEmpty()) {
111 list.append(s);
112 qDebug("Appended %s",s.latin1());
113 }
114 QStringList::Iterator it;
115 for ( it = list.begin(); it != list.end(); it++ ) {
116 int err = mailimf_address_list_add_parse( addresses, (char*)(*it).latin1() );
117 if ( err != MAILIMF_NO_ERROR ) {
118 qDebug( "Error parsing" );
119 qDebug( *it );
120 } else {
121 qDebug( "Parse success! %s",(*it).latin1());
122 }
123 }
124 return addresses;
125}
126
127mailmime *Generatemail::buildFilePart(const QString&filename,const QString&mimetype,const QString&TextContent ) {
128 mailmime * filePart = 0;
129 mailmime_fields * fields = 0;
130 mailmime_content * content = 0;
131 mailmime_parameter * param = 0;
132 char*name = 0;
133 char*file = 0;
134 int err;
135
136 int pos = filename.findRev( '/' );
137
138 if (filename.length()>0) {
139 QString tmp = filename.right( filename.length() - ( pos + 1 ) );
140 name = strdup( tmp.latin1() ); // just filename
141 file = strdup( filename.latin1() ); // full name with path
142 }
143
144 int disptype = MAILMIME_DISPOSITION_TYPE_ATTACHMENT;
145 int mechanism = MAILMIME_MECHANISM_BASE64;
146
147 if ( mimetype.startsWith( "text/" ) ) {
148 param = mailmime_parameter_new( strdup( "charset" ),
149 strdup( "iso-8859-1" ) );
150 mechanism = MAILMIME_MECHANISM_QUOTED_PRINTABLE;
151 }
152
153 fields = mailmime_fields_new_filename(
154 disptype, name,
155 mechanism );
156 content = mailmime_content_new_with_str( (char*)mimetype.latin1() );
157 if (content!=0 && fields != 0) {
158 if (param) {
159 clist_append(content->ct_parameters,param);
160 param = 0;
161 }
162 if (filename.length()>0) {
163 QFileInfo f(filename);
164 param = mailmime_parameter_new(strdup("name"),strdup(f.fileName().latin1()));
165 clist_append(content->ct_parameters,param);
166 param = 0;
167 }
168 filePart = mailmime_new_empty( content, fields );
169 }
170 if (filePart) {
171 if (filename.length()>0) {
172 err = mailmime_set_body_file( filePart, file );
173 } else {
174 err = mailmime_set_body_text(filePart,strdup(TextContent.data()),TextContent.length());
175 }
176 if (err != MAILIMF_NO_ERROR) {
177 qDebug("Error setting body with file %s",file);
178 mailmime_free( filePart );
179 filePart = 0;
180 }
181 }
182
183 if (!filePart) {
184 if ( param != NULL ) {
185 mailmime_parameter_free( param );
186 }
187 if (content) {
188 mailmime_content_free( content );
189 }
190 if (fields) {
191 mailmime_fields_free( fields );
192 } else {
193 if (name) {
194 free( name );
195 }
196 if (file) {
197 free( file );
198 }
199 }
200 }
201 return filePart; // Success :)
202
203}
204
205void Generatemail::addFileParts( mailmime *message,const QList<Attachment>&files ) {
206 const Attachment *it;
207 unsigned int count = files.count();
208 qDebug("List contains %i values",count);
209 for ( unsigned int i = 0; i < count; ++i ) {
210 qDebug( "Adding file" );
211 mailmime *filePart;
212 int err;
213 it = ((QList<Attachment>)files).at(i);
214
215 filePart = buildFilePart( it->getFileName(), it->getMimeType(),"" );
216 if ( filePart == NULL ) {
217 qDebug( "addFileParts: error adding file:" );
218 qDebug( it->getFileName() );
219 continue;
220 }
221 err = mailmime_smart_add_part( message, filePart );
222 if ( err != MAILIMF_NO_ERROR ) {
223 mailmime_free( filePart );
224 qDebug("error smart add");
225 }
226 }
227}
228
229mailmime *Generatemail::buildTxtPart(const QString&str ) {
230 mailmime *txtPart;
231 mailmime_fields *fields;
232 mailmime_content *content;
233 mailmime_parameter *param;
234 int err;
235
236 param = mailmime_parameter_new( strdup( "charset" ),
237 strdup( "iso-8859-1" ) );
238 if ( param == NULL )
239 goto err_free;
240
241 content = mailmime_content_new_with_str( "text/plain" );
242 if ( content == NULL )
243 goto err_free_param;
244
245 err = clist_append( content->ct_parameters, param );
246 if ( err != MAILIMF_NO_ERROR )
247 goto err_free_content;
248
249 fields = mailmime_fields_new_encoding(MAILMIME_MECHANISM_8BIT);
250 if ( fields == NULL )
251 goto err_free_content;
252
253 txtPart = mailmime_new_empty( content, fields );
254 if ( txtPart == NULL )
255 goto err_free_fields;
256
257 err = mailmime_set_body_text( txtPart, (char*)str.data(), str.length() );
258 if ( err != MAILIMF_NO_ERROR )
259 goto err_free_txtPart;
260
261 return txtPart; // Success :)
262
263err_free_txtPart:
264 mailmime_free( txtPart );
265err_free_fields:
266 mailmime_fields_free( fields );
267err_free_content:
268 mailmime_content_free( content );
269err_free_param:
270 mailmime_parameter_free( param );
271err_free:
272 qDebug( "buildTxtPart - error" );
273
274 return NULL; // Error :(
275}
276
277mailimf_mailbox *Generatemail::newMailbox(const QString&name, const QString&mail ) {
278 return mailimf_mailbox_new( strdup( name.latin1() ),
279 strdup( mail.latin1() ) );
280}
281
282mailimf_fields *Generatemail::createImfFields(const Mail&mail ) {
283 mailimf_fields *fields;
284 mailimf_field *xmailer;
285 mailimf_mailbox *sender=0,*fromBox=0;
286 mailimf_mailbox_list *from=0;
287 mailimf_address_list *to=0, *cc=0, *bcc=0, *reply=0;
288 clist*in_reply_to = 0;
289 char *subject = strdup( mail.getSubject().latin1() );
290 int err;
291
292 sender = newMailbox( mail.getName(), mail.getMail() );
293 if ( sender == NULL )
294 goto err_free;
295
296 fromBox = newMailbox( mail.getName(), mail.getMail() );
297 if ( fromBox == NULL )
298 goto err_free_sender;
299
300 from = mailimf_mailbox_list_new_empty();
301 if ( from == NULL )
302 goto err_free_fromBox;
303
304 err = mailimf_mailbox_list_add( from, fromBox );
305 if ( err != MAILIMF_NO_ERROR )
306 goto err_free_from;
307
308 to = parseAddresses( mail.getTo() );
309 if ( to == NULL )
310 goto err_free_from;
311
312 cc = parseAddresses( mail.getCC() );
313 bcc = parseAddresses( mail.getBCC() );
314 reply = parseAddresses( mail.getReply() );
315
316 if (mail.Inreply().count()>0) {
317 in_reply_to = clist_new();
318 char*c_reply;
319 unsigned int nsize = 0;
320 for (QStringList::ConstIterator it=mail.Inreply().begin();
321 it != mail.Inreply().end();++it) {
322 if ((*it).isEmpty())
323 continue;
324 QString h((*it));
325 while (h.length()>0 && h[0]=='<') {
326 h.remove(0,1);
327 }
328 while (h.length()>0 && h[h.length()-1]=='>') {
329 h.remove(h.length()-1,1);
330 }
331 if (h.isEmpty()) continue;
332 nsize = strlen(h.latin1());
333 /* yes! must be malloc! */
334 c_reply = (char*)malloc( (nsize+1)*sizeof(char));
335 memset(c_reply,0,nsize+1);
336 memcpy(c_reply,h.latin1(),nsize);
337 clist_append(in_reply_to,c_reply);
338 qDebug("In reply to: %s",c_reply);
339 }
340 }
341
342 fields = mailimf_fields_new_with_data( from, sender, reply, to, cc, bcc,
343 in_reply_to, NULL, subject );
344 if ( fields == NULL )
345 goto err_free_reply;
346
347 xmailer = mailimf_field_new_custom( strdup( "User-Agent" ),
348 strdup( USER_AGENT ) );
349 if ( xmailer == NULL )
350 goto err_free_fields;
351
352 err = mailimf_fields_add( fields, xmailer );
353 if ( err != MAILIMF_NO_ERROR )
354 goto err_free_xmailer;
355
356 return fields; // Success :)
357
358err_free_xmailer:
359 if (xmailer)
360 mailimf_field_free( xmailer );
361err_free_fields:
362 if (fields)
363 mailimf_fields_free( fields );
364err_free_reply:
365 if (reply)
366 mailimf_address_list_free( reply );
367 if (bcc)
368 mailimf_address_list_free( bcc );
369 if (cc)
370 mailimf_address_list_free( cc );
371 if (to)
372 mailimf_address_list_free( to );
373err_free_from:
374 if (from)
375 mailimf_mailbox_list_free( from );
376err_free_fromBox:
377 mailimf_mailbox_free( fromBox );
378err_free_sender:
379 if (sender)
380 mailimf_mailbox_free( sender );
381err_free:
382 if (subject)
383 free( subject );
384 qDebug( "createImfFields - error" );
385
386 return NULL; // Error :(
387}
388
389mailmime *Generatemail::createMimeMail(const Mail &mail ) {
390 mailmime *message, *txtPart;
391 mailimf_fields *fields;
392 int err;
393
394 fields = createImfFields( mail );
395 if ( fields == NULL )
396 goto err_free;
397
398 message = mailmime_new_message_data( NULL );
399 if ( message == NULL )
400 goto err_free_fields;
401
402 mailmime_set_imf_fields( message, fields );
403
404 txtPart = buildTxtPart( mail.getMessage() );
405
406 if ( txtPart == NULL )
407 goto err_free_message;
408
409 err = mailmime_smart_add_part( message, txtPart );
410 if ( err != MAILIMF_NO_ERROR )
411 goto err_free_txtPart;
412
413 addFileParts( message, mail.getAttachments() );
414
415 return message; // Success :)
416
417err_free_txtPart:
418 mailmime_free( txtPart );
419err_free_message:
420 mailmime_free( message );
421err_free_fields:
422 mailimf_fields_free( fields );
423err_free:
424 qDebug( "createMimeMail: error" );
425
426 return NULL; // Error :(
427}
428
429clist *Generatemail::createRcptList( mailimf_fields *fields ) {
430 clist *rcptList;
431 mailimf_field *field;
432
433 rcptList = esmtp_address_list_new();
434
435 field = getField( fields, MAILIMF_FIELD_TO );
436 if ( field && (field->fld_type == MAILIMF_FIELD_TO)
437 && field->fld_data.fld_to->to_addr_list ) {
438 addRcpts( rcptList, field->fld_data.fld_to->to_addr_list );
439 }
440
441 field = getField( fields, MAILIMF_FIELD_CC );
442 if ( field && (field->fld_type == MAILIMF_FIELD_CC)
443 && field->fld_data.fld_cc->cc_addr_list ) {
444 addRcpts( rcptList, field->fld_data.fld_cc->cc_addr_list );
445 }
446
447 field = getField( fields, MAILIMF_FIELD_BCC );
448 if ( field && (field->fld_type == MAILIMF_FIELD_BCC)
449 && field->fld_data.fld_bcc->bcc_addr_list ) {
450 addRcpts( rcptList, field->fld_data.fld_bcc->bcc_addr_list );
451 }
452
453 return rcptList;
454}
diff --git a/noncore/net/mail/libmailwrapper/generatemail.h b/noncore/net/mail/libmailwrapper/generatemail.h
new file mode 100644
index 0000000..8be5a2b
--- a/dev/null
+++ b/noncore/net/mail/libmailwrapper/generatemail.h
@@ -0,0 +1,44 @@
1#ifndef __GENERATE_MAIL_H
2#define __GENERATE_MAIL_H
3
4#include <qpe/applnk.h>
5
6#include <qobject.h>
7#include <libetpan/clist.h>
8
9class Mail;
10class RecMail;
11class Attachment;
12struct mailimf_fields;
13struct mailimf_field;
14struct mailimf_mailbox;
15struct mailmime;
16struct mailimf_address_list;
17class progressMailSend;
18struct mailsmtp;
19
20class Generatemail : public QObject
21{
22 Q_OBJECT
23public:
24 Generatemail();
25 virtual ~Generatemail();
26
27protected:
28 static void addRcpts( clist *list, mailimf_address_list *addr_list );
29 static char *getFrom( mailmime *mail );
30 static char *getFrom( mailimf_field *ffrom);
31 static mailimf_field *getField( mailimf_fields *fields, int type );
32 mailimf_address_list *parseAddresses(const QString&addr );
33 void addFileParts( mailmime *message,const QList<Attachment>&files );
34 mailmime *buildFilePart(const QString&filename,const QString&mimetype,const QString&content);
35 mailmime *buildTxtPart(const QString&str );
36 mailimf_mailbox *newMailbox(const QString&name,const QString&mail );
37 mailimf_fields *createImfFields(const Mail &mail );
38 mailmime *createMimeMail(const Mail&mail );
39 clist *createRcptList( mailimf_fields *fields );
40
41 static const char* USER_AGENT;
42};
43
44#endif
diff --git a/noncore/net/mail/libmailwrapper/genericwrapper.cpp b/noncore/net/mail/libmailwrapper/genericwrapper.cpp
index eb2c031..137a6ef 100644
--- a/noncore/net/mail/libmailwrapper/genericwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/genericwrapper.cpp
@@ -1,441 +1,467 @@
1#include "genericwrapper.h" 1#include "genericwrapper.h"
2#include <libetpan/libetpan.h> 2#include <libetpan/libetpan.h>
3#include "mailtypes.h" 3#include "mailtypes.h"
4 4
5Genericwrapper::Genericwrapper() 5Genericwrapper::Genericwrapper()
6 : AbstractMail() 6 : AbstractMail()
7{ 7{
8 bodyCache.clear(); 8 bodyCache.clear();
9 m_storage = 0; 9 m_storage = 0;
10 m_folder = 0; 10 m_folder = 0;
11} 11}
12 12
13Genericwrapper::~Genericwrapper() 13Genericwrapper::~Genericwrapper()
14{ 14{
15 if (m_folder) { 15 if (m_folder) {
16 mailfolder_free(m_folder); 16 mailfolder_free(m_folder);
17 } 17 }
18 if (m_storage) { 18 if (m_storage) {
19 mailstorage_free(m_storage); 19 mailstorage_free(m_storage);
20 } 20 }
21 cleanMimeCache(); 21 cleanMimeCache();
22} 22}
23 23
24void Genericwrapper::fillSingleBody(RecPart&target,mailmessage*,mailmime*mime) 24void Genericwrapper::fillSingleBody(RecPart&target,mailmessage*,mailmime*mime)
25{ 25{
26 if (!mime) { 26 if (!mime) {
27 return; 27 return;
28 } 28 }
29 mailmime_field*field = 0; 29 mailmime_field*field = 0;
30 mailmime_single_fields fields; 30 mailmime_single_fields fields;
31 memset(&fields, 0, sizeof(struct mailmime_single_fields)); 31 memset(&fields, 0, sizeof(struct mailmime_single_fields));
32 if (mime->mm_mime_fields != NULL) { 32 if (mime->mm_mime_fields != NULL) {
33 mailmime_single_fields_init(&fields, mime->mm_mime_fields, 33 mailmime_single_fields_init(&fields, mime->mm_mime_fields,
34 mime->mm_content_type); 34 mime->mm_content_type);
35 } 35 }
36 36
37 mailmime_content*type = fields.fld_content; 37 mailmime_content*type = fields.fld_content;
38 clistcell*current; 38 clistcell*current;
39 if (!type) { 39 if (!type) {
40 target.setType("text"); 40 target.setType("text");
41 target.setSubtype("plain"); 41 target.setSubtype("plain");
42 } else { 42 } else {
43 target.setSubtype(type->ct_subtype); 43 target.setSubtype(type->ct_subtype);
44 switch(type->ct_type->tp_data.tp_discrete_type->dt_type) { 44 switch(type->ct_type->tp_data.tp_discrete_type->dt_type) {
45 case MAILMIME_DISCRETE_TYPE_TEXT: 45 case MAILMIME_DISCRETE_TYPE_TEXT:
46 target.setType("text"); 46 target.setType("text");
47 break; 47 break;
48 case MAILMIME_DISCRETE_TYPE_IMAGE: 48 case MAILMIME_DISCRETE_TYPE_IMAGE:
49 target.setType("image"); 49 target.setType("image");
50 break; 50 break;
51 case MAILMIME_DISCRETE_TYPE_AUDIO: 51 case MAILMIME_DISCRETE_TYPE_AUDIO:
52 target.setType("audio"); 52 target.setType("audio");
53 break; 53 break;
54 case MAILMIME_DISCRETE_TYPE_VIDEO: 54 case MAILMIME_DISCRETE_TYPE_VIDEO:
55 target.setType("video"); 55 target.setType("video");
56 break; 56 break;
57 case MAILMIME_DISCRETE_TYPE_APPLICATION: 57 case MAILMIME_DISCRETE_TYPE_APPLICATION:
58 target.setType("application"); 58 target.setType("application");
59 break; 59 break;
60 case MAILMIME_DISCRETE_TYPE_EXTENSION: 60 case MAILMIME_DISCRETE_TYPE_EXTENSION:
61 default: 61 default:
62 if (type->ct_type->tp_data.tp_discrete_type->dt_extension) { 62 if (type->ct_type->tp_data.tp_discrete_type->dt_extension) {
63 target.setType(type->ct_type->tp_data.tp_discrete_type->dt_extension); 63 target.setType(type->ct_type->tp_data.tp_discrete_type->dt_extension);
64 } 64 }
65 break; 65 break;
66 } 66 }
67 if (type->ct_parameters) { 67 if (type->ct_parameters) {
68 fillParameters(target,type->ct_parameters); 68 fillParameters(target,type->ct_parameters);
69 } 69 }
70 } 70 }
71 if (mime->mm_mime_fields && mime->mm_mime_fields->fld_list) { 71 if (mime->mm_mime_fields && mime->mm_mime_fields->fld_list) {
72 for (current=clist_begin(mime->mm_mime_fields->fld_list);current!=0;current=clist_next(current)) { 72 for (current=clist_begin(mime->mm_mime_fields->fld_list);current!=0;current=clist_next(current)) {
73 field = (mailmime_field*)current->data; 73 field = (mailmime_field*)current->data;
74 switch(field->fld_type) { 74 switch(field->fld_type) {
75 case MAILMIME_FIELD_TRANSFER_ENCODING: 75 case MAILMIME_FIELD_TRANSFER_ENCODING:
76 target.setEncoding(getencoding(field->fld_data.fld_encoding)); 76 target.setEncoding(getencoding(field->fld_data.fld_encoding));
77 break; 77 break;
78 case MAILMIME_FIELD_ID: 78 case MAILMIME_FIELD_ID:
79 target.setIdentifier(field->fld_data.fld_id); 79 target.setIdentifier(field->fld_data.fld_id);
80 break; 80 break;
81 case MAILMIME_FIELD_DESCRIPTION: 81 case MAILMIME_FIELD_DESCRIPTION:
82 target.setDescription(field->fld_data.fld_description); 82 target.setDescription(field->fld_data.fld_description);
83 break; 83 break;
84 default: 84 default:
85 break; 85 break;
86 } 86 }
87 } 87 }
88 } 88 }
89} 89}
90 90
91void Genericwrapper::fillParameters(RecPart&target,clist*parameters) 91void Genericwrapper::fillParameters(RecPart&target,clist*parameters)
92{ 92{
93 if (!parameters) {return;} 93 if (!parameters) {return;}
94 clistcell*current=0; 94 clistcell*current=0;
95 mailmime_parameter*param; 95 mailmime_parameter*param;
96 for (current=clist_begin(parameters);current!=0;current=clist_next(current)) { 96 for (current=clist_begin(parameters);current!=0;current=clist_next(current)) {
97 param = (mailmime_parameter*)current->data; 97 param = (mailmime_parameter*)current->data;
98 if (param) { 98 if (param) {
99 target.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); 99 target.addParameter(QString(param->pa_name).lower(),QString(param->pa_value));
100 } 100 }
101 } 101 }
102} 102}
103 103
104QString Genericwrapper::getencoding(mailmime_mechanism*aEnc) 104QString Genericwrapper::getencoding(mailmime_mechanism*aEnc)
105{ 105{
106 QString enc="7bit"; 106 QString enc="7bit";
107 if (!aEnc) return enc; 107 if (!aEnc) return enc;
108 switch(aEnc->enc_type) { 108 switch(aEnc->enc_type) {
109 case MAILMIME_MECHANISM_7BIT: 109 case MAILMIME_MECHANISM_7BIT:
110 enc = "7bit"; 110 enc = "7bit";
111 break; 111 break;
112 case MAILMIME_MECHANISM_8BIT: 112 case MAILMIME_MECHANISM_8BIT:
113 enc = "8bit"; 113 enc = "8bit";
114 break; 114 break;
115 case MAILMIME_MECHANISM_BINARY: 115 case MAILMIME_MECHANISM_BINARY:
116 enc = "binary"; 116 enc = "binary";
117 break; 117 break;
118 case MAILMIME_MECHANISM_QUOTED_PRINTABLE: 118 case MAILMIME_MECHANISM_QUOTED_PRINTABLE:
119 enc = "quoted-printable"; 119 enc = "quoted-printable";
120 break; 120 break;
121 case MAILMIME_MECHANISM_BASE64: 121 case MAILMIME_MECHANISM_BASE64:
122 enc = "base64"; 122 enc = "base64";
123 break; 123 break;
124 case MAILMIME_MECHANISM_TOKEN: 124 case MAILMIME_MECHANISM_TOKEN:
125 default: 125 default:
126 if (aEnc->enc_token) { 126 if (aEnc->enc_token) {
127 enc = QString(aEnc->enc_token); 127 enc = QString(aEnc->enc_token);
128 } 128 }
129 break; 129 break;
130 } 130 }
131 return enc; 131 return enc;
132} 132}
133 133
134void Genericwrapper::traverseBody(RecBody&target,mailmessage*message,mailmime*mime,QValueList<int>recList,unsigned int current_rec,int current_count) 134void Genericwrapper::traverseBody(RecBody&target,mailmessage*message,mailmime*mime,QValueList<int>recList,unsigned int current_rec,int current_count)
135{ 135{
136 if (current_rec >= 10) { 136 if (current_rec >= 10) {
137 qDebug("too deep recursion!"); 137 qDebug("too deep recursion!");
138 } 138 }
139 if (!message || !mime) { 139 if (!message || !mime) {
140 return; 140 return;
141 } 141 }
142 int r; 142 int r;
143 char*data = 0; 143 char*data = 0;
144 size_t len; 144 size_t len;
145 clistiter * cur = 0; 145 clistiter * cur = 0;
146 QString b; 146 QString b;
147 RecPart part; 147 RecPart part;
148 148
149 switch (mime->mm_type) { 149 switch (mime->mm_type) {
150 case MAILMIME_SINGLE: 150 case MAILMIME_SINGLE:
151 { 151 {
152 QValueList<int>countlist = recList; 152 QValueList<int>countlist = recList;
153 countlist.append(current_count); 153 countlist.append(current_count);
154 r = mailmessage_fetch_section(message,mime,&data,&len); 154 r = mailmessage_fetch_section(message,mime,&data,&len);
155 part.setSize(len); 155 part.setSize(len);
156 part.setPositionlist(countlist); 156 part.setPositionlist(countlist);
157 b = gen_attachment_id(); 157 b = gen_attachment_id();
158 part.setIdentifier(b); 158 part.setIdentifier(b);
159 fillSingleBody(part,message,mime); 159 fillSingleBody(part,message,mime);
160 if (part.Type()=="text" && target.Bodytext().isNull()) { 160 if (part.Type()=="text" && target.Bodytext().isNull()) {
161 encodedString*r = new encodedString(); 161 encodedString*r = new encodedString();
162 r->setContent(data,len); 162 r->setContent(data,len);
163 encodedString*res = decode_String(r,part.Encoding()); 163 encodedString*res = decode_String(r,part.Encoding());
164 if (countlist.count()>2) { 164 if (countlist.count()>2) {
165 bodyCache[b]=r; 165 bodyCache[b]=r;
166 target.addPart(part); 166 target.addPart(part);
167 } else { 167 } else {
168 delete r; 168 delete r;
169 } 169 }
170 b = QString(res->Content()); 170 b = QString(res->Content());
171 delete res; 171 delete res;
172 target.setBodytext(b); 172 target.setBodytext(b);
173 target.setDescription(part); 173 target.setDescription(part);
174 } else { 174 } else {
175 bodyCache[b]=new encodedString(data,len); 175 bodyCache[b]=new encodedString(data,len);
176 target.addPart(part); 176 target.addPart(part);
177 } 177 }
178 } 178 }
179 break; 179 break;
180 case MAILMIME_MULTIPLE: 180 case MAILMIME_MULTIPLE:
181 { 181 {
182 unsigned int ccount = 1; 182 unsigned int ccount = 1;
183 mailmime*cbody=0; 183 mailmime*cbody=0;
184 QValueList<int>countlist = recList; 184 QValueList<int>countlist = recList;
185 for (cur = clist_begin(mime->mm_data.mm_multipart.mm_mp_list) ; cur != NULL ; cur = clist_next(cur)) { 185 for (cur = clist_begin(mime->mm_data.mm_multipart.mm_mp_list) ; cur != NULL ; cur = clist_next(cur)) {
186 cbody = (mailmime*)clist_content(cur); 186 cbody = (mailmime*)clist_content(cur);
187 if (cbody->mm_type==MAILMIME_MULTIPLE) { 187 if (cbody->mm_type==MAILMIME_MULTIPLE) {
188 RecPart targetPart; 188 RecPart targetPart;
189 targetPart.setType("multipart"); 189 targetPart.setType("multipart");
190 countlist.append(current_count); 190 countlist.append(current_count);
191 targetPart.setPositionlist(countlist); 191 targetPart.setPositionlist(countlist);
192 target.addPart(targetPart); 192 target.addPart(targetPart);
193 } 193 }
194 traverseBody(target,message, cbody,countlist,current_rec+1,ccount); 194 traverseBody(target,message, cbody,countlist,current_rec+1,ccount);
195 if (cbody->mm_type==MAILMIME_MULTIPLE) { 195 if (cbody->mm_type==MAILMIME_MULTIPLE) {
196 countlist = recList; 196 countlist = recList;
197 } 197 }
198 ++ccount; 198 ++ccount;
199 } 199 }
200 } 200 }
201 break; 201 break;
202 case MAILMIME_MESSAGE: 202 case MAILMIME_MESSAGE:
203 { 203 {
204 QValueList<int>countlist = recList; 204 QValueList<int>countlist = recList;
205 countlist.append(current_count); 205 countlist.append(current_count);
206 /* the own header is always at recursion 0 - we don't need that */ 206 /* the own header is always at recursion 0 - we don't need that */
207 if (current_rec > 0) { 207 if (current_rec > 0) {
208 part.setPositionlist(countlist); 208 part.setPositionlist(countlist);
209 r = mailmessage_fetch_section(message,mime,&data,&len); 209 r = mailmessage_fetch_section(message,mime,&data,&len);
210 part.setSize(len); 210 part.setSize(len);
211 part.setPositionlist(countlist); 211 part.setPositionlist(countlist);
212 b = gen_attachment_id(); 212 b = gen_attachment_id();
213 part.setIdentifier(b); 213 part.setIdentifier(b);
214 part.setType("message"); 214 part.setType("message");
215 part.setSubtype("rfc822"); 215 part.setSubtype("rfc822");
216 bodyCache[b]=new encodedString(data,len); 216 bodyCache[b]=new encodedString(data,len);
217 target.addPart(part); 217 target.addPart(part);
218 } 218 }
219 if (mime->mm_data.mm_message.mm_msg_mime != NULL) { 219 if (mime->mm_data.mm_message.mm_msg_mime != NULL) {
220 traverseBody(target,message,mime->mm_data.mm_message.mm_msg_mime,countlist,current_rec+1); 220 traverseBody(target,message,mime->mm_data.mm_message.mm_msg_mime,countlist,current_rec+1);
221 } 221 }
222 } 222 }
223 break; 223 break;
224 } 224 }
225} 225}
226 226
227RecBody Genericwrapper::parseMail( mailmessage * msg ) 227RecBody Genericwrapper::parseMail( mailmessage * msg )
228{ 228{
229 int err = MAILIMF_NO_ERROR; 229 int err = MAILIMF_NO_ERROR;
230 mailmime_single_fields fields; 230 mailmime_single_fields fields;
231 /* is bound to msg and will be freed there */ 231 /* is bound to msg and will be freed there */
232 mailmime * mime=0; 232 mailmime * mime=0;
233 RecBody body; 233 RecBody body;
234 memset(&fields, 0, sizeof(struct mailmime_single_fields)); 234 memset(&fields, 0, sizeof(struct mailmime_single_fields));
235 err = mailmessage_get_bodystructure(msg,&mime); 235 err = mailmessage_get_bodystructure(msg,&mime);
236 QValueList<int>recList; 236 QValueList<int>recList;
237 traverseBody(body,msg,mime,recList); 237 traverseBody(body,msg,mime,recList);
238 return body; 238 return body;
239} 239}
240 240
241QString Genericwrapper::parseDateTime( mailimf_date_time *date ) 241QString Genericwrapper::parseDateTime( mailimf_date_time *date )
242{ 242{
243 char tmp[23]; 243 char tmp[23];
244 244
245 snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i", 245 snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i",
246 date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone ); 246 date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone );
247 247
248 return QString( tmp ); 248 return QString( tmp );
249} 249}
250 250
251QString Genericwrapper::parseAddressList( mailimf_address_list *list ) 251QString Genericwrapper::parseAddressList( mailimf_address_list *list )
252{ 252{
253 QString result( "" ); 253 QString result( "" );
254 254
255 bool first = true; 255 bool first = true;
256 if (list == 0) return result; 256 if (list == 0) return result;
257 for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) { 257 for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) {
258 mailimf_address *addr = (mailimf_address *) current->data; 258 mailimf_address *addr = (mailimf_address *) current->data;
259 259
260 if ( !first ) { 260 if ( !first ) {
261 result.append( "," ); 261 result.append( "," );
262 } else { 262 } else {
263 first = false; 263 first = false;
264 } 264 }
265 265
266 switch ( addr->ad_type ) { 266 switch ( addr->ad_type ) {
267 case MAILIMF_ADDRESS_MAILBOX: 267 case MAILIMF_ADDRESS_MAILBOX:
268 result.append( parseMailbox( addr->ad_data.ad_mailbox ) ); 268 result.append( parseMailbox( addr->ad_data.ad_mailbox ) );
269 break; 269 break;
270 case MAILIMF_ADDRESS_GROUP: 270 case MAILIMF_ADDRESS_GROUP:
271 result.append( parseGroup( addr->ad_data.ad_group ) ); 271 result.append( parseGroup( addr->ad_data.ad_group ) );
272 break; 272 break;
273 default: 273 default:
274 qDebug( "Generic: unkown mailimf address type" ); 274 qDebug( "Generic: unkown mailimf address type" );
275 break; 275 break;
276 } 276 }
277 } 277 }
278 278
279 return result; 279 return result;
280} 280}
281 281
282QString Genericwrapper::parseGroup( mailimf_group *group ) 282QString Genericwrapper::parseGroup( mailimf_group *group )
283{ 283{
284 QString result( "" ); 284 QString result( "" );
285 285
286 result.append( group->grp_display_name ); 286 result.append( group->grp_display_name );
287 result.append( ": " ); 287 result.append( ": " );
288 288
289 if ( group->grp_mb_list != NULL ) { 289 if ( group->grp_mb_list != NULL ) {
290 result.append( parseMailboxList( group->grp_mb_list ) ); 290 result.append( parseMailboxList( group->grp_mb_list ) );
291 } 291 }
292 292
293 result.append( ";" ); 293 result.append( ";" );
294 294
295 return result; 295 return result;
296} 296}
297 297
298QString Genericwrapper::parseMailbox( mailimf_mailbox *box ) 298QString Genericwrapper::parseMailbox( mailimf_mailbox *box )
299{ 299{
300 QString result( "" ); 300 QString result( "" );
301 301
302 if ( box->mb_display_name == NULL ) { 302 if ( box->mb_display_name == NULL ) {
303 result.append( box->mb_addr_spec ); 303 result.append( box->mb_addr_spec );
304 } else { 304 } else {
305 result.append( convert_String(box->mb_display_name).latin1() ); 305 result.append( convert_String(box->mb_display_name).latin1() );
306 result.append( " <" ); 306 result.append( " <" );
307 result.append( box->mb_addr_spec ); 307 result.append( box->mb_addr_spec );
308 result.append( ">" ); 308 result.append( ">" );
309 } 309 }
310 310
311 return result; 311 return result;
312} 312}
313 313
314QString Genericwrapper::parseMailboxList( mailimf_mailbox_list *list ) 314QString Genericwrapper::parseMailboxList( mailimf_mailbox_list *list )
315{ 315{
316 QString result( "" ); 316 QString result( "" );
317 317
318 bool first = true; 318 bool first = true;
319 for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) { 319 for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) {
320 mailimf_mailbox *box = (mailimf_mailbox *) current->data; 320 mailimf_mailbox *box = (mailimf_mailbox *) current->data;
321 321
322 if ( !first ) { 322 if ( !first ) {
323 result.append( "," ); 323 result.append( "," );
324 } else { 324 } else {
325 first = false; 325 first = false;
326 } 326 }
327 327
328 result.append( parseMailbox( box ) ); 328 result.append( parseMailbox( box ) );
329 } 329 }
330 330
331 return result; 331 return result;
332} 332}
333 333
334encodedString* Genericwrapper::fetchDecodedPart(const RecMail&,const RecPart&part) 334encodedString* Genericwrapper::fetchDecodedPart(const RecMail&,const RecPart&part)
335{ 335{
336 QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part.Identifier()); 336 QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part.Identifier());
337 if (it==bodyCache.end()) return new encodedString(); 337 if (it==bodyCache.end()) return new encodedString();
338 encodedString*t = decode_String(it.data(),part.Encoding()); 338 encodedString*t = decode_String(it.data(),part.Encoding());
339 return t; 339 return t;
340} 340}
341 341
342encodedString* Genericwrapper::fetchRawPart(const RecMail&mail,const RecPart&part) 342encodedString* Genericwrapper::fetchRawPart(const RecMail&mail,const RecPart&part)
343{ 343{
344 QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part.Identifier()); 344 QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part.Identifier());
345 if (it==bodyCache.end()) return new encodedString(); 345 if (it==bodyCache.end()) return new encodedString();
346 encodedString*t = it.data(); 346 encodedString*t = it.data();
347 return t; 347 return t;
348} 348}
349 349
350QString Genericwrapper::fetchTextPart(const RecMail&mail,const RecPart&part) 350QString Genericwrapper::fetchTextPart(const RecMail&mail,const RecPart&part)
351{ 351{
352 encodedString*t = fetchDecodedPart(mail,part); 352 encodedString*t = fetchDecodedPart(mail,part);
353 QString text=t->Content(); 353 QString text=t->Content();
354 delete t; 354 delete t;
355 return text; 355 return text;
356} 356}
357 357
358void Genericwrapper::cleanMimeCache() 358void Genericwrapper::cleanMimeCache()
359{ 359{
360 QMap<QString,encodedString*>::Iterator it = bodyCache.begin(); 360 QMap<QString,encodedString*>::Iterator it = bodyCache.begin();
361 for (;it!=bodyCache.end();++it) { 361 for (;it!=bodyCache.end();++it) {
362 encodedString*t = it.data(); 362 encodedString*t = it.data();
363 //it.setValue(0); 363 //it.setValue(0);
364 if (t) delete t; 364 if (t) delete t;
365 } 365 }
366 bodyCache.clear(); 366 bodyCache.clear();
367 qDebug("Genericwrapper: cache cleaned"); 367 qDebug("Genericwrapper: cache cleaned");
368} 368}
369 369
370QStringList Genericwrapper::parseInreplies(mailimf_in_reply_to * in_replies)
371{
372 QStringList res;
373 if (!in_replies || !in_replies->mid_list) return res;
374 clistiter * current = 0;
375 for ( current = clist_begin( in_replies->mid_list ); current != NULL; current = current->next ) {
376 QString h((char*)current->data);
377 while (h.length()>0 && h[0]=='<') {
378 h.remove(0,1);
379 }
380 while (h.length()>0 && h[h.length()-1]=='>') {
381 h.remove(h.length()-1,1);
382 }
383 if (h.length()>0) {
384 res.append(h);
385 }
386 }
387 return res;
388}
389
370void Genericwrapper::parseList(QList<RecMail> &target,mailsession*session,const QString&mailbox,bool mbox_as_to) 390void Genericwrapper::parseList(QList<RecMail> &target,mailsession*session,const QString&mailbox,bool mbox_as_to)
371{ 391{
372 int r; 392 int r;
373 mailmessage_list * env_list = 0; 393 mailmessage_list * env_list = 0;
374 r = mailsession_get_messages_list(session,&env_list); 394 r = mailsession_get_messages_list(session,&env_list);
375 if (r != MAIL_NO_ERROR) { 395 if (r != MAIL_NO_ERROR) {
376 qDebug("Error message list"); 396 qDebug("Error message list");
377 return; 397 return;
378 } 398 }
379 r = mailsession_get_envelopes_list(session, env_list); 399 r = mailsession_get_envelopes_list(session, env_list);
380 if (r != MAIL_NO_ERROR) { 400 if (r != MAIL_NO_ERROR) {
381 qDebug("Error filling message list"); 401 qDebug("Error filling message list");
382 if (env_list) { 402 if (env_list) {
383 mailmessage_list_free(env_list); 403 mailmessage_list_free(env_list);
384 } 404 }
385 return; 405 return;
386 } 406 }
387 mailimf_references * refs; 407 mailimf_references * refs = 0;
408 mailimf_in_reply_to * in_replies = 0;
388 uint32_t i = 0; 409 uint32_t i = 0;
389 for(; i < carray_count(env_list->msg_tab) ; ++i) { 410 for(; i < carray_count(env_list->msg_tab) ; ++i) {
390 mailmessage * msg; 411 mailmessage * msg;
391 QBitArray mFlags(7); 412 QBitArray mFlags(7);
392 msg = (mailmessage*)carray_get(env_list->msg_tab, i); 413 msg = (mailmessage*)carray_get(env_list->msg_tab, i);
393 if (msg->msg_fields == NULL) { 414 if (msg->msg_fields == NULL) {
394 //qDebug("could not fetch envelope of message %i", i); 415 //qDebug("could not fetch envelope of message %i", i);
395 continue; 416 continue;
396 } 417 }
397 RecMail * mail = new RecMail(); 418 RecMail * mail = new RecMail();
398 mail->setWrapper(this); 419 mail->setWrapper(this);
399 mail_flags * flag_result = 0; 420 mail_flags * flag_result = 0;
400 r = mailmessage_get_flags(msg,&flag_result); 421 r = mailmessage_get_flags(msg,&flag_result);
401 if (r == MAIL_ERROR_NOT_IMPLEMENTED) { 422 if (r == MAIL_ERROR_NOT_IMPLEMENTED) {
402 mFlags.setBit(FLAG_SEEN); 423 mFlags.setBit(FLAG_SEEN);
403 } 424 }
404 mailimf_single_fields single_fields; 425 mailimf_single_fields single_fields;
405 mailimf_single_fields_init(&single_fields, msg->msg_fields); 426 mailimf_single_fields_init(&single_fields, msg->msg_fields);
406 mail->setMsgsize(msg->msg_size); 427 mail->setMsgsize(msg->msg_size);
407 mail->setFlags(mFlags); 428 mail->setFlags(mFlags);
408 mail->setMbox(mailbox); 429 mail->setMbox(mailbox);
409 mail->setNumber(msg->msg_index); 430 mail->setNumber(msg->msg_index);
410 if (single_fields.fld_subject) 431 if (single_fields.fld_subject)
411 mail->setSubject( convert_String(single_fields.fld_subject->sbj_value)); 432 mail->setSubject( convert_String(single_fields.fld_subject->sbj_value));
412 if (single_fields.fld_from) 433 if (single_fields.fld_from)
413 mail->setFrom(parseMailboxList(single_fields.fld_from->frm_mb_list)); 434 mail->setFrom(parseMailboxList(single_fields.fld_from->frm_mb_list));
414 if (!mbox_as_to) { 435 if (!mbox_as_to) {
415 if (single_fields.fld_to) 436 if (single_fields.fld_to)
416 mail->setTo( parseAddressList( single_fields.fld_to->to_addr_list ) ); 437 mail->setTo( parseAddressList( single_fields.fld_to->to_addr_list ) );
417 } else { 438 } else {
418 mail->setTo(mailbox); 439 mail->setTo(mailbox);
419 } 440 }
420 if (single_fields.fld_cc) 441 if (single_fields.fld_cc)
421 mail->setCC( parseAddressList( single_fields.fld_cc->cc_addr_list ) ); 442 mail->setCC( parseAddressList( single_fields.fld_cc->cc_addr_list ) );
422 if (single_fields.fld_bcc) 443 if (single_fields.fld_bcc)
423 mail->setBcc( parseAddressList( single_fields.fld_bcc->bcc_addr_list ) ); 444 mail->setBcc( parseAddressList( single_fields.fld_bcc->bcc_addr_list ) );
424 if (single_fields.fld_orig_date) 445 if (single_fields.fld_orig_date)
425 mail->setDate( parseDateTime( single_fields.fld_orig_date->dt_date_time ) ); 446 mail->setDate( parseDateTime( single_fields.fld_orig_date->dt_date_time ) );
426 // crashes when accessing pop3 account? 447 // crashes when accessing pop3 account?
427 if (single_fields.fld_message_id->mid_value) { 448 if (single_fields.fld_message_id->mid_value) {
428 mail->setMsgid(QString(single_fields.fld_message_id->mid_value)); 449 mail->setMsgid(QString(single_fields.fld_message_id->mid_value));
429 qDebug("Msqgid == %s",mail->Msgid().latin1()); 450 qDebug("Msgid == %s",mail->Msgid().latin1());
430 } 451 }
452
431 refs = single_fields.fld_references; 453 refs = single_fields.fld_references;
432 if (refs && refs->mid_list && clist_count(refs->mid_list)) { 454 if (refs && refs->mid_list && clist_count(refs->mid_list)) {
433 char * text = (char*)refs->mid_list->first->data; 455 char * text = (char*)refs->mid_list->first->data;
434 mail->setReplyto(QString(text)); 456 mail->setReplyto(QString(text));
435 } 457 }
458 if (single_fields.fld_in_reply_to && single_fields.fld_in_reply_to->mid_list &&
459 clist_count(single_fields.fld_in_reply_to->mid_list)) {
460 mail->setInreply(parseInreplies(single_fields.fld_in_reply_to));
461 }
436 target.append(mail); 462 target.append(mail);
437 } 463 }
438 if (env_list) { 464 if (env_list) {
439 mailmessage_list_free(env_list); 465 mailmessage_list_free(env_list);
440 } 466 }
441} 467}
diff --git a/noncore/net/mail/libmailwrapper/genericwrapper.h b/noncore/net/mail/libmailwrapper/genericwrapper.h
index 0870912..b3cd4fe 100644
--- a/noncore/net/mail/libmailwrapper/genericwrapper.h
+++ b/noncore/net/mail/libmailwrapper/genericwrapper.h
@@ -1,65 +1,67 @@
1#ifndef __GENERIC_WRAPPER_H 1#ifndef __GENERIC_WRAPPER_H
2#define __GENERIC_WRAPPER_H 2#define __GENERIC_WRAPPER_H
3 3
4#include "abstractmail.h" 4#include "abstractmail.h"
5#include <qmap.h> 5#include <qmap.h>
6#include <qstring.h> 6#include <qstring.h>
7#include <libetpan/clist.h> 7#include <libetpan/clist.h>
8 8
9class RecMail; 9class RecMail;
10class RecBody; 10class RecBody;
11class encodedString; 11class encodedString;
12struct mailpop3; 12struct mailpop3;
13struct mailmessage; 13struct mailmessage;
14struct mailmime; 14struct mailmime;
15struct mailmime_mechanism; 15struct mailmime_mechanism;
16struct mailimf_mailbox_list; 16struct mailimf_mailbox_list;
17struct mailimf_mailbox; 17struct mailimf_mailbox;
18struct mailimf_date_time; 18struct mailimf_date_time;
19struct mailimf_group; 19struct mailimf_group;
20struct mailimf_address_list; 20struct mailimf_address_list;
21struct mailsession; 21struct mailsession;
22struct mailstorage; 22struct mailstorage;
23struct mailfolder; 23struct mailfolder;
24struct mailimf_in_reply_to;
24 25
25/* this class hold just the funs shared between 26/* this class hold just the funs shared between
26 * mbox and pop3 (later mh, too) mail access. 27 * mbox and pop3 (later mh, too) mail access.
27 * it is not desigend to make a instance of it! 28 * it is not desigend to make a instance of it!
28 */ 29 */
29class Genericwrapper : public AbstractMail 30class Genericwrapper : public AbstractMail
30{ 31{
31 Q_OBJECT 32 Q_OBJECT
32public: 33public:
33 Genericwrapper(); 34 Genericwrapper();
34 virtual ~Genericwrapper(); 35 virtual ~Genericwrapper();
35 36
36 virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part); 37 virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part);
37 virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part); 38 virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part);
38 virtual QString fetchTextPart(const RecMail&mail,const RecPart&part); 39 virtual QString fetchTextPart(const RecMail&mail,const RecPart&part);
39 virtual void cleanMimeCache(); 40 virtual void cleanMimeCache();
40 virtual int deleteMbox(const Folder*){return 1;} 41 virtual int deleteMbox(const Folder*){return 1;}
41 virtual void logout(){}; 42 virtual void logout(){};
42 virtual void storeMessage(const char*msg,size_t length, const QString&folder){}; 43 virtual void storeMessage(const char*msg,size_t length, const QString&folder){};
43 44
44protected: 45protected:
45 RecBody parseMail( mailmessage * msg ); 46 RecBody parseMail( mailmessage * msg );
46 QString parseMailboxList( mailimf_mailbox_list *list ); 47 QString parseMailboxList( mailimf_mailbox_list *list );
47 QString parseMailbox( mailimf_mailbox *box ); 48 QString parseMailbox( mailimf_mailbox *box );
48 QString parseGroup( mailimf_group *group ); 49 QString parseGroup( mailimf_group *group );
49 QString parseAddressList( mailimf_address_list *list ); 50 QString parseAddressList( mailimf_address_list *list );
50 QString parseDateTime( mailimf_date_time *date ); 51 QString parseDateTime( mailimf_date_time *date );
51 52
52 void traverseBody(RecBody&target,mailmessage*message,mailmime*mime,QValueList<int>recList,unsigned int current_rek=0,int current_count=1); 53 void traverseBody(RecBody&target,mailmessage*message,mailmime*mime,QValueList<int>recList,unsigned int current_rek=0,int current_count=1);
53 static void fillSingleBody(RecPart&target,mailmessage*message,mailmime*mime); 54 static void fillSingleBody(RecPart&target,mailmessage*message,mailmime*mime);
54 static void fillParameters(RecPart&target,clist*parameters); 55 static void fillParameters(RecPart&target,clist*parameters);
55 static QString getencoding(mailmime_mechanism*aEnc); 56 static QString getencoding(mailmime_mechanism*aEnc);
56 virtual void parseList(QList<RecMail> &target,mailsession*session,const QString&mailbox,bool mbox_as_to=false); 57 virtual void parseList(QList<RecMail> &target,mailsession*session,const QString&mailbox,bool mbox_as_to=false);
58 QStringList parseInreplies(mailimf_in_reply_to * in_replies);
57 59
58 QString msgTempName; 60 QString msgTempName;
59 unsigned int last_msg_id; 61 unsigned int last_msg_id;
60 QMap<QString,encodedString*> bodyCache; 62 QMap<QString,encodedString*> bodyCache;
61 mailstorage * m_storage; 63 mailstorage * m_storage;
62 mailfolder*m_folder; 64 mailfolder*m_folder;
63}; 65};
64 66
65#endif 67#endif
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.cpp b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
index 3375e69..e29a0a0 100644
--- a/noncore/net/mail/libmailwrapper/imapwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
@@ -1,703 +1,718 @@
1#include <stdlib.h> 1#include <stdlib.h>
2#include <libetpan/libetpan.h> 2#include <libetpan/libetpan.h>
3#include <qpe/global.h> 3#include <qpe/global.h>
4 4
5#include "imapwrapper.h" 5#include "imapwrapper.h"
6#include "mailtypes.h" 6#include "mailtypes.h"
7#include "logindialog.h" 7#include "logindialog.h"
8 8
9IMAPwrapper::IMAPwrapper( IMAPaccount *a ) 9IMAPwrapper::IMAPwrapper( IMAPaccount *a )
10 : AbstractMail() 10 : AbstractMail()
11{ 11{
12 account = a; 12 account = a;
13 m_imap = 0; 13 m_imap = 0;
14 m_Lastmbox = ""; 14 m_Lastmbox = "";
15} 15}
16 16
17IMAPwrapper::~IMAPwrapper() 17IMAPwrapper::~IMAPwrapper()
18{ 18{
19 logout(); 19 logout();
20} 20}
21 21
22/* to avoid to often select statements in loops etc. 22/* to avoid to often select statements in loops etc.
23 we trust that we are logged in and connection is established!*/ 23 we trust that we are logged in and connection is established!*/
24int IMAPwrapper::selectMbox(const QString&mbox) 24int IMAPwrapper::selectMbox(const QString&mbox)
25{ 25{
26 if (mbox == m_Lastmbox) { 26 if (mbox == m_Lastmbox) {
27 return MAILIMAP_NO_ERROR; 27 return MAILIMAP_NO_ERROR;
28 } 28 }
29 int err = mailimap_select( m_imap, (char*)mbox.latin1()); 29 int err = mailimap_select( m_imap, (char*)mbox.latin1());
30 if ( err != MAILIMAP_NO_ERROR ) { 30 if ( err != MAILIMAP_NO_ERROR ) {
31 qDebug("error selecting mailbox: %s",m_imap->imap_response); 31 qDebug("error selecting mailbox: %s",m_imap->imap_response);
32 m_Lastmbox = ""; 32 m_Lastmbox = "";
33 return err; 33 return err;
34 } 34 }
35 m_Lastmbox = mbox; 35 m_Lastmbox = mbox;
36 return err; 36 return err;
37} 37}
38 38
39void IMAPwrapper::imap_progress( size_t current, size_t maximum ) 39void IMAPwrapper::imap_progress( size_t current, size_t maximum )
40{ 40{
41 qDebug( "IMAP: %i of %i", current, maximum ); 41 qDebug( "IMAP: %i of %i", current, maximum );
42} 42}
43 43
44bool IMAPwrapper::start_tls(bool force_tls) 44bool IMAPwrapper::start_tls(bool force_tls)
45{ 45{
46 int err; 46 int err;
47 bool try_tls; 47 bool try_tls;
48 mailimap_capability_data * cap_data = 0; 48 mailimap_capability_data * cap_data = 0;
49 49
50 err = mailimap_capability(m_imap,&cap_data); 50 err = mailimap_capability(m_imap,&cap_data);
51 if (err != MAILIMAP_NO_ERROR) { 51 if (err != MAILIMAP_NO_ERROR) {
52 Global::statusMessage("error getting capabilities!"); 52 Global::statusMessage("error getting capabilities!");
53 qDebug("error getting capabilities!"); 53 qDebug("error getting capabilities!");
54 return false; 54 return false;
55 } 55 }
56 clistiter * cur; 56 clistiter * cur;
57 for(cur = clist_begin(cap_data->cap_list) ; cur != NULL;cur = clist_next(cur)) { 57 for(cur = clist_begin(cap_data->cap_list) ; cur != NULL;cur = clist_next(cur)) {
58 struct mailimap_capability * cap; 58 struct mailimap_capability * cap;
59 cap = (struct mailimap_capability *)clist_content(cur); 59 cap = (struct mailimap_capability *)clist_content(cur);
60 if (cap->cap_type == MAILIMAP_CAPABILITY_NAME) { 60 if (cap->cap_type == MAILIMAP_CAPABILITY_NAME) {
61 if (strcasecmp(cap->cap_data.cap_name, "STARTTLS") == 0) { 61 if (strcasecmp(cap->cap_data.cap_name, "STARTTLS") == 0) {
62 try_tls = true; 62 try_tls = true;
63 break; 63 break;
64 } 64 }
65 } 65 }
66 } 66 }
67 if (cap_data) { 67 if (cap_data) {
68 mailimap_capability_data_free(cap_data); 68 mailimap_capability_data_free(cap_data);
69 } 69 }
70 if (try_tls) { 70 if (try_tls) {
71 err = mailimap_starttls(m_imap); 71 err = mailimap_starttls(m_imap);
72 if (err != MAILIMAP_NO_ERROR && force_tls) { 72 if (err != MAILIMAP_NO_ERROR && force_tls) {
73 Global::statusMessage(tr("Server has no TLS support!")); 73 Global::statusMessage(tr("Server has no TLS support!"));
74 qDebug("Server has no TLS support!"); 74 qDebug("Server has no TLS support!");
75 try_tls = false; 75 try_tls = false;
76 } else { 76 } else {
77 mailstream_low * low; 77 mailstream_low * low;
78 mailstream_low * new_low; 78 mailstream_low * new_low;
79 low = mailstream_get_low(m_imap->imap_stream); 79 low = mailstream_get_low(m_imap->imap_stream);
80 if (!low) { 80 if (!low) {
81 try_tls = false; 81 try_tls = false;
82 } else { 82 } else {
83 int fd = mailstream_low_get_fd(low); 83 int fd = mailstream_low_get_fd(low);
84 if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) { 84 if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) {
85 mailstream_low_free(low); 85 mailstream_low_free(low);
86 mailstream_set_low(m_imap->imap_stream, new_low); 86 mailstream_set_low(m_imap->imap_stream, new_low);
87 } else { 87 } else {
88 try_tls = false; 88 try_tls = false;
89 } 89 }
90 } 90 }
91 } 91 }
92 } 92 }
93 return try_tls; 93 return try_tls;
94} 94}
95 95
96void IMAPwrapper::login() 96void IMAPwrapper::login()
97{ 97{
98 const char *server, *user, *pass; 98 const char *server, *user, *pass;
99 uint16_t port; 99 uint16_t port;
100 int err = MAILIMAP_NO_ERROR; 100 int err = MAILIMAP_NO_ERROR;
101 101
102 if (account->getOffline()) return; 102 if (account->getOffline()) return;
103 /* we are connected this moment */ 103 /* we are connected this moment */
104 /* TODO: setup a timer holding the line or if connection closed - delete the value */ 104 /* TODO: setup a timer holding the line or if connection closed - delete the value */
105 if (m_imap) { 105 if (m_imap) {
106 err = mailimap_noop(m_imap); 106 err = mailimap_noop(m_imap);
107 if (err!=MAILIMAP_NO_ERROR) { 107 if (err!=MAILIMAP_NO_ERROR) {
108 logout(); 108 logout();
109 } else { 109 } else {
110 mailstream_flush(m_imap->imap_stream); 110 mailstream_flush(m_imap->imap_stream);
111 return; 111 return;
112 } 112 }
113 } 113 }
114 server = account->getServer().latin1(); 114 server = account->getServer().latin1();
115 port = account->getPort().toUInt(); 115 port = account->getPort().toUInt();
116 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { 116 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) {
117 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); 117 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true );
118 login.show(); 118 login.show();
119 if ( QDialog::Accepted == login.exec() ) { 119 if ( QDialog::Accepted == login.exec() ) {
120 // ok 120 // ok
121 user = login.getUser().latin1(); 121 user = login.getUser().latin1();
122 pass = login.getPassword().latin1(); 122 pass = login.getPassword().latin1();
123 } else { 123 } else {
124 // cancel 124 // cancel
125 qDebug( "IMAP: Login canceled" ); 125 qDebug( "IMAP: Login canceled" );
126 return; 126 return;
127 } 127 }
128 } else { 128 } else {
129 user = account->getUser().latin1(); 129 user = account->getUser().latin1();
130 pass = account->getPassword().latin1(); 130 pass = account->getPassword().latin1();
131 } 131 }
132 132
133 m_imap = mailimap_new( 20, &imap_progress ); 133 m_imap = mailimap_new( 20, &imap_progress );
134 134
135 /* connect */ 135 /* connect */
136 bool ssl = false; 136 bool ssl = false;
137 bool try_tls = false; 137 bool try_tls = false;
138 bool force_tls = false; 138 bool force_tls = false;
139 139
140 if ( account->ConnectionType() == 2 ) { 140 if ( account->ConnectionType() == 2 ) {
141 ssl = true; 141 ssl = true;
142 } 142 }
143 if (account->ConnectionType()==1) { 143 if (account->ConnectionType()==1) {
144 force_tls = true; 144 force_tls = true;
145 } 145 }
146 146
147 if ( ssl ) { 147 if ( ssl ) {
148 qDebug( "using ssl" ); 148 qDebug( "using ssl" );
149 err = mailimap_ssl_connect( m_imap, (char*)server, port ); 149 err = mailimap_ssl_connect( m_imap, (char*)server, port );
150 } else { 150 } else {
151 err = mailimap_socket_connect( m_imap, (char*)server, port ); 151 err = mailimap_socket_connect( m_imap, (char*)server, port );
152 } 152 }
153 153
154 if ( err != MAILIMAP_NO_ERROR && 154 if ( err != MAILIMAP_NO_ERROR &&
155 err != MAILIMAP_NO_ERROR_AUTHENTICATED && 155 err != MAILIMAP_NO_ERROR_AUTHENTICATED &&
156 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { 156 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) {
157 QString failure = ""; 157 QString failure = "";
158 if (err == MAILIMAP_ERROR_CONNECTION_REFUSED) { 158 if (err == MAILIMAP_ERROR_CONNECTION_REFUSED) {
159 failure="Connection refused"; 159 failure="Connection refused";
160 } else { 160 } else {
161 failure="Unknown failure"; 161 failure="Unknown failure";
162 } 162 }
163 Global::statusMessage(tr("error connecting imap server: %1").arg(failure)); 163 Global::statusMessage(tr("error connecting imap server: %1").arg(failure));
164 mailimap_free( m_imap ); 164 mailimap_free( m_imap );
165 m_imap = 0; 165 m_imap = 0;
166 return; 166 return;
167 } 167 }
168 168
169 if (!ssl) { 169 if (!ssl) {
170 try_tls = start_tls(force_tls); 170 try_tls = start_tls(force_tls);
171 } 171 }
172 172
173 bool ok = true; 173 bool ok = true;
174 if (force_tls && !try_tls) { 174 if (force_tls && !try_tls) {
175 Global::statusMessage(tr("Server has no TLS support!")); 175 Global::statusMessage(tr("Server has no TLS support!"));
176 qDebug("Server has no TLS support!"); 176 qDebug("Server has no TLS support!");
177 ok = false; 177 ok = false;
178 } 178 }
179 179
180 180
181 /* login */ 181 /* login */
182 182
183 if (ok) { 183 if (ok) {
184 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); 184 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass );
185 if ( err != MAILIMAP_NO_ERROR ) { 185 if ( err != MAILIMAP_NO_ERROR ) {
186 Global::statusMessage(tr("error logging in imap server: %1").arg(m_imap->imap_response)); 186 Global::statusMessage(tr("error logging in imap server: %1").arg(m_imap->imap_response));
187 ok = false; 187 ok = false;
188 } 188 }
189 } 189 }
190 if (!ok) { 190 if (!ok) {
191 err = mailimap_close( m_imap ); 191 err = mailimap_close( m_imap );
192 mailimap_free( m_imap ); 192 mailimap_free( m_imap );
193 m_imap = 0; 193 m_imap = 0;
194 } 194 }
195} 195}
196 196
197void IMAPwrapper::logout() 197void IMAPwrapper::logout()
198{ 198{
199 int err = MAILIMAP_NO_ERROR; 199 int err = MAILIMAP_NO_ERROR;
200 if (!m_imap) return; 200 if (!m_imap) return;
201 err = mailimap_logout( m_imap ); 201 err = mailimap_logout( m_imap );
202 err = mailimap_close( m_imap ); 202 err = mailimap_close( m_imap );
203 mailimap_free( m_imap ); 203 mailimap_free( m_imap );
204 m_imap = 0; 204 m_imap = 0;
205 m_Lastmbox = ""; 205 m_Lastmbox = "";
206} 206}
207 207
208void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) 208void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target )
209{ 209{
210 int err = MAILIMAP_NO_ERROR; 210 int err = MAILIMAP_NO_ERROR;
211 clist *result = 0; 211 clist *result = 0;
212 clistcell *current; 212 clistcell *current;
213 mailimap_fetch_type *fetchType = 0; 213 mailimap_fetch_type *fetchType = 0;
214 mailimap_set *set = 0; 214 mailimap_set *set = 0;
215 215
216 login(); 216 login();
217 if (!m_imap) { 217 if (!m_imap) {
218 return; 218 return;
219 } 219 }
220 /* select mailbox READONLY for operations */ 220 /* select mailbox READONLY for operations */
221 err = selectMbox(mailbox); 221 err = selectMbox(mailbox);
222 if ( err != MAILIMAP_NO_ERROR ) { 222 if ( err != MAILIMAP_NO_ERROR ) {
223 return; 223 return;
224 } 224 }
225 225
226 int last = m_imap->imap_selection_info->sel_exists; 226 int last = m_imap->imap_selection_info->sel_exists;
227 227
228 if (last == 0) { 228 if (last == 0) {
229 Global::statusMessage(tr("Mailbox has no mails")); 229 Global::statusMessage(tr("Mailbox has no mails"));
230 return; 230 return;
231 } else { 231 } else {
232 } 232 }
233 233
234 /* the range has to start at 1!!! not with 0!!!! */ 234 /* the range has to start at 1!!! not with 0!!!! */
235 set = mailimap_set_new_interval( 1, last ); 235 set = mailimap_set_new_interval( 1, last );
236 fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); 236 fetchType = mailimap_fetch_type_new_fetch_att_list_empty();
237 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); 237 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope());
238 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); 238 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags());
239 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); 239 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate());
240 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); 240 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size());
241 241
242 err = mailimap_fetch( m_imap, set, fetchType, &result ); 242 err = mailimap_fetch( m_imap, set, fetchType, &result );
243 mailimap_set_free( set ); 243 mailimap_set_free( set );
244 mailimap_fetch_type_free( fetchType ); 244 mailimap_fetch_type_free( fetchType );
245 245
246 QString date,subject,from; 246 QString date,subject,from;
247 247
248 if ( err == MAILIMAP_NO_ERROR ) { 248 if ( err == MAILIMAP_NO_ERROR ) {
249 mailimap_msg_att * msg_att; 249 mailimap_msg_att * msg_att;
250 int i = 0; 250 int i = 0;
251 for (current = clist_begin(result); current != 0; current=clist_next(current)) { 251 for (current = clist_begin(result); current != 0; current=clist_next(current)) {
252 ++i; 252 ++i;
253 msg_att = (mailimap_msg_att*)current->data; 253 msg_att = (mailimap_msg_att*)current->data;
254 RecMail*m = parse_list_result(msg_att); 254 RecMail*m = parse_list_result(msg_att);
255 if (m) { 255 if (m) {
256 m->setNumber(i); 256 m->setNumber(i);
257 m->setMbox(mailbox); 257 m->setMbox(mailbox);
258 m->setWrapper(this); 258 m->setWrapper(this);
259 target.append(m); 259 target.append(m);
260 } 260 }
261 } 261 }
262 Global::statusMessage(tr("Mailbox has %1 mails").arg(target.count())); 262 Global::statusMessage(tr("Mailbox has %1 mails").arg(target.count()));
263 } else { 263 } else {
264 Global::statusMessage(tr("Error fetching headers: %1").arg(m_imap->imap_response)); 264 Global::statusMessage(tr("Error fetching headers: %1").arg(m_imap->imap_response));
265 } 265 }
266 if (result) mailimap_fetch_list_free(result); 266 if (result) mailimap_fetch_list_free(result);
267} 267}
268 268
269QList<Folder>* IMAPwrapper::listFolders() 269QList<Folder>* IMAPwrapper::listFolders()
270{ 270{
271 const char *path, *mask; 271 const char *path, *mask;
272 int err = MAILIMAP_NO_ERROR; 272 int err = MAILIMAP_NO_ERROR;
273 clist *result = 0; 273 clist *result = 0;
274 clistcell *current = 0; 274 clistcell *current = 0;
275 clistcell*cur_flag = 0; 275 clistcell*cur_flag = 0;
276 mailimap_mbx_list_flags*bflags = 0; 276 mailimap_mbx_list_flags*bflags = 0;
277 277
278 QList<Folder> * folders = new QList<Folder>(); 278 QList<Folder> * folders = new QList<Folder>();
279 folders->setAutoDelete( false ); 279 folders->setAutoDelete( false );
280 login(); 280 login();
281 if (!m_imap) { 281 if (!m_imap) {
282 return folders; 282 return folders;
283 } 283 }
284 284
285/* 285/*
286 * First we have to check for INBOX 'cause it sometimes it's not inside the path. 286 * First we have to check for INBOX 'cause it sometimes it's not inside the path.
287 * We must not forget to filter them out in next loop! 287 * We must not forget to filter them out in next loop!
288 * it seems like ugly code. and yes - it is ugly code. but the best way. 288 * it seems like ugly code. and yes - it is ugly code. but the best way.
289 */ 289 */
290 QString temp; 290 QString temp;
291 mask = "INBOX" ; 291 mask = "INBOX" ;
292 mailimap_mailbox_list *list; 292 mailimap_mailbox_list *list;
293 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); 293 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result );
294 QString del; 294 QString del;
295 bool selectable = true; 295 bool selectable = true;
296 bool no_inferiors = false; 296 bool no_inferiors = false;
297 if ( err == MAILIMAP_NO_ERROR ) { 297 if ( err == MAILIMAP_NO_ERROR ) {
298 current = result->first; 298 current = result->first;
299 for ( int i = result->count; i > 0; i-- ) { 299 for ( int i = result->count; i > 0; i-- ) {
300 list = (mailimap_mailbox_list *) current->data; 300 list = (mailimap_mailbox_list *) current->data;
301 // it is better use the deep copy mechanism of qt itself 301 // it is better use the deep copy mechanism of qt itself
302 // instead of using strdup! 302 // instead of using strdup!
303 temp = list->mb_name; 303 temp = list->mb_name;
304 del = list->mb_delimiter; 304 del = list->mb_delimiter;
305 current = current->next; 305 current = current->next;
306 if ( (bflags = list->mb_flag) ) { 306 if ( (bflags = list->mb_flag) ) {
307 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& 307 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&&
308 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); 308 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT);
309 for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { 309 for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) {
310 if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { 310 if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) {
311 no_inferiors = true; 311 no_inferiors = true;
312 } 312 }
313 } 313 }
314 } 314 }
315 folders->append( new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); 315 folders->append( new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix()));
316 } 316 }
317 } else { 317 } else {
318 qDebug("error fetching folders: %s",m_imap->imap_response); 318 qDebug("error fetching folders: %s",m_imap->imap_response);
319 } 319 }
320 mailimap_list_result_free( result ); 320 mailimap_list_result_free( result );
321 321
322/* 322/*
323 * second stage - get the other then inbox folders 323 * second stage - get the other then inbox folders
324 */ 324 */
325 mask = "*" ; 325 mask = "*" ;
326 path = account->getPrefix().latin1(); 326 path = account->getPrefix().latin1();
327 if (!path) path = ""; 327 if (!path) path = "";
328 qDebug(path); 328 qDebug(path);
329 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); 329 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result );
330 if ( err == MAILIMAP_NO_ERROR ) { 330 if ( err == MAILIMAP_NO_ERROR ) {
331 current = result->first; 331 current = result->first;
332 for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { 332 for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) {
333 no_inferiors = false; 333 no_inferiors = false;
334 list = (mailimap_mailbox_list *) current->data; 334 list = (mailimap_mailbox_list *) current->data;
335 // it is better use the deep copy mechanism of qt itself 335 // it is better use the deep copy mechanism of qt itself
336 // instead of using strdup! 336 // instead of using strdup!
337 temp = list->mb_name; 337 temp = list->mb_name;
338 if (temp.lower()=="inbox") 338 if (temp.lower()=="inbox")
339 continue; 339 continue;
340 if (temp.lower()==account->getPrefix().lower()) 340 if (temp.lower()==account->getPrefix().lower())
341 continue; 341 continue;
342 if ( (bflags = list->mb_flag) ) { 342 if ( (bflags = list->mb_flag) ) {
343 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& 343 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&&
344 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); 344 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT);
345 for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { 345 for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) {
346 if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { 346 if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) {
347 no_inferiors = true; 347 no_inferiors = true;
348 } 348 }
349 } 349 }
350 } 350 }
351 del = list->mb_delimiter; 351 del = list->mb_delimiter;
352 folders->append(new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); 352 folders->append(new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix()));
353 } 353 }
354 } else { 354 } else {
355 qDebug("error fetching folders %s",m_imap->imap_response); 355 qDebug("error fetching folders %s",m_imap->imap_response);
356 } 356 }
357 if (result) mailimap_list_result_free( result ); 357 if (result) mailimap_list_result_free( result );
358 return folders; 358 return folders;
359} 359}
360 360
361RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) 361RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
362{ 362{
363 RecMail * m = 0; 363 RecMail * m = 0;
364 mailimap_msg_att_item *item=0; 364 mailimap_msg_att_item *item=0;
365 clistcell *current,*c,*cf; 365 clistcell *current,*c,*cf;
366 mailimap_msg_att_dynamic*flist; 366 mailimap_msg_att_dynamic*flist;
367 mailimap_flag_fetch*cflag; 367 mailimap_flag_fetch*cflag;
368 int size; 368 int size;
369 QBitArray mFlags(7); 369 QBitArray mFlags(7);
370 QStringList addresslist; 370 QStringList addresslist;
371 371
372 if (!m_att) { 372 if (!m_att) {
373 return m; 373 return m;
374 } 374 }
375 m = new RecMail(); 375 m = new RecMail();
376 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { 376 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) {
377 current = c; 377 current = c;
378 size = 0; 378 size = 0;
379 item = (mailimap_msg_att_item*)current->data; 379 item = (mailimap_msg_att_item*)current->data;
380 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { 380 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) {
381 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; 381 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn;
382 if (!flist->att_list) { 382 if (!flist->att_list) {
383 continue; 383 continue;
384 } 384 }
385 cf = flist->att_list->first; 385 cf = flist->att_list->first;
386 for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { 386 for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) {
387 cflag = (mailimap_flag_fetch*)cf->data; 387 cflag = (mailimap_flag_fetch*)cf->data;
388 if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { 388 if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) {
389 switch (cflag->fl_flag->fl_type) { 389 switch (cflag->fl_flag->fl_type) {
390 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ 390 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */
391 mFlags.setBit(FLAG_ANSWERED); 391 mFlags.setBit(FLAG_ANSWERED);
392 break; 392 break;
393 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ 393 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */
394 mFlags.setBit(FLAG_FLAGGED); 394 mFlags.setBit(FLAG_FLAGGED);
395 break; 395 break;
396 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ 396 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */
397 mFlags.setBit(FLAG_DELETED); 397 mFlags.setBit(FLAG_DELETED);
398 break; 398 break;
399 case MAILIMAP_FLAG_SEEN: /* \Seen flag */ 399 case MAILIMAP_FLAG_SEEN: /* \Seen flag */
400 mFlags.setBit(FLAG_SEEN); 400 mFlags.setBit(FLAG_SEEN);
401 break; 401 break;
402 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ 402 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */
403 mFlags.setBit(FLAG_DRAFT); 403 mFlags.setBit(FLAG_DRAFT);
404 break; 404 break;
405 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ 405 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */
406 break; 406 break;
407 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ 407 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */
408 break; 408 break;
409 default: 409 default:
410 break; 410 break;
411 } 411 }
412 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { 412 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) {
413 mFlags.setBit(FLAG_RECENT); 413 mFlags.setBit(FLAG_RECENT);
414 } 414 }
415 } 415 }
416 continue; 416 continue;
417 } 417 }
418 if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { 418 if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) {
419 mailimap_envelope * head = item->att_data.att_static->att_data.att_env; 419 mailimap_envelope * head = item->att_data.att_static->att_data.att_env;
420 m->setDate(head->env_date); 420 m->setDate(head->env_date);
421 m->setSubject(convert_String((const char*)head->env_subject)); 421 m->setSubject(convert_String((const char*)head->env_subject));
422 //m->setSubject(head->env_subject); 422 //m->setSubject(head->env_subject);
423 if (head->env_from!=NULL) { 423 if (head->env_from!=NULL) {
424 addresslist = address_list_to_stringlist(head->env_from->frm_list); 424 addresslist = address_list_to_stringlist(head->env_from->frm_list);
425 if (addresslist.count()) { 425 if (addresslist.count()) {
426 m->setFrom(addresslist.first()); 426 m->setFrom(addresslist.first());
427 } 427 }
428 } 428 }
429 if (head->env_to!=NULL) { 429 if (head->env_to!=NULL) {
430 addresslist = address_list_to_stringlist(head->env_to->to_list); 430 addresslist = address_list_to_stringlist(head->env_to->to_list);
431 m->setTo(addresslist); 431 m->setTo(addresslist);
432 } 432 }
433 if (head->env_cc!=NULL) { 433 if (head->env_cc!=NULL) {
434 addresslist = address_list_to_stringlist(head->env_cc->cc_list); 434 addresslist = address_list_to_stringlist(head->env_cc->cc_list);
435 m->setCC(addresslist); 435 m->setCC(addresslist);
436 } 436 }
437 if (head->env_bcc!=NULL) { 437 if (head->env_bcc!=NULL) {
438 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); 438 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list);
439 m->setBcc(addresslist); 439 m->setBcc(addresslist);
440 } 440 }
441 /* reply to address, eg. email. */
441 if (head->env_reply_to!=NULL) { 442 if (head->env_reply_to!=NULL) {
442 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); 443 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list);
443 if (addresslist.count()) { 444 if (addresslist.count()) {
444 m->setReplyto(addresslist.first()); 445 m->setReplyto(addresslist.first());
445 } 446 }
446 } 447 }
447 m->setMsgid(QString(head->env_message_id)); 448 if (head->env_in_reply_to!=NULL) {
449 QString h(head->env_in_reply_to);
450 while (h.length()>0 && h[0]=='<') {
451 h.remove(0,1);
452 }
453 while (h.length()>0 && h[h.length()-1]=='>') {
454 h.remove(h.length()-1,1);
455 }
456 if (h.length()>0) {
457 m->setInreply(QStringList(h));
458 }
459 }
460 if (head->env_message_id) {
461 m->setMsgid(QString(head->env_message_id));
462 }
448 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { 463 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) {
449#if 0 464#if 0
450 mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; 465 mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date;
451 QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); 466 QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec));
452 qDebug("%i %i %i - %i %i %i",d->dt_year,d->dt_month,d->dt_day,d->dt_hour,d->dt_min,d->dt_sec); 467 qDebug("%i %i %i - %i %i %i",d->dt_year,d->dt_month,d->dt_day,d->dt_hour,d->dt_min,d->dt_sec);
453 qDebug(da.toString()); 468 qDebug(da.toString());
454#endif 469#endif
455 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { 470 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) {
456 size = item->att_data.att_static->att_data.att_rfc822_size; 471 size = item->att_data.att_static->att_data.att_rfc822_size;
457 } 472 }
458 } 473 }
459 /* msg is already deleted */ 474 /* msg is already deleted */
460 if (mFlags.testBit(FLAG_DELETED) && m) { 475 if (mFlags.testBit(FLAG_DELETED) && m) {
461 delete m; 476 delete m;
462 m = 0; 477 m = 0;
463 } 478 }
464 if (m) { 479 if (m) {
465 m->setFlags(mFlags); 480 m->setFlags(mFlags);
466 m->setMsgsize(size); 481 m->setMsgsize(size);
467 } 482 }
468 return m; 483 return m;
469} 484}
470 485
471RecBody IMAPwrapper::fetchBody(const RecMail&mail) 486RecBody IMAPwrapper::fetchBody(const RecMail&mail)
472{ 487{
473 RecBody body; 488 RecBody body;
474 const char *mb; 489 const char *mb;
475 int err = MAILIMAP_NO_ERROR; 490 int err = MAILIMAP_NO_ERROR;
476 clist *result = 0; 491 clist *result = 0;
477 clistcell *current; 492 clistcell *current;
478 mailimap_fetch_att *fetchAtt = 0; 493 mailimap_fetch_att *fetchAtt = 0;
479 mailimap_fetch_type *fetchType = 0; 494 mailimap_fetch_type *fetchType = 0;
480 mailimap_set *set = 0; 495 mailimap_set *set = 0;
481 mailimap_body*body_desc = 0; 496 mailimap_body*body_desc = 0;
482 497
483 mb = mail.getMbox().latin1(); 498 mb = mail.getMbox().latin1();
484 499
485 login(); 500 login();
486 if (!m_imap) { 501 if (!m_imap) {
487 return body; 502 return body;
488 } 503 }
489 err = selectMbox(mail.getMbox()); 504 err = selectMbox(mail.getMbox());
490 if ( err != MAILIMAP_NO_ERROR ) { 505 if ( err != MAILIMAP_NO_ERROR ) {
491 return body; 506 return body;
492 } 507 }
493 508
494 /* the range has to start at 1!!! not with 0!!!! */ 509 /* the range has to start at 1!!! not with 0!!!! */
495 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); 510 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() );
496 fetchAtt = mailimap_fetch_att_new_bodystructure(); 511 fetchAtt = mailimap_fetch_att_new_bodystructure();
497 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); 512 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
498 err = mailimap_fetch( m_imap, set, fetchType, &result ); 513 err = mailimap_fetch( m_imap, set, fetchType, &result );
499 mailimap_set_free( set ); 514 mailimap_set_free( set );
500 mailimap_fetch_type_free( fetchType ); 515 mailimap_fetch_type_free( fetchType );
501 516
502 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 517 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
503 mailimap_msg_att * msg_att; 518 mailimap_msg_att * msg_att;
504 msg_att = (mailimap_msg_att*)current->data; 519 msg_att = (mailimap_msg_att*)current->data;
505 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; 520 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data;
506 QValueList<int> path; 521 QValueList<int> path;
507 body_desc = item->att_data.att_static->att_data.att_body; 522 body_desc = item->att_data.att_static->att_data.att_body;
508 traverseBody(mail,body_desc,body,0,path); 523 traverseBody(mail,body_desc,body,0,path);
509 } else { 524 } else {
510 qDebug("error fetching body: %s",m_imap->imap_response); 525 qDebug("error fetching body: %s",m_imap->imap_response);
511 } 526 }
512 if (result) mailimap_fetch_list_free(result); 527 if (result) mailimap_fetch_list_free(result);
513 return body; 528 return body;
514} 529}
515 530
516QStringList IMAPwrapper::address_list_to_stringlist(clist*list) 531QStringList IMAPwrapper::address_list_to_stringlist(clist*list)
517{ 532{
518 QStringList l; 533 QStringList l;
519 QString from; 534 QString from;
520 bool named_from; 535 bool named_from;
521 clistcell *current = NULL; 536 clistcell *current = NULL;
522 mailimap_address * current_address=NULL; 537 mailimap_address * current_address=NULL;
523 if (!list) { 538 if (!list) {
524 return l; 539 return l;
525 } 540 }
526 unsigned int count = 0; 541 unsigned int count = 0;
527 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { 542 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) {
528 from = ""; 543 from = "";
529 named_from = false; 544 named_from = false;
530 current_address=(mailimap_address*)current->data; 545 current_address=(mailimap_address*)current->data;
531 if (current_address->ad_personal_name){ 546 if (current_address->ad_personal_name){
532 from+=convert_String((const char*)current_address->ad_personal_name); 547 from+=convert_String((const char*)current_address->ad_personal_name);
533 from+=" "; 548 from+=" ";
534 named_from = true; 549 named_from = true;
535 } 550 }
536 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { 551 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
537 from+="<"; 552 from+="<";
538 } 553 }
539 if (current_address->ad_mailbox_name) { 554 if (current_address->ad_mailbox_name) {
540 from+=QString(current_address->ad_mailbox_name); 555 from+=QString(current_address->ad_mailbox_name);
541 from+="@"; 556 from+="@";
542 } 557 }
543 if (current_address->ad_host_name) { 558 if (current_address->ad_host_name) {
544 from+=QString(current_address->ad_host_name); 559 from+=QString(current_address->ad_host_name);
545 } 560 }
546 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { 561 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
547 from+=">"; 562 from+=">";
548 } 563 }
549 l.append(QString(from)); 564 l.append(QString(from));
550 if (++count > 99) { 565 if (++count > 99) {
551 break; 566 break;
552 } 567 }
553 } 568 }
554 return l; 569 return l;
555} 570}
556 571
557encodedString*IMAPwrapper::fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call) 572encodedString*IMAPwrapper::fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call)
558{ 573{
559 encodedString*res=new encodedString; 574 encodedString*res=new encodedString;
560 int err; 575 int err;
561 mailimap_fetch_type *fetchType; 576 mailimap_fetch_type *fetchType;
562 mailimap_set *set; 577 mailimap_set *set;
563 clistcell*current,*cur; 578 clistcell*current,*cur;
564 mailimap_section_part * section_part = 0; 579 mailimap_section_part * section_part = 0;
565 mailimap_section_spec * section_spec = 0; 580 mailimap_section_spec * section_spec = 0;
566 mailimap_section * section = 0; 581 mailimap_section * section = 0;
567 mailimap_fetch_att * fetch_att = 0; 582 mailimap_fetch_att * fetch_att = 0;
568 583
569 login(); 584 login();
570 if (!m_imap) { 585 if (!m_imap) {
571 return res; 586 return res;
572 } 587 }
573 if (!internal_call) { 588 if (!internal_call) {
574 err = selectMbox(mail.getMbox()); 589 err = selectMbox(mail.getMbox());
575 if ( err != MAILIMAP_NO_ERROR ) { 590 if ( err != MAILIMAP_NO_ERROR ) {
576 return res; 591 return res;
577 } 592 }
578 } 593 }
579 set = mailimap_set_new_single(mail.getNumber()); 594 set = mailimap_set_new_single(mail.getNumber());
580 595
581 clist*id_list = 0; 596 clist*id_list = 0;
582 597
583 /* if path == empty then its a request for the whole rfc822 mail and generates 598 /* if path == empty then its a request for the whole rfc822 mail and generates
584 a "fetch <id> (body[])" statement on imap server */ 599 a "fetch <id> (body[])" statement on imap server */
585 if (path.count()>0 ) { 600 if (path.count()>0 ) {
586 id_list = clist_new(); 601 id_list = clist_new();
587 for (unsigned j=0; j < path.count();++j) { 602 for (unsigned j=0; j < path.count();++j) {
588 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); 603 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id));
589 *p_id = path[j]; 604 *p_id = path[j];
590 clist_append(id_list,p_id); 605 clist_append(id_list,p_id);
591 } 606 }
592 section_part = mailimap_section_part_new(id_list); 607 section_part = mailimap_section_part_new(id_list);
593 section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); 608 section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL);
594 } 609 }
595 610
596 section = mailimap_section_new(section_spec); 611 section = mailimap_section_new(section_spec);
597 fetch_att = mailimap_fetch_att_new_body_section(section); 612 fetch_att = mailimap_fetch_att_new_body_section(section);
598 fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); 613 fetchType = mailimap_fetch_type_new_fetch_att(fetch_att);
599 614
600 clist*result = 0; 615 clist*result = 0;
601 616
602 err = mailimap_fetch( m_imap, set, fetchType, &result ); 617 err = mailimap_fetch( m_imap, set, fetchType, &result );
603 mailimap_set_free( set ); 618 mailimap_set_free( set );
604 mailimap_fetch_type_free( fetchType ); 619 mailimap_fetch_type_free( fetchType );
605 620
606 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 621 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
607 mailimap_msg_att * msg_att; 622 mailimap_msg_att * msg_att;
608 msg_att = (mailimap_msg_att*)current->data; 623 msg_att = (mailimap_msg_att*)current->data;
609 mailimap_msg_att_item*msg_att_item; 624 mailimap_msg_att_item*msg_att_item;
610 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { 625 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) {
611 msg_att_item = (mailimap_msg_att_item*)clist_content(cur); 626 msg_att_item = (mailimap_msg_att_item*)clist_content(cur);
612 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { 627 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) {
613 if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { 628 if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) {
614 char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; 629 char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part;
615 /* detach - we take over the content */ 630 /* detach - we take over the content */
616 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; 631 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L;
617 res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length); 632 res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length);
618 } 633 }
619 } 634 }
620 } 635 }
621 } else { 636 } else {
622 qDebug("error fetching text: %s",m_imap->imap_response); 637 qDebug("error fetching text: %s",m_imap->imap_response);
623 } 638 }
624 if (result) mailimap_fetch_list_free(result); 639 if (result) mailimap_fetch_list_free(result);
625 return res; 640 return res;
626} 641}
627 642
628/* current_recursion is for recursive calls. 643/* current_recursion is for recursive calls.
629 current_count means the position inside the internal loop! */ 644 current_count means the position inside the internal loop! */
630void IMAPwrapper::traverseBody(const RecMail&mail,mailimap_body*body,RecBody&target_body, 645void IMAPwrapper::traverseBody(const RecMail&mail,mailimap_body*body,RecBody&target_body,
631 int current_recursion,QValueList<int>recList,int current_count) 646 int current_recursion,QValueList<int>recList,int current_count)
632{ 647{
633 if (!body || current_recursion>=10) { 648 if (!body || current_recursion>=10) {
634 return; 649 return;
635 } 650 }
636 switch (body->bd_type) { 651 switch (body->bd_type) {
637 case MAILIMAP_BODY_1PART: 652 case MAILIMAP_BODY_1PART:
638 { 653 {
639 QValueList<int>countlist = recList; 654 QValueList<int>countlist = recList;
640 countlist.append(current_count); 655 countlist.append(current_count);
641 RecPart currentPart; 656 RecPart currentPart;
642 mailimap_body_type_1part*part1 = body->bd_data.bd_body_1part; 657 mailimap_body_type_1part*part1 = body->bd_data.bd_body_1part;
643 QString id(""); 658 QString id("");
644 currentPart.setPositionlist(countlist); 659 currentPart.setPositionlist(countlist);
645 for (unsigned int j = 0; j < countlist.count();++j) { 660 for (unsigned int j = 0; j < countlist.count();++j) {
646 id+=(j>0?" ":""); 661 id+=(j>0?" ":"");
647 id+=QString("%1").arg(countlist[j]); 662 id+=QString("%1").arg(countlist[j]);
648 } 663 }
649 qDebug("ID = %s",id.latin1()); 664 qDebug("ID = %s",id.latin1());
650 currentPart.setIdentifier(id); 665 currentPart.setIdentifier(id);
651 fillSinglePart(currentPart,part1); 666 fillSinglePart(currentPart,part1);
652 /* important: Check for is NULL 'cause a body can be empty! 667 /* important: Check for is NULL 'cause a body can be empty!
653 And we put it only into the mail if it is the FIRST part */ 668 And we put it only into the mail if it is the FIRST part */
654 if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_TEXT && target_body.Bodytext().isNull() && countlist[0]==1) { 669 if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_TEXT && target_body.Bodytext().isNull() && countlist[0]==1) {
655 QString body_text = fetchTextPart(mail,countlist,true,currentPart.Encoding()); 670 QString body_text = fetchTextPart(mail,countlist,true,currentPart.Encoding());
656 target_body.setDescription(currentPart); 671 target_body.setDescription(currentPart);
657 target_body.setBodytext(body_text); 672 target_body.setBodytext(body_text);
658 if (countlist.count()>1) { 673 if (countlist.count()>1) {
659 target_body.addPart(currentPart); 674 target_body.addPart(currentPart);
660 } 675 }
661 } else { 676 } else {
662 target_body.addPart(currentPart); 677 target_body.addPart(currentPart);
663 } 678 }
664 if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_MSG) { 679 if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_MSG) {
665 traverseBody(mail,part1->bd_data.bd_type_msg->bd_body,target_body,current_recursion+1,countlist); 680 traverseBody(mail,part1->bd_data.bd_type_msg->bd_body,target_body,current_recursion+1,countlist);
666 } 681 }
667 } 682 }
668 break; 683 break;
669 case MAILIMAP_BODY_MPART: 684 case MAILIMAP_BODY_MPART:
670 { 685 {
671 QValueList<int>countlist = recList; 686 QValueList<int>countlist = recList;
672 clistcell*current=0; 687 clistcell*current=0;
673 mailimap_body*current_body=0; 688 mailimap_body*current_body=0;
674 unsigned int ccount = 1; 689 unsigned int ccount = 1;
675 mailimap_body_type_mpart*mailDescription = body->bd_data.bd_body_mpart; 690 mailimap_body_type_mpart*mailDescription = body->bd_data.bd_body_mpart;
676 for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { 691 for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) {
677 current_body = (mailimap_body*)current->data; 692 current_body = (mailimap_body*)current->data;
678 if (current_body->bd_type==MAILIMAP_BODY_MPART) { 693 if (current_body->bd_type==MAILIMAP_BODY_MPART) {
679 RecPart targetPart; 694 RecPart targetPart;
680 targetPart.setType("multipart"); 695 targetPart.setType("multipart");
681 fillMultiPart(targetPart,mailDescription); 696 fillMultiPart(targetPart,mailDescription);
682 countlist.append(current_count); 697 countlist.append(current_count);
683 targetPart.setPositionlist(countlist); 698 targetPart.setPositionlist(countlist);
684 target_body.addPart(targetPart); 699 target_body.addPart(targetPart);
685 QString id(""); 700 QString id("");
686 for (unsigned int j = 0; j < countlist.count();++j) { 701 for (unsigned int j = 0; j < countlist.count();++j) {
687 id+=(j>0?" ":""); 702 id+=(j>0?" ":"");
688 id+=QString("%1").arg(countlist[j]); 703 id+=QString("%1").arg(countlist[j]);
689 } 704 }
690 qDebug("ID(mpart) = %s",id.latin1()); 705 qDebug("ID(mpart) = %s",id.latin1());
691 } 706 }
692 traverseBody(mail,current_body,target_body,current_recursion+1,countlist,ccount); 707 traverseBody(mail,current_body,target_body,current_recursion+1,countlist,ccount);
693 if (current_body->bd_type==MAILIMAP_BODY_MPART) { 708 if (current_body->bd_type==MAILIMAP_BODY_MPART) {
694 countlist = recList; 709 countlist = recList;
695 } 710 }
696 ++ccount; 711 ++ccount;
697 } 712 }
698 } 713 }
699 break; 714 break;
700 default: 715 default:
701 break; 716 break;
702 } 717 }
703} 718}
diff --git a/noncore/net/mail/libmailwrapper/libmailwrapper.pro b/noncore/net/mail/libmailwrapper/libmailwrapper.pro
index 8ea04a4..cb1e573 100644
--- a/noncore/net/mail/libmailwrapper/libmailwrapper.pro
+++ b/noncore/net/mail/libmailwrapper/libmailwrapper.pro
@@ -1,50 +1,52 @@
1TEMPLATE = lib 1TEMPLATE = lib
2CONFIG += qt warn_on debug 2CONFIG += qt warn_on debug
3 3
4HEADERS = mailwrapper.h \ 4HEADERS = mailwrapper.h \
5 imapwrapper.h \ 5 imapwrapper.h \
6 mailtypes.h \ 6 mailtypes.h \
7 pop3wrapper.h \ 7 pop3wrapper.h \
8 abstractmail.h \ 8 abstractmail.h \
9 smtpwrapper.h \ 9 smtpwrapper.h \
10 genericwrapper.h \ 10 genericwrapper.h \
11 mboxwrapper.h \ 11 mboxwrapper.h \
12 settings.h \ 12 settings.h \
13 logindialog.h \ 13 logindialog.h \
14 sendmailprogress.h \ 14 sendmailprogress.h \
15 statusmail.h \ 15 statusmail.h \
16 mhwrapper.h \ 16 mhwrapper.h \
17 nntpwrapper.h 17 nntpwrapper.h \
18 18 generatemail.h
19
19SOURCES = imapwrapper.cpp \ 20SOURCES = imapwrapper.cpp \
20 mailwrapper.cpp \ 21 mailwrapper.cpp \
21 mailtypes.cpp \ 22 mailtypes.cpp \
22 pop3wrapper.cpp \ 23 pop3wrapper.cpp \
23 abstractmail.cpp \ 24 abstractmail.cpp \
24 smtpwrapper.cpp \ 25 smtpwrapper.cpp \
25 genericwrapper.cpp \ 26 genericwrapper.cpp \
26 mboxwrapper.cpp \ 27 mboxwrapper.cpp \
27 settings.cpp \ 28 settings.cpp \
28 logindialog.cpp \ 29 logindialog.cpp \
29 sendmailprogress.cpp \ 30 sendmailprogress.cpp \
30 statusmail.cpp \ 31 statusmail.cpp \
31 mhwrapper.cpp \ 32 mhwrapper.cpp \
32 nntpwrapper.cpp 33 nntpwrapper.cpp \
34 generatemail.cpp
33 35
34 INTERFACES = logindialogui.ui \ 36INTERFACES = logindialogui.ui \
35 sendmailprogressui.ui 37 sendmailprogressui.ui
36 38
37 39
38INCLUDEPATH += $(OPIEDIR)/include 40INCLUDEPATH += $(OPIEDIR)/include
39 41
40CONFTEST = $$system( echo $CONFIG_TARGET_MACOSX ) 42CONFTEST = $$system( echo $CONFIG_TARGET_MACOSX )
41contains( CONFTEST, y ){ 43contains( CONFTEST, y ){
42 LIBS += -lqpe -letpan -lssl -lcrypto -liconv 44 LIBS += -lqpe -letpan -lssl -lcrypto -liconv
43}else{ 45}else{
44 LIBS += -lqpe -letpan -lssl -lcrypto 46 LIBS += -lqpe -letpan -lssl -lcrypto
45} 47}
46 48
47DESTDIR = $(OPIEDIR)/lib$(PROJMAK) 49DESTDIR = $(OPIEDIR)/lib$(PROJMAK)
48TARGET = mailwrapper 50TARGET = mailwrapper
49 51
50include ( $(OPIEDIR)/include.pro ) 52include ( $(OPIEDIR)/include.pro )
diff --git a/noncore/net/mail/libmailwrapper/mailtypes.cpp b/noncore/net/mail/libmailwrapper/mailtypes.cpp
index 96e0fd5..e4646d9 100644
--- a/noncore/net/mail/libmailwrapper/mailtypes.cpp
+++ b/noncore/net/mail/libmailwrapper/mailtypes.cpp
@@ -1,357 +1,368 @@
1#include "mailtypes.h" 1#include "mailtypes.h"
2#include <stdlib.h> 2#include <stdlib.h>
3 3
4RecMail::RecMail() 4RecMail::RecMail()
5 :subject(""),date(""),from(""),mbox(""),msg_id(""),msg_number(0),msg_size(0),msg_flags(7) 5 :subject(""),date(""),from(""),mbox(""),msg_id(""),msg_number(0),msg_size(0),msg_flags(7)
6{ 6{
7 init(); 7 init();
8} 8}
9 9
10RecMail::RecMail(const RecMail&old) 10RecMail::RecMail(const RecMail&old)
11 :subject(""),date(""),from(""),mbox(""),msg_id(""),msg_number(0),msg_flags(7) 11 :subject(""),date(""),from(""),mbox(""),msg_id(""),msg_number(0),msg_flags(7)
12{ 12{
13 init(); 13 init();
14 copy_old(old); 14 copy_old(old);
15 qDebug("Copy constructor RecMail"); 15 qDebug("Copy constructor RecMail");
16} 16}
17 17
18RecMail::~RecMail() 18RecMail::~RecMail()
19{ 19{
20 wrapper = 0; 20 wrapper = 0;
21} 21}
22 22
23void RecMail::copy_old(const RecMail&old) 23void RecMail::copy_old(const RecMail&old)
24{ 24{
25 subject = old.subject; 25 subject = old.subject;
26 date = old.date; 26 date = old.date;
27 mbox = old.mbox; 27 mbox = old.mbox;
28 msg_id = old.msg_id; 28 msg_id = old.msg_id;
29 msg_size = old.msg_size; 29 msg_size = old.msg_size;
30 msg_number = old.msg_number; 30 msg_number = old.msg_number;
31 from = old.from; 31 from = old.from;
32 msg_flags = old.msg_flags; 32 msg_flags = old.msg_flags;
33 to = old.to; 33 to = old.to;
34 cc = old.cc; 34 cc = old.cc;
35 bcc = old.bcc; 35 bcc = old.bcc;
36 wrapper = old.wrapper; 36 wrapper = old.wrapper;
37 in_reply_to = old.in_reply_to; 37 in_reply_to = old.in_reply_to;
38 references = old.references;
38} 39}
39 40
40void RecMail::init() 41void RecMail::init()
41{ 42{
42 to.clear(); 43 to.clear();
43 cc.clear(); 44 cc.clear();
44 bcc.clear(); 45 bcc.clear();
45 in_reply_to.clear(); 46 in_reply_to.clear();
47 references.clear();
46 wrapper = 0; 48 wrapper = 0;
47} 49}
48 50
49void RecMail::setWrapper(AbstractMail*awrapper) 51void RecMail::setWrapper(AbstractMail*awrapper)
50{ 52{
51 wrapper = awrapper; 53 wrapper = awrapper;
52} 54}
53 55
54AbstractMail* RecMail::Wrapper() 56AbstractMail* RecMail::Wrapper()
55{ 57{
56 return wrapper; 58 return wrapper;
57} 59}
58 60
59void RecMail::setTo(const QStringList&list) 61void RecMail::setTo(const QStringList&list)
60{ 62{
61 to = list; 63 to = list;
62} 64}
63 65
64const QStringList&RecMail::To()const 66const QStringList&RecMail::To()const
65{ 67{
66 return to; 68 return to;
67} 69}
68 70
69void RecMail::setCC(const QStringList&list) 71void RecMail::setCC(const QStringList&list)
70{ 72{
71 cc = list; 73 cc = list;
72} 74}
73 75
74const QStringList&RecMail::CC()const 76const QStringList&RecMail::CC()const
75{ 77{
76 return cc; 78 return cc;
77} 79}
78 80
79void RecMail::setBcc(const QStringList&list) 81void RecMail::setBcc(const QStringList&list)
80{ 82{
81 bcc = list; 83 bcc = list;
82} 84}
83 85
84const QStringList& RecMail::Bcc()const 86const QStringList& RecMail::Bcc()const
85{ 87{
86 return bcc; 88 return bcc;
87} 89}
88 90
89void RecMail::setInreply(const QStringList&list) 91void RecMail::setInreply(const QStringList&list)
90{ 92{
91 in_reply_to = list; 93 in_reply_to = list;
92} 94}
93 95
94const QStringList& RecMail::Inreply()const 96const QStringList& RecMail::Inreply()const
95{ 97{
96 return in_reply_to; 98 return in_reply_to;
97} 99}
98 100
101void RecMail::setReferences(const QStringList&list)
102{
103 references = list;
104}
105
106const QStringList& RecMail::References()const
107{
108 return references;
109}
99 110
100RecPart::RecPart() 111RecPart::RecPart()
101 : m_type(""),m_subtype(""),m_identifier(""),m_encoding(""),m_description(""),m_lines(0),m_size(0) 112 : m_type(""),m_subtype(""),m_identifier(""),m_encoding(""),m_description(""),m_lines(0),m_size(0)
102{ 113{
103 m_Parameters.clear(); 114 m_Parameters.clear();
104 m_poslist.clear(); 115 m_poslist.clear();
105} 116}
106 117
107RecPart::~RecPart() 118RecPart::~RecPart()
108{ 119{
109} 120}
110 121
111void RecPart::setSize(unsigned int size) 122void RecPart::setSize(unsigned int size)
112{ 123{
113 m_size = size; 124 m_size = size;
114} 125}
115 126
116const unsigned int RecPart::Size()const 127const unsigned int RecPart::Size()const
117{ 128{
118 return m_size; 129 return m_size;
119} 130}
120 131
121void RecPart::setLines(unsigned int lines) 132void RecPart::setLines(unsigned int lines)
122{ 133{
123 m_lines = lines; 134 m_lines = lines;
124} 135}
125 136
126const unsigned int RecPart::Lines()const 137const unsigned int RecPart::Lines()const
127{ 138{
128 return m_lines; 139 return m_lines;
129} 140}
130 141
131const QString& RecPart::Type()const 142const QString& RecPart::Type()const
132{ 143{
133 return m_type; 144 return m_type;
134} 145}
135 146
136void RecPart::setType(const QString&type) 147void RecPart::setType(const QString&type)
137{ 148{
138 m_type = type; 149 m_type = type;
139} 150}
140 151
141const QString& RecPart::Subtype()const 152const QString& RecPart::Subtype()const
142{ 153{
143 return m_subtype; 154 return m_subtype;
144} 155}
145 156
146void RecPart::setSubtype(const QString&subtype) 157void RecPart::setSubtype(const QString&subtype)
147{ 158{
148 m_subtype = subtype; 159 m_subtype = subtype;
149} 160}
150 161
151const QString& RecPart::Identifier()const 162const QString& RecPart::Identifier()const
152{ 163{
153 return m_identifier; 164 return m_identifier;
154} 165}
155 166
156void RecPart::setIdentifier(const QString&identifier) 167void RecPart::setIdentifier(const QString&identifier)
157{ 168{
158 m_identifier = identifier; 169 m_identifier = identifier;
159} 170}
160 171
161const QString& RecPart::Encoding()const 172const QString& RecPart::Encoding()const
162{ 173{
163 return m_encoding; 174 return m_encoding;
164} 175}
165 176
166void RecPart::setEncoding(const QString&encoding) 177void RecPart::setEncoding(const QString&encoding)
167{ 178{
168 m_encoding = encoding; 179 m_encoding = encoding;
169} 180}
170 181
171const QString& RecPart::Description()const 182const QString& RecPart::Description()const
172{ 183{
173 return m_description; 184 return m_description;
174} 185}
175 186
176void RecPart::setDescription(const QString&desc) 187void RecPart::setDescription(const QString&desc)
177{ 188{
178 m_description = desc; 189 m_description = desc;
179} 190}
180 191
181void RecPart::setParameters(const part_plist_t&list) 192void RecPart::setParameters(const part_plist_t&list)
182{ 193{
183 m_Parameters = list; 194 m_Parameters = list;
184} 195}
185 196
186const part_plist_t& RecPart::Parameters()const 197const part_plist_t& RecPart::Parameters()const
187{ 198{
188 return m_Parameters; 199 return m_Parameters;
189} 200}
190 201
191void RecPart::addParameter(const QString&key,const QString&value) 202void RecPart::addParameter(const QString&key,const QString&value)
192{ 203{
193 m_Parameters[key]=value; 204 m_Parameters[key]=value;
194} 205}
195 206
196const QString RecPart::searchParamter(const QString&key)const 207const QString RecPart::searchParamter(const QString&key)const
197{ 208{
198 QString value(""); 209 QString value("");
199 part_plist_t::ConstIterator it = m_Parameters.find(key); 210 part_plist_t::ConstIterator it = m_Parameters.find(key);
200 if (it != m_Parameters.end()) { 211 if (it != m_Parameters.end()) {
201 value = it.data(); 212 value = it.data();
202 } 213 }
203 return value; 214 return value;
204} 215}
205 216
206void RecPart::setPositionlist(const QValueList<int>&poslist) 217void RecPart::setPositionlist(const QValueList<int>&poslist)
207{ 218{
208 m_poslist = poslist; 219 m_poslist = poslist;
209} 220}
210 221
211const QValueList<int>& RecPart::Positionlist()const 222const QValueList<int>& RecPart::Positionlist()const
212{ 223{
213 return m_poslist; 224 return m_poslist;
214} 225}
215 226
216RecBody::RecBody() 227RecBody::RecBody()
217 : m_BodyText(),m_PartsList(),m_description() 228 : m_BodyText(),m_PartsList(),m_description()
218{ 229{
219 m_PartsList.clear(); 230 m_PartsList.clear();
220} 231}
221 232
222RecBody::~RecBody() 233RecBody::~RecBody()
223{ 234{
224} 235}
225 236
226void RecBody::setBodytext(const QString&bodyText) 237void RecBody::setBodytext(const QString&bodyText)
227{ 238{
228 m_BodyText = bodyText; 239 m_BodyText = bodyText;
229} 240}
230 241
231const QString& RecBody::Bodytext()const 242const QString& RecBody::Bodytext()const
232{ 243{
233 return m_BodyText; 244 return m_BodyText;
234} 245}
235 246
236void RecBody::setParts(const QValueList<RecPart>&parts) 247void RecBody::setParts(const QValueList<RecPart>&parts)
237{ 248{
238 m_PartsList.clear(); 249 m_PartsList.clear();
239 m_PartsList = parts; 250 m_PartsList = parts;
240} 251}
241 252
242const QValueList<RecPart>& RecBody::Parts()const 253const QValueList<RecPart>& RecBody::Parts()const
243{ 254{
244 return m_PartsList; 255 return m_PartsList;
245} 256}
246 257
247void RecBody::addPart(const RecPart& part) 258void RecBody::addPart(const RecPart& part)
248{ 259{
249 m_PartsList.append(part); 260 m_PartsList.append(part);
250} 261}
251 262
252void RecBody::setDescription(const RecPart&des) 263void RecBody::setDescription(const RecPart&des)
253{ 264{
254 m_description = des; 265 m_description = des;
255} 266}
256 267
257const RecPart& RecBody::Description()const 268const RecPart& RecBody::Description()const
258{ 269{
259 return m_description; 270 return m_description;
260} 271}
261 272
262/* handling encoded content */ 273/* handling encoded content */
263encodedString::encodedString() 274encodedString::encodedString()
264{ 275{
265 init(); 276 init();
266} 277}
267 278
268encodedString::encodedString(const char*nContent,unsigned int nSize) 279encodedString::encodedString(const char*nContent,unsigned int nSize)
269{ 280{
270 init(); 281 init();
271 setContent(nContent,nSize); 282 setContent(nContent,nSize);
272} 283}
273 284
274encodedString::encodedString(char*nContent,unsigned int nSize) 285encodedString::encodedString(char*nContent,unsigned int nSize)
275{ 286{
276 init(); 287 init();
277 setContent(nContent,nSize); 288 setContent(nContent,nSize);
278} 289}
279 290
280encodedString::encodedString(const encodedString&old) 291encodedString::encodedString(const encodedString&old)
281{ 292{
282 init(); 293 init();
283 copy_old(old); 294 copy_old(old);
284 qDebug("encodedeString: copy constructor!"); 295 qDebug("encodedeString: copy constructor!");
285} 296}
286 297
287encodedString& encodedString::operator=(const encodedString&old) 298encodedString& encodedString::operator=(const encodedString&old)
288{ 299{
289 init(); 300 init();
290 copy_old(old); 301 copy_old(old);
291 qDebug("encodedString: assign operator!"); 302 qDebug("encodedString: assign operator!");
292 return *this; 303 return *this;
293} 304}
294 305
295encodedString::~encodedString() 306encodedString::~encodedString()
296{ 307{
297 clean(); 308 clean();
298} 309}
299 310
300void encodedString::init() 311void encodedString::init()
301{ 312{
302 content = 0; 313 content = 0;
303 size = 0; 314 size = 0;
304} 315}
305 316
306void encodedString::clean() 317void encodedString::clean()
307{ 318{
308 if (content) { 319 if (content) {
309 free(content); 320 free(content);
310 } 321 }
311 content = 0; 322 content = 0;
312 size = 0; 323 size = 0;
313} 324}
314 325
315void encodedString::copy_old(const encodedString&old) 326void encodedString::copy_old(const encodedString&old)
316{ 327{
317 clean(); 328 clean();
318 if (old.size>0 && old.content) { 329 if (old.size>0 && old.content) {
319 content = (char*)malloc(old.size*sizeof(char)); 330 content = (char*)malloc(old.size*sizeof(char));
320 memcpy(content,old.content,size); 331 memcpy(content,old.content,size);
321 size = old.size; 332 size = old.size;
322 } 333 }
323} 334}
324 335
325const char*encodedString::Content()const 336const char*encodedString::Content()const
326{ 337{
327 return content; 338 return content;
328} 339}
329 340
330const int encodedString::Length()const 341const int encodedString::Length()const
331{ 342{
332 return size; 343 return size;
333} 344}
334 345
335void encodedString::setContent(const char*nContent,int nSize) 346void encodedString::setContent(const char*nContent,int nSize)
336{ 347{
337 if (nSize>0 && nContent) { 348 if (nSize>0 && nContent) {
338 content = (char*)malloc(nSize*sizeof(char)); 349 content = (char*)malloc(nSize*sizeof(char));
339 memcpy(content,nContent,nSize); 350 memcpy(content,nContent,nSize);
340 size = nSize; 351 size = nSize;
341 } 352 }
342} 353}
343 354
344void encodedString::setContent(char*nContent,int nSize) 355void encodedString::setContent(char*nContent,int nSize)
345{ 356{
346 content = nContent; 357 content = nContent;
347 size = nSize; 358 size = nSize;
348} 359}
349 360
350folderStat&folderStat::operator=(const folderStat&old) 361folderStat&folderStat::operator=(const folderStat&old)
351{ 362{
352 message_count = old.message_count; 363 message_count = old.message_count;
353 message_unseen = old.message_unseen; 364 message_unseen = old.message_unseen;
354 message_recent = old.message_recent; 365 message_recent = old.message_recent;
355 return *this; 366 return *this;
356} 367}
357 368
diff --git a/noncore/net/mail/libmailwrapper/mailtypes.h b/noncore/net/mail/libmailwrapper/mailtypes.h
index 1420f79..17c6db9 100644
--- a/noncore/net/mail/libmailwrapper/mailtypes.h
+++ b/noncore/net/mail/libmailwrapper/mailtypes.h
@@ -1,195 +1,198 @@
1#ifndef __MAIL_TYPES_H 1#ifndef __MAIL_TYPES_H
2#define __MAIL_TYPES_H 2#define __MAIL_TYPES_H
3 3
4#define FLAG_ANSWERED 0 4#define FLAG_ANSWERED 0
5#define FLAG_FLAGGED 1 5#define FLAG_FLAGGED 1
6#define FLAG_DELETED 2 6#define FLAG_DELETED 2
7#define FLAG_SEEN 3 7#define FLAG_SEEN 3
8#define FLAG_DRAFT 4 8#define FLAG_DRAFT 4
9#define FLAG_RECENT 5 9#define FLAG_RECENT 5
10 10
11#include <qlist.h> 11#include <qlist.h>
12#include <qbitarray.h> 12#include <qbitarray.h>
13#include <qstring.h> 13#include <qstring.h>
14#include <qstringlist.h> 14#include <qstringlist.h>
15#include <qmap.h> 15#include <qmap.h>
16#include <qvaluelist.h> 16#include <qvaluelist.h>
17 17
18class AbstractMail; 18class AbstractMail;
19/* a class to describe mails in a mailbox */ 19/* a class to describe mails in a mailbox */
20/* Attention! 20/* Attention!
21 From programmers point of view it would make sense to 21 From programmers point of view it would make sense to
22 store the mail body into this class, too. 22 store the mail body into this class, too.
23 But: not from the point of view of the device. 23 But: not from the point of view of the device.
24 Mailbodies can be real large. So we request them when 24 Mailbodies can be real large. So we request them when
25 needed from the mail-wrapper class direct from the server itself 25 needed from the mail-wrapper class direct from the server itself
26 (imap) or from a file-based cache (pop3?) 26 (imap) or from a file-based cache (pop3?)
27 So there is no interface "const QString&body()" but you should 27 So there is no interface "const QString&body()" but you should
28 make a request to the mailwrapper with this class as parameter to 28 make a request to the mailwrapper with this class as parameter to
29 get the body. Same words for the attachments. 29 get the body. Same words for the attachments.
30*/ 30*/
31class RecMail 31class RecMail
32{ 32{
33public: 33public:
34 RecMail(); 34 RecMail();
35 RecMail(const RecMail&old); 35 RecMail(const RecMail&old);
36 virtual ~RecMail(); 36 virtual ~RecMail();
37 37
38 const int getNumber()const{return msg_number;} 38 const int getNumber()const{return msg_number;}
39 void setNumber(int number){msg_number=number;} 39 void setNumber(int number){msg_number=number;}
40 const QString&getDate()const{ return date; } 40 const QString&getDate()const{ return date; }
41 void setDate( const QString&a ) { date = a; } 41 void setDate( const QString&a ) { date = a; }
42 const QString&getFrom()const{ return from; } 42 const QString&getFrom()const{ return from; }
43 void setFrom( const QString&a ) { from = a; } 43 void setFrom( const QString&a ) { from = a; }
44 const QString&getSubject()const { return subject; } 44 const QString&getSubject()const { return subject; }
45 void setSubject( const QString&s ) { subject = s; } 45 void setSubject( const QString&s ) { subject = s; }
46 const QString&getMbox()const{return mbox;} 46 const QString&getMbox()const{return mbox;}
47 void setMbox(const QString&box){mbox = box;} 47 void setMbox(const QString&box){mbox = box;}
48 void setMsgid(const QString&id){msg_id=id;} 48 void setMsgid(const QString&id){msg_id=id;}
49 const QString&Msgid()const{return msg_id;} 49 const QString&Msgid()const{return msg_id;}
50 void setReplyto(const QString&reply){replyto=reply;} 50 void setReplyto(const QString&reply){replyto=reply;}
51 const QString&Replyto()const{return replyto;} 51 const QString&Replyto()const{return replyto;}
52 void setMsgsize(int size){msg_size = size;} 52 void setMsgsize(int size){msg_size = size;}
53 const int Msgsize()const{return msg_size;} 53 const int Msgsize()const{return msg_size;}
54 54
55 55
56 void setTo(const QStringList&list); 56 void setTo(const QStringList&list);
57 const QStringList&To()const; 57 const QStringList&To()const;
58 void setCC(const QStringList&list); 58 void setCC(const QStringList&list);
59 const QStringList&CC()const; 59 const QStringList&CC()const;
60 void setBcc(const QStringList&list); 60 void setBcc(const QStringList&list);
61 const QStringList&Bcc()const; 61 const QStringList&Bcc()const;
62 void setInreply(const QStringList&list); 62 void setInreply(const QStringList&list);
63 const QStringList&Inreply()const; 63 const QStringList&Inreply()const;
64 void setReferences(const QStringList&list);
65 const QStringList&References()const;
66
64 const QBitArray&getFlags()const{return msg_flags;} 67 const QBitArray&getFlags()const{return msg_flags;}
65 void setFlags(const QBitArray&flags){msg_flags = flags;} 68 void setFlags(const QBitArray&flags){msg_flags = flags;}
66 69
67 void setWrapper(AbstractMail*wrapper); 70 void setWrapper(AbstractMail*wrapper);
68 AbstractMail* Wrapper(); 71 AbstractMail* Wrapper();
69 72
70protected: 73protected:
71 QString subject,date,from,mbox,msg_id,replyto; 74 QString subject,date,from,mbox,msg_id,replyto;
72 int msg_number,msg_size; 75 int msg_number,msg_size;
73 QBitArray msg_flags; 76 QBitArray msg_flags;
74 QStringList to,cc,bcc,in_reply_to; 77 QStringList to,cc,bcc,in_reply_to,references;
75 AbstractMail*wrapper; 78 AbstractMail*wrapper;
76 void init(); 79 void init();
77 void copy_old(const RecMail&old); 80 void copy_old(const RecMail&old);
78}; 81};
79 82
80typedef QMap<QString,QString> part_plist_t; 83typedef QMap<QString,QString> part_plist_t;
81 84
82class RecPart 85class RecPart
83{ 86{
84protected: 87protected:
85 QString m_type,m_subtype,m_identifier,m_encoding,m_description; 88 QString m_type,m_subtype,m_identifier,m_encoding,m_description;
86 unsigned int m_lines,m_size; 89 unsigned int m_lines,m_size;
87 part_plist_t m_Parameters; 90 part_plist_t m_Parameters;
88 /* describes the position in the mail */ 91 /* describes the position in the mail */
89 QValueList<int> m_poslist; 92 QValueList<int> m_poslist;
90 93
91public: 94public:
92 RecPart(); 95 RecPart();
93 virtual ~RecPart(); 96 virtual ~RecPart();
94 97
95 const QString&Type()const; 98 const QString&Type()const;
96 void setType(const QString&type); 99 void setType(const QString&type);
97 const QString&Subtype()const; 100 const QString&Subtype()const;
98 void setSubtype(const QString&subtype); 101 void setSubtype(const QString&subtype);
99 const QString&Identifier()const; 102 const QString&Identifier()const;
100 void setIdentifier(const QString&identifier); 103 void setIdentifier(const QString&identifier);
101 const QString&Encoding()const; 104 const QString&Encoding()const;
102 void setEncoding(const QString&encoding); 105 void setEncoding(const QString&encoding);
103 const QString&Description()const; 106 const QString&Description()const;
104 void setDescription(const QString&desc); 107 void setDescription(const QString&desc);
105 void setLines(unsigned int lines); 108 void setLines(unsigned int lines);
106 const unsigned int Lines()const; 109 const unsigned int Lines()const;
107 void setSize(unsigned int size); 110 void setSize(unsigned int size);
108 const unsigned int Size()const; 111 const unsigned int Size()const;
109 112
110 113
111 void setParameters(const part_plist_t&list); 114 void setParameters(const part_plist_t&list);
112 const part_plist_t&Parameters()const; 115 const part_plist_t&Parameters()const;
113 void addParameter(const QString&key,const QString&value); 116 void addParameter(const QString&key,const QString&value);
114 const QString searchParamter(const QString&key)const; 117 const QString searchParamter(const QString&key)const;
115 void setPositionlist(const QValueList<int>&poslist); 118 void setPositionlist(const QValueList<int>&poslist);
116 const QValueList<int>& Positionlist()const; 119 const QValueList<int>& Positionlist()const;
117}; 120};
118 121
119class RecBody 122class RecBody
120{ 123{
121protected: 124protected:
122 QString m_BodyText; 125 QString m_BodyText;
123 QValueList<RecPart> m_PartsList; 126 QValueList<RecPart> m_PartsList;
124 RecPart m_description; 127 RecPart m_description;
125 128
126public: 129public:
127 RecBody(); 130 RecBody();
128 virtual ~RecBody(); 131 virtual ~RecBody();
129 void setBodytext(const QString&); 132 void setBodytext(const QString&);
130 const QString& Bodytext()const; 133 const QString& Bodytext()const;
131 134
132 void setDescription(const RecPart&des); 135 void setDescription(const RecPart&des);
133 const RecPart& Description()const; 136 const RecPart& Description()const;
134 137
135 void setParts(const QValueList<RecPart>&parts); 138 void setParts(const QValueList<RecPart>&parts);
136 const QValueList<RecPart>& Parts()const; 139 const QValueList<RecPart>& Parts()const;
137 void addPart(const RecPart&part); 140 void addPart(const RecPart&part);
138}; 141};
139 142
140class encodedString 143class encodedString
141{ 144{
142public: 145public:
143 encodedString(); 146 encodedString();
144 /* 147 /*
145 creates an new content string. 148 creates an new content string.
146 it makes a deep copy of it! 149 it makes a deep copy of it!
147 */ 150 */
148 encodedString(const char*nContent,unsigned int length); 151 encodedString(const char*nContent,unsigned int length);
149 /* 152 /*
150 Take over the nContent. Means: it will just copy the pointer, not the content. 153 Take over the nContent. Means: it will just copy the pointer, not the content.
151 so make sure: No one else frees the string, the string has allocated with 154 so make sure: No one else frees the string, the string has allocated with
152 malloc for compatibility with c-based libs 155 malloc for compatibility with c-based libs
153 */ 156 */
154 encodedString(char*nContent,unsigned int nSize); 157 encodedString(char*nContent,unsigned int nSize);
155 /* copy construkor - makes ALWAYS a deep copy!!!! */ 158 /* copy construkor - makes ALWAYS a deep copy!!!! */
156 encodedString(const encodedString&old); 159 encodedString(const encodedString&old);
157 /* assign operator - makes ALWAYS a deep copy!!!! */ 160 /* assign operator - makes ALWAYS a deep copy!!!! */
158 encodedString& operator=(const encodedString&old); 161 encodedString& operator=(const encodedString&old);
159 /* destructor - cleans the content */ 162 /* destructor - cleans the content */
160 virtual ~encodedString(); 163 virtual ~encodedString();
161 164
162 /* returns a pointer to the content - do not delete yoursel! */ 165 /* returns a pointer to the content - do not delete yoursel! */
163 const char*Content()const; 166 const char*Content()const;
164 /* returns the lengths of the content 'cause it must not be a null-terminated string! */ 167 /* returns the lengths of the content 'cause it must not be a null-terminated string! */
165 const int Length()const; 168 const int Length()const;
166 169
167 /* 170 /*
168 makes a deep copy of nContent! 171 makes a deep copy of nContent!
169 */ 172 */
170 void setContent(const char*nContent,int nSize); 173 void setContent(const char*nContent,int nSize);
171 /* 174 /*
172 Take over the nContent. Means: it will just copy the pointer, not the content. 175 Take over the nContent. Means: it will just copy the pointer, not the content.
173 so make sure: No one else frees the string, the string has allocated with 176 so make sure: No one else frees the string, the string has allocated with
174 malloc for compatibility with c-based libs 177 malloc for compatibility with c-based libs
175 */ 178 */
176 void setContent(char*nContent,int nSize); 179 void setContent(char*nContent,int nSize);
177 180
178protected: 181protected:
179 char * content; 182 char * content;
180 unsigned int size; 183 unsigned int size;
181 184
182 void init(); 185 void init();
183 void copy_old(const encodedString&old); 186 void copy_old(const encodedString&old);
184 void clean(); 187 void clean();
185}; 188};
186 189
187struct folderStat 190struct folderStat
188{ 191{
189 unsigned int message_count; 192 unsigned int message_count;
190 unsigned int message_unseen; 193 unsigned int message_unseen;
191 unsigned int message_recent; 194 unsigned int message_recent;
192 folderStat&operator=(const folderStat&old); 195 folderStat&operator=(const folderStat&old);
193}; 196};
194 197
195#endif 198#endif
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,900 +1,456 @@
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
21const 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
23progressMailSend*SMTPwrapper::sendProgress = 0; 16progressMailSend*SMTPwrapper::sendProgress = 0;
24 17
25SMTPwrapper::SMTPwrapper(SMTPaccount * aSmtp ) 18SMTPwrapper::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
37SMTPwrapper::~SMTPwrapper() 30SMTPwrapper::~SMTPwrapper()
38{ 31{
39 disc_server(); 32 disc_server();
40} 33}
41 34
42void SMTPwrapper::emitQCop( int queued ) { 35void SMTPwrapper::emitQCop( int queued ) {
43 QCopEnvelope env( "QPE/Pim", "outgoingMails(int)" ); 36 QCopEnvelope env( "QPE/Pim", "outgoingMails(int)" );
44 env << queued; 37 env << queued;
45} 38}
46 39
47QString SMTPwrapper::mailsmtpError( int errnum ) { 40QString SMTPwrapper::mailsmtpError( int errnum ) {
48 switch ( errnum ) { 41 switch ( errnum ) {
49 case MAILSMTP_NO_ERROR: 42 case MAILSMTP_NO_ERROR:
50 return tr( "No error" ); 43 return tr( "No error" );
51 case MAILSMTP_ERROR_UNEXPECTED_CODE: 44 case MAILSMTP_ERROR_UNEXPECTED_CODE:
52 return tr( "Unexpected error code" ); 45 return tr( "Unexpected error code" );
53 case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE: 46 case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE:
54 return tr( "Service not available" ); 47 return tr( "Service not available" );
55 case MAILSMTP_ERROR_STREAM: 48 case MAILSMTP_ERROR_STREAM:
56 return tr( "Stream error" ); 49 return tr( "Stream error" );
57 case MAILSMTP_ERROR_HOSTNAME: 50 case MAILSMTP_ERROR_HOSTNAME:
58 return tr( "gethostname() failed" ); 51 return tr( "gethostname() failed" );
59 case MAILSMTP_ERROR_NOT_IMPLEMENTED: 52 case MAILSMTP_ERROR_NOT_IMPLEMENTED:
60 return tr( "Not implemented" ); 53 return tr( "Not implemented" );
61 case MAILSMTP_ERROR_ACTION_NOT_TAKEN: 54 case MAILSMTP_ERROR_ACTION_NOT_TAKEN:
62 return tr( "Error, action not taken" ); 55 return tr( "Error, action not taken" );
63 case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION: 56 case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION:
64 return tr( "Data exceeds storage allocation" ); 57 return tr( "Data exceeds storage allocation" );
65 case MAILSMTP_ERROR_IN_PROCESSING: 58 case MAILSMTP_ERROR_IN_PROCESSING:
66 return tr( "Error in processing" ); 59 return tr( "Error in processing" );
67 case MAILSMTP_ERROR_STARTTLS_NOT_SUPPORTED: 60 case MAILSMTP_ERROR_STARTTLS_NOT_SUPPORTED:
68 return tr( "Starttls not supported" ); 61 return tr( "Starttls not supported" );
69 // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE: 62 // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE:
70 // return tr( "Insufficient system storage" ); 63 // return tr( "Insufficient system storage" );
71 case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE: 64 case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE:
72 return tr( "Mailbox unavailable" ); 65 return tr( "Mailbox unavailable" );
73 case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED: 66 case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED:
74 return tr( "Mailbox name not allowed" ); 67 return tr( "Mailbox name not allowed" );
75 case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND: 68 case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND:
76 return tr( "Bad command sequence" ); 69 return tr( "Bad command sequence" );
77 case MAILSMTP_ERROR_USER_NOT_LOCAL: 70 case MAILSMTP_ERROR_USER_NOT_LOCAL:
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
90mailimf_mailbox *SMTPwrapper::newMailbox(const QString&name, const QString&mail ) {
91 return mailimf_mailbox_new( strdup( name.latin1() ),
92 strdup( mail.latin1() ) );
93}
94
95mailimf_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
146mailimf_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
222err_free_xmailer:
223 if (xmailer)
224 mailimf_field_free( xmailer );
225err_free_fields:
226 if (fields)
227 mailimf_fields_free( fields );
228err_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 );
237err_free_from:
238 if (from)
239 mailimf_mailbox_list_free( from );
240err_free_fromBox:
241 mailimf_mailbox_free( fromBox );
242err_free_sender:
243 if (sender)
244 mailimf_mailbox_free( sender );
245err_free:
246 if (subject)
247 free( subject );
248 qDebug( "createImfFields - error" );
249
250 return NULL; // Error :(
251}
252
253mailmime *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
287err_free_txtPart:
288 mailmime_free( txtPart );
289err_free_fields:
290 mailmime_fields_free( fields );
291err_free_content:
292 mailmime_content_free( content );
293err_free_param:
294 mailmime_parameter_free( param );
295err_free:
296 qDebug( "buildTxtPart - error" );
297
298 return NULL; // Error :(
299}
300
301mailmime *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
379void 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
403mailmime *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
431err_free_txtPart:
432 mailmime_free( txtPart );
433err_free_message:
434 mailmime_free( message );
435err_free_fields:
436 mailimf_fields_free( fields );
437err_free:
438 qDebug( "createMimeMail: error" );
439
440 return NULL; // Error :(
441}
442
443mailimf_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
459void 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
479clist *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
506char *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
521char *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
528void SMTPwrapper::progress( size_t current, size_t maximum ) { 84void 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
535void SMTPwrapper::storeMail(const char*mail, size_t length, const QString&box) { 91void 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();
539 AbstractMail*wrap = AbstractMail::getWrapper(localfolders); 95 AbstractMail*wrap = AbstractMail::getWrapper(localfolders);
540 wrap->createMbox(box); 96 wrap->createMbox(box);
541 wrap->storeMessage(mail,length,box); 97 wrap->storeMessage(mail,length,box);
542 delete wrap; 98 delete wrap;
543} 99}
544 100
545void SMTPwrapper::smtpSend( mailmime *mail,bool later) { 101void SMTPwrapper::smtpSend( mailmime *mail,bool later) {
546 clist *rcpts = 0; 102 clist *rcpts = 0;
547 char *from, *data; 103 char *from, *data;
548 size_t size; 104 size_t size;
549 105
550 from = data = 0; 106 from = data = 0;
551 107
552 mailmessage * msg = 0; 108 mailmessage * msg = 0;
553 msg = mime_message_init(mail); 109 msg = mime_message_init(mail);
554 mime_message_set_tmpdir(msg,getenv( "HOME" )); 110 mime_message_set_tmpdir(msg,getenv( "HOME" ));
555 int r = mailmessage_fetch(msg,&data,&size); 111 int r = mailmessage_fetch(msg,&data,&size);
556 mime_message_detach_mime(msg); 112 mime_message_detach_mime(msg);
557 mailmessage_free(msg); 113 mailmessage_free(msg);
558 if (r != MAIL_NO_ERROR || !data) { 114 if (r != MAIL_NO_ERROR || !data) {
559 if (data) 115 if (data)
560 free(data); 116 free(data);
561 qDebug("Error fetching mime..."); 117 qDebug("Error fetching mime...");
562 return; 118 return;
563 } 119 }
564 msg = 0; 120 msg = 0;
565 if (later) { 121 if (later) {
566 storeMail(data,size,"Outgoing"); 122 storeMail(data,size,"Outgoing");
567 if (data) 123 if (data)
568 free( data ); 124 free( data );
569 Config cfg( "mail" ); 125 Config cfg( "mail" );
570 cfg.setGroup( "Status" ); 126 cfg.setGroup( "Status" );
571 cfg.writeEntry( "outgoing", ++m_queuedMail ); 127 cfg.writeEntry( "outgoing", ++m_queuedMail );
572 emit queuedMails( m_queuedMail ); 128 emit queuedMails( m_queuedMail );
573 return; 129 return;
574 } 130 }
575 from = getFrom( mail ); 131 from = getFrom( mail );
576 rcpts = createRcptList( mail->mm_data.mm_message.mm_fields ); 132 rcpts = createRcptList( mail->mm_data.mm_message.mm_fields );
577 smtpSend(from,rcpts,data,size); 133 smtpSend(from,rcpts,data,size);
578 if (data) { 134 if (data) {
579 free(data); 135 free(data);
580 } 136 }
581 if (from) { 137 if (from) {
582 free(from); 138 free(from);
583 } 139 }
584 if (rcpts) 140 if (rcpts)
585 smtp_address_list_free( rcpts ); 141 smtp_address_list_free( rcpts );
586} 142}
587 143
588void SMTPwrapper::storeFailedMail(const char*data,unsigned int size, const char*failuremessage) 144void SMTPwrapper::storeFailedMail(const char*data,unsigned int size, const char*failuremessage)
589{ 145{
590 if (data) { 146 if (data) {
591 storeMail(data,size,"Sendfailed"); 147 storeMail(data,size,"Sendfailed");
592 } 148 }
593 if (failuremessage) { 149 if (failuremessage) {
594 QMessageBox::critical(0,tr("Error sending mail"), 150 QMessageBox::critical(0,tr("Error sending mail"),
595 tr("<center>%1</center>").arg(failuremessage)); 151 tr("<center>%1</center>").arg(failuremessage));
596 } 152 }
597} 153}
598 154
599int SMTPwrapper::start_smtp_tls() 155int SMTPwrapper::start_smtp_tls()
600{ 156{
601 if (!m_smtp) { 157 if (!m_smtp) {
602 return MAILSMTP_ERROR_IN_PROCESSING; 158 return MAILSMTP_ERROR_IN_PROCESSING;
603 } 159 }
604 int err = mailesmtp_starttls(m_smtp); 160 int err = mailesmtp_starttls(m_smtp);
605 if (err != MAILSMTP_NO_ERROR) return err; 161 if (err != MAILSMTP_NO_ERROR) return err;
606 mailstream_low * low; 162 mailstream_low * low;
607 mailstream_low * new_low; 163 mailstream_low * new_low;
608 low = mailstream_get_low(m_smtp->stream); 164 low = mailstream_get_low(m_smtp->stream);
609 if (!low) { 165 if (!low) {
610 return MAILSMTP_ERROR_IN_PROCESSING; 166 return MAILSMTP_ERROR_IN_PROCESSING;
611 } 167 }
612 int fd = mailstream_low_get_fd(low); 168 int fd = mailstream_low_get_fd(low);
613 if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) { 169 if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) {
614 mailstream_low_free(low); 170 mailstream_low_free(low);
615 mailstream_set_low(m_smtp->stream, new_low); 171 mailstream_set_low(m_smtp->stream, new_low);
616 } else { 172 } else {
617 return MAILSMTP_ERROR_IN_PROCESSING; 173 return MAILSMTP_ERROR_IN_PROCESSING;
618 } 174 }
619 return err; 175 return err;
620} 176}
621 177
622void SMTPwrapper::connect_server() 178void 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();
645 201
646 m_smtp = mailsmtp_new( 20, &progress ); 202 m_smtp = mailsmtp_new( 20, &progress );
647 if ( m_smtp == NULL ) { 203 if ( m_smtp == NULL ) {
648 /* no failure message cause this happens when problems with memory - than we 204 /* no failure message cause this happens when problems with memory - than we
649 we can not display any messagebox */ 205 we can not display any messagebox */
650 return; 206 return;
651 } 207 }
652 208
653 int err = MAILSMTP_NO_ERROR; 209 int err = MAILSMTP_NO_ERROR;
654 qDebug( "Servername %s at port %i", server, port ); 210 qDebug( "Servername %s at port %i", server, port );
655 if ( ssl ) { 211 if ( ssl ) {
656 qDebug( "SSL session" ); 212 qDebug( "SSL session" );
657 err = mailsmtp_ssl_connect( m_smtp, server, port ); 213 err = mailsmtp_ssl_connect( m_smtp, server, port );
658 } else { 214 } else {
659 qDebug( "No SSL session" ); 215 qDebug( "No SSL session" );
660 err = mailsmtp_socket_connect( m_smtp, server, port ); 216 err = mailsmtp_socket_connect( m_smtp, server, port );
661 } 217 }
662 if ( err != MAILSMTP_NO_ERROR ) { 218 if ( err != MAILSMTP_NO_ERROR ) {
663 qDebug("Error init connection"); 219 qDebug("Error init connection");
664 failuretext = tr("Error init SMTP connection: %1").arg(mailsmtpError(err)); 220 failuretext = tr("Error init SMTP connection: %1").arg(mailsmtpError(err));
665 result = 0; 221 result = 0;
666 } 222 }
667 223
668 /* switch to tls after init 'cause there it will send the ehlo */ 224 /* switch to tls after init 'cause there it will send the ehlo */
669 if (result) { 225 if (result) {
670 err = mailsmtp_init( m_smtp ); 226 err = mailsmtp_init( m_smtp );
671 if (err != MAILSMTP_NO_ERROR) { 227 if (err != MAILSMTP_NO_ERROR) {
672 result = 0; 228 result = 0;
673 failuretext = tr("Error init SMTP connection: %1").arg(mailsmtpError(err)); 229 failuretext = tr("Error init SMTP connection: %1").arg(mailsmtpError(err));
674 } 230 }
675 } 231 }
676 232
677 if (try_tls) { 233 if (try_tls) {
678 err = start_smtp_tls(); 234 err = start_smtp_tls();
679 if (err != MAILSMTP_NO_ERROR) { 235 if (err != MAILSMTP_NO_ERROR) {
680 try_tls = false; 236 try_tls = false;
681 } else { 237 } else {
682 err = mailesmtp_ehlo(m_smtp); 238 err = mailesmtp_ehlo(m_smtp);
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();
708 pass = m_SmtpAccount->getPassword().latin1(); 264 pass = m_SmtpAccount->getPassword().latin1();
709 } 265 }
710 qDebug( "session->auth: %i", m_smtp->auth); 266 qDebug( "session->auth: %i", m_smtp->auth);
711 if (result) { 267 if (result) {
712 err = mailsmtp_auth( m_smtp, (char*)user, (char*)pass ); 268 err = mailsmtp_auth( m_smtp, (char*)user, (char*)pass );
713 if ( err == MAILSMTP_NO_ERROR ) { 269 if ( err == MAILSMTP_NO_ERROR ) {
714 qDebug("auth ok"); 270 qDebug("auth ok");
715 } else { 271 } else {
716 failuretext = tr("Authentification failed"); 272 failuretext = tr("Authentification failed");
717 result = 0; 273 result = 0;
718 } 274 }
719 } 275 }
720 } 276 }
721} 277}
722 278
723void SMTPwrapper::disc_server() 279void SMTPwrapper::disc_server()
724{ 280{
725 if (m_smtp) { 281 if (m_smtp) {
726 mailsmtp_quit( m_smtp ); 282 mailsmtp_quit( m_smtp );
727 mailsmtp_free( m_smtp ); 283 mailsmtp_free( m_smtp );
728 m_smtp = 0; 284 m_smtp = 0;
729 } 285 }
730} 286}
731 287
732int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size ) 288int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size )
733{ 289{
734 int err,result; 290 int err,result;
735 QString failuretext = ""; 291 QString failuretext = "";
736 292
737 connect_server(); 293 connect_server();
738 294
739 result = 1; 295 result = 1;
740 if (m_smtp) { 296 if (m_smtp) {
741 err = mailsmtp_send( m_smtp, from, rcpts, data, size ); 297 err = mailsmtp_send( m_smtp, from, rcpts, data, size );
742 if ( err != MAILSMTP_NO_ERROR ) { 298 if ( err != MAILSMTP_NO_ERROR ) {
743 failuretext=tr("Error sending mail: %1").arg(mailsmtpError(err)); 299 failuretext=tr("Error sending mail: %1").arg(mailsmtpError(err));
744 result = 0; 300 result = 0;
745 } 301 }
746 } else { 302 } else {
747 result = 0; 303 result = 0;
748 } 304 }
749 305
750 if (!result) { 306 if (!result) {
751 storeFailedMail(data,size,failuretext); 307 storeFailedMail(data,size,failuretext);
752 } else { 308 } else {
753 qDebug( "Mail sent." ); 309 qDebug( "Mail sent." );
754 storeMail(data,size,"Sent"); 310 storeMail(data,size,"Sent");
755 } 311 }
756 return result; 312 return result;
757} 313}
758 314
759void SMTPwrapper::sendMail(const Mail&mail,bool later ) 315void SMTPwrapper::sendMail(const Mail&mail,bool later )
760{ 316{
761 mailmime * mimeMail; 317 mailmime * mimeMail;
762 318
763 mimeMail = createMimeMail(mail ); 319 mimeMail = createMimeMail(mail );
764 if ( mimeMail == NULL ) { 320 if ( mimeMail == NULL ) {
765 qDebug( "sendMail: error creating mime mail" ); 321 qDebug( "sendMail: error creating mime mail" );
766 } else { 322 } else {
767 sendProgress = new progressMailSend(); 323 sendProgress = new progressMailSend();
768 sendProgress->show(); 324 sendProgress->show();
769 sendProgress->setMaxMails(1); 325 sendProgress->setMaxMails(1);
770 smtpSend( mimeMail,later); 326 smtpSend( mimeMail,later);
771 qDebug("Clean up done"); 327 qDebug("Clean up done");
772 sendProgress->hide(); 328 sendProgress->hide();
773 delete sendProgress; 329 delete sendProgress;
774 sendProgress = 0; 330 sendProgress = 0;
775 mailmime_free( mimeMail ); 331 mailmime_free( mimeMail );
776 } 332 }
777} 333}
778 334
779int SMTPwrapper::sendQueuedMail(AbstractMail*wrap,RecMail*which) { 335int SMTPwrapper::sendQueuedMail(AbstractMail*wrap,RecMail*which) {
780 size_t curTok = 0; 336 size_t curTok = 0;
781 mailimf_fields *fields = 0; 337 mailimf_fields *fields = 0;
782 mailimf_field*ffrom = 0; 338 mailimf_field*ffrom = 0;
783 clist *rcpts = 0; 339 clist *rcpts = 0;
784 char*from = 0; 340 char*from = 0;
785 int res = 0; 341 int res = 0;
786 342
787 encodedString * data = wrap->fetchRawBody(*which); 343 encodedString * data = wrap->fetchRawBody(*which);
788 if (!data) 344 if (!data)
789 return 0; 345 return 0;
790 int err = mailimf_fields_parse( data->Content(), data->Length(), &curTok, &fields ); 346 int err = mailimf_fields_parse( data->Content(), data->Length(), &curTok, &fields );
791 if (err != MAILIMF_NO_ERROR) { 347 if (err != MAILIMF_NO_ERROR) {
792 delete data; 348 delete data;
793 delete wrap; 349 delete wrap;
794 return 0; 350 return 0;
795 } 351 }
796 352
797 rcpts = createRcptList( fields ); 353 rcpts = createRcptList( fields );
798 ffrom = getField(fields, MAILIMF_FIELD_FROM ); 354 ffrom = getField(fields, MAILIMF_FIELD_FROM );
799 from = getFrom(ffrom); 355 from = getFrom(ffrom);
800 356
801 if (rcpts && from) { 357 if (rcpts && from) {
802 res = smtpSend(from,rcpts,data->Content(),data->Length()); 358 res = smtpSend(from,rcpts,data->Content(),data->Length());
803 } 359 }
804 if (fields) { 360 if (fields) {
805 mailimf_fields_free(fields); 361 mailimf_fields_free(fields);
806 fields = 0; 362 fields = 0;
807 } 363 }
808 if (data) { 364 if (data) {
809 delete data; 365 delete data;
810 } 366 }
811 if (from) { 367 if (from) {
812 free(from); 368 free(from);
813 } 369 }
814 if (rcpts) { 370 if (rcpts) {
815 smtp_address_list_free( rcpts ); 371 smtp_address_list_free( rcpts );
816 } 372 }
817 return res; 373 return res;
818} 374}
819 375
820/* this is a special fun */ 376/* this is a special fun */
821bool SMTPwrapper::flushOutbox() { 377bool SMTPwrapper::flushOutbox() {
822 bool returnValue = true; 378 bool returnValue = true;
823 379
824 qDebug("Sending the queue"); 380 qDebug("Sending the queue");
825 if (!m_SmtpAccount) { 381 if (!m_SmtpAccount) {
826 qDebug("No smtp account given"); 382 qDebug("No smtp account given");
827 return false; 383 return false;
828 } 384 }
829 385
830 bool reset_user_value = false; 386 bool reset_user_value = false;
831 QString localfolders = AbstractMail::defaultLocalfolder(); 387 QString localfolders = AbstractMail::defaultLocalfolder();
832 AbstractMail*wrap = AbstractMail::getWrapper(localfolders); 388 AbstractMail*wrap = AbstractMail::getWrapper(localfolders);
833 if (!wrap) { 389 if (!wrap) {
834 qDebug("memory error"); 390 qDebug("memory error");
835 return false; 391 return false;
836 } 392 }
837 QString oldPw, oldUser; 393 QString oldPw, oldUser;
838 QList<RecMail> mailsToSend; 394 QList<RecMail> mailsToSend;
839 QList<RecMail> mailsToRemove; 395 QList<RecMail> mailsToRemove;
840 QString mbox("Outgoing"); 396 QString mbox("Outgoing");
841 wrap->listMessages(mbox,mailsToSend); 397 wrap->listMessages(mbox,mailsToSend);
842 if (mailsToSend.count()==0) { 398 if (mailsToSend.count()==0) {
843 delete wrap; 399 delete wrap;
844 qDebug("No mails to send"); 400 qDebug("No mails to send");
845 return false; 401 return false;
846 } 402 }
847 403
848 oldPw = m_SmtpAccount->getPassword(); 404 oldPw = m_SmtpAccount->getPassword();
849 oldUser = m_SmtpAccount->getUser(); 405 oldUser = m_SmtpAccount->getUser();
850 if (m_SmtpAccount->getLogin() && (m_SmtpAccount->getUser().isEmpty() || m_SmtpAccount->getPassword().isEmpty()) ) { 406 if (m_SmtpAccount->getLogin() && (m_SmtpAccount->getUser().isEmpty() || m_SmtpAccount->getPassword().isEmpty()) ) {
851 // get'em 407 // get'em
852 QString user,pass; 408 QString user,pass;
853 LoginDialog login( m_SmtpAccount->getUser(), m_SmtpAccount->getPassword(), NULL, 0, true ); 409 LoginDialog login( m_SmtpAccount->getUser(), m_SmtpAccount->getPassword(), NULL, 0, true );
854 login.show(); 410 login.show();
855 if ( QDialog::Accepted == login.exec() ) { 411 if ( QDialog::Accepted == login.exec() ) {
856 // ok 412 // ok
857 user = login.getUser().latin1(); 413 user = login.getUser().latin1();
858 pass = login.getPassword().latin1(); 414 pass = login.getPassword().latin1();
859 reset_user_value = true; 415 reset_user_value = true;
860 m_SmtpAccount->setUser(user); 416 m_SmtpAccount->setUser(user);
861 m_SmtpAccount->setPassword(pass); 417 m_SmtpAccount->setPassword(pass);
862 } else { 418 } else {
863 return true; 419 return true;
864 } 420 }
865 } 421 }
866 422
867 423
868 mailsToSend.setAutoDelete(false); 424 mailsToSend.setAutoDelete(false);
869 sendProgress = new progressMailSend(); 425 sendProgress = new progressMailSend();
870 sendProgress->show(); 426 sendProgress->show();
871 sendProgress->setMaxMails(mailsToSend.count()); 427 sendProgress->setMaxMails(mailsToSend.count());
872 428
873 while (mailsToSend.count()>0) { 429 while (mailsToSend.count()>0) {
874 if (sendQueuedMail(wrap,mailsToSend.at(0))==0) { 430 if (sendQueuedMail(wrap,mailsToSend.at(0))==0) {
875 QMessageBox::critical(0,tr("Error sending mail"), 431 QMessageBox::critical(0,tr("Error sending mail"),
876 tr("Error sending queued mail - breaking")); 432 tr("Error sending queued mail - breaking"));
877 returnValue = false; 433 returnValue = false;
878 break; 434 break;
879 } 435 }
880 mailsToRemove.append(mailsToSend.at(0)); 436 mailsToRemove.append(mailsToSend.at(0));
881 mailsToSend.removeFirst(); 437 mailsToSend.removeFirst();
882 sendProgress->setCurrentMails(mailsToRemove.count()); 438 sendProgress->setCurrentMails(mailsToRemove.count());
883 } 439 }
884 if (reset_user_value) { 440 if (reset_user_value) {
885 m_SmtpAccount->setUser(oldUser); 441 m_SmtpAccount->setUser(oldUser);
886 m_SmtpAccount->setPassword(oldPw); 442 m_SmtpAccount->setPassword(oldPw);
887 } 443 }
888 Config cfg( "mail" ); 444 Config cfg( "mail" );
889 cfg.setGroup( "Status" ); 445 cfg.setGroup( "Status" );
890 m_queuedMail = 0; 446 m_queuedMail = 0;
891 cfg.writeEntry( "outgoing", m_queuedMail ); 447 cfg.writeEntry( "outgoing", m_queuedMail );
892 emit queuedMails( m_queuedMail ); 448 emit queuedMails( m_queuedMail );
893 sendProgress->hide(); 449 sendProgress->hide();
894 delete sendProgress; 450 delete sendProgress;
895 sendProgress = 0; 451 sendProgress = 0;
896 wrap->deleteMails(mbox,mailsToRemove); 452 wrap->deleteMails(mbox,mailsToRemove);
897 mailsToSend.setAutoDelete(true); 453 mailsToSend.setAutoDelete(true);
898 delete wrap; 454 delete wrap;
899 return returnValue; 455 return returnValue;
900} 456}
diff --git a/noncore/net/mail/libmailwrapper/smtpwrapper.h b/noncore/net/mail/libmailwrapper/smtpwrapper.h
index 7f6aac1..1796df7 100644
--- a/noncore/net/mail/libmailwrapper/smtpwrapper.h
+++ b/noncore/net/mail/libmailwrapper/smtpwrapper.h
@@ -1,83 +1,61 @@
1// -*- Mode: C++; -*- 1// -*- Mode: C++; -*-
2#ifndef SMTPwrapper_H 2#ifndef SMTPwrapper_H
3#define SMTPwrapper_H 3#define SMTPwrapper_H
4 4
5#include <qpe/applnk.h> 5#include <qpe/applnk.h>
6 6
7#include <qbitarray.h> 7#include <qbitarray.h>
8#include <qdatetime.h> 8#include <qdatetime.h>
9#include <libetpan/clist.h> 9#include <libetpan/clist.h>
10 10
11#include "settings.h" 11#include "settings.h"
12#include "generatemail.h"
12 13
13class Mail;
14class AbstractMail;
15class RecMail;
16class Attachment;
17struct mailimf_fields;
18struct mailimf_field;
19struct mailimf_mailbox;
20struct mailmime;
21struct mailimf_address_list;
22class progressMailSend;
23struct mailsmtp;
24class SMTPaccount; 14class SMTPaccount;
15class AbstractMail;
25 16
26class SMTPwrapper : public QObject 17class SMTPwrapper : public Generatemail
27{ 18{
28 Q_OBJECT 19 Q_OBJECT
29 20
30public: 21public:
31 SMTPwrapper(SMTPaccount * aSmtp); 22 SMTPwrapper(SMTPaccount * aSmtp);
32 virtual ~SMTPwrapper(); 23 virtual ~SMTPwrapper();
33 void sendMail(const Mail& mail,bool later=false ); 24 void sendMail(const Mail& mail,bool later=false );
34 bool flushOutbox(); 25 bool flushOutbox();
35 26
36 static progressMailSend*sendProgress; 27 static progressMailSend*sendProgress;
37 28
38signals: 29signals:
39 void queuedMails( int ); 30 void queuedMails( int );
40 31
41protected: 32protected:
42 mailsmtp *m_smtp; 33 mailsmtp *m_smtp;
43 SMTPaccount * m_SmtpAccount; 34 SMTPaccount * m_SmtpAccount;
44 35
45 void connect_server(); 36 void connect_server();
46 void disc_server(); 37 void disc_server();
47 int start_smtp_tls(); 38 int start_smtp_tls();
48 39
49 mailimf_mailbox *newMailbox(const QString&name,const QString&mail ); 40
50 mailimf_fields *createImfFields(const Mail &mail );
51 mailmime *createMimeMail(const Mail&mail );
52
53 mailimf_address_list *parseAddresses(const QString&addr );
54 void addFileParts( mailmime *message,const QList<Attachment>&files );
55 mailmime *buildTxtPart(const QString&str );
56 mailmime *buildFilePart(const QString&filename,const QString&mimetype,const QString&content);
57 void smtpSend( mailmime *mail,bool later); 41 void smtpSend( mailmime *mail,bool later);
58 clist *createRcptList( mailimf_fields *fields );
59 42
60 static void storeMail(const char*mail, size_t length, const QString&box); 43 static void storeMail(const char*mail, size_t length, const QString&box);
61 static QString mailsmtpError( int err ); 44 static QString mailsmtpError( int err );
62 static void progress( size_t current, size_t maximum ); 45 static void progress( size_t current, size_t maximum );
63 static void addRcpts( clist *list, mailimf_address_list *addr_list );
64 static char *getFrom( mailmime *mail );
65 static char *getFrom( mailimf_field *ffrom);
66 static mailimf_field *getField( mailimf_fields *fields, int type );
67 46
68 int smtpSend(char*from,clist*rcpts,const char*data,size_t size); 47 int smtpSend(char*from,clist*rcpts,const char*data,size_t size);
69 48
70 void storeMail(mailmime*mail, const QString&box); 49 void storeMail(mailmime*mail, const QString&box);
71 50
72 int sendQueuedMail(AbstractMail*wrap,RecMail*which); 51 int sendQueuedMail(AbstractMail*wrap,RecMail*which);
73 void storeFailedMail(const char*data,unsigned int size, const char*failuremessage); 52 void storeFailedMail(const char*data,unsigned int size, const char*failuremessage);
74 53
75 int m_queuedMail; 54 int m_queuedMail;
76 static const char* USER_AGENT;
77 55
78protected slots: 56protected slots:
79 void emitQCop( int queued ); 57 void emitQCop( int queued );
80 58
81}; 59};
82 60
83#endif 61#endif