author | Michael Krelin <hacker@klever.net> | 2007-07-04 11:23:42 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2007-07-04 11:23:42 (UTC) |
commit | a08aff328d4393031d5ba7d622c2b05705a89d73 (patch) (unidiff) | |
tree | 8ee90d686081c52e7c69b5ce946e9b1a7d690001 /kmicromail/libmailwrapper/generatemail.cpp | |
parent | 11edc920afe4f274c0964436633aa632c8288a40 (diff) | |
download | kdepimpi-p1.zip kdepimpi-p1.tar.gz kdepimpi-p1.tar.bz2 |
initial public commit of qt4 portp1
Diffstat (limited to 'kmicromail/libmailwrapper/generatemail.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | kmicromail/libmailwrapper/generatemail.cpp | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/kmicromail/libmailwrapper/generatemail.cpp b/kmicromail/libmailwrapper/generatemail.cpp index 2d213fe..ddad21b 100644 --- a/kmicromail/libmailwrapper/generatemail.cpp +++ b/kmicromail/libmailwrapper/generatemail.cpp | |||
@@ -1,447 +1,449 @@ | |||
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 | #include <stdlib.h> | 8 | #include <stdlib.h> |
9 | #include <qfileinfo.h> | 9 | #include <qfileinfo.h> |
10 | //Added by qt3to4: | ||
11 | #include <Q3CString> | ||
10 | 12 | ||
11 | using namespace Opie::Core; | 13 | using namespace Opie::Core; |
12 | const char* Generatemail::USER_AGENT="KOpieMail 33 1/3"; | 14 | const char* Generatemail::USER_AGENT="KOpieMail 33 1/3"; |
13 | 15 | ||
14 | Generatemail::Generatemail() | 16 | Generatemail::Generatemail() |
15 | { | 17 | { |
16 | mCharset = "iso-8859-1"; | 18 | mCharset = "iso-8859-1"; |
17 | } | 19 | } |
18 | 20 | ||
19 | Generatemail::~Generatemail() | 21 | Generatemail::~Generatemail() |
20 | { | 22 | { |
21 | } | 23 | } |
22 | 24 | ||
23 | void Generatemail::addRcpts( clist *list, mailimf_address_list *addr_list ) { | 25 | void Generatemail::addRcpts( clist *list, mailimf_address_list *addr_list ) { |
24 | clistiter *it, *it2; | 26 | clistiter *it, *it2; |
25 | 27 | ||
26 | for ( it = clist_begin( addr_list->ad_list ); it; it = it->next ) { | 28 | for ( it = clist_begin( addr_list->ad_list ); it; it = it->next ) { |
27 | mailimf_address *addr; | 29 | mailimf_address *addr; |
28 | addr = (mailimf_address *) it->data; | 30 | addr = (mailimf_address *) it->data; |
29 | 31 | ||
30 | if ( addr->ad_type == MAILIMF_ADDRESS_MAILBOX ) { | 32 | if ( addr->ad_type == MAILIMF_ADDRESS_MAILBOX ) { |
31 | esmtp_address_list_add( list, addr->ad_data.ad_mailbox->mb_addr_spec, 0, NULL ); | 33 | esmtp_address_list_add( list, addr->ad_data.ad_mailbox->mb_addr_spec, 0, NULL ); |
32 | } else if ( addr->ad_type == MAILIMF_ADDRESS_GROUP ) { | 34 | } else if ( addr->ad_type == MAILIMF_ADDRESS_GROUP ) { |
33 | clist *l = addr->ad_data.ad_group->grp_mb_list->mb_list; | 35 | clist *l = addr->ad_data.ad_group->grp_mb_list->mb_list; |
34 | for ( it2 = clist_begin( l ); it2; it2 = it2->next ) { | 36 | for ( it2 = clist_begin( l ); it2; it2 = it2->next ) { |
35 | mailimf_mailbox *mbox; | 37 | mailimf_mailbox *mbox; |
36 | mbox = (mailimf_mailbox *) it2->data; | 38 | mbox = (mailimf_mailbox *) it2->data; |
37 | esmtp_address_list_add( list, mbox->mb_addr_spec, 0, NULL ); | 39 | esmtp_address_list_add( list, mbox->mb_addr_spec, 0, NULL ); |
38 | } | 40 | } |
39 | } | 41 | } |
40 | } | 42 | } |
41 | } | 43 | } |
42 | 44 | ||
43 | char *Generatemail::getFrom( mailimf_field *ffrom) { | 45 | char *Generatemail::getFrom( mailimf_field *ffrom) { |
44 | char *from = NULL; | 46 | char *from = NULL; |
45 | if ( ffrom && (ffrom->fld_type == MAILIMF_FIELD_FROM) | 47 | if ( ffrom && (ffrom->fld_type == MAILIMF_FIELD_FROM) |
46 | && ffrom->fld_data.fld_from->frm_mb_list && ffrom->fld_data.fld_from->frm_mb_list->mb_list ) { | 48 | && ffrom->fld_data.fld_from->frm_mb_list && ffrom->fld_data.fld_from->frm_mb_list->mb_list ) { |
47 | clist *cl = ffrom->fld_data.fld_from->frm_mb_list->mb_list; | 49 | clist *cl = ffrom->fld_data.fld_from->frm_mb_list->mb_list; |
48 | clistiter *it; | 50 | clistiter *it; |
49 | for ( it = clist_begin( cl ); it; it = it->next ) { | 51 | for ( it = clist_begin( cl ); it; it = it->next ) { |
50 | mailimf_mailbox *mb = (mailimf_mailbox *) it->data; | 52 | mailimf_mailbox *mb = (mailimf_mailbox *) it->data; |
51 | from = strdup( mb->mb_addr_spec ); | 53 | from = strdup( mb->mb_addr_spec ); |
52 | } | 54 | } |
53 | } | 55 | } |
54 | 56 | ||
55 | return from; | 57 | return from; |
56 | } | 58 | } |
57 | 59 | ||
58 | char *Generatemail::getFrom( mailmime *mail ) { | 60 | char *Generatemail::getFrom( mailmime *mail ) { |
59 | /* no need to delete - its just a pointer to structure content */ | 61 | /* no need to delete - its just a pointer to structure content */ |
60 | mailimf_field *ffrom = 0; | 62 | mailimf_field *ffrom = 0; |
61 | ffrom = getField( mail->mm_data.mm_message.mm_fields, MAILIMF_FIELD_FROM ); | 63 | ffrom = getField( mail->mm_data.mm_message.mm_fields, MAILIMF_FIELD_FROM ); |
62 | return getFrom(ffrom); | 64 | return getFrom(ffrom); |
63 | } | 65 | } |
64 | 66 | ||
65 | mailimf_field *Generatemail::getField( mailimf_fields *fields, int type ) { | 67 | mailimf_field *Generatemail::getField( mailimf_fields *fields, int type ) { |
66 | mailimf_field *field; | 68 | mailimf_field *field; |
67 | clistiter *it; | 69 | clistiter *it; |
68 | 70 | ||
69 | it = clist_begin( fields->fld_list ); | 71 | it = clist_begin( fields->fld_list ); |
70 | while ( it ) { | 72 | while ( it ) { |
71 | field = (mailimf_field *) it->data; | 73 | field = (mailimf_field *) it->data; |
72 | if ( field->fld_type == type ) { | 74 | if ( field->fld_type == type ) { |
73 | return field; | 75 | return field; |
74 | } | 76 | } |
75 | it = it->next; | 77 | it = it->next; |
76 | } | 78 | } |
77 | 79 | ||
78 | return NULL; | 80 | return NULL; |
79 | } | 81 | } |
80 | 82 | ||
81 | mailimf_address_list *Generatemail::parseAddresses(const QString&addr ) { | 83 | mailimf_address_list *Generatemail::parseAddresses(const QString&addr ) { |
82 | mailimf_address_list *addresses; | 84 | mailimf_address_list *addresses; |
83 | 85 | ||
84 | if ( addr.isEmpty() ) | 86 | if ( addr.isEmpty() ) |
85 | return NULL; | 87 | return NULL; |
86 | 88 | ||
87 | addresses = mailimf_address_list_new_empty(); | 89 | addresses = mailimf_address_list_new_empty(); |
88 | 90 | ||
89 | bool literal_open = false; | 91 | bool literal_open = false; |
90 | unsigned int startpos = 0; | 92 | unsigned int startpos = 0; |
91 | QStringList list; | 93 | QStringList list; |
92 | QString s; | 94 | QString s; |
93 | unsigned int i = 0; | 95 | unsigned int i = 0; |
94 | for (; i < addr.length();++i) { | 96 | for (; i < addr.length();++i) { |
95 | switch (addr[i]) { | 97 | switch (addr[i]) { |
96 | case '\"': | 98 | case '\"': |
97 | literal_open = !literal_open; | 99 | literal_open = !literal_open; |
98 | break; | 100 | break; |
99 | case ',': | 101 | case ',': |
100 | if (!literal_open) { | 102 | if (!literal_open) { |
101 | s = addr.mid(startpos,i-startpos); | 103 | s = addr.mid(startpos,i-startpos); |
102 | if (!s.isEmpty()) { | 104 | if (!s.isEmpty()) { |
103 | list.append(s); | 105 | list.append(s); |
104 | } | 106 | } |
105 | // !!!! this is a MUST BE! | 107 | // !!!! this is a MUST BE! |
106 | startpos = ++i; | 108 | startpos = ++i; |
107 | } | 109 | } |
108 | break; | 110 | break; |
109 | default: | 111 | default: |
110 | break; | 112 | break; |
111 | } | 113 | } |
112 | } | 114 | } |
113 | s = addr.mid(startpos,i-startpos); | 115 | s = addr.mid(startpos,i-startpos); |
114 | if (!s.isEmpty()) { | 116 | if (!s.isEmpty()) { |
115 | list.append(s); | 117 | list.append(s); |
116 | } | 118 | } |
117 | QStringList::Iterator it; | 119 | QStringList::Iterator it; |
118 | for ( it = list.begin(); it != list.end(); it++ ) { | 120 | for ( it = list.begin(); it != list.end(); it++ ) { |
119 | int err = mailimf_address_list_add_parse( addresses, (char*)(*it).latin1() ); | 121 | int err = mailimf_address_list_add_parse( addresses, (char*)(*it).latin1() ); |
120 | if ( err != MAILIMF_NO_ERROR ) { | 122 | if ( err != MAILIMF_NO_ERROR ) { |
121 | qDebug(" Error parsing"); // *it | 123 | qDebug(" Error parsing"); // *it |
122 | } else { | 124 | } else { |
123 | } | 125 | } |
124 | } | 126 | } |
125 | return addresses; | 127 | return addresses; |
126 | } | 128 | } |
127 | 129 | ||
128 | mailmime *Generatemail::buildFilePart(const QString&filename,const QString&mimetype,const QString&TextContent ) { | 130 | mailmime *Generatemail::buildFilePart(const QString&filename,const QString&mimetype,const QString&TextContent ) { |
129 | mailmime * filePart = 0; | 131 | mailmime * filePart = 0; |
130 | mailmime_fields * fields = 0; | 132 | mailmime_fields * fields = 0; |
131 | mailmime_content * content = 0; | 133 | mailmime_content * content = 0; |
132 | mailmime_parameter * param = 0; | 134 | mailmime_parameter * param = 0; |
133 | char*name = 0; | 135 | char*name = 0; |
134 | char*file = 0; | 136 | char*file = 0; |
135 | int err; | 137 | int err; |
136 | int pos = filename.findRev( '/' ); | 138 | int pos = filename.findRev( '/' ); |
137 | 139 | ||
138 | if (filename.length()>0) { | 140 | if (filename.length()>0) { |
139 | QString tmp = filename.right( filename.length() - ( pos + 1 ) ); | 141 | QString tmp = filename.right( filename.length() - ( pos + 1 ) ); |
140 | name = strdup( tmp.latin1() ); // just filename | 142 | name = strdup( tmp.latin1() ); // just filename |
141 | file = strdup( filename.latin1() ); // full name with path | 143 | file = strdup( filename.latin1() ); // full name with path |
142 | } | 144 | } |
143 | 145 | ||
144 | int disptype = MAILMIME_DISPOSITION_TYPE_ATTACHMENT; | 146 | int disptype = MAILMIME_DISPOSITION_TYPE_ATTACHMENT; |
145 | int mechanism = MAILMIME_MECHANISM_BASE64; | 147 | int mechanism = MAILMIME_MECHANISM_BASE64; |
146 | 148 | ||
147 | if ( mimetype.startsWith( "text/" ) ) { | 149 | if ( mimetype.startsWith( "text/" ) ) { |
148 | param = mailmime_parameter_new( strdup( "charset" ), | 150 | param = mailmime_parameter_new( strdup( "charset" ), |
149 | strdup( mCharset.latin1() ) ); | 151 | strdup( mCharset.latin1() ) ); |
150 | mechanism = MAILMIME_MECHANISM_QUOTED_PRINTABLE; | 152 | mechanism = MAILMIME_MECHANISM_QUOTED_PRINTABLE; |
151 | } | 153 | } |
152 | 154 | ||
153 | fields = mailmime_fields_new_filename( | 155 | fields = mailmime_fields_new_filename( |
154 | disptype, name, | 156 | disptype, name, |
155 | mechanism ); | 157 | mechanism ); |
156 | content = mailmime_content_new_with_str( (char*)mimetype.latin1() ); | 158 | content = mailmime_content_new_with_str( (char*)mimetype.latin1() ); |
157 | if (content!=0 && fields != 0) { | 159 | if (content!=0 && fields != 0) { |
158 | if (param) { | 160 | if (param) { |
159 | clist_append(content->ct_parameters,param); | 161 | clist_append(content->ct_parameters,param); |
160 | param = 0; | 162 | param = 0; |
161 | } | 163 | } |
162 | if (filename.length()>0) { | 164 | if (filename.length()>0) { |
163 | QFileInfo f(filename); | 165 | QFileInfo f(filename); |
164 | param = mailmime_parameter_new(strdup("name"),strdup(f.fileName().latin1())); | 166 | param = mailmime_parameter_new(strdup("name"),strdup(f.fileName().latin1())); |
165 | clist_append(content->ct_parameters,param); | 167 | clist_append(content->ct_parameters,param); |
166 | param = 0; | 168 | param = 0; |
167 | } | 169 | } |
168 | filePart = mailmime_new_empty( content, fields ); | 170 | filePart = mailmime_new_empty( content, fields ); |
169 | } | 171 | } |
170 | if (filePart) { | 172 | if (filePart) { |
171 | if (filename.length()>0) { | 173 | if (filename.length()>0) { |
172 | err = mailmime_set_body_file( filePart, file ); | 174 | err = mailmime_set_body_file( filePart, file ); |
173 | } else { | 175 | } else { |
174 | err = mailmime_set_body_text(filePart,strdup( TextContent.utf8().data()),TextContent.utf8().length()); | 176 | err = mailmime_set_body_text(filePart,strdup( TextContent.utf8().data()),TextContent.utf8().length()); |
175 | //err = mailmime_set_body_text(filePart,strdup( TextContent.latin1()),TextContent.length()); | 177 | //err = mailmime_set_body_text(filePart,strdup( TextContent.latin1()),TextContent.length()); |
176 | } | 178 | } |
177 | if (err != MAILIMF_NO_ERROR) { | 179 | if (err != MAILIMF_NO_ERROR) { |
178 | qDebug("Error setting body with file "); | 180 | qDebug("Error setting body with file "); |
179 | mailmime_free( filePart ); | 181 | mailmime_free( filePart ); |
180 | filePart = 0; | 182 | filePart = 0; |
181 | } | 183 | } |
182 | } | 184 | } |
183 | 185 | ||
184 | if (!filePart) { | 186 | if (!filePart) { |
185 | if ( param != NULL ) { | 187 | if ( param != NULL ) { |
186 | mailmime_parameter_free( param ); | 188 | mailmime_parameter_free( param ); |
187 | } | 189 | } |
188 | if (content) { | 190 | if (content) { |
189 | mailmime_content_free( content ); | 191 | mailmime_content_free( content ); |
190 | } | 192 | } |
191 | if (fields) { | 193 | if (fields) { |
192 | mailmime_fields_free( fields ); | 194 | mailmime_fields_free( fields ); |
193 | } else { | 195 | } else { |
194 | if (name) { | 196 | if (name) { |
195 | free( name ); | 197 | free( name ); |
196 | } | 198 | } |
197 | if (file) { | 199 | if (file) { |
198 | free( file ); | 200 | free( file ); |
199 | } | 201 | } |
200 | } | 202 | } |
201 | } | 203 | } |
202 | return filePart; // Success :) | 204 | return filePart; // Success :) |
203 | 205 | ||
204 | } | 206 | } |
205 | 207 | ||
206 | void Generatemail::addFileParts( mailmime *message,const QList<Attachment>&files ) { | 208 | void Generatemail::addFileParts( mailmime *message,const QList<Attachment>&files ) { |
207 | const Attachment *it; | 209 | const Attachment *it; |
208 | unsigned int count = files.count(); | 210 | unsigned int count = files.count(); |
209 | for ( unsigned int i = 0; i < count; ++i ) { | 211 | for ( unsigned int i = 0; i < count; ++i ) { |
210 | mailmime *filePart; | 212 | mailmime *filePart; |
211 | int err; | 213 | int err; |
212 | it = ((QList<Attachment>)files).at(i); | 214 | it = ((QList<Attachment>)files).at(i); |
213 | 215 | ||
214 | filePart = buildFilePart( it->getFileName(), it->getMimeType(),"" ); | 216 | filePart = buildFilePart( it->getFileName(), it->getMimeType(),"" ); |
215 | if ( filePart == NULL ) { | 217 | if ( filePart == NULL ) { |
216 | continue; | 218 | continue; |
217 | } | 219 | } |
218 | err = mailmime_smart_add_part( message, filePart ); | 220 | err = mailmime_smart_add_part( message, filePart ); |
219 | if ( err != MAILIMF_NO_ERROR ) { | 221 | if ( err != MAILIMF_NO_ERROR ) { |
220 | mailmime_free( filePart ); | 222 | mailmime_free( filePart ); |
221 | } | 223 | } |
222 | } | 224 | } |
223 | } | 225 | } |
224 | 226 | ||
225 | mailmime *Generatemail::buildTxtPart(const QString&str ) { | 227 | mailmime *Generatemail::buildTxtPart(const QString&str ) { |
226 | mailmime *txtPart; | 228 | mailmime *txtPart; |
227 | mailmime_fields *fields; | 229 | mailmime_fields *fields; |
228 | mailmime_content *content; | 230 | mailmime_content *content; |
229 | mailmime_parameter *param; | 231 | mailmime_parameter *param; |
230 | int err; | 232 | int err; |
231 | QCString __str; | 233 | Q3CString __str; |
232 | //qDebug(" Generatemail::buildTxtPart %s", str.latin1()); | 234 | //qDebug(" Generatemail::buildTxtPart %s", str.latin1()); |
233 | param = mailmime_parameter_new( strdup( "charset" ), | 235 | param = mailmime_parameter_new( strdup( "charset" ), |
234 | strdup( mCharset.latin1() ) ); | 236 | strdup( mCharset.latin1() ) ); |
235 | if ( param == NULL ) | 237 | if ( param == NULL ) |
236 | goto err_free; | 238 | goto err_free; |
237 | 239 | ||
238 | content = mailmime_content_new_with_str( "text/plain" ); | 240 | content = mailmime_content_new_with_str( "text/plain" ); |
239 | if ( content == NULL ) | 241 | if ( content == NULL ) |
240 | goto err_free_param; | 242 | goto err_free_param; |
241 | 243 | ||
242 | err = clist_append( content->ct_parameters, param ); | 244 | err = clist_append( content->ct_parameters, param ); |
243 | if ( err != MAILIMF_NO_ERROR ) | 245 | if ( err != MAILIMF_NO_ERROR ) |
244 | goto err_free_content; | 246 | goto err_free_content; |
245 | 247 | ||
246 | fields = mailmime_fields_new_encoding(MAILMIME_MECHANISM_8BIT); | 248 | fields = mailmime_fields_new_encoding(MAILMIME_MECHANISM_8BIT); |
247 | if ( fields == NULL ) | 249 | if ( fields == NULL ) |
248 | goto err_free_content; | 250 | goto err_free_content; |
249 | 251 | ||
250 | txtPart = mailmime_new_empty( content, fields ); | 252 | txtPart = mailmime_new_empty( content, fields ); |
251 | if ( txtPart == NULL ) | 253 | if ( txtPart == NULL ) |
252 | goto err_free_fields; | 254 | goto err_free_fields; |
253 | { | 255 | { |
254 | //__str = str.utf8(); | 256 | //__str = str.utf8(); |
255 | __str = QCString (str.latin1()); | 257 | __str = Q3CString (str.latin1()); |
256 | err = mailmime_set_body_text( txtPart, strdup(__str.data()), __str.length() ); | 258 | err = mailmime_set_body_text( txtPart, strdup(__str.data()), __str.length() ); |
257 | } | 259 | } |
258 | if ( err != MAILIMF_NO_ERROR ) | 260 | if ( err != MAILIMF_NO_ERROR ) |
259 | goto err_free_txtPart; | 261 | goto err_free_txtPart; |
260 | 262 | ||
261 | return txtPart; // Success :) | 263 | return txtPart; // Success :) |
262 | 264 | ||
263 | err_free_txtPart: | 265 | err_free_txtPart: |
264 | mailmime_free( txtPart ); | 266 | mailmime_free( txtPart ); |
265 | err_free_fields: | 267 | err_free_fields: |
266 | mailmime_fields_free( fields ); | 268 | mailmime_fields_free( fields ); |
267 | err_free_content: | 269 | err_free_content: |
268 | mailmime_content_free( content ); | 270 | mailmime_content_free( content ); |
269 | err_free_param: | 271 | err_free_param: |
270 | mailmime_parameter_free( param ); | 272 | mailmime_parameter_free( param ); |
271 | err_free: | 273 | err_free: |
272 | ; | 274 | ; |
273 | 275 | ||
274 | return NULL; // Error :( | 276 | return NULL; // Error :( |
275 | } | 277 | } |
276 | 278 | ||
277 | mailimf_mailbox *Generatemail::newMailbox(const QString&name, const QString&mail ) { | 279 | mailimf_mailbox *Generatemail::newMailbox(const QString&name, const QString&mail ) { |
278 | return mailimf_mailbox_new( strdup( name.latin1() ), | 280 | return mailimf_mailbox_new( strdup( name.latin1() ), |
279 | strdup( mail.latin1() ) ); | 281 | strdup( mail.latin1() ) ); |
280 | } | 282 | } |
281 | 283 | ||
282 | mailimf_fields *Generatemail::createImfFields(const Opie::Core::OSmartPointer<Mail>&mail ) | 284 | mailimf_fields *Generatemail::createImfFields(const Opie::Core::OSmartPointer<Mail>&mail ) |
283 | { | 285 | { |
284 | mailimf_fields *fields = NULL; | 286 | mailimf_fields *fields = NULL; |
285 | mailimf_field *xmailer = NULL; | 287 | mailimf_field *xmailer = NULL; |
286 | mailimf_mailbox *sender=0,*fromBox=0; | 288 | mailimf_mailbox *sender=0,*fromBox=0; |
287 | mailimf_mailbox_list *from=0; | 289 | mailimf_mailbox_list *from=0; |
288 | mailimf_address_list *to=0, *cc=0, *bcc=0, *reply=0; | 290 | mailimf_address_list *to=0, *cc=0, *bcc=0, *reply=0; |
289 | clist*in_reply_to = 0; | 291 | clist*in_reply_to = 0; |
290 | char *subject = strdup( mail->getSubject().latin1() ); | 292 | char *subject = strdup( mail->getSubject().latin1() ); |
291 | int err; | 293 | int err; |
292 | int res = 1; | 294 | int res = 1; |
293 | 295 | ||
294 | sender = newMailbox( mail->getName(), mail->getMail() ); | 296 | sender = newMailbox( mail->getName(), mail->getMail() ); |
295 | if ( sender == NULL ) { | 297 | if ( sender == NULL ) { |
296 | res = 0; | 298 | res = 0; |
297 | } | 299 | } |
298 | 300 | ||
299 | if (res) { | 301 | if (res) { |
300 | fromBox = newMailbox( mail->getName(), mail->getMail() ); | 302 | fromBox = newMailbox( mail->getName(), mail->getMail() ); |
301 | } | 303 | } |
302 | if ( fromBox == NULL ) { | 304 | if ( fromBox == NULL ) { |
303 | res = 0; | 305 | res = 0; |
304 | } | 306 | } |
305 | 307 | ||
306 | if (res) { | 308 | if (res) { |
307 | from = mailimf_mailbox_list_new_empty(); | 309 | from = mailimf_mailbox_list_new_empty(); |
308 | } | 310 | } |
309 | if ( from == NULL ) { | 311 | if ( from == NULL ) { |
310 | res = 0; | 312 | res = 0; |
311 | } | 313 | } |
312 | 314 | ||
313 | if (res && from) { | 315 | if (res && from) { |
314 | err = mailimf_mailbox_list_add( from, fromBox ); | 316 | err = mailimf_mailbox_list_add( from, fromBox ); |
315 | if ( err != MAILIMF_NO_ERROR ) { | 317 | if ( err != MAILIMF_NO_ERROR ) { |
316 | res = 0; | 318 | res = 0; |
317 | } | 319 | } |
318 | } | 320 | } |
319 | 321 | ||
320 | if (res) to = parseAddresses( mail->getTo() ); | 322 | if (res) to = parseAddresses( mail->getTo() ); |
321 | if (res) cc = parseAddresses( mail->getCC() ); | 323 | if (res) cc = parseAddresses( mail->getCC() ); |
322 | if (res) bcc = parseAddresses( mail->getBCC() ); | 324 | if (res) bcc = parseAddresses( mail->getBCC() ); |
323 | if (res) reply = parseAddresses( mail->getReply() ); | 325 | if (res) reply = parseAddresses( mail->getReply() ); |
324 | 326 | ||
325 | if (res && mail->Inreply().count()>0) { | 327 | if (res && mail->Inreply().count()>0) { |
326 | in_reply_to = clist_new(); | 328 | in_reply_to = clist_new(); |
327 | char*c_reply; | 329 | char*c_reply; |
328 | unsigned int nsize = 0; | 330 | unsigned int nsize = 0; |
329 | for (QStringList::ConstIterator it=mail->Inreply().begin(); | 331 | for (QStringList::ConstIterator it=mail->Inreply().begin(); |
330 | it != mail->Inreply().end();++it) { | 332 | it != mail->Inreply().end();++it) { |
331 | if ((*it).isEmpty()) | 333 | if ((*it).isEmpty()) |
332 | continue; | 334 | continue; |
333 | QString h((*it)); | 335 | QString h((*it)); |
334 | while (h.length()>0 && h[0]=='<') { | 336 | while (h.length()>0 && h[0]=='<') { |
335 | h.remove(0,1); | 337 | h.remove(0,1); |
336 | } | 338 | } |
337 | while (h.length()>0 && h[h.length()-1]=='>') { | 339 | while (h.length()>0 && h[h.length()-1]=='>') { |
338 | h.remove(h.length()-1,1); | 340 | h.remove(h.length()-1,1); |
339 | } | 341 | } |
340 | if (h.isEmpty()) continue; | 342 | if (h.isEmpty()) continue; |
341 | nsize = strlen(h.latin1()); | 343 | nsize = strlen(h.latin1()); |
342 | /* yes! must be malloc! */ | 344 | /* yes! must be malloc! */ |
343 | c_reply = (char*)malloc( (nsize+1)*sizeof(char)); | 345 | c_reply = (char*)malloc( (nsize+1)*sizeof(char)); |
344 | memset(c_reply,0,nsize+1); | 346 | memset(c_reply,0,nsize+1); |
345 | memcpy(c_reply,h.latin1(),nsize); | 347 | memcpy(c_reply,h.latin1(),nsize); |
346 | clist_append(in_reply_to,c_reply); | 348 | clist_append(in_reply_to,c_reply); |
347 | } | 349 | } |
348 | } | 350 | } |
349 | 351 | ||
350 | if (res) { | 352 | if (res) { |
351 | 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, |
352 | in_reply_to, NULL, subject ); | 354 | in_reply_to, NULL, subject ); |
353 | if ( fields == NULL ) { | 355 | if ( fields == NULL ) { |
354 | res = 0; | 356 | res = 0; |
355 | } | 357 | } |
356 | } | 358 | } |
357 | if (res) xmailer = mailimf_field_new_custom( strdup( "User-Agent" ), | 359 | if (res) xmailer = mailimf_field_new_custom( strdup( "User-Agent" ), |
358 | strdup( USER_AGENT ) ); | 360 | strdup( USER_AGENT ) ); |
359 | if ( xmailer == NULL ) { | 361 | if ( xmailer == NULL ) { |
360 | res = 0; | 362 | res = 0; |
361 | } else { | 363 | } else { |
362 | err = mailimf_fields_add( fields, xmailer ); | 364 | err = mailimf_fields_add( fields, xmailer ); |
363 | if ( err != MAILIMF_NO_ERROR ) { | 365 | if ( err != MAILIMF_NO_ERROR ) { |
364 | res = 0; | 366 | res = 0; |
365 | } | 367 | } |
366 | } | 368 | } |
367 | if (!res ) { | 369 | if (!res ) { |
368 | if (xmailer) { | 370 | if (xmailer) { |
369 | mailimf_field_free( xmailer ); | 371 | mailimf_field_free( xmailer ); |
370 | xmailer = NULL; | 372 | xmailer = NULL; |
371 | } | 373 | } |
372 | if (fields) { | 374 | if (fields) { |
373 | mailimf_fields_free( fields ); | 375 | mailimf_fields_free( fields ); |
374 | fields = NULL; | 376 | fields = NULL; |
375 | } else { | 377 | } else { |
376 | if (reply) | 378 | if (reply) |
377 | mailimf_address_list_free( reply ); | 379 | mailimf_address_list_free( reply ); |
378 | if (bcc) | 380 | if (bcc) |
379 | mailimf_address_list_free( bcc ); | 381 | mailimf_address_list_free( bcc ); |
380 | if (cc) | 382 | if (cc) |
381 | mailimf_address_list_free( cc ); | 383 | mailimf_address_list_free( cc ); |
382 | if (to) | 384 | if (to) |
383 | mailimf_address_list_free( to ); | 385 | mailimf_address_list_free( to ); |
384 | if (fromBox) { | 386 | if (fromBox) { |
385 | mailimf_mailbox_free( fromBox ); | 387 | mailimf_mailbox_free( fromBox ); |
386 | } else if (from) { | 388 | } else if (from) { |
387 | mailimf_mailbox_list_free( from ); | 389 | mailimf_mailbox_list_free( from ); |
388 | } | 390 | } |
389 | if (sender) { | 391 | if (sender) { |
390 | mailimf_mailbox_free( sender ); | 392 | mailimf_mailbox_free( sender ); |
391 | } | 393 | } |
392 | if (subject) { | 394 | if (subject) { |
393 | free( subject ); | 395 | free( subject ); |
394 | } | 396 | } |
395 | } | 397 | } |
396 | } | 398 | } |
397 | return fields; | 399 | return fields; |
398 | } | 400 | } |
399 | 401 | ||
400 | mailmime *Generatemail::createMimeMail(const Opie::Core::OSmartPointer<Mail> &mail ) { | 402 | mailmime *Generatemail::createMimeMail(const Opie::Core::OSmartPointer<Mail> &mail ) { |
401 | mailmime *message, *txtPart; | 403 | mailmime *message, *txtPart; |
402 | mailimf_fields *fields; | 404 | mailimf_fields *fields; |
403 | int err; | 405 | int err; |
404 | 406 | ||
405 | //LR disabled for now | 407 | //LR disabled for now |
406 | //mCharset = mail->getCharset().lower(); | 408 | //mCharset = mail->getCharset().lower(); |
407 | fields = createImfFields( mail ); | 409 | fields = createImfFields( mail ); |
408 | if ( fields == NULL ) | 410 | if ( fields == NULL ) |
409 | goto err_free; | 411 | goto err_free; |
410 | 412 | ||
411 | message = mailmime_new_message_data( NULL ); | 413 | message = mailmime_new_message_data( NULL ); |
412 | if ( message == NULL ) | 414 | if ( message == NULL ) |
413 | goto err_free_fields; | 415 | goto err_free_fields; |
414 | 416 | ||
415 | mailmime_set_imf_fields( message, fields ); | 417 | mailmime_set_imf_fields( message, fields ); |
416 | 418 | ||
417 | txtPart = buildTxtPart( mail->getMessage() ); | 419 | txtPart = buildTxtPart( mail->getMessage() ); |
418 | 420 | ||
419 | if ( txtPart == NULL ) | 421 | if ( txtPart == NULL ) |
420 | goto err_free_message; | 422 | goto err_free_message; |
421 | 423 | ||
422 | err = mailmime_smart_add_part( message, txtPart ); | 424 | err = mailmime_smart_add_part( message, txtPart ); |
423 | if ( err != MAILIMF_NO_ERROR ) | 425 | if ( err != MAILIMF_NO_ERROR ) |
424 | goto err_free_txtPart; | 426 | goto err_free_txtPart; |
425 | 427 | ||
426 | addFileParts( message, mail->getAttachments() ); | 428 | addFileParts( message, mail->getAttachments() ); |
427 | 429 | ||
428 | return message; // Success :) | 430 | return message; // Success :) |
429 | 431 | ||
430 | err_free_txtPart: | 432 | err_free_txtPart: |
431 | mailmime_free( txtPart ); | 433 | mailmime_free( txtPart ); |
432 | err_free_message: | 434 | err_free_message: |
433 | mailmime_free( message ); | 435 | mailmime_free( message ); |
434 | err_free_fields: | 436 | err_free_fields: |
435 | mailimf_fields_free( fields ); | 437 | mailimf_fields_free( fields ); |
436 | err_free: | 438 | err_free: |
437 | ; | 439 | ; |
438 | 440 | ||
439 | return NULL; // Error :( | 441 | return NULL; // Error :( |
440 | } | 442 | } |
441 | 443 | ||
442 | clist *Generatemail::createRcptList( mailimf_fields *fields ) { | 444 | clist *Generatemail::createRcptList( mailimf_fields *fields ) { |
443 | clist *rcptList; | 445 | clist *rcptList; |
444 | mailimf_field *field; | 446 | mailimf_field *field; |
445 | 447 | ||
446 | rcptList = esmtp_address_list_new(); | 448 | rcptList = esmtp_address_list_new(); |
447 | 449 | ||