summaryrefslogtreecommitdiff
path: root/noncore/net/mail/libmailwrapper/generatemail.cpp
Unidiff
Diffstat (limited to 'noncore/net/mail/libmailwrapper/generatemail.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/libmailwrapper/generatemail.cpp30
1 files changed, 15 insertions, 15 deletions
diff --git a/noncore/net/mail/libmailwrapper/generatemail.cpp b/noncore/net/mail/libmailwrapper/generatemail.cpp
index cb58d82..36ec232 100644
--- a/noncore/net/mail/libmailwrapper/generatemail.cpp
+++ b/noncore/net/mail/libmailwrapper/generatemail.cpp
@@ -76,71 +76,71 @@ mailimf_field *Generatemail::getField( mailimf_fields *fields, int type ) {
76 76
77mailimf_address_list *Generatemail::parseAddresses(const QString&addr ) { 77mailimf_address_list *Generatemail::parseAddresses(const QString&addr ) {
78 mailimf_address_list *addresses; 78 mailimf_address_list *addresses;
79 79
80 if ( addr.isEmpty() ) 80 if ( addr.isEmpty() )
81 return NULL; 81 return NULL;
82 82
83 addresses = mailimf_address_list_new_empty(); 83 addresses = mailimf_address_list_new_empty();
84 84
85 bool literal_open = false; 85 bool literal_open = false;
86 unsigned int startpos = 0; 86 unsigned int startpos = 0;
87 QStringList list; 87 QStringList list;
88 QString s; 88 QString s;
89 unsigned int i = 0; 89 unsigned int i = 0;
90 for (; i < addr.length();++i) { 90 for (; i < addr.length();++i) {
91 switch (addr[i]) { 91 switch (addr[i]) {
92 case '\"': 92 case '\"':
93 literal_open = !literal_open; 93 literal_open = !literal_open;
94 break; 94 break;
95 case ',': 95 case ',':
96 if (!literal_open) { 96 if (!literal_open) {
97 s = addr.mid(startpos,i-startpos); 97 s = addr.mid(startpos,i-startpos);
98 if (!s.isEmpty()) { 98 if (!s.isEmpty()) {
99 list.append(s); 99 list.append(s);
100 qDebug("Appended %s",s.latin1()); 100 odebug << "Appended " << s.latin1() << "" << oendl;
101 } 101 }
102 // !!!! this is a MUST BE! 102 // !!!! this is a MUST BE!
103 startpos = ++i; 103 startpos = ++i;
104 } 104 }
105 break; 105 break;
106 default: 106 default:
107 break; 107 break;
108 } 108 }
109 } 109 }
110 s = addr.mid(startpos,i-startpos); 110 s = addr.mid(startpos,i-startpos);
111 if (!s.isEmpty()) { 111 if (!s.isEmpty()) {
112 list.append(s); 112 list.append(s);
113 qDebug("Appended %s",s.latin1()); 113 odebug << "Appended " << s.latin1() << "" << oendl;
114 } 114 }
115 QStringList::Iterator it; 115 QStringList::Iterator it;
116 for ( it = list.begin(); it != list.end(); it++ ) { 116 for ( it = list.begin(); it != list.end(); it++ ) {
117 int err = mailimf_address_list_add_parse( addresses, (char*)(*it).latin1() ); 117 int err = mailimf_address_list_add_parse( addresses, (char*)(*it).latin1() );
118 if ( err != MAILIMF_NO_ERROR ) { 118 if ( err != MAILIMF_NO_ERROR ) {
119 qDebug( "Error parsing" ); 119 odebug << "Error parsing" << oendl;
120 qDebug( *it ); 120 odebug << *it << oendl;
121 } else { 121 } else {
122 qDebug( "Parse success! %s",(*it).latin1()); 122 odebug << "Parse success! " << (*it).latin1() << "" << oendl;
123 } 123 }
124 } 124 }
125 return addresses; 125 return addresses;
126} 126}
127 127
128mailmime *Generatemail::buildFilePart(const QString&filename,const QString&mimetype,const QString&TextContent ) { 128mailmime *Generatemail::buildFilePart(const QString&filename,const QString&mimetype,const QString&TextContent ) {
129 mailmime * filePart = 0; 129 mailmime * filePart = 0;
130 mailmime_fields * fields = 0; 130 mailmime_fields * fields = 0;
131 mailmime_content * content = 0; 131 mailmime_content * content = 0;
132 mailmime_parameter * param = 0; 132 mailmime_parameter * param = 0;
133 char*name = 0; 133 char*name = 0;
134 char*file = 0; 134 char*file = 0;
135 int err; 135 int err;
136 136
137 int pos = filename.findRev( '/' ); 137 int pos = filename.findRev( '/' );
138 138
139 if (filename.length()>0) { 139 if (filename.length()>0) {
140 QString tmp = filename.right( filename.length() - ( pos + 1 ) ); 140 QString tmp = filename.right( filename.length() - ( pos + 1 ) );
141 name = strdup( tmp.latin1() ); // just filename 141 name = strdup( tmp.latin1() ); // just filename
142 file = strdup( filename.latin1() ); // full name with path 142 file = strdup( filename.latin1() ); // full name with path
143 } 143 }
144 144
145 int disptype = MAILMIME_DISPOSITION_TYPE_ATTACHMENT; 145 int disptype = MAILMIME_DISPOSITION_TYPE_ATTACHMENT;
146 int mechanism = MAILMIME_MECHANISM_BASE64; 146 int mechanism = MAILMIME_MECHANISM_BASE64;
@@ -154,144 +154,144 @@ mailmime *Generatemail::buildFilePart(const QString&filename,const QString&mimet
154 fields = mailmime_fields_new_filename( 154 fields = mailmime_fields_new_filename(
155 disptype, name, 155 disptype, name,
156 mechanism ); 156 mechanism );
157 content = mailmime_content_new_with_str( (char*)mimetype.latin1() ); 157 content = mailmime_content_new_with_str( (char*)mimetype.latin1() );
158 if (content!=0 && fields != 0) { 158 if (content!=0 && fields != 0) {
159 if (param) { 159 if (param) {
160 clist_append(content->ct_parameters,param); 160 clist_append(content->ct_parameters,param);
161 param = 0; 161 param = 0;
162 } 162 }
163 if (filename.length()>0) { 163 if (filename.length()>0) {
164 QFileInfo f(filename); 164 QFileInfo f(filename);
165 param = mailmime_parameter_new(strdup("name"),strdup(f.fileName().latin1())); 165 param = mailmime_parameter_new(strdup("name"),strdup(f.fileName().latin1()));
166 clist_append(content->ct_parameters,param); 166 clist_append(content->ct_parameters,param);
167 param = 0; 167 param = 0;
168 } 168 }
169 filePart = mailmime_new_empty( content, fields ); 169 filePart = mailmime_new_empty( content, fields );
170 } 170 }
171 if (filePart) { 171 if (filePart) {
172 if (filename.length()>0) { 172 if (filename.length()>0) {
173 err = mailmime_set_body_file( filePart, file ); 173 err = mailmime_set_body_file( filePart, file );
174 } else { 174 } else {
175 err = mailmime_set_body_text(filePart,strdup(TextContent.data()),TextContent.length()); 175 err = mailmime_set_body_text(filePart,strdup(TextContent.data()),TextContent.length());
176 } 176 }
177 if (err != MAILIMF_NO_ERROR) { 177 if (err != MAILIMF_NO_ERROR) {
178 qDebug("Error setting body with file %s",file); 178 odebug << "Error setting body with file " << file << "" << oendl;
179 mailmime_free( filePart ); 179 mailmime_free( filePart );
180 filePart = 0; 180 filePart = 0;
181 } 181 }
182 } 182 }
183 183
184 if (!filePart) { 184 if (!filePart) {
185 if ( param != NULL ) { 185 if ( param != NULL ) {
186 mailmime_parameter_free( param ); 186 mailmime_parameter_free( param );
187 } 187 }
188 if (content) { 188 if (content) {
189 mailmime_content_free( content ); 189 mailmime_content_free( content );
190 } 190 }
191 if (fields) { 191 if (fields) {
192 mailmime_fields_free( fields ); 192 mailmime_fields_free( fields );
193 } else { 193 } else {
194 if (name) { 194 if (name) {
195 free( name ); 195 free( name );
196 } 196 }
197 if (file) { 197 if (file) {
198 free( file ); 198 free( file );
199 } 199 }
200 } 200 }
201 } 201 }
202 return filePart; // Success :) 202 return filePart; // Success :)
203 203
204} 204}
205 205
206void Generatemail::addFileParts( mailmime *message,const QList<Attachment>&files ) { 206void Generatemail::addFileParts( mailmime *message,const QList<Attachment>&files ) {
207 const Attachment *it; 207 const Attachment *it;
208 unsigned int count = files.count(); 208 unsigned int count = files.count();
209 qDebug("List contains %i values",count); 209 odebug << "List contains " << count << " values" << oendl;
210 for ( unsigned int i = 0; i < count; ++i ) { 210 for ( unsigned int i = 0; i < count; ++i ) {
211 qDebug( "Adding file" ); 211 odebug << "Adding file" << oendl;
212 mailmime *filePart; 212 mailmime *filePart;
213 int err; 213 int err;
214 it = ((QList<Attachment>)files).at(i); 214 it = ((QList<Attachment>)files).at(i);
215 215
216 filePart = buildFilePart( it->getFileName(), it->getMimeType(),"" ); 216 filePart = buildFilePart( it->getFileName(), it->getMimeType(),"" );
217 if ( filePart == NULL ) { 217 if ( filePart == NULL ) {
218 qDebug( "addFileParts: error adding file:" ); 218 odebug << "addFileParts: error adding file:" << oendl;
219 qDebug( it->getFileName() ); 219 odebug << it->getFileName() << oendl;
220 continue; 220 continue;
221 } 221 }
222 err = mailmime_smart_add_part( message, filePart ); 222 err = mailmime_smart_add_part( message, filePart );
223 if ( err != MAILIMF_NO_ERROR ) { 223 if ( err != MAILIMF_NO_ERROR ) {
224 mailmime_free( filePart ); 224 mailmime_free( filePart );
225 qDebug("error smart add"); 225 odebug << "error smart add" << oendl;
226 } 226 }
227 } 227 }
228} 228}
229 229
230mailmime *Generatemail::buildTxtPart(const QString&str ) { 230mailmime *Generatemail::buildTxtPart(const QString&str ) {
231 mailmime *txtPart; 231 mailmime *txtPart;
232 mailmime_fields *fields; 232 mailmime_fields *fields;
233 mailmime_content *content; 233 mailmime_content *content;
234 mailmime_parameter *param; 234 mailmime_parameter *param;
235 int err; 235 int err;
236 236
237 param = mailmime_parameter_new( strdup( "charset" ), 237 param = mailmime_parameter_new( strdup( "charset" ),
238 strdup( "iso-8859-1" ) ); 238 strdup( "iso-8859-1" ) );
239 if ( param == NULL ) 239 if ( param == NULL )
240 goto err_free; 240 goto err_free;
241 241
242 content = mailmime_content_new_with_str( "text/plain" ); 242 content = mailmime_content_new_with_str( "text/plain" );
243 if ( content == NULL ) 243 if ( content == NULL )
244 goto err_free_param; 244 goto err_free_param;
245 245
246 err = clist_append( content->ct_parameters, param ); 246 err = clist_append( content->ct_parameters, param );
247 if ( err != MAILIMF_NO_ERROR ) 247 if ( err != MAILIMF_NO_ERROR )
248 goto err_free_content; 248 goto err_free_content;
249 249
250 fields = mailmime_fields_new_encoding(MAILMIME_MECHANISM_8BIT); 250 fields = mailmime_fields_new_encoding(MAILMIME_MECHANISM_8BIT);
251 if ( fields == NULL ) 251 if ( fields == NULL )
252 goto err_free_content; 252 goto err_free_content;
253 253
254 txtPart = mailmime_new_empty( content, fields ); 254 txtPart = mailmime_new_empty( content, fields );
255 if ( txtPart == NULL ) 255 if ( txtPart == NULL )
256 goto err_free_fields; 256 goto err_free_fields;
257 257
258 err = mailmime_set_body_text( txtPart, (char*)str.data(), str.length() ); 258 err = mailmime_set_body_text( txtPart, (char*)str.data(), str.length() );
259 if ( err != MAILIMF_NO_ERROR ) 259 if ( err != MAILIMF_NO_ERROR )
260 goto err_free_txtPart; 260 goto err_free_txtPart;
261 261
262 return txtPart; // Success :) 262 return txtPart; // Success :)
263 263
264err_free_txtPart: 264err_free_txtPart:
265 mailmime_free( txtPart ); 265 mailmime_free( txtPart );
266err_free_fields: 266err_free_fields:
267 mailmime_fields_free( fields ); 267 mailmime_fields_free( fields );
268err_free_content: 268err_free_content:
269 mailmime_content_free( content ); 269 mailmime_content_free( content );
270err_free_param: 270err_free_param:
271 mailmime_parameter_free( param ); 271 mailmime_parameter_free( param );
272err_free: 272err_free:
273 qDebug( "buildTxtPart - error" ); 273 odebug << "buildTxtPart - error" << oendl;
274 274
275 return NULL; // Error :( 275 return NULL; // Error :(
276} 276}
277 277
278mailimf_mailbox *Generatemail::newMailbox(const QString&name, const QString&mail ) { 278mailimf_mailbox *Generatemail::newMailbox(const QString&name, const QString&mail ) {
279 return mailimf_mailbox_new( strdup( name.latin1() ), 279 return mailimf_mailbox_new( strdup( name.latin1() ),
280 strdup( mail.latin1() ) ); 280 strdup( mail.latin1() ) );
281} 281}
282 282
283mailimf_fields *Generatemail::createImfFields(const Opie::Core::OSmartPointer<Mail>&mail ) 283mailimf_fields *Generatemail::createImfFields(const Opie::Core::OSmartPointer<Mail>&mail )
284{ 284{
285 mailimf_fields *fields = NULL; 285 mailimf_fields *fields = NULL;
286 mailimf_field *xmailer = NULL; 286 mailimf_field *xmailer = NULL;
287 mailimf_mailbox *sender=0,*fromBox=0; 287 mailimf_mailbox *sender=0,*fromBox=0;
288 mailimf_mailbox_list *from=0; 288 mailimf_mailbox_list *from=0;
289 mailimf_address_list *to=0, *cc=0, *bcc=0, *reply=0; 289 mailimf_address_list *to=0, *cc=0, *bcc=0, *reply=0;
290 clist*in_reply_to = 0; 290 clist*in_reply_to = 0;
291 char *subject = strdup( mail->getSubject().latin1() ); 291 char *subject = strdup( mail->getSubject().latin1() );
292 int err; 292 int err;
293 int res = 1; 293 int res = 1;
294 294
295 sender = newMailbox( mail->getName(), mail->getMail() ); 295 sender = newMailbox( mail->getName(), mail->getMail() );
296 if ( sender == NULL ) { 296 if ( sender == NULL ) {
297 res = 0; 297 res = 0;
@@ -324,57 +324,57 @@ mailimf_fields *Generatemail::createImfFields(const Opie::Core::OSmartPointer<Ma
324 if (res) reply = parseAddresses( mail->getReply() ); 324 if (res) reply = parseAddresses( mail->getReply() );
325 325
326 if (res && mail->Inreply().count()>0) { 326 if (res && mail->Inreply().count()>0) {
327 in_reply_to = clist_new(); 327 in_reply_to = clist_new();
328 char*c_reply; 328 char*c_reply;
329 unsigned int nsize = 0; 329 unsigned int nsize = 0;
330 for (QStringList::ConstIterator it=mail->Inreply().begin(); 330 for (QStringList::ConstIterator it=mail->Inreply().begin();
331 it != mail->Inreply().end();++it) { 331 it != mail->Inreply().end();++it) {
332 if ((*it).isEmpty()) 332 if ((*it).isEmpty())
333 continue; 333 continue;
334 QString h((*it)); 334 QString h((*it));
335 while (h.length()>0 && h[0]=='<') { 335 while (h.length()>0 && h[0]=='<') {
336 h.remove(0,1); 336 h.remove(0,1);
337 } 337 }
338 while (h.length()>0 && h[h.length()-1]=='>') { 338 while (h.length()>0 && h[h.length()-1]=='>') {
339 h.remove(h.length()-1,1); 339 h.remove(h.length()-1,1);
340 } 340 }
341 if (h.isEmpty()) continue; 341 if (h.isEmpty()) continue;
342 nsize = strlen(h.latin1()); 342 nsize = strlen(h.latin1());
343 /* yes! must be malloc! */ 343 /* yes! must be malloc! */
344 c_reply = (char*)malloc( (nsize+1)*sizeof(char)); 344 c_reply = (char*)malloc( (nsize+1)*sizeof(char));
345 memset(c_reply,0,nsize+1); 345 memset(c_reply,0,nsize+1);
346 memcpy(c_reply,h.latin1(),nsize); 346 memcpy(c_reply,h.latin1(),nsize);
347 clist_append(in_reply_to,c_reply); 347 clist_append(in_reply_to,c_reply);
348 qDebug("In reply to: %s",c_reply); 348 odebug << "In reply to: " << c_reply << "" << oendl;
349 } 349 }
350 } 350 }
351 351
352 if (res) { 352 if (res) {
353 fields = mailimf_fields_new_with_data( from, sender, reply, to, cc, bcc, 353 fields = mailimf_fields_new_with_data( from, sender, reply, to, cc, bcc,
354 in_reply_to, NULL, subject ); 354 in_reply_to, NULL, subject );
355 if ( fields == NULL ) { 355 if ( fields == NULL ) {
356 qDebug("Error creating mailimf fields"); 356 odebug << "Error creating mailimf fields" << oendl;
357 res = 0; 357 res = 0;
358 } 358 }
359 } 359 }
360 if (res) xmailer = mailimf_field_new_custom( strdup( "User-Agent" ), 360 if (res) xmailer = mailimf_field_new_custom( strdup( "User-Agent" ),
361 strdup( USER_AGENT ) ); 361 strdup( USER_AGENT ) );
362 if ( xmailer == NULL ) { 362 if ( xmailer == NULL ) {
363 res = 0; 363 res = 0;
364 } else { 364 } else {
365 err = mailimf_fields_add( fields, xmailer ); 365 err = mailimf_fields_add( fields, xmailer );
366 if ( err != MAILIMF_NO_ERROR ) { 366 if ( err != MAILIMF_NO_ERROR ) {
367 res = 0; 367 res = 0;
368 } 368 }
369 } 369 }
370 if (!res ) { 370 if (!res ) {
371 if (xmailer) { 371 if (xmailer) {
372 mailimf_field_free( xmailer ); 372 mailimf_field_free( xmailer );
373 xmailer = NULL; 373 xmailer = NULL;
374 } 374 }
375 if (fields) { 375 if (fields) {
376 mailimf_fields_free( fields ); 376 mailimf_fields_free( fields );
377 fields = NULL; 377 fields = NULL;
378 } else { 378 } else {
379 if (reply) 379 if (reply)
380 mailimf_address_list_free( reply ); 380 mailimf_address_list_free( reply );
@@ -414,49 +414,49 @@ mailmime *Generatemail::createMimeMail(const Opie::Core::OSmartPointer<Mail> &ma
414 goto err_free_fields; 414 goto err_free_fields;
415 415
416 mailmime_set_imf_fields( message, fields ); 416 mailmime_set_imf_fields( message, fields );
417 417
418 txtPart = buildTxtPart( mail->getMessage() ); 418 txtPart = buildTxtPart( mail->getMessage() );
419 419
420 if ( txtPart == NULL ) 420 if ( txtPart == NULL )
421 goto err_free_message; 421 goto err_free_message;
422 422
423 err = mailmime_smart_add_part( message, txtPart ); 423 err = mailmime_smart_add_part( message, txtPart );
424 if ( err != MAILIMF_NO_ERROR ) 424 if ( err != MAILIMF_NO_ERROR )
425 goto err_free_txtPart; 425 goto err_free_txtPart;
426 426
427 addFileParts( message, mail->getAttachments() ); 427 addFileParts( message, mail->getAttachments() );
428 428
429 return message; // Success :) 429 return message; // Success :)
430 430
431err_free_txtPart: 431err_free_txtPart:
432 mailmime_free( txtPart ); 432 mailmime_free( txtPart );
433err_free_message: 433err_free_message:
434 mailmime_free( message ); 434 mailmime_free( message );
435err_free_fields: 435err_free_fields:
436 mailimf_fields_free( fields ); 436 mailimf_fields_free( fields );
437err_free: 437err_free:
438 qDebug( "createMimeMail: error" ); 438 odebug << "createMimeMail: error" << oendl;
439 439
440 return NULL; // Error :( 440 return NULL; // Error :(
441} 441}
442 442
443clist *Generatemail::createRcptList( mailimf_fields *fields ) { 443clist *Generatemail::createRcptList( mailimf_fields *fields ) {
444 clist *rcptList; 444 clist *rcptList;
445 mailimf_field *field; 445 mailimf_field *field;
446 446
447 rcptList = esmtp_address_list_new(); 447 rcptList = esmtp_address_list_new();
448 448
449 field = getField( fields, MAILIMF_FIELD_TO ); 449 field = getField( fields, MAILIMF_FIELD_TO );
450 if ( field && (field->fld_type == MAILIMF_FIELD_TO) 450 if ( field && (field->fld_type == MAILIMF_FIELD_TO)
451 && field->fld_data.fld_to->to_addr_list ) { 451 && field->fld_data.fld_to->to_addr_list ) {
452 addRcpts( rcptList, field->fld_data.fld_to->to_addr_list ); 452 addRcpts( rcptList, field->fld_data.fld_to->to_addr_list );
453 } 453 }
454 454
455 field = getField( fields, MAILIMF_FIELD_CC ); 455 field = getField( fields, MAILIMF_FIELD_CC );
456 if ( field && (field->fld_type == MAILIMF_FIELD_CC) 456 if ( field && (field->fld_type == MAILIMF_FIELD_CC)
457 && field->fld_data.fld_cc->cc_addr_list ) { 457 && field->fld_data.fld_cc->cc_addr_list ) {
458 addRcpts( rcptList, field->fld_data.fld_cc->cc_addr_list ); 458 addRcpts( rcptList, field->fld_data.fld_cc->cc_addr_list );
459 } 459 }
460 460
461 field = getField( fields, MAILIMF_FIELD_BCC ); 461 field = getField( fields, MAILIMF_FIELD_BCC );
462 if ( field && (field->fld_type == MAILIMF_FIELD_BCC) 462 if ( field && (field->fld_type == MAILIMF_FIELD_BCC)