author | alwin <alwin> | 2004-03-08 21:43:14 (UTC) |
---|---|---|
committer | alwin <alwin> | 2004-03-08 21:43:14 (UTC) |
commit | 25434cbbcd2d2473c9cd3d486cec7a96a6a6323e (patch) (unidiff) | |
tree | 31cfa6ceaebe0e2e1e0094e4905d05509e778364 /noncore | |
parent | f3f2b2b3389d62af0f1a3aabac87f6c3cf147379 (diff) | |
download | opie-25434cbbcd2d2473c9cd3d486cec7a96a6a6323e.zip opie-25434cbbcd2d2473c9cd3d486cec7a96a6a6323e.tar.gz opie-25434cbbcd2d2473c9cd3d486cec7a96a6a6323e.tar.bz2 |
some required code restructuring in preparation of new features
-rw-r--r-- | noncore/net/mail/libmailwrapper/generatemail.cpp | 454 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/generatemail.h | 44 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/genericwrapper.cpp | 52 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/genericwrapper.h | 4 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/imapwrapper.cpp | 49 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/libmailwrapper.pro | 16 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/mailtypes.cpp | 19 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/mailtypes.h | 25 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/smtpwrapper.cpp | 464 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/smtpwrapper.h | 32 |
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 | |||
8 | const char* Generatemail::USER_AGENT="OpieMail v0.5"; | ||
9 | |||
10 | Generatemail::Generatemail() | ||
11 | { | ||
12 | } | ||
13 | |||
14 | Generatemail::~Generatemail() | ||
15 | { | ||
16 | } | ||
17 | |||
18 | void 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 | |||
38 | char *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 | |||
53 | char *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 | |||
60 | mailimf_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 | |||
76 | mailimf_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 | |||
127 | mailmime *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 | |||
205 | void 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 | |||
229 | mailmime *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 | |||
263 | err_free_txtPart: | ||
264 | mailmime_free( txtPart ); | ||
265 | err_free_fields: | ||
266 | mailmime_fields_free( fields ); | ||
267 | err_free_content: | ||
268 | mailmime_content_free( content ); | ||
269 | err_free_param: | ||
270 | mailmime_parameter_free( param ); | ||
271 | err_free: | ||
272 | qDebug( "buildTxtPart - error" ); | ||
273 | |||
274 | return NULL; // Error :( | ||
275 | } | ||
276 | |||
277 | mailimf_mailbox *Generatemail::newMailbox(const QString&name, const QString&mail ) { | ||
278 | return mailimf_mailbox_new( strdup( name.latin1() ), | ||
279 | strdup( mail.latin1() ) ); | ||
280 | } | ||
281 | |||
282 | mailimf_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 | |||
358 | err_free_xmailer: | ||
359 | if (xmailer) | ||
360 | mailimf_field_free( xmailer ); | ||
361 | err_free_fields: | ||
362 | if (fields) | ||
363 | mailimf_fields_free( fields ); | ||
364 | err_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 ); | ||
373 | err_free_from: | ||
374 | if (from) | ||
375 | mailimf_mailbox_list_free( from ); | ||
376 | err_free_fromBox: | ||
377 | mailimf_mailbox_free( fromBox ); | ||
378 | err_free_sender: | ||
379 | if (sender) | ||
380 | mailimf_mailbox_free( sender ); | ||
381 | err_free: | ||
382 | if (subject) | ||
383 | free( subject ); | ||
384 | qDebug( "createImfFields - error" ); | ||
385 | |||
386 | return NULL; // Error :( | ||
387 | } | ||
388 | |||
389 | mailmime *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 | |||
417 | err_free_txtPart: | ||
418 | mailmime_free( txtPart ); | ||
419 | err_free_message: | ||
420 | mailmime_free( message ); | ||
421 | err_free_fields: | ||
422 | mailimf_fields_free( fields ); | ||
423 | err_free: | ||
424 | qDebug( "createMimeMail: error" ); | ||
425 | |||
426 | return NULL; // Error :( | ||
427 | } | ||
428 | |||
429 | clist *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 | |||
9 | class Mail; | ||
10 | class RecMail; | ||
11 | class Attachment; | ||
12 | struct mailimf_fields; | ||
13 | struct mailimf_field; | ||
14 | struct mailimf_mailbox; | ||
15 | struct mailmime; | ||
16 | struct mailimf_address_list; | ||
17 | class progressMailSend; | ||
18 | struct mailsmtp; | ||
19 | |||
20 | class Generatemail : public QObject | ||
21 | { | ||
22 | Q_OBJECT | ||
23 | public: | ||
24 | Generatemail(); | ||
25 | virtual ~Generatemail(); | ||
26 | |||
27 | protected: | ||
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 | |||
@@ -34,5 +34,5 @@ void Genericwrapper::fillSingleBody(RecPart&target,mailmessage*,mailmime*mime) | |||
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; |
@@ -146,5 +146,5 @@ void Genericwrapper::traverseBody(RecBody&target,mailmessage*message,mailmime*mi | |||
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: |
@@ -242,8 +242,8 @@ QString 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 | } |
@@ -257,5 +257,5 @@ QString Genericwrapper::parseAddressList( mailimf_address_list *list ) | |||
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( "," ); |
@@ -276,5 +276,5 @@ QString Genericwrapper::parseAddressList( mailimf_address_list *list ) | |||
276 | } | 276 | } |
277 | } | 277 | } |
278 | 278 | ||
279 | return result; | 279 | return result; |
280 | } | 280 | } |
@@ -292,5 +292,5 @@ QString Genericwrapper::parseGroup( mailimf_group *group ) | |||
292 | 292 | ||
293 | result.append( ";" ); | 293 | result.append( ";" ); |
294 | 294 | ||
295 | return result; | 295 | return result; |
296 | } | 296 | } |
@@ -308,5 +308,5 @@ QString Genericwrapper::parseMailbox( mailimf_mailbox *box ) | |||
308 | result.append( ">" ); | 308 | result.append( ">" ); |
309 | } | 309 | } |
310 | 310 | ||
311 | return result; | 311 | return result; |
312 | } | 312 | } |
@@ -325,8 +325,8 @@ QString Genericwrapper::parseMailboxList( mailimf_mailbox_list *list ) | |||
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 | } |
@@ -368,4 +368,24 @@ void Genericwrapper::cleanMimeCache() | |||
368 | } | 368 | } |
369 | 369 | ||
370 | QStringList 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 | |||
370 | void Genericwrapper::parseList(QList<RecMail> &target,mailsession*session,const QString&mailbox,bool mbox_as_to) | 390 | void Genericwrapper::parseList(QList<RecMail> &target,mailsession*session,const QString&mailbox,bool mbox_as_to) |
371 | { | 391 | { |
@@ -385,5 +405,6 @@ void Genericwrapper::parseList(QList<RecMail> &target,mailsession*session,const | |||
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) { |
@@ -427,6 +448,7 @@ void Genericwrapper::parseList(QList<RecMail> &target,mailsession*session,const | |||
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)) { |
@@ -434,4 +456,8 @@ void Genericwrapper::parseList(QList<RecMail> &target,mailsession*session,const | |||
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 | } |
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 | |||
@@ -22,4 +22,5 @@ struct mailsession; | |||
22 | struct mailstorage; | 22 | struct mailstorage; |
23 | struct mailfolder; | 23 | struct mailfolder; |
24 | struct mailimf_in_reply_to; | ||
24 | 25 | ||
25 | /* this class hold just the funs shared between | 26 | /* this class hold just the funs shared between |
@@ -49,5 +50,5 @@ protected: | |||
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); |
@@ -55,4 +56,5 @@ protected: | |||
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; |
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 | |||
@@ -114,20 +114,20 @@ void IMAPwrapper::login() | |||
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 ); |
@@ -439,4 +439,5 @@ RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) | |||
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); |
@@ -445,5 +446,19 @@ RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) | |||
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 |
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,4 +1,4 @@ | |||
1 | TEMPLATE = lib | 1 | TEMPLATE = lib |
2 | CONFIG += qt warn_on debug | 2 | CONFIG += qt warn_on debug |
3 | 3 | ||
4 | HEADERS = mailwrapper.h \ | 4 | HEADERS = mailwrapper.h \ |
@@ -15,6 +15,7 @@ HEADERS = mailwrapper.h \ | |||
15 | statusmail.h \ | 15 | statusmail.h \ |
16 | mhwrapper.h \ | 16 | mhwrapper.h \ |
17 | nntpwrapper.h | 17 | nntpwrapper.h \ |
18 | 18 | generatemail.h | |
19 | |||
19 | SOURCES = imapwrapper.cpp \ | 20 | SOURCES = imapwrapper.cpp \ |
20 | mailwrapper.cpp \ | 21 | mailwrapper.cpp \ |
@@ -30,9 +31,10 @@ SOURCES = imapwrapper.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 \ | 36 | INTERFACES = logindialogui.ui \ |
35 | sendmailprogressui.ui | 37 | sendmailprogressui.ui |
36 | 38 | ||
37 | 39 | ||
38 | INCLUDEPATH += $(OPIEDIR)/include | 40 | INCLUDEPATH += $(OPIEDIR)/include |
@@ -42,5 +44,5 @@ contains( 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 | ||
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 | |||
@@ -36,4 +36,5 @@ void RecMail::copy_old(const RecMail&old) | |||
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 | ||
@@ -44,4 +45,5 @@ void RecMail::init() | |||
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 | } |
@@ -97,4 +99,13 @@ const QStringList& RecMail::Inreply()const | |||
97 | } | 99 | } |
98 | 100 | ||
101 | void RecMail::setReferences(const QStringList&list) | ||
102 | { | ||
103 | references = list; | ||
104 | } | ||
105 | |||
106 | const QStringList& RecMail::References()const | ||
107 | { | ||
108 | return references; | ||
109 | } | ||
99 | 110 | ||
100 | RecPart::RecPart() | 111 | RecPart::RecPart() |
@@ -113,5 +124,5 @@ void RecPart::setSize(unsigned int size) | |||
113 | m_size = size; | 124 | m_size = size; |
114 | } | 125 | } |
115 | 126 | ||
116 | const unsigned int RecPart::Size()const | 127 | const unsigned int RecPart::Size()const |
117 | { | 128 | { |
@@ -123,5 +134,5 @@ void RecPart::setLines(unsigned int lines) | |||
123 | m_lines = lines; | 134 | m_lines = lines; |
124 | } | 135 | } |
125 | 136 | ||
126 | const unsigned int RecPart::Lines()const | 137 | const unsigned int RecPart::Lines()const |
127 | { | 138 | { |
@@ -178,5 +189,5 @@ void RecPart::setDescription(const QString&desc) | |||
178 | m_description = desc; | 189 | m_description = desc; |
179 | } | 190 | } |
180 | 191 | ||
181 | void RecPart::setParameters(const part_plist_t&list) | 192 | void RecPart::setParameters(const part_plist_t&list) |
182 | { | 193 | { |
@@ -338,5 +349,5 @@ void encodedString::setContent(const char*nContent,int nSize) | |||
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 | } |
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 | |||
@@ -21,6 +21,6 @@ class AbstractMail; | |||
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?) |
@@ -62,7 +62,10 @@ public: | |||
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(); |
@@ -72,5 +75,5 @@ protected: | |||
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(); |
@@ -92,5 +95,5 @@ public: | |||
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); |
@@ -108,5 +111,5 @@ public: | |||
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; |
@@ -132,5 +135,5 @@ public: | |||
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; |
@@ -143,5 +146,5 @@ public: | |||
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 | */ |
@@ -159,10 +162,10 @@ public: | |||
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! |
@@ -179,5 +182,5 @@ protected: | |||
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); |
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,15 +1,2 @@ | |||
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" |
@@ -19,10 +6,16 @@ | |||
19 | #include "sendmailprogress.h" | 6 | #include "sendmailprogress.h" |
20 | 7 | ||
21 | const char* SMTPwrapper::USER_AGENT="OpieMail v0.4"; | 8 | #include <qt.h> |
9 | |||
10 | #include <qpe/config.h> | ||
11 | #include <qpe/qcopenvelope_qws.h> | ||
12 | |||
13 | #include <libetpan/libetpan.h> | ||
14 | |||
22 | 15 | ||
23 | progressMailSend*SMTPwrapper::sendProgress = 0; | 16 | progressMailSend*SMTPwrapper::sendProgress = 0; |
24 | 17 | ||
25 | SMTPwrapper::SMTPwrapper(SMTPaccount * aSmtp ) | 18 | SMTPwrapper::SMTPwrapper(SMTPaccount * aSmtp ) |
26 | : QObject() | 19 | : Generatemail() |
27 | { | 20 | { |
28 | m_SmtpAccount = aSmtp; | 21 | m_SmtpAccount = aSmtp; |
@@ -88,441 +81,4 @@ QString SMTPwrapper::mailsmtpError( int errnum ) { | |||
88 | } | 81 | } |
89 | 82 | ||
90 | mailimf_mailbox *SMTPwrapper::newMailbox(const QString&name, const QString&mail ) { | ||
91 | return mailimf_mailbox_new( strdup( name.latin1() ), | ||
92 | strdup( mail.latin1() ) ); | ||
93 | } | ||
94 | |||
95 | mailimf_address_list *SMTPwrapper::parseAddresses(const QString&addr ) { | ||
96 | mailimf_address_list *addresses; | ||
97 | |||
98 | if ( addr.isEmpty() ) | ||
99 | return NULL; | ||
100 | |||
101 | addresses = mailimf_address_list_new_empty(); | ||
102 | |||
103 | bool literal_open = false; | ||
104 | unsigned int startpos = 0; | ||
105 | QStringList list; | ||
106 | QString s; | ||
107 | unsigned int i = 0; | ||
108 | for (; i < addr.length();++i) { | ||
109 | switch (addr[i]) { | ||
110 | case '\"': | ||
111 | literal_open = !literal_open; | ||
112 | break; | ||
113 | case ',': | ||
114 | if (!literal_open) { | ||
115 | s = addr.mid(startpos,i-startpos); | ||
116 | if (!s.isEmpty()) { | ||
117 | list.append(s); | ||
118 | qDebug("Appended %s",s.latin1()); | ||
119 | } | ||
120 | // !!!! this is a MUST BE! | ||
121 | startpos = ++i; | ||
122 | } | ||
123 | break; | ||
124 | default: | ||
125 | break; | ||
126 | } | ||
127 | } | ||
128 | s = addr.mid(startpos,i-startpos); | ||
129 | if (!s.isEmpty()) { | ||
130 | list.append(s); | ||
131 | qDebug("Appended %s",s.latin1()); | ||
132 | } | ||
133 | QStringList::Iterator it; | ||
134 | for ( it = list.begin(); it != list.end(); it++ ) { | ||
135 | int err = mailimf_address_list_add_parse( addresses, (char*)(*it).latin1() ); | ||
136 | if ( err != MAILIMF_NO_ERROR ) { | ||
137 | qDebug( "Error parsing" ); | ||
138 | qDebug( *it ); | ||
139 | } else { | ||
140 | qDebug( "Parse success! %s",(*it).latin1()); | ||
141 | } | ||
142 | } | ||
143 | return addresses; | ||
144 | } | ||
145 | |||
146 | mailimf_fields *SMTPwrapper::createImfFields(const Mail&mail ) { | ||
147 | mailimf_fields *fields; | ||
148 | mailimf_field *xmailer; | ||
149 | mailimf_mailbox *sender=0,*fromBox=0; | ||
150 | mailimf_mailbox_list *from=0; | ||
151 | mailimf_address_list *to=0, *cc=0, *bcc=0, *reply=0; | ||
152 | clist*in_reply_to = 0; | ||
153 | char *subject = strdup( mail.getSubject().latin1() ); | ||
154 | int err; | ||
155 | |||
156 | sender = newMailbox( mail.getName(), mail.getMail() ); | ||
157 | if ( sender == NULL ) | ||
158 | goto err_free; | ||
159 | |||
160 | fromBox = newMailbox( mail.getName(), mail.getMail() ); | ||
161 | if ( fromBox == NULL ) | ||
162 | goto err_free_sender; | ||
163 | |||
164 | from = mailimf_mailbox_list_new_empty(); | ||
165 | if ( from == NULL ) | ||
166 | goto err_free_fromBox; | ||
167 | |||
168 | err = mailimf_mailbox_list_add( from, fromBox ); | ||
169 | if ( err != MAILIMF_NO_ERROR ) | ||
170 | goto err_free_from; | ||
171 | |||
172 | to = parseAddresses( mail.getTo() ); | ||
173 | if ( to == NULL ) | ||
174 | goto err_free_from; | ||
175 | |||
176 | cc = parseAddresses( mail.getCC() ); | ||
177 | bcc = parseAddresses( mail.getBCC() ); | ||
178 | reply = parseAddresses( mail.getReply() ); | ||
179 | |||
180 | if (mail.Inreply().count()>0) { | ||
181 | in_reply_to = clist_new(); | ||
182 | char*c_reply; | ||
183 | unsigned int nsize = 0; | ||
184 | for (QStringList::ConstIterator it=mail.Inreply().begin(); | ||
185 | it != mail.Inreply().end();++it) { | ||
186 | /* yes! must be malloc! */ | ||
187 | if ((*it).isEmpty()) | ||
188 | continue; | ||
189 | QString h((*it)); | ||
190 | while (h.length()>0 && h[0]=='<') { | ||
191 | h.remove(0,1); | ||
192 | } | ||
193 | while (h.length()>0 && h[h.length()-1]=='>') { | ||
194 | h.remove(h.length()-1,1); | ||
195 | } | ||
196 | if (h.isEmpty()) continue; | ||
197 | nsize = strlen(h.latin1()); | ||
198 | c_reply = (char*)malloc( (nsize+1)*sizeof(char)); | ||
199 | memset(c_reply,0,nsize+1); | ||
200 | memcpy(c_reply,h.latin1(),nsize); | ||
201 | clist_append(in_reply_to,c_reply); | ||
202 | qDebug("In reply to: %s",c_reply); | ||
203 | } | ||
204 | } | ||
205 | |||
206 | fields = mailimf_fields_new_with_data( from, sender, reply, to, cc, bcc, | ||
207 | in_reply_to, NULL, subject ); | ||
208 | if ( fields == NULL ) | ||
209 | goto err_free_reply; | ||
210 | |||
211 | xmailer = mailimf_field_new_custom( strdup( "User-Agent" ), | ||
212 | strdup( USER_AGENT ) ); | ||
213 | if ( xmailer == NULL ) | ||
214 | goto err_free_fields; | ||
215 | |||
216 | err = mailimf_fields_add( fields, xmailer ); | ||
217 | if ( err != MAILIMF_NO_ERROR ) | ||
218 | goto err_free_xmailer; | ||
219 | |||
220 | return fields; // Success :) | ||
221 | |||
222 | err_free_xmailer: | ||
223 | if (xmailer) | ||
224 | mailimf_field_free( xmailer ); | ||
225 | err_free_fields: | ||
226 | if (fields) | ||
227 | mailimf_fields_free( fields ); | ||
228 | err_free_reply: | ||
229 | if (reply) | ||
230 | mailimf_address_list_free( reply ); | ||
231 | if (bcc) | ||
232 | mailimf_address_list_free( bcc ); | ||
233 | if (cc) | ||
234 | mailimf_address_list_free( cc ); | ||
235 | if (to) | ||
236 | mailimf_address_list_free( to ); | ||
237 | err_free_from: | ||
238 | if (from) | ||
239 | mailimf_mailbox_list_free( from ); | ||
240 | err_free_fromBox: | ||
241 | mailimf_mailbox_free( fromBox ); | ||
242 | err_free_sender: | ||
243 | if (sender) | ||
244 | mailimf_mailbox_free( sender ); | ||
245 | err_free: | ||
246 | if (subject) | ||
247 | free( subject ); | ||
248 | qDebug( "createImfFields - error" ); | ||
249 | |||
250 | return NULL; // Error :( | ||
251 | } | ||
252 | |||
253 | mailmime *SMTPwrapper::buildTxtPart(const QString&str ) { | ||
254 | mailmime *txtPart; | ||
255 | mailmime_fields *fields; | ||
256 | mailmime_content *content; | ||
257 | mailmime_parameter *param; | ||
258 | int err; | ||
259 | |||
260 | param = mailmime_parameter_new( strdup( "charset" ), | ||
261 | strdup( "iso-8859-1" ) ); | ||
262 | if ( param == NULL ) | ||
263 | goto err_free; | ||
264 | |||
265 | content = mailmime_content_new_with_str( "text/plain" ); | ||
266 | if ( content == NULL ) | ||
267 | goto err_free_param; | ||
268 | |||
269 | err = clist_append( content->ct_parameters, param ); | ||
270 | if ( err != MAILIMF_NO_ERROR ) | ||
271 | goto err_free_content; | ||
272 | |||
273 | fields = mailmime_fields_new_encoding(MAILMIME_MECHANISM_8BIT); | ||
274 | if ( fields == NULL ) | ||
275 | goto err_free_content; | ||
276 | |||
277 | txtPart = mailmime_new_empty( content, fields ); | ||
278 | if ( txtPart == NULL ) | ||
279 | goto err_free_fields; | ||
280 | |||
281 | err = mailmime_set_body_text( txtPart, (char*)str.data(), str.length() ); | ||
282 | if ( err != MAILIMF_NO_ERROR ) | ||
283 | goto err_free_txtPart; | ||
284 | |||
285 | return txtPart; // Success :) | ||
286 | |||
287 | err_free_txtPart: | ||
288 | mailmime_free( txtPart ); | ||
289 | err_free_fields: | ||
290 | mailmime_fields_free( fields ); | ||
291 | err_free_content: | ||
292 | mailmime_content_free( content ); | ||
293 | err_free_param: | ||
294 | mailmime_parameter_free( param ); | ||
295 | err_free: | ||
296 | qDebug( "buildTxtPart - error" ); | ||
297 | |||
298 | return NULL; // Error :( | ||
299 | } | ||
300 | |||
301 | mailmime *SMTPwrapper::buildFilePart(const QString&filename,const QString&mimetype,const QString&TextContent ) { | ||
302 | mailmime * filePart = 0; | ||
303 | mailmime_fields * fields = 0; | ||
304 | mailmime_content * content = 0; | ||
305 | mailmime_parameter * param = 0; | ||
306 | char*name = 0; | ||
307 | char*file = 0; | ||
308 | int err; | ||
309 | |||
310 | int pos = filename.findRev( '/' ); | ||
311 | |||
312 | if (filename.length()>0) { | ||
313 | QString tmp = filename.right( filename.length() - ( pos + 1 ) ); | ||
314 | name = strdup( tmp.latin1() ); // just filename | ||
315 | file = strdup( filename.latin1() ); // full name with path | ||
316 | } | ||
317 | |||
318 | int disptype = MAILMIME_DISPOSITION_TYPE_ATTACHMENT; | ||
319 | int mechanism = MAILMIME_MECHANISM_BASE64; | ||
320 | |||
321 | if ( mimetype.startsWith( "text/" ) ) { | ||
322 | param = mailmime_parameter_new( strdup( "charset" ), | ||
323 | strdup( "iso-8859-1" ) ); | ||
324 | mechanism = MAILMIME_MECHANISM_QUOTED_PRINTABLE; | ||
325 | } | ||
326 | |||
327 | fields = mailmime_fields_new_filename( | ||
328 | disptype, name, | ||
329 | mechanism ); | ||
330 | content = mailmime_content_new_with_str( (char*)mimetype.latin1() ); | ||
331 | if (content!=0 && fields != 0) { | ||
332 | if (param) { | ||
333 | clist_append(content->ct_parameters,param); | ||
334 | param = 0; | ||
335 | } | ||
336 | if (filename.length()>0) { | ||
337 | QFileInfo f(filename); | ||
338 | param = mailmime_parameter_new(strdup("name"),strdup(f.fileName().latin1())); | ||
339 | clist_append(content->ct_parameters,param); | ||
340 | param = 0; | ||
341 | } | ||
342 | filePart = mailmime_new_empty( content, fields ); | ||
343 | } | ||
344 | if (filePart) { | ||
345 | if (filename.length()>0) { | ||
346 | err = mailmime_set_body_file( filePart, file ); | ||
347 | } else { | ||
348 | err = mailmime_set_body_text(filePart,strdup(TextContent.data()),TextContent.length()); | ||
349 | } | ||
350 | if (err != MAILIMF_NO_ERROR) { | ||
351 | qDebug("Error setting body with file %s",file); | ||
352 | mailmime_free( filePart ); | ||
353 | filePart = 0; | ||
354 | } | ||
355 | } | ||
356 | |||
357 | if (!filePart) { | ||
358 | if ( param != NULL ) { | ||
359 | mailmime_parameter_free( param ); | ||
360 | } | ||
361 | if (content) { | ||
362 | mailmime_content_free( content ); | ||
363 | } | ||
364 | if (fields) { | ||
365 | mailmime_fields_free( fields ); | ||
366 | } else { | ||
367 | if (name) { | ||
368 | free( name ); | ||
369 | } | ||
370 | if (file) { | ||
371 | free( file ); | ||
372 | } | ||
373 | } | ||
374 | } | ||
375 | return filePart; // Success :) | ||
376 | |||
377 | } | ||
378 | |||
379 | void SMTPwrapper::addFileParts( mailmime *message,const QList<Attachment>&files ) { | ||
380 | const Attachment *it; | ||
381 | unsigned int count = files.count(); | ||
382 | qDebug("List contains %i values",count); | ||
383 | for ( unsigned int i = 0; i < count; ++i ) { | ||
384 | qDebug( "Adding file" ); | ||
385 | mailmime *filePart; | ||
386 | int err; | ||
387 | it = ((QList<Attachment>)files).at(i); | ||
388 | |||
389 | filePart = buildFilePart( it->getFileName(), it->getMimeType(),"" ); | ||
390 | if ( filePart == NULL ) { | ||
391 | qDebug( "addFileParts: error adding file:" ); | ||
392 | qDebug( it->getFileName() ); | ||
393 | continue; | ||
394 | } | ||
395 | err = mailmime_smart_add_part( message, filePart ); | ||
396 | if ( err != MAILIMF_NO_ERROR ) { | ||
397 | mailmime_free( filePart ); | ||
398 | qDebug("error smart add"); | ||
399 | } | ||
400 | } | ||
401 | } | ||
402 | |||
403 | mailmime *SMTPwrapper::createMimeMail(const Mail &mail ) { | ||
404 | mailmime *message, *txtPart; | ||
405 | mailimf_fields *fields; | ||
406 | int err; | ||
407 | |||
408 | fields = createImfFields( mail ); | ||
409 | if ( fields == NULL ) | ||
410 | goto err_free; | ||
411 | |||
412 | message = mailmime_new_message_data( NULL ); | ||
413 | if ( message == NULL ) | ||
414 | goto err_free_fields; | ||
415 | |||
416 | mailmime_set_imf_fields( message, fields ); | ||
417 | |||
418 | txtPart = buildTxtPart( mail.getMessage() ); | ||
419 | |||
420 | if ( txtPart == NULL ) | ||
421 | goto err_free_message; | ||
422 | |||
423 | err = mailmime_smart_add_part( message, txtPart ); | ||
424 | if ( err != MAILIMF_NO_ERROR ) | ||
425 | goto err_free_txtPart; | ||
426 | |||
427 | addFileParts( message, mail.getAttachments() ); | ||
428 | |||
429 | return message; // Success :) | ||
430 | |||
431 | err_free_txtPart: | ||
432 | mailmime_free( txtPart ); | ||
433 | err_free_message: | ||
434 | mailmime_free( message ); | ||
435 | err_free_fields: | ||
436 | mailimf_fields_free( fields ); | ||
437 | err_free: | ||
438 | qDebug( "createMimeMail: error" ); | ||
439 | |||
440 | return NULL; // Error :( | ||
441 | } | ||
442 | |||
443 | mailimf_field *SMTPwrapper::getField( mailimf_fields *fields, int type ) { | ||
444 | mailimf_field *field; | ||
445 | clistiter *it; | ||
446 | |||
447 | it = clist_begin( fields->fld_list ); | ||
448 | while ( it ) { | ||
449 | field = (mailimf_field *) it->data; | ||
450 | if ( field->fld_type == type ) { | ||
451 | return field; | ||
452 | } | ||
453 | it = it->next; | ||
454 | } | ||
455 | |||
456 | return NULL; | ||
457 | } | ||
458 | |||
459 | void SMTPwrapper::addRcpts( clist *list, mailimf_address_list *addr_list ) { | ||
460 | clistiter *it, *it2; | ||
461 | |||
462 | for ( it = clist_begin( addr_list->ad_list ); it; it = it->next ) { | ||
463 | mailimf_address *addr; | ||
464 | addr = (mailimf_address *) it->data; | ||
465 | |||
466 | if ( addr->ad_type == MAILIMF_ADDRESS_MAILBOX ) { | ||
467 | esmtp_address_list_add( list, addr->ad_data.ad_mailbox->mb_addr_spec, 0, NULL ); | ||
468 | } else if ( addr->ad_type == MAILIMF_ADDRESS_GROUP ) { | ||
469 | clist *l = addr->ad_data.ad_group->grp_mb_list->mb_list; | ||
470 | for ( it2 = clist_begin( l ); it2; it2 = it2->next ) { | ||
471 | mailimf_mailbox *mbox; | ||
472 | mbox = (mailimf_mailbox *) it2->data; | ||
473 | esmtp_address_list_add( list, mbox->mb_addr_spec, 0, NULL ); | ||
474 | } | ||
475 | } | ||
476 | } | ||
477 | } | ||
478 | |||
479 | clist *SMTPwrapper::createRcptList( mailimf_fields *fields ) { | ||
480 | clist *rcptList; | ||
481 | mailimf_field *field; | ||
482 | |||
483 | rcptList = esmtp_address_list_new(); | ||
484 | |||
485 | field = getField( fields, MAILIMF_FIELD_TO ); | ||
486 | if ( field && (field->fld_type == MAILIMF_FIELD_TO) | ||
487 | && field->fld_data.fld_to->to_addr_list ) { | ||
488 | addRcpts( rcptList, field->fld_data.fld_to->to_addr_list ); | ||
489 | } | ||
490 | |||
491 | field = getField( fields, MAILIMF_FIELD_CC ); | ||
492 | if ( field && (field->fld_type == MAILIMF_FIELD_CC) | ||
493 | && field->fld_data.fld_cc->cc_addr_list ) { | ||
494 | addRcpts( rcptList, field->fld_data.fld_cc->cc_addr_list ); | ||
495 | } | ||
496 | |||
497 | field = getField( fields, MAILIMF_FIELD_BCC ); | ||
498 | if ( field && (field->fld_type == MAILIMF_FIELD_BCC) | ||
499 | && field->fld_data.fld_bcc->bcc_addr_list ) { | ||
500 | addRcpts( rcptList, field->fld_data.fld_bcc->bcc_addr_list ); | ||
501 | } | ||
502 | |||
503 | return rcptList; | ||
504 | } | ||
505 | |||
506 | char *SMTPwrapper::getFrom( mailimf_field *ffrom) { | ||
507 | char *from = NULL; | ||
508 | if ( ffrom && (ffrom->fld_type == MAILIMF_FIELD_FROM) | ||
509 | && ffrom->fld_data.fld_from->frm_mb_list && ffrom->fld_data.fld_from->frm_mb_list->mb_list ) { | ||
510 | clist *cl = ffrom->fld_data.fld_from->frm_mb_list->mb_list; | ||
511 | clistiter *it; | ||
512 | for ( it = clist_begin( cl ); it; it = it->next ) { | ||
513 | mailimf_mailbox *mb = (mailimf_mailbox *) it->data; | ||
514 | from = strdup( mb->mb_addr_spec ); | ||
515 | } | ||
516 | } | ||
517 | |||
518 | return from; | ||
519 | } | ||
520 | |||
521 | char *SMTPwrapper::getFrom( mailmime *mail ) { | ||
522 | /* no need to delete - its just a pointer to structure content */ | ||
523 | mailimf_field *ffrom = 0; | ||
524 | ffrom = getField( mail->mm_data.mm_message.mm_fields, MAILIMF_FIELD_FROM ); | ||
525 | return getFrom(ffrom); | ||
526 | } | ||
527 | 83 | ||
528 | void SMTPwrapper::progress( size_t current, size_t maximum ) { | 84 | void SMTPwrapper::progress( size_t current, size_t maximum ) { |
@@ -630,5 +186,5 @@ void SMTPwrapper::connect_server() | |||
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; |
@@ -693,5 +249,5 @@ void SMTPwrapper::connect_server() | |||
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(); |
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 | |||
@@ -10,19 +10,10 @@ | |||
10 | 10 | ||
11 | #include "settings.h" | 11 | #include "settings.h" |
12 | #include "generatemail.h" | ||
12 | 13 | ||
13 | class Mail; | ||
14 | class AbstractMail; | ||
15 | class RecMail; | ||
16 | class Attachment; | ||
17 | struct mailimf_fields; | ||
18 | struct mailimf_field; | ||
19 | struct mailimf_mailbox; | ||
20 | struct mailmime; | ||
21 | struct mailimf_address_list; | ||
22 | class progressMailSend; | ||
23 | struct mailsmtp; | ||
24 | class SMTPaccount; | 14 | class SMTPaccount; |
15 | class AbstractMail; | ||
25 | 16 | ||
26 | class SMTPwrapper : public QObject | 17 | class SMTPwrapper : public Generatemail |
27 | { | 18 | { |
28 | Q_OBJECT | 19 | Q_OBJECT |
@@ -46,23 +37,11 @@ protected: | |||
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); |
@@ -74,5 +53,4 @@ protected: | |||
74 | 53 | ||
75 | int m_queuedMail; | 54 | int m_queuedMail; |
76 | static const char* USER_AGENT; | ||
77 | 55 | ||
78 | protected slots: | 56 | protected slots: |