-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,467 +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 | ||
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; |
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 | ||
127 | mailmime *Generatemail::buildFilePart(const QString&filename,const QString&mimetype,const QString&TextContent ) { | 127 | mailmime *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 | ||
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 | |||
@@ -1,456 +1,456 @@ | |||
1 | #include "smtpwrapper.h" | 1 | #include "smtpwrapper.h" |
2 | #include "mailwrapper.h" | 2 | #include "mailwrapper.h" |
3 | #include "abstractmail.h" | 3 | #include "abstractmail.h" |
4 | #include "logindialog.h" | 4 | #include "logindialog.h" |
5 | #include "mailtypes.h" | 5 | #include "mailtypes.h" |
6 | #include "sendmailprogress.h" | 6 | #include "sendmailprogress.h" |
7 | 7 | ||
8 | #include <qt.h> | 8 | #include <qt.h> |
9 | 9 | ||
10 | #include <qpe/config.h> | 10 | #include <qpe/config.h> |
11 | #include <qpe/qcopenvelope_qws.h> | 11 | #include <qpe/qcopenvelope_qws.h> |
12 | 12 | ||
13 | #include <libetpan/libetpan.h> | 13 | #include <libetpan/libetpan.h> |
14 | 14 | ||
15 | 15 | ||
16 | progressMailSend*SMTPwrapper::sendProgress = 0; | 16 | progressMailSend*SMTPwrapper::sendProgress = 0; |
17 | 17 | ||
18 | SMTPwrapper::SMTPwrapper(SMTPaccount * aSmtp ) | 18 | SMTPwrapper::SMTPwrapper(SMTPaccount * aSmtp ) |
19 | : Generatemail() | 19 | : Generatemail() |
20 | { | 20 | { |
21 | m_SmtpAccount = aSmtp; | 21 | m_SmtpAccount = aSmtp; |
22 | Config cfg( "mail" ); | 22 | Config cfg( "mail" ); |
23 | cfg.setGroup( "Status" ); | 23 | cfg.setGroup( "Status" ); |
24 | m_queuedMail = cfg.readNumEntry( "outgoing", 0 ); | 24 | m_queuedMail = cfg.readNumEntry( "outgoing", 0 ); |
25 | emit queuedMails( m_queuedMail ); | 25 | emit queuedMails( m_queuedMail ); |
26 | connect( this, SIGNAL( queuedMails(int) ), this, SLOT( emitQCop(int) ) ); | 26 | connect( this, SIGNAL( queuedMails(int) ), this, SLOT( emitQCop(int) ) ); |
27 | m_smtp = 0; | 27 | m_smtp = 0; |
28 | } | 28 | } |
29 | 29 | ||
30 | SMTPwrapper::~SMTPwrapper() | 30 | SMTPwrapper::~SMTPwrapper() |
31 | { | 31 | { |
32 | disc_server(); | 32 | disc_server(); |
33 | } | 33 | } |
34 | 34 | ||
35 | void SMTPwrapper::emitQCop( int queued ) { | 35 | void SMTPwrapper::emitQCop( int queued ) { |
36 | QCopEnvelope env( "QPE/Pim", "outgoingMails(int)" ); | 36 | QCopEnvelope env( "QPE/Pim", "outgoingMails(int)" ); |
37 | env << queued; | 37 | env << queued; |
38 | } | 38 | } |
39 | 39 | ||
40 | QString SMTPwrapper::mailsmtpError( int errnum ) { | 40 | QString SMTPwrapper::mailsmtpError( int errnum ) { |
41 | switch ( errnum ) { | 41 | switch ( errnum ) { |
42 | case MAILSMTP_NO_ERROR: | 42 | case MAILSMTP_NO_ERROR: |
43 | return tr( "No error" ); | 43 | return tr( "No error" ); |
44 | case MAILSMTP_ERROR_UNEXPECTED_CODE: | 44 | case MAILSMTP_ERROR_UNEXPECTED_CODE: |
45 | return tr( "Unexpected error code" ); | 45 | return tr( "Unexpected error code" ); |
46 | case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE: | 46 | case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE: |
47 | return tr( "Service not available" ); | 47 | return tr( "Service not available" ); |
48 | case MAILSMTP_ERROR_STREAM: | 48 | case MAILSMTP_ERROR_STREAM: |
49 | return tr( "Stream error" ); | 49 | return tr( "Stream error" ); |
50 | case MAILSMTP_ERROR_HOSTNAME: | 50 | case MAILSMTP_ERROR_HOSTNAME: |
51 | return tr( "gethostname() failed" ); | 51 | return tr( "gethostname() failed" ); |
52 | case MAILSMTP_ERROR_NOT_IMPLEMENTED: | 52 | case MAILSMTP_ERROR_NOT_IMPLEMENTED: |
53 | return tr( "Not implemented" ); | 53 | return tr( "Not implemented" ); |
54 | case MAILSMTP_ERROR_ACTION_NOT_TAKEN: | 54 | case MAILSMTP_ERROR_ACTION_NOT_TAKEN: |
55 | return tr( "Error, action not taken" ); | 55 | return tr( "Error, action not taken" ); |
56 | case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION: | 56 | case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION: |
57 | return tr( "Data exceeds storage allocation" ); | 57 | return tr( "Data exceeds storage allocation" ); |
58 | case MAILSMTP_ERROR_IN_PROCESSING: | 58 | case MAILSMTP_ERROR_IN_PROCESSING: |
59 | return tr( "Error in processing" ); | 59 | return tr( "Error in processing" ); |
60 | case MAILSMTP_ERROR_STARTTLS_NOT_SUPPORTED: | 60 | case MAILSMTP_ERROR_STARTTLS_NOT_SUPPORTED: |
61 | return tr( "Starttls not supported" ); | 61 | return tr( "Starttls not supported" ); |
62 | // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE: | 62 | // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE: |
63 | // return tr( "Insufficient system storage" ); | 63 | // return tr( "Insufficient system storage" ); |
64 | case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE: | 64 | case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE: |
65 | return tr( "Mailbox unavailable" ); | 65 | return tr( "Mailbox unavailable" ); |
66 | case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED: | 66 | case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED: |
67 | return tr( "Mailbox name not allowed" ); | 67 | return tr( "Mailbox name not allowed" ); |
68 | case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND: | 68 | case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND: |
69 | return tr( "Bad command sequence" ); | 69 | return tr( "Bad command sequence" ); |
70 | case MAILSMTP_ERROR_USER_NOT_LOCAL: | 70 | case MAILSMTP_ERROR_USER_NOT_LOCAL: |
71 | return tr( "User not local" ); | 71 | return tr( "User not local" ); |
72 | case MAILSMTP_ERROR_TRANSACTION_FAILED: | 72 | case MAILSMTP_ERROR_TRANSACTION_FAILED: |
73 | return tr( "Transaction failed" ); | 73 | return tr( "Transaction failed" ); |
74 | case MAILSMTP_ERROR_MEMORY: | 74 | case MAILSMTP_ERROR_MEMORY: |
75 | return tr( "Memory error" ); | 75 | return tr( "Memory error" ); |
76 | case MAILSMTP_ERROR_CONNECTION_REFUSED: | 76 | case MAILSMTP_ERROR_CONNECTION_REFUSED: |
77 | return tr( "Connection refused" ); | 77 | return tr( "Connection refused" ); |
78 | default: | 78 | default: |
79 | return tr( "Unknown error code" ); | 79 | return tr( "Unknown error code" ); |
80 | } | 80 | } |
81 | } | 81 | } |
82 | 82 | ||
83 | 83 | ||
84 | void SMTPwrapper::progress( size_t current, size_t maximum ) { | 84 | void SMTPwrapper::progress( size_t current, size_t maximum ) { |
85 | if (SMTPwrapper::sendProgress) { | 85 | if (SMTPwrapper::sendProgress) { |
86 | SMTPwrapper::sendProgress->setSingleMail(current, maximum ); | 86 | SMTPwrapper::sendProgress->setSingleMail(current, maximum ); |
87 | qApp->processEvents(); | 87 | qApp->processEvents(); |
88 | } | 88 | } |
89 | } | 89 | } |
90 | 90 | ||
91 | void SMTPwrapper::storeMail(const char*mail, size_t length, const QString&box) { | 91 | void SMTPwrapper::storeMail(const char*mail, size_t length, const QString&box) { |
92 | if (!mail) | 92 | if (!mail) |
93 | return; | 93 | return; |
94 | QString localfolders = AbstractMail::defaultLocalfolder(); | 94 | QString localfolders = AbstractMail::defaultLocalfolder(); |
95 | AbstractMail*wrap = AbstractMail::getWrapper(localfolders); | 95 | AbstractMail*wrap = AbstractMail::getWrapper(localfolders); |
96 | wrap->createMbox(box); | 96 | wrap->createMbox(box); |
97 | wrap->storeMessage(mail,length,box); | 97 | wrap->storeMessage(mail,length,box); |
98 | delete wrap; | 98 | delete wrap; |
99 | } | 99 | } |
100 | 100 | ||
101 | void SMTPwrapper::smtpSend( mailmime *mail,bool later) { | 101 | void SMTPwrapper::smtpSend( mailmime *mail,bool later) { |
102 | clist *rcpts = 0; | 102 | clist *rcpts = 0; |
103 | char *from, *data; | 103 | char *from, *data; |
104 | size_t size; | 104 | size_t size; |
105 | 105 | ||
106 | from = data = 0; | 106 | from = data = 0; |
107 | 107 | ||
108 | mailmessage * msg = 0; | 108 | mailmessage * msg = 0; |
109 | msg = mime_message_init(mail); | 109 | msg = mime_message_init(mail); |
110 | mime_message_set_tmpdir(msg,getenv( "HOME" )); | 110 | mime_message_set_tmpdir(msg,getenv( "HOME" )); |
111 | int r = mailmessage_fetch(msg,&data,&size); | 111 | int r = mailmessage_fetch(msg,&data,&size); |
112 | mime_message_detach_mime(msg); | 112 | mime_message_detach_mime(msg); |
113 | mailmessage_free(msg); | 113 | mailmessage_free(msg); |
114 | if (r != MAIL_NO_ERROR || !data) { | 114 | if (r != MAIL_NO_ERROR || !data) { |
115 | if (data) | 115 | if (data) |
116 | free(data); | 116 | free(data); |
117 | qDebug("Error fetching mime..."); | 117 | qDebug("Error fetching mime..."); |
118 | return; | 118 | return; |
119 | } | 119 | } |
120 | msg = 0; | 120 | msg = 0; |
121 | if (later) { | 121 | if (later) { |
122 | storeMail(data,size,"Outgoing"); | 122 | storeMail(data,size,"Outgoing"); |
123 | if (data) | 123 | if (data) |
124 | free( data ); | 124 | free( data ); |
125 | Config cfg( "mail" ); | 125 | Config cfg( "mail" ); |
126 | cfg.setGroup( "Status" ); | 126 | cfg.setGroup( "Status" ); |
127 | cfg.writeEntry( "outgoing", ++m_queuedMail ); | 127 | cfg.writeEntry( "outgoing", ++m_queuedMail ); |
128 | emit queuedMails( m_queuedMail ); | 128 | emit queuedMails( m_queuedMail ); |
129 | return; | 129 | return; |
130 | } | 130 | } |
131 | from = getFrom( mail ); | 131 | from = getFrom( mail ); |
132 | rcpts = createRcptList( mail->mm_data.mm_message.mm_fields ); | 132 | rcpts = createRcptList( mail->mm_data.mm_message.mm_fields ); |
133 | smtpSend(from,rcpts,data,size); | 133 | smtpSend(from,rcpts,data,size); |
134 | if (data) { | 134 | if (data) { |
135 | free(data); | 135 | free(data); |
136 | } | 136 | } |
137 | if (from) { | 137 | if (from) { |
138 | free(from); | 138 | free(from); |
139 | } | 139 | } |
140 | if (rcpts) | 140 | if (rcpts) |
141 | smtp_address_list_free( rcpts ); | 141 | smtp_address_list_free( rcpts ); |
142 | } | 142 | } |
143 | 143 | ||
144 | void SMTPwrapper::storeFailedMail(const char*data,unsigned int size, const char*failuremessage) | 144 | void SMTPwrapper::storeFailedMail(const char*data,unsigned int size, const char*failuremessage) |
145 | { | 145 | { |
146 | if (data) { | 146 | if (data) { |
147 | storeMail(data,size,"Sendfailed"); | 147 | storeMail(data,size,"Sendfailed"); |
148 | } | 148 | } |
149 | if (failuremessage) { | 149 | if (failuremessage) { |
150 | QMessageBox::critical(0,tr("Error sending mail"), | 150 | QMessageBox::critical(0,tr("Error sending mail"), |
151 | tr("<center>%1</center>").arg(failuremessage)); | 151 | tr("<center>%1</center>").arg(failuremessage)); |
152 | } | 152 | } |
153 | } | 153 | } |
154 | 154 | ||
155 | int SMTPwrapper::start_smtp_tls() | 155 | int SMTPwrapper::start_smtp_tls() |
156 | { | 156 | { |
157 | if (!m_smtp) { | 157 | if (!m_smtp) { |
158 | return MAILSMTP_ERROR_IN_PROCESSING; | 158 | return MAILSMTP_ERROR_IN_PROCESSING; |
159 | } | 159 | } |
160 | int err = mailesmtp_starttls(m_smtp); | 160 | int err = mailesmtp_starttls(m_smtp); |
161 | if (err != MAILSMTP_NO_ERROR) return err; | 161 | if (err != MAILSMTP_NO_ERROR) return err; |
162 | mailstream_low * low; | 162 | mailstream_low * low; |
163 | mailstream_low * new_low; | 163 | mailstream_low * new_low; |
164 | low = mailstream_get_low(m_smtp->stream); | 164 | low = mailstream_get_low(m_smtp->stream); |
165 | if (!low) { | 165 | if (!low) { |
166 | return MAILSMTP_ERROR_IN_PROCESSING; | 166 | return MAILSMTP_ERROR_IN_PROCESSING; |
167 | } | 167 | } |
168 | int fd = mailstream_low_get_fd(low); | 168 | int fd = mailstream_low_get_fd(low); |
169 | if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) { | 169 | if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) { |
170 | mailstream_low_free(low); | 170 | mailstream_low_free(low); |
171 | mailstream_set_low(m_smtp->stream, new_low); | 171 | mailstream_set_low(m_smtp->stream, new_low); |
172 | } else { | 172 | } else { |
173 | return MAILSMTP_ERROR_IN_PROCESSING; | 173 | return MAILSMTP_ERROR_IN_PROCESSING; |
174 | } | 174 | } |
175 | return err; | 175 | return err; |
176 | } | 176 | } |
177 | 177 | ||
178 | void SMTPwrapper::connect_server() | 178 | void SMTPwrapper::connect_server() |
179 | { | 179 | { |
180 | const char *server, *user, *pass; | 180 | const char *server, *user, *pass; |
181 | bool ssl; | 181 | bool ssl; |
182 | uint16_t port; | 182 | uint16_t port; |
183 | ssl = false; | 183 | ssl = false; |
184 | bool try_tls = true; | 184 | bool try_tls = true; |
185 | bool force_tls=false; | 185 | bool force_tls=false; |
186 | server = user = pass = 0; | 186 | server = user = pass = 0; |
187 | QString failuretext = ""; | 187 | QString failuretext = ""; |
188 | 188 | ||
189 | if (m_smtp || !m_SmtpAccount) { | 189 | if (m_smtp || !m_SmtpAccount) { |
190 | return; | 190 | return; |
191 | } | 191 | } |
192 | server = m_SmtpAccount->getServer().latin1(); | 192 | server = m_SmtpAccount->getServer().latin1(); |
193 | if ( m_SmtpAccount->ConnectionType() == 2 ) { | 193 | if ( m_SmtpAccount->ConnectionType() == 2 ) { |
194 | ssl = true; | 194 | ssl = true; |
195 | try_tls = false; | 195 | try_tls = false; |
196 | } else if (m_SmtpAccount->ConnectionType() == 1) { | 196 | } else if (m_SmtpAccount->ConnectionType() == 1) { |
197 | force_tls = true; | 197 | force_tls = true; |
198 | } | 198 | } |
199 | int result = 1; | 199 | int result = 1; |
200 | port = m_SmtpAccount->getPort().toUInt(); | 200 | port = m_SmtpAccount->getPort().toUInt(); |
201 | 201 | ||
202 | m_smtp = mailsmtp_new( 20, &progress ); | 202 | m_smtp = mailsmtp_new( 20, &progress ); |
203 | if ( m_smtp == NULL ) { | 203 | if ( m_smtp == NULL ) { |
204 | /* no failure message cause this happens when problems with memory - than we | 204 | /* no failure message cause this happens when problems with memory - than we |
205 | we can not display any messagebox */ | 205 | we can not display any messagebox */ |
206 | return; | 206 | return; |
207 | } | 207 | } |
208 | 208 | ||
209 | int err = MAILSMTP_NO_ERROR; | 209 | int err = MAILSMTP_NO_ERROR; |
210 | qDebug( "Servername %s at port %i", server, port ); | 210 | qDebug( "Servername %s at port %i", server, port ); |
211 | if ( ssl ) { | 211 | if ( ssl ) { |
212 | qDebug( "SSL session" ); | 212 | qDebug( "SSL session" ); |
213 | err = mailsmtp_ssl_connect( m_smtp, server, port ); | 213 | err = mailsmtp_ssl_connect( m_smtp, server, port ); |
214 | } else { | 214 | } else { |
215 | qDebug( "No SSL session" ); | 215 | qDebug( "No SSL session" ); |
216 | err = mailsmtp_socket_connect( m_smtp, server, port ); | 216 | err = mailsmtp_socket_connect( m_smtp, server, port ); |
217 | } | 217 | } |
218 | if ( err != MAILSMTP_NO_ERROR ) { | 218 | if ( err != MAILSMTP_NO_ERROR ) { |
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() ) { |
412 | // ok | 412 | // ok |
413 | user = login.getUser().latin1(); | 413 | user = login.getUser().latin1(); |
414 | pass = login.getPassword().latin1(); | 414 | pass = login.getPassword().latin1(); |
415 | reset_user_value = true; | 415 | reset_user_value = true; |
416 | m_SmtpAccount->setUser(user); | 416 | m_SmtpAccount->setUser(user); |
417 | m_SmtpAccount->setPassword(pass); | 417 | m_SmtpAccount->setPassword(pass); |
418 | } else { | 418 | } else { |
419 | return true; | 419 | return true; |
420 | } | 420 | } |
421 | } | 421 | } |
422 | 422 | ||
423 | 423 | ||
424 | mailsToSend.setAutoDelete(false); | 424 | mailsToSend.setAutoDelete(false); |
425 | sendProgress = new progressMailSend(); | 425 | sendProgress = new progressMailSend(); |
426 | sendProgress->show(); | 426 | sendProgress->show(); |
427 | sendProgress->setMaxMails(mailsToSend.count()); | 427 | sendProgress->setMaxMails(mailsToSend.count()); |
428 | 428 | ||
429 | while (mailsToSend.count()>0) { | 429 | while (mailsToSend.count()>0) { |
430 | if (sendQueuedMail(wrap,mailsToSend.at(0))==0) { | 430 | if (sendQueuedMail(wrap,mailsToSend.at(0))==0) { |
431 | QMessageBox::critical(0,tr("Error sending mail"), | 431 | QMessageBox::critical(0,tr("Error sending mail"), |
432 | tr("Error sending queued mail - breaking")); | 432 | tr("Error sending queued mail - breaking")); |
433 | returnValue = false; | 433 | returnValue = false; |
434 | break; | 434 | break; |
435 | } | 435 | } |
436 | mailsToRemove.append(mailsToSend.at(0)); | 436 | mailsToRemove.append(mailsToSend.at(0)); |
437 | mailsToSend.removeFirst(); | 437 | mailsToSend.removeFirst(); |
438 | sendProgress->setCurrentMails(mailsToRemove.count()); | 438 | sendProgress->setCurrentMails(mailsToRemove.count()); |
439 | } | 439 | } |
440 | if (reset_user_value) { | 440 | if (reset_user_value) { |
441 | m_SmtpAccount->setUser(oldUser); | 441 | m_SmtpAccount->setUser(oldUser); |
442 | m_SmtpAccount->setPassword(oldPw); | 442 | m_SmtpAccount->setPassword(oldPw); |
443 | } | 443 | } |
444 | Config cfg( "mail" ); | 444 | Config cfg( "mail" ); |
445 | cfg.setGroup( "Status" ); | 445 | cfg.setGroup( "Status" ); |
446 | m_queuedMail = 0; | 446 | m_queuedMail = 0; |
447 | cfg.writeEntry( "outgoing", m_queuedMail ); | 447 | cfg.writeEntry( "outgoing", m_queuedMail ); |
448 | emit queuedMails( m_queuedMail ); | 448 | emit queuedMails( m_queuedMail ); |
449 | sendProgress->hide(); | 449 | sendProgress->hide(); |
450 | delete sendProgress; | 450 | delete sendProgress; |
451 | sendProgress = 0; | 451 | sendProgress = 0; |
452 | wrap->deleteMails(mbox,mailsToRemove); | 452 | wrap->deleteMails(mbox,mailsToRemove); |
453 | mailsToSend.setAutoDelete(true); | 453 | mailsToSend.setAutoDelete(true); |
454 | delete wrap; | 454 | delete wrap; |
455 | return returnValue; | 455 | return returnValue; |
456 | } | 456 | } |
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 |