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
@@ -4,65 +4,65 @@
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);
@@ -116,65 +116,65 @@ QString Genericwrapper::getencoding(mailmime_mechanism*aEnc)
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:
@@ -212,230 +212,256 @@ void Genericwrapper::traverseBody(RecBody&target,mailmessage*message,mailmime*mi
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
@@ -84,80 +84,80 @@ bool IMAPwrapper::start_tls(bool force_tls)
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));
@@ -409,71 +409,86 @@ RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
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;
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
@@ -6,207 +6,218 @@ RecMail::RecMail()
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{
@@ -308,50 +319,50 @@ void encodedString::clean()
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,558 +1,114 @@
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) {
@@ -600,128 +156,128 @@ int 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 );
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