-rw-r--r-- | kmicromail/libmailwrapper/generatemail.cpp | 16 | ||||
-rw-r--r-- | kmicromail/libmailwrapper/generatemail.h | 1 | ||||
-rw-r--r-- | kmicromail/libmailwrapper/genericwrapper.cpp | 3 | ||||
-rw-r--r-- | kmicromail/libmailwrapper/imapwrapper.cpp | 4 | ||||
-rw-r--r-- | kmicromail/libmailwrapper/mailwrapper.h | 2 |
5 files changed, 17 insertions, 9 deletions
diff --git a/kmicromail/libmailwrapper/generatemail.cpp b/kmicromail/libmailwrapper/generatemail.cpp index 32311d7..2d213fe 100644 --- a/kmicromail/libmailwrapper/generatemail.cpp +++ b/kmicromail/libmailwrapper/generatemail.cpp | |||
@@ -1,461 +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 | #include <stdlib.h> | 8 | #include <stdlib.h> |
9 | #include <qfileinfo.h> | 9 | #include <qfileinfo.h> |
10 | 10 | ||
11 | using namespace Opie::Core; | 11 | using namespace Opie::Core; |
12 | const char* Generatemail::USER_AGENT="KOpieMail 33 1/3"; | 12 | const char* Generatemail::USER_AGENT="KOpieMail 33 1/3"; |
13 | 13 | ||
14 | Generatemail::Generatemail() | 14 | Generatemail::Generatemail() |
15 | { | 15 | { |
16 | mCharset = "iso-8859-1"; | ||
16 | } | 17 | } |
17 | 18 | ||
18 | Generatemail::~Generatemail() | 19 | Generatemail::~Generatemail() |
19 | { | 20 | { |
20 | } | 21 | } |
21 | 22 | ||
22 | void Generatemail::addRcpts( clist *list, mailimf_address_list *addr_list ) { | 23 | void Generatemail::addRcpts( clist *list, mailimf_address_list *addr_list ) { |
23 | clistiter *it, *it2; | 24 | clistiter *it, *it2; |
24 | 25 | ||
25 | for ( it = clist_begin( addr_list->ad_list ); it; it = it->next ) { | 26 | for ( it = clist_begin( addr_list->ad_list ); it; it = it->next ) { |
26 | mailimf_address *addr; | 27 | mailimf_address *addr; |
27 | addr = (mailimf_address *) it->data; | 28 | addr = (mailimf_address *) it->data; |
28 | 29 | ||
29 | if ( addr->ad_type == MAILIMF_ADDRESS_MAILBOX ) { | 30 | if ( addr->ad_type == MAILIMF_ADDRESS_MAILBOX ) { |
30 | esmtp_address_list_add( list, addr->ad_data.ad_mailbox->mb_addr_spec, 0, NULL ); | 31 | esmtp_address_list_add( list, addr->ad_data.ad_mailbox->mb_addr_spec, 0, NULL ); |
31 | } else if ( addr->ad_type == MAILIMF_ADDRESS_GROUP ) { | 32 | } else if ( addr->ad_type == MAILIMF_ADDRESS_GROUP ) { |
32 | clist *l = addr->ad_data.ad_group->grp_mb_list->mb_list; | 33 | clist *l = addr->ad_data.ad_group->grp_mb_list->mb_list; |
33 | for ( it2 = clist_begin( l ); it2; it2 = it2->next ) { | 34 | for ( it2 = clist_begin( l ); it2; it2 = it2->next ) { |
34 | mailimf_mailbox *mbox; | 35 | mailimf_mailbox *mbox; |
35 | mbox = (mailimf_mailbox *) it2->data; | 36 | mbox = (mailimf_mailbox *) it2->data; |
36 | esmtp_address_list_add( list, mbox->mb_addr_spec, 0, NULL ); | 37 | esmtp_address_list_add( list, mbox->mb_addr_spec, 0, NULL ); |
37 | } | 38 | } |
38 | } | 39 | } |
39 | } | 40 | } |
40 | } | 41 | } |
41 | 42 | ||
42 | char *Generatemail::getFrom( mailimf_field *ffrom) { | 43 | char *Generatemail::getFrom( mailimf_field *ffrom) { |
43 | char *from = NULL; | 44 | char *from = NULL; |
44 | if ( ffrom && (ffrom->fld_type == MAILIMF_FIELD_FROM) | 45 | if ( ffrom && (ffrom->fld_type == MAILIMF_FIELD_FROM) |
45 | && ffrom->fld_data.fld_from->frm_mb_list && ffrom->fld_data.fld_from->frm_mb_list->mb_list ) { | 46 | && ffrom->fld_data.fld_from->frm_mb_list && ffrom->fld_data.fld_from->frm_mb_list->mb_list ) { |
46 | clist *cl = ffrom->fld_data.fld_from->frm_mb_list->mb_list; | 47 | clist *cl = ffrom->fld_data.fld_from->frm_mb_list->mb_list; |
47 | clistiter *it; | 48 | clistiter *it; |
48 | for ( it = clist_begin( cl ); it; it = it->next ) { | 49 | for ( it = clist_begin( cl ); it; it = it->next ) { |
49 | mailimf_mailbox *mb = (mailimf_mailbox *) it->data; | 50 | mailimf_mailbox *mb = (mailimf_mailbox *) it->data; |
50 | from = strdup( mb->mb_addr_spec ); | 51 | from = strdup( mb->mb_addr_spec ); |
51 | } | 52 | } |
52 | } | 53 | } |
53 | 54 | ||
54 | return from; | 55 | return from; |
55 | } | 56 | } |
56 | 57 | ||
57 | char *Generatemail::getFrom( mailmime *mail ) { | 58 | char *Generatemail::getFrom( mailmime *mail ) { |
58 | /* no need to delete - its just a pointer to structure content */ | 59 | /* no need to delete - its just a pointer to structure content */ |
59 | mailimf_field *ffrom = 0; | 60 | mailimf_field *ffrom = 0; |
60 | ffrom = getField( mail->mm_data.mm_message.mm_fields, MAILIMF_FIELD_FROM ); | 61 | ffrom = getField( mail->mm_data.mm_message.mm_fields, MAILIMF_FIELD_FROM ); |
61 | return getFrom(ffrom); | 62 | return getFrom(ffrom); |
62 | } | 63 | } |
63 | 64 | ||
64 | mailimf_field *Generatemail::getField( mailimf_fields *fields, int type ) { | 65 | mailimf_field *Generatemail::getField( mailimf_fields *fields, int type ) { |
65 | mailimf_field *field; | 66 | mailimf_field *field; |
66 | clistiter *it; | 67 | clistiter *it; |
67 | 68 | ||
68 | it = clist_begin( fields->fld_list ); | 69 | it = clist_begin( fields->fld_list ); |
69 | while ( it ) { | 70 | while ( it ) { |
70 | field = (mailimf_field *) it->data; | 71 | field = (mailimf_field *) it->data; |
71 | if ( field->fld_type == type ) { | 72 | if ( field->fld_type == type ) { |
72 | return field; | 73 | return field; |
73 | } | 74 | } |
74 | it = it->next; | 75 | it = it->next; |
75 | } | 76 | } |
76 | 77 | ||
77 | return NULL; | 78 | return NULL; |
78 | } | 79 | } |
79 | 80 | ||
80 | mailimf_address_list *Generatemail::parseAddresses(const QString&addr ) { | 81 | mailimf_address_list *Generatemail::parseAddresses(const QString&addr ) { |
81 | mailimf_address_list *addresses; | 82 | mailimf_address_list *addresses; |
82 | 83 | ||
83 | if ( addr.isEmpty() ) | 84 | if ( addr.isEmpty() ) |
84 | return NULL; | 85 | return NULL; |
85 | 86 | ||
86 | addresses = mailimf_address_list_new_empty(); | 87 | addresses = mailimf_address_list_new_empty(); |
87 | 88 | ||
88 | bool literal_open = false; | 89 | bool literal_open = false; |
89 | unsigned int startpos = 0; | 90 | unsigned int startpos = 0; |
90 | QStringList list; | 91 | QStringList list; |
91 | QString s; | 92 | QString s; |
92 | unsigned int i = 0; | 93 | unsigned int i = 0; |
93 | for (; i < addr.length();++i) { | 94 | for (; i < addr.length();++i) { |
94 | switch (addr[i]) { | 95 | switch (addr[i]) { |
95 | case '\"': | 96 | case '\"': |
96 | literal_open = !literal_open; | 97 | literal_open = !literal_open; |
97 | break; | 98 | break; |
98 | case ',': | 99 | case ',': |
99 | if (!literal_open) { | 100 | if (!literal_open) { |
100 | s = addr.mid(startpos,i-startpos); | 101 | s = addr.mid(startpos,i-startpos); |
101 | if (!s.isEmpty()) { | 102 | if (!s.isEmpty()) { |
102 | list.append(s); | 103 | list.append(s); |
103 | } | 104 | } |
104 | // !!!! this is a MUST BE! | 105 | // !!!! this is a MUST BE! |
105 | startpos = ++i; | 106 | startpos = ++i; |
106 | } | 107 | } |
107 | break; | 108 | break; |
108 | default: | 109 | default: |
109 | break; | 110 | break; |
110 | } | 111 | } |
111 | } | 112 | } |
112 | s = addr.mid(startpos,i-startpos); | 113 | s = addr.mid(startpos,i-startpos); |
113 | if (!s.isEmpty()) { | 114 | if (!s.isEmpty()) { |
114 | list.append(s); | 115 | list.append(s); |
115 | } | 116 | } |
116 | QStringList::Iterator it; | 117 | QStringList::Iterator it; |
117 | for ( it = list.begin(); it != list.end(); it++ ) { | 118 | for ( it = list.begin(); it != list.end(); it++ ) { |
118 | int err = mailimf_address_list_add_parse( addresses, (char*)(*it).latin1() ); | 119 | int err = mailimf_address_list_add_parse( addresses, (char*)(*it).latin1() ); |
119 | if ( err != MAILIMF_NO_ERROR ) { | 120 | if ( err != MAILIMF_NO_ERROR ) { |
120 | qDebug(" Error parsing"); // *it | 121 | qDebug(" Error parsing"); // *it |
121 | } else { | 122 | } else { |
122 | } | 123 | } |
123 | } | 124 | } |
124 | return addresses; | 125 | return addresses; |
125 | } | 126 | } |
126 | 127 | ||
127 | mailmime *Generatemail::buildFilePart(const QString&filename,const QString&mimetype,const QString&TextContent ) { | 128 | mailmime *Generatemail::buildFilePart(const QString&filename,const QString&mimetype,const QString&TextContent ) { |
128 | mailmime * filePart = 0; | 129 | mailmime * filePart = 0; |
129 | mailmime_fields * fields = 0; | 130 | mailmime_fields * fields = 0; |
130 | mailmime_content * content = 0; | 131 | mailmime_content * content = 0; |
131 | mailmime_parameter * param = 0; | 132 | mailmime_parameter * param = 0; |
132 | char*name = 0; | 133 | char*name = 0; |
133 | char*file = 0; | 134 | char*file = 0; |
134 | int err; | 135 | int err; |
135 | int pos = filename.findRev( '/' ); | 136 | int pos = filename.findRev( '/' ); |
136 | 137 | ||
137 | if (filename.length()>0) { | 138 | if (filename.length()>0) { |
138 | QString tmp = filename.right( filename.length() - ( pos + 1 ) ); | 139 | QString tmp = filename.right( filename.length() - ( pos + 1 ) ); |
139 | name = strdup( tmp.latin1() ); // just filename | 140 | name = strdup( tmp.latin1() ); // just filename |
140 | file = strdup( filename.latin1() ); // full name with path | 141 | file = strdup( filename.latin1() ); // full name with path |
141 | } | 142 | } |
142 | 143 | ||
143 | int disptype = MAILMIME_DISPOSITION_TYPE_ATTACHMENT; | 144 | int disptype = MAILMIME_DISPOSITION_TYPE_ATTACHMENT; |
144 | int mechanism = MAILMIME_MECHANISM_BASE64; | 145 | int mechanism = MAILMIME_MECHANISM_BASE64; |
145 | 146 | ||
146 | if ( mimetype.startsWith( "text/" ) ) { | 147 | if ( mimetype.startsWith( "text/" ) ) { |
147 | param = mailmime_parameter_new( strdup( "charset" ), | 148 | param = mailmime_parameter_new( strdup( "charset" ), |
148 | strdup( "iso-8859-1" ) ); | 149 | strdup( mCharset.latin1() ) ); |
149 | mechanism = MAILMIME_MECHANISM_QUOTED_PRINTABLE; | 150 | mechanism = MAILMIME_MECHANISM_QUOTED_PRINTABLE; |
150 | } | 151 | } |
151 | 152 | ||
152 | fields = mailmime_fields_new_filename( | 153 | fields = mailmime_fields_new_filename( |
153 | disptype, name, | 154 | disptype, name, |
154 | mechanism ); | 155 | mechanism ); |
155 | content = mailmime_content_new_with_str( (char*)mimetype.latin1() ); | 156 | content = mailmime_content_new_with_str( (char*)mimetype.latin1() ); |
156 | if (content!=0 && fields != 0) { | 157 | if (content!=0 && fields != 0) { |
157 | if (param) { | 158 | if (param) { |
158 | clist_append(content->ct_parameters,param); | 159 | clist_append(content->ct_parameters,param); |
159 | param = 0; | 160 | param = 0; |
160 | } | 161 | } |
161 | if (filename.length()>0) { | 162 | if (filename.length()>0) { |
162 | QFileInfo f(filename); | 163 | QFileInfo f(filename); |
163 | param = mailmime_parameter_new(strdup("name"),strdup(f.fileName().latin1())); | 164 | param = mailmime_parameter_new(strdup("name"),strdup(f.fileName().latin1())); |
164 | clist_append(content->ct_parameters,param); | 165 | clist_append(content->ct_parameters,param); |
165 | param = 0; | 166 | param = 0; |
166 | } | 167 | } |
167 | filePart = mailmime_new_empty( content, fields ); | 168 | filePart = mailmime_new_empty( content, fields ); |
168 | } | 169 | } |
169 | if (filePart) { | 170 | if (filePart) { |
170 | if (filename.length()>0) { | 171 | if (filename.length()>0) { |
171 | err = mailmime_set_body_file( filePart, file ); | 172 | err = mailmime_set_body_file( filePart, file ); |
172 | } else { | 173 | } else { |
173 | err = mailmime_set_body_text(filePart,strdup( TextContent.utf8()),TextContent.utf8().length()); | 174 | 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()); | ||
174 | } | 176 | } |
175 | if (err != MAILIMF_NO_ERROR) { | 177 | if (err != MAILIMF_NO_ERROR) { |
176 | qDebug("Error setting body with file "); | 178 | qDebug("Error setting body with file "); |
177 | mailmime_free( filePart ); | 179 | mailmime_free( filePart ); |
178 | filePart = 0; | 180 | filePart = 0; |
179 | } | 181 | } |
180 | } | 182 | } |
181 | 183 | ||
182 | if (!filePart) { | 184 | if (!filePart) { |
183 | if ( param != NULL ) { | 185 | if ( param != NULL ) { |
184 | mailmime_parameter_free( param ); | 186 | mailmime_parameter_free( param ); |
185 | } | 187 | } |
186 | if (content) { | 188 | if (content) { |
187 | mailmime_content_free( content ); | 189 | mailmime_content_free( content ); |
188 | } | 190 | } |
189 | if (fields) { | 191 | if (fields) { |
190 | mailmime_fields_free( fields ); | 192 | mailmime_fields_free( fields ); |
191 | } else { | 193 | } else { |
192 | if (name) { | 194 | if (name) { |
193 | free( name ); | 195 | free( name ); |
194 | } | 196 | } |
195 | if (file) { | 197 | if (file) { |
196 | free( file ); | 198 | free( file ); |
197 | } | 199 | } |
198 | } | 200 | } |
199 | } | 201 | } |
200 | return filePart; // Success :) | 202 | return filePart; // Success :) |
201 | 203 | ||
202 | } | 204 | } |
203 | 205 | ||
204 | void Generatemail::addFileParts( mailmime *message,const QList<Attachment>&files ) { | 206 | void Generatemail::addFileParts( mailmime *message,const QList<Attachment>&files ) { |
205 | const Attachment *it; | 207 | const Attachment *it; |
206 | unsigned int count = files.count(); | 208 | unsigned int count = files.count(); |
207 | for ( unsigned int i = 0; i < count; ++i ) { | 209 | for ( unsigned int i = 0; i < count; ++i ) { |
208 | mailmime *filePart; | 210 | mailmime *filePart; |
209 | int err; | 211 | int err; |
210 | it = ((QList<Attachment>)files).at(i); | 212 | it = ((QList<Attachment>)files).at(i); |
211 | 213 | ||
212 | filePart = buildFilePart( it->getFileName(), it->getMimeType(),"" ); | 214 | filePart = buildFilePart( it->getFileName(), it->getMimeType(),"" ); |
213 | if ( filePart == NULL ) { | 215 | if ( filePart == NULL ) { |
214 | continue; | 216 | continue; |
215 | } | 217 | } |
216 | err = mailmime_smart_add_part( message, filePart ); | 218 | err = mailmime_smart_add_part( message, filePart ); |
217 | if ( err != MAILIMF_NO_ERROR ) { | 219 | if ( err != MAILIMF_NO_ERROR ) { |
218 | mailmime_free( filePart ); | 220 | mailmime_free( filePart ); |
219 | } | 221 | } |
220 | } | 222 | } |
221 | } | 223 | } |
222 | 224 | ||
223 | mailmime *Generatemail::buildTxtPart(const QString&str ) { | 225 | mailmime *Generatemail::buildTxtPart(const QString&str ) { |
224 | mailmime *txtPart; | 226 | mailmime *txtPart; |
225 | mailmime_fields *fields; | 227 | mailmime_fields *fields; |
226 | mailmime_content *content; | 228 | mailmime_content *content; |
227 | mailmime_parameter *param; | 229 | mailmime_parameter *param; |
228 | int err; | 230 | int err; |
229 | QCString __str; | 231 | QCString __str; |
232 | //qDebug(" Generatemail::buildTxtPart %s", str.latin1()); | ||
230 | param = mailmime_parameter_new( strdup( "charset" ), | 233 | param = mailmime_parameter_new( strdup( "charset" ), |
231 | strdup( "iso-8859-1" ) ); | 234 | strdup( mCharset.latin1() ) ); |
232 | if ( param == NULL ) | 235 | if ( param == NULL ) |
233 | goto err_free; | 236 | goto err_free; |
234 | 237 | ||
235 | content = mailmime_content_new_with_str( "text/plain" ); | 238 | content = mailmime_content_new_with_str( "text/plain" ); |
236 | if ( content == NULL ) | 239 | if ( content == NULL ) |
237 | goto err_free_param; | 240 | goto err_free_param; |
238 | 241 | ||
239 | err = clist_append( content->ct_parameters, param ); | 242 | err = clist_append( content->ct_parameters, param ); |
240 | if ( err != MAILIMF_NO_ERROR ) | 243 | if ( err != MAILIMF_NO_ERROR ) |
241 | goto err_free_content; | 244 | goto err_free_content; |
242 | 245 | ||
243 | fields = mailmime_fields_new_encoding(MAILMIME_MECHANISM_8BIT); | 246 | fields = mailmime_fields_new_encoding(MAILMIME_MECHANISM_8BIT); |
244 | if ( fields == NULL ) | 247 | if ( fields == NULL ) |
245 | goto err_free_content; | 248 | goto err_free_content; |
246 | 249 | ||
247 | txtPart = mailmime_new_empty( content, fields ); | 250 | txtPart = mailmime_new_empty( content, fields ); |
248 | if ( txtPart == NULL ) | 251 | if ( txtPart == NULL ) |
249 | goto err_free_fields; | 252 | goto err_free_fields; |
250 | { | 253 | { |
251 | __str = str.utf8(); | 254 | //__str = str.utf8(); |
252 | err = mailmime_set_body_text( txtPart, __str.data(), __str.length() ); | 255 | __str = QCString (str.latin1()); |
256 | err = mailmime_set_body_text( txtPart, strdup(__str.data()), __str.length() ); | ||
253 | } | 257 | } |
254 | if ( err != MAILIMF_NO_ERROR ) | 258 | if ( err != MAILIMF_NO_ERROR ) |
255 | goto err_free_txtPart; | 259 | goto err_free_txtPart; |
256 | 260 | ||
257 | return txtPart; // Success :) | 261 | return txtPart; // Success :) |
258 | 262 | ||
259 | err_free_txtPart: | 263 | err_free_txtPart: |
260 | mailmime_free( txtPart ); | 264 | mailmime_free( txtPart ); |
261 | err_free_fields: | 265 | err_free_fields: |
262 | mailmime_fields_free( fields ); | 266 | mailmime_fields_free( fields ); |
263 | err_free_content: | 267 | err_free_content: |
264 | mailmime_content_free( content ); | 268 | mailmime_content_free( content ); |
265 | err_free_param: | 269 | err_free_param: |
266 | mailmime_parameter_free( param ); | 270 | mailmime_parameter_free( param ); |
267 | err_free: | 271 | err_free: |
268 | ; | 272 | ; |
269 | 273 | ||
270 | return NULL; // Error :( | 274 | return NULL; // Error :( |
271 | } | 275 | } |
272 | 276 | ||
273 | mailimf_mailbox *Generatemail::newMailbox(const QString&name, const QString&mail ) { | 277 | mailimf_mailbox *Generatemail::newMailbox(const QString&name, const QString&mail ) { |
274 | return mailimf_mailbox_new( strdup( name.latin1() ), | 278 | return mailimf_mailbox_new( strdup( name.latin1() ), |
275 | strdup( mail.latin1() ) ); | 279 | strdup( mail.latin1() ) ); |
276 | } | 280 | } |
277 | 281 | ||
278 | mailimf_fields *Generatemail::createImfFields(const Opie::Core::OSmartPointer<Mail>&mail ) | 282 | mailimf_fields *Generatemail::createImfFields(const Opie::Core::OSmartPointer<Mail>&mail ) |
279 | { | 283 | { |
280 | mailimf_fields *fields = NULL; | 284 | mailimf_fields *fields = NULL; |
281 | mailimf_field *xmailer = NULL; | 285 | mailimf_field *xmailer = NULL; |
282 | mailimf_mailbox *sender=0,*fromBox=0; | 286 | mailimf_mailbox *sender=0,*fromBox=0; |
283 | mailimf_mailbox_list *from=0; | 287 | mailimf_mailbox_list *from=0; |
284 | mailimf_address_list *to=0, *cc=0, *bcc=0, *reply=0; | 288 | mailimf_address_list *to=0, *cc=0, *bcc=0, *reply=0; |
285 | clist*in_reply_to = 0; | 289 | clist*in_reply_to = 0; |
286 | char *subject = strdup( mail->getSubject().latin1() ); | 290 | char *subject = strdup( mail->getSubject().latin1() ); |
287 | int err; | 291 | int err; |
288 | int res = 1; | 292 | int res = 1; |
289 | 293 | ||
290 | sender = newMailbox( mail->getName(), mail->getMail() ); | 294 | sender = newMailbox( mail->getName(), mail->getMail() ); |
291 | if ( sender == NULL ) { | 295 | if ( sender == NULL ) { |
292 | res = 0; | 296 | res = 0; |
293 | } | 297 | } |
294 | 298 | ||
295 | if (res) { | 299 | if (res) { |
296 | fromBox = newMailbox( mail->getName(), mail->getMail() ); | 300 | fromBox = newMailbox( mail->getName(), mail->getMail() ); |
297 | } | 301 | } |
298 | if ( fromBox == NULL ) { | 302 | if ( fromBox == NULL ) { |
299 | res = 0; | 303 | res = 0; |
300 | } | 304 | } |
301 | 305 | ||
302 | if (res) { | 306 | if (res) { |
303 | from = mailimf_mailbox_list_new_empty(); | 307 | from = mailimf_mailbox_list_new_empty(); |
304 | } | 308 | } |
305 | if ( from == NULL ) { | 309 | if ( from == NULL ) { |
306 | res = 0; | 310 | res = 0; |
307 | } | 311 | } |
308 | 312 | ||
309 | if (res && from) { | 313 | if (res && from) { |
310 | err = mailimf_mailbox_list_add( from, fromBox ); | 314 | err = mailimf_mailbox_list_add( from, fromBox ); |
311 | if ( err != MAILIMF_NO_ERROR ) { | 315 | if ( err != MAILIMF_NO_ERROR ) { |
312 | res = 0; | 316 | res = 0; |
313 | } | 317 | } |
314 | } | 318 | } |
315 | 319 | ||
316 | if (res) to = parseAddresses( mail->getTo() ); | 320 | if (res) to = parseAddresses( mail->getTo() ); |
317 | if (res) cc = parseAddresses( mail->getCC() ); | 321 | if (res) cc = parseAddresses( mail->getCC() ); |
318 | if (res) bcc = parseAddresses( mail->getBCC() ); | 322 | if (res) bcc = parseAddresses( mail->getBCC() ); |
319 | if (res) reply = parseAddresses( mail->getReply() ); | 323 | if (res) reply = parseAddresses( mail->getReply() ); |
320 | 324 | ||
321 | if (res && mail->Inreply().count()>0) { | 325 | if (res && mail->Inreply().count()>0) { |
322 | in_reply_to = clist_new(); | 326 | in_reply_to = clist_new(); |
323 | char*c_reply; | 327 | char*c_reply; |
324 | unsigned int nsize = 0; | 328 | unsigned int nsize = 0; |
325 | for (QStringList::ConstIterator it=mail->Inreply().begin(); | 329 | for (QStringList::ConstIterator it=mail->Inreply().begin(); |
326 | it != mail->Inreply().end();++it) { | 330 | it != mail->Inreply().end();++it) { |
327 | if ((*it).isEmpty()) | 331 | if ((*it).isEmpty()) |
328 | continue; | 332 | continue; |
329 | QString h((*it)); | 333 | QString h((*it)); |
330 | while (h.length()>0 && h[0]=='<') { | 334 | while (h.length()>0 && h[0]=='<') { |
331 | h.remove(0,1); | 335 | h.remove(0,1); |
332 | } | 336 | } |
333 | while (h.length()>0 && h[h.length()-1]=='>') { | 337 | while (h.length()>0 && h[h.length()-1]=='>') { |
334 | h.remove(h.length()-1,1); | 338 | h.remove(h.length()-1,1); |
335 | } | 339 | } |
336 | if (h.isEmpty()) continue; | 340 | if (h.isEmpty()) continue; |
337 | nsize = strlen(h.latin1()); | 341 | nsize = strlen(h.latin1()); |
338 | /* yes! must be malloc! */ | 342 | /* yes! must be malloc! */ |
339 | c_reply = (char*)malloc( (nsize+1)*sizeof(char)); | 343 | c_reply = (char*)malloc( (nsize+1)*sizeof(char)); |
340 | memset(c_reply,0,nsize+1); | 344 | memset(c_reply,0,nsize+1); |
341 | memcpy(c_reply,h.latin1(),nsize); | 345 | memcpy(c_reply,h.latin1(),nsize); |
342 | clist_append(in_reply_to,c_reply); | 346 | clist_append(in_reply_to,c_reply); |
343 | } | 347 | } |
344 | } | 348 | } |
345 | 349 | ||
346 | if (res) { | 350 | if (res) { |
347 | fields = mailimf_fields_new_with_data( from, sender, reply, to, cc, bcc, | 351 | fields = mailimf_fields_new_with_data( from, sender, reply, to, cc, bcc, |
348 | in_reply_to, NULL, subject ); | 352 | in_reply_to, NULL, subject ); |
349 | if ( fields == NULL ) { | 353 | if ( fields == NULL ) { |
350 | res = 0; | 354 | res = 0; |
351 | } | 355 | } |
352 | } | 356 | } |
353 | if (res) xmailer = mailimf_field_new_custom( strdup( "User-Agent" ), | 357 | if (res) xmailer = mailimf_field_new_custom( strdup( "User-Agent" ), |
354 | strdup( USER_AGENT ) ); | 358 | strdup( USER_AGENT ) ); |
355 | if ( xmailer == NULL ) { | 359 | if ( xmailer == NULL ) { |
356 | res = 0; | 360 | res = 0; |
357 | } else { | 361 | } else { |
358 | err = mailimf_fields_add( fields, xmailer ); | 362 | err = mailimf_fields_add( fields, xmailer ); |
359 | if ( err != MAILIMF_NO_ERROR ) { | 363 | if ( err != MAILIMF_NO_ERROR ) { |
360 | res = 0; | 364 | res = 0; |
361 | } | 365 | } |
362 | } | 366 | } |
363 | if (!res ) { | 367 | if (!res ) { |
364 | if (xmailer) { | 368 | if (xmailer) { |
365 | mailimf_field_free( xmailer ); | 369 | mailimf_field_free( xmailer ); |
366 | xmailer = NULL; | 370 | xmailer = NULL; |
367 | } | 371 | } |
368 | if (fields) { | 372 | if (fields) { |
369 | mailimf_fields_free( fields ); | 373 | mailimf_fields_free( fields ); |
370 | fields = NULL; | 374 | fields = NULL; |
371 | } else { | 375 | } else { |
372 | if (reply) | 376 | if (reply) |
373 | mailimf_address_list_free( reply ); | 377 | mailimf_address_list_free( reply ); |
374 | if (bcc) | 378 | if (bcc) |
375 | mailimf_address_list_free( bcc ); | 379 | mailimf_address_list_free( bcc ); |
376 | if (cc) | 380 | if (cc) |
377 | mailimf_address_list_free( cc ); | 381 | mailimf_address_list_free( cc ); |
378 | if (to) | 382 | if (to) |
379 | mailimf_address_list_free( to ); | 383 | mailimf_address_list_free( to ); |
380 | if (fromBox) { | 384 | if (fromBox) { |
381 | mailimf_mailbox_free( fromBox ); | 385 | mailimf_mailbox_free( fromBox ); |
382 | } else if (from) { | 386 | } else if (from) { |
383 | mailimf_mailbox_list_free( from ); | 387 | mailimf_mailbox_list_free( from ); |
384 | } | 388 | } |
385 | if (sender) { | 389 | if (sender) { |
386 | mailimf_mailbox_free( sender ); | 390 | mailimf_mailbox_free( sender ); |
387 | } | 391 | } |
388 | if (subject) { | 392 | if (subject) { |
389 | free( subject ); | 393 | free( subject ); |
390 | } | 394 | } |
391 | } | 395 | } |
392 | } | 396 | } |
393 | return fields; | 397 | return fields; |
394 | } | 398 | } |
395 | 399 | ||
396 | mailmime *Generatemail::createMimeMail(const Opie::Core::OSmartPointer<Mail> &mail ) { | 400 | mailmime *Generatemail::createMimeMail(const Opie::Core::OSmartPointer<Mail> &mail ) { |
397 | mailmime *message, *txtPart; | 401 | mailmime *message, *txtPart; |
398 | mailimf_fields *fields; | 402 | mailimf_fields *fields; |
399 | int err; | 403 | int err; |
400 | 404 | ||
405 | //LR disabled for now | ||
406 | //mCharset = mail->getCharset().lower(); | ||
401 | fields = createImfFields( mail ); | 407 | fields = createImfFields( mail ); |
402 | if ( fields == NULL ) | 408 | if ( fields == NULL ) |
403 | goto err_free; | 409 | goto err_free; |
404 | 410 | ||
405 | message = mailmime_new_message_data( NULL ); | 411 | message = mailmime_new_message_data( NULL ); |
406 | if ( message == NULL ) | 412 | if ( message == NULL ) |
407 | goto err_free_fields; | 413 | goto err_free_fields; |
408 | 414 | ||
409 | mailmime_set_imf_fields( message, fields ); | 415 | mailmime_set_imf_fields( message, fields ); |
410 | 416 | ||
411 | txtPart = buildTxtPart( mail->getMessage() ); | 417 | txtPart = buildTxtPart( mail->getMessage() ); |
412 | 418 | ||
413 | if ( txtPart == NULL ) | 419 | if ( txtPart == NULL ) |
414 | goto err_free_message; | 420 | goto err_free_message; |
415 | 421 | ||
416 | err = mailmime_smart_add_part( message, txtPart ); | 422 | err = mailmime_smart_add_part( message, txtPart ); |
417 | if ( err != MAILIMF_NO_ERROR ) | 423 | if ( err != MAILIMF_NO_ERROR ) |
418 | goto err_free_txtPart; | 424 | goto err_free_txtPart; |
419 | 425 | ||
420 | addFileParts( message, mail->getAttachments() ); | 426 | addFileParts( message, mail->getAttachments() ); |
421 | 427 | ||
422 | return message; // Success :) | 428 | return message; // Success :) |
423 | 429 | ||
424 | err_free_txtPart: | 430 | err_free_txtPart: |
425 | mailmime_free( txtPart ); | 431 | mailmime_free( txtPart ); |
426 | err_free_message: | 432 | err_free_message: |
427 | mailmime_free( message ); | 433 | mailmime_free( message ); |
428 | err_free_fields: | 434 | err_free_fields: |
429 | mailimf_fields_free( fields ); | 435 | mailimf_fields_free( fields ); |
430 | err_free: | 436 | err_free: |
431 | ; | 437 | ; |
432 | 438 | ||
433 | return NULL; // Error :( | 439 | return NULL; // Error :( |
434 | } | 440 | } |
435 | 441 | ||
436 | clist *Generatemail::createRcptList( mailimf_fields *fields ) { | 442 | clist *Generatemail::createRcptList( mailimf_fields *fields ) { |
437 | clist *rcptList; | 443 | clist *rcptList; |
438 | mailimf_field *field; | 444 | mailimf_field *field; |
439 | 445 | ||
440 | rcptList = esmtp_address_list_new(); | 446 | rcptList = esmtp_address_list_new(); |
441 | 447 | ||
442 | field = getField( fields, MAILIMF_FIELD_TO ); | 448 | field = getField( fields, MAILIMF_FIELD_TO ); |
443 | if ( field && (field->fld_type == MAILIMF_FIELD_TO) | 449 | if ( field && (field->fld_type == MAILIMF_FIELD_TO) |
444 | && field->fld_data.fld_to->to_addr_list ) { | 450 | && field->fld_data.fld_to->to_addr_list ) { |
445 | addRcpts( rcptList, field->fld_data.fld_to->to_addr_list ); | 451 | addRcpts( rcptList, field->fld_data.fld_to->to_addr_list ); |
446 | } | 452 | } |
447 | 453 | ||
448 | field = getField( fields, MAILIMF_FIELD_CC ); | 454 | field = getField( fields, MAILIMF_FIELD_CC ); |
449 | if ( field && (field->fld_type == MAILIMF_FIELD_CC) | 455 | if ( field && (field->fld_type == MAILIMF_FIELD_CC) |
450 | && field->fld_data.fld_cc->cc_addr_list ) { | 456 | && field->fld_data.fld_cc->cc_addr_list ) { |
451 | addRcpts( rcptList, field->fld_data.fld_cc->cc_addr_list ); | 457 | addRcpts( rcptList, field->fld_data.fld_cc->cc_addr_list ); |
452 | } | 458 | } |
453 | 459 | ||
454 | field = getField( fields, MAILIMF_FIELD_BCC ); | 460 | field = getField( fields, MAILIMF_FIELD_BCC ); |
455 | if ( field && (field->fld_type == MAILIMF_FIELD_BCC) | 461 | if ( field && (field->fld_type == MAILIMF_FIELD_BCC) |
456 | && field->fld_data.fld_bcc->bcc_addr_list ) { | 462 | && field->fld_data.fld_bcc->bcc_addr_list ) { |
457 | addRcpts( rcptList, field->fld_data.fld_bcc->bcc_addr_list ); | 463 | addRcpts( rcptList, field->fld_data.fld_bcc->bcc_addr_list ); |
458 | } | 464 | } |
459 | 465 | ||
460 | return rcptList; | 466 | return rcptList; |
461 | } | 467 | } |
diff --git a/kmicromail/libmailwrapper/generatemail.h b/kmicromail/libmailwrapper/generatemail.h index b9f8285..a9fb648 100644 --- a/kmicromail/libmailwrapper/generatemail.h +++ b/kmicromail/libmailwrapper/generatemail.h | |||
@@ -1,47 +1,48 @@ | |||
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 | #include "mailwrapper.h" | 8 | #include "mailwrapper.h" |
9 | 9 | ||
10 | #include <opie2/osmartpointer.h> | 10 | #include <opie2/osmartpointer.h> |
11 | 11 | ||
12 | class Mail; | 12 | class Mail; |
13 | class RecMail; | 13 | class RecMail; |
14 | 14 | ||
15 | struct mailimf_fields; | 15 | struct mailimf_fields; |
16 | struct mailimf_field; | 16 | struct mailimf_field; |
17 | struct mailimf_mailbox; | 17 | struct mailimf_mailbox; |
18 | struct mailmime; | 18 | struct mailmime; |
19 | struct mailimf_address_list; | 19 | struct mailimf_address_list; |
20 | class progressMailSend; | 20 | class progressMailSend; |
21 | struct mailsmtp; | 21 | struct mailsmtp; |
22 | 22 | ||
23 | class Generatemail : public QObject | 23 | class Generatemail : public QObject |
24 | { | 24 | { |
25 | Q_OBJECT | 25 | Q_OBJECT |
26 | public: | 26 | public: |
27 | Generatemail(); | 27 | Generatemail(); |
28 | virtual ~Generatemail(); | 28 | virtual ~Generatemail(); |
29 | 29 | ||
30 | protected: | 30 | protected: |
31 | static void addRcpts( clist *list, mailimf_address_list *addr_list ); | 31 | static void addRcpts( clist *list, mailimf_address_list *addr_list ); |
32 | static char *getFrom( mailmime *mail ); | 32 | static char *getFrom( mailmime *mail ); |
33 | static char *getFrom( mailimf_field *ffrom); | 33 | static char *getFrom( mailimf_field *ffrom); |
34 | static mailimf_field *getField( mailimf_fields *fields, int type ); | 34 | static mailimf_field *getField( mailimf_fields *fields, int type ); |
35 | mailimf_address_list *parseAddresses(const QString&addr ); | 35 | mailimf_address_list *parseAddresses(const QString&addr ); |
36 | void addFileParts( mailmime *message,const QList<Attachment>&files ); | 36 | void addFileParts( mailmime *message,const QList<Attachment>&files ); |
37 | mailmime *buildFilePart(const QString&filename,const QString&mimetype,const QString&content); | 37 | mailmime *buildFilePart(const QString&filename,const QString&mimetype,const QString&content); |
38 | mailmime *buildTxtPart(const QString&str ); | 38 | mailmime *buildTxtPart(const QString&str ); |
39 | mailimf_mailbox *newMailbox(const QString&name,const QString&mail ); | 39 | mailimf_mailbox *newMailbox(const QString&name,const QString&mail ); |
40 | mailimf_fields *createImfFields(const Opie::Core::OSmartPointer<Mail> &mail ); | 40 | mailimf_fields *createImfFields(const Opie::Core::OSmartPointer<Mail> &mail ); |
41 | mailmime *createMimeMail(const Opie::Core::OSmartPointer<Mail>&mail ); | 41 | mailmime *createMimeMail(const Opie::Core::OSmartPointer<Mail>&mail ); |
42 | clist *createRcptList( mailimf_fields *fields ); | 42 | clist *createRcptList( mailimf_fields *fields ); |
43 | 43 | ||
44 | static const char* USER_AGENT; | 44 | static const char* USER_AGENT; |
45 | QString mCharset; | ||
45 | }; | 46 | }; |
46 | 47 | ||
47 | #endif | 48 | #endif |
diff --git a/kmicromail/libmailwrapper/genericwrapper.cpp b/kmicromail/libmailwrapper/genericwrapper.cpp index 28d45ce..eac05e5 100644 --- a/kmicromail/libmailwrapper/genericwrapper.cpp +++ b/kmicromail/libmailwrapper/genericwrapper.cpp | |||
@@ -1,545 +1,546 @@ | |||
1 | // CHANGED 2004-09-31 Lutz Rogowski | 1 | // CHANGED 2004-09-31 Lutz Rogowski |
2 | #include "genericwrapper.h" | 2 | #include "genericwrapper.h" |
3 | #include <libetpan/libetpan.h> | 3 | #include <libetpan/libetpan.h> |
4 | #include "mailtypes.h" | 4 | #include "mailtypes.h" |
5 | 5 | ||
6 | #include <kconfig.h> | 6 | #include <kconfig.h> |
7 | #include <kglobal.h> | 7 | #include <kglobal.h> |
8 | #include <kstandarddirs.h> | 8 | #include <kstandarddirs.h> |
9 | 9 | ||
10 | 10 | ||
11 | using namespace Opie::Core; | 11 | using namespace Opie::Core; |
12 | Genericwrapper::Genericwrapper() | 12 | Genericwrapper::Genericwrapper() |
13 | : AbstractMail() | 13 | : AbstractMail() |
14 | { | 14 | { |
15 | bodyCache.clear(); | 15 | bodyCache.clear(); |
16 | m_storage = 0; | 16 | m_storage = 0; |
17 | m_folder = 0; | 17 | m_folder = 0; |
18 | } | 18 | } |
19 | 19 | ||
20 | Genericwrapper::~Genericwrapper() | 20 | Genericwrapper::~Genericwrapper() |
21 | { | 21 | { |
22 | if (m_folder) { | 22 | if (m_folder) { |
23 | mailfolder_free(m_folder); | 23 | mailfolder_free(m_folder); |
24 | } | 24 | } |
25 | if (m_storage) { | 25 | if (m_storage) { |
26 | mailstorage_free(m_storage); | 26 | mailstorage_free(m_storage); |
27 | } | 27 | } |
28 | cleanMimeCache(); | 28 | cleanMimeCache(); |
29 | } | 29 | } |
30 | const QDateTime Genericwrapper::parseDateTime( mailimf_date_time *date ) | 30 | const QDateTime Genericwrapper::parseDateTime( mailimf_date_time *date ) |
31 | { | 31 | { |
32 | 32 | ||
33 | QDate da (date->dt_year,date->dt_month, date->dt_day ); | 33 | QDate da (date->dt_year,date->dt_month, date->dt_day ); |
34 | QTime ti ( date->dt_hour, date->dt_min, date->dt_sec ); | 34 | QTime ti ( date->dt_hour, date->dt_min, date->dt_sec ); |
35 | QDateTime dt ( da ,ti ); | 35 | QDateTime dt ( da ,ti ); |
36 | int addsec = -date->dt_zone*36; | 36 | int addsec = -date->dt_zone*36; |
37 | //qDebug("adsec1 %d ",addsec ); | 37 | //qDebug("adsec1 %d ",addsec ); |
38 | dt = dt.addSecs( addsec ); | 38 | dt = dt.addSecs( addsec ); |
39 | int off = KGlobal::locale()->localTimeOffset( dt ); | 39 | int off = KGlobal::locale()->localTimeOffset( dt ); |
40 | //qDebug("adsec2 %d ",off*60 ); | 40 | //qDebug("adsec2 %d ",off*60 ); |
41 | 41 | ||
42 | dt = dt.addSecs( off*60 ); | 42 | dt = dt.addSecs( off*60 ); |
43 | return dt; | 43 | return dt; |
44 | #if 0 | 44 | #if 0 |
45 | QString ret; | 45 | QString ret; |
46 | if ( dt.date() == QDate::currentDate () ) | 46 | if ( dt.date() == QDate::currentDate () ) |
47 | ret = KGlobal::locale()->formatTime( dt.time(),true); | 47 | ret = KGlobal::locale()->formatTime( dt.time(),true); |
48 | 48 | ||
49 | else { | 49 | else { |
50 | ret = KGlobal::locale()->formatDateTime( dt,true,true); | 50 | ret = KGlobal::locale()->formatDateTime( dt,true,true); |
51 | } | 51 | } |
52 | #endif | 52 | #endif |
53 | #if 0 | 53 | #if 0 |
54 | if ( off < 0 ) | 54 | if ( off < 0 ) |
55 | ret += " -"; | 55 | ret += " -"; |
56 | else | 56 | else |
57 | ret += " +"; | 57 | ret += " +"; |
58 | ret += QString::number( off / 60 ); | 58 | ret += QString::number( off / 60 ); |
59 | ret += "h"; | 59 | ret += "h"; |
60 | #endif | 60 | #endif |
61 | #if 0 | 61 | #if 0 |
62 | char tmp[23]; | 62 | char tmp[23]; |
63 | 63 | ||
64 | // snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i", | 64 | // snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i", |
65 | // date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone ); | 65 | // date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone ); |
66 | snprintf( tmp, 23, "%04i-%02i-%02i %02i:%02i:%02i %+05i", | 66 | snprintf( tmp, 23, "%04i-%02i-%02i %02i:%02i:%02i %+05i", |
67 | date->dt_year,date->dt_month, date->dt_day, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone ); | 67 | date->dt_year,date->dt_month, date->dt_day, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone ); |
68 | 68 | ||
69 | 69 | ||
70 | return QString( tmp ); | 70 | return QString( tmp ); |
71 | #endif | 71 | #endif |
72 | //return ret; | 72 | //return ret; |
73 | } | 73 | } |
74 | 74 | ||
75 | void Genericwrapper::fillSingleBody(RecPartP&target,mailmessage*,mailmime*mime) | 75 | void Genericwrapper::fillSingleBody(RecPartP&target,mailmessage*,mailmime*mime) |
76 | { | 76 | { |
77 | if (!mime) { | 77 | if (!mime) { |
78 | return; | 78 | return; |
79 | } | 79 | } |
80 | mailmime_field*field = 0; | 80 | mailmime_field*field = 0; |
81 | mailmime_single_fields fields; | 81 | mailmime_single_fields fields; |
82 | memset(&fields, 0, sizeof(struct mailmime_single_fields)); | 82 | memset(&fields, 0, sizeof(struct mailmime_single_fields)); |
83 | if (mime->mm_mime_fields != NULL) { | 83 | if (mime->mm_mime_fields != NULL) { |
84 | mailmime_single_fields_init(&fields, mime->mm_mime_fields, | 84 | mailmime_single_fields_init(&fields, mime->mm_mime_fields, |
85 | mime->mm_content_type); | 85 | mime->mm_content_type); |
86 | } | 86 | } |
87 | 87 | ||
88 | mailmime_content*type = fields.fld_content; | 88 | mailmime_content*type = fields.fld_content; |
89 | clistcell*current; | 89 | clistcell*current; |
90 | if (!type) { | 90 | if (!type) { |
91 | target->setType("text"); | 91 | target->setType("text"); |
92 | target->setSubtype("plain"); | 92 | target->setSubtype("plain"); |
93 | } else { | 93 | } else { |
94 | target->setSubtype(type->ct_subtype); | 94 | target->setSubtype(type->ct_subtype); |
95 | switch(type->ct_type->tp_data.tp_discrete_type->dt_type) { | 95 | switch(type->ct_type->tp_data.tp_discrete_type->dt_type) { |
96 | case MAILMIME_DISCRETE_TYPE_TEXT: | 96 | case MAILMIME_DISCRETE_TYPE_TEXT: |
97 | target->setType("text"); | 97 | target->setType("text"); |
98 | break; | 98 | break; |
99 | case MAILMIME_DISCRETE_TYPE_IMAGE: | 99 | case MAILMIME_DISCRETE_TYPE_IMAGE: |
100 | target->setType("image"); | 100 | target->setType("image"); |
101 | break; | 101 | break; |
102 | case MAILMIME_DISCRETE_TYPE_AUDIO: | 102 | case MAILMIME_DISCRETE_TYPE_AUDIO: |
103 | target->setType("audio"); | 103 | target->setType("audio"); |
104 | break; | 104 | break; |
105 | case MAILMIME_DISCRETE_TYPE_VIDEO: | 105 | case MAILMIME_DISCRETE_TYPE_VIDEO: |
106 | target->setType("video"); | 106 | target->setType("video"); |
107 | break; | 107 | break; |
108 | case MAILMIME_DISCRETE_TYPE_APPLICATION: | 108 | case MAILMIME_DISCRETE_TYPE_APPLICATION: |
109 | target->setType("application"); | 109 | target->setType("application"); |
110 | break; | 110 | break; |
111 | case MAILMIME_DISCRETE_TYPE_EXTENSION: | 111 | case MAILMIME_DISCRETE_TYPE_EXTENSION: |
112 | default: | 112 | default: |
113 | if (type->ct_type->tp_data.tp_discrete_type->dt_extension) { | 113 | if (type->ct_type->tp_data.tp_discrete_type->dt_extension) { |
114 | target->setType(type->ct_type->tp_data.tp_discrete_type->dt_extension); | 114 | target->setType(type->ct_type->tp_data.tp_discrete_type->dt_extension); |
115 | } | 115 | } |
116 | break; | 116 | break; |
117 | } | 117 | } |
118 | if (type->ct_parameters) { | 118 | if (type->ct_parameters) { |
119 | fillParameters(target,type->ct_parameters); | 119 | fillParameters(target,type->ct_parameters); |
120 | } | 120 | } |
121 | } | 121 | } |
122 | if (mime->mm_mime_fields && mime->mm_mime_fields->fld_list) { | 122 | if (mime->mm_mime_fields && mime->mm_mime_fields->fld_list) { |
123 | for (current=clist_begin(mime->mm_mime_fields->fld_list);current!=0;current=clist_next(current)) { | 123 | for (current=clist_begin(mime->mm_mime_fields->fld_list);current!=0;current=clist_next(current)) { |
124 | field = (mailmime_field*)current->data; | 124 | field = (mailmime_field*)current->data; |
125 | switch(field->fld_type) { | 125 | switch(field->fld_type) { |
126 | case MAILMIME_FIELD_TRANSFER_ENCODING: | 126 | case MAILMIME_FIELD_TRANSFER_ENCODING: |
127 | target->setEncoding(getencoding(field->fld_data.fld_encoding)); | 127 | target->setEncoding(getencoding(field->fld_data.fld_encoding)); |
128 | break; | 128 | break; |
129 | case MAILMIME_FIELD_ID: | 129 | case MAILMIME_FIELD_ID: |
130 | target->setIdentifier(field->fld_data.fld_id); | 130 | target->setIdentifier(field->fld_data.fld_id); |
131 | break; | 131 | break; |
132 | case MAILMIME_FIELD_DESCRIPTION: | 132 | case MAILMIME_FIELD_DESCRIPTION: |
133 | target->setDescription(field->fld_data.fld_description); | 133 | target->setDescription(field->fld_data.fld_description); |
134 | break; | 134 | break; |
135 | default: | 135 | default: |
136 | break; | 136 | break; |
137 | } | 137 | } |
138 | } | 138 | } |
139 | } | 139 | } |
140 | } | 140 | } |
141 | 141 | ||
142 | void Genericwrapper::fillParameters(RecPartP&target,clist*parameters) | 142 | void Genericwrapper::fillParameters(RecPartP&target,clist*parameters) |
143 | { | 143 | { |
144 | if (!parameters) {return;} | 144 | if (!parameters) {return;} |
145 | clistcell*current=0; | 145 | clistcell*current=0; |
146 | mailmime_parameter*param; | 146 | mailmime_parameter*param; |
147 | for (current=clist_begin(parameters);current!=0;current=clist_next(current)) { | 147 | for (current=clist_begin(parameters);current!=0;current=clist_next(current)) { |
148 | param = (mailmime_parameter*)current->data; | 148 | param = (mailmime_parameter*)current->data; |
149 | if (param) { | 149 | if (param) { |
150 | target->addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); | 150 | target->addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); |
151 | } | 151 | } |
152 | } | 152 | } |
153 | } | 153 | } |
154 | 154 | ||
155 | QString Genericwrapper::getencoding(mailmime_mechanism*aEnc) | 155 | QString Genericwrapper::getencoding(mailmime_mechanism*aEnc) |
156 | { | 156 | { |
157 | QString enc="7bit"; | 157 | QString enc="7bit"; |
158 | if (!aEnc) return enc; | 158 | if (!aEnc) return enc; |
159 | switch(aEnc->enc_type) { | 159 | switch(aEnc->enc_type) { |
160 | case MAILMIME_MECHANISM_7BIT: | 160 | case MAILMIME_MECHANISM_7BIT: |
161 | enc = "7bit"; | 161 | enc = "7bit"; |
162 | break; | 162 | break; |
163 | case MAILMIME_MECHANISM_8BIT: | 163 | case MAILMIME_MECHANISM_8BIT: |
164 | enc = "8bit"; | 164 | enc = "8bit"; |
165 | break; | 165 | break; |
166 | case MAILMIME_MECHANISM_BINARY: | 166 | case MAILMIME_MECHANISM_BINARY: |
167 | enc = "binary"; | 167 | enc = "binary"; |
168 | break; | 168 | break; |
169 | case MAILMIME_MECHANISM_QUOTED_PRINTABLE: | 169 | case MAILMIME_MECHANISM_QUOTED_PRINTABLE: |
170 | enc = "quoted-printable"; | 170 | enc = "quoted-printable"; |
171 | break; | 171 | break; |
172 | case MAILMIME_MECHANISM_BASE64: | 172 | case MAILMIME_MECHANISM_BASE64: |
173 | enc = "base64"; | 173 | enc = "base64"; |
174 | break; | 174 | break; |
175 | case MAILMIME_MECHANISM_TOKEN: | 175 | case MAILMIME_MECHANISM_TOKEN: |
176 | default: | 176 | default: |
177 | if (aEnc->enc_token) { | 177 | if (aEnc->enc_token) { |
178 | enc = QString(aEnc->enc_token); | 178 | enc = QString(aEnc->enc_token); |
179 | } | 179 | } |
180 | break; | 180 | break; |
181 | } | 181 | } |
182 | return enc; | 182 | return enc; |
183 | } | 183 | } |
184 | 184 | ||
185 | void Genericwrapper::traverseBody(RecBodyP&target,mailmessage*message,mailmime*mime,QValueList<int>recList,unsigned int current_rec,int current_count) | 185 | void Genericwrapper::traverseBody(RecBodyP&target,mailmessage*message,mailmime*mime,QValueList<int>recList,unsigned int current_rec,int current_count) |
186 | { | 186 | { |
187 | if (current_rec >= 10) { | 187 | if (current_rec >= 10) { |
188 | ; // odebug << "too deep recursion!" << oendl; | 188 | ; // odebug << "too deep recursion!" << oendl; |
189 | } | 189 | } |
190 | if (!message || !mime) { | 190 | if (!message || !mime) { |
191 | return; | 191 | return; |
192 | } | 192 | } |
193 | int r; | 193 | int r; |
194 | char*data = 0; | 194 | char*data = 0; |
195 | size_t len; | 195 | size_t len; |
196 | clistiter * cur = 0; | 196 | clistiter * cur = 0; |
197 | QString b; | 197 | QString b; |
198 | RecPartP part = new RecPart(); | 198 | RecPartP part = new RecPart(); |
199 | 199 | ||
200 | switch (mime->mm_type) { | 200 | switch (mime->mm_type) { |
201 | case MAILMIME_SINGLE: | 201 | case MAILMIME_SINGLE: |
202 | { | 202 | { |
203 | QValueList<int>countlist = recList; | 203 | QValueList<int>countlist = recList; |
204 | countlist.append(current_count); | 204 | countlist.append(current_count); |
205 | r = mailmessage_fetch_section(message,mime,&data,&len); | 205 | r = mailmessage_fetch_section(message,mime,&data,&len); |
206 | part->setSize(len); | 206 | part->setSize(len); |
207 | part->setPositionlist(countlist); | 207 | part->setPositionlist(countlist); |
208 | b = gen_attachment_id(); | 208 | b = gen_attachment_id(); |
209 | part->setIdentifier(b); | 209 | part->setIdentifier(b); |
210 | fillSingleBody(part,message,mime); | 210 | fillSingleBody(part,message,mime); |
211 | if (part->Type()=="text" && target->Bodytext().isNull()) { | 211 | if (part->Type()=="text" && target->Bodytext().isNull()) { |
212 | encodedString*rs = new encodedString(); | 212 | encodedString*rs = new encodedString(); |
213 | rs->setContent(data,len); | 213 | rs->setContent(data,len); |
214 | encodedString*res = decode_String(rs,part->Encoding()); | 214 | encodedString*res = decode_String(rs,part->Encoding()); |
215 | if (countlist.count()>2) { | 215 | if (countlist.count()>2) { |
216 | bodyCache[b]=rs; | 216 | bodyCache[b]=rs; |
217 | target->addPart(part); | 217 | target->addPart(part); |
218 | } else { | 218 | } else { |
219 | delete rs; | 219 | delete rs; |
220 | } | 220 | } |
221 | b = QString(res->Content()); | 221 | b = QString(res->Content()); |
222 | delete res; | 222 | delete res; |
223 | size_t index = 0; | 223 | size_t index = 0; |
224 | char*resu = 0; | 224 | char*resu = 0; |
225 | int err = MAILIMF_NO_ERROR; | 225 | int err = MAILIMF_NO_ERROR; |
226 | QString charset = part->searchParamter( "charset"); | 226 | QString charset = part->searchParamter( "charset"); |
227 | qDebug("CHARSET %s ",charset.latin1() ); | 227 | qDebug("CHARSET %s ",charset.latin1() ); |
228 | if ( !charset.isEmpty() ) { | 228 | if (false ) { |
229 | //if ( !charset.isEmpty() ) { | ||
229 | target->setCharset( charset ); | 230 | target->setCharset( charset ); |
230 | err = mailmime_encoded_phrase_parse(charset.latin1(), | 231 | err = mailmime_encoded_phrase_parse(charset.latin1(), |
231 | b.latin1(), b.length(),&index, "utf-8",&resu); | 232 | b.latin1(), b.length(),&index, "utf-8",&resu); |
232 | if (err == MAILIMF_NO_ERROR && resu && strlen(resu)) { | 233 | if (err == MAILIMF_NO_ERROR && resu && strlen(resu)) { |
233 | //qDebug("res %d %s ", index, resu); | 234 | //qDebug("res %d %s ", index, resu); |
234 | b = QString::fromUtf8(resu); | 235 | b = QString::fromUtf8(resu); |
235 | } | 236 | } |
236 | if (resu) free(resu); | 237 | if (resu) free(resu); |
237 | } | 238 | } |
238 | target->setBodytext(b); | 239 | target->setBodytext(b); |
239 | target->setDescription(part); | 240 | target->setDescription(part); |
240 | } else { | 241 | } else { |
241 | bodyCache[b]=new encodedString(data,len); | 242 | bodyCache[b]=new encodedString(data,len); |
242 | target->addPart(part); | 243 | target->addPart(part); |
243 | } | 244 | } |
244 | } | 245 | } |
245 | break; | 246 | break; |
246 | case MAILMIME_MULTIPLE: | 247 | case MAILMIME_MULTIPLE: |
247 | { | 248 | { |
248 | unsigned int ccount = 1; | 249 | unsigned int ccount = 1; |
249 | mailmime*cbody=0; | 250 | mailmime*cbody=0; |
250 | QValueList<int>countlist = recList; | 251 | QValueList<int>countlist = recList; |
251 | for (cur = clist_begin(mime->mm_data.mm_multipart.mm_mp_list) ; cur != NULL ; cur = clist_next(cur)) { | 252 | for (cur = clist_begin(mime->mm_data.mm_multipart.mm_mp_list) ; cur != NULL ; cur = clist_next(cur)) { |
252 | cbody = (mailmime*)clist_content(cur); | 253 | cbody = (mailmime*)clist_content(cur); |
253 | if (cbody->mm_type==MAILMIME_MULTIPLE) { | 254 | if (cbody->mm_type==MAILMIME_MULTIPLE) { |
254 | RecPartP targetPart = new RecPart(); | 255 | RecPartP targetPart = new RecPart(); |
255 | targetPart->setType("multipart"); | 256 | targetPart->setType("multipart"); |
256 | countlist.append(current_count); | 257 | countlist.append(current_count); |
257 | targetPart->setPositionlist(countlist); | 258 | targetPart->setPositionlist(countlist); |
258 | target->addPart(targetPart); | 259 | target->addPart(targetPart); |
259 | } | 260 | } |
260 | traverseBody(target,message, cbody,countlist,current_rec+1,ccount); | 261 | traverseBody(target,message, cbody,countlist,current_rec+1,ccount); |
261 | if (cbody->mm_type==MAILMIME_MULTIPLE) { | 262 | if (cbody->mm_type==MAILMIME_MULTIPLE) { |
262 | countlist = recList; | 263 | countlist = recList; |
263 | } | 264 | } |
264 | ++ccount; | 265 | ++ccount; |
265 | } | 266 | } |
266 | } | 267 | } |
267 | break; | 268 | break; |
268 | case MAILMIME_MESSAGE: | 269 | case MAILMIME_MESSAGE: |
269 | { | 270 | { |
270 | QValueList<int>countlist = recList; | 271 | QValueList<int>countlist = recList; |
271 | countlist.append(current_count); | 272 | countlist.append(current_count); |
272 | /* the own header is always at recursion 0 - we don't need that */ | 273 | /* the own header is always at recursion 0 - we don't need that */ |
273 | if (current_rec > 0) { | 274 | if (current_rec > 0) { |
274 | part->setPositionlist(countlist); | 275 | part->setPositionlist(countlist); |
275 | r = mailmessage_fetch_section(message,mime,&data,&len); | 276 | r = mailmessage_fetch_section(message,mime,&data,&len); |
276 | part->setSize(len); | 277 | part->setSize(len); |
277 | part->setPositionlist(countlist); | 278 | part->setPositionlist(countlist); |
278 | b = gen_attachment_id(); | 279 | b = gen_attachment_id(); |
279 | part->setIdentifier(b); | 280 | part->setIdentifier(b); |
280 | part->setType("message"); | 281 | part->setType("message"); |
281 | part->setSubtype("rfc822"); | 282 | part->setSubtype("rfc822"); |
282 | bodyCache[b]=new encodedString(data,len); | 283 | bodyCache[b]=new encodedString(data,len); |
283 | target->addPart(part); | 284 | target->addPart(part); |
284 | } | 285 | } |
285 | if (mime->mm_data.mm_message.mm_msg_mime != NULL) { | 286 | if (mime->mm_data.mm_message.mm_msg_mime != NULL) { |
286 | traverseBody(target,message,mime->mm_data.mm_message.mm_msg_mime,countlist,current_rec+1); | 287 | traverseBody(target,message,mime->mm_data.mm_message.mm_msg_mime,countlist,current_rec+1); |
287 | } | 288 | } |
288 | } | 289 | } |
289 | break; | 290 | break; |
290 | } | 291 | } |
291 | } | 292 | } |
292 | 293 | ||
293 | RecBodyP Genericwrapper::parseMail( mailmessage * msg ) | 294 | RecBodyP Genericwrapper::parseMail( mailmessage * msg ) |
294 | { | 295 | { |
295 | int err = MAILIMF_NO_ERROR; | 296 | int err = MAILIMF_NO_ERROR; |
296 | //mailmime_single_fields fields; | 297 | //mailmime_single_fields fields; |
297 | /* is bound to msg and will be freed there */ | 298 | /* is bound to msg and will be freed there */ |
298 | mailmime * mime=0; | 299 | mailmime * mime=0; |
299 | RecBodyP body = new RecBody(); | 300 | RecBodyP body = new RecBody(); |
300 | //memset(&fields, 0, sizeof(struct mailmime_single_fields)); | 301 | //memset(&fields, 0, sizeof(struct mailmime_single_fields)); |
301 | err = mailmessage_get_bodystructure(msg,&mime); | 302 | err = mailmessage_get_bodystructure(msg,&mime); |
302 | QValueList<int>recList; | 303 | QValueList<int>recList; |
303 | traverseBody(body,msg,mime,recList); | 304 | traverseBody(body,msg,mime,recList); |
304 | return body; | 305 | return body; |
305 | } | 306 | } |
306 | 307 | ||
307 | 308 | ||
308 | QString Genericwrapper::parseAddressList( mailimf_address_list *list ) | 309 | QString Genericwrapper::parseAddressList( mailimf_address_list *list ) |
309 | { | 310 | { |
310 | QString result( "" ); | 311 | QString result( "" ); |
311 | 312 | ||
312 | bool first = true; | 313 | bool first = true; |
313 | if (list == 0) return result; | 314 | if (list == 0) return result; |
314 | for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) { | 315 | for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) { |
315 | mailimf_address *addr = (mailimf_address *) current->data; | 316 | mailimf_address *addr = (mailimf_address *) current->data; |
316 | 317 | ||
317 | if ( !first ) { | 318 | if ( !first ) { |
318 | result.append( "," ); | 319 | result.append( "," ); |
319 | } else { | 320 | } else { |
320 | first = false; | 321 | first = false; |
321 | } | 322 | } |
322 | 323 | ||
323 | switch ( addr->ad_type ) { | 324 | switch ( addr->ad_type ) { |
324 | case MAILIMF_ADDRESS_MAILBOX: | 325 | case MAILIMF_ADDRESS_MAILBOX: |
325 | result.append( parseMailbox( addr->ad_data.ad_mailbox ) ); | 326 | result.append( parseMailbox( addr->ad_data.ad_mailbox ) ); |
326 | break; | 327 | break; |
327 | case MAILIMF_ADDRESS_GROUP: | 328 | case MAILIMF_ADDRESS_GROUP: |
328 | result.append( parseGroup( addr->ad_data.ad_group ) ); | 329 | result.append( parseGroup( addr->ad_data.ad_group ) ); |
329 | break; | 330 | break; |
330 | default: | 331 | default: |
331 | ; // odebug << "Generic: unkown mailimf address type" << oendl; | 332 | ; // odebug << "Generic: unkown mailimf address type" << oendl; |
332 | break; | 333 | break; |
333 | } | 334 | } |
334 | } | 335 | } |
335 | 336 | ||
336 | return result; | 337 | return result; |
337 | } | 338 | } |
338 | 339 | ||
339 | QString Genericwrapper::parseGroup( mailimf_group *group ) | 340 | QString Genericwrapper::parseGroup( mailimf_group *group ) |
340 | { | 341 | { |
341 | QString result( "" ); | 342 | QString result( "" ); |
342 | 343 | ||
343 | result.append( group->grp_display_name ); | 344 | result.append( group->grp_display_name ); |
344 | result.append( ": " ); | 345 | result.append( ": " ); |
345 | 346 | ||
346 | if ( group->grp_mb_list != NULL ) { | 347 | if ( group->grp_mb_list != NULL ) { |
347 | result.append( parseMailboxList( group->grp_mb_list ) ); | 348 | result.append( parseMailboxList( group->grp_mb_list ) ); |
348 | } | 349 | } |
349 | 350 | ||
350 | result.append( ";" ); | 351 | result.append( ";" ); |
351 | 352 | ||
352 | return result; | 353 | return result; |
353 | } | 354 | } |
354 | 355 | ||
355 | QString Genericwrapper::parseMailbox( mailimf_mailbox *box ) | 356 | QString Genericwrapper::parseMailbox( mailimf_mailbox *box ) |
356 | { | 357 | { |
357 | QString result( "" ); | 358 | QString result( "" ); |
358 | 359 | ||
359 | if ( box->mb_display_name == NULL ) { | 360 | if ( box->mb_display_name == NULL ) { |
360 | result.append( box->mb_addr_spec ); | 361 | result.append( box->mb_addr_spec ); |
361 | } else { | 362 | } else { |
362 | result.append( convert_String(box->mb_display_name) ); | 363 | result.append( convert_String(box->mb_display_name) ); |
363 | result.append( " <" ); | 364 | result.append( " <" ); |
364 | result.append( box->mb_addr_spec ); | 365 | result.append( box->mb_addr_spec ); |
365 | result.append( ">" ); | 366 | result.append( ">" ); |
366 | } | 367 | } |
367 | 368 | ||
368 | return result; | 369 | return result; |
369 | } | 370 | } |
370 | 371 | ||
371 | QString Genericwrapper::parseMailboxList( mailimf_mailbox_list *list ) | 372 | QString Genericwrapper::parseMailboxList( mailimf_mailbox_list *list ) |
372 | { | 373 | { |
373 | QString result( "" ); | 374 | QString result( "" ); |
374 | 375 | ||
375 | bool first = true; | 376 | bool first = true; |
376 | for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) { | 377 | for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) { |
377 | mailimf_mailbox *box = (mailimf_mailbox *) current->data; | 378 | mailimf_mailbox *box = (mailimf_mailbox *) current->data; |
378 | 379 | ||
379 | if ( !first ) { | 380 | if ( !first ) { |
380 | result.append( "," ); | 381 | result.append( "," ); |
381 | } else { | 382 | } else { |
382 | first = false; | 383 | first = false; |
383 | } | 384 | } |
384 | 385 | ||
385 | result.append( parseMailbox( box ) ); | 386 | result.append( parseMailbox( box ) ); |
386 | } | 387 | } |
387 | 388 | ||
388 | return result; | 389 | return result; |
389 | } | 390 | } |
390 | 391 | ||
391 | encodedString* Genericwrapper::fetchDecodedPart(const RecMailP&,const RecPartP&part) | 392 | encodedString* Genericwrapper::fetchDecodedPart(const RecMailP&,const RecPartP&part) |
392 | { | 393 | { |
393 | QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part->Identifier()); | 394 | QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part->Identifier()); |
394 | if (it==bodyCache.end()) return new encodedString(); | 395 | if (it==bodyCache.end()) return new encodedString(); |
395 | encodedString*t = decode_String(it.data(),part->Encoding()); | 396 | encodedString*t = decode_String(it.data(),part->Encoding()); |
396 | return t; | 397 | return t; |
397 | } | 398 | } |
398 | 399 | ||
399 | encodedString* Genericwrapper::fetchRawPart(const RecMailP&,const RecPartP&part) | 400 | encodedString* Genericwrapper::fetchRawPart(const RecMailP&,const RecPartP&part) |
400 | { | 401 | { |
401 | QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part->Identifier()); | 402 | QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part->Identifier()); |
402 | if (it==bodyCache.end()) return new encodedString(); | 403 | if (it==bodyCache.end()) return new encodedString(); |
403 | encodedString*t = it.data(); | 404 | encodedString*t = it.data(); |
404 | return t; | 405 | return t; |
405 | } | 406 | } |
406 | 407 | ||
407 | QString Genericwrapper::fetchTextPart(const RecMailP&mail,const RecPartP&part) | 408 | QString Genericwrapper::fetchTextPart(const RecMailP&mail,const RecPartP&part) |
408 | { | 409 | { |
409 | encodedString*t = fetchDecodedPart(mail,part); | 410 | encodedString*t = fetchDecodedPart(mail,part); |
410 | QString text=t->Content(); | 411 | QString text=t->Content(); |
411 | delete t; | 412 | delete t; |
412 | return text; | 413 | return text; |
413 | } | 414 | } |
414 | 415 | ||
415 | void Genericwrapper::cleanMimeCache() | 416 | void Genericwrapper::cleanMimeCache() |
416 | { | 417 | { |
417 | QMap<QString,encodedString*>::Iterator it = bodyCache.begin(); | 418 | QMap<QString,encodedString*>::Iterator it = bodyCache.begin(); |
418 | for (;it!=bodyCache.end();++it) { | 419 | for (;it!=bodyCache.end();++it) { |
419 | encodedString*t = it.data(); | 420 | encodedString*t = it.data(); |
420 | //it.setValue(0); | 421 | //it.setValue(0); |
421 | if (t) delete t; | 422 | if (t) delete t; |
422 | } | 423 | } |
423 | bodyCache.clear(); | 424 | bodyCache.clear(); |
424 | ; // odebug << "Genericwrapper: cache cleaned" << oendl; | 425 | ; // odebug << "Genericwrapper: cache cleaned" << oendl; |
425 | } | 426 | } |
426 | 427 | ||
427 | QStringList Genericwrapper::parseInreplies(mailimf_in_reply_to * in_replies) | 428 | QStringList Genericwrapper::parseInreplies(mailimf_in_reply_to * in_replies) |
428 | { | 429 | { |
429 | QStringList res; | 430 | QStringList res; |
430 | if (!in_replies || !in_replies->mid_list) return res; | 431 | if (!in_replies || !in_replies->mid_list) return res; |
431 | clistiter * current = 0; | 432 | clistiter * current = 0; |
432 | for ( current = clist_begin( in_replies->mid_list ); current != NULL; current = current->next ) { | 433 | for ( current = clist_begin( in_replies->mid_list ); current != NULL; current = current->next ) { |
433 | QString h((char*)current->data); | 434 | QString h((char*)current->data); |
434 | while (h.length()>0 && h[0]=='<') { | 435 | while (h.length()>0 && h[0]=='<') { |
435 | h.remove(0,1); | 436 | h.remove(0,1); |
436 | } | 437 | } |
437 | while (h.length()>0 && h[h.length()-1]=='>') { | 438 | while (h.length()>0 && h[h.length()-1]=='>') { |
438 | h.remove(h.length()-1,1); | 439 | h.remove(h.length()-1,1); |
439 | } | 440 | } |
440 | if (h.length()>0) { | 441 | if (h.length()>0) { |
441 | res.append(h); | 442 | res.append(h); |
442 | } | 443 | } |
443 | } | 444 | } |
444 | return res; | 445 | return res; |
445 | } | 446 | } |
446 | 447 | ||
447 | void Genericwrapper::parseList(QValueList<Opie::Core::OSmartPointer<RecMail> > &target,mailsession*session,const QString&mailbox,bool mbox_as_to, int maxSizeInKb) | 448 | void Genericwrapper::parseList(QValueList<Opie::Core::OSmartPointer<RecMail> > &target,mailsession*session,const QString&mailbox,bool mbox_as_to, int maxSizeInKb) |
448 | { | 449 | { |
449 | int r; | 450 | int r; |
450 | mailmessage_list * env_list = 0; | 451 | mailmessage_list * env_list = 0; |
451 | r = mailsession_get_messages_list(session,&env_list); | 452 | r = mailsession_get_messages_list(session,&env_list); |
452 | if (r != MAIL_NO_ERROR) { | 453 | if (r != MAIL_NO_ERROR) { |
453 | ; // odebug << "Error message list" << oendl; | 454 | ; // odebug << "Error message list" << oendl; |
454 | return; | 455 | return; |
455 | } | 456 | } |
456 | r = mailsession_get_envelopes_list(session, env_list); | 457 | r = mailsession_get_envelopes_list(session, env_list); |
457 | if (r != MAIL_NO_ERROR) { | 458 | if (r != MAIL_NO_ERROR) { |
458 | ; // odebug << "Error filling message list" << oendl; | 459 | ; // odebug << "Error filling message list" << oendl; |
459 | if (env_list) { | 460 | if (env_list) { |
460 | mailmessage_list_free(env_list); | 461 | mailmessage_list_free(env_list); |
461 | } | 462 | } |
462 | return; | 463 | return; |
463 | } | 464 | } |
464 | mailimf_references * refs = 0; | 465 | mailimf_references * refs = 0; |
465 | mailimf_in_reply_to * in_replies = 0; | 466 | mailimf_in_reply_to * in_replies = 0; |
466 | uint32_t i = 0; | 467 | uint32_t i = 0; |
467 | for(; i < carray_count(env_list->msg_tab) ; ++i) { | 468 | for(; i < carray_count(env_list->msg_tab) ; ++i) { |
468 | mailmessage * msg; | 469 | mailmessage * msg; |
469 | QBitArray mFlags(7); | 470 | QBitArray mFlags(7); |
470 | msg = (mailmessage*)carray_get(env_list->msg_tab, i); | 471 | msg = (mailmessage*)carray_get(env_list->msg_tab, i); |
471 | if (msg->msg_fields == NULL) { | 472 | if (msg->msg_fields == NULL) { |
472 | //; // odebug << "could not fetch envelope of message " << i << "" << oendl; | 473 | //; // odebug << "could not fetch envelope of message " << i << "" << oendl; |
473 | continue; | 474 | continue; |
474 | } | 475 | } |
475 | RecMailP mail = new RecMail(); | 476 | RecMailP mail = new RecMail(); |
476 | mail->setWrapper(this); | 477 | mail->setWrapper(this); |
477 | mail_flags * flag_result = 0; | 478 | mail_flags * flag_result = 0; |
478 | r = mailmessage_get_flags(msg,&flag_result); | 479 | r = mailmessage_get_flags(msg,&flag_result); |
479 | if (r == MAIL_ERROR_NOT_IMPLEMENTED) { | 480 | if (r == MAIL_ERROR_NOT_IMPLEMENTED) { |
480 | mFlags.setBit(FLAG_SEEN); | 481 | mFlags.setBit(FLAG_SEEN); |
481 | } | 482 | } |
482 | mailimf_single_fields single_fields; | 483 | mailimf_single_fields single_fields; |
483 | mailimf_single_fields_init(&single_fields, msg->msg_fields); | 484 | mailimf_single_fields_init(&single_fields, msg->msg_fields); |
484 | mail->setMsgsize(msg->msg_size); | 485 | mail->setMsgsize(msg->msg_size); |
485 | mail->setFlags(mFlags); | 486 | mail->setFlags(mFlags); |
486 | mail->setMbox(mailbox); | 487 | mail->setMbox(mailbox); |
487 | mail->setNumber(msg->msg_index); | 488 | mail->setNumber(msg->msg_index); |
488 | if (single_fields.fld_subject) | 489 | if (single_fields.fld_subject) |
489 | mail->setSubject( convert_String(single_fields.fld_subject->sbj_value)); | 490 | mail->setSubject( convert_String(single_fields.fld_subject->sbj_value)); |
490 | if (single_fields.fld_from) | 491 | if (single_fields.fld_from) |
491 | mail->setFrom(parseMailboxList(single_fields.fld_from->frm_mb_list)); | 492 | mail->setFrom(parseMailboxList(single_fields.fld_from->frm_mb_list)); |
492 | if (!mbox_as_to) { | 493 | if (!mbox_as_to) { |
493 | if (single_fields.fld_to) | 494 | if (single_fields.fld_to) |
494 | mail->setTo( parseAddressList( single_fields.fld_to->to_addr_list ) ); | 495 | mail->setTo( parseAddressList( single_fields.fld_to->to_addr_list ) ); |
495 | } else { | 496 | } else { |
496 | mail->setTo(mailbox); | 497 | mail->setTo(mailbox); |
497 | } | 498 | } |
498 | if (single_fields.fld_cc) | 499 | if (single_fields.fld_cc) |
499 | mail->setCC( parseAddressList( single_fields.fld_cc->cc_addr_list ) ); | 500 | mail->setCC( parseAddressList( single_fields.fld_cc->cc_addr_list ) ); |
500 | if (single_fields.fld_bcc) | 501 | if (single_fields.fld_bcc) |
501 | mail->setBcc( parseAddressList( single_fields.fld_bcc->bcc_addr_list ) ); | 502 | mail->setBcc( parseAddressList( single_fields.fld_bcc->bcc_addr_list ) ); |
502 | if (single_fields.fld_orig_date) { | 503 | if (single_fields.fld_orig_date) { |
503 | QDateTime dt = Genericwrapper::parseDateTime( single_fields.fld_orig_date->dt_date_time ); | 504 | QDateTime dt = Genericwrapper::parseDateTime( single_fields.fld_orig_date->dt_date_time ); |
504 | QString ret; | 505 | QString ret; |
505 | if ( dt.date() == QDate::currentDate () ) | 506 | if ( dt.date() == QDate::currentDate () ) |
506 | ret = KGlobal::locale()->formatTime( dt.time(),true); | 507 | ret = KGlobal::locale()->formatTime( dt.time(),true); |
507 | else { | 508 | else { |
508 | ret = KGlobal::locale()->formatDateTime( dt,true,true); | 509 | ret = KGlobal::locale()->formatDateTime( dt,true,true); |
509 | } | 510 | } |
510 | mail->setDate( ret ); | 511 | mail->setDate( ret ); |
511 | char tmp[20]; | 512 | char tmp[20]; |
512 | snprintf( tmp, 20, "%04i-%02i-%02i %02i:%02i:%02i", | 513 | snprintf( tmp, 20, "%04i-%02i-%02i %02i:%02i:%02i", |
513 | dt.date().year(),dt.date().month(), dt.date().day(), dt.time().hour(), dt.time().minute(), dt.time().second() ); | 514 | dt.date().year(),dt.date().month(), dt.date().day(), dt.time().hour(), dt.time().minute(), dt.time().second() ); |
514 | //qDebug(" iso %s ", tmp); | 515 | //qDebug(" iso %s ", tmp); |
515 | mail->setIsoDate( QString( tmp ) ); | 516 | mail->setIsoDate( QString( tmp ) ); |
516 | } | 517 | } |
517 | // crashes when accessing pop3 account? | 518 | // crashes when accessing pop3 account? |
518 | if (single_fields.fld_message_id) { | 519 | if (single_fields.fld_message_id) { |
519 | mail->setMsgid(QString(single_fields.fld_message_id->mid_value)); | 520 | mail->setMsgid(QString(single_fields.fld_message_id->mid_value)); |
520 | ; // odebug << "Msgid == " << mail->Msgid().latin1() << "" << oendl; | 521 | ; // odebug << "Msgid == " << mail->Msgid().latin1() << "" << oendl; |
521 | } | 522 | } |
522 | if (single_fields.fld_reply_to) { | 523 | if (single_fields.fld_reply_to) { |
523 | QStringList t = parseAddressList(single_fields.fld_reply_to->rt_addr_list); | 524 | QStringList t = parseAddressList(single_fields.fld_reply_to->rt_addr_list); |
524 | if (t.count()>0) { | 525 | if (t.count()>0) { |
525 | mail->setReplyto(t[0]); | 526 | mail->setReplyto(t[0]); |
526 | } | 527 | } |
527 | } | 528 | } |
528 | #if 0 | 529 | #if 0 |
529 | refs = single_fields.fld_references; | 530 | refs = single_fields.fld_references; |
530 | if (refs && refs->mid_list && clist_count(refs->mid_list)) { | 531 | if (refs && refs->mid_list && clist_count(refs->mid_list)) { |
531 | char * text = (char*)refs->mid_list->first->data; | 532 | char * text = (char*)refs->mid_list->first->data; |
532 | mail->setReplyto(QString(text)); | 533 | mail->setReplyto(QString(text)); |
533 | } | 534 | } |
534 | #endif | 535 | #endif |
535 | if (single_fields.fld_in_reply_to && single_fields.fld_in_reply_to->mid_list && | 536 | if (single_fields.fld_in_reply_to && single_fields.fld_in_reply_to->mid_list && |
536 | clist_count(single_fields.fld_in_reply_to->mid_list)) { | 537 | clist_count(single_fields.fld_in_reply_to->mid_list)) { |
537 | mail->setInreply(parseInreplies(single_fields.fld_in_reply_to)); | 538 | mail->setInreply(parseInreplies(single_fields.fld_in_reply_to)); |
538 | } | 539 | } |
539 | if ( maxSizeInKb == 0 || mail->Msgsize()<=maxSizeInKb*1024 ) | 540 | if ( maxSizeInKb == 0 || mail->Msgsize()<=maxSizeInKb*1024 ) |
540 | target.append(mail); | 541 | target.append(mail); |
541 | } | 542 | } |
542 | if (env_list) { | 543 | if (env_list) { |
543 | mailmessage_list_free(env_list); | 544 | mailmessage_list_free(env_list); |
544 | } | 545 | } |
545 | } | 546 | } |
diff --git a/kmicromail/libmailwrapper/imapwrapper.cpp b/kmicromail/libmailwrapper/imapwrapper.cpp index 2a54381..da7065f 100644 --- a/kmicromail/libmailwrapper/imapwrapper.cpp +++ b/kmicromail/libmailwrapper/imapwrapper.cpp | |||
@@ -1,1359 +1,1359 @@ | |||
1 | // CHANGED 2004-09-31 Lutz Rogowski | 1 | // CHANGED 2004-09-31 Lutz Rogowski |
2 | #include <stdlib.h> | 2 | #include <stdlib.h> |
3 | #include <libetpan/libetpan.h> | 3 | #include <libetpan/libetpan.h> |
4 | #include <qpe/global.h> | 4 | #include <qpe/global.h> |
5 | #include <qapplication.h> | 5 | #include <qapplication.h> |
6 | #include "imapwrapper.h" | 6 | #include "imapwrapper.h" |
7 | #include "mailtypes.h" | 7 | #include "mailtypes.h" |
8 | #include "logindialog.h" | 8 | #include "logindialog.h" |
9 | #include <qprogressbar.h> | 9 | #include <qprogressbar.h> |
10 | #include "genericwrapper.h" | 10 | #include "genericwrapper.h" |
11 | #include <kglobal.h> | 11 | #include <kglobal.h> |
12 | 12 | ||
13 | using namespace Opie::Core; | 13 | using namespace Opie::Core; |
14 | int IMAPwrapper::mMax = 0; | 14 | int IMAPwrapper::mMax = 0; |
15 | int IMAPwrapper::mCurrent = 0; | 15 | int IMAPwrapper::mCurrent = 0; |
16 | 16 | ||
17 | IMAPwrapper::IMAPwrapper( IMAPaccount *a ) | 17 | IMAPwrapper::IMAPwrapper( IMAPaccount *a ) |
18 | : AbstractMail() | 18 | : AbstractMail() |
19 | { | 19 | { |
20 | account = a; | 20 | account = a; |
21 | m_imap = 0; | 21 | m_imap = 0; |
22 | m_Lastmbox = ""; | 22 | m_Lastmbox = ""; |
23 | mCurrent = 0; | 23 | mCurrent = 0; |
24 | mMax = 0; | 24 | mMax = 0; |
25 | } | 25 | } |
26 | 26 | ||
27 | IMAPwrapper::~IMAPwrapper() | 27 | IMAPwrapper::~IMAPwrapper() |
28 | { | 28 | { |
29 | logout(); | 29 | logout(); |
30 | } | 30 | } |
31 | 31 | ||
32 | /* to avoid to often select statements in loops etc. | 32 | /* to avoid to often select statements in loops etc. |
33 | we trust that we are logged in and connection is established!*/ | 33 | we trust that we are logged in and connection is established!*/ |
34 | int IMAPwrapper::selectMbox(const QString&mbox) | 34 | int IMAPwrapper::selectMbox(const QString&mbox) |
35 | { | 35 | { |
36 | if (mbox == m_Lastmbox) { | 36 | if (mbox == m_Lastmbox) { |
37 | return MAILIMAP_NO_ERROR; | 37 | return MAILIMAP_NO_ERROR; |
38 | } | 38 | } |
39 | int err = mailimap_select( m_imap, (char*)mbox.latin1()); | 39 | int err = mailimap_select( m_imap, (char*)mbox.latin1()); |
40 | if ( err != MAILIMAP_NO_ERROR ) { | 40 | if ( err != MAILIMAP_NO_ERROR ) { |
41 | m_Lastmbox = ""; | 41 | m_Lastmbox = ""; |
42 | return err; | 42 | return err; |
43 | } | 43 | } |
44 | m_Lastmbox = mbox; | 44 | m_Lastmbox = mbox; |
45 | return err; | 45 | return err; |
46 | } | 46 | } |
47 | 47 | ||
48 | void IMAPwrapper::imap_progress( size_t current, size_t maximum ) | 48 | void IMAPwrapper::imap_progress( size_t current, size_t maximum ) |
49 | { | 49 | { |
50 | //qDebug("imap progress %d of %d ",current,maximum ); | 50 | //qDebug("imap progress %d of %d ",current,maximum ); |
51 | //Global::statusMessage(i18n("Downloading message %1 of %2").arg( current).arg(maximum)); | 51 | //Global::statusMessage(i18n("Downloading message %1 of %2").arg( current).arg(maximum)); |
52 | //qApp->processEvents() | 52 | //qApp->processEvents() |
53 | static unsigned int last = 0; | 53 | static unsigned int last = 0; |
54 | if ( last != current ) | 54 | if ( last != current ) |
55 | IMAPwrapper::progress(); | 55 | IMAPwrapper::progress(); |
56 | last = current; | 56 | last = current; |
57 | } | 57 | } |
58 | void IMAPwrapper::progress( QString m ) | 58 | void IMAPwrapper::progress( QString m ) |
59 | { | 59 | { |
60 | 60 | ||
61 | static QString mProgrMess; | 61 | static QString mProgrMess; |
62 | if ( m != QString::null ) { | 62 | if ( m != QString::null ) { |
63 | mProgrMess = m; | 63 | mProgrMess = m; |
64 | mCurrent = 1; | 64 | mCurrent = 1; |
65 | return; | 65 | return; |
66 | } | 66 | } |
67 | QString mess; | 67 | QString mess; |
68 | //qDebug("progress "); | 68 | //qDebug("progress "); |
69 | if ( mMax ) mess = mProgrMess +i18n(" message %1 of %2").arg( mCurrent++).arg(mMax); | 69 | if ( mMax ) mess = mProgrMess +i18n(" message %1 of %2").arg( mCurrent++).arg(mMax); |
70 | else mess = mProgrMess +i18n(" message %1").arg( mCurrent++); | 70 | else mess = mProgrMess +i18n(" message %1").arg( mCurrent++); |
71 | Global::statusMessage(mess); | 71 | Global::statusMessage(mess); |
72 | //qDebug("Progress %s %s", mess.latin1(), m.latin1()); | 72 | //qDebug("Progress %s %s", mess.latin1(), m.latin1()); |
73 | qApp->processEvents(); | 73 | qApp->processEvents(); |
74 | } | 74 | } |
75 | bool IMAPwrapper::start_tls(bool force_tls) | 75 | bool IMAPwrapper::start_tls(bool force_tls) |
76 | { | 76 | { |
77 | int err; | 77 | int err; |
78 | bool try_tls = force_tls; | 78 | bool try_tls = force_tls; |
79 | mailimap_capability_data * cap_data = 0; | 79 | mailimap_capability_data * cap_data = 0; |
80 | 80 | ||
81 | err = mailimap_capability(m_imap,&cap_data); | 81 | err = mailimap_capability(m_imap,&cap_data); |
82 | if (err != MAILIMAP_NO_ERROR) { | 82 | if (err != MAILIMAP_NO_ERROR) { |
83 | Global::statusMessage("error getting capabilities!"); | 83 | Global::statusMessage("error getting capabilities!"); |
84 | return false; | 84 | return false; |
85 | } | 85 | } |
86 | clistiter * cur; | 86 | clistiter * cur; |
87 | for(cur = clist_begin(cap_data->cap_list) ; cur != NULL;cur = clist_next(cur)) { | 87 | for(cur = clist_begin(cap_data->cap_list) ; cur != NULL;cur = clist_next(cur)) { |
88 | struct mailimap_capability * cap; | 88 | struct mailimap_capability * cap; |
89 | cap = (struct mailimap_capability *)clist_content(cur); | 89 | cap = (struct mailimap_capability *)clist_content(cur); |
90 | if (cap->cap_type == MAILIMAP_CAPABILITY_NAME) { | 90 | if (cap->cap_type == MAILIMAP_CAPABILITY_NAME) { |
91 | if (strcasecmp(cap->cap_data.cap_name, "STARTTLS") == 0) { | 91 | if (strcasecmp(cap->cap_data.cap_name, "STARTTLS") == 0) { |
92 | try_tls = true; | 92 | try_tls = true; |
93 | break; | 93 | break; |
94 | } | 94 | } |
95 | } | 95 | } |
96 | } | 96 | } |
97 | if (cap_data) { | 97 | if (cap_data) { |
98 | mailimap_capability_data_free(cap_data); | 98 | mailimap_capability_data_free(cap_data); |
99 | } | 99 | } |
100 | if (try_tls) { | 100 | if (try_tls) { |
101 | err = mailimap_starttls(m_imap); | 101 | err = mailimap_starttls(m_imap); |
102 | if (err != MAILIMAP_NO_ERROR && force_tls) { | 102 | if (err != MAILIMAP_NO_ERROR && force_tls) { |
103 | Global::statusMessage(i18n("Server has no TLS support!")); | 103 | Global::statusMessage(i18n("Server has no TLS support!")); |
104 | try_tls = false; | 104 | try_tls = false; |
105 | } else { | 105 | } else { |
106 | mailstream_low * low; | 106 | mailstream_low * low; |
107 | mailstream_low * new_low; | 107 | mailstream_low * new_low; |
108 | low = mailstream_get_low(m_imap->imap_stream); | 108 | low = mailstream_get_low(m_imap->imap_stream); |
109 | if (!low) { | 109 | if (!low) { |
110 | try_tls = false; | 110 | try_tls = false; |
111 | } else { | 111 | } else { |
112 | int fd = mailstream_low_get_fd(low); | 112 | int fd = mailstream_low_get_fd(low); |
113 | if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) { | 113 | if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) { |
114 | mailstream_low_free(low); | 114 | mailstream_low_free(low); |
115 | mailstream_set_low(m_imap->imap_stream, new_low); | 115 | mailstream_set_low(m_imap->imap_stream, new_low); |
116 | } else { | 116 | } else { |
117 | try_tls = false; | 117 | try_tls = false; |
118 | } | 118 | } |
119 | } | 119 | } |
120 | } | 120 | } |
121 | } | 121 | } |
122 | return try_tls; | 122 | return try_tls; |
123 | } | 123 | } |
124 | 124 | ||
125 | void IMAPwrapper::login() | 125 | void IMAPwrapper::login() |
126 | { | 126 | { |
127 | QString server, user, pass; | 127 | QString server, user, pass; |
128 | uint16_t port; | 128 | uint16_t port; |
129 | int err = MAILIMAP_NO_ERROR; | 129 | int err = MAILIMAP_NO_ERROR; |
130 | 130 | ||
131 | if (account->getOffline()) return; | 131 | if (account->getOffline()) return; |
132 | /* we are connected this moment */ | 132 | /* we are connected this moment */ |
133 | /* TODO: setup a timer holding the line or if connection closed - delete the value */ | 133 | /* TODO: setup a timer holding the line or if connection closed - delete the value */ |
134 | if (m_imap) { | 134 | if (m_imap) { |
135 | err = mailimap_noop(m_imap); | 135 | err = mailimap_noop(m_imap); |
136 | if (err!=MAILIMAP_NO_ERROR) { | 136 | if (err!=MAILIMAP_NO_ERROR) { |
137 | logout(); | 137 | logout(); |
138 | } else { | 138 | } else { |
139 | mailstream_flush(m_imap->imap_stream); | 139 | mailstream_flush(m_imap->imap_stream); |
140 | return; | 140 | return; |
141 | } | 141 | } |
142 | } | 142 | } |
143 | server = account->getServer(); | 143 | server = account->getServer(); |
144 | port = account->getPort().toUInt(); | 144 | port = account->getPort().toUInt(); |
145 | if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { | 145 | if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { |
146 | LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); | 146 | LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); |
147 | login.show(); | 147 | login.show(); |
148 | if ( QDialog::Accepted == login.exec() ) { | 148 | if ( QDialog::Accepted == login.exec() ) { |
149 | // ok | 149 | // ok |
150 | user = login.getUser(); | 150 | user = login.getUser(); |
151 | pass = login.getPassword(); | 151 | pass = login.getPassword(); |
152 | } else { | 152 | } else { |
153 | // cancel | 153 | // cancel |
154 | return; | 154 | return; |
155 | } | 155 | } |
156 | } else { | 156 | } else { |
157 | user = account->getUser(); | 157 | user = account->getUser(); |
158 | pass = account->getPassword(); | 158 | pass = account->getPassword(); |
159 | } | 159 | } |
160 | 160 | ||
161 | m_imap = mailimap_new( 20, &imap_progress ); | 161 | m_imap = mailimap_new( 20, &imap_progress ); |
162 | 162 | ||
163 | /* connect */ | 163 | /* connect */ |
164 | bool ssl = false; | 164 | bool ssl = false; |
165 | bool try_tls = false; | 165 | bool try_tls = false; |
166 | bool force_tls = false; | 166 | bool force_tls = false; |
167 | 167 | ||
168 | if ( account->ConnectionType() == 2 ) { | 168 | if ( account->ConnectionType() == 2 ) { |
169 | ssl = true; | 169 | ssl = true; |
170 | } | 170 | } |
171 | if (account->ConnectionType()==1) { | 171 | if (account->ConnectionType()==1) { |
172 | force_tls = true; | 172 | force_tls = true; |
173 | } | 173 | } |
174 | 174 | ||
175 | if ( ssl ) { | 175 | if ( ssl ) { |
176 | qDebug("using ssl "); | 176 | qDebug("using ssl "); |
177 | err = mailimap_ssl_connect( m_imap, (char*)server.latin1(), port ); | 177 | err = mailimap_ssl_connect( m_imap, (char*)server.latin1(), port ); |
178 | qDebug("back "); | 178 | qDebug("back "); |
179 | } else { | 179 | } else { |
180 | err = mailimap_socket_connect( m_imap, (char*)server.latin1(), port ); | 180 | err = mailimap_socket_connect( m_imap, (char*)server.latin1(), port ); |
181 | } | 181 | } |
182 | 182 | ||
183 | if ( err != MAILIMAP_NO_ERROR && | 183 | if ( err != MAILIMAP_NO_ERROR && |
184 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && | 184 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && |
185 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { | 185 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { |
186 | QString failure = ""; | 186 | QString failure = ""; |
187 | if (err == MAILIMAP_ERROR_CONNECTION_REFUSED) { | 187 | if (err == MAILIMAP_ERROR_CONNECTION_REFUSED) { |
188 | failure="Connection refused"; | 188 | failure="Connection refused"; |
189 | } else { | 189 | } else { |
190 | failure="Unknown failure"; | 190 | failure="Unknown failure"; |
191 | } | 191 | } |
192 | Global::statusMessage(i18n("error connecting imap server: %1").arg(failure)); | 192 | Global::statusMessage(i18n("error connecting imap server: %1").arg(failure)); |
193 | mailimap_free( m_imap ); | 193 | mailimap_free( m_imap ); |
194 | m_imap = 0; | 194 | m_imap = 0; |
195 | return; | 195 | return; |
196 | } | 196 | } |
197 | 197 | ||
198 | if (!ssl) { | 198 | if (!ssl) { |
199 | try_tls = start_tls(force_tls); | 199 | try_tls = start_tls(force_tls); |
200 | } | 200 | } |
201 | 201 | ||
202 | bool ok = true; | 202 | bool ok = true; |
203 | if (force_tls && !try_tls) { | 203 | if (force_tls && !try_tls) { |
204 | Global::statusMessage(i18n("Server has no TLS support!")); | 204 | Global::statusMessage(i18n("Server has no TLS support!")); |
205 | ok = false; | 205 | ok = false; |
206 | } | 206 | } |
207 | 207 | ||
208 | 208 | ||
209 | /* login */ | 209 | /* login */ |
210 | 210 | ||
211 | if (ok) { | 211 | if (ok) { |
212 | err = mailimap_login_simple( m_imap, (char*)user.latin1(), (char*)pass.latin1() ); | 212 | err = mailimap_login_simple( m_imap, (char*)user.latin1(), (char*)pass.latin1() ); |
213 | if ( err != MAILIMAP_NO_ERROR ) { | 213 | if ( err != MAILIMAP_NO_ERROR ) { |
214 | Global::statusMessage(i18n("error logging in imap server: %1").arg(m_imap->imap_response)); | 214 | Global::statusMessage(i18n("error logging in imap server: %1").arg(m_imap->imap_response)); |
215 | ok = false; | 215 | ok = false; |
216 | } | 216 | } |
217 | } | 217 | } |
218 | if (!ok) { | 218 | if (!ok) { |
219 | err = mailimap_close( m_imap ); | 219 | err = mailimap_close( m_imap ); |
220 | mailimap_free( m_imap ); | 220 | mailimap_free( m_imap ); |
221 | m_imap = 0; | 221 | m_imap = 0; |
222 | } | 222 | } |
223 | } | 223 | } |
224 | 224 | ||
225 | void IMAPwrapper::logout() | 225 | void IMAPwrapper::logout() |
226 | { | 226 | { |
227 | int err = MAILIMAP_NO_ERROR; | 227 | int err = MAILIMAP_NO_ERROR; |
228 | if (!m_imap) return; | 228 | if (!m_imap) return; |
229 | err = mailimap_logout( m_imap ); | 229 | err = mailimap_logout( m_imap ); |
230 | err = mailimap_close( m_imap ); | 230 | err = mailimap_close( m_imap ); |
231 | mailimap_free( m_imap ); | 231 | mailimap_free( m_imap ); |
232 | m_imap = 0; | 232 | m_imap = 0; |
233 | m_Lastmbox = ""; | 233 | m_Lastmbox = ""; |
234 | } | 234 | } |
235 | 235 | ||
236 | void IMAPwrapper::listMessages(const QString&mailbox,QValueList<Opie::Core::OSmartPointer<RecMail> > &target , int maxSizeInKb) | 236 | void IMAPwrapper::listMessages(const QString&mailbox,QValueList<Opie::Core::OSmartPointer<RecMail> > &target , int maxSizeInKb) |
237 | { | 237 | { |
238 | 238 | ||
239 | int tryAgain = 1; | 239 | int tryAgain = 1; |
240 | while ( tryAgain >= 0 ) { | 240 | while ( tryAgain >= 0 ) { |
241 | int err = MAILIMAP_NO_ERROR; | 241 | int err = MAILIMAP_NO_ERROR; |
242 | clist *result = 0; | 242 | clist *result = 0; |
243 | clistcell *current; | 243 | clistcell *current; |
244 | mailimap_fetch_type *fetchType = 0; | 244 | mailimap_fetch_type *fetchType = 0; |
245 | mailimap_set *set = 0; | 245 | mailimap_set *set = 0; |
246 | 246 | ||
247 | login(); | 247 | login(); |
248 | if (!m_imap) { | 248 | if (!m_imap) { |
249 | return; | 249 | return; |
250 | } | 250 | } |
251 | /* select mailbox READONLY for operations */ | 251 | /* select mailbox READONLY for operations */ |
252 | err = selectMbox(mailbox); | 252 | err = selectMbox(mailbox); |
253 | if ( err != MAILIMAP_NO_ERROR ) { | 253 | if ( err != MAILIMAP_NO_ERROR ) { |
254 | return; | 254 | return; |
255 | } | 255 | } |
256 | 256 | ||
257 | int last = m_imap->imap_selection_info->sel_exists; | 257 | int last = m_imap->imap_selection_info->sel_exists; |
258 | 258 | ||
259 | if (last == 0) { | 259 | if (last == 0) { |
260 | Global::statusMessage(i18n("Mailbox has no mails")); | 260 | Global::statusMessage(i18n("Mailbox has no mails")); |
261 | return; | 261 | return; |
262 | } else { | 262 | } else { |
263 | } | 263 | } |
264 | progress( i18n("Fetch ")); | 264 | progress( i18n("Fetch ")); |
265 | mMax = last; | 265 | mMax = last; |
266 | //qDebug("last %d ", last); | 266 | //qDebug("last %d ", last); |
267 | Global::statusMessage(i18n("Fetching header list")); | 267 | Global::statusMessage(i18n("Fetching header list")); |
268 | qApp->processEvents(); | 268 | qApp->processEvents(); |
269 | /* the range has to start at 1!!! not with 0!!!! */ | 269 | /* the range has to start at 1!!! not with 0!!!! */ |
270 | //LR the access to web.de imap server is no working with value 1 | 270 | //LR the access to web.de imap server is no working with value 1 |
271 | //qDebug("interval %d - %d ", tryAgain, last-1+tryAgain ); | 271 | //qDebug("interval %d - %d ", tryAgain, last-1+tryAgain ); |
272 | set = mailimap_set_new_interval( tryAgain, last ); | 272 | set = mailimap_set_new_interval( tryAgain, last ); |
273 | fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); | 273 | fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); |
274 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); | 274 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); |
275 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); | 275 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); |
276 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); | 276 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); |
277 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); | 277 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); |
278 | 278 | ||
279 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 279 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
280 | mailimap_set_free( set ); | 280 | mailimap_set_free( set ); |
281 | mailimap_fetch_type_free( fetchType ); | 281 | mailimap_fetch_type_free( fetchType ); |
282 | 282 | ||
283 | QString date,subject,from; | 283 | QString date,subject,from; |
284 | 284 | ||
285 | if ( err == MAILIMAP_NO_ERROR ) { | 285 | if ( err == MAILIMAP_NO_ERROR ) { |
286 | tryAgain = -1; | 286 | tryAgain = -1; |
287 | mailimap_msg_att * msg_att; | 287 | mailimap_msg_att * msg_att; |
288 | int i = 0; | 288 | int i = 0; |
289 | for (current = clist_begin(result); current != 0; current=clist_next(current)) { | 289 | for (current = clist_begin(result); current != 0; current=clist_next(current)) { |
290 | ++i; | 290 | ++i; |
291 | //qDebug("iii %d ",i); | 291 | //qDebug("iii %d ",i); |
292 | msg_att = (mailimap_msg_att*)current->data; | 292 | msg_att = (mailimap_msg_att*)current->data; |
293 | RecMail*m = parse_list_result(msg_att); | 293 | RecMail*m = parse_list_result(msg_att); |
294 | if (m) { | 294 | if (m) { |
295 | if ( maxSizeInKb == 0 || m->Msgsize()<=(unsigned int ) maxSizeInKb*1024 ) { | 295 | if ( maxSizeInKb == 0 || m->Msgsize()<=(unsigned int ) maxSizeInKb*1024 ) { |
296 | m->setNumber(i); | 296 | m->setNumber(i); |
297 | m->setMbox(mailbox); | 297 | m->setMbox(mailbox); |
298 | m->setWrapper(this); | 298 | m->setWrapper(this); |
299 | target.append(m); | 299 | target.append(m); |
300 | } | 300 | } |
301 | } | 301 | } |
302 | } | 302 | } |
303 | Global::statusMessage(i18n("Mailbox has %1 mails").arg(target.count())); | 303 | Global::statusMessage(i18n("Mailbox has %1 mails").arg(target.count())); |
304 | } else { | 304 | } else { |
305 | --tryAgain; | 305 | --tryAgain; |
306 | --tryAgain;//disabled tryagain by adding this line | 306 | --tryAgain;//disabled tryagain by adding this line |
307 | if ( tryAgain < 0 ) | 307 | if ( tryAgain < 0 ) |
308 | Global::statusMessage(i18n("Error fetching headers: %1").arg(m_imap->imap_response)); | 308 | Global::statusMessage(i18n("Error fetching headers: %1").arg(m_imap->imap_response)); |
309 | else | 309 | else |
310 | qDebug("try again... "); | 310 | qDebug("try again... "); |
311 | } | 311 | } |
312 | 312 | ||
313 | if (result) mailimap_fetch_list_free(result); | 313 | if (result) mailimap_fetch_list_free(result); |
314 | } | 314 | } |
315 | } | 315 | } |
316 | 316 | ||
317 | QValueList<Opie::Core::OSmartPointer<Folder> >* IMAPwrapper::listFolders() | 317 | QValueList<Opie::Core::OSmartPointer<Folder> >* IMAPwrapper::listFolders() |
318 | { | 318 | { |
319 | const char *path, *mask; | 319 | const char *path, *mask; |
320 | int err = MAILIMAP_NO_ERROR; | 320 | int err = MAILIMAP_NO_ERROR; |
321 | clist *result = 0; | 321 | clist *result = 0; |
322 | clistcell *current = 0; | 322 | clistcell *current = 0; |
323 | clistcell*cur_flag = 0; | 323 | clistcell*cur_flag = 0; |
324 | mailimap_mbx_list_flags*bflags = 0; | 324 | mailimap_mbx_list_flags*bflags = 0; |
325 | 325 | ||
326 | QValueList<FolderP>* folders = new QValueList<FolderP>(); | 326 | QValueList<FolderP>* folders = new QValueList<FolderP>(); |
327 | login(); | 327 | login(); |
328 | if (!m_imap) { | 328 | if (!m_imap) { |
329 | return folders; | 329 | return folders; |
330 | } | 330 | } |
331 | 331 | ||
332 | /* | 332 | /* |
333 | * First we have to check for INBOX 'cause it sometimes it's not inside the path. | 333 | * First we have to check for INBOX 'cause it sometimes it's not inside the path. |
334 | * We must not forget to filter them out in next loop! | 334 | * We must not forget to filter them out in next loop! |
335 | * it seems like ugly code. and yes - it is ugly code. but the best way. | 335 | * it seems like ugly code. and yes - it is ugly code. but the best way. |
336 | */ | 336 | */ |
337 | Global::statusMessage(i18n("Fetching folder list")); | 337 | Global::statusMessage(i18n("Fetching folder list")); |
338 | qApp->processEvents(); | 338 | qApp->processEvents(); |
339 | QString temp; | 339 | QString temp; |
340 | mask = "INBOX" ; | 340 | mask = "INBOX" ; |
341 | mailimap_mailbox_list *list; | 341 | mailimap_mailbox_list *list; |
342 | err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); | 342 | err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); |
343 | QString del; | 343 | QString del; |
344 | bool selectable = true; | 344 | bool selectable = true; |
345 | bool no_inferiors = false; | 345 | bool no_inferiors = false; |
346 | if ( err == MAILIMAP_NO_ERROR ) { | 346 | if ( err == MAILIMAP_NO_ERROR ) { |
347 | current = result->first; | 347 | current = result->first; |
348 | for ( int i = result->count; i > 0; i-- ) { | 348 | for ( int i = result->count; i > 0; i-- ) { |
349 | list = (mailimap_mailbox_list *) current->data; | 349 | list = (mailimap_mailbox_list *) current->data; |
350 | // it is better use the deep copy mechanism of qt itself | 350 | // it is better use the deep copy mechanism of qt itself |
351 | // instead of using strdup! | 351 | // instead of using strdup! |
352 | temp = list->mb_name; | 352 | temp = list->mb_name; |
353 | del = list->mb_delimiter; | 353 | del = list->mb_delimiter; |
354 | current = current->next; | 354 | current = current->next; |
355 | if ( (bflags = list->mb_flag) ) { | 355 | if ( (bflags = list->mb_flag) ) { |
356 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& | 356 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& |
357 | bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); | 357 | bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); |
358 | for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { | 358 | for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { |
359 | if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { | 359 | if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { |
360 | no_inferiors = true; | 360 | no_inferiors = true; |
361 | } | 361 | } |
362 | } | 362 | } |
363 | } | 363 | } |
364 | folders->append( new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); | 364 | folders->append( new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); |
365 | } | 365 | } |
366 | } else { | 366 | } else { |
367 | qDebug("error fetching folders: "); | 367 | qDebug("error fetching folders: "); |
368 | 368 | ||
369 | } | 369 | } |
370 | mailimap_list_result_free( result ); | 370 | mailimap_list_result_free( result ); |
371 | 371 | ||
372 | /* | 372 | /* |
373 | * second stage - get the other then inbox folders | 373 | * second stage - get the other then inbox folders |
374 | */ | 374 | */ |
375 | mask = "*" ; | 375 | mask = "*" ; |
376 | path = account->getPrefix().latin1(); | 376 | path = account->getPrefix().latin1(); |
377 | if (!path) path = ""; | 377 | if (!path) path = ""; |
378 | err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); | 378 | err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); |
379 | if ( err == MAILIMAP_NO_ERROR ) { | 379 | if ( err == MAILIMAP_NO_ERROR ) { |
380 | current = result->first; | 380 | current = result->first; |
381 | for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { | 381 | for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { |
382 | no_inferiors = false; | 382 | no_inferiors = false; |
383 | list = (mailimap_mailbox_list *) current->data; | 383 | list = (mailimap_mailbox_list *) current->data; |
384 | // it is better use the deep copy mechanism of qt itself | 384 | // it is better use the deep copy mechanism of qt itself |
385 | // instead of using strdup! | 385 | // instead of using strdup! |
386 | temp = list->mb_name; | 386 | temp = list->mb_name; |
387 | if (temp.lower()=="inbox") | 387 | if (temp.lower()=="inbox") |
388 | continue; | 388 | continue; |
389 | if (temp.lower()==account->getPrefix().lower()) | 389 | if (temp.lower()==account->getPrefix().lower()) |
390 | continue; | 390 | continue; |
391 | if ( (bflags = list->mb_flag) ) { | 391 | if ( (bflags = list->mb_flag) ) { |
392 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& | 392 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& |
393 | bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); | 393 | bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); |
394 | for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { | 394 | for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { |
395 | if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { | 395 | if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { |
396 | no_inferiors = true; | 396 | no_inferiors = true; |
397 | } | 397 | } |
398 | } | 398 | } |
399 | } | 399 | } |
400 | del = list->mb_delimiter; | 400 | del = list->mb_delimiter; |
401 | folders->append(new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); | 401 | folders->append(new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); |
402 | } | 402 | } |
403 | } else { | 403 | } else { |
404 | qDebug("error fetching folders "); | 404 | qDebug("error fetching folders "); |
405 | 405 | ||
406 | } | 406 | } |
407 | if (result) mailimap_list_result_free( result ); | 407 | if (result) mailimap_list_result_free( result ); |
408 | return folders; | 408 | return folders; |
409 | } | 409 | } |
410 | 410 | ||
411 | RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) | 411 | RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) |
412 | { | 412 | { |
413 | RecMail * m = 0; | 413 | RecMail * m = 0; |
414 | mailimap_msg_att_item *item=0; | 414 | mailimap_msg_att_item *item=0; |
415 | clistcell *current,*c,*cf; | 415 | clistcell *current,*c,*cf; |
416 | mailimap_msg_att_dynamic*flist; | 416 | mailimap_msg_att_dynamic*flist; |
417 | mailimap_flag_fetch*cflag; | 417 | mailimap_flag_fetch*cflag; |
418 | int size = 0; | 418 | int size = 0; |
419 | QBitArray mFlags(7); | 419 | QBitArray mFlags(7); |
420 | QStringList addresslist; | 420 | QStringList addresslist; |
421 | 421 | ||
422 | if (!m_att) { | 422 | if (!m_att) { |
423 | return m; | 423 | return m; |
424 | } | 424 | } |
425 | m = new RecMail(); | 425 | m = new RecMail(); |
426 | for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { | 426 | for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { |
427 | current = c; | 427 | current = c; |
428 | size = 0; | 428 | size = 0; |
429 | item = (mailimap_msg_att_item*)current->data; | 429 | item = (mailimap_msg_att_item*)current->data; |
430 | if ( !item ) | 430 | if ( !item ) |
431 | continue; | 431 | continue; |
432 | if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { | 432 | if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { |
433 | flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; | 433 | flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; |
434 | if (!flist || !flist->att_list) { | 434 | if (!flist || !flist->att_list) { |
435 | continue; | 435 | continue; |
436 | } | 436 | } |
437 | cf = flist->att_list->first; | 437 | cf = flist->att_list->first; |
438 | if( ! cf ) | 438 | if( ! cf ) |
439 | for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { | 439 | for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { |
440 | cflag = (mailimap_flag_fetch*)cf->data; | 440 | cflag = (mailimap_flag_fetch*)cf->data; |
441 | if( ! cflag ) | 441 | if( ! cflag ) |
442 | qDebug("imap:not cflag "); | 442 | qDebug("imap:not cflag "); |
443 | if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { | 443 | if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { |
444 | switch (cflag->fl_flag->fl_type) { | 444 | switch (cflag->fl_flag->fl_type) { |
445 | case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ | 445 | case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ |
446 | mFlags.setBit(FLAG_ANSWERED); | 446 | mFlags.setBit(FLAG_ANSWERED); |
447 | break; | 447 | break; |
448 | case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ | 448 | case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ |
449 | mFlags.setBit(FLAG_FLAGGED); | 449 | mFlags.setBit(FLAG_FLAGGED); |
450 | break; | 450 | break; |
451 | case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ | 451 | case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ |
452 | mFlags.setBit(FLAG_DELETED); | 452 | mFlags.setBit(FLAG_DELETED); |
453 | break; | 453 | break; |
454 | case MAILIMAP_FLAG_SEEN: /* \Seen flag */ | 454 | case MAILIMAP_FLAG_SEEN: /* \Seen flag */ |
455 | mFlags.setBit(FLAG_SEEN); | 455 | mFlags.setBit(FLAG_SEEN); |
456 | break; | 456 | break; |
457 | case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ | 457 | case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ |
458 | mFlags.setBit(FLAG_DRAFT); | 458 | mFlags.setBit(FLAG_DRAFT); |
459 | break; | 459 | break; |
460 | case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ | 460 | case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ |
461 | break; | 461 | break; |
462 | case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ | 462 | case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ |
463 | break; | 463 | break; |
464 | default: | 464 | default: |
465 | break; | 465 | break; |
466 | } | 466 | } |
467 | } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { | 467 | } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { |
468 | mFlags.setBit(FLAG_RECENT); | 468 | mFlags.setBit(FLAG_RECENT); |
469 | } | 469 | } |
470 | } | 470 | } |
471 | continue; | 471 | continue; |
472 | } | 472 | } |
473 | if ( item->att_data.att_static == NULL ) | 473 | if ( item->att_data.att_static == NULL ) |
474 | continue; | 474 | continue; |
475 | if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { | 475 | if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { |
476 | mailimap_envelope * head = item->att_data.att_static->att_data.att_env; | 476 | mailimap_envelope * head = item->att_data.att_static->att_data.att_env; |
477 | if ( head == NULL ) | 477 | if ( head == NULL ) |
478 | continue; | 478 | continue; |
479 | if ( head->env_date != NULL ) { | 479 | if ( head->env_date != NULL ) { |
480 | m->setDate(head->env_date); | 480 | m->setDate(head->env_date); |
481 | //struct mailimf_date_time result; | 481 | //struct mailimf_date_time result; |
482 | struct mailimf_date_time* date;// = &result; | 482 | struct mailimf_date_time* date;// = &result; |
483 | struct mailimf_date_time **re = &date; | 483 | struct mailimf_date_time **re = &date; |
484 | size_t length = m->getDate().length(); | 484 | size_t length = m->getDate().length(); |
485 | size_t index = 0; | 485 | size_t index = 0; |
486 | if ( mailimf_date_time_parse(head->env_date, length,&index, re ) == MAILIMF_NO_ERROR ) { | 486 | if ( mailimf_date_time_parse(head->env_date, length,&index, re ) == MAILIMF_NO_ERROR ) { |
487 | QDateTime dt = Genericwrapper::parseDateTime( date ); | 487 | QDateTime dt = Genericwrapper::parseDateTime( date ); |
488 | QString ret; | 488 | QString ret; |
489 | if ( dt.date() == QDate::currentDate () ) | 489 | if ( dt.date() == QDate::currentDate () ) |
490 | ret = KGlobal::locale()->formatTime( dt.time(),true); | 490 | ret = KGlobal::locale()->formatTime( dt.time(),true); |
491 | else { | 491 | else { |
492 | ret = KGlobal::locale()->formatDateTime( dt,true,true); | 492 | ret = KGlobal::locale()->formatDateTime( dt,true,true); |
493 | } | 493 | } |
494 | m->setDate( ret ); | 494 | m->setDate( ret ); |
495 | char tmp[20]; | 495 | char tmp[20]; |
496 | snprintf( tmp, 20, "%04i-%02i-%02i %02i:%02i:%02i", | 496 | snprintf( tmp, 20, "%04i-%02i-%02i %02i:%02i:%02i", |
497 | dt.date().year(),dt.date().month(), dt.date().day(), dt.time().hour(), dt.time().minute(), dt.time().second() ); | 497 | dt.date().year(),dt.date().month(), dt.date().day(), dt.time().hour(), dt.time().minute(), dt.time().second() ); |
498 | //qDebug("%d iso %s %s ", date->dt_zone, tmp, head->env_date); | 498 | //qDebug("%d iso %s %s ", date->dt_zone, tmp, head->env_date); |
499 | m->setIsoDate( QString( tmp ) ); | 499 | m->setIsoDate( QString( tmp ) ); |
500 | mailimf_date_time_free ( date ); | 500 | mailimf_date_time_free ( date ); |
501 | } else { | 501 | } else { |
502 | m->setIsoDate(head->env_date); | 502 | m->setIsoDate(head->env_date); |
503 | } | 503 | } |
504 | } | 504 | } |
505 | if ( head->env_subject != NULL ) | 505 | if ( head->env_subject != NULL ) |
506 | m->setSubject(convert_String((const char*)head->env_subject)); | 506 | m->setSubject(convert_String((const char*)head->env_subject)); |
507 | //m->setSubject(head->env_subject); | 507 | //m->setSubject(head->env_subject); |
508 | if (head->env_from!=NULL) { | 508 | if (head->env_from!=NULL) { |
509 | addresslist = address_list_to_stringlist(head->env_from->frm_list); | 509 | addresslist = address_list_to_stringlist(head->env_from->frm_list); |
510 | if (addresslist.count()) { | 510 | if (addresslist.count()) { |
511 | m->setFrom(addresslist.first()); | 511 | m->setFrom(addresslist.first()); |
512 | } | 512 | } |
513 | } | 513 | } |
514 | if (head->env_to!=NULL) { | 514 | if (head->env_to!=NULL) { |
515 | addresslist = address_list_to_stringlist(head->env_to->to_list); | 515 | addresslist = address_list_to_stringlist(head->env_to->to_list); |
516 | m->setTo(addresslist); | 516 | m->setTo(addresslist); |
517 | } | 517 | } |
518 | if (head->env_cc!=NULL) { | 518 | if (head->env_cc!=NULL) { |
519 | addresslist = address_list_to_stringlist(head->env_cc->cc_list); | 519 | addresslist = address_list_to_stringlist(head->env_cc->cc_list); |
520 | m->setCC(addresslist); | 520 | m->setCC(addresslist); |
521 | } | 521 | } |
522 | if (head->env_bcc!=NULL) { | 522 | if (head->env_bcc!=NULL) { |
523 | addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); | 523 | addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); |
524 | m->setBcc(addresslist); | 524 | m->setBcc(addresslist); |
525 | } | 525 | } |
526 | /* reply to address, eg. email. */ | 526 | /* reply to address, eg. email. */ |
527 | if (head->env_reply_to!=NULL) { | 527 | if (head->env_reply_to!=NULL) { |
528 | addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); | 528 | addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); |
529 | if (addresslist.count()) { | 529 | if (addresslist.count()) { |
530 | m->setReplyto(addresslist.first()); | 530 | m->setReplyto(addresslist.first()); |
531 | } | 531 | } |
532 | } | 532 | } |
533 | if (head->env_in_reply_to!=NULL) { | 533 | if (head->env_in_reply_to!=NULL) { |
534 | QString h(head->env_in_reply_to); | 534 | QString h(head->env_in_reply_to); |
535 | while (h.length()>0 && h[0]=='<') { | 535 | while (h.length()>0 && h[0]=='<') { |
536 | h.remove(0,1); | 536 | h.remove(0,1); |
537 | } | 537 | } |
538 | while (h.length()>0 && h[h.length()-1]=='>') { | 538 | while (h.length()>0 && h[h.length()-1]=='>') { |
539 | h.remove(h.length()-1,1); | 539 | h.remove(h.length()-1,1); |
540 | } | 540 | } |
541 | if (h.length()>0) { | 541 | if (h.length()>0) { |
542 | m->setInreply(QStringList(h)); | 542 | m->setInreply(QStringList(h)); |
543 | } | 543 | } |
544 | } | 544 | } |
545 | if (head->env_message_id != NULL) { | 545 | if (head->env_message_id != NULL) { |
546 | m->setMsgid(QString(head->env_message_id)); | 546 | m->setMsgid(QString(head->env_message_id)); |
547 | } | 547 | } |
548 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { | 548 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { |
549 | #if 0 | 549 | #if 0 |
550 | mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; | 550 | mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; |
551 | QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); | 551 | QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); |
552 | qDebug("time %s ",da.toString().latin1() ); | 552 | qDebug("time %s ",da.toString().latin1() ); |
553 | #endif | 553 | #endif |
554 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { | 554 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { |
555 | size = item->att_data.att_static->att_data.att_rfc822_size; | 555 | size = item->att_data.att_static->att_data.att_rfc822_size; |
556 | } | 556 | } |
557 | } | 557 | } |
558 | /* msg is already deleted */ | 558 | /* msg is already deleted */ |
559 | if (mFlags.testBit(FLAG_DELETED) && m) { | 559 | if (mFlags.testBit(FLAG_DELETED) && m) { |
560 | delete m; | 560 | delete m; |
561 | m = 0; | 561 | m = 0; |
562 | } | 562 | } |
563 | if (m) { | 563 | if (m) { |
564 | m->setFlags(mFlags); | 564 | m->setFlags(mFlags); |
565 | m->setMsgsize(size); | 565 | m->setMsgsize(size); |
566 | } | 566 | } |
567 | return m; | 567 | return m; |
568 | } | 568 | } |
569 | 569 | ||
570 | RecBodyP IMAPwrapper::fetchBody(const RecMailP&mail) | 570 | RecBodyP IMAPwrapper::fetchBody(const RecMailP&mail) |
571 | { | 571 | { |
572 | RecBodyP body = new RecBody(); | 572 | RecBodyP body = new RecBody(); |
573 | const char *mb; | 573 | const char *mb; |
574 | int err = MAILIMAP_NO_ERROR; | 574 | int err = MAILIMAP_NO_ERROR; |
575 | clist *result = 0; | 575 | clist *result = 0; |
576 | clistcell *current; | 576 | clistcell *current; |
577 | mailimap_fetch_att *fetchAtt = 0; | 577 | mailimap_fetch_att *fetchAtt = 0; |
578 | mailimap_fetch_type *fetchType = 0; | 578 | mailimap_fetch_type *fetchType = 0; |
579 | mailimap_set *set = 0; | 579 | mailimap_set *set = 0; |
580 | mailimap_body*body_desc = 0; | 580 | mailimap_body*body_desc = 0; |
581 | 581 | ||
582 | mb = mail->getMbox().latin1(); | 582 | mb = mail->getMbox().latin1(); |
583 | 583 | ||
584 | login(); | 584 | login(); |
585 | if (!m_imap) { | 585 | if (!m_imap) { |
586 | return body; | 586 | return body; |
587 | } | 587 | } |
588 | err = selectMbox(mail->getMbox()); | 588 | err = selectMbox(mail->getMbox()); |
589 | if ( err != MAILIMAP_NO_ERROR ) { | 589 | if ( err != MAILIMAP_NO_ERROR ) { |
590 | return body; | 590 | return body; |
591 | } | 591 | } |
592 | 592 | ||
593 | /* the range has to start at 1!!! not with 0!!!! */ | 593 | /* the range has to start at 1!!! not with 0!!!! */ |
594 | set = mailimap_set_new_interval( mail->getNumber(),mail->getNumber() ); | 594 | set = mailimap_set_new_interval( mail->getNumber(),mail->getNumber() ); |
595 | fetchAtt = mailimap_fetch_att_new_bodystructure(); | 595 | fetchAtt = mailimap_fetch_att_new_bodystructure(); |
596 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); | 596 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); |
597 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 597 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
598 | mailimap_set_free( set ); | 598 | mailimap_set_free( set ); |
599 | mailimap_fetch_type_free( fetchType ); | 599 | mailimap_fetch_type_free( fetchType ); |
600 | 600 | ||
601 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { | 601 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { |
602 | mailimap_msg_att * msg_att; | 602 | mailimap_msg_att * msg_att; |
603 | msg_att = (mailimap_msg_att*)current->data; | 603 | msg_att = (mailimap_msg_att*)current->data; |
604 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; | 604 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; |
605 | QValueList<int> path; | 605 | QValueList<int> path; |
606 | body_desc = item->att_data.att_static->att_data.att_body; | 606 | body_desc = item->att_data.att_static->att_data.att_body; |
607 | traverseBody(mail,body_desc,body,0,path); | 607 | traverseBody(mail,body_desc,body,0,path); |
608 | } else { | 608 | } else { |
609 | //odebug << "error fetching body: " << m_imap->imap_response << "" << oendl; | 609 | //odebug << "error fetching body: " << m_imap->imap_response << "" << oendl; |
610 | } | 610 | } |
611 | if (result) mailimap_fetch_list_free(result); | 611 | if (result) mailimap_fetch_list_free(result); |
612 | return body; | 612 | return body; |
613 | } | 613 | } |
614 | 614 | ||
615 | QStringList IMAPwrapper::address_list_to_stringlist(clist*list) | 615 | QStringList IMAPwrapper::address_list_to_stringlist(clist*list) |
616 | { | 616 | { |
617 | QStringList l; | 617 | QStringList l; |
618 | QString from; | 618 | QString from; |
619 | bool named_from; | 619 | bool named_from; |
620 | clistcell *current = NULL; | 620 | clistcell *current = NULL; |
621 | mailimap_address * current_address=NULL; | 621 | mailimap_address * current_address=NULL; |
622 | if (!list) { | 622 | if (!list) { |
623 | return l; | 623 | return l; |
624 | } | 624 | } |
625 | unsigned int count = 0; | 625 | unsigned int count = 0; |
626 | for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { | 626 | for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { |
627 | from = ""; | 627 | from = ""; |
628 | named_from = false; | 628 | named_from = false; |
629 | current_address=(mailimap_address*)current->data; | 629 | current_address=(mailimap_address*)current->data; |
630 | if (current_address->ad_personal_name){ | 630 | if (current_address->ad_personal_name){ |
631 | from+=convert_String((const char*)current_address->ad_personal_name); | 631 | from+=convert_String((const char*)current_address->ad_personal_name); |
632 | from+=" "; | 632 | from+=" "; |
633 | named_from = true; | 633 | named_from = true; |
634 | } | 634 | } |
635 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { | 635 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { |
636 | from+="<"; | 636 | from+="<"; |
637 | } | 637 | } |
638 | if (current_address->ad_mailbox_name) { | 638 | if (current_address->ad_mailbox_name) { |
639 | from+=QString(current_address->ad_mailbox_name); | 639 | from+=QString(current_address->ad_mailbox_name); |
640 | from+="@"; | 640 | from+="@"; |
641 | } | 641 | } |
642 | if (current_address->ad_host_name) { | 642 | if (current_address->ad_host_name) { |
643 | from+=QString(current_address->ad_host_name); | 643 | from+=QString(current_address->ad_host_name); |
644 | } | 644 | } |
645 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { | 645 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { |
646 | from+=">"; | 646 | from+=">"; |
647 | } | 647 | } |
648 | l.append(QString(from)); | 648 | l.append(QString(from)); |
649 | if (++count > 99) { | 649 | if (++count > 99) { |
650 | break; | 650 | break; |
651 | } | 651 | } |
652 | } | 652 | } |
653 | return l; | 653 | return l; |
654 | } | 654 | } |
655 | 655 | ||
656 | encodedString*IMAPwrapper::fetchRawPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call) | 656 | encodedString*IMAPwrapper::fetchRawPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call) |
657 | { | 657 | { |
658 | encodedString*res=new encodedString; | 658 | encodedString*res=new encodedString; |
659 | int err; | 659 | int err; |
660 | mailimap_fetch_type *fetchType; | 660 | mailimap_fetch_type *fetchType; |
661 | mailimap_set *set; | 661 | mailimap_set *set; |
662 | clistcell*current,*cur; | 662 | clistcell*current,*cur; |
663 | mailimap_section_part * section_part = 0; | 663 | mailimap_section_part * section_part = 0; |
664 | mailimap_section_spec * section_spec = 0; | 664 | mailimap_section_spec * section_spec = 0; |
665 | mailimap_section * section = 0; | 665 | mailimap_section * section = 0; |
666 | mailimap_fetch_att * fetch_att = 0; | 666 | mailimap_fetch_att * fetch_att = 0; |
667 | 667 | ||
668 | login(); | 668 | login(); |
669 | if (!m_imap) { | 669 | if (!m_imap) { |
670 | return res; | 670 | return res; |
671 | } | 671 | } |
672 | if (!internal_call) { | 672 | if (!internal_call) { |
673 | err = selectMbox(mail->getMbox()); | 673 | err = selectMbox(mail->getMbox()); |
674 | if ( err != MAILIMAP_NO_ERROR ) { | 674 | if ( err != MAILIMAP_NO_ERROR ) { |
675 | return res; | 675 | return res; |
676 | } | 676 | } |
677 | } | 677 | } |
678 | set = mailimap_set_new_single(mail->getNumber()); | 678 | set = mailimap_set_new_single(mail->getNumber()); |
679 | 679 | ||
680 | clist*id_list = 0; | 680 | clist*id_list = 0; |
681 | 681 | ||
682 | /* if path == empty then its a request for the whole rfc822 mail and generates | 682 | /* if path == empty then its a request for the whole rfc822 mail and generates |
683 | a "fetch <id> (body[])" statement on imap server */ | 683 | a "fetch <id> (body[])" statement on imap server */ |
684 | if (path.count()>0 ) { | 684 | if (path.count()>0 ) { |
685 | id_list = clist_new(); | 685 | id_list = clist_new(); |
686 | for (unsigned j=0; j < path.count();++j) { | 686 | for (unsigned j=0; j < path.count();++j) { |
687 | uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); | 687 | uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); |
688 | *p_id = path[j]; | 688 | *p_id = path[j]; |
689 | clist_append(id_list,p_id); | 689 | clist_append(id_list,p_id); |
690 | } | 690 | } |
691 | section_part = mailimap_section_part_new(id_list); | 691 | section_part = mailimap_section_part_new(id_list); |
692 | section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); | 692 | section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); |
693 | } | 693 | } |
694 | 694 | ||
695 | section = mailimap_section_new(section_spec); | 695 | section = mailimap_section_new(section_spec); |
696 | fetch_att = mailimap_fetch_att_new_body_section(section); | 696 | fetch_att = mailimap_fetch_att_new_body_section(section); |
697 | fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); | 697 | fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); |
698 | 698 | ||
699 | clist*result = 0; | 699 | clist*result = 0; |
700 | 700 | ||
701 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 701 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
702 | mailimap_set_free( set ); | 702 | mailimap_set_free( set ); |
703 | mailimap_fetch_type_free( fetchType ); | 703 | mailimap_fetch_type_free( fetchType ); |
704 | 704 | ||
705 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { | 705 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { |
706 | mailimap_msg_att * msg_att; | 706 | mailimap_msg_att * msg_att; |
707 | msg_att = (mailimap_msg_att*)current->data; | 707 | msg_att = (mailimap_msg_att*)current->data; |
708 | mailimap_msg_att_item*msg_att_item; | 708 | mailimap_msg_att_item*msg_att_item; |
709 | for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { | 709 | for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { |
710 | msg_att_item = (mailimap_msg_att_item*)clist_content(cur); | 710 | msg_att_item = (mailimap_msg_att_item*)clist_content(cur); |
711 | if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { | 711 | if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { |
712 | if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { | 712 | if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { |
713 | char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; | 713 | char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; |
714 | /* detach - we take over the content */ | 714 | /* detach - we take over the content */ |
715 | msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; | 715 | msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; |
716 | res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length); | 716 | res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length); |
717 | } | 717 | } |
718 | } | 718 | } |
719 | } | 719 | } |
720 | } else { | 720 | } else { |
721 | ;//odebug << "error fetching text: " << m_imap->imap_response << "" << oendl; | 721 | ;//odebug << "error fetching text: " << m_imap->imap_response << "" << oendl; |
722 | } | 722 | } |
723 | if (result) mailimap_fetch_list_free(result); | 723 | if (result) mailimap_fetch_list_free(result); |
724 | return res; | 724 | return res; |
725 | } | 725 | } |
726 | 726 | ||
727 | /* current_recursion is for recursive calls. | 727 | /* current_recursion is for recursive calls. |
728 | current_count means the position inside the internal loop! */ | 728 | current_count means the position inside the internal loop! */ |
729 | void IMAPwrapper::traverseBody(const RecMailP&mail,mailimap_body*body,RecBodyP&target_body, | 729 | void IMAPwrapper::traverseBody(const RecMailP&mail,mailimap_body*body,RecBodyP&target_body, |
730 | int current_recursion,QValueList<int>recList,int current_count) | 730 | int current_recursion,QValueList<int>recList,int current_count) |
731 | { | 731 | { |
732 | if (!body || current_recursion>=10) { | 732 | if (!body || current_recursion>=10) { |
733 | return; | 733 | return; |
734 | } | 734 | } |
735 | switch (body->bd_type) { | 735 | switch (body->bd_type) { |
736 | case MAILIMAP_BODY_1PART: | 736 | case MAILIMAP_BODY_1PART: |
737 | { | 737 | { |
738 | QValueList<int>countlist = recList; | 738 | QValueList<int>countlist = recList; |
739 | countlist.append(current_count); | 739 | countlist.append(current_count); |
740 | RecPartP currentPart = new RecPart(); | 740 | RecPartP currentPart = new RecPart(); |
741 | mailimap_body_type_1part*part1 = body->bd_data.bd_body_1part; | 741 | mailimap_body_type_1part*part1 = body->bd_data.bd_body_1part; |
742 | QString id(""); | 742 | QString id(""); |
743 | currentPart->setPositionlist(countlist); | 743 | currentPart->setPositionlist(countlist); |
744 | for (unsigned int j = 0; j < countlist.count();++j) { | 744 | for (unsigned int j = 0; j < countlist.count();++j) { |
745 | id+=(j>0?" ":""); | 745 | id+=(j>0?" ":""); |
746 | id+=QString("%1").arg(countlist[j]); | 746 | id+=QString("%1").arg(countlist[j]); |
747 | } | 747 | } |
748 | //odebug << "ID = " << id.latin1() << "" << oendl; | 748 | //odebug << "ID = " << id.latin1() << "" << oendl; |
749 | currentPart->setIdentifier(id); | 749 | currentPart->setIdentifier(id); |
750 | fillSinglePart(currentPart,part1); | 750 | fillSinglePart(currentPart,part1); |
751 | /* important: Check for is NULL 'cause a body can be empty! | 751 | /* important: Check for is NULL 'cause a body can be empty! |
752 | And we put it only into the mail if it is the FIRST part */ | 752 | And we put it only into the mail if it is the FIRST part */ |
753 | if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_TEXT && target_body->Bodytext().isNull() && countlist[0]==1) { | 753 | if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_TEXT && target_body->Bodytext().isNull() && countlist[0]==1) { |
754 | QString body_text = fetchTextPart(mail,countlist,true,currentPart->Encoding()); | 754 | QString body_text = fetchTextPart(mail,countlist,true,currentPart->Encoding()); |
755 | 755 | ||
756 | size_t index = 0; | 756 | size_t index = 0; |
757 | char*res = 0; | 757 | char*res = 0; |
758 | int err = MAILIMF_NO_ERROR; | 758 | int err = MAILIMF_NO_ERROR; |
759 | 759 | ||
760 | QString charset = currentPart->searchParamter( "charset"); | 760 | QString charset = currentPart->searchParamter( "charset"); |
761 | qDebug("CHARSET %s ",charset.latin1() ); | 761 | qDebug("CHARSET %s ",charset.latin1() ); |
762 | //if ( false ) { | 762 | if ( false ) { |
763 | if ( !charset.isEmpty() ) { | 763 | //if ( !charset.isEmpty() ) { |
764 | target_body->setCharset( charset ); | 764 | target_body->setCharset( charset ); |
765 | //err = mailmime_encoded_phrase_parse("iso-8859-1", | 765 | //err = mailmime_encoded_phrase_parse("iso-8859-1", |
766 | // text, strlen(text),&index, "iso-8859-1",&res); | 766 | // text, strlen(text),&index, "iso-8859-1",&res); |
767 | err = mailmime_encoded_phrase_parse(charset.latin1(), | 767 | err = mailmime_encoded_phrase_parse(charset.latin1(), |
768 | body_text.latin1(), body_text.length(),&index, "utf-8",&res); | 768 | body_text.latin1(), body_text.length(),&index, "utf-8",&res); |
769 | if (err == MAILIMF_NO_ERROR && res && strlen(res)) { | 769 | if (err == MAILIMF_NO_ERROR && res && strlen(res)) { |
770 | //qDebug("res %d %s ", index, res); | 770 | //qDebug("res %d %s ", index, res); |
771 | body_text = QString::fromUtf8(res); | 771 | body_text = QString::fromUtf8(res); |
772 | } | 772 | } |
773 | if (res) free(res); | 773 | if (res) free(res); |
774 | } | 774 | } |
775 | //qDebug("encoding %d text %s ",currentPart->Encoding().latin1(), body_text.latin1() ); | 775 | //qDebug("encoding %d text %s ",currentPart->Encoding().latin1(), body_text.latin1() ); |
776 | target_body->setDescription(currentPart); | 776 | target_body->setDescription(currentPart); |
777 | target_body->setBodytext(body_text); | 777 | target_body->setBodytext(body_text); |
778 | if (countlist.count()>1) { | 778 | if (countlist.count()>1) { |
779 | target_body->addPart(currentPart); | 779 | target_body->addPart(currentPart); |
780 | } | 780 | } |
781 | } else { | 781 | } else { |
782 | target_body->addPart(currentPart); | 782 | target_body->addPart(currentPart); |
783 | } | 783 | } |
784 | if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_MSG) { | 784 | if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_MSG) { |
785 | traverseBody(mail,part1->bd_data.bd_type_msg->bd_body,target_body,current_recursion+1,countlist); | 785 | traverseBody(mail,part1->bd_data.bd_type_msg->bd_body,target_body,current_recursion+1,countlist); |
786 | } | 786 | } |
787 | } | 787 | } |
788 | break; | 788 | break; |
789 | case MAILIMAP_BODY_MPART: | 789 | case MAILIMAP_BODY_MPART: |
790 | { | 790 | { |
791 | QValueList<int>countlist = recList; | 791 | QValueList<int>countlist = recList; |
792 | clistcell*current=0; | 792 | clistcell*current=0; |
793 | mailimap_body*current_body=0; | 793 | mailimap_body*current_body=0; |
794 | unsigned int ccount = 1; | 794 | unsigned int ccount = 1; |
795 | mailimap_body_type_mpart*mailDescription = body->bd_data.bd_body_mpart; | 795 | mailimap_body_type_mpart*mailDescription = body->bd_data.bd_body_mpart; |
796 | for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { | 796 | for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { |
797 | current_body = (mailimap_body*)current->data; | 797 | current_body = (mailimap_body*)current->data; |
798 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { | 798 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { |
799 | RecPartP targetPart = new RecPart(); | 799 | RecPartP targetPart = new RecPart(); |
800 | targetPart->setType("multipart"); | 800 | targetPart->setType("multipart"); |
801 | fillMultiPart(targetPart,mailDescription); | 801 | fillMultiPart(targetPart,mailDescription); |
802 | countlist.append(current_count); | 802 | countlist.append(current_count); |
803 | targetPart->setPositionlist(countlist); | 803 | targetPart->setPositionlist(countlist); |
804 | target_body->addPart(targetPart); | 804 | target_body->addPart(targetPart); |
805 | QString id(""); | 805 | QString id(""); |
806 | for (unsigned int j = 0; j < countlist.count();++j) { | 806 | for (unsigned int j = 0; j < countlist.count();++j) { |
807 | id+=(j>0?" ":""); | 807 | id+=(j>0?" ":""); |
808 | id+=QString("%1").arg(countlist[j]); | 808 | id+=QString("%1").arg(countlist[j]); |
809 | } | 809 | } |
810 | // odebug << "ID(mpart) = " << id.latin1() << "" << oendl; | 810 | // odebug << "ID(mpart) = " << id.latin1() << "" << oendl; |
811 | } | 811 | } |
812 | traverseBody(mail,current_body,target_body,current_recursion+1,countlist,ccount); | 812 | traverseBody(mail,current_body,target_body,current_recursion+1,countlist,ccount); |
813 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { | 813 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { |
814 | countlist = recList; | 814 | countlist = recList; |
815 | } | 815 | } |
816 | ++ccount; | 816 | ++ccount; |
817 | } | 817 | } |
818 | } | 818 | } |
819 | break; | 819 | break; |
820 | default: | 820 | default: |
821 | break; | 821 | break; |
822 | } | 822 | } |
823 | } | 823 | } |
824 | 824 | ||
825 | void IMAPwrapper::fillSinglePart(RecPartP&target_part,mailimap_body_type_1part*Description) | 825 | void IMAPwrapper::fillSinglePart(RecPartP&target_part,mailimap_body_type_1part*Description) |
826 | { | 826 | { |
827 | if (!Description) { | 827 | if (!Description) { |
828 | return; | 828 | return; |
829 | } | 829 | } |
830 | switch (Description->bd_type) { | 830 | switch (Description->bd_type) { |
831 | case MAILIMAP_BODY_TYPE_1PART_TEXT: | 831 | case MAILIMAP_BODY_TYPE_1PART_TEXT: |
832 | target_part->setType("text"); | 832 | target_part->setType("text"); |
833 | fillSingleTextPart(target_part,Description->bd_data.bd_type_text); | 833 | fillSingleTextPart(target_part,Description->bd_data.bd_type_text); |
834 | break; | 834 | break; |
835 | case MAILIMAP_BODY_TYPE_1PART_BASIC: | 835 | case MAILIMAP_BODY_TYPE_1PART_BASIC: |
836 | fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); | 836 | fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); |
837 | break; | 837 | break; |
838 | case MAILIMAP_BODY_TYPE_1PART_MSG: | 838 | case MAILIMAP_BODY_TYPE_1PART_MSG: |
839 | target_part->setType("message"); | 839 | target_part->setType("message"); |
840 | fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); | 840 | fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); |
841 | break; | 841 | break; |
842 | default: | 842 | default: |
843 | break; | 843 | break; |
844 | } | 844 | } |
845 | } | 845 | } |
846 | 846 | ||
847 | void IMAPwrapper::fillSingleTextPart(RecPartP&target_part,mailimap_body_type_text*which) | 847 | void IMAPwrapper::fillSingleTextPart(RecPartP&target_part,mailimap_body_type_text*which) |
848 | { | 848 | { |
849 | if (!which) { | 849 | if (!which) { |
850 | return; | 850 | return; |
851 | } | 851 | } |
852 | QString sub; | 852 | QString sub; |
853 | sub = which->bd_media_text; | 853 | sub = which->bd_media_text; |
854 | //odebug << "Type= text/" << which->bd_media_text << "" << oendl; | 854 | //odebug << "Type= text/" << which->bd_media_text << "" << oendl; |
855 | target_part->setSubtype(sub.lower()); | 855 | target_part->setSubtype(sub.lower()); |
856 | target_part->setLines(which->bd_lines); | 856 | target_part->setLines(which->bd_lines); |
857 | fillBodyFields(target_part,which->bd_fields); | 857 | fillBodyFields(target_part,which->bd_fields); |
858 | } | 858 | } |
859 | 859 | ||
860 | void IMAPwrapper::fillSingleMsgPart(RecPartP&target_part,mailimap_body_type_msg*which) | 860 | void IMAPwrapper::fillSingleMsgPart(RecPartP&target_part,mailimap_body_type_msg*which) |
861 | { | 861 | { |
862 | if (!which) { | 862 | if (!which) { |
863 | return; | 863 | return; |
864 | } | 864 | } |
865 | target_part->setSubtype("rfc822"); | 865 | target_part->setSubtype("rfc822"); |
866 | //odebug << "Message part" << oendl; | 866 | //odebug << "Message part" << oendl; |
867 | /* we set this type to text/plain */ | 867 | /* we set this type to text/plain */ |
868 | target_part->setLines(which->bd_lines); | 868 | target_part->setLines(which->bd_lines); |
869 | fillBodyFields(target_part,which->bd_fields); | 869 | fillBodyFields(target_part,which->bd_fields); |
870 | } | 870 | } |
871 | 871 | ||
872 | void IMAPwrapper::fillMultiPart(RecPartP&target_part,mailimap_body_type_mpart*which) | 872 | void IMAPwrapper::fillMultiPart(RecPartP&target_part,mailimap_body_type_mpart*which) |
873 | { | 873 | { |
874 | if (!which) return; | 874 | if (!which) return; |
875 | QString sub = which->bd_media_subtype; | 875 | QString sub = which->bd_media_subtype; |
876 | target_part->setSubtype(sub.lower()); | 876 | target_part->setSubtype(sub.lower()); |
877 | if (which->bd_ext_mpart && which->bd_ext_mpart->bd_parameter && which->bd_ext_mpart->bd_parameter->pa_list) { | 877 | if (which->bd_ext_mpart && which->bd_ext_mpart->bd_parameter && which->bd_ext_mpart->bd_parameter->pa_list) { |
878 | clistcell*cur = 0; | 878 | clistcell*cur = 0; |
879 | mailimap_single_body_fld_param*param=0; | 879 | mailimap_single_body_fld_param*param=0; |
880 | for (cur = clist_begin(which->bd_ext_mpart->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { | 880 | for (cur = clist_begin(which->bd_ext_mpart->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { |
881 | param = (mailimap_single_body_fld_param*)cur->data; | 881 | param = (mailimap_single_body_fld_param*)cur->data; |
882 | if (param) { | 882 | if (param) { |
883 | target_part->addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); | 883 | target_part->addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); |
884 | } | 884 | } |
885 | } | 885 | } |
886 | } | 886 | } |
887 | } | 887 | } |
888 | 888 | ||
889 | void IMAPwrapper::fillSingleBasicPart(RecPartP&target_part,mailimap_body_type_basic*which) | 889 | void IMAPwrapper::fillSingleBasicPart(RecPartP&target_part,mailimap_body_type_basic*which) |
890 | { | 890 | { |
891 | if (!which) { | 891 | if (!which) { |
892 | return; | 892 | return; |
893 | } | 893 | } |
894 | QString type,sub; | 894 | QString type,sub; |
895 | switch (which->bd_media_basic->med_type) { | 895 | switch (which->bd_media_basic->med_type) { |
896 | case MAILIMAP_MEDIA_BASIC_APPLICATION: | 896 | case MAILIMAP_MEDIA_BASIC_APPLICATION: |
897 | type = "application"; | 897 | type = "application"; |
898 | break; | 898 | break; |
899 | case MAILIMAP_MEDIA_BASIC_AUDIO: | 899 | case MAILIMAP_MEDIA_BASIC_AUDIO: |
900 | type = "audio"; | 900 | type = "audio"; |
901 | break; | 901 | break; |
902 | case MAILIMAP_MEDIA_BASIC_IMAGE: | 902 | case MAILIMAP_MEDIA_BASIC_IMAGE: |
903 | type = "image"; | 903 | type = "image"; |
904 | break; | 904 | break; |
905 | case MAILIMAP_MEDIA_BASIC_MESSAGE: | 905 | case MAILIMAP_MEDIA_BASIC_MESSAGE: |
906 | type = "message"; | 906 | type = "message"; |
907 | break; | 907 | break; |
908 | case MAILIMAP_MEDIA_BASIC_VIDEO: | 908 | case MAILIMAP_MEDIA_BASIC_VIDEO: |
909 | type = "video"; | 909 | type = "video"; |
910 | break; | 910 | break; |
911 | case MAILIMAP_MEDIA_BASIC_OTHER: | 911 | case MAILIMAP_MEDIA_BASIC_OTHER: |
912 | default: | 912 | default: |
913 | if (which->bd_media_basic->med_basic_type) { | 913 | if (which->bd_media_basic->med_basic_type) { |
914 | type = which->bd_media_basic->med_basic_type; | 914 | type = which->bd_media_basic->med_basic_type; |
915 | } else { | 915 | } else { |
916 | type = ""; | 916 | type = ""; |
917 | } | 917 | } |
918 | break; | 918 | break; |
919 | } | 919 | } |
920 | if (which->bd_media_basic->med_subtype) { | 920 | if (which->bd_media_basic->med_subtype) { |
921 | sub = which->bd_media_basic->med_subtype; | 921 | sub = which->bd_media_basic->med_subtype; |
922 | } else { | 922 | } else { |
923 | sub = ""; | 923 | sub = ""; |
924 | } | 924 | } |
925 | // odebug << "Type = " << type.latin1() << "/" << sub.latin1() << "" << oendl; | 925 | // odebug << "Type = " << type.latin1() << "/" << sub.latin1() << "" << oendl; |
926 | target_part->setType(type.lower()); | 926 | target_part->setType(type.lower()); |
927 | target_part->setSubtype(sub.lower()); | 927 | target_part->setSubtype(sub.lower()); |
928 | fillBodyFields(target_part,which->bd_fields); | 928 | fillBodyFields(target_part,which->bd_fields); |
929 | } | 929 | } |
930 | 930 | ||
931 | void IMAPwrapper::fillBodyFields(RecPartP&target_part,mailimap_body_fields*which) | 931 | void IMAPwrapper::fillBodyFields(RecPartP&target_part,mailimap_body_fields*which) |
932 | { | 932 | { |
933 | if (!which) return; | 933 | if (!which) return; |
934 | if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) { | 934 | if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) { |
935 | clistcell*cur; | 935 | clistcell*cur; |
936 | mailimap_single_body_fld_param*param=0; | 936 | mailimap_single_body_fld_param*param=0; |
937 | for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { | 937 | for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { |
938 | param = (mailimap_single_body_fld_param*)cur->data; | 938 | param = (mailimap_single_body_fld_param*)cur->data; |
939 | if (param) { | 939 | if (param) { |
940 | target_part->addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); | 940 | target_part->addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); |
941 | } | 941 | } |
942 | } | 942 | } |
943 | } | 943 | } |
944 | mailimap_body_fld_enc*enc = which->bd_encoding; | 944 | mailimap_body_fld_enc*enc = which->bd_encoding; |
945 | QString encoding(""); | 945 | QString encoding(""); |
946 | switch (enc->enc_type) { | 946 | switch (enc->enc_type) { |
947 | case MAILIMAP_BODY_FLD_ENC_7BIT: | 947 | case MAILIMAP_BODY_FLD_ENC_7BIT: |
948 | encoding = "7bit"; | 948 | encoding = "7bit"; |
949 | break; | 949 | break; |
950 | case MAILIMAP_BODY_FLD_ENC_8BIT: | 950 | case MAILIMAP_BODY_FLD_ENC_8BIT: |
951 | encoding = "8bit"; | 951 | encoding = "8bit"; |
952 | break; | 952 | break; |
953 | case MAILIMAP_BODY_FLD_ENC_BINARY: | 953 | case MAILIMAP_BODY_FLD_ENC_BINARY: |
954 | encoding="binary"; | 954 | encoding="binary"; |
955 | break; | 955 | break; |
956 | case MAILIMAP_BODY_FLD_ENC_BASE64: | 956 | case MAILIMAP_BODY_FLD_ENC_BASE64: |
957 | encoding="base64"; | 957 | encoding="base64"; |
958 | break; | 958 | break; |
959 | case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: | 959 | case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: |
960 | encoding="quoted-printable"; | 960 | encoding="quoted-printable"; |
961 | break; | 961 | break; |
962 | case MAILIMAP_BODY_FLD_ENC_OTHER: | 962 | case MAILIMAP_BODY_FLD_ENC_OTHER: |
963 | default: | 963 | default: |
964 | if (enc->enc_value) { | 964 | if (enc->enc_value) { |
965 | char*t=enc->enc_value; | 965 | char*t=enc->enc_value; |
966 | encoding=QString(enc->enc_value); | 966 | encoding=QString(enc->enc_value); |
967 | enc->enc_value=0L; | 967 | enc->enc_value=0L; |
968 | free(t); | 968 | free(t); |
969 | } | 969 | } |
970 | } | 970 | } |
971 | if (which->bd_description) { | 971 | if (which->bd_description) { |
972 | target_part->setDescription(QString(which->bd_description)); | 972 | target_part->setDescription(QString(which->bd_description)); |
973 | } | 973 | } |
974 | target_part->setEncoding(encoding); | 974 | target_part->setEncoding(encoding); |
975 | target_part->setSize(which->bd_size); | 975 | target_part->setSize(which->bd_size); |
976 | } | 976 | } |
977 | void IMAPwrapper::deleteMailList(const QValueList<RecMailP>&target) | 977 | void IMAPwrapper::deleteMailList(const QValueList<RecMailP>&target) |
978 | { | 978 | { |
979 | //#if 0 | 979 | //#if 0 |
980 | mailimap_flag_list*flist; | 980 | mailimap_flag_list*flist; |
981 | mailimap_set *set; | 981 | mailimap_set *set; |
982 | mailimap_store_att_flags * store_flags; | 982 | mailimap_store_att_flags * store_flags; |
983 | int err; | 983 | int err; |
984 | login(); | 984 | login(); |
985 | //#endif | 985 | //#endif |
986 | if (!m_imap) { | 986 | if (!m_imap) { |
987 | return; | 987 | return; |
988 | } | 988 | } |
989 | int iii = 0; | 989 | int iii = 0; |
990 | int count = target.count(); | 990 | int count = target.count(); |
991 | // qDebug("imap remove count %d ", count); | 991 | // qDebug("imap remove count %d ", count); |
992 | 992 | ||
993 | 993 | ||
994 | mMax = count; | 994 | mMax = count; |
995 | progress( i18n("Delete")); | 995 | progress( i18n("Delete")); |
996 | 996 | ||
997 | QProgressBar wid ( count ); | 997 | QProgressBar wid ( count ); |
998 | wid.setCaption( i18n("Deleting ...")); | 998 | wid.setCaption( i18n("Deleting ...")); |
999 | wid.show(); | 999 | wid.show(); |
1000 | while (iii < count ) { | 1000 | while (iii < count ) { |
1001 | Global::statusMessage(i18n("Delete message %1 of %2").arg(iii).arg(count)); | 1001 | Global::statusMessage(i18n("Delete message %1 of %2").arg(iii).arg(count)); |
1002 | wid.setProgress( iii ); | 1002 | wid.setProgress( iii ); |
1003 | wid.raise(); | 1003 | wid.raise(); |
1004 | qApp->processEvents(); | 1004 | qApp->processEvents(); |
1005 | RecMailP mail = (*target.at( iii )); | 1005 | RecMailP mail = (*target.at( iii )); |
1006 | //#if 0 | 1006 | //#if 0 |
1007 | //qDebug("IMAP remove %d %d ", iii, mail->getNumber() ); | 1007 | //qDebug("IMAP remove %d %d ", iii, mail->getNumber() ); |
1008 | err = selectMbox(mail->getMbox()); | 1008 | err = selectMbox(mail->getMbox()); |
1009 | if ( err != MAILIMAP_NO_ERROR ) { | 1009 | if ( err != MAILIMAP_NO_ERROR ) { |
1010 | return; | 1010 | return; |
1011 | } | 1011 | } |
1012 | flist = mailimap_flag_list_new_empty(); | 1012 | flist = mailimap_flag_list_new_empty(); |
1013 | mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); | 1013 | mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); |
1014 | store_flags = mailimap_store_att_flags_new_set_flags(flist); | 1014 | store_flags = mailimap_store_att_flags_new_set_flags(flist); |
1015 | set = mailimap_set_new_single(mail->getNumber()); | 1015 | set = mailimap_set_new_single(mail->getNumber()); |
1016 | err = mailimap_store(m_imap,set,store_flags); | 1016 | err = mailimap_store(m_imap,set,store_flags); |
1017 | mailimap_set_free( set ); | 1017 | mailimap_set_free( set ); |
1018 | mailimap_store_att_flags_free(store_flags); | 1018 | mailimap_store_att_flags_free(store_flags); |
1019 | 1019 | ||
1020 | if (err != MAILIMAP_NO_ERROR) { | 1020 | if (err != MAILIMAP_NO_ERROR) { |
1021 | // odebug << "error deleting mail: " << m_imap->imap_response << "" << oendl; | 1021 | // odebug << "error deleting mail: " << m_imap->imap_response << "" << oendl; |
1022 | return; | 1022 | return; |
1023 | } | 1023 | } |
1024 | // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl; | 1024 | // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl; |
1025 | /* should we realy do that at this moment? */ | 1025 | /* should we realy do that at this moment? */ |
1026 | 1026 | ||
1027 | // err = mailimap_expunge(m_imap); | 1027 | // err = mailimap_expunge(m_imap); |
1028 | //if (err != MAILIMAP_NO_ERROR) { | 1028 | //if (err != MAILIMAP_NO_ERROR) { |
1029 | // Global::statusMessage(i18n("Error deleting mails: %s").arg(m_imap->imap_response)); | 1029 | // Global::statusMessage(i18n("Error deleting mails: %s").arg(m_imap->imap_response)); |
1030 | // } | 1030 | // } |
1031 | //#endif | 1031 | //#endif |
1032 | //deleteMail( mail); | 1032 | //deleteMail( mail); |
1033 | ++iii; | 1033 | ++iii; |
1034 | } | 1034 | } |
1035 | //qDebug("Deleting imap mails... "); | 1035 | //qDebug("Deleting imap mails... "); |
1036 | err = mailimap_expunge(m_imap); | 1036 | err = mailimap_expunge(m_imap); |
1037 | if (err != MAILIMAP_NO_ERROR) { | 1037 | if (err != MAILIMAP_NO_ERROR) { |
1038 | Global::statusMessage(i18n("Error deleting mails: %s").arg(m_imap->imap_response)); | 1038 | Global::statusMessage(i18n("Error deleting mails: %s").arg(m_imap->imap_response)); |
1039 | } | 1039 | } |
1040 | } | 1040 | } |
1041 | void IMAPwrapper::deleteMail(const RecMailP&mail) | 1041 | void IMAPwrapper::deleteMail(const RecMailP&mail) |
1042 | { | 1042 | { |
1043 | mailimap_flag_list*flist; | 1043 | mailimap_flag_list*flist; |
1044 | mailimap_set *set; | 1044 | mailimap_set *set; |
1045 | mailimap_store_att_flags * store_flags; | 1045 | mailimap_store_att_flags * store_flags; |
1046 | int err; | 1046 | int err; |
1047 | login(); | 1047 | login(); |
1048 | if (!m_imap) { | 1048 | if (!m_imap) { |
1049 | return; | 1049 | return; |
1050 | } | 1050 | } |
1051 | err = selectMbox(mail->getMbox()); | 1051 | err = selectMbox(mail->getMbox()); |
1052 | if ( err != MAILIMAP_NO_ERROR ) { | 1052 | if ( err != MAILIMAP_NO_ERROR ) { |
1053 | return; | 1053 | return; |
1054 | } | 1054 | } |
1055 | flist = mailimap_flag_list_new_empty(); | 1055 | flist = mailimap_flag_list_new_empty(); |
1056 | mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); | 1056 | mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); |
1057 | store_flags = mailimap_store_att_flags_new_set_flags(flist); | 1057 | store_flags = mailimap_store_att_flags_new_set_flags(flist); |
1058 | set = mailimap_set_new_single(mail->getNumber()); | 1058 | set = mailimap_set_new_single(mail->getNumber()); |
1059 | err = mailimap_store(m_imap,set,store_flags); | 1059 | err = mailimap_store(m_imap,set,store_flags); |
1060 | mailimap_set_free( set ); | 1060 | mailimap_set_free( set ); |
1061 | mailimap_store_att_flags_free(store_flags); | 1061 | mailimap_store_att_flags_free(store_flags); |
1062 | 1062 | ||
1063 | if (err != MAILIMAP_NO_ERROR) { | 1063 | if (err != MAILIMAP_NO_ERROR) { |
1064 | // odebug << "error deleting mail: " << m_imap->imap_response << "" << oendl; | 1064 | // odebug << "error deleting mail: " << m_imap->imap_response << "" << oendl; |
1065 | return; | 1065 | return; |
1066 | } | 1066 | } |
1067 | // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl; | 1067 | // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl; |
1068 | /* should we realy do that at this moment? */ | 1068 | /* should we realy do that at this moment? */ |
1069 | 1069 | ||
1070 | err = mailimap_expunge(m_imap); | 1070 | err = mailimap_expunge(m_imap); |
1071 | if (err != MAILIMAP_NO_ERROR) { | 1071 | if (err != MAILIMAP_NO_ERROR) { |
1072 | Global::statusMessage(i18n("error deleting mail: %s").arg(m_imap->imap_response)); | 1072 | Global::statusMessage(i18n("error deleting mail: %s").arg(m_imap->imap_response)); |
1073 | } | 1073 | } |
1074 | //qDebug("IMAPwrapper::deleteMail 2"); | 1074 | //qDebug("IMAPwrapper::deleteMail 2"); |
1075 | 1075 | ||
1076 | } | 1076 | } |
1077 | 1077 | ||
1078 | void IMAPwrapper::answeredMail(const RecMailP&mail) | 1078 | void IMAPwrapper::answeredMail(const RecMailP&mail) |
1079 | { | 1079 | { |
1080 | mailimap_flag_list*flist; | 1080 | mailimap_flag_list*flist; |
1081 | mailimap_set *set; | 1081 | mailimap_set *set; |
1082 | mailimap_store_att_flags * store_flags; | 1082 | mailimap_store_att_flags * store_flags; |
1083 | int err; | 1083 | int err; |
1084 | login(); | 1084 | login(); |
1085 | if (!m_imap) { | 1085 | if (!m_imap) { |
1086 | return; | 1086 | return; |
1087 | } | 1087 | } |
1088 | err = selectMbox(mail->getMbox()); | 1088 | err = selectMbox(mail->getMbox()); |
1089 | if ( err != MAILIMAP_NO_ERROR ) { | 1089 | if ( err != MAILIMAP_NO_ERROR ) { |
1090 | return; | 1090 | return; |
1091 | } | 1091 | } |
1092 | flist = mailimap_flag_list_new_empty(); | 1092 | flist = mailimap_flag_list_new_empty(); |
1093 | mailimap_flag_list_add(flist,mailimap_flag_new_answered()); | 1093 | mailimap_flag_list_add(flist,mailimap_flag_new_answered()); |
1094 | store_flags = mailimap_store_att_flags_new_add_flags(flist); | 1094 | store_flags = mailimap_store_att_flags_new_add_flags(flist); |
1095 | set = mailimap_set_new_single(mail->getNumber()); | 1095 | set = mailimap_set_new_single(mail->getNumber()); |
1096 | err = mailimap_store(m_imap,set,store_flags); | 1096 | err = mailimap_store(m_imap,set,store_flags); |
1097 | mailimap_set_free( set ); | 1097 | mailimap_set_free( set ); |
1098 | mailimap_store_att_flags_free(store_flags); | 1098 | mailimap_store_att_flags_free(store_flags); |
1099 | 1099 | ||
1100 | if (err != MAILIMAP_NO_ERROR) { | 1100 | if (err != MAILIMAP_NO_ERROR) { |
1101 | // odebug << "error marking mail: " << m_imap->imap_response << "" << oendl; | 1101 | // odebug << "error marking mail: " << m_imap->imap_response << "" << oendl; |
1102 | return; | 1102 | return; |
1103 | } | 1103 | } |
1104 | } | 1104 | } |
1105 | 1105 | ||
1106 | QString IMAPwrapper::fetchTextPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call,const QString&enc) | 1106 | QString IMAPwrapper::fetchTextPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call,const QString&enc) |
1107 | { | 1107 | { |
1108 | QString body(""); | 1108 | QString body(""); |
1109 | encodedString*res = fetchRawPart(mail,path,internal_call); | 1109 | encodedString*res = fetchRawPart(mail,path,internal_call); |
1110 | encodedString*r = decode_String(res,enc); | 1110 | encodedString*r = decode_String(res,enc); |
1111 | delete res; | 1111 | delete res; |
1112 | if (r) { | 1112 | if (r) { |
1113 | if (r->Length()>0) { | 1113 | if (r->Length()>0) { |
1114 | body = r->Content(); | 1114 | body = r->Content(); |
1115 | } | 1115 | } |
1116 | delete r; | 1116 | delete r; |
1117 | } | 1117 | } |
1118 | return body; | 1118 | return body; |
1119 | } | 1119 | } |
1120 | 1120 | ||
1121 | QString IMAPwrapper::fetchTextPart(const RecMailP&mail,const RecPartP&part) | 1121 | QString IMAPwrapper::fetchTextPart(const RecMailP&mail,const RecPartP&part) |
1122 | { | 1122 | { |
1123 | return fetchTextPart(mail,part->Positionlist(),false,part->Encoding()); | 1123 | return fetchTextPart(mail,part->Positionlist(),false,part->Encoding()); |
1124 | } | 1124 | } |
1125 | 1125 | ||
1126 | encodedString* IMAPwrapper::fetchDecodedPart(const RecMailP&mail,const RecPartP&part) | 1126 | encodedString* IMAPwrapper::fetchDecodedPart(const RecMailP&mail,const RecPartP&part) |
1127 | { | 1127 | { |
1128 | encodedString*res = fetchRawPart(mail,part->Positionlist(),false); | 1128 | encodedString*res = fetchRawPart(mail,part->Positionlist(),false); |
1129 | encodedString*r = decode_String(res,part->Encoding()); | 1129 | encodedString*r = decode_String(res,part->Encoding()); |
1130 | delete res; | 1130 | delete res; |
1131 | return r; | 1131 | return r; |
1132 | } | 1132 | } |
1133 | 1133 | ||
1134 | encodedString* IMAPwrapper::fetchRawPart(const RecMailP&mail,const RecPartP&part) | 1134 | encodedString* IMAPwrapper::fetchRawPart(const RecMailP&mail,const RecPartP&part) |
1135 | { | 1135 | { |
1136 | return fetchRawPart(mail,part->Positionlist(),false); | 1136 | return fetchRawPart(mail,part->Positionlist(),false); |
1137 | } | 1137 | } |
1138 | 1138 | ||
1139 | int IMAPwrapper::deleteAllMail(const FolderP&folder) | 1139 | int IMAPwrapper::deleteAllMail(const FolderP&folder) |
1140 | { | 1140 | { |
1141 | login(); | 1141 | login(); |
1142 | if (!m_imap) { | 1142 | if (!m_imap) { |
1143 | return 0; | 1143 | return 0; |
1144 | } | 1144 | } |
1145 | mailimap_flag_list*flist; | 1145 | mailimap_flag_list*flist; |
1146 | mailimap_set *set; | 1146 | mailimap_set *set; |
1147 | mailimap_store_att_flags * store_flags; | 1147 | mailimap_store_att_flags * store_flags; |
1148 | int err = selectMbox(folder->getName()); | 1148 | int err = selectMbox(folder->getName()); |
1149 | if ( err != MAILIMAP_NO_ERROR ) { | 1149 | if ( err != MAILIMAP_NO_ERROR ) { |
1150 | return 0; | 1150 | return 0; |
1151 | } | 1151 | } |
1152 | 1152 | ||
1153 | int last = m_imap->imap_selection_info->sel_exists; | 1153 | int last = m_imap->imap_selection_info->sel_exists; |
1154 | if (last == 0) { | 1154 | if (last == 0) { |
1155 | Global::statusMessage(i18n("Mailbox has no mails!")); | 1155 | Global::statusMessage(i18n("Mailbox has no mails!")); |
1156 | return 0; | 1156 | return 0; |
1157 | } | 1157 | } |
1158 | flist = mailimap_flag_list_new_empty(); | 1158 | flist = mailimap_flag_list_new_empty(); |
1159 | mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); | 1159 | mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); |
1160 | store_flags = mailimap_store_att_flags_new_set_flags(flist); | 1160 | store_flags = mailimap_store_att_flags_new_set_flags(flist); |
1161 | set = mailimap_set_new_interval( 1, last ); | 1161 | set = mailimap_set_new_interval( 1, last ); |
1162 | err = mailimap_store(m_imap,set,store_flags); | 1162 | err = mailimap_store(m_imap,set,store_flags); |
1163 | mailimap_set_free( set ); | 1163 | mailimap_set_free( set ); |
1164 | mailimap_store_att_flags_free(store_flags); | 1164 | mailimap_store_att_flags_free(store_flags); |
1165 | if (err != MAILIMAP_NO_ERROR) { | 1165 | if (err != MAILIMAP_NO_ERROR) { |
1166 | Global::statusMessage(i18n("error deleting mail: %s").arg(m_imap->imap_response)); | 1166 | Global::statusMessage(i18n("error deleting mail: %s").arg(m_imap->imap_response)); |
1167 | return 0; | 1167 | return 0; |
1168 | } | 1168 | } |
1169 | // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl; | 1169 | // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl; |
1170 | /* should we realy do that at this moment? */ | 1170 | /* should we realy do that at this moment? */ |
1171 | err = mailimap_expunge(m_imap); | 1171 | err = mailimap_expunge(m_imap); |
1172 | if (err != MAILIMAP_NO_ERROR) { | 1172 | if (err != MAILIMAP_NO_ERROR) { |
1173 | Global::statusMessage(i18n("error deleting mail: %s").arg(m_imap->imap_response)); | 1173 | Global::statusMessage(i18n("error deleting mail: %s").arg(m_imap->imap_response)); |
1174 | return 0; | 1174 | return 0; |
1175 | } | 1175 | } |
1176 | // odebug << "Delete successfull " << m_imap->imap_response << "" << oendl; | 1176 | // odebug << "Delete successfull " << m_imap->imap_response << "" << oendl; |
1177 | return 1; | 1177 | return 1; |
1178 | } | 1178 | } |
1179 | 1179 | ||
1180 | int IMAPwrapper::createMbox(const QString&folder,const FolderP&parentfolder,const QString& delemiter,bool getsubfolder) | 1180 | int IMAPwrapper::createMbox(const QString&folder,const FolderP&parentfolder,const QString& delemiter,bool getsubfolder) |
1181 | { | 1181 | { |
1182 | if (folder.length()==0) return 0; | 1182 | if (folder.length()==0) return 0; |
1183 | login(); | 1183 | login(); |
1184 | if (!m_imap) {return 0;} | 1184 | if (!m_imap) {return 0;} |
1185 | QString pre = account->getPrefix(); | 1185 | QString pre = account->getPrefix(); |
1186 | if (delemiter.length()>0 && pre.findRev(delemiter)!=((int)pre.length())-1) { | 1186 | if (delemiter.length()>0 && pre.findRev(delemiter)!=((int)pre.length())-1) { |
1187 | pre+=delemiter; | 1187 | pre+=delemiter; |
1188 | } | 1188 | } |
1189 | if (parentfolder) { | 1189 | if (parentfolder) { |
1190 | pre += parentfolder->getDisplayName()+delemiter; | 1190 | pre += parentfolder->getDisplayName()+delemiter; |
1191 | } | 1191 | } |
1192 | pre+=folder; | 1192 | pre+=folder; |
1193 | if (getsubfolder) { | 1193 | if (getsubfolder) { |
1194 | if (delemiter.length()>0) { | 1194 | if (delemiter.length()>0) { |
1195 | pre+=delemiter; | 1195 | pre+=delemiter; |
1196 | } else { | 1196 | } else { |
1197 | Global::statusMessage(i18n("Cannot create folder %1 for holding subfolders").arg(pre)); | 1197 | Global::statusMessage(i18n("Cannot create folder %1 for holding subfolders").arg(pre)); |
1198 | return 0; | 1198 | return 0; |
1199 | } | 1199 | } |
1200 | } | 1200 | } |
1201 | // odebug << "Creating " << pre.latin1() << "" << oendl; | 1201 | // odebug << "Creating " << pre.latin1() << "" << oendl; |
1202 | int res = mailimap_create(m_imap,pre.latin1()); | 1202 | int res = mailimap_create(m_imap,pre.latin1()); |
1203 | if (res != MAILIMAP_NO_ERROR) { | 1203 | if (res != MAILIMAP_NO_ERROR) { |
1204 | Global::statusMessage(i18n("%1").arg(m_imap->imap_response)); | 1204 | Global::statusMessage(i18n("%1").arg(m_imap->imap_response)); |
1205 | return 0; | 1205 | return 0; |
1206 | } | 1206 | } |
1207 | return 1; | 1207 | return 1; |
1208 | } | 1208 | } |
1209 | 1209 | ||
1210 | int IMAPwrapper::deleteMbox(const FolderP&folder) | 1210 | int IMAPwrapper::deleteMbox(const FolderP&folder) |
1211 | { | 1211 | { |
1212 | if (!folder) return 0; | 1212 | if (!folder) return 0; |
1213 | login(); | 1213 | login(); |
1214 | if (!m_imap) {return 0;} | 1214 | if (!m_imap) {return 0;} |
1215 | int res = mailimap_delete(m_imap,folder->getName()); | 1215 | int res = mailimap_delete(m_imap,folder->getName()); |
1216 | if (res != MAILIMAP_NO_ERROR) { | 1216 | if (res != MAILIMAP_NO_ERROR) { |
1217 | Global::statusMessage(i18n("%1").arg(m_imap->imap_response)); | 1217 | Global::statusMessage(i18n("%1").arg(m_imap->imap_response)); |
1218 | return 0; | 1218 | return 0; |
1219 | } | 1219 | } |
1220 | return 1; | 1220 | return 1; |
1221 | } | 1221 | } |
1222 | 1222 | ||
1223 | void IMAPwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) | 1223 | void IMAPwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) |
1224 | { | 1224 | { |
1225 | mailimap_status_att_list * att_list =0; | 1225 | mailimap_status_att_list * att_list =0; |
1226 | mailimap_mailbox_data_status * status=0; | 1226 | mailimap_mailbox_data_status * status=0; |
1227 | clistiter * cur = 0; | 1227 | clistiter * cur = 0; |
1228 | int r = 0; | 1228 | int r = 0; |
1229 | target_stat.message_count = 0; | 1229 | target_stat.message_count = 0; |
1230 | target_stat.message_unseen = 0; | 1230 | target_stat.message_unseen = 0; |
1231 | target_stat.message_recent = 0; | 1231 | target_stat.message_recent = 0; |
1232 | login(); | 1232 | login(); |
1233 | if (!m_imap) { | 1233 | if (!m_imap) { |
1234 | return; | 1234 | return; |
1235 | } | 1235 | } |
1236 | att_list = mailimap_status_att_list_new_empty(); | 1236 | att_list = mailimap_status_att_list_new_empty(); |
1237 | if (!att_list) return; | 1237 | if (!att_list) return; |
1238 | r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_MESSAGES); | 1238 | r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_MESSAGES); |
1239 | r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_RECENT); | 1239 | r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_RECENT); |
1240 | r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_UNSEEN); | 1240 | r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_UNSEEN); |
1241 | r = mailimap_status(m_imap, mailbox.latin1(), att_list, &status); | 1241 | r = mailimap_status(m_imap, mailbox.latin1(), att_list, &status); |
1242 | if (r==MAILIMAP_NO_ERROR&&status->st_info_list!=0) { | 1242 | if (r==MAILIMAP_NO_ERROR&&status->st_info_list!=0) { |
1243 | for (cur = clist_begin(status->st_info_list); | 1243 | for (cur = clist_begin(status->st_info_list); |
1244 | cur != NULL ; cur = clist_next(cur)) { | 1244 | cur != NULL ; cur = clist_next(cur)) { |
1245 | mailimap_status_info * status_info; | 1245 | mailimap_status_info * status_info; |
1246 | status_info = (mailimap_status_info *)clist_content(cur); | 1246 | status_info = (mailimap_status_info *)clist_content(cur); |
1247 | switch (status_info->st_att) { | 1247 | switch (status_info->st_att) { |
1248 | case MAILIMAP_STATUS_ATT_MESSAGES: | 1248 | case MAILIMAP_STATUS_ATT_MESSAGES: |
1249 | target_stat.message_count = status_info->st_value; | 1249 | target_stat.message_count = status_info->st_value; |
1250 | break; | 1250 | break; |
1251 | case MAILIMAP_STATUS_ATT_RECENT: | 1251 | case MAILIMAP_STATUS_ATT_RECENT: |
1252 | target_stat.message_recent = status_info->st_value; | 1252 | target_stat.message_recent = status_info->st_value; |
1253 | break; | 1253 | break; |
1254 | case MAILIMAP_STATUS_ATT_UNSEEN: | 1254 | case MAILIMAP_STATUS_ATT_UNSEEN: |
1255 | target_stat.message_unseen = status_info->st_value; | 1255 | target_stat.message_unseen = status_info->st_value; |
1256 | break; | 1256 | break; |
1257 | } | 1257 | } |
1258 | } | 1258 | } |
1259 | } else { | 1259 | } else { |
1260 | // odebug << "Error retrieving status" << oendl; | 1260 | // odebug << "Error retrieving status" << oendl; |
1261 | } | 1261 | } |
1262 | if (status) mailimap_mailbox_data_status_free(status); | 1262 | if (status) mailimap_mailbox_data_status_free(status); |
1263 | if (att_list) mailimap_status_att_list_free(att_list); | 1263 | if (att_list) mailimap_status_att_list_free(att_list); |
1264 | } | 1264 | } |
1265 | 1265 | ||
1266 | void IMAPwrapper::storeMessage(const char*msg,size_t length, const QString&folder) | 1266 | void IMAPwrapper::storeMessage(const char*msg,size_t length, const QString&folder) |
1267 | { | 1267 | { |
1268 | login(); | 1268 | login(); |
1269 | if (!m_imap) return; | 1269 | if (!m_imap) return; |
1270 | if (!msg) return; | 1270 | if (!msg) return; |
1271 | int r = mailimap_append(m_imap,(char*)folder.latin1(),0,0,msg,length); | 1271 | int r = mailimap_append(m_imap,(char*)folder.latin1(),0,0,msg,length); |
1272 | if (r != MAILIMAP_NO_ERROR) { | 1272 | if (r != MAILIMAP_NO_ERROR) { |
1273 | Global::statusMessage("Error storing mail!"); | 1273 | Global::statusMessage("Error storing mail!"); |
1274 | } | 1274 | } |
1275 | } | 1275 | } |
1276 | 1276 | ||
1277 | MAILLIB::ATYPE IMAPwrapper::getType()const | 1277 | MAILLIB::ATYPE IMAPwrapper::getType()const |
1278 | { | 1278 | { |
1279 | return account->getType(); | 1279 | return account->getType(); |
1280 | } | 1280 | } |
1281 | 1281 | ||
1282 | const QString&IMAPwrapper::getName()const | 1282 | const QString&IMAPwrapper::getName()const |
1283 | { | 1283 | { |
1284 | // odebug << "Get name: " << account->getAccountName().latin1() << "" << oendl; | 1284 | // odebug << "Get name: " << account->getAccountName().latin1() << "" << oendl; |
1285 | return account->getAccountName(); | 1285 | return account->getAccountName(); |
1286 | } | 1286 | } |
1287 | 1287 | ||
1288 | encodedString* IMAPwrapper::fetchRawBody(const RecMailP&mail) | 1288 | encodedString* IMAPwrapper::fetchRawBody(const RecMailP&mail) |
1289 | { | 1289 | { |
1290 | // dummy | 1290 | // dummy |
1291 | QValueList<int> path; | 1291 | QValueList<int> path; |
1292 | return fetchRawPart(mail,path,false); | 1292 | return fetchRawPart(mail,path,false); |
1293 | } | 1293 | } |
1294 | 1294 | ||
1295 | void IMAPwrapper::mvcpAllMails(const FolderP&fromFolder, | 1295 | void IMAPwrapper::mvcpAllMails(const FolderP&fromFolder, |
1296 | const QString&targetFolder,AbstractMail*targetWrapper,bool moveit, int maxSizeInKb) | 1296 | const QString&targetFolder,AbstractMail*targetWrapper,bool moveit, int maxSizeInKb) |
1297 | { | 1297 | { |
1298 | if (targetWrapper != this || maxSizeInKb > 0 ) { | 1298 | if (targetWrapper != this || maxSizeInKb > 0 ) { |
1299 | mMax = 0; | 1299 | mMax = 0; |
1300 | progress( i18n("Copy")); | 1300 | progress( i18n("Copy")); |
1301 | AbstractMail::mvcpAllMails(fromFolder,targetFolder,targetWrapper,moveit, maxSizeInKb); | 1301 | AbstractMail::mvcpAllMails(fromFolder,targetFolder,targetWrapper,moveit, maxSizeInKb); |
1302 | //qDebug("IMAPwrapper::mvcpAllMails::Using generic"); | 1302 | //qDebug("IMAPwrapper::mvcpAllMails::Using generic"); |
1303 | // odebug << "Using generic" << oendl; | 1303 | // odebug << "Using generic" << oendl; |
1304 | return; | 1304 | return; |
1305 | } | 1305 | } |
1306 | mailimap_set *set = 0; | 1306 | mailimap_set *set = 0; |
1307 | login(); | 1307 | login(); |
1308 | if (!m_imap) { | 1308 | if (!m_imap) { |
1309 | return; | 1309 | return; |
1310 | } | 1310 | } |
1311 | int err = selectMbox(fromFolder->getName()); | 1311 | int err = selectMbox(fromFolder->getName()); |
1312 | if ( err != MAILIMAP_NO_ERROR ) { | 1312 | if ( err != MAILIMAP_NO_ERROR ) { |
1313 | return; | 1313 | return; |
1314 | } | 1314 | } |
1315 | Global::statusMessage( i18n("Copying mails on server...") ); | 1315 | Global::statusMessage( i18n("Copying mails on server...") ); |
1316 | int last = m_imap->imap_selection_info->sel_exists; | 1316 | int last = m_imap->imap_selection_info->sel_exists; |
1317 | set = mailimap_set_new_interval( 1, last ); | 1317 | set = mailimap_set_new_interval( 1, last ); |
1318 | err = mailimap_copy(m_imap,set,targetFolder.latin1()); | 1318 | err = mailimap_copy(m_imap,set,targetFolder.latin1()); |
1319 | mailimap_set_free( set ); | 1319 | mailimap_set_free( set ); |
1320 | if ( err != MAILIMAP_NO_ERROR ) { | 1320 | if ( err != MAILIMAP_NO_ERROR ) { |
1321 | QString error_msg = i18n("Error copy mails: %1").arg(m_imap->imap_response); | 1321 | QString error_msg = i18n("Error copy mails: %1").arg(m_imap->imap_response); |
1322 | Global::statusMessage(error_msg); | 1322 | Global::statusMessage(error_msg); |
1323 | // odebug << error_msg << oendl; | 1323 | // odebug << error_msg << oendl; |
1324 | return; | 1324 | return; |
1325 | } | 1325 | } |
1326 | if (moveit) { | 1326 | if (moveit) { |
1327 | deleteAllMail(fromFolder); | 1327 | deleteAllMail(fromFolder); |
1328 | } | 1328 | } |
1329 | } | 1329 | } |
1330 | 1330 | ||
1331 | void IMAPwrapper::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) | 1331 | void IMAPwrapper::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) |
1332 | { | 1332 | { |
1333 | if (targetWrapper != this) { | 1333 | if (targetWrapper != this) { |
1334 | // odebug << "Using generic" << oendl; | 1334 | // odebug << "Using generic" << oendl; |
1335 | AbstractMail::mvcpMail(mail,targetFolder,targetWrapper,moveit); | 1335 | AbstractMail::mvcpMail(mail,targetFolder,targetWrapper,moveit); |
1336 | return; | 1336 | return; |
1337 | } | 1337 | } |
1338 | mailimap_set *set = 0; | 1338 | mailimap_set *set = 0; |
1339 | login(); | 1339 | login(); |
1340 | if (!m_imap) { | 1340 | if (!m_imap) { |
1341 | return; | 1341 | return; |
1342 | } | 1342 | } |
1343 | int err = selectMbox(mail->getMbox()); | 1343 | int err = selectMbox(mail->getMbox()); |
1344 | if ( err != MAILIMAP_NO_ERROR ) { | 1344 | if ( err != MAILIMAP_NO_ERROR ) { |
1345 | return; | 1345 | return; |
1346 | } | 1346 | } |
1347 | set = mailimap_set_new_single(mail->getNumber()); | 1347 | set = mailimap_set_new_single(mail->getNumber()); |
1348 | err = mailimap_copy(m_imap,set,targetFolder.latin1()); | 1348 | err = mailimap_copy(m_imap,set,targetFolder.latin1()); |
1349 | mailimap_set_free( set ); | 1349 | mailimap_set_free( set ); |
1350 | if ( err != MAILIMAP_NO_ERROR ) { | 1350 | if ( err != MAILIMAP_NO_ERROR ) { |
1351 | QString error_msg = i18n("error copy mail: %1").arg(m_imap->imap_response); | 1351 | QString error_msg = i18n("error copy mail: %1").arg(m_imap->imap_response); |
1352 | Global::statusMessage(error_msg); | 1352 | Global::statusMessage(error_msg); |
1353 | // odebug << error_msg << oendl; | 1353 | // odebug << error_msg << oendl; |
1354 | return; | 1354 | return; |
1355 | } | 1355 | } |
1356 | if (moveit) { | 1356 | if (moveit) { |
1357 | deleteMail(mail); | 1357 | deleteMail(mail); |
1358 | } | 1358 | } |
1359 | } | 1359 | } |
diff --git a/kmicromail/libmailwrapper/mailwrapper.h b/kmicromail/libmailwrapper/mailwrapper.h index ea6bf36..3e8b51f 100644 --- a/kmicromail/libmailwrapper/mailwrapper.h +++ b/kmicromail/libmailwrapper/mailwrapper.h | |||
@@ -1,131 +1,131 @@ | |||
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 | #include <qfileinfo.h> | 8 | #include <qfileinfo.h> |
9 | #include <kiconloader.h> | 9 | #include <kiconloader.h> |
10 | 10 | ||
11 | #include "settings.h" | 11 | #include "settings.h" |
12 | 12 | ||
13 | #include <opie2/osmartpointer.h> | 13 | #include <opie2/osmartpointer.h> |
14 | /* | 14 | /* |
15 | class Attachment | 15 | class Attachment |
16 | { | 16 | { |
17 | public: | 17 | public: |
18 | Attachment( DocLnk lnk ); | 18 | Attachment( DocLnk lnk ); |
19 | virtual ~Attachment(){} | 19 | virtual ~Attachment(){} |
20 | const QString getFileName()const{ return doc.file(); } | 20 | const QString getFileName()const{ return doc.file(); } |
21 | const QString getName()const{ return doc.name(); } | 21 | const QString getName()const{ return doc.name(); } |
22 | const QString getMimeType()const{ return doc.type(); } | 22 | const QString getMimeType()const{ return doc.type(); } |
23 | const QPixmap getPixmap()const{ return doc.pixmap(); } | 23 | const QPixmap getPixmap()const{ return doc.pixmap(); } |
24 | const int getSize()const { return size; } | 24 | const int getSize()const { return size; } |
25 | DocLnk getDocLnk() { return doc; } | 25 | DocLnk getDocLnk() { return doc; } |
26 | 26 | ||
27 | protected: | 27 | protected: |
28 | DocLnk doc; | 28 | DocLnk doc; |
29 | int size; | 29 | int size; |
30 | 30 | ||
31 | }; | 31 | }; |
32 | */ | 32 | */ |
33 | 33 | ||
34 | class Attachment | 34 | class Attachment |
35 | { | 35 | { |
36 | public: | 36 | public: |
37 | Attachment( QString lnk ); | 37 | Attachment( QString lnk ); |
38 | virtual ~Attachment(){} | 38 | virtual ~Attachment(){} |
39 | const QString getFileName()const{ return doc; } | 39 | const QString getFileName()const{ return doc; } |
40 | const QString getName()const{ return QFileInfo( doc ).baseName (); } | 40 | const QString getName()const{ return QFileInfo( doc ).baseName (); } |
41 | const QString getMimeType()const{ return QFileInfo( doc ).extension(false); } | 41 | const QString getMimeType()const{ return QFileInfo( doc ).extension(false); } |
42 | const QPixmap getPixmap()const{ return mPix; } | 42 | const QPixmap getPixmap()const{ return mPix; } |
43 | const int getSize()const { return size; } | 43 | const int getSize()const { return size; } |
44 | QString getDocLnk() { return doc; } | 44 | QString getDocLnk() { return doc; } |
45 | 45 | ||
46 | protected: | 46 | protected: |
47 | QPixmap mPix; | 47 | QPixmap mPix; |
48 | QString doc; | 48 | QString doc; |
49 | int size; | 49 | int size; |
50 | 50 | ||
51 | }; | 51 | }; |
52 | 52 | ||
53 | class Mail:public Opie::Core::ORefCount | 53 | class Mail:public Opie::Core::ORefCount |
54 | { | 54 | { |
55 | public: | 55 | public: |
56 | Mail(); | 56 | Mail(); |
57 | /* Possible that this destructor must not be declared virtual | 57 | /* Possible that this destructor must not be declared virtual |
58 | * 'cause it seems that it will never have some child classes. | 58 | * 'cause it seems that it will never have some child classes. |
59 | * in this case this object will not get a virtual table -> memory and | 59 | * in this case this object will not get a virtual table -> memory and |
60 | * speed will be a little bit better? | 60 | * speed will be a little bit better? |
61 | */ | 61 | */ |
62 | virtual ~Mail(){} | 62 | virtual ~Mail(){} |
63 | void addAttachment( Attachment *att ) { attList.append( att ); } | 63 | void addAttachment( Attachment *att ) { attList.append( att ); } |
64 | const QList<Attachment>& getAttachments()const { return attList; } | 64 | const QList<Attachment>& getAttachments()const { return attList; } |
65 | void removeAttachment( Attachment *att ) { attList.remove( att ); } | 65 | void removeAttachment( Attachment *att ) { attList.remove( att ); } |
66 | const QString&getName()const { return name; } | 66 | const QString&getName()const { return name; } |
67 | void setName( QString s ) { name = s; } | 67 | void setName( QString s ) { name = s; } |
68 | const QString&getMail()const{ return mail; } | 68 | const QString&getMail()const{ return mail; } |
69 | void setMail( const QString&s ) { mail = s; } | 69 | void setMail( const QString&s ) { mail = s; } |
70 | const QString&getTo()const{ return to; } | 70 | const QString&getTo()const{ return to; } |
71 | void setTo( const QString&s ) { to = s; } | 71 | void setTo( const QString&s ) { to = s; } |
72 | const QString&getCC()const{ return cc; } | 72 | const QString&getCC()const{ return cc; } |
73 | void setCC( const QString&s ) { cc = s; } | 73 | void setCC( const QString&s ) { cc = s; } |
74 | const QString&getBCC()const { return bcc; } | 74 | const QString&getBCC()const { return bcc; } |
75 | void setBCC( const QString&s ) { bcc = s; } | 75 | void setBCC( const QString&s ) { bcc = s; } |
76 | const QString&getMessage()const { return message; } | 76 | const QString&getMessage()const { return message; } |
77 | void setMessage( const QString&s ) { message = s; } | 77 | void setMessage( const QString&s ) { message = s; } |
78 | const QString&getSubject()const { return subject; } | 78 | const QString&getSubject()const { return subject; } |
79 | void setSubject( const QString&s ) { subject = s; } | 79 | void setSubject( const QString&s ) { subject = s; } |
80 | const QString&getReply()const{ return reply; } | 80 | const QString&getReply()const{ return reply; } |
81 | void setReply( const QString&a ) { reply = a; } | 81 | void setReply( const QString&a ) { reply = a; } |
82 | void setInreply(const QStringList&list){m_in_reply_to = list;} | 82 | void setInreply(const QStringList&list){m_in_reply_to = list;} |
83 | const QStringList&Inreply()const{return m_in_reply_to;} | 83 | const QStringList&Inreply()const{return m_in_reply_to;} |
84 | 84 | ||
85 | void setCharset( const QString&a ) { charset= a; } | 85 | void setCharset( const QString&a ) { charset= a; } |
86 | const QString& getCharset() { return charset; } | 86 | const QString& getCharset() const { return charset; } |
87 | 87 | ||
88 | private: | 88 | private: |
89 | QList<Attachment> attList; | 89 | QList<Attachment> attList; |
90 | QString name, mail, to, cc, bcc, reply, subject, message, charset; | 90 | QString name, mail, to, cc, bcc, reply, subject, message, charset; |
91 | QStringList m_in_reply_to; | 91 | QStringList m_in_reply_to; |
92 | }; | 92 | }; |
93 | 93 | ||
94 | class Folder:public Opie::Core::ORefCount | 94 | class Folder:public Opie::Core::ORefCount |
95 | { | 95 | { |
96 | public: | 96 | public: |
97 | Folder( const QString&init_name,const QString&sep ); | 97 | Folder( const QString&init_name,const QString&sep ); |
98 | virtual ~Folder(); | 98 | virtual ~Folder(); |
99 | const QString&getDisplayName()const { return nameDisplay; } | 99 | const QString&getDisplayName()const { return nameDisplay; } |
100 | const QString&getName()const { return name; } | 100 | const QString&getName()const { return name; } |
101 | const QString&getPrefix()const{return prefix; } | 101 | const QString&getPrefix()const{return prefix; } |
102 | virtual bool may_select()const{return true;} | 102 | virtual bool may_select()const{return true;} |
103 | virtual bool no_inferior()const{return true;} | 103 | virtual bool no_inferior()const{return true;} |
104 | const QString&Separator()const; | 104 | const QString&Separator()const; |
105 | 105 | ||
106 | protected: | 106 | protected: |
107 | QString nameDisplay, name, separator,prefix; | 107 | QString nameDisplay, name, separator,prefix; |
108 | }; | 108 | }; |
109 | 109 | ||
110 | typedef Opie::Core::OSmartPointer<Folder> FolderP; | 110 | typedef Opie::Core::OSmartPointer<Folder> FolderP; |
111 | 111 | ||
112 | class MHFolder : public Folder | 112 | class MHFolder : public Folder |
113 | { | 113 | { |
114 | public: | 114 | public: |
115 | MHFolder(const QString&disp_name,const QString&mbox); | 115 | MHFolder(const QString&disp_name,const QString&mbox); |
116 | virtual ~MHFolder(); | 116 | virtual ~MHFolder(); |
117 | }; | 117 | }; |
118 | 118 | ||
119 | class IMAPFolder : public Folder | 119 | class IMAPFolder : public Folder |
120 | { | 120 | { |
121 | public: | 121 | public: |
122 | IMAPFolder(const QString&name, const QString&sep, bool select=true,bool noinf=false,const QString&prefix="" ); | 122 | IMAPFolder(const QString&name, const QString&sep, bool select=true,bool noinf=false,const QString&prefix="" ); |
123 | virtual ~IMAPFolder(); | 123 | virtual ~IMAPFolder(); |
124 | virtual bool may_select()const{return m_MaySelect;} | 124 | virtual bool may_select()const{return m_MaySelect;} |
125 | virtual bool no_inferior()const{return m_NoInferior;} | 125 | virtual bool no_inferior()const{return m_NoInferior;} |
126 | static QString decodeFolderName( const QString &name ); | 126 | static QString decodeFolderName( const QString &name ); |
127 | private: | 127 | private: |
128 | bool m_MaySelect,m_NoInferior; | 128 | bool m_MaySelect,m_NoInferior; |
129 | }; | 129 | }; |
130 | 130 | ||
131 | #endif | 131 | #endif |