author | alwin <alwin> | 2004-03-12 11:22:24 (UTC) |
---|---|---|
committer | alwin <alwin> | 2004-03-12 11:22:24 (UTC) |
commit | a1ddbd219fcee196172f3fd684afac467e5f2469 (patch) (unidiff) | |
tree | 7f9206c519ceeff108a24e526bcad978977fa7a4 | |
parent | c71234bda29bd83de34ce04c766f2be641ed86be (diff) | |
download | opie-a1ddbd219fcee196172f3fd684afac467e5f2469.zip opie-a1ddbd219fcee196172f3fd684afac467e5f2469.tar.gz opie-a1ddbd219fcee196172f3fd684afac467e5f2469.tar.bz2 |
start usage of smart-pointers
-rw-r--r-- | noncore/net/mail/libmailwrapper/generatemail.cpp | 30 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/generatemail.h | 6 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/mailwrapper.cpp | 4 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/mailwrapper.h | 4 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/smtpwrapper.cpp | 2 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/smtpwrapper.h | 4 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/storemail.cpp | 2 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/storemail.h | 2 |
8 files changed, 31 insertions, 23 deletions
diff --git a/noncore/net/mail/libmailwrapper/generatemail.cpp b/noncore/net/mail/libmailwrapper/generatemail.cpp index 48fa02e..4f7ec0c 100644 --- a/noncore/net/mail/libmailwrapper/generatemail.cpp +++ b/noncore/net/mail/libmailwrapper/generatemail.cpp | |||
@@ -1,104 +1,104 @@ | |||
1 | #include "generatemail.h" | 1 | #include "generatemail.h" |
2 | #include "mailwrapper.h" | 2 | #include "mailwrapper.h" |
3 | 3 | ||
4 | #include <libetpan/libetpan.h> | 4 | #include <libetpan/libetpan.h> |
5 | 5 | ||
6 | #include <qt.h> | 6 | #include <qt.h> |
7 | 7 | ||
8 | const char* Generatemail::USER_AGENT="OpieMail v0.5"; | 8 | const char* Generatemail::USER_AGENT="OpieMail v0.6"; |
9 | 9 | ||
10 | Generatemail::Generatemail() | 10 | Generatemail::Generatemail() |
11 | { | 11 | { |
12 | } | 12 | } |
13 | 13 | ||
14 | Generatemail::~Generatemail() | 14 | Generatemail::~Generatemail() |
15 | { | 15 | { |
16 | } | 16 | } |
17 | 17 | ||
18 | void Generatemail::addRcpts( clist *list, mailimf_address_list *addr_list ) { | 18 | void Generatemail::addRcpts( clist *list, mailimf_address_list *addr_list ) { |
19 | clistiter *it, *it2; | 19 | clistiter *it, *it2; |
20 | 20 | ||
21 | for ( it = clist_begin( addr_list->ad_list ); it; it = it->next ) { | 21 | for ( it = clist_begin( addr_list->ad_list ); it; it = it->next ) { |
22 | mailimf_address *addr; | 22 | mailimf_address *addr; |
23 | addr = (mailimf_address *) it->data; | 23 | addr = (mailimf_address *) it->data; |
24 | 24 | ||
25 | if ( addr->ad_type == MAILIMF_ADDRESS_MAILBOX ) { | 25 | if ( addr->ad_type == MAILIMF_ADDRESS_MAILBOX ) { |
26 | esmtp_address_list_add( list, addr->ad_data.ad_mailbox->mb_addr_spec, 0, NULL ); | 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 ) { | 27 | } else if ( addr->ad_type == MAILIMF_ADDRESS_GROUP ) { |
28 | clist *l = addr->ad_data.ad_group->grp_mb_list->mb_list; | 28 | clist *l = addr->ad_data.ad_group->grp_mb_list->mb_list; |
29 | for ( it2 = clist_begin( l ); it2; it2 = it2->next ) { | 29 | for ( it2 = clist_begin( l ); it2; it2 = it2->next ) { |
30 | mailimf_mailbox *mbox; | 30 | mailimf_mailbox *mbox; |
31 | mbox = (mailimf_mailbox *) it2->data; | 31 | mbox = (mailimf_mailbox *) it2->data; |
32 | esmtp_address_list_add( list, mbox->mb_addr_spec, 0, NULL ); | 32 | esmtp_address_list_add( list, mbox->mb_addr_spec, 0, NULL ); |
33 | } | 33 | } |
34 | } | 34 | } |
35 | } | 35 | } |
36 | } | 36 | } |
37 | 37 | ||
38 | char *Generatemail::getFrom( mailimf_field *ffrom) { | 38 | char *Generatemail::getFrom( mailimf_field *ffrom) { |
39 | char *from = NULL; | 39 | char *from = NULL; |
40 | if ( ffrom && (ffrom->fld_type == MAILIMF_FIELD_FROM) | 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 ) { | 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; | 42 | clist *cl = ffrom->fld_data.fld_from->frm_mb_list->mb_list; |
43 | clistiter *it; | 43 | clistiter *it; |
44 | for ( it = clist_begin( cl ); it; it = it->next ) { | 44 | for ( it = clist_begin( cl ); it; it = it->next ) { |
45 | mailimf_mailbox *mb = (mailimf_mailbox *) it->data; | 45 | mailimf_mailbox *mb = (mailimf_mailbox *) it->data; |
46 | from = strdup( mb->mb_addr_spec ); | 46 | from = strdup( mb->mb_addr_spec ); |
47 | } | 47 | } |
48 | } | 48 | } |
49 | 49 | ||
50 | return from; | 50 | return from; |
51 | } | 51 | } |
52 | 52 | ||
53 | char *Generatemail::getFrom( mailmime *mail ) { | 53 | char *Generatemail::getFrom( mailmime *mail ) { |
54 | /* no need to delete - its just a pointer to structure content */ | 54 | /* no need to delete - its just a pointer to structure content */ |
55 | mailimf_field *ffrom = 0; | 55 | mailimf_field *ffrom = 0; |
56 | ffrom = getField( mail->mm_data.mm_message.mm_fields, MAILIMF_FIELD_FROM ); | 56 | ffrom = getField( mail->mm_data.mm_message.mm_fields, MAILIMF_FIELD_FROM ); |
57 | return getFrom(ffrom); | 57 | return getFrom(ffrom); |
58 | } | 58 | } |
59 | 59 | ||
60 | mailimf_field *Generatemail::getField( mailimf_fields *fields, int type ) { | 60 | mailimf_field *Generatemail::getField( mailimf_fields *fields, int type ) { |
61 | mailimf_field *field; | 61 | mailimf_field *field; |
62 | clistiter *it; | 62 | clistiter *it; |
63 | 63 | ||
64 | it = clist_begin( fields->fld_list ); | 64 | it = clist_begin( fields->fld_list ); |
65 | while ( it ) { | 65 | while ( it ) { |
66 | field = (mailimf_field *) it->data; | 66 | field = (mailimf_field *) it->data; |
67 | if ( field->fld_type == type ) { | 67 | if ( field->fld_type == type ) { |
68 | return field; | 68 | return field; |
69 | } | 69 | } |
70 | it = it->next; | 70 | it = it->next; |
71 | } | 71 | } |
72 | 72 | ||
73 | return NULL; | 73 | return NULL; |
74 | } | 74 | } |
75 | 75 | ||
76 | mailimf_address_list *Generatemail::parseAddresses(const QString&addr ) { | 76 | mailimf_address_list *Generatemail::parseAddresses(const QString&addr ) { |
77 | mailimf_address_list *addresses; | 77 | mailimf_address_list *addresses; |
78 | 78 | ||
79 | if ( addr.isEmpty() ) | 79 | if ( addr.isEmpty() ) |
80 | return NULL; | 80 | return NULL; |
81 | 81 | ||
82 | addresses = mailimf_address_list_new_empty(); | 82 | addresses = mailimf_address_list_new_empty(); |
83 | 83 | ||
84 | bool literal_open = false; | 84 | bool literal_open = false; |
85 | unsigned int startpos = 0; | 85 | unsigned int startpos = 0; |
86 | QStringList list; | 86 | QStringList list; |
87 | QString s; | 87 | QString s; |
88 | unsigned int i = 0; | 88 | unsigned int i = 0; |
89 | for (; i < addr.length();++i) { | 89 | for (; i < addr.length();++i) { |
90 | switch (addr[i]) { | 90 | switch (addr[i]) { |
91 | case '\"': | 91 | case '\"': |
92 | literal_open = !literal_open; | 92 | literal_open = !literal_open; |
93 | break; | 93 | break; |
94 | case ',': | 94 | case ',': |
95 | if (!literal_open) { | 95 | if (!literal_open) { |
96 | s = addr.mid(startpos,i-startpos); | 96 | s = addr.mid(startpos,i-startpos); |
97 | if (!s.isEmpty()) { | 97 | if (!s.isEmpty()) { |
98 | list.append(s); | 98 | list.append(s); |
99 | qDebug("Appended %s",s.latin1()); | 99 | qDebug("Appended %s",s.latin1()); |
100 | } | 100 | } |
101 | // !!!! this is a MUST BE! | 101 | // !!!! this is a MUST BE! |
102 | startpos = ++i; | 102 | startpos = ++i; |
103 | } | 103 | } |
104 | break; | 104 | break; |
@@ -186,282 +186,282 @@ mailmime *Generatemail::buildFilePart(const QString&filename,const QString&mimet | |||
186 | } | 186 | } |
187 | if (content) { | 187 | if (content) { |
188 | mailmime_content_free( content ); | 188 | mailmime_content_free( content ); |
189 | } | 189 | } |
190 | if (fields) { | 190 | if (fields) { |
191 | mailmime_fields_free( fields ); | 191 | mailmime_fields_free( fields ); |
192 | } else { | 192 | } else { |
193 | if (name) { | 193 | if (name) { |
194 | free( name ); | 194 | free( name ); |
195 | } | 195 | } |
196 | if (file) { | 196 | if (file) { |
197 | free( file ); | 197 | free( file ); |
198 | } | 198 | } |
199 | } | 199 | } |
200 | } | 200 | } |
201 | return filePart; // Success :) | 201 | return filePart; // Success :) |
202 | 202 | ||
203 | } | 203 | } |
204 | 204 | ||
205 | void Generatemail::addFileParts( mailmime *message,const QList<Attachment>&files ) { | 205 | void Generatemail::addFileParts( mailmime *message,const QList<Attachment>&files ) { |
206 | const Attachment *it; | 206 | const Attachment *it; |
207 | unsigned int count = files.count(); | 207 | unsigned int count = files.count(); |
208 | qDebug("List contains %i values",count); | 208 | qDebug("List contains %i values",count); |
209 | for ( unsigned int i = 0; i < count; ++i ) { | 209 | for ( unsigned int i = 0; i < count; ++i ) { |
210 | qDebug( "Adding file" ); | 210 | qDebug( "Adding file" ); |
211 | mailmime *filePart; | 211 | mailmime *filePart; |
212 | int err; | 212 | int err; |
213 | it = ((QList<Attachment>)files).at(i); | 213 | it = ((QList<Attachment>)files).at(i); |
214 | 214 | ||
215 | filePart = buildFilePart( it->getFileName(), it->getMimeType(),"" ); | 215 | filePart = buildFilePart( it->getFileName(), it->getMimeType(),"" ); |
216 | if ( filePart == NULL ) { | 216 | if ( filePart == NULL ) { |
217 | qDebug( "addFileParts: error adding file:" ); | 217 | qDebug( "addFileParts: error adding file:" ); |
218 | qDebug( it->getFileName() ); | 218 | qDebug( it->getFileName() ); |
219 | continue; | 219 | continue; |
220 | } | 220 | } |
221 | err = mailmime_smart_add_part( message, filePart ); | 221 | err = mailmime_smart_add_part( message, filePart ); |
222 | if ( err != MAILIMF_NO_ERROR ) { | 222 | if ( err != MAILIMF_NO_ERROR ) { |
223 | mailmime_free( filePart ); | 223 | mailmime_free( filePart ); |
224 | qDebug("error smart add"); | 224 | qDebug("error smart add"); |
225 | } | 225 | } |
226 | } | 226 | } |
227 | } | 227 | } |
228 | 228 | ||
229 | mailmime *Generatemail::buildTxtPart(const QString&str ) { | 229 | mailmime *Generatemail::buildTxtPart(const QString&str ) { |
230 | mailmime *txtPart; | 230 | mailmime *txtPart; |
231 | mailmime_fields *fields; | 231 | mailmime_fields *fields; |
232 | mailmime_content *content; | 232 | mailmime_content *content; |
233 | mailmime_parameter *param; | 233 | mailmime_parameter *param; |
234 | int err; | 234 | int err; |
235 | 235 | ||
236 | param = mailmime_parameter_new( strdup( "charset" ), | 236 | param = mailmime_parameter_new( strdup( "charset" ), |
237 | strdup( "iso-8859-1" ) ); | 237 | strdup( "iso-8859-1" ) ); |
238 | if ( param == NULL ) | 238 | if ( param == NULL ) |
239 | goto err_free; | 239 | goto err_free; |
240 | 240 | ||
241 | content = mailmime_content_new_with_str( "text/plain" ); | 241 | content = mailmime_content_new_with_str( "text/plain" ); |
242 | if ( content == NULL ) | 242 | if ( content == NULL ) |
243 | goto err_free_param; | 243 | goto err_free_param; |
244 | 244 | ||
245 | err = clist_append( content->ct_parameters, param ); | 245 | err = clist_append( content->ct_parameters, param ); |
246 | if ( err != MAILIMF_NO_ERROR ) | 246 | if ( err != MAILIMF_NO_ERROR ) |
247 | goto err_free_content; | 247 | goto err_free_content; |
248 | 248 | ||
249 | fields = mailmime_fields_new_encoding(MAILMIME_MECHANISM_8BIT); | 249 | fields = mailmime_fields_new_encoding(MAILMIME_MECHANISM_8BIT); |
250 | if ( fields == NULL ) | 250 | if ( fields == NULL ) |
251 | goto err_free_content; | 251 | goto err_free_content; |
252 | 252 | ||
253 | txtPart = mailmime_new_empty( content, fields ); | 253 | txtPart = mailmime_new_empty( content, fields ); |
254 | if ( txtPart == NULL ) | 254 | if ( txtPart == NULL ) |
255 | goto err_free_fields; | 255 | goto err_free_fields; |
256 | 256 | ||
257 | err = mailmime_set_body_text( txtPart, (char*)str.data(), str.length() ); | 257 | err = mailmime_set_body_text( txtPart, (char*)str.data(), str.length() ); |
258 | if ( err != MAILIMF_NO_ERROR ) | 258 | if ( err != MAILIMF_NO_ERROR ) |
259 | goto err_free_txtPart; | 259 | goto err_free_txtPart; |
260 | 260 | ||
261 | return txtPart; // Success :) | 261 | return txtPart; // Success :) |
262 | 262 | ||
263 | err_free_txtPart: | 263 | err_free_txtPart: |
264 | mailmime_free( txtPart ); | 264 | mailmime_free( txtPart ); |
265 | err_free_fields: | 265 | err_free_fields: |
266 | mailmime_fields_free( fields ); | 266 | mailmime_fields_free( fields ); |
267 | err_free_content: | 267 | err_free_content: |
268 | mailmime_content_free( content ); | 268 | mailmime_content_free( content ); |
269 | err_free_param: | 269 | err_free_param: |
270 | mailmime_parameter_free( param ); | 270 | mailmime_parameter_free( param ); |
271 | err_free: | 271 | err_free: |
272 | qDebug( "buildTxtPart - error" ); | 272 | qDebug( "buildTxtPart - error" ); |
273 | 273 | ||
274 | return NULL; // Error :( | 274 | return NULL; // Error :( |
275 | } | 275 | } |
276 | 276 | ||
277 | mailimf_mailbox *Generatemail::newMailbox(const QString&name, const QString&mail ) { | 277 | mailimf_mailbox *Generatemail::newMailbox(const QString&name, const QString&mail ) { |
278 | return mailimf_mailbox_new( strdup( name.latin1() ), | 278 | return mailimf_mailbox_new( strdup( name.latin1() ), |
279 | strdup( mail.latin1() ) ); | 279 | strdup( mail.latin1() ) ); |
280 | } | 280 | } |
281 | 281 | ||
282 | mailimf_fields *Generatemail::createImfFields(const Mail&mail ) | 282 | mailimf_fields *Generatemail::createImfFields(const Opie::osmart_pointer<Mail>&mail ) |
283 | { | 283 | { |
284 | mailimf_fields *fields = NULL; | 284 | mailimf_fields *fields = NULL; |
285 | mailimf_field *xmailer = NULL; | 285 | mailimf_field *xmailer = NULL; |
286 | mailimf_mailbox *sender=0,*fromBox=0; | 286 | mailimf_mailbox *sender=0,*fromBox=0; |
287 | mailimf_mailbox_list *from=0; | 287 | mailimf_mailbox_list *from=0; |
288 | mailimf_address_list *to=0, *cc=0, *bcc=0, *reply=0; | 288 | mailimf_address_list *to=0, *cc=0, *bcc=0, *reply=0; |
289 | clist*in_reply_to = 0; | 289 | clist*in_reply_to = 0; |
290 | char *subject = strdup( mail.getSubject().latin1() ); | 290 | char *subject = strdup( mail->getSubject().latin1() ); |
291 | int err; | 291 | int err; |
292 | int res = 1; | 292 | int res = 1; |
293 | 293 | ||
294 | sender = newMailbox( mail.getName(), mail.getMail() ); | 294 | sender = newMailbox( mail->getName(), mail->getMail() ); |
295 | if ( sender == NULL ) { | 295 | if ( sender == NULL ) { |
296 | res = 0; | 296 | res = 0; |
297 | } | 297 | } |
298 | 298 | ||
299 | if (res) { | 299 | if (res) { |
300 | fromBox = newMailbox( mail.getName(), mail.getMail() ); | 300 | fromBox = newMailbox( mail->getName(), mail->getMail() ); |
301 | } | 301 | } |
302 | if ( fromBox == NULL ) { | 302 | if ( fromBox == NULL ) { |
303 | res = 0; | 303 | res = 0; |
304 | } | 304 | } |
305 | 305 | ||
306 | if (res) { | 306 | if (res) { |
307 | from = mailimf_mailbox_list_new_empty(); | 307 | from = mailimf_mailbox_list_new_empty(); |
308 | } | 308 | } |
309 | if ( from == NULL ) { | 309 | if ( from == NULL ) { |
310 | res = 0; | 310 | res = 0; |
311 | } | 311 | } |
312 | 312 | ||
313 | if (res && from) { | 313 | if (res && from) { |
314 | err = mailimf_mailbox_list_add( from, fromBox ); | 314 | err = mailimf_mailbox_list_add( from, fromBox ); |
315 | if ( err != MAILIMF_NO_ERROR ) { | 315 | if ( err != MAILIMF_NO_ERROR ) { |
316 | res = 0; | 316 | res = 0; |
317 | } | 317 | } |
318 | } | 318 | } |
319 | 319 | ||
320 | if (res) to = parseAddresses( mail.getTo() ); | 320 | if (res) to = parseAddresses( mail->getTo() ); |
321 | if (res) cc = parseAddresses( mail.getCC() ); | 321 | if (res) cc = parseAddresses( mail->getCC() ); |
322 | if (res) bcc = parseAddresses( mail.getBCC() ); | 322 | if (res) bcc = parseAddresses( mail->getBCC() ); |
323 | if (res) reply = parseAddresses( mail.getReply() ); | 323 | if (res) reply = parseAddresses( mail->getReply() ); |
324 | 324 | ||
325 | if (res && mail.Inreply().count()>0) { | 325 | if (res && mail->Inreply().count()>0) { |
326 | in_reply_to = clist_new(); | 326 | in_reply_to = clist_new(); |
327 | char*c_reply; | 327 | char*c_reply; |
328 | unsigned int nsize = 0; | 328 | unsigned int nsize = 0; |
329 | for (QStringList::ConstIterator it=mail.Inreply().begin(); | 329 | for (QStringList::ConstIterator it=mail->Inreply().begin(); |
330 | it != mail.Inreply().end();++it) { | 330 | it != mail->Inreply().end();++it) { |
331 | if ((*it).isEmpty()) | 331 | if ((*it).isEmpty()) |
332 | continue; | 332 | continue; |
333 | QString h((*it)); | 333 | QString h((*it)); |
334 | while (h.length()>0 && h[0]=='<') { | 334 | while (h.length()>0 && h[0]=='<') { |
335 | h.remove(0,1); | 335 | h.remove(0,1); |
336 | } | 336 | } |
337 | while (h.length()>0 && h[h.length()-1]=='>') { | 337 | while (h.length()>0 && h[h.length()-1]=='>') { |
338 | h.remove(h.length()-1,1); | 338 | h.remove(h.length()-1,1); |
339 | } | 339 | } |
340 | if (h.isEmpty()) continue; | 340 | if (h.isEmpty()) continue; |
341 | nsize = strlen(h.latin1()); | 341 | nsize = strlen(h.latin1()); |
342 | /* yes! must be malloc! */ | 342 | /* yes! must be malloc! */ |
343 | c_reply = (char*)malloc( (nsize+1)*sizeof(char)); | 343 | c_reply = (char*)malloc( (nsize+1)*sizeof(char)); |
344 | memset(c_reply,0,nsize+1); | 344 | memset(c_reply,0,nsize+1); |
345 | memcpy(c_reply,h.latin1(),nsize); | 345 | memcpy(c_reply,h.latin1(),nsize); |
346 | clist_append(in_reply_to,c_reply); | 346 | clist_append(in_reply_to,c_reply); |
347 | qDebug("In reply to: %s",c_reply); | 347 | qDebug("In reply to: %s",c_reply); |
348 | } | 348 | } |
349 | } | 349 | } |
350 | 350 | ||
351 | if (res) { | 351 | if (res) { |
352 | fields = mailimf_fields_new_with_data( from, sender, reply, to, cc, bcc, | 352 | fields = mailimf_fields_new_with_data( from, sender, reply, to, cc, bcc, |
353 | in_reply_to, NULL, subject ); | 353 | in_reply_to, NULL, subject ); |
354 | if ( fields == NULL ) { | 354 | if ( fields == NULL ) { |
355 | qDebug("Error creating mailimf fields"); | 355 | qDebug("Error creating mailimf fields"); |
356 | res = 0; | 356 | res = 0; |
357 | } | 357 | } |
358 | } | 358 | } |
359 | if (res) xmailer = mailimf_field_new_custom( strdup( "User-Agent" ), | 359 | if (res) xmailer = mailimf_field_new_custom( strdup( "User-Agent" ), |
360 | strdup( USER_AGENT ) ); | 360 | strdup( USER_AGENT ) ); |
361 | if ( xmailer == NULL ) { | 361 | if ( xmailer == NULL ) { |
362 | res = 0; | 362 | res = 0; |
363 | } else { | 363 | } else { |
364 | err = mailimf_fields_add( fields, xmailer ); | 364 | err = mailimf_fields_add( fields, xmailer ); |
365 | if ( err != MAILIMF_NO_ERROR ) { | 365 | if ( err != MAILIMF_NO_ERROR ) { |
366 | res = 0; | 366 | res = 0; |
367 | } | 367 | } |
368 | } | 368 | } |
369 | if (!res ) { | 369 | if (!res ) { |
370 | if (xmailer) { | 370 | if (xmailer) { |
371 | mailimf_field_free( xmailer ); | 371 | mailimf_field_free( xmailer ); |
372 | xmailer = NULL; | 372 | xmailer = NULL; |
373 | } | 373 | } |
374 | if (fields) { | 374 | if (fields) { |
375 | mailimf_fields_free( fields ); | 375 | mailimf_fields_free( fields ); |
376 | fields = NULL; | 376 | fields = NULL; |
377 | } else { | 377 | } else { |
378 | if (reply) | 378 | if (reply) |
379 | mailimf_address_list_free( reply ); | 379 | mailimf_address_list_free( reply ); |
380 | if (bcc) | 380 | if (bcc) |
381 | mailimf_address_list_free( bcc ); | 381 | mailimf_address_list_free( bcc ); |
382 | if (cc) | 382 | if (cc) |
383 | mailimf_address_list_free( cc ); | 383 | mailimf_address_list_free( cc ); |
384 | if (to) | 384 | if (to) |
385 | mailimf_address_list_free( to ); | 385 | mailimf_address_list_free( to ); |
386 | if (fromBox) { | 386 | if (fromBox) { |
387 | mailimf_mailbox_free( fromBox ); | 387 | mailimf_mailbox_free( fromBox ); |
388 | } else if (from) { | 388 | } else if (from) { |
389 | mailimf_mailbox_list_free( from ); | 389 | mailimf_mailbox_list_free( from ); |
390 | } | 390 | } |
391 | if (sender) { | 391 | if (sender) { |
392 | mailimf_mailbox_free( sender ); | 392 | mailimf_mailbox_free( sender ); |
393 | } | 393 | } |
394 | if (subject) { | 394 | if (subject) { |
395 | free( subject ); | 395 | free( subject ); |
396 | } | 396 | } |
397 | } | 397 | } |
398 | } | 398 | } |
399 | return fields; | 399 | return fields; |
400 | } | 400 | } |
401 | 401 | ||
402 | mailmime *Generatemail::createMimeMail(const Mail &mail ) { | 402 | mailmime *Generatemail::createMimeMail(const Opie::osmart_pointer<Mail> &mail ) { |
403 | mailmime *message, *txtPart; | 403 | mailmime *message, *txtPart; |
404 | mailimf_fields *fields; | 404 | mailimf_fields *fields; |
405 | int err; | 405 | int err; |
406 | 406 | ||
407 | fields = createImfFields( mail ); | 407 | fields = createImfFields( mail ); |
408 | if ( fields == NULL ) | 408 | if ( fields == NULL ) |
409 | goto err_free; | 409 | goto err_free; |
410 | 410 | ||
411 | message = mailmime_new_message_data( NULL ); | 411 | message = mailmime_new_message_data( NULL ); |
412 | if ( message == NULL ) | 412 | if ( message == NULL ) |
413 | goto err_free_fields; | 413 | goto err_free_fields; |
414 | 414 | ||
415 | mailmime_set_imf_fields( message, fields ); | 415 | mailmime_set_imf_fields( message, fields ); |
416 | 416 | ||
417 | txtPart = buildTxtPart( mail.getMessage() ); | 417 | txtPart = buildTxtPart( mail->getMessage() ); |
418 | 418 | ||
419 | if ( txtPart == NULL ) | 419 | if ( txtPart == NULL ) |
420 | goto err_free_message; | 420 | goto err_free_message; |
421 | 421 | ||
422 | err = mailmime_smart_add_part( message, txtPart ); | 422 | err = mailmime_smart_add_part( message, txtPart ); |
423 | if ( err != MAILIMF_NO_ERROR ) | 423 | if ( err != MAILIMF_NO_ERROR ) |
424 | goto err_free_txtPart; | 424 | goto err_free_txtPart; |
425 | 425 | ||
426 | addFileParts( message, mail.getAttachments() ); | 426 | addFileParts( message, mail->getAttachments() ); |
427 | 427 | ||
428 | return message; // Success :) | 428 | return message; // Success :) |
429 | 429 | ||
430 | err_free_txtPart: | 430 | err_free_txtPart: |
431 | mailmime_free( txtPart ); | 431 | mailmime_free( txtPart ); |
432 | err_free_message: | 432 | err_free_message: |
433 | mailmime_free( message ); | 433 | mailmime_free( message ); |
434 | err_free_fields: | 434 | err_free_fields: |
435 | mailimf_fields_free( fields ); | 435 | mailimf_fields_free( fields ); |
436 | err_free: | 436 | err_free: |
437 | qDebug( "createMimeMail: error" ); | 437 | qDebug( "createMimeMail: error" ); |
438 | 438 | ||
439 | return NULL; // Error :( | 439 | return NULL; // Error :( |
440 | } | 440 | } |
441 | 441 | ||
442 | clist *Generatemail::createRcptList( mailimf_fields *fields ) { | 442 | clist *Generatemail::createRcptList( mailimf_fields *fields ) { |
443 | clist *rcptList; | 443 | clist *rcptList; |
444 | mailimf_field *field; | 444 | mailimf_field *field; |
445 | 445 | ||
446 | rcptList = esmtp_address_list_new(); | 446 | rcptList = esmtp_address_list_new(); |
447 | 447 | ||
448 | field = getField( fields, MAILIMF_FIELD_TO ); | 448 | field = getField( fields, MAILIMF_FIELD_TO ); |
449 | if ( field && (field->fld_type == MAILIMF_FIELD_TO) | 449 | if ( field && (field->fld_type == MAILIMF_FIELD_TO) |
450 | && field->fld_data.fld_to->to_addr_list ) { | 450 | && field->fld_data.fld_to->to_addr_list ) { |
451 | addRcpts( rcptList, field->fld_data.fld_to->to_addr_list ); | 451 | addRcpts( rcptList, field->fld_data.fld_to->to_addr_list ); |
452 | } | 452 | } |
453 | 453 | ||
454 | field = getField( fields, MAILIMF_FIELD_CC ); | 454 | field = getField( fields, MAILIMF_FIELD_CC ); |
455 | if ( field && (field->fld_type == MAILIMF_FIELD_CC) | 455 | if ( field && (field->fld_type == MAILIMF_FIELD_CC) |
456 | && field->fld_data.fld_cc->cc_addr_list ) { | 456 | && field->fld_data.fld_cc->cc_addr_list ) { |
457 | addRcpts( rcptList, field->fld_data.fld_cc->cc_addr_list ); | 457 | addRcpts( rcptList, field->fld_data.fld_cc->cc_addr_list ); |
458 | } | 458 | } |
459 | 459 | ||
460 | field = getField( fields, MAILIMF_FIELD_BCC ); | 460 | field = getField( fields, MAILIMF_FIELD_BCC ); |
461 | if ( field && (field->fld_type == MAILIMF_FIELD_BCC) | 461 | if ( field && (field->fld_type == MAILIMF_FIELD_BCC) |
462 | && field->fld_data.fld_bcc->bcc_addr_list ) { | 462 | && field->fld_data.fld_bcc->bcc_addr_list ) { |
463 | addRcpts( rcptList, field->fld_data.fld_bcc->bcc_addr_list ); | 463 | addRcpts( rcptList, field->fld_data.fld_bcc->bcc_addr_list ); |
464 | } | 464 | } |
465 | 465 | ||
466 | return rcptList; | 466 | return rcptList; |
467 | } | 467 | } |
diff --git a/noncore/net/mail/libmailwrapper/generatemail.h b/noncore/net/mail/libmailwrapper/generatemail.h index 8be5a2b..409a55e 100644 --- a/noncore/net/mail/libmailwrapper/generatemail.h +++ b/noncore/net/mail/libmailwrapper/generatemail.h | |||
@@ -1,44 +1,46 @@ | |||
1 | #ifndef __GENERATE_MAIL_H | 1 | #ifndef __GENERATE_MAIL_H |
2 | #define __GENERATE_MAIL_H | 2 | #define __GENERATE_MAIL_H |
3 | 3 | ||
4 | #include <qpe/applnk.h> | 4 | #include <qpe/applnk.h> |
5 | 5 | ||
6 | #include <qobject.h> | 6 | #include <qobject.h> |
7 | #include <libetpan/clist.h> | 7 | #include <libetpan/clist.h> |
8 | 8 | ||
9 | #include <opie2/osmart_pointer.h> | ||
10 | |||
9 | class Mail; | 11 | class Mail; |
10 | class RecMail; | 12 | class RecMail; |
11 | class Attachment; | 13 | class Attachment; |
12 | struct mailimf_fields; | 14 | struct mailimf_fields; |
13 | struct mailimf_field; | 15 | struct mailimf_field; |
14 | struct mailimf_mailbox; | 16 | struct mailimf_mailbox; |
15 | struct mailmime; | 17 | struct mailmime; |
16 | struct mailimf_address_list; | 18 | struct mailimf_address_list; |
17 | class progressMailSend; | 19 | class progressMailSend; |
18 | struct mailsmtp; | 20 | struct mailsmtp; |
19 | 21 | ||
20 | class Generatemail : public QObject | 22 | class Generatemail : public QObject |
21 | { | 23 | { |
22 | Q_OBJECT | 24 | Q_OBJECT |
23 | public: | 25 | public: |
24 | Generatemail(); | 26 | Generatemail(); |
25 | virtual ~Generatemail(); | 27 | virtual ~Generatemail(); |
26 | 28 | ||
27 | protected: | 29 | protected: |
28 | static void addRcpts( clist *list, mailimf_address_list *addr_list ); | 30 | static void addRcpts( clist *list, mailimf_address_list *addr_list ); |
29 | static char *getFrom( mailmime *mail ); | 31 | static char *getFrom( mailmime *mail ); |
30 | static char *getFrom( mailimf_field *ffrom); | 32 | static char *getFrom( mailimf_field *ffrom); |
31 | static mailimf_field *getField( mailimf_fields *fields, int type ); | 33 | static mailimf_field *getField( mailimf_fields *fields, int type ); |
32 | mailimf_address_list *parseAddresses(const QString&addr ); | 34 | mailimf_address_list *parseAddresses(const QString&addr ); |
33 | void addFileParts( mailmime *message,const QList<Attachment>&files ); | 35 | void addFileParts( mailmime *message,const QList<Attachment>&files ); |
34 | mailmime *buildFilePart(const QString&filename,const QString&mimetype,const QString&content); | 36 | mailmime *buildFilePart(const QString&filename,const QString&mimetype,const QString&content); |
35 | mailmime *buildTxtPart(const QString&str ); | 37 | mailmime *buildTxtPart(const QString&str ); |
36 | mailimf_mailbox *newMailbox(const QString&name,const QString&mail ); | 38 | mailimf_mailbox *newMailbox(const QString&name,const QString&mail ); |
37 | mailimf_fields *createImfFields(const Mail &mail ); | 39 | mailimf_fields *createImfFields(const Opie::osmart_pointer<Mail> &mail ); |
38 | mailmime *createMimeMail(const Mail&mail ); | 40 | mailmime *createMimeMail(const Opie::osmart_pointer<Mail>&mail ); |
39 | clist *createRcptList( mailimf_fields *fields ); | 41 | clist *createRcptList( mailimf_fields *fields ); |
40 | 42 | ||
41 | static const char* USER_AGENT; | 43 | static const char* USER_AGENT; |
42 | }; | 44 | }; |
43 | 45 | ||
44 | #endif | 46 | #endif |
diff --git a/noncore/net/mail/libmailwrapper/mailwrapper.cpp b/noncore/net/mail/libmailwrapper/mailwrapper.cpp index ebdbf4b..6bd98f6 100644 --- a/noncore/net/mail/libmailwrapper/mailwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/mailwrapper.cpp | |||
@@ -1,164 +1,166 @@ | |||
1 | #include <stdlib.h> | 1 | #include <stdlib.h> |
2 | #include <sys/stat.h> | 2 | #include <sys/stat.h> |
3 | #include <sys/types.h> | 3 | #include <sys/types.h> |
4 | #include <unistd.h> | 4 | #include <unistd.h> |
5 | #include <fcntl.h> | 5 | #include <fcntl.h> |
6 | #include <string.h> | 6 | #include <string.h> |
7 | #include <qdir.h> | 7 | #include <qdir.h> |
8 | 8 | ||
9 | #include "mailwrapper.h" | 9 | #include "mailwrapper.h" |
10 | //#include "logindialog.h" | 10 | //#include "logindialog.h" |
11 | //#include "defines.h" | 11 | //#include "defines.h" |
12 | 12 | ||
13 | #define UNDEFINED 64 | 13 | #define UNDEFINED 64 |
14 | #define MAXLINE 76 | 14 | #define MAXLINE 76 |
15 | #define UTF16MASK 0x03FFUL | 15 | #define UTF16MASK 0x03FFUL |
16 | #define UTF16SHIFT 10 | 16 | #define UTF16SHIFT 10 |
17 | #define UTF16BASE 0x10000UL | 17 | #define UTF16BASE 0x10000UL |
18 | #define UTF16HIGHSTART 0xD800UL | 18 | #define UTF16HIGHSTART 0xD800UL |
19 | #define UTF16HIGHEND 0xDBFFUL | 19 | #define UTF16HIGHEND 0xDBFFUL |
20 | #define UTF16LOSTART 0xDC00UL | 20 | #define UTF16LOSTART 0xDC00UL |
21 | #define UTF16LOEND 0xDFFFUL | 21 | #define UTF16LOEND 0xDFFFUL |
22 | 22 | ||
23 | 23 | ||
24 | Attachment::Attachment( DocLnk lnk ) | 24 | Attachment::Attachment( DocLnk lnk ) |
25 | { | 25 | { |
26 | doc = lnk; | 26 | doc = lnk; |
27 | size = QFileInfo( doc.file() ).size(); | 27 | size = QFileInfo( doc.file() ).size(); |
28 | } | 28 | } |
29 | 29 | ||
30 | Folder::Folder(const QString&tmp_name, const QString&sep ) | 30 | Folder::Folder(const QString&tmp_name, const QString&sep ) |
31 | { | 31 | { |
32 | name = tmp_name; | 32 | name = tmp_name; |
33 | nameDisplay = name; | 33 | nameDisplay = name; |
34 | separator = sep; | 34 | separator = sep; |
35 | prefix = ""; | 35 | prefix = ""; |
36 | } | 36 | } |
37 | 37 | ||
38 | const QString& Folder::Separator()const | 38 | const QString& Folder::Separator()const |
39 | { | 39 | { |
40 | return separator; | 40 | return separator; |
41 | } | 41 | } |
42 | 42 | ||
43 | IMAPFolder::IMAPFolder(const QString&name,const QString&sep, bool select,bool no_inf, const QString&aprefix ) | 43 | IMAPFolder::IMAPFolder(const QString&name,const QString&sep, bool select,bool no_inf, const QString&aprefix ) |
44 | : Folder( name,sep ),m_MaySelect(select),m_NoInferior(no_inf) | 44 | : Folder( name,sep ),m_MaySelect(select),m_NoInferior(no_inf) |
45 | { | 45 | { |
46 | // Decode IMAP foldername | 46 | // Decode IMAP foldername |
47 | nameDisplay = IMAPFolder::decodeFolderName( name ); | 47 | nameDisplay = IMAPFolder::decodeFolderName( name ); |
48 | /* | ||
48 | qDebug( "folder " + name + " - displayed as " + nameDisplay ); | 49 | qDebug( "folder " + name + " - displayed as " + nameDisplay ); |
50 | */ | ||
49 | prefix = aprefix; | 51 | prefix = aprefix; |
50 | 52 | ||
51 | if (prefix.length()>0) { | 53 | if (prefix.length()>0) { |
52 | if (nameDisplay.startsWith(prefix) && nameDisplay.length()>prefix.length()) { | 54 | if (nameDisplay.startsWith(prefix) && nameDisplay.length()>prefix.length()) { |
53 | nameDisplay=nameDisplay.right(nameDisplay.length()-prefix.length()); | 55 | nameDisplay=nameDisplay.right(nameDisplay.length()-prefix.length()); |
54 | } | 56 | } |
55 | } | 57 | } |
56 | } | 58 | } |
57 | 59 | ||
58 | static unsigned char base64chars[] = | 60 | static unsigned char base64chars[] = |
59 | "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+,"; | 61 | "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+,"; |
60 | 62 | ||
61 | /** | 63 | /** |
62 | * Decodes base64 encoded parts of the imapfolder name | 64 | * Decodes base64 encoded parts of the imapfolder name |
63 | * Code taken from kde cvs: kdebase/kioslave/imap4/rfcdecoder.cc | 65 | * Code taken from kde cvs: kdebase/kioslave/imap4/rfcdecoder.cc |
64 | */ | 66 | */ |
65 | QString IMAPFolder::decodeFolderName( const QString &name ) | 67 | QString IMAPFolder::decodeFolderName( const QString &name ) |
66 | { | 68 | { |
67 | unsigned char c, i, bitcount; | 69 | unsigned char c, i, bitcount; |
68 | unsigned long ucs4, utf16, bitbuf; | 70 | unsigned long ucs4, utf16, bitbuf; |
69 | unsigned char base64[256], utf8[6]; | 71 | unsigned char base64[256], utf8[6]; |
70 | unsigned long srcPtr = 0; | 72 | unsigned long srcPtr = 0; |
71 | QCString dst = ""; | 73 | QCString dst = ""; |
72 | QCString src = name.ascii(); | 74 | QCString src = name.ascii(); |
73 | 75 | ||
74 | /* initialize modified base64 decoding table */ | 76 | /* initialize modified base64 decoding table */ |
75 | memset(base64, UNDEFINED, sizeof(base64)); | 77 | memset(base64, UNDEFINED, sizeof(base64)); |
76 | for (i = 0; i < sizeof(base64chars); ++i) { | 78 | for (i = 0; i < sizeof(base64chars); ++i) { |
77 | base64[(int)base64chars[i]] = i; | 79 | base64[(int)base64chars[i]] = i; |
78 | } | 80 | } |
79 | 81 | ||
80 | /* loop until end of string */ | 82 | /* loop until end of string */ |
81 | while (srcPtr < src.length ()) { | 83 | while (srcPtr < src.length ()) { |
82 | c = src[srcPtr++]; | 84 | c = src[srcPtr++]; |
83 | /* deal with literal characters and &- */ | 85 | /* deal with literal characters and &- */ |
84 | if (c != '&' || src[srcPtr] == '-') { | 86 | if (c != '&' || src[srcPtr] == '-') { |
85 | /* encode literally */ | 87 | /* encode literally */ |
86 | dst += c; | 88 | dst += c; |
87 | /* skip over the '-' if this is an &- sequence */ | 89 | /* skip over the '-' if this is an &- sequence */ |
88 | if (c == '&') | 90 | if (c == '&') |
89 | srcPtr++; | 91 | srcPtr++; |
90 | } else { | 92 | } else { |
91 | /* convert modified UTF-7 -> UTF-16 -> UCS-4 -> UTF-8 -> HEX */ | 93 | /* convert modified UTF-7 -> UTF-16 -> UCS-4 -> UTF-8 -> HEX */ |
92 | bitbuf = 0; | 94 | bitbuf = 0; |
93 | bitcount = 0; | 95 | bitcount = 0; |
94 | ucs4 = 0; | 96 | ucs4 = 0; |
95 | while ((c = base64[(unsigned char) src[srcPtr]]) != UNDEFINED) { | 97 | while ((c = base64[(unsigned char) src[srcPtr]]) != UNDEFINED) { |
96 | ++srcPtr; | 98 | ++srcPtr; |
97 | bitbuf = (bitbuf << 6) | c; | 99 | bitbuf = (bitbuf << 6) | c; |
98 | bitcount += 6; | 100 | bitcount += 6; |
99 | /* enough bits for a UTF-16 character? */ | 101 | /* enough bits for a UTF-16 character? */ |
100 | if (bitcount >= 16) { | 102 | if (bitcount >= 16) { |
101 | bitcount -= 16; | 103 | bitcount -= 16; |
102 | utf16 = (bitcount ? bitbuf >> bitcount : bitbuf) & 0xffff; | 104 | utf16 = (bitcount ? bitbuf >> bitcount : bitbuf) & 0xffff; |
103 | /* convert UTF16 to UCS4 */ | 105 | /* convert UTF16 to UCS4 */ |
104 | if (utf16 >= UTF16HIGHSTART && utf16 <= UTF16HIGHEND) { | 106 | if (utf16 >= UTF16HIGHSTART && utf16 <= UTF16HIGHEND) { |
105 | ucs4 = (utf16 - UTF16HIGHSTART) << UTF16SHIFT; | 107 | ucs4 = (utf16 - UTF16HIGHSTART) << UTF16SHIFT; |
106 | continue; | 108 | continue; |
107 | } else if (utf16 >= UTF16LOSTART && utf16 <= UTF16LOEND) { | 109 | } else if (utf16 >= UTF16LOSTART && utf16 <= UTF16LOEND) { |
108 | ucs4 += utf16 - UTF16LOSTART + UTF16BASE; | 110 | ucs4 += utf16 - UTF16LOSTART + UTF16BASE; |
109 | } else { | 111 | } else { |
110 | ucs4 = utf16; | 112 | ucs4 = utf16; |
111 | } | 113 | } |
112 | /* convert UTF-16 range of UCS4 to UTF-8 */ | 114 | /* convert UTF-16 range of UCS4 to UTF-8 */ |
113 | if (ucs4 <= 0x7fUL) { | 115 | if (ucs4 <= 0x7fUL) { |
114 | utf8[0] = ucs4; | 116 | utf8[0] = ucs4; |
115 | i = 1; | 117 | i = 1; |
116 | } else if (ucs4 <= 0x7ffUL) { | 118 | } else if (ucs4 <= 0x7ffUL) { |
117 | utf8[0] = 0xc0 | (ucs4 >> 6); | 119 | utf8[0] = 0xc0 | (ucs4 >> 6); |
118 | utf8[1] = 0x80 | (ucs4 & 0x3f); | 120 | utf8[1] = 0x80 | (ucs4 & 0x3f); |
119 | i = 2; | 121 | i = 2; |
120 | } else if (ucs4 <= 0xffffUL) { | 122 | } else if (ucs4 <= 0xffffUL) { |
121 | utf8[0] = 0xe0 | (ucs4 >> 12); | 123 | utf8[0] = 0xe0 | (ucs4 >> 12); |
122 | utf8[1] = 0x80 | ((ucs4 >> 6) & 0x3f); | 124 | utf8[1] = 0x80 | ((ucs4 >> 6) & 0x3f); |
123 | utf8[2] = 0x80 | (ucs4 & 0x3f); | 125 | utf8[2] = 0x80 | (ucs4 & 0x3f); |
124 | i = 3; | 126 | i = 3; |
125 | } else { | 127 | } else { |
126 | utf8[0] = 0xf0 | (ucs4 >> 18); | 128 | utf8[0] = 0xf0 | (ucs4 >> 18); |
127 | utf8[1] = 0x80 | ((ucs4 >> 12) & 0x3f); | 129 | utf8[1] = 0x80 | ((ucs4 >> 12) & 0x3f); |
128 | utf8[2] = 0x80 | ((ucs4 >> 6) & 0x3f); | 130 | utf8[2] = 0x80 | ((ucs4 >> 6) & 0x3f); |
129 | utf8[3] = 0x80 | (ucs4 & 0x3f); | 131 | utf8[3] = 0x80 | (ucs4 & 0x3f); |
130 | i = 4; | 132 | i = 4; |
131 | } | 133 | } |
132 | /* copy it */ | 134 | /* copy it */ |
133 | for (c = 0; c < i; ++c) { | 135 | for (c = 0; c < i; ++c) { |
134 | dst += utf8[c]; | 136 | dst += utf8[c]; |
135 | } | 137 | } |
136 | } | 138 | } |
137 | } | 139 | } |
138 | /* skip over trailing '-' in modified UTF-7 encoding */ | 140 | /* skip over trailing '-' in modified UTF-7 encoding */ |
139 | if (src[srcPtr] == '-') | 141 | if (src[srcPtr] == '-') |
140 | ++srcPtr; | 142 | ++srcPtr; |
141 | } | 143 | } |
142 | } | 144 | } |
143 | 145 | ||
144 | return QString::fromUtf8( dst.data() ); | 146 | return QString::fromUtf8( dst.data() ); |
145 | } | 147 | } |
146 | 148 | ||
147 | Mail::Mail() | 149 | Mail::Mail() |
148 | :name(""), mail(""), to(""), cc(""), bcc(""), reply(""), subject(""), message("") | 150 | :Opie::oref_count(),name(""), mail(""), to(""), cc(""), bcc(""), reply(""), subject(""), message("") |
149 | { | 151 | { |
150 | } | 152 | } |
151 | 153 | ||
152 | MHFolder::MHFolder(const QString&disp_name,const QString&mbox) | 154 | MHFolder::MHFolder(const QString&disp_name,const QString&mbox) |
153 | : Folder( disp_name,"/" ) | 155 | : Folder( disp_name,"/" ) |
154 | { | 156 | { |
155 | separator = "/"; | 157 | separator = "/"; |
156 | name = mbox; | 158 | name = mbox; |
157 | if (!disp_name.startsWith("/") && disp_name.length()>0) | 159 | if (!disp_name.startsWith("/") && disp_name.length()>0) |
158 | name+="/"; | 160 | name+="/"; |
159 | name+=disp_name; | 161 | name+=disp_name; |
160 | if (disp_name.length()==0) { | 162 | if (disp_name.length()==0) { |
161 | nameDisplay = separator; | 163 | nameDisplay = separator; |
162 | } | 164 | } |
163 | prefix = mbox; | 165 | prefix = mbox; |
164 | } | 166 | } |
diff --git a/noncore/net/mail/libmailwrapper/mailwrapper.h b/noncore/net/mail/libmailwrapper/mailwrapper.h index 3a9f97b..c66572c 100644 --- a/noncore/net/mail/libmailwrapper/mailwrapper.h +++ b/noncore/net/mail/libmailwrapper/mailwrapper.h | |||
@@ -1,102 +1,104 @@ | |||
1 | #ifndef MAILWRAPPER_H | 1 | #ifndef MAILWRAPPER_H |
2 | #define MAILWRAPPER_H | 2 | #define MAILWRAPPER_H |
3 | 3 | ||
4 | #include <qpe/applnk.h> | 4 | #include <qpe/applnk.h> |
5 | 5 | ||
6 | #include <qbitarray.h> | 6 | #include <qbitarray.h> |
7 | #include <qdatetime.h> | 7 | #include <qdatetime.h> |
8 | 8 | ||
9 | #include "settings.h" | 9 | #include "settings.h" |
10 | 10 | ||
11 | #include <opie2/osmart_pointer.h> | ||
12 | |||
11 | class Attachment | 13 | class Attachment |
12 | { | 14 | { |
13 | public: | 15 | public: |
14 | Attachment( DocLnk lnk ); | 16 | Attachment( DocLnk lnk ); |
15 | virtual ~Attachment(){} | 17 | virtual ~Attachment(){} |
16 | const QString getFileName()const{ return doc.file(); } | 18 | const QString getFileName()const{ return doc.file(); } |
17 | const QString getName()const{ return doc.name(); } | 19 | const QString getName()const{ return doc.name(); } |
18 | const QString getMimeType()const{ return doc.type(); } | 20 | const QString getMimeType()const{ return doc.type(); } |
19 | const QPixmap getPixmap()const{ return doc.pixmap(); } | 21 | const QPixmap getPixmap()const{ return doc.pixmap(); } |
20 | const int getSize()const { return size; } | 22 | const int getSize()const { return size; } |
21 | DocLnk getDocLnk() { return doc; } | 23 | DocLnk getDocLnk() { return doc; } |
22 | 24 | ||
23 | protected: | 25 | protected: |
24 | DocLnk doc; | 26 | DocLnk doc; |
25 | int size; | 27 | int size; |
26 | 28 | ||
27 | }; | 29 | }; |
28 | 30 | ||
29 | class Mail | 31 | class Mail:public Opie::oref_count |
30 | { | 32 | { |
31 | public: | 33 | public: |
32 | Mail(); | 34 | Mail(); |
33 | /* Possible that this destructor must not be declared virtual | 35 | /* Possible that this destructor must not be declared virtual |
34 | * 'cause it seems that it will never have some child classes. | 36 | * 'cause it seems that it will never have some child classes. |
35 | * in this case this object will not get a virtual table -> memory and | 37 | * in this case this object will not get a virtual table -> memory and |
36 | * speed will be a little bit better? | 38 | * speed will be a little bit better? |
37 | */ | 39 | */ |
38 | virtual ~Mail(){} | 40 | virtual ~Mail(){} |
39 | void addAttachment( Attachment *att ) { attList.append( att ); } | 41 | void addAttachment( Attachment *att ) { attList.append( att ); } |
40 | const QList<Attachment>& getAttachments()const { return attList; } | 42 | const QList<Attachment>& getAttachments()const { return attList; } |
41 | void removeAttachment( Attachment *att ) { attList.remove( att ); } | 43 | void removeAttachment( Attachment *att ) { attList.remove( att ); } |
42 | const QString&getName()const { return name; } | 44 | const QString&getName()const { return name; } |
43 | void setName( QString s ) { name = s; } | 45 | void setName( QString s ) { name = s; } |
44 | const QString&getMail()const{ return mail; } | 46 | const QString&getMail()const{ return mail; } |
45 | void setMail( const QString&s ) { mail = s; } | 47 | void setMail( const QString&s ) { mail = s; } |
46 | const QString&getTo()const{ return to; } | 48 | const QString&getTo()const{ return to; } |
47 | void setTo( const QString&s ) { to = s; } | 49 | void setTo( const QString&s ) { to = s; } |
48 | const QString&getCC()const{ return cc; } | 50 | const QString&getCC()const{ return cc; } |
49 | void setCC( const QString&s ) { cc = s; } | 51 | void setCC( const QString&s ) { cc = s; } |
50 | const QString&getBCC()const { return bcc; } | 52 | const QString&getBCC()const { return bcc; } |
51 | void setBCC( const QString&s ) { bcc = s; } | 53 | void setBCC( const QString&s ) { bcc = s; } |
52 | const QString&getMessage()const { return message; } | 54 | const QString&getMessage()const { return message; } |
53 | void setMessage( const QString&s ) { message = s; } | 55 | void setMessage( const QString&s ) { message = s; } |
54 | const QString&getSubject()const { return subject; } | 56 | const QString&getSubject()const { return subject; } |
55 | void setSubject( const QString&s ) { subject = s; } | 57 | void setSubject( const QString&s ) { subject = s; } |
56 | const QString&getReply()const{ return reply; } | 58 | const QString&getReply()const{ return reply; } |
57 | void setReply( const QString&a ) { reply = a; } | 59 | void setReply( const QString&a ) { reply = a; } |
58 | void setInreply(const QStringList&list){m_in_reply_to = list;} | 60 | void setInreply(const QStringList&list){m_in_reply_to = list;} |
59 | const QStringList&Inreply()const{return m_in_reply_to;} | 61 | const QStringList&Inreply()const{return m_in_reply_to;} |
60 | 62 | ||
61 | private: | 63 | private: |
62 | QList<Attachment> attList; | 64 | QList<Attachment> attList; |
63 | QString name, mail, to, cc, bcc, reply, subject, message; | 65 | QString name, mail, to, cc, bcc, reply, subject, message; |
64 | QStringList m_in_reply_to; | 66 | QStringList m_in_reply_to; |
65 | }; | 67 | }; |
66 | 68 | ||
67 | class Folder : public QObject | 69 | class Folder : public QObject |
68 | { | 70 | { |
69 | Q_OBJECT | 71 | Q_OBJECT |
70 | 72 | ||
71 | public: | 73 | public: |
72 | Folder( const QString&init_name,const QString&sep ); | 74 | Folder( const QString&init_name,const QString&sep ); |
73 | const QString&getDisplayName()const { return nameDisplay; } | 75 | const QString&getDisplayName()const { return nameDisplay; } |
74 | const QString&getName()const { return name; } | 76 | const QString&getName()const { return name; } |
75 | const QString&getPrefix()const{return prefix; } | 77 | const QString&getPrefix()const{return prefix; } |
76 | virtual bool may_select()const{return true;} | 78 | virtual bool may_select()const{return true;} |
77 | virtual bool no_inferior()const{return true;} | 79 | virtual bool no_inferior()const{return true;} |
78 | const QString&Separator()const; | 80 | const QString&Separator()const; |
79 | 81 | ||
80 | protected: | 82 | protected: |
81 | QString nameDisplay, name, separator,prefix; | 83 | QString nameDisplay, name, separator,prefix; |
82 | }; | 84 | }; |
83 | 85 | ||
84 | class MHFolder : public Folder | 86 | class MHFolder : public Folder |
85 | { | 87 | { |
86 | Q_OBJECT | 88 | Q_OBJECT |
87 | public: | 89 | public: |
88 | MHFolder(const QString&disp_name,const QString&mbox); | 90 | MHFolder(const QString&disp_name,const QString&mbox); |
89 | }; | 91 | }; |
90 | 92 | ||
91 | class IMAPFolder : public Folder | 93 | class IMAPFolder : public Folder |
92 | { | 94 | { |
93 | public: | 95 | public: |
94 | IMAPFolder(const QString&name, const QString&sep, bool select=true,bool noinf=false,const QString&prefix="" ); | 96 | IMAPFolder(const QString&name, const QString&sep, bool select=true,bool noinf=false,const QString&prefix="" ); |
95 | virtual bool may_select()const{return m_MaySelect;} | 97 | virtual bool may_select()const{return m_MaySelect;} |
96 | virtual bool no_inferior()const{return m_NoInferior;} | 98 | virtual bool no_inferior()const{return m_NoInferior;} |
97 | private: | 99 | private: |
98 | static QString decodeFolderName( const QString &name ); | 100 | static QString decodeFolderName( const QString &name ); |
99 | bool m_MaySelect,m_NoInferior; | 101 | bool m_MaySelect,m_NoInferior; |
100 | }; | 102 | }; |
101 | 103 | ||
102 | #endif | 104 | #endif |
diff --git a/noncore/net/mail/libmailwrapper/smtpwrapper.cpp b/noncore/net/mail/libmailwrapper/smtpwrapper.cpp index a4e0beb..afc5618 100644 --- a/noncore/net/mail/libmailwrapper/smtpwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/smtpwrapper.cpp | |||
@@ -219,193 +219,193 @@ void SMTPwrapper::connect_server() | |||
219 | qDebug("Error init connection"); | 219 | qDebug("Error init connection"); |
220 | failuretext = tr("Error init SMTP connection: %1").arg(mailsmtpError(err)); | 220 | failuretext = tr("Error init SMTP connection: %1").arg(mailsmtpError(err)); |
221 | result = 0; | 221 | result = 0; |
222 | } | 222 | } |
223 | 223 | ||
224 | /* 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 */ |
225 | if (result) { | 225 | if (result) { |
226 | err = mailsmtp_init( m_smtp ); | 226 | err = mailsmtp_init( m_smtp ); |
227 | if (err != MAILSMTP_NO_ERROR) { | 227 | if (err != MAILSMTP_NO_ERROR) { |
228 | result = 0; | 228 | result = 0; |
229 | failuretext = tr("Error init SMTP connection: %1").arg(mailsmtpError(err)); | 229 | failuretext = tr("Error init SMTP connection: %1").arg(mailsmtpError(err)); |
230 | } | 230 | } |
231 | } | 231 | } |
232 | 232 | ||
233 | if (try_tls) { | 233 | if (try_tls) { |
234 | err = start_smtp_tls(); | 234 | err = start_smtp_tls(); |
235 | if (err != MAILSMTP_NO_ERROR) { | 235 | if (err != MAILSMTP_NO_ERROR) { |
236 | try_tls = false; | 236 | try_tls = false; |
237 | } else { | 237 | } else { |
238 | err = mailesmtp_ehlo(m_smtp); | 238 | err = mailesmtp_ehlo(m_smtp); |
239 | } | 239 | } |
240 | } | 240 | } |
241 | 241 | ||
242 | if (!try_tls && force_tls) { | 242 | if (!try_tls && force_tls) { |
243 | result = 0; | 243 | result = 0; |
244 | failuretext = tr("Error init SMTP tls: %1").arg(mailsmtpError(err)); | 244 | failuretext = tr("Error init SMTP tls: %1").arg(mailsmtpError(err)); |
245 | } | 245 | } |
246 | 246 | ||
247 | if (result==1 && m_SmtpAccount->getLogin() ) { | 247 | if (result==1 && m_SmtpAccount->getLogin() ) { |
248 | qDebug("smtp with auth"); | 248 | qDebug("smtp with auth"); |
249 | if ( m_SmtpAccount->getUser().isEmpty() || m_SmtpAccount->getPassword().isEmpty() ) { | 249 | if ( m_SmtpAccount->getUser().isEmpty() || m_SmtpAccount->getPassword().isEmpty() ) { |
250 | // get'em | 250 | // get'em |
251 | LoginDialog login( m_SmtpAccount->getUser(), | 251 | LoginDialog login( m_SmtpAccount->getUser(), |
252 | m_SmtpAccount->getPassword(), NULL, 0, true ); | 252 | m_SmtpAccount->getPassword(), NULL, 0, true ); |
253 | login.show(); | 253 | login.show(); |
254 | if ( QDialog::Accepted == login.exec() ) { | 254 | if ( QDialog::Accepted == login.exec() ) { |
255 | // ok | 255 | // ok |
256 | user = login.getUser().latin1(); | 256 | user = login.getUser().latin1(); |
257 | pass = login.getPassword().latin1(); | 257 | pass = login.getPassword().latin1(); |
258 | } else { | 258 | } else { |
259 | result = 0; | 259 | result = 0; |
260 | failuretext=tr("Login aborted - storing mail to localfolder"); | 260 | failuretext=tr("Login aborted - storing mail to localfolder"); |
261 | } | 261 | } |
262 | } else { | 262 | } else { |
263 | user = m_SmtpAccount->getUser().latin1(); | 263 | user = m_SmtpAccount->getUser().latin1(); |
264 | pass = m_SmtpAccount->getPassword().latin1(); | 264 | pass = m_SmtpAccount->getPassword().latin1(); |
265 | } | 265 | } |
266 | qDebug( "session->auth: %i", m_smtp->auth); | 266 | qDebug( "session->auth: %i", m_smtp->auth); |
267 | if (result) { | 267 | if (result) { |
268 | err = mailsmtp_auth( m_smtp, (char*)user, (char*)pass ); | 268 | err = mailsmtp_auth( m_smtp, (char*)user, (char*)pass ); |
269 | if ( err == MAILSMTP_NO_ERROR ) { | 269 | if ( err == MAILSMTP_NO_ERROR ) { |
270 | qDebug("auth ok"); | 270 | qDebug("auth ok"); |
271 | } else { | 271 | } else { |
272 | failuretext = tr("Authentification failed"); | 272 | failuretext = tr("Authentification failed"); |
273 | result = 0; | 273 | result = 0; |
274 | } | 274 | } |
275 | } | 275 | } |
276 | } | 276 | } |
277 | } | 277 | } |
278 | 278 | ||
279 | void SMTPwrapper::disc_server() | 279 | void SMTPwrapper::disc_server() |
280 | { | 280 | { |
281 | if (m_smtp) { | 281 | if (m_smtp) { |
282 | mailsmtp_quit( m_smtp ); | 282 | mailsmtp_quit( m_smtp ); |
283 | mailsmtp_free( m_smtp ); | 283 | mailsmtp_free( m_smtp ); |
284 | m_smtp = 0; | 284 | m_smtp = 0; |
285 | } | 285 | } |
286 | } | 286 | } |
287 | 287 | ||
288 | int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size ) | 288 | int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size ) |
289 | { | 289 | { |
290 | int err,result; | 290 | int err,result; |
291 | QString failuretext = ""; | 291 | QString failuretext = ""; |
292 | 292 | ||
293 | connect_server(); | 293 | connect_server(); |
294 | 294 | ||
295 | result = 1; | 295 | result = 1; |
296 | if (m_smtp) { | 296 | if (m_smtp) { |
297 | err = mailsmtp_send( m_smtp, from, rcpts, data, size ); | 297 | err = mailsmtp_send( m_smtp, from, rcpts, data, size ); |
298 | if ( err != MAILSMTP_NO_ERROR ) { | 298 | if ( err != MAILSMTP_NO_ERROR ) { |
299 | failuretext=tr("Error sending mail: %1").arg(mailsmtpError(err)); | 299 | failuretext=tr("Error sending mail: %1").arg(mailsmtpError(err)); |
300 | result = 0; | 300 | result = 0; |
301 | } | 301 | } |
302 | } else { | 302 | } else { |
303 | result = 0; | 303 | result = 0; |
304 | } | 304 | } |
305 | 305 | ||
306 | if (!result) { | 306 | if (!result) { |
307 | storeFailedMail(data,size,failuretext); | 307 | storeFailedMail(data,size,failuretext); |
308 | } else { | 308 | } else { |
309 | qDebug( "Mail sent." ); | 309 | qDebug( "Mail sent." ); |
310 | storeMail(data,size,"Sent"); | 310 | storeMail(data,size,"Sent"); |
311 | } | 311 | } |
312 | return result; | 312 | return result; |
313 | } | 313 | } |
314 | 314 | ||
315 | void SMTPwrapper::sendMail(const Mail&mail,bool later ) | 315 | void SMTPwrapper::sendMail(const Opie::osmart_pointer<Mail>&mail,bool later ) |
316 | { | 316 | { |
317 | mailmime * mimeMail; | 317 | mailmime * mimeMail; |
318 | 318 | ||
319 | mimeMail = createMimeMail(mail ); | 319 | mimeMail = createMimeMail(mail ); |
320 | if ( mimeMail == NULL ) { | 320 | if ( mimeMail == NULL ) { |
321 | qDebug( "sendMail: error creating mime mail" ); | 321 | qDebug( "sendMail: error creating mime mail" ); |
322 | } else { | 322 | } else { |
323 | sendProgress = new progressMailSend(); | 323 | sendProgress = new progressMailSend(); |
324 | sendProgress->show(); | 324 | sendProgress->show(); |
325 | sendProgress->setMaxMails(1); | 325 | sendProgress->setMaxMails(1); |
326 | smtpSend( mimeMail,later); | 326 | smtpSend( mimeMail,later); |
327 | qDebug("Clean up done"); | 327 | qDebug("Clean up done"); |
328 | sendProgress->hide(); | 328 | sendProgress->hide(); |
329 | delete sendProgress; | 329 | delete sendProgress; |
330 | sendProgress = 0; | 330 | sendProgress = 0; |
331 | mailmime_free( mimeMail ); | 331 | mailmime_free( mimeMail ); |
332 | } | 332 | } |
333 | } | 333 | } |
334 | 334 | ||
335 | int SMTPwrapper::sendQueuedMail(AbstractMail*wrap,RecMail*which) { | 335 | int SMTPwrapper::sendQueuedMail(AbstractMail*wrap,RecMail*which) { |
336 | size_t curTok = 0; | 336 | size_t curTok = 0; |
337 | mailimf_fields *fields = 0; | 337 | mailimf_fields *fields = 0; |
338 | mailimf_field*ffrom = 0; | 338 | mailimf_field*ffrom = 0; |
339 | clist *rcpts = 0; | 339 | clist *rcpts = 0; |
340 | char*from = 0; | 340 | char*from = 0; |
341 | int res = 0; | 341 | int res = 0; |
342 | 342 | ||
343 | encodedString * data = wrap->fetchRawBody(*which); | 343 | encodedString * data = wrap->fetchRawBody(*which); |
344 | if (!data) | 344 | if (!data) |
345 | return 0; | 345 | return 0; |
346 | int err = mailimf_fields_parse( data->Content(), data->Length(), &curTok, &fields ); | 346 | int err = mailimf_fields_parse( data->Content(), data->Length(), &curTok, &fields ); |
347 | if (err != MAILIMF_NO_ERROR) { | 347 | if (err != MAILIMF_NO_ERROR) { |
348 | delete data; | 348 | delete data; |
349 | delete wrap; | 349 | delete wrap; |
350 | return 0; | 350 | return 0; |
351 | } | 351 | } |
352 | 352 | ||
353 | rcpts = createRcptList( fields ); | 353 | rcpts = createRcptList( fields ); |
354 | ffrom = getField(fields, MAILIMF_FIELD_FROM ); | 354 | ffrom = getField(fields, MAILIMF_FIELD_FROM ); |
355 | from = getFrom(ffrom); | 355 | from = getFrom(ffrom); |
356 | 356 | ||
357 | if (rcpts && from) { | 357 | if (rcpts && from) { |
358 | res = smtpSend(from,rcpts,data->Content(),data->Length()); | 358 | res = smtpSend(from,rcpts,data->Content(),data->Length()); |
359 | } | 359 | } |
360 | if (fields) { | 360 | if (fields) { |
361 | mailimf_fields_free(fields); | 361 | mailimf_fields_free(fields); |
362 | fields = 0; | 362 | fields = 0; |
363 | } | 363 | } |
364 | if (data) { | 364 | if (data) { |
365 | delete data; | 365 | delete data; |
366 | } | 366 | } |
367 | if (from) { | 367 | if (from) { |
368 | free(from); | 368 | free(from); |
369 | } | 369 | } |
370 | if (rcpts) { | 370 | if (rcpts) { |
371 | smtp_address_list_free( rcpts ); | 371 | smtp_address_list_free( rcpts ); |
372 | } | 372 | } |
373 | return res; | 373 | return res; |
374 | } | 374 | } |
375 | 375 | ||
376 | /* this is a special fun */ | 376 | /* this is a special fun */ |
377 | bool SMTPwrapper::flushOutbox() { | 377 | bool SMTPwrapper::flushOutbox() { |
378 | bool returnValue = true; | 378 | bool returnValue = true; |
379 | 379 | ||
380 | qDebug("Sending the queue"); | 380 | qDebug("Sending the queue"); |
381 | if (!m_SmtpAccount) { | 381 | if (!m_SmtpAccount) { |
382 | qDebug("No smtp account given"); | 382 | qDebug("No smtp account given"); |
383 | return false; | 383 | return false; |
384 | } | 384 | } |
385 | 385 | ||
386 | bool reset_user_value = false; | 386 | bool reset_user_value = false; |
387 | QString localfolders = AbstractMail::defaultLocalfolder(); | 387 | QString localfolders = AbstractMail::defaultLocalfolder(); |
388 | AbstractMail*wrap = AbstractMail::getWrapper(localfolders); | 388 | AbstractMail*wrap = AbstractMail::getWrapper(localfolders); |
389 | if (!wrap) { | 389 | if (!wrap) { |
390 | qDebug("memory error"); | 390 | qDebug("memory error"); |
391 | return false; | 391 | return false; |
392 | } | 392 | } |
393 | QString oldPw, oldUser; | 393 | QString oldPw, oldUser; |
394 | QList<RecMail> mailsToSend; | 394 | QList<RecMail> mailsToSend; |
395 | QList<RecMail> mailsToRemove; | 395 | QList<RecMail> mailsToRemove; |
396 | QString mbox("Outgoing"); | 396 | QString mbox("Outgoing"); |
397 | wrap->listMessages(mbox,mailsToSend); | 397 | wrap->listMessages(mbox,mailsToSend); |
398 | if (mailsToSend.count()==0) { | 398 | if (mailsToSend.count()==0) { |
399 | delete wrap; | 399 | delete wrap; |
400 | qDebug("No mails to send"); | 400 | qDebug("No mails to send"); |
401 | return false; | 401 | return false; |
402 | } | 402 | } |
403 | 403 | ||
404 | oldPw = m_SmtpAccount->getPassword(); | 404 | oldPw = m_SmtpAccount->getPassword(); |
405 | oldUser = m_SmtpAccount->getUser(); | 405 | oldUser = m_SmtpAccount->getUser(); |
406 | if (m_SmtpAccount->getLogin() && (m_SmtpAccount->getUser().isEmpty() || m_SmtpAccount->getPassword().isEmpty()) ) { | 406 | if (m_SmtpAccount->getLogin() && (m_SmtpAccount->getUser().isEmpty() || m_SmtpAccount->getPassword().isEmpty()) ) { |
407 | // get'em | 407 | // get'em |
408 | QString user,pass; | 408 | QString user,pass; |
409 | LoginDialog login( m_SmtpAccount->getUser(), m_SmtpAccount->getPassword(), NULL, 0, true ); | 409 | LoginDialog login( m_SmtpAccount->getUser(), m_SmtpAccount->getPassword(), NULL, 0, true ); |
410 | login.show(); | 410 | login.show(); |
411 | if ( QDialog::Accepted == login.exec() ) { | 411 | if ( QDialog::Accepted == login.exec() ) { |
diff --git a/noncore/net/mail/libmailwrapper/smtpwrapper.h b/noncore/net/mail/libmailwrapper/smtpwrapper.h index 1796df7..08bde74 100644 --- a/noncore/net/mail/libmailwrapper/smtpwrapper.h +++ b/noncore/net/mail/libmailwrapper/smtpwrapper.h | |||
@@ -1,61 +1,63 @@ | |||
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 | #include "generatemail.h" |
13 | 13 | ||
14 | #include <opie2/osmart_pointer.h> | ||
15 | |||
14 | class SMTPaccount; | 16 | class SMTPaccount; |
15 | class AbstractMail; | 17 | class AbstractMail; |
16 | 18 | ||
17 | class SMTPwrapper : public Generatemail | 19 | class SMTPwrapper : public Generatemail |
18 | { | 20 | { |
19 | Q_OBJECT | 21 | Q_OBJECT |
20 | 22 | ||
21 | public: | 23 | public: |
22 | SMTPwrapper(SMTPaccount * aSmtp); | 24 | SMTPwrapper(SMTPaccount * aSmtp); |
23 | virtual ~SMTPwrapper(); | 25 | virtual ~SMTPwrapper(); |
24 | void sendMail(const Mail& mail,bool later=false ); | 26 | void sendMail(const Opie::osmart_pointer<Mail>& mail,bool later=false ); |
25 | bool flushOutbox(); | 27 | bool flushOutbox(); |
26 | 28 | ||
27 | static progressMailSend*sendProgress; | 29 | static progressMailSend*sendProgress; |
28 | 30 | ||
29 | signals: | 31 | signals: |
30 | void queuedMails( int ); | 32 | void queuedMails( int ); |
31 | 33 | ||
32 | protected: | 34 | protected: |
33 | mailsmtp *m_smtp; | 35 | mailsmtp *m_smtp; |
34 | SMTPaccount * m_SmtpAccount; | 36 | SMTPaccount * m_SmtpAccount; |
35 | 37 | ||
36 | void connect_server(); | 38 | void connect_server(); |
37 | void disc_server(); | 39 | void disc_server(); |
38 | int start_smtp_tls(); | 40 | int start_smtp_tls(); |
39 | 41 | ||
40 | 42 | ||
41 | void smtpSend( mailmime *mail,bool later); | 43 | void smtpSend( mailmime *mail,bool later); |
42 | 44 | ||
43 | static void storeMail(const char*mail, size_t length, const QString&box); | 45 | static void storeMail(const char*mail, size_t length, const QString&box); |
44 | static QString mailsmtpError( int err ); | 46 | static QString mailsmtpError( int err ); |
45 | static void progress( size_t current, size_t maximum ); | 47 | static void progress( size_t current, size_t maximum ); |
46 | 48 | ||
47 | int smtpSend(char*from,clist*rcpts,const char*data,size_t size); | 49 | int smtpSend(char*from,clist*rcpts,const char*data,size_t size); |
48 | 50 | ||
49 | void storeMail(mailmime*mail, const QString&box); | 51 | void storeMail(mailmime*mail, const QString&box); |
50 | 52 | ||
51 | int sendQueuedMail(AbstractMail*wrap,RecMail*which); | 53 | int sendQueuedMail(AbstractMail*wrap,RecMail*which); |
52 | void storeFailedMail(const char*data,unsigned int size, const char*failuremessage); | 54 | void storeFailedMail(const char*data,unsigned int size, const char*failuremessage); |
53 | 55 | ||
54 | int m_queuedMail; | 56 | int m_queuedMail; |
55 | 57 | ||
56 | protected slots: | 58 | protected slots: |
57 | void emitQCop( int queued ); | 59 | void emitQCop( int queued ); |
58 | 60 | ||
59 | }; | 61 | }; |
60 | 62 | ||
61 | #endif | 63 | #endif |
diff --git a/noncore/net/mail/libmailwrapper/storemail.cpp b/noncore/net/mail/libmailwrapper/storemail.cpp index 53101f8..052e0f1 100644 --- a/noncore/net/mail/libmailwrapper/storemail.cpp +++ b/noncore/net/mail/libmailwrapper/storemail.cpp | |||
@@ -1,90 +1,90 @@ | |||
1 | #include "storemail.h" | 1 | #include "storemail.h" |
2 | #include "mailwrapper.h" | 2 | #include "mailwrapper.h" |
3 | #include "settings.h" | 3 | #include "settings.h" |
4 | #include "abstractmail.h" | 4 | #include "abstractmail.h" |
5 | 5 | ||
6 | #include <libetpan/libetpan.h> | 6 | #include <libetpan/libetpan.h> |
7 | 7 | ||
8 | #include <qstring.h> | 8 | #include <qstring.h> |
9 | 9 | ||
10 | #include <stdlib.h> | 10 | #include <stdlib.h> |
11 | 11 | ||
12 | Storemail::Storemail(Account*aAccount,const QString&aFolder) | 12 | Storemail::Storemail(Account*aAccount,const QString&aFolder) |
13 | : Generatemail() | 13 | : Generatemail() |
14 | { | 14 | { |
15 | wrapper = 0; | 15 | wrapper = 0; |
16 | m_Account = aAccount; | 16 | m_Account = aAccount; |
17 | m_tfolder = aFolder; | 17 | m_tfolder = aFolder; |
18 | wrapper = AbstractMail::getWrapper(m_Account); | 18 | wrapper = AbstractMail::getWrapper(m_Account); |
19 | if (wrapper) { | 19 | if (wrapper) { |
20 | wrapper->createMbox(m_tfolder); | 20 | wrapper->createMbox(m_tfolder); |
21 | } | 21 | } |
22 | } | 22 | } |
23 | 23 | ||
24 | Storemail::Storemail(const QString&dir,const QString&aFolder) | 24 | Storemail::Storemail(const QString&dir,const QString&aFolder) |
25 | : Generatemail() | 25 | : Generatemail() |
26 | { | 26 | { |
27 | wrapper = 0; | 27 | wrapper = 0; |
28 | m_Account = 0; | 28 | m_Account = 0; |
29 | m_tfolder = aFolder; | 29 | m_tfolder = aFolder; |
30 | wrapper = AbstractMail::getWrapper(dir); | 30 | wrapper = AbstractMail::getWrapper(dir); |
31 | if (wrapper) { | 31 | if (wrapper) { |
32 | wrapper->createMbox(m_tfolder); | 32 | wrapper->createMbox(m_tfolder); |
33 | } | 33 | } |
34 | } | 34 | } |
35 | 35 | ||
36 | Storemail::Storemail(const QString&aFolder) | 36 | Storemail::Storemail(const QString&aFolder) |
37 | : Generatemail() | 37 | : Generatemail() |
38 | { | 38 | { |
39 | wrapper = 0; | 39 | wrapper = 0; |
40 | m_Account = 0; | 40 | m_Account = 0; |
41 | m_tfolder = aFolder; | 41 | m_tfolder = aFolder; |
42 | wrapper = AbstractMail::getWrapper(AbstractMail::defaultLocalfolder()); | 42 | wrapper = AbstractMail::getWrapper(AbstractMail::defaultLocalfolder()); |
43 | if (wrapper) { | 43 | if (wrapper) { |
44 | wrapper->createMbox(m_tfolder); | 44 | wrapper->createMbox(m_tfolder); |
45 | } | 45 | } |
46 | } | 46 | } |
47 | 47 | ||
48 | Storemail::~Storemail() | 48 | Storemail::~Storemail() |
49 | { | 49 | { |
50 | } | 50 | } |
51 | 51 | ||
52 | int Storemail::storeMail(const Mail&mail) | 52 | int Storemail::storeMail(const Opie::osmart_pointer<Mail>&mail) |
53 | { | 53 | { |
54 | if (!wrapper) return 0; | 54 | if (!wrapper) return 0; |
55 | int ret = 1; | 55 | int ret = 1; |
56 | 56 | ||
57 | mailmime * mimeMail = 0; | 57 | mailmime * mimeMail = 0; |
58 | mimeMail = createMimeMail(mail ); | 58 | mimeMail = createMimeMail(mail ); |
59 | if ( mimeMail == NULL ) { | 59 | if ( mimeMail == NULL ) { |
60 | qDebug( "storeMail: error creating mime mail" ); | 60 | qDebug( "storeMail: error creating mime mail" ); |
61 | return 0; | 61 | return 0; |
62 | } | 62 | } |
63 | char *data; | 63 | char *data; |
64 | size_t size; | 64 | size_t size; |
65 | data = 0; | 65 | data = 0; |
66 | 66 | ||
67 | mailmessage * msg = 0; | 67 | mailmessage * msg = 0; |
68 | msg = mime_message_init(mimeMail); | 68 | msg = mime_message_init(mimeMail); |
69 | mime_message_set_tmpdir(msg,getenv( "HOME" )); | 69 | mime_message_set_tmpdir(msg,getenv( "HOME" )); |
70 | int r = mailmessage_fetch(msg,&data,&size); | 70 | int r = mailmessage_fetch(msg,&data,&size); |
71 | mime_message_detach_mime(msg); | 71 | mime_message_detach_mime(msg); |
72 | mailmessage_free(msg); | 72 | mailmessage_free(msg); |
73 | msg = 0; | 73 | msg = 0; |
74 | if (r != MAIL_NO_ERROR || !data) { | 74 | if (r != MAIL_NO_ERROR || !data) { |
75 | qDebug("Error fetching mime..."); | 75 | qDebug("Error fetching mime..."); |
76 | ret = 0; | 76 | ret = 0; |
77 | } | 77 | } |
78 | 78 | ||
79 | if (ret) { | 79 | if (ret) { |
80 | wrapper->storeMessage(data,size,m_tfolder); | 80 | wrapper->storeMessage(data,size,m_tfolder); |
81 | } | 81 | } |
82 | 82 | ||
83 | if (data) { | 83 | if (data) { |
84 | free(data); | 84 | free(data); |
85 | } | 85 | } |
86 | if (mimeMail) { | 86 | if (mimeMail) { |
87 | mailmime_free( mimeMail ); | 87 | mailmime_free( mimeMail ); |
88 | } | 88 | } |
89 | return ret; | 89 | return ret; |
90 | } | 90 | } |
diff --git a/noncore/net/mail/libmailwrapper/storemail.h b/noncore/net/mail/libmailwrapper/storemail.h index 872c981..7d8ea3d 100644 --- a/noncore/net/mail/libmailwrapper/storemail.h +++ b/noncore/net/mail/libmailwrapper/storemail.h | |||
@@ -1,29 +1,29 @@ | |||
1 | #ifndef __STORE_MAIL_H | 1 | #ifndef __STORE_MAIL_H |
2 | #define __STORE_MAIL_H | 2 | #define __STORE_MAIL_H |
3 | 3 | ||
4 | #include <qpe/applnk.h> | 4 | #include <qpe/applnk.h> |
5 | 5 | ||
6 | #include "generatemail.h" | 6 | #include "generatemail.h" |
7 | 7 | ||
8 | class Account; | 8 | class Account; |
9 | class Mail; | 9 | class Mail; |
10 | class AbstractMail; | 10 | class AbstractMail; |
11 | 11 | ||
12 | class Storemail : public Generatemail | 12 | class Storemail : public Generatemail |
13 | { | 13 | { |
14 | Q_OBJECT | 14 | Q_OBJECT |
15 | public: | 15 | public: |
16 | Storemail(Account*aAccount,const QString&aFolder); | 16 | Storemail(Account*aAccount,const QString&aFolder); |
17 | Storemail(const QString&dir,const QString&aFolder); | 17 | Storemail(const QString&dir,const QString&aFolder); |
18 | Storemail(const QString&aFolder); | 18 | Storemail(const QString&aFolder); |
19 | virtual ~Storemail(); | 19 | virtual ~Storemail(); |
20 | 20 | ||
21 | int storeMail(const Mail&mail); | 21 | int storeMail(const Opie::osmart_pointer<Mail>&mail); |
22 | 22 | ||
23 | protected: | 23 | protected: |
24 | Account* m_Account; | 24 | Account* m_Account; |
25 | QString m_tfolder; | 25 | QString m_tfolder; |
26 | AbstractMail*wrapper; | 26 | AbstractMail*wrapper; |
27 | }; | 27 | }; |
28 | 28 | ||
29 | #endif | 29 | #endif |