summaryrefslogtreecommitdiff
authoralwin <alwin>2004-03-10 21:21:32 (UTC)
committer alwin <alwin>2004-03-10 21:21:32 (UTC)
commita72855867dedd2b4c16f703fa104b5c6175ce484 (patch) (unidiff)
treeef38ab8d70f15ce8921cf8c587e77b1b460dfe88
parentdd34b866c0f3e5041696dd97cf356d86a8d6d212 (diff)
downloadopie-a72855867dedd2b4c16f703fa104b5c6175ce484.zip
opie-a72855867dedd2b4c16f703fa104b5c6175ce484.tar.gz
opie-a72855867dedd2b4c16f703fa104b5c6175ce484.tar.bz2
fixed a problem with corrupted memory
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/libmailwrapper/generatemail.cpp143
1 files changed, 78 insertions, 65 deletions
diff --git a/noncore/net/mail/libmailwrapper/generatemail.cpp b/noncore/net/mail/libmailwrapper/generatemail.cpp
index 9272d0c..48fa02e 100644
--- a/noncore/net/mail/libmailwrapper/generatemail.cpp
+++ b/noncore/net/mail/libmailwrapper/generatemail.cpp
@@ -1,454 +1,467 @@
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
8const char* Generatemail::USER_AGENT="OpieMail v0.5"; 8const char* Generatemail::USER_AGENT="OpieMail v0.5";
9 9
10Generatemail::Generatemail() 10Generatemail::Generatemail()
11{ 11{
12} 12}
13 13
14Generatemail::~Generatemail() 14Generatemail::~Generatemail()
15{ 15{
16} 16}
17 17
18void Generatemail::addRcpts( clist *list, mailimf_address_list *addr_list ) { 18void 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
38char *Generatemail::getFrom( mailimf_field *ffrom) { 38char *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
53char *Generatemail::getFrom( mailmime *mail ) { 53char *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
60mailimf_field *Generatemail::getField( mailimf_fields *fields, int type ) { 60mailimf_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
76mailimf_address_list *Generatemail::parseAddresses(const QString&addr ) { 76mailimf_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;
105 default: 105 default:
106 break; 106 break;
107 } 107 }
108 } 108 }
109 s = addr.mid(startpos,i-startpos); 109 s = addr.mid(startpos,i-startpos);
110 if (!s.isEmpty()) { 110 if (!s.isEmpty()) {
111 list.append(s); 111 list.append(s);
112 qDebug("Appended %s",s.latin1()); 112 qDebug("Appended %s",s.latin1());
113 } 113 }
114 QStringList::Iterator it; 114 QStringList::Iterator it;
115 for ( it = list.begin(); it != list.end(); it++ ) { 115 for ( it = list.begin(); it != list.end(); it++ ) {
116 int err = mailimf_address_list_add_parse( addresses, (char*)(*it).latin1() ); 116 int err = mailimf_address_list_add_parse( addresses, (char*)(*it).latin1() );
117 if ( err != MAILIMF_NO_ERROR ) { 117 if ( err != MAILIMF_NO_ERROR ) {
118 qDebug( "Error parsing" ); 118 qDebug( "Error parsing" );
119 qDebug( *it ); 119 qDebug( *it );
120 } else { 120 } else {
121 qDebug( "Parse success! %s",(*it).latin1()); 121 qDebug( "Parse success! %s",(*it).latin1());
122 } 122 }
123 } 123 }
124 return addresses; 124 return addresses;
125} 125}
126 126
127mailmime *Generatemail::buildFilePart(const QString&filename,const QString&mimetype,const QString&TextContent ) { 127mailmime *Generatemail::buildFilePart(const QString&filename,const QString&mimetype,const QString&TextContent ) {
128 mailmime * filePart = 0; 128 mailmime * filePart = 0;
129 mailmime_fields * fields = 0; 129 mailmime_fields * fields = 0;
130 mailmime_content * content = 0; 130 mailmime_content * content = 0;
131 mailmime_parameter * param = 0; 131 mailmime_parameter * param = 0;
132 char*name = 0; 132 char*name = 0;
133 char*file = 0; 133 char*file = 0;
134 int err; 134 int err;
135 135
136 int pos = filename.findRev( '/' ); 136 int pos = filename.findRev( '/' );
137 137
138 if (filename.length()>0) { 138 if (filename.length()>0) {
139 QString tmp = filename.right( filename.length() - ( pos + 1 ) ); 139 QString tmp = filename.right( filename.length() - ( pos + 1 ) );
140 name = strdup( tmp.latin1() ); // just filename 140 name = strdup( tmp.latin1() ); // just filename
141 file = strdup( filename.latin1() ); // full name with path 141 file = strdup( filename.latin1() ); // full name with path
142 } 142 }
143 143
144 int disptype = MAILMIME_DISPOSITION_TYPE_ATTACHMENT; 144 int disptype = MAILMIME_DISPOSITION_TYPE_ATTACHMENT;
145 int mechanism = MAILMIME_MECHANISM_BASE64; 145 int mechanism = MAILMIME_MECHANISM_BASE64;
146 146
147 if ( mimetype.startsWith( "text/" ) ) { 147 if ( mimetype.startsWith( "text/" ) ) {
148 param = mailmime_parameter_new( strdup( "charset" ), 148 param = mailmime_parameter_new( strdup( "charset" ),
149 strdup( "iso-8859-1" ) ); 149 strdup( "iso-8859-1" ) );
150 mechanism = MAILMIME_MECHANISM_QUOTED_PRINTABLE; 150 mechanism = MAILMIME_MECHANISM_QUOTED_PRINTABLE;
151 } 151 }
152 152
153 fields = mailmime_fields_new_filename( 153 fields = mailmime_fields_new_filename(
154 disptype, name, 154 disptype, name,
155 mechanism ); 155 mechanism );
156 content = mailmime_content_new_with_str( (char*)mimetype.latin1() ); 156 content = mailmime_content_new_with_str( (char*)mimetype.latin1() );
157 if (content!=0 && fields != 0) { 157 if (content!=0 && fields != 0) {
158 if (param) { 158 if (param) {
159 clist_append(content->ct_parameters,param); 159 clist_append(content->ct_parameters,param);
160 param = 0; 160 param = 0;
161 } 161 }
162 if (filename.length()>0) { 162 if (filename.length()>0) {
163 QFileInfo f(filename); 163 QFileInfo f(filename);
164 param = mailmime_parameter_new(strdup("name"),strdup(f.fileName().latin1())); 164 param = mailmime_parameter_new(strdup("name"),strdup(f.fileName().latin1()));
165 clist_append(content->ct_parameters,param); 165 clist_append(content->ct_parameters,param);
166 param = 0; 166 param = 0;
167 } 167 }
168 filePart = mailmime_new_empty( content, fields ); 168 filePart = mailmime_new_empty( content, fields );
169 } 169 }
170 if (filePart) { 170 if (filePart) {
171 if (filename.length()>0) { 171 if (filename.length()>0) {
172 err = mailmime_set_body_file( filePart, file ); 172 err = mailmime_set_body_file( filePart, file );
173 } else { 173 } else {
174 err = mailmime_set_body_text(filePart,strdup(TextContent.data()),TextContent.length()); 174 err = mailmime_set_body_text(filePart,strdup(TextContent.data()),TextContent.length());
175 } 175 }
176 if (err != MAILIMF_NO_ERROR) { 176 if (err != MAILIMF_NO_ERROR) {
177 qDebug("Error setting body with file %s",file); 177 qDebug("Error setting body with file %s",file);
178 mailmime_free( filePart ); 178 mailmime_free( filePart );
179 filePart = 0; 179 filePart = 0;
180 } 180 }
181 } 181 }
182 182
183 if (!filePart) { 183 if (!filePart) {
184 if ( param != NULL ) { 184 if ( param != NULL ) {
185 mailmime_parameter_free( param ); 185 mailmime_parameter_free( param );
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
205void Generatemail::addFileParts( mailmime *message,const QList<Attachment>&files ) { 205void 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
229mailmime *Generatemail::buildTxtPart(const QString&str ) { 229mailmime *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
263err_free_txtPart: 263err_free_txtPart:
264 mailmime_free( txtPart ); 264 mailmime_free( txtPart );
265err_free_fields: 265err_free_fields:
266 mailmime_fields_free( fields ); 266 mailmime_fields_free( fields );
267err_free_content: 267err_free_content:
268 mailmime_content_free( content ); 268 mailmime_content_free( content );
269err_free_param: 269err_free_param:
270 mailmime_parameter_free( param ); 270 mailmime_parameter_free( param );
271err_free: 271err_free:
272 qDebug( "buildTxtPart - error" ); 272 qDebug( "buildTxtPart - error" );
273 273
274 return NULL; // Error :( 274 return NULL; // Error :(
275} 275}
276 276
277mailimf_mailbox *Generatemail::newMailbox(const QString&name, const QString&mail ) { 277mailimf_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
282mailimf_fields *Generatemail::createImfFields(const Mail&mail ) { 282mailimf_fields *Generatemail::createImfFields(const Mail&mail )
283 mailimf_fields *fields; 283{
284 mailimf_field *xmailer; 284 mailimf_fields *fields = NULL;
285 mailimf_field *xmailer = NULL;
285 mailimf_mailbox *sender=0,*fromBox=0; 286 mailimf_mailbox *sender=0,*fromBox=0;
286 mailimf_mailbox_list *from=0; 287 mailimf_mailbox_list *from=0;
287 mailimf_address_list *to=0, *cc=0, *bcc=0, *reply=0; 288 mailimf_address_list *to=0, *cc=0, *bcc=0, *reply=0;
288 clist*in_reply_to = 0; 289 clist*in_reply_to = 0;
289 char *subject = strdup( mail.getSubject().latin1() ); 290 char *subject = strdup( mail.getSubject().latin1() );
290 int err; 291 int err;
292 int res = 1;
291 293
292 sender = newMailbox( mail.getName(), mail.getMail() ); 294 sender = newMailbox( mail.getName(), mail.getMail() );
293 if ( sender == NULL ) 295 if ( sender == NULL ) {
294 goto err_free; 296 res = 0;
295 297 }
296 fromBox = newMailbox( mail.getName(), mail.getMail() );
297 if ( fromBox == NULL )
298 goto err_free_sender;
299 298
300 from = mailimf_mailbox_list_new_empty(); 299 if (res) {
301 if ( from == NULL ) 300 fromBox = newMailbox( mail.getName(), mail.getMail() );
302 goto err_free_fromBox; 301 }
302 if ( fromBox == NULL ) {
303 res = 0;
304 }
303 305
304 err = mailimf_mailbox_list_add( from, fromBox ); 306 if (res) {
305 if ( err != MAILIMF_NO_ERROR ) 307 from = mailimf_mailbox_list_new_empty();
306 goto err_free_from; 308 }
309 if ( from == NULL ) {
310 res = 0;
311 }
307 312
308 to = parseAddresses( mail.getTo() ); 313 if (res && from) {
309 if ( to == NULL ) 314 err = mailimf_mailbox_list_add( from, fromBox );
310 goto err_free_from; 315 if ( err != MAILIMF_NO_ERROR ) {
316 res = 0;
317 }
318 }
311 319
312 cc = parseAddresses( mail.getCC() ); 320 if (res) to = parseAddresses( mail.getTo() );
313 bcc = parseAddresses( mail.getBCC() ); 321 if (res) cc = parseAddresses( mail.getCC() );
314 reply = parseAddresses( mail.getReply() ); 322 if (res) bcc = parseAddresses( mail.getBCC() );
323 if (res) reply = parseAddresses( mail.getReply() );
315 324
316 if (mail.Inreply().count()>0) { 325 if (res && mail.Inreply().count()>0) {
317 in_reply_to = clist_new(); 326 in_reply_to = clist_new();
318 char*c_reply; 327 char*c_reply;
319 unsigned int nsize = 0; 328 unsigned int nsize = 0;
320 for (QStringList::ConstIterator it=mail.Inreply().begin(); 329 for (QStringList::ConstIterator it=mail.Inreply().begin();
321 it != mail.Inreply().end();++it) { 330 it != mail.Inreply().end();++it) {
322 if ((*it).isEmpty()) 331 if ((*it).isEmpty())
323 continue; 332 continue;
324 QString h((*it)); 333 QString h((*it));
325 while (h.length()>0 && h[0]=='<') { 334 while (h.length()>0 && h[0]=='<') {
326 h.remove(0,1); 335 h.remove(0,1);
327 } 336 }
328 while (h.length()>0 && h[h.length()-1]=='>') { 337 while (h.length()>0 && h[h.length()-1]=='>') {
329 h.remove(h.length()-1,1); 338 h.remove(h.length()-1,1);
330 } 339 }
331 if (h.isEmpty()) continue; 340 if (h.isEmpty()) continue;
332 nsize = strlen(h.latin1()); 341 nsize = strlen(h.latin1());
333 /* yes! must be malloc! */ 342 /* yes! must be malloc! */
334 c_reply = (char*)malloc( (nsize+1)*sizeof(char)); 343 c_reply = (char*)malloc( (nsize+1)*sizeof(char));
335 memset(c_reply,0,nsize+1); 344 memset(c_reply,0,nsize+1);
336 memcpy(c_reply,h.latin1(),nsize); 345 memcpy(c_reply,h.latin1(),nsize);
337 clist_append(in_reply_to,c_reply); 346 clist_append(in_reply_to,c_reply);
338 qDebug("In reply to: %s",c_reply); 347 qDebug("In reply to: %s",c_reply);
339 } 348 }
340 } 349 }
341 350
342 fields = mailimf_fields_new_with_data( from, sender, reply, to, cc, bcc, 351 if (res) {
352 fields = mailimf_fields_new_with_data( from, sender, reply, to, cc, bcc,
343 in_reply_to, NULL, subject ); 353 in_reply_to, NULL, subject );
344 if ( fields == NULL ) 354 if ( fields == NULL ) {
345 goto err_free_reply; 355 qDebug("Error creating mailimf fields");
346 356 res = 0;
347 xmailer = mailimf_field_new_custom( strdup( "User-Agent" ), 357 }
358 }
359 if (res) xmailer = mailimf_field_new_custom( strdup( "User-Agent" ),
348 strdup( USER_AGENT ) ); 360 strdup( USER_AGENT ) );
349 if ( xmailer == NULL ) 361 if ( xmailer == NULL ) {
350 goto err_free_fields; 362 res = 0;
351 363 } else {
352 err = mailimf_fields_add( fields, xmailer ); 364 err = mailimf_fields_add( fields, xmailer );
353 if ( err != MAILIMF_NO_ERROR ) 365 if ( err != MAILIMF_NO_ERROR ) {
354 goto err_free_xmailer; 366 res = 0;
355 367 }
356 return fields; // Success :) 368 }
357 369 if (!res ) {
358err_free_xmailer: 370 if (xmailer) {
359 if (xmailer) 371 mailimf_field_free( xmailer );
360 mailimf_field_free( xmailer ); 372 xmailer = NULL;
361err_free_fields: 373 }
362 if (fields) 374 if (fields) {
363 mailimf_fields_free( fields ); 375 mailimf_fields_free( fields );
364err_free_reply: 376 fields = NULL;
365 if (reply) 377 } else {
366 mailimf_address_list_free( reply ); 378 if (reply)
367 if (bcc) 379 mailimf_address_list_free( reply );
368 mailimf_address_list_free( bcc ); 380 if (bcc)
369 if (cc) 381 mailimf_address_list_free( bcc );
370 mailimf_address_list_free( cc ); 382 if (cc)
371 if (to) 383 mailimf_address_list_free( cc );
372 mailimf_address_list_free( to ); 384 if (to)
373err_free_from: 385 mailimf_address_list_free( to );
374 if (from) 386 if (fromBox) {
375 mailimf_mailbox_list_free( from ); 387 mailimf_mailbox_free( fromBox );
376err_free_fromBox: 388 } else if (from) {
377 mailimf_mailbox_free( fromBox ); 389 mailimf_mailbox_list_free( from );
378err_free_sender: 390 }
379 if (sender) 391 if (sender) {
380 mailimf_mailbox_free( sender ); 392 mailimf_mailbox_free( sender );
381err_free: 393 }
382 if (subject) 394 if (subject) {
383 free( subject ); 395 free( subject );
384 qDebug( "createImfFields - error" ); 396 }
385 397 }
386 return NULL; // Error :( 398 }
399 return fields;
387} 400}
388 401
389mailmime *Generatemail::createMimeMail(const Mail &mail ) { 402mailmime *Generatemail::createMimeMail(const Mail &mail ) {
390 mailmime *message, *txtPart; 403 mailmime *message, *txtPart;
391 mailimf_fields *fields; 404 mailimf_fields *fields;
392 int err; 405 int err;
393 406
394 fields = createImfFields( mail ); 407 fields = createImfFields( mail );
395 if ( fields == NULL ) 408 if ( fields == NULL )
396 goto err_free; 409 goto err_free;
397 410
398 message = mailmime_new_message_data( NULL ); 411 message = mailmime_new_message_data( NULL );
399 if ( message == NULL ) 412 if ( message == NULL )
400 goto err_free_fields; 413 goto err_free_fields;
401 414
402 mailmime_set_imf_fields( message, fields ); 415 mailmime_set_imf_fields( message, fields );
403 416
404 txtPart = buildTxtPart( mail.getMessage() ); 417 txtPart = buildTxtPart( mail.getMessage() );
405 418
406 if ( txtPart == NULL ) 419 if ( txtPart == NULL )
407 goto err_free_message; 420 goto err_free_message;
408 421
409 err = mailmime_smart_add_part( message, txtPart ); 422 err = mailmime_smart_add_part( message, txtPart );
410 if ( err != MAILIMF_NO_ERROR ) 423 if ( err != MAILIMF_NO_ERROR )
411 goto err_free_txtPart; 424 goto err_free_txtPart;
412 425
413 addFileParts( message, mail.getAttachments() ); 426 addFileParts( message, mail.getAttachments() );
414 427
415 return message; // Success :) 428 return message; // Success :)
416 429
417err_free_txtPart: 430err_free_txtPart:
418 mailmime_free( txtPart ); 431 mailmime_free( txtPart );
419err_free_message: 432err_free_message:
420 mailmime_free( message ); 433 mailmime_free( message );
421err_free_fields: 434err_free_fields:
422 mailimf_fields_free( fields ); 435 mailimf_fields_free( fields );
423err_free: 436err_free:
424 qDebug( "createMimeMail: error" ); 437 qDebug( "createMimeMail: error" );
425 438
426 return NULL; // Error :( 439 return NULL; // Error :(
427} 440}
428 441
429clist *Generatemail::createRcptList( mailimf_fields *fields ) { 442clist *Generatemail::createRcptList( mailimf_fields *fields ) {
430 clist *rcptList; 443 clist *rcptList;
431 mailimf_field *field; 444 mailimf_field *field;
432 445
433 rcptList = esmtp_address_list_new(); 446 rcptList = esmtp_address_list_new();
434 447
435 field = getField( fields, MAILIMF_FIELD_TO ); 448 field = getField( fields, MAILIMF_FIELD_TO );
436 if ( field && (field->fld_type == MAILIMF_FIELD_TO) 449 if ( field && (field->fld_type == MAILIMF_FIELD_TO)
437 && field->fld_data.fld_to->to_addr_list ) { 450 && field->fld_data.fld_to->to_addr_list ) {
438 addRcpts( rcptList, field->fld_data.fld_to->to_addr_list ); 451 addRcpts( rcptList, field->fld_data.fld_to->to_addr_list );
439 } 452 }
440 453
441 field = getField( fields, MAILIMF_FIELD_CC ); 454 field = getField( fields, MAILIMF_FIELD_CC );
442 if ( field && (field->fld_type == MAILIMF_FIELD_CC) 455 if ( field && (field->fld_type == MAILIMF_FIELD_CC)
443 && field->fld_data.fld_cc->cc_addr_list ) { 456 && field->fld_data.fld_cc->cc_addr_list ) {
444 addRcpts( rcptList, field->fld_data.fld_cc->cc_addr_list ); 457 addRcpts( rcptList, field->fld_data.fld_cc->cc_addr_list );
445 } 458 }
446 459
447 field = getField( fields, MAILIMF_FIELD_BCC ); 460 field = getField( fields, MAILIMF_FIELD_BCC );
448 if ( field && (field->fld_type == MAILIMF_FIELD_BCC) 461 if ( field && (field->fld_type == MAILIMF_FIELD_BCC)
449 && field->fld_data.fld_bcc->bcc_addr_list ) { 462 && field->fld_data.fld_bcc->bcc_addr_list ) {
450 addRcpts( rcptList, field->fld_data.fld_bcc->bcc_addr_list ); 463 addRcpts( rcptList, field->fld_data.fld_bcc->bcc_addr_list );
451 } 464 }
452 465
453 return rcptList; 466 return rcptList;
454} 467}