summaryrefslogtreecommitdiffabout
path: root/kmicromail
authorzautrix <zautrix>2004-11-01 14:15:56 (UTC)
committer zautrix <zautrix>2004-11-01 14:15:56 (UTC)
commit3320af5e47cdb4b54c4185c91d0332c013d90818 (patch) (unidiff)
tree9d7db42d4350616d315c5f95e1ac0aed00ed1314 /kmicromail
parent56845a3ee7013af8a2db26a89aa151ee482ef0ed (diff)
downloadkdepimpi-3320af5e47cdb4b54c4185c91d0332c013d90818.zip
kdepimpi-3320af5e47cdb4b54c4185c91d0332c013d90818.tar.gz
kdepimpi-3320af5e47cdb4b54c4185c91d0332c013d90818.tar.bz2
ompi fixes
Diffstat (limited to 'kmicromail') (more/less context) (ignore whitespace changes)
-rw-r--r--kmicromail/libetpan/mime/mailmime_decode.c3
-rw-r--r--kmicromail/libmailwrapper/generatemail.cpp13
-rw-r--r--kmicromail/libmailwrapper/imapwrapper.cpp7
-rw-r--r--kmicromail/libmailwrapper/settings.cpp3
-rw-r--r--kmicromail/opiemail.cpp11
5 files changed, 24 insertions, 13 deletions
diff --git a/kmicromail/libetpan/mime/mailmime_decode.c b/kmicromail/libetpan/mime/mailmime_decode.c
index e48ec19..dbaeb68 100644
--- a/kmicromail/libetpan/mime/mailmime_decode.c
+++ b/kmicromail/libetpan/mime/mailmime_decode.c
@@ -1,543 +1,544 @@
1/* 1/*
2 * libEtPan! -- a mail stuff library 2 * libEtPan! -- a mail stuff library
3 * 3 *
4 * Copyright (C) 2001, 2002 - DINH Viet Hoa 4 * Copyright (C) 2001, 2002 - DINH Viet Hoa
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the libEtPan! project nor the names of its 15 * 3. Neither the name of the libEtPan! project nor the names of its
16 * contributors may be used to endorse or promote products derived 16 * contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission. 17 * from this software without specific prior written permission.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE. 29 * SUCH DAMAGE.
30 */ 30 */
31 31
32/* 32/*
33 * $Id$ 33 * $Id$
34 */ 34 */
35 35
36/* 36/*
37 RFC 2047 : MIME (Multipurpose Internet Mail Extensions) Part Three: 37 RFC 2047 : MIME (Multipurpose Internet Mail Extensions) Part Three:
38 Message Header Extensions for Non-ASCII Text 38 Message Header Extensions for Non-ASCII Text
39*/ 39*/
40 40
41#include "mailmime_decode.h" 41#include "mailmime_decode.h"
42 42
43#include <ctype.h> 43#include <ctype.h>
44#include <unistd.h> 44#include <unistd.h>
45#include <sys/mman.h> 45#include <sys/mman.h>
46#include <string.h> 46#include <string.h>
47#include <stdlib.h> 47#include <stdlib.h>
48 48
49#include "mailmime_content.h" 49#include "mailmime_content.h"
50 50
51#include "charconv.h" 51#include "charconv.h"
52#include "mmapstring.h" 52#include "mmapstring.h"
53#include "mailimf.h" 53#include "mailimf.h"
54 54
55#ifndef TRUE 55#ifndef TRUE
56#define TRUE 1 56#define TRUE 1
57#endif 57#endif
58 58
59#ifndef FALSE 59#ifndef FALSE
60#define FALSE 0 60#define FALSE 0
61#endif 61#endif
62 62
63static int mailmime_charset_parse(const char * message, size_t length, 63static int mailmime_charset_parse(const char * message, size_t length,
64 size_t * index, char ** charset); 64 size_t * index, char ** charset);
65 65
66enum { 66enum {
67 MAILMIME_ENCODING_B, 67 MAILMIME_ENCODING_B,
68 MAILMIME_ENCODING_Q 68 MAILMIME_ENCODING_Q
69}; 69};
70 70
71static int mailmime_encoding_parse(const char * message, size_t length, 71static int mailmime_encoding_parse(const char * message, size_t length,
72 size_t * index, int * result); 72 size_t * index, int * result);
73 73
74static int mailmime_etoken_parse(const char * message, size_t length, 74static int mailmime_etoken_parse(const char * message, size_t length,
75 size_t * index, char ** result); 75 size_t * index, char ** result);
76 76
77static int 77static int
78mailmime_non_encoded_word_parse(const char * message, size_t length, 78mailmime_non_encoded_word_parse(const char * message, size_t length,
79 size_t * index, 79 size_t * index,
80 char ** result); 80 char ** result);
81 81
82static int 82static int
83mailmime_encoded_word_parse(const char * message, size_t length, 83mailmime_encoded_word_parse(const char * message, size_t length,
84 size_t * index, 84 size_t * index,
85 struct mailmime_encoded_word ** result); 85 struct mailmime_encoded_word ** result);
86 86
87 87
88enum { 88enum {
89 TYPE_ERROR, 89 TYPE_ERROR,
90 TYPE_WORD, 90 TYPE_WORD,
91 TYPE_ENCODED_WORD, 91 TYPE_ENCODED_WORD,
92}; 92};
93 93
94int mailmime_encoded_phrase_parse(const char * default_fromcode, 94int mailmime_encoded_phrase_parse(const char * default_fromcode,
95 const char * message, size_t length, 95 const char * message, size_t length,
96 size_t * index, const char * tocode, 96 size_t * index, const char * tocode,
97 char ** result) 97 char ** result)
98{ 98{
99 MMAPString * gphrase; 99 MMAPString * gphrase;
100 struct mailmime_encoded_word * word; 100 struct mailmime_encoded_word * word;
101 int first; 101 int first;
102 size_t cur_token; 102 size_t cur_token;
103 int r; 103 int r;
104 int res; 104 int res;
105 char * str; 105 char * str;
106 char * wordutf8; 106 char * wordutf8;
107 int type; 107 int type;
108 108
109 cur_token = * index; 109 cur_token = * index;
110 110
111 gphrase = mmap_string_new(""); 111 gphrase = mmap_string_new("");
112 if (gphrase == NULL) { 112 if (gphrase == NULL) {
113 res = MAILIMF_ERROR_MEMORY; 113 res = MAILIMF_ERROR_MEMORY;
114 goto err; 114 goto err;
115 } 115 }
116 116
117 first = TRUE; 117 first = TRUE;
118 118
119 type = TYPE_ERROR; /* XXX - removes a gcc warning */ 119 type = TYPE_ERROR; /* XXX - removes a gcc warning */
120 120
121 while (1) { 121 while (1) {
122 122
123 r = mailmime_encoded_word_parse(message, length, &cur_token, &word); 123 r = mailmime_encoded_word_parse(message, length, &cur_token, &word);
124 if (r == MAILIMF_NO_ERROR) { 124 if (r == MAILIMF_NO_ERROR) {
125 if (!first) { 125 if (!first) {
126 if (type != TYPE_ENCODED_WORD) { 126 if (type != TYPE_ENCODED_WORD) {
127 if (mmap_string_append_c(gphrase, ' ') == NULL) { 127 if (mmap_string_append_c(gphrase, ' ') == NULL) {
128 mailmime_encoded_word_free(word); 128 mailmime_encoded_word_free(word);
129 res = MAILIMF_ERROR_MEMORY; 129 res = MAILIMF_ERROR_MEMORY;
130 goto free; 130 goto free;
131 } 131 }
132 } 132 }
133 } 133 }
134 type = TYPE_ENCODED_WORD; 134 type = TYPE_ENCODED_WORD;
135 wordutf8 = NULL; 135 wordutf8 = NULL;
136 r = charconv(tocode, word->wd_charset, word->wd_text, 136 r = charconv(tocode, word->wd_charset, word->wd_text,
137 strlen(word->wd_text), &wordutf8); 137 strlen(word->wd_text), &wordutf8);
138 switch (r) { 138 switch (r) {
139 case MAIL_CHARCONV_ERROR_MEMORY: 139 case MAIL_CHARCONV_ERROR_MEMORY:
140 mailmime_encoded_word_free(word); 140 mailmime_encoded_word_free(word);
141 res = MAILIMF_ERROR_MEMORY; 141 res = MAILIMF_ERROR_MEMORY;
142 goto free; 142 goto free;
143 143
144 case MAIL_CHARCONV_ERROR_UNKNOWN_CHARSET: 144 case MAIL_CHARCONV_ERROR_UNKNOWN_CHARSET:
145 case MAIL_CHARCONV_ERROR_CONV: 145 case MAIL_CHARCONV_ERROR_CONV:
146 mailmime_encoded_word_free(word); 146 mailmime_encoded_word_free(word);
147 res = MAILIMF_ERROR_PARSE; 147 res = MAILIMF_ERROR_PARSE;
148 goto free; 148 goto free;
149 } 149 }
150 150
151 if (wordutf8 != NULL) { 151 if (wordutf8 != NULL) {
152 if (mmap_string_append(gphrase, wordutf8) == NULL) { 152 if (mmap_string_append(gphrase, wordutf8) == NULL) {
153 mailmime_encoded_word_free(word); 153 mailmime_encoded_word_free(word);
154 free(wordutf8); 154 free(wordutf8);
155 res = MAILIMF_ERROR_MEMORY; 155 res = MAILIMF_ERROR_MEMORY;
156 goto free; 156 goto free;
157 } 157 }
158 free(wordutf8); 158 free(wordutf8);
159 } 159 }
160 mailmime_encoded_word_free(word); 160 mailmime_encoded_word_free(word);
161 first = FALSE; 161 first = FALSE;
162 } 162 }
163 else if (r == MAILIMF_ERROR_PARSE) { 163 else if (r == MAILIMF_ERROR_PARSE) {
164 /* do nothing */ 164 /* do nothing */
165 } 165 }
166 else { 166 else {
167 res = r; 167 res = r;
168 goto free; 168 goto free;
169 } 169 }
170 170
171 if (r == MAILIMF_ERROR_PARSE) { 171 if (r == MAILIMF_ERROR_PARSE) {
172 char * raw_word; 172 char * raw_word;
173 173
174 r = mailmime_non_encoded_word_parse(message, length, 174 r = mailmime_non_encoded_word_parse(message, length,
175 &cur_token, &raw_word); 175 &cur_token, &raw_word);
176 if (r == MAILIMF_NO_ERROR) { 176 if (r == MAILIMF_NO_ERROR) {
177 if (!first) { 177 if (!first) {
178 if (mmap_string_append_c(gphrase, ' ') == NULL) { 178 if (mmap_string_append_c(gphrase, ' ') == NULL) {
179 free(raw_word); 179 free(raw_word);
180 res = MAILIMF_ERROR_MEMORY; 180 res = MAILIMF_ERROR_MEMORY;
181 goto free; 181 goto free;
182 } 182 }
183 } 183 }
184 type = TYPE_WORD; 184 type = TYPE_WORD;
185 185
186 wordutf8 = NULL; 186 wordutf8 = NULL;
187 r = charconv(tocode, default_fromcode, raw_word, 187 r = charconv(tocode, default_fromcode, raw_word,
188 strlen(raw_word), &wordutf8); 188 strlen(raw_word), &wordutf8);
189 189
190 switch (r) { 190 switch (r) {
191 case MAIL_CHARCONV_ERROR_MEMORY: 191 case MAIL_CHARCONV_ERROR_MEMORY:
192 free(raw_word); 192 free(raw_word);
193 res = MAILIMF_ERROR_MEMORY; 193 res = MAILIMF_ERROR_MEMORY;
194 goto free; 194 goto free;
195 195
196 case MAIL_CHARCONV_ERROR_UNKNOWN_CHARSET: 196 case MAIL_CHARCONV_ERROR_UNKNOWN_CHARSET:
197 case MAIL_CHARCONV_ERROR_CONV: 197 case MAIL_CHARCONV_ERROR_CONV:
198 free(raw_word); 198 free(raw_word);
199 res = MAILIMF_ERROR_PARSE; 199 res = MAILIMF_ERROR_PARSE;
200 goto free; 200 goto free;
201 } 201 }
202 202
203 if (mmap_string_append(gphrase, wordutf8) == NULL) { 203 if (mmap_string_append(gphrase, wordutf8) == NULL) {
204 free(wordutf8); 204 free(wordutf8);
205 free(raw_word); 205 free(raw_word);
206 res = MAILIMF_ERROR_MEMORY; 206 res = MAILIMF_ERROR_MEMORY;
207 goto free; 207 goto free;
208 } 208 }
209 209 // LUTZ fix
210 free(wordutf8);
210 free(raw_word); 211 free(raw_word);
211 first = FALSE; 212 first = FALSE;
212 } 213 }
213 else if (r == MAILIMF_ERROR_PARSE) { 214 else if (r == MAILIMF_ERROR_PARSE) {
214 break; 215 break;
215 } 216 }
216 else { 217 else {
217 res = r; 218 res = r;
218 goto free; 219 goto free;
219 } 220 }
220 } 221 }
221 } 222 }
222 223
223 if (first) { 224 if (first) {
224 res = MAILIMF_ERROR_PARSE; 225 res = MAILIMF_ERROR_PARSE;
225 goto free; 226 goto free;
226 } 227 }
227 228
228 str = strdup(gphrase->str); 229 str = strdup(gphrase->str);
229 if (str == NULL) { 230 if (str == NULL) {
230 res = MAILIMF_ERROR_MEMORY; 231 res = MAILIMF_ERROR_MEMORY;
231 goto free; 232 goto free;
232 } 233 }
233 mmap_string_free(gphrase); 234 mmap_string_free(gphrase);
234 235
235 * result = str; 236 * result = str;
236 * index = cur_token; 237 * index = cur_token;
237 238
238 return MAILIMF_NO_ERROR; 239 return MAILIMF_NO_ERROR;
239 240
240 free: 241 free:
241 mmap_string_free(gphrase); 242 mmap_string_free(gphrase);
242 err: 243 err:
243 return res; 244 return res;
244} 245}
245 246
246static int 247static int
247mailmime_non_encoded_word_parse(const char * message, size_t length, 248mailmime_non_encoded_word_parse(const char * message, size_t length,
248 size_t * index, 249 size_t * index,
249 char ** result) 250 char ** result)
250{ 251{
251 int end; 252 int end;
252 size_t cur_token; 253 size_t cur_token;
253 int res; 254 int res;
254 char * text; 255 char * text;
255 int r; 256 int r;
256 size_t begin; 257 size_t begin;
257 258
258 cur_token = * index; 259 cur_token = * index;
259 260
260 r = mailimf_fws_parse(message, length, &cur_token); 261 r = mailimf_fws_parse(message, length, &cur_token);
261 if ((r != MAILIMF_NO_ERROR) && (r != MAILIMF_ERROR_PARSE)) { 262 if ((r != MAILIMF_NO_ERROR) && (r != MAILIMF_ERROR_PARSE)) {
262 res = r; 263 res = r;
263 goto err; 264 goto err;
264 } 265 }
265 266
266 begin = cur_token; 267 begin = cur_token;
267 268
268 end = FALSE; 269 end = FALSE;
269 while (1) { 270 while (1) {
270 if (cur_token >= length) 271 if (cur_token >= length)
271 break; 272 break;
272 273
273 switch (message[cur_token]) { 274 switch (message[cur_token]) {
274 case ' ': 275 case ' ':
275 case '\t': 276 case '\t':
276 case '\r': 277 case '\r':
277 case '\n': 278 case '\n':
278 end = TRUE; 279 end = TRUE;
279 break; 280 break;
280 } 281 }
281 282
282 if (end) 283 if (end)
283 break; 284 break;
284 285
285 cur_token ++; 286 cur_token ++;
286 } 287 }
287 288
288 if (cur_token - begin == 0) { 289 if (cur_token - begin == 0) {
289 res = MAILIMF_ERROR_PARSE; 290 res = MAILIMF_ERROR_PARSE;
290 goto err; 291 goto err;
291 } 292 }
292 293
293 text = malloc(cur_token - begin + 1); 294 text = malloc(cur_token - begin + 1);
294 if (text == NULL) { 295 if (text == NULL) {
295 res = MAILIMF_ERROR_MEMORY; 296 res = MAILIMF_ERROR_MEMORY;
296 goto err; 297 goto err;
297 } 298 }
298 299
299 memcpy(text, message + begin, cur_token - begin); 300 memcpy(text, message + begin, cur_token - begin);
300 text[cur_token - begin] = '\0'; 301 text[cur_token - begin] = '\0';
301 302
302 * index = cur_token; 303 * index = cur_token;
303 * result = text; 304 * result = text;
304 305
305 return MAILIMF_NO_ERROR; 306 return MAILIMF_NO_ERROR;
306 307
307 err: 308 err:
308 return res; 309 return res;
309} 310}
310 311
311static int mailmime_encoded_word_parse(const char * message, size_t length, 312static int mailmime_encoded_word_parse(const char * message, size_t length,
312 size_t * index, 313 size_t * index,
313 struct mailmime_encoded_word ** result) 314 struct mailmime_encoded_word ** result)
314{ 315{
315 size_t cur_token; 316 size_t cur_token;
316 char * charset; 317 char * charset;
317 int encoding; 318 int encoding;
318 char * text; 319 char * text;
319 size_t end_encoding; 320 size_t end_encoding;
320 char * decoded; 321 char * decoded;
321 size_t decoded_len; 322 size_t decoded_len;
322 struct mailmime_encoded_word * ew; 323 struct mailmime_encoded_word * ew;
323 int r; 324 int r;
324 int res; 325 int res;
325 int opening_quote; 326 int opening_quote;
326 int end; 327 int end;
327 328
328 cur_token = * index; 329 cur_token = * index;
329 330
330 r = mailimf_fws_parse(message, length, &cur_token); 331 r = mailimf_fws_parse(message, length, &cur_token);
331 if ((r != MAILIMF_NO_ERROR) && (r != MAILIMF_ERROR_PARSE)) { 332 if ((r != MAILIMF_NO_ERROR) && (r != MAILIMF_ERROR_PARSE)) {
332 res = r; 333 res = r;
333 goto err; 334 goto err;
334 } 335 }
335 336
336 opening_quote = FALSE; 337 opening_quote = FALSE;
337 r = mailimf_char_parse(message, length, &cur_token, '\"'); 338 r = mailimf_char_parse(message, length, &cur_token, '\"');
338 if (r == MAILIMF_NO_ERROR) { 339 if (r == MAILIMF_NO_ERROR) {
339 opening_quote = TRUE; 340 opening_quote = TRUE;
340 } 341 }
341 else if (r == MAILIMF_ERROR_PARSE) { 342 else if (r == MAILIMF_ERROR_PARSE) {
342 /* do nothing */ 343 /* do nothing */
343 } 344 }
344 else { 345 else {
345 res = r; 346 res = r;
346 goto err; 347 goto err;
347 } 348 }
348 349
349 r = mailimf_token_case_insensitive_parse(message, length, &cur_token, "=?"); 350 r = mailimf_token_case_insensitive_parse(message, length, &cur_token, "=?");
350 if (r != MAILIMF_NO_ERROR) { 351 if (r != MAILIMF_NO_ERROR) {
351 res = r; 352 res = r;
352 goto err; 353 goto err;
353 } 354 }
354 355
355 r = mailmime_charset_parse(message, length, &cur_token, &charset); 356 r = mailmime_charset_parse(message, length, &cur_token, &charset);
356 if (r != MAILIMF_NO_ERROR) { 357 if (r != MAILIMF_NO_ERROR) {
357 res = r; 358 res = r;
358 goto err; 359 goto err;
359 } 360 }
360 361
361 r = mailimf_char_parse(message, length, &cur_token, '?'); 362 r = mailimf_char_parse(message, length, &cur_token, '?');
362 if (r != MAILIMF_NO_ERROR) { 363 if (r != MAILIMF_NO_ERROR) {
363 res = r; 364 res = r;
364 goto free_charset; 365 goto free_charset;
365 } 366 }
366 367
367 r = mailmime_encoding_parse(message, length, &cur_token, &encoding); 368 r = mailmime_encoding_parse(message, length, &cur_token, &encoding);
368 if (r != MAILIMF_NO_ERROR) { 369 if (r != MAILIMF_NO_ERROR) {
369 res = r; 370 res = r;
370 goto free_charset; 371 goto free_charset;
371 } 372 }
372 373
373 r = mailimf_char_parse(message, length, &cur_token, '?'); 374 r = mailimf_char_parse(message, length, &cur_token, '?');
374 if (r != MAILIMF_NO_ERROR) { 375 if (r != MAILIMF_NO_ERROR) {
375 res = r; 376 res = r;
376 goto free_charset; 377 goto free_charset;
377 } 378 }
378 379
379 end = FALSE; 380 end = FALSE;
380 end_encoding = cur_token; 381 end_encoding = cur_token;
381 while (1) { 382 while (1) {
382 if (end_encoding >= length) 383 if (end_encoding >= length)
383 break; 384 break;
384 385
385 switch (message[end_encoding]) { 386 switch (message[end_encoding]) {
386 case '?': 387 case '?':
387#if 0 388#if 0
388 case ' ': 389 case ' ':
389#endif 390#endif
390 end = TRUE; 391 end = TRUE;
391 break; 392 break;
392 } 393 }
393 394
394 if (end) 395 if (end)
395 break; 396 break;
396 397
397 end_encoding ++; 398 end_encoding ++;
398 } 399 }
399 400
400 decoded_len = 0; 401 decoded_len = 0;
401 decoded = NULL; 402 decoded = NULL;
402 switch (encoding) { 403 switch (encoding) {
403 case MAILMIME_ENCODING_B: 404 case MAILMIME_ENCODING_B:
404 r = mailmime_base64_body_parse(message, end_encoding, 405 r = mailmime_base64_body_parse(message, end_encoding,
405 &cur_token, &decoded, 406 &cur_token, &decoded,
406 &decoded_len); 407 &decoded_len);
407 408
408 if (r != MAILIMF_NO_ERROR) { 409 if (r != MAILIMF_NO_ERROR) {
409 res = r; 410 res = r;
410 goto free_charset; 411 goto free_charset;
411 } 412 }
412 break; 413 break;
413 case MAILMIME_ENCODING_Q: 414 case MAILMIME_ENCODING_Q:
414 r = mailmime_quoted_printable_body_parse(message, end_encoding, 415 r = mailmime_quoted_printable_body_parse(message, end_encoding,
415 &cur_token, &decoded, 416 &cur_token, &decoded,
416 &decoded_len, TRUE); 417 &decoded_len, TRUE);
417 418
418 if (r != MAILIMF_NO_ERROR) { 419 if (r != MAILIMF_NO_ERROR) {
419 res = r; 420 res = r;
420 goto free_charset; 421 goto free_charset;
421 } 422 }
422 423
423 break; 424 break;
424 } 425 }
425 426
426 text = malloc(decoded_len + 1); 427 text = malloc(decoded_len + 1);
427 if (text == NULL) { 428 if (text == NULL) {
428 res = MAILIMF_ERROR_MEMORY; 429 res = MAILIMF_ERROR_MEMORY;
429 goto free_charset; 430 goto free_charset;
430 } 431 }
431 432
432 if (decoded_len > 0) 433 if (decoded_len > 0)
433 memcpy(text, decoded, decoded_len); 434 memcpy(text, decoded, decoded_len);
434 text[decoded_len] = '\0'; 435 text[decoded_len] = '\0';
435 436
436 mailmime_decoded_part_free(decoded); 437 mailmime_decoded_part_free(decoded);
437 438
438 r = mailimf_token_case_insensitive_parse(message, length, &cur_token, "?="); 439 r = mailimf_token_case_insensitive_parse(message, length, &cur_token, "?=");
439 if (r != MAILIMF_NO_ERROR) { 440 if (r != MAILIMF_NO_ERROR) {
440 res = r; 441 res = r;
441 goto free_encoded_text; 442 goto free_encoded_text;
442 } 443 }
443 444
444 if (opening_quote) { 445 if (opening_quote) {
445 r = mailimf_char_parse(message, length, &cur_token, '\"'); 446 r = mailimf_char_parse(message, length, &cur_token, '\"');
446 if ((r != MAILIMF_NO_ERROR) && (r != MAILIMF_ERROR_PARSE)) { 447 if ((r != MAILIMF_NO_ERROR) && (r != MAILIMF_ERROR_PARSE)) {
447 res = r; 448 res = r;
448 goto free_encoded_text; 449 goto free_encoded_text;
449 } 450 }
450 } 451 }
451 452
452 ew = mailmime_encoded_word_new(charset, text); 453 ew = mailmime_encoded_word_new(charset, text);
453 if (ew == NULL) { 454 if (ew == NULL) {
454 res = MAILIMF_ERROR_MEMORY; 455 res = MAILIMF_ERROR_MEMORY;
455 goto free_encoded_text; 456 goto free_encoded_text;
456 } 457 }
457 458
458 * result = ew; 459 * result = ew;
459 * index = cur_token; 460 * index = cur_token;
460 461
461 return MAILIMF_NO_ERROR; 462 return MAILIMF_NO_ERROR;
462 463
463 free_encoded_text: 464 free_encoded_text:
464 mailmime_encoded_text_free(text); 465 mailmime_encoded_text_free(text);
465 free_charset: 466 free_charset:
466 mailmime_charset_free(charset); 467 mailmime_charset_free(charset);
467 err: 468 err:
468 return res; 469 return res;
469} 470}
470 471
471static int mailmime_charset_parse(const char * message, size_t length, 472static int mailmime_charset_parse(const char * message, size_t length,
472 size_t * index, char ** charset) 473 size_t * index, char ** charset)
473{ 474{
474 return mailmime_etoken_parse(message, length, index, charset); 475 return mailmime_etoken_parse(message, length, index, charset);
475} 476}
476 477
477static int mailmime_encoding_parse(const char * message, size_t length, 478static int mailmime_encoding_parse(const char * message, size_t length,
478 size_t * index, int * result) 479 size_t * index, int * result)
479{ 480{
480 size_t cur_token; 481 size_t cur_token;
481 int encoding; 482 int encoding;
482 483
483 cur_token = * index; 484 cur_token = * index;
484 485
485 if (cur_token >= length) 486 if (cur_token >= length)
486 return MAILIMF_ERROR_PARSE; 487 return MAILIMF_ERROR_PARSE;
487 488
488 switch ((char) toupper((unsigned char) message[cur_token])) { 489 switch ((char) toupper((unsigned char) message[cur_token])) {
489 case 'Q': 490 case 'Q':
490 encoding = MAILMIME_ENCODING_Q; 491 encoding = MAILMIME_ENCODING_Q;
491 break; 492 break;
492 case 'B': 493 case 'B':
493 encoding = MAILMIME_ENCODING_B; 494 encoding = MAILMIME_ENCODING_B;
494 break; 495 break;
495 default: 496 default:
496 return MAILIMF_ERROR_INVAL; 497 return MAILIMF_ERROR_INVAL;
497 } 498 }
498 499
499 cur_token ++; 500 cur_token ++;
500 501
501 * result = encoding; 502 * result = encoding;
502 * index = cur_token; 503 * index = cur_token;
503 504
504 return MAILIMF_NO_ERROR; 505 return MAILIMF_NO_ERROR;
505} 506}
506 507
507int is_etoken_char(char ch) 508int is_etoken_char(char ch)
508{ 509{
509 unsigned char uch = ch; 510 unsigned char uch = ch;
510 511
511 if (uch < 31) 512 if (uch < 31)
512 return FALSE; 513 return FALSE;
513 514
514 switch (uch) { 515 switch (uch) {
515 case ' ': 516 case ' ':
516 case '(': 517 case '(':
517 case ')': 518 case ')':
518 case '<': 519 case '<':
519 case '>': 520 case '>':
520 case '@': 521 case '@':
521 case ',': 522 case ',':
522 case ';': 523 case ';':
523 case ':': 524 case ':':
524 case '"': 525 case '"':
525 case '/': 526 case '/':
526 case '[': 527 case '[':
527 case ']': 528 case ']':
528 case '?': 529 case '?':
529 case '.': 530 case '.':
530 case '=': 531 case '=':
531 return FALSE; 532 return FALSE;
532 } 533 }
533 534
534 return TRUE; 535 return TRUE;
535} 536}
536 537
537static int mailmime_etoken_parse(const char * message, size_t length, 538static int mailmime_etoken_parse(const char * message, size_t length,
538 size_t * index, char ** result) 539 size_t * index, char ** result)
539{ 540{
540 return mailimf_custom_string_parse(message, length, 541 return mailimf_custom_string_parse(message, length,
541 index, result, 542 index, result,
542 is_etoken_char); 543 is_etoken_char);
543} 544}
diff --git a/kmicromail/libmailwrapper/generatemail.cpp b/kmicromail/libmailwrapper/generatemail.cpp
index 49315ba..32311d7 100644
--- a/kmicromail/libmailwrapper/generatemail.cpp
+++ b/kmicromail/libmailwrapper/generatemail.cpp
@@ -1,460 +1,461 @@
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
11using namespace Opie::Core; 11using namespace Opie::Core;
12const char* Generatemail::USER_AGENT="OpieMail v0.6"; 12const char* Generatemail::USER_AGENT="KOpieMail 33 1/3";
13 13
14Generatemail::Generatemail() 14Generatemail::Generatemail()
15{ 15{
16} 16}
17 17
18Generatemail::~Generatemail() 18Generatemail::~Generatemail()
19{ 19{
20} 20}
21 21
22void Generatemail::addRcpts( clist *list, mailimf_address_list *addr_list ) { 22void Generatemail::addRcpts( clist *list, mailimf_address_list *addr_list ) {
23 clistiter *it, *it2; 23 clistiter *it, *it2;
24 24
25 for ( it = clist_begin( addr_list->ad_list ); it; it = it->next ) { 25 for ( it = clist_begin( addr_list->ad_list ); it; it = it->next ) {
26 mailimf_address *addr; 26 mailimf_address *addr;
27 addr = (mailimf_address *) it->data; 27 addr = (mailimf_address *) it->data;
28 28
29 if ( addr->ad_type == MAILIMF_ADDRESS_MAILBOX ) { 29 if ( addr->ad_type == MAILIMF_ADDRESS_MAILBOX ) {
30 esmtp_address_list_add( list, addr->ad_data.ad_mailbox->mb_addr_spec, 0, NULL ); 30 esmtp_address_list_add( list, addr->ad_data.ad_mailbox->mb_addr_spec, 0, NULL );
31 } else if ( addr->ad_type == MAILIMF_ADDRESS_GROUP ) { 31 } else if ( addr->ad_type == MAILIMF_ADDRESS_GROUP ) {
32 clist *l = addr->ad_data.ad_group->grp_mb_list->mb_list; 32 clist *l = addr->ad_data.ad_group->grp_mb_list->mb_list;
33 for ( it2 = clist_begin( l ); it2; it2 = it2->next ) { 33 for ( it2 = clist_begin( l ); it2; it2 = it2->next ) {
34 mailimf_mailbox *mbox; 34 mailimf_mailbox *mbox;
35 mbox = (mailimf_mailbox *) it2->data; 35 mbox = (mailimf_mailbox *) it2->data;
36 esmtp_address_list_add( list, mbox->mb_addr_spec, 0, NULL ); 36 esmtp_address_list_add( list, mbox->mb_addr_spec, 0, NULL );
37 } 37 }
38 } 38 }
39 } 39 }
40} 40}
41 41
42char *Generatemail::getFrom( mailimf_field *ffrom) { 42char *Generatemail::getFrom( mailimf_field *ffrom) {
43 char *from = NULL; 43 char *from = NULL;
44 if ( ffrom && (ffrom->fld_type == MAILIMF_FIELD_FROM) 44 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 ) { 45 && 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; 46 clist *cl = ffrom->fld_data.fld_from->frm_mb_list->mb_list;
47 clistiter *it; 47 clistiter *it;
48 for ( it = clist_begin( cl ); it; it = it->next ) { 48 for ( it = clist_begin( cl ); it; it = it->next ) {
49 mailimf_mailbox *mb = (mailimf_mailbox *) it->data; 49 mailimf_mailbox *mb = (mailimf_mailbox *) it->data;
50 from = strdup( mb->mb_addr_spec ); 50 from = strdup( mb->mb_addr_spec );
51 } 51 }
52 } 52 }
53 53
54 return from; 54 return from;
55} 55}
56 56
57char *Generatemail::getFrom( mailmime *mail ) { 57char *Generatemail::getFrom( mailmime *mail ) {
58 /* no need to delete - its just a pointer to structure content */ 58 /* no need to delete - its just a pointer to structure content */
59 mailimf_field *ffrom = 0; 59 mailimf_field *ffrom = 0;
60 ffrom = getField( mail->mm_data.mm_message.mm_fields, MAILIMF_FIELD_FROM ); 60 ffrom = getField( mail->mm_data.mm_message.mm_fields, MAILIMF_FIELD_FROM );
61 return getFrom(ffrom); 61 return getFrom(ffrom);
62} 62}
63 63
64mailimf_field *Generatemail::getField( mailimf_fields *fields, int type ) { 64mailimf_field *Generatemail::getField( mailimf_fields *fields, int type ) {
65 mailimf_field *field; 65 mailimf_field *field;
66 clistiter *it; 66 clistiter *it;
67 67
68 it = clist_begin( fields->fld_list ); 68 it = clist_begin( fields->fld_list );
69 while ( it ) { 69 while ( it ) {
70 field = (mailimf_field *) it->data; 70 field = (mailimf_field *) it->data;
71 if ( field->fld_type == type ) { 71 if ( field->fld_type == type ) {
72 return field; 72 return field;
73 } 73 }
74 it = it->next; 74 it = it->next;
75 } 75 }
76 76
77 return NULL; 77 return NULL;
78} 78}
79 79
80mailimf_address_list *Generatemail::parseAddresses(const QString&addr ) { 80mailimf_address_list *Generatemail::parseAddresses(const QString&addr ) {
81 mailimf_address_list *addresses; 81 mailimf_address_list *addresses;
82 82
83 if ( addr.isEmpty() ) 83 if ( addr.isEmpty() )
84 return NULL; 84 return NULL;
85 85
86 addresses = mailimf_address_list_new_empty(); 86 addresses = mailimf_address_list_new_empty();
87 87
88 bool literal_open = false; 88 bool literal_open = false;
89 unsigned int startpos = 0; 89 unsigned int startpos = 0;
90 QStringList list; 90 QStringList list;
91 QString s; 91 QString s;
92 unsigned int i = 0; 92 unsigned int i = 0;
93 for (; i < addr.length();++i) { 93 for (; i < addr.length();++i) {
94 switch (addr[i]) { 94 switch (addr[i]) {
95 case '\"': 95 case '\"':
96 literal_open = !literal_open; 96 literal_open = !literal_open;
97 break; 97 break;
98 case ',': 98 case ',':
99 if (!literal_open) { 99 if (!literal_open) {
100 s = addr.mid(startpos,i-startpos); 100 s = addr.mid(startpos,i-startpos);
101 if (!s.isEmpty()) { 101 if (!s.isEmpty()) {
102 list.append(s); 102 list.append(s);
103 } 103 }
104 // !!!! this is a MUST BE! 104 // !!!! this is a MUST BE!
105 startpos = ++i; 105 startpos = ++i;
106 } 106 }
107 break; 107 break;
108 default: 108 default:
109 break; 109 break;
110 } 110 }
111 } 111 }
112 s = addr.mid(startpos,i-startpos); 112 s = addr.mid(startpos,i-startpos);
113 if (!s.isEmpty()) { 113 if (!s.isEmpty()) {
114 list.append(s); 114 list.append(s);
115 } 115 }
116 QStringList::Iterator it; 116 QStringList::Iterator it;
117 for ( it = list.begin(); it != list.end(); it++ ) { 117 for ( it = list.begin(); it != list.end(); it++ ) {
118 int err = mailimf_address_list_add_parse( addresses, (char*)(*it).latin1() ); 118 int err = mailimf_address_list_add_parse( addresses, (char*)(*it).latin1() );
119 if ( err != MAILIMF_NO_ERROR ) { 119 if ( err != MAILIMF_NO_ERROR ) {
120 qDebug(" Error parsing"); // *it 120 qDebug(" Error parsing"); // *it
121 } else { 121 } else {
122 } 122 }
123 } 123 }
124 return addresses; 124 return addresses;
125} 125}
126 126
127mailmime *Generatemail::buildFilePart(const QString&filename,const QString&mimetype,const QString&TextContent ) { 127mailmime *Generatemail::buildFilePart(const QString&filename,const QString&mimetype,const QString&TextContent ) {
128 mailmime * filePart = 0; 128 mailmime * filePart = 0;
129 mailmime_fields * fields = 0; 129 mailmime_fields * fields = 0;
130 mailmime_content * content = 0; 130 mailmime_content * content = 0;
131 mailmime_parameter * param = 0; 131 mailmime_parameter * param = 0;
132 char*name = 0; 132 char*name = 0;
133 char*file = 0; 133 char*file = 0;
134 int err; 134 int err;
135
136 int pos = filename.findRev( '/' ); 135 int pos = filename.findRev( '/' );
137 136
138 if (filename.length()>0) { 137 if (filename.length()>0) {
139 QString tmp = filename.right( filename.length() - ( pos + 1 ) ); 138 QString tmp = filename.right( filename.length() - ( pos + 1 ) );
140 name = strdup( tmp.latin1() ); // just filename 139 name = strdup( tmp.latin1() ); // just filename
141 file = strdup( filename.latin1() ); // full name with path 140 file = strdup( filename.latin1() ); // full name with path
142 } 141 }
143 142
144 int disptype = MAILMIME_DISPOSITION_TYPE_ATTACHMENT; 143 int disptype = MAILMIME_DISPOSITION_TYPE_ATTACHMENT;
145 int mechanism = MAILMIME_MECHANISM_BASE64; 144 int mechanism = MAILMIME_MECHANISM_BASE64;
146 145
147 if ( mimetype.startsWith( "text/" ) ) { 146 if ( mimetype.startsWith( "text/" ) ) {
148 param = mailmime_parameter_new( strdup( "charset" ), 147 param = mailmime_parameter_new( strdup( "charset" ),
149 strdup( "iso-8859-1" ) ); 148 strdup( "iso-8859-1" ) );
150 mechanism = MAILMIME_MECHANISM_QUOTED_PRINTABLE; 149 mechanism = MAILMIME_MECHANISM_QUOTED_PRINTABLE;
151 } 150 }
152 151
153 fields = mailmime_fields_new_filename( 152 fields = mailmime_fields_new_filename(
154 disptype, name, 153 disptype, name,
155 mechanism ); 154 mechanism );
156 content = mailmime_content_new_with_str( (char*)mimetype.latin1() ); 155 content = mailmime_content_new_with_str( (char*)mimetype.latin1() );
157 if (content!=0 && fields != 0) { 156 if (content!=0 && fields != 0) {
158 if (param) { 157 if (param) {
159 clist_append(content->ct_parameters,param); 158 clist_append(content->ct_parameters,param);
160 param = 0; 159 param = 0;
161 } 160 }
162 if (filename.length()>0) { 161 if (filename.length()>0) {
163 QFileInfo f(filename); 162 QFileInfo f(filename);
164 param = mailmime_parameter_new(strdup("name"),strdup(f.fileName().latin1())); 163 param = mailmime_parameter_new(strdup("name"),strdup(f.fileName().latin1()));
165 clist_append(content->ct_parameters,param); 164 clist_append(content->ct_parameters,param);
166 param = 0; 165 param = 0;
167 } 166 }
168 filePart = mailmime_new_empty( content, fields ); 167 filePart = mailmime_new_empty( content, fields );
169 } 168 }
170 if (filePart) { 169 if (filePart) {
171 if (filename.length()>0) { 170 if (filename.length()>0) {
172 err = mailmime_set_body_file( filePart, file ); 171 err = mailmime_set_body_file( filePart, file );
173 } else { 172 } else {
174 err = mailmime_set_body_text(filePart,strdup(TextContent.data()),TextContent.length()); 173 err = mailmime_set_body_text(filePart,strdup( TextContent.utf8()),TextContent.utf8().length());
175 } 174 }
176 if (err != MAILIMF_NO_ERROR) { 175 if (err != MAILIMF_NO_ERROR) {
177 qDebug("Error setting body with file "); 176 qDebug("Error setting body with file ");
178 mailmime_free( filePart ); 177 mailmime_free( filePart );
179 filePart = 0; 178 filePart = 0;
180 } 179 }
181 } 180 }
182 181
183 if (!filePart) { 182 if (!filePart) {
184 if ( param != NULL ) { 183 if ( param != NULL ) {
185 mailmime_parameter_free( param ); 184 mailmime_parameter_free( param );
186 } 185 }
187 if (content) { 186 if (content) {
188 mailmime_content_free( content ); 187 mailmime_content_free( content );
189 } 188 }
190 if (fields) { 189 if (fields) {
191 mailmime_fields_free( fields ); 190 mailmime_fields_free( fields );
192 } else { 191 } else {
193 if (name) { 192 if (name) {
194 free( name ); 193 free( name );
195 } 194 }
196 if (file) { 195 if (file) {
197 free( file ); 196 free( file );
198 } 197 }
199 } 198 }
200 } 199 }
201 return filePart; // Success :) 200 return filePart; // Success :)
202 201
203} 202}
204 203
205void Generatemail::addFileParts( mailmime *message,const QList<Attachment>&files ) { 204void Generatemail::addFileParts( mailmime *message,const QList<Attachment>&files ) {
206 const Attachment *it; 205 const Attachment *it;
207 unsigned int count = files.count(); 206 unsigned int count = files.count();
208 for ( unsigned int i = 0; i < count; ++i ) { 207 for ( unsigned int i = 0; i < count; ++i ) {
209 mailmime *filePart; 208 mailmime *filePart;
210 int err; 209 int err;
211 it = ((QList<Attachment>)files).at(i); 210 it = ((QList<Attachment>)files).at(i);
212 211
213 filePart = buildFilePart( it->getFileName(), it->getMimeType(),"" ); 212 filePart = buildFilePart( it->getFileName(), it->getMimeType(),"" );
214 if ( filePart == NULL ) { 213 if ( filePart == NULL ) {
215 continue; 214 continue;
216 } 215 }
217 err = mailmime_smart_add_part( message, filePart ); 216 err = mailmime_smart_add_part( message, filePart );
218 if ( err != MAILIMF_NO_ERROR ) { 217 if ( err != MAILIMF_NO_ERROR ) {
219 mailmime_free( filePart ); 218 mailmime_free( filePart );
220 } 219 }
221 } 220 }
222} 221}
223 222
224mailmime *Generatemail::buildTxtPart(const QString&str ) { 223mailmime *Generatemail::buildTxtPart(const QString&str ) {
225 mailmime *txtPart; 224 mailmime *txtPart;
226 mailmime_fields *fields; 225 mailmime_fields *fields;
227 mailmime_content *content; 226 mailmime_content *content;
228 mailmime_parameter *param; 227 mailmime_parameter *param;
229 int err; 228 int err;
230 229 QCString __str;
231 param = mailmime_parameter_new( strdup( "charset" ), 230 param = mailmime_parameter_new( strdup( "charset" ),
232 strdup( "iso-8859-1" ) ); 231 strdup( "iso-8859-1" ) );
233 if ( param == NULL ) 232 if ( param == NULL )
234 goto err_free; 233 goto err_free;
235 234
236 content = mailmime_content_new_with_str( "text/plain" ); 235 content = mailmime_content_new_with_str( "text/plain" );
237 if ( content == NULL ) 236 if ( content == NULL )
238 goto err_free_param; 237 goto err_free_param;
239 238
240 err = clist_append( content->ct_parameters, param ); 239 err = clist_append( content->ct_parameters, param );
241 if ( err != MAILIMF_NO_ERROR ) 240 if ( err != MAILIMF_NO_ERROR )
242 goto err_free_content; 241 goto err_free_content;
243 242
244 fields = mailmime_fields_new_encoding(MAILMIME_MECHANISM_8BIT); 243 fields = mailmime_fields_new_encoding(MAILMIME_MECHANISM_8BIT);
245 if ( fields == NULL ) 244 if ( fields == NULL )
246 goto err_free_content; 245 goto err_free_content;
247 246
248 txtPart = mailmime_new_empty( content, fields ); 247 txtPart = mailmime_new_empty( content, fields );
249 if ( txtPart == NULL ) 248 if ( txtPart == NULL )
250 goto err_free_fields; 249 goto err_free_fields;
251 250 {
252 err = mailmime_set_body_text( txtPart, (char*)str.data(), str.length() ); 251 __str = str.utf8();
252 err = mailmime_set_body_text( txtPart, __str.data(), __str.length() );
253 }
253 if ( err != MAILIMF_NO_ERROR ) 254 if ( err != MAILIMF_NO_ERROR )
254 goto err_free_txtPart; 255 goto err_free_txtPart;
255 256
256 return txtPart; // Success :) 257 return txtPart; // Success :)
257 258
258err_free_txtPart: 259err_free_txtPart:
259 mailmime_free( txtPart ); 260 mailmime_free( txtPart );
260err_free_fields: 261err_free_fields:
261 mailmime_fields_free( fields ); 262 mailmime_fields_free( fields );
262err_free_content: 263err_free_content:
263 mailmime_content_free( content ); 264 mailmime_content_free( content );
264err_free_param: 265err_free_param:
265 mailmime_parameter_free( param ); 266 mailmime_parameter_free( param );
266err_free: 267err_free:
267 ; 268 ;
268 269
269 return NULL; // Error :( 270 return NULL; // Error :(
270} 271}
271 272
272mailimf_mailbox *Generatemail::newMailbox(const QString&name, const QString&mail ) { 273mailimf_mailbox *Generatemail::newMailbox(const QString&name, const QString&mail ) {
273 return mailimf_mailbox_new( strdup( name.latin1() ), 274 return mailimf_mailbox_new( strdup( name.latin1() ),
274 strdup( mail.latin1() ) ); 275 strdup( mail.latin1() ) );
275} 276}
276 277
277mailimf_fields *Generatemail::createImfFields(const Opie::Core::OSmartPointer<Mail>&mail ) 278mailimf_fields *Generatemail::createImfFields(const Opie::Core::OSmartPointer<Mail>&mail )
278{ 279{
279 mailimf_fields *fields = NULL; 280 mailimf_fields *fields = NULL;
280 mailimf_field *xmailer = NULL; 281 mailimf_field *xmailer = NULL;
281 mailimf_mailbox *sender=0,*fromBox=0; 282 mailimf_mailbox *sender=0,*fromBox=0;
282 mailimf_mailbox_list *from=0; 283 mailimf_mailbox_list *from=0;
283 mailimf_address_list *to=0, *cc=0, *bcc=0, *reply=0; 284 mailimf_address_list *to=0, *cc=0, *bcc=0, *reply=0;
284 clist*in_reply_to = 0; 285 clist*in_reply_to = 0;
285 char *subject = strdup( mail->getSubject().latin1() ); 286 char *subject = strdup( mail->getSubject().latin1() );
286 int err; 287 int err;
287 int res = 1; 288 int res = 1;
288 289
289 sender = newMailbox( mail->getName(), mail->getMail() ); 290 sender = newMailbox( mail->getName(), mail->getMail() );
290 if ( sender == NULL ) { 291 if ( sender == NULL ) {
291 res = 0; 292 res = 0;
292 } 293 }
293 294
294 if (res) { 295 if (res) {
295 fromBox = newMailbox( mail->getName(), mail->getMail() ); 296 fromBox = newMailbox( mail->getName(), mail->getMail() );
296 } 297 }
297 if ( fromBox == NULL ) { 298 if ( fromBox == NULL ) {
298 res = 0; 299 res = 0;
299 } 300 }
300 301
301 if (res) { 302 if (res) {
302 from = mailimf_mailbox_list_new_empty(); 303 from = mailimf_mailbox_list_new_empty();
303 } 304 }
304 if ( from == NULL ) { 305 if ( from == NULL ) {
305 res = 0; 306 res = 0;
306 } 307 }
307 308
308 if (res && from) { 309 if (res && from) {
309 err = mailimf_mailbox_list_add( from, fromBox ); 310 err = mailimf_mailbox_list_add( from, fromBox );
310 if ( err != MAILIMF_NO_ERROR ) { 311 if ( err != MAILIMF_NO_ERROR ) {
311 res = 0; 312 res = 0;
312 } 313 }
313 } 314 }
314 315
315 if (res) to = parseAddresses( mail->getTo() ); 316 if (res) to = parseAddresses( mail->getTo() );
316 if (res) cc = parseAddresses( mail->getCC() ); 317 if (res) cc = parseAddresses( mail->getCC() );
317 if (res) bcc = parseAddresses( mail->getBCC() ); 318 if (res) bcc = parseAddresses( mail->getBCC() );
318 if (res) reply = parseAddresses( mail->getReply() ); 319 if (res) reply = parseAddresses( mail->getReply() );
319 320
320 if (res && mail->Inreply().count()>0) { 321 if (res && mail->Inreply().count()>0) {
321 in_reply_to = clist_new(); 322 in_reply_to = clist_new();
322 char*c_reply; 323 char*c_reply;
323 unsigned int nsize = 0; 324 unsigned int nsize = 0;
324 for (QStringList::ConstIterator it=mail->Inreply().begin(); 325 for (QStringList::ConstIterator it=mail->Inreply().begin();
325 it != mail->Inreply().end();++it) { 326 it != mail->Inreply().end();++it) {
326 if ((*it).isEmpty()) 327 if ((*it).isEmpty())
327 continue; 328 continue;
328 QString h((*it)); 329 QString h((*it));
329 while (h.length()>0 && h[0]=='<') { 330 while (h.length()>0 && h[0]=='<') {
330 h.remove(0,1); 331 h.remove(0,1);
331 } 332 }
332 while (h.length()>0 && h[h.length()-1]=='>') { 333 while (h.length()>0 && h[h.length()-1]=='>') {
333 h.remove(h.length()-1,1); 334 h.remove(h.length()-1,1);
334 } 335 }
335 if (h.isEmpty()) continue; 336 if (h.isEmpty()) continue;
336 nsize = strlen(h.latin1()); 337 nsize = strlen(h.latin1());
337 /* yes! must be malloc! */ 338 /* yes! must be malloc! */
338 c_reply = (char*)malloc( (nsize+1)*sizeof(char)); 339 c_reply = (char*)malloc( (nsize+1)*sizeof(char));
339 memset(c_reply,0,nsize+1); 340 memset(c_reply,0,nsize+1);
340 memcpy(c_reply,h.latin1(),nsize); 341 memcpy(c_reply,h.latin1(),nsize);
341 clist_append(in_reply_to,c_reply); 342 clist_append(in_reply_to,c_reply);
342 } 343 }
343 } 344 }
344 345
345 if (res) { 346 if (res) {
346 fields = mailimf_fields_new_with_data( from, sender, reply, to, cc, bcc, 347 fields = mailimf_fields_new_with_data( from, sender, reply, to, cc, bcc,
347 in_reply_to, NULL, subject ); 348 in_reply_to, NULL, subject );
348 if ( fields == NULL ) { 349 if ( fields == NULL ) {
349 res = 0; 350 res = 0;
350 } 351 }
351 } 352 }
352 if (res) xmailer = mailimf_field_new_custom( strdup( "User-Agent" ), 353 if (res) xmailer = mailimf_field_new_custom( strdup( "User-Agent" ),
353 strdup( USER_AGENT ) ); 354 strdup( USER_AGENT ) );
354 if ( xmailer == NULL ) { 355 if ( xmailer == NULL ) {
355 res = 0; 356 res = 0;
356 } else { 357 } else {
357 err = mailimf_fields_add( fields, xmailer ); 358 err = mailimf_fields_add( fields, xmailer );
358 if ( err != MAILIMF_NO_ERROR ) { 359 if ( err != MAILIMF_NO_ERROR ) {
359 res = 0; 360 res = 0;
360 } 361 }
361 } 362 }
362 if (!res ) { 363 if (!res ) {
363 if (xmailer) { 364 if (xmailer) {
364 mailimf_field_free( xmailer ); 365 mailimf_field_free( xmailer );
365 xmailer = NULL; 366 xmailer = NULL;
366 } 367 }
367 if (fields) { 368 if (fields) {
368 mailimf_fields_free( fields ); 369 mailimf_fields_free( fields );
369 fields = NULL; 370 fields = NULL;
370 } else { 371 } else {
371 if (reply) 372 if (reply)
372 mailimf_address_list_free( reply ); 373 mailimf_address_list_free( reply );
373 if (bcc) 374 if (bcc)
374 mailimf_address_list_free( bcc ); 375 mailimf_address_list_free( bcc );
375 if (cc) 376 if (cc)
376 mailimf_address_list_free( cc ); 377 mailimf_address_list_free( cc );
377 if (to) 378 if (to)
378 mailimf_address_list_free( to ); 379 mailimf_address_list_free( to );
379 if (fromBox) { 380 if (fromBox) {
380 mailimf_mailbox_free( fromBox ); 381 mailimf_mailbox_free( fromBox );
381 } else if (from) { 382 } else if (from) {
382 mailimf_mailbox_list_free( from ); 383 mailimf_mailbox_list_free( from );
383 } 384 }
384 if (sender) { 385 if (sender) {
385 mailimf_mailbox_free( sender ); 386 mailimf_mailbox_free( sender );
386 } 387 }
387 if (subject) { 388 if (subject) {
388 free( subject ); 389 free( subject );
389 } 390 }
390 } 391 }
391 } 392 }
392 return fields; 393 return fields;
393} 394}
394 395
395mailmime *Generatemail::createMimeMail(const Opie::Core::OSmartPointer<Mail> &mail ) { 396mailmime *Generatemail::createMimeMail(const Opie::Core::OSmartPointer<Mail> &mail ) {
396 mailmime *message, *txtPart; 397 mailmime *message, *txtPart;
397 mailimf_fields *fields; 398 mailimf_fields *fields;
398 int err; 399 int err;
399 400
400 fields = createImfFields( mail ); 401 fields = createImfFields( mail );
401 if ( fields == NULL ) 402 if ( fields == NULL )
402 goto err_free; 403 goto err_free;
403 404
404 message = mailmime_new_message_data( NULL ); 405 message = mailmime_new_message_data( NULL );
405 if ( message == NULL ) 406 if ( message == NULL )
406 goto err_free_fields; 407 goto err_free_fields;
407 408
408 mailmime_set_imf_fields( message, fields ); 409 mailmime_set_imf_fields( message, fields );
409 410
410 txtPart = buildTxtPart( mail->getMessage() ); 411 txtPart = buildTxtPart( mail->getMessage() );
411 412
412 if ( txtPart == NULL ) 413 if ( txtPart == NULL )
413 goto err_free_message; 414 goto err_free_message;
414 415
415 err = mailmime_smart_add_part( message, txtPart ); 416 err = mailmime_smart_add_part( message, txtPart );
416 if ( err != MAILIMF_NO_ERROR ) 417 if ( err != MAILIMF_NO_ERROR )
417 goto err_free_txtPart; 418 goto err_free_txtPart;
418 419
419 addFileParts( message, mail->getAttachments() ); 420 addFileParts( message, mail->getAttachments() );
420 421
421 return message; // Success :) 422 return message; // Success :)
422 423
423err_free_txtPart: 424err_free_txtPart:
424 mailmime_free( txtPart ); 425 mailmime_free( txtPart );
425err_free_message: 426err_free_message:
426 mailmime_free( message ); 427 mailmime_free( message );
427err_free_fields: 428err_free_fields:
428 mailimf_fields_free( fields ); 429 mailimf_fields_free( fields );
429err_free: 430err_free:
430 ; 431 ;
431 432
432 return NULL; // Error :( 433 return NULL; // Error :(
433} 434}
434 435
435clist *Generatemail::createRcptList( mailimf_fields *fields ) { 436clist *Generatemail::createRcptList( mailimf_fields *fields ) {
436 clist *rcptList; 437 clist *rcptList;
437 mailimf_field *field; 438 mailimf_field *field;
438 439
439 rcptList = esmtp_address_list_new(); 440 rcptList = esmtp_address_list_new();
440 441
441 field = getField( fields, MAILIMF_FIELD_TO ); 442 field = getField( fields, MAILIMF_FIELD_TO );
442 if ( field && (field->fld_type == MAILIMF_FIELD_TO) 443 if ( field && (field->fld_type == MAILIMF_FIELD_TO)
443 && field->fld_data.fld_to->to_addr_list ) { 444 && field->fld_data.fld_to->to_addr_list ) {
444 addRcpts( rcptList, field->fld_data.fld_to->to_addr_list ); 445 addRcpts( rcptList, field->fld_data.fld_to->to_addr_list );
445 } 446 }
446 447
447 field = getField( fields, MAILIMF_FIELD_CC ); 448 field = getField( fields, MAILIMF_FIELD_CC );
448 if ( field && (field->fld_type == MAILIMF_FIELD_CC) 449 if ( field && (field->fld_type == MAILIMF_FIELD_CC)
449 && field->fld_data.fld_cc->cc_addr_list ) { 450 && field->fld_data.fld_cc->cc_addr_list ) {
450 addRcpts( rcptList, field->fld_data.fld_cc->cc_addr_list ); 451 addRcpts( rcptList, field->fld_data.fld_cc->cc_addr_list );
451 } 452 }
452 453
453 field = getField( fields, MAILIMF_FIELD_BCC ); 454 field = getField( fields, MAILIMF_FIELD_BCC );
454 if ( field && (field->fld_type == MAILIMF_FIELD_BCC) 455 if ( field && (field->fld_type == MAILIMF_FIELD_BCC)
455 && field->fld_data.fld_bcc->bcc_addr_list ) { 456 && field->fld_data.fld_bcc->bcc_addr_list ) {
456 addRcpts( rcptList, field->fld_data.fld_bcc->bcc_addr_list ); 457 addRcpts( rcptList, field->fld_data.fld_bcc->bcc_addr_list );
457 } 458 }
458 459
459 return rcptList; 460 return rcptList;
460} 461}
diff --git a/kmicromail/libmailwrapper/imapwrapper.cpp b/kmicromail/libmailwrapper/imapwrapper.cpp
index ae667ec..d90a8d2 100644
--- a/kmicromail/libmailwrapper/imapwrapper.cpp
+++ b/kmicromail/libmailwrapper/imapwrapper.cpp
@@ -1,1267 +1,1268 @@
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
13using namespace Opie::Core; 13using namespace Opie::Core;
14int IMAPwrapper::mMax = 0; 14int IMAPwrapper::mMax = 0;
15int IMAPwrapper::mCurrent = 0; 15int IMAPwrapper::mCurrent = 0;
16 16
17IMAPwrapper::IMAPwrapper( IMAPaccount *a ) 17IMAPwrapper::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
27IMAPwrapper::~IMAPwrapper() 27IMAPwrapper::~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!*/
34int IMAPwrapper::selectMbox(const QString&mbox) 34int 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
48void IMAPwrapper::imap_progress( size_t current, size_t maximum ) 48void 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 int last = 0; 53 static 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}
58void IMAPwrapper::progress( QString m ) 58void 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}
75bool IMAPwrapper::start_tls(bool force_tls) 75bool IMAPwrapper::start_tls(bool force_tls)
76{ 76{
77 int err; 77 int err;
78 bool try_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
125void IMAPwrapper::login() 125void 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
225void IMAPwrapper::logout() 225void 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
236void IMAPwrapper::listMessages(const QString&mailbox,QValueList<Opie::Core::OSmartPointer<RecMail> > &target , int maxSizeInKb) 236void 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()<=maxSizeInKb*1024 ) { 295 if ( maxSizeInKb == 0 || m->Msgsize()<=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
317QValueList<Opie::Core::OSmartPointer<Folder> >* IMAPwrapper::listFolders() 317QValueList<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
411RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) 411RecMail*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; 418 int size;
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 } else { 501 } else {
501 m->setIsoDate(head->env_date); 502 m->setIsoDate(head->env_date);
502 } 503 }
503 } 504 }
504 if ( head->env_subject != NULL ) 505 if ( head->env_subject != NULL )
505 m->setSubject(convert_String((const char*)head->env_subject)); 506 m->setSubject(convert_String((const char*)head->env_subject));
506 //m->setSubject(head->env_subject); 507 //m->setSubject(head->env_subject);
507 if (head->env_from!=NULL) { 508 if (head->env_from!=NULL) {
508 addresslist = address_list_to_stringlist(head->env_from->frm_list); 509 addresslist = address_list_to_stringlist(head->env_from->frm_list);
509 if (addresslist.count()) { 510 if (addresslist.count()) {
510 m->setFrom(addresslist.first()); 511 m->setFrom(addresslist.first());
511 } 512 }
512 } 513 }
513 if (head->env_to!=NULL) { 514 if (head->env_to!=NULL) {
514 addresslist = address_list_to_stringlist(head->env_to->to_list); 515 addresslist = address_list_to_stringlist(head->env_to->to_list);
515 m->setTo(addresslist); 516 m->setTo(addresslist);
516 } 517 }
517 if (head->env_cc!=NULL) { 518 if (head->env_cc!=NULL) {
518 addresslist = address_list_to_stringlist(head->env_cc->cc_list); 519 addresslist = address_list_to_stringlist(head->env_cc->cc_list);
519 m->setCC(addresslist); 520 m->setCC(addresslist);
520 } 521 }
521 if (head->env_bcc!=NULL) { 522 if (head->env_bcc!=NULL) {
522 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); 523 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list);
523 m->setBcc(addresslist); 524 m->setBcc(addresslist);
524 } 525 }
525 /* reply to address, eg. email. */ 526 /* reply to address, eg. email. */
526 if (head->env_reply_to!=NULL) { 527 if (head->env_reply_to!=NULL) {
527 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); 528 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list);
528 if (addresslist.count()) { 529 if (addresslist.count()) {
529 m->setReplyto(addresslist.first()); 530 m->setReplyto(addresslist.first());
530 } 531 }
531 } 532 }
532 if (head->env_in_reply_to!=NULL) { 533 if (head->env_in_reply_to!=NULL) {
533 QString h(head->env_in_reply_to); 534 QString h(head->env_in_reply_to);
534 while (h.length()>0 && h[0]=='<') { 535 while (h.length()>0 && h[0]=='<') {
535 h.remove(0,1); 536 h.remove(0,1);
536 } 537 }
537 while (h.length()>0 && h[h.length()-1]=='>') { 538 while (h.length()>0 && h[h.length()-1]=='>') {
538 h.remove(h.length()-1,1); 539 h.remove(h.length()-1,1);
539 } 540 }
540 if (h.length()>0) { 541 if (h.length()>0) {
541 m->setInreply(QStringList(h)); 542 m->setInreply(QStringList(h));
542 } 543 }
543 } 544 }
544 if (head->env_message_id != NULL) { 545 if (head->env_message_id != NULL) {
545 m->setMsgid(QString(head->env_message_id)); 546 m->setMsgid(QString(head->env_message_id));
546 } 547 }
547 } 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) {
548#if 0 549#if 0
549 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;
550 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));
551 qDebug("time %s ",da.toString().latin1() ); 552 qDebug("time %s ",da.toString().latin1() );
552#endif 553#endif
553 } 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) {
554 size = item->att_data.att_static->att_data.att_rfc822_size; 555 size = item->att_data.att_static->att_data.att_rfc822_size;
555 } 556 }
556 } 557 }
557 /* msg is already deleted */ 558 /* msg is already deleted */
558 if (mFlags.testBit(FLAG_DELETED) && m) { 559 if (mFlags.testBit(FLAG_DELETED) && m) {
559 delete m; 560 delete m;
560 m = 0; 561 m = 0;
561 } 562 }
562 if (m) { 563 if (m) {
563 m->setFlags(mFlags); 564 m->setFlags(mFlags);
564 m->setMsgsize(size); 565 m->setMsgsize(size);
565 } 566 }
566 return m; 567 return m;
567} 568}
568 569
569RecBodyP IMAPwrapper::fetchBody(const RecMailP&mail) 570RecBodyP IMAPwrapper::fetchBody(const RecMailP&mail)
570{ 571{
571 RecBodyP body = new RecBody(); 572 RecBodyP body = new RecBody();
572 const char *mb; 573 const char *mb;
573 int err = MAILIMAP_NO_ERROR; 574 int err = MAILIMAP_NO_ERROR;
574 clist *result = 0; 575 clist *result = 0;
575 clistcell *current; 576 clistcell *current;
576 mailimap_fetch_att *fetchAtt = 0; 577 mailimap_fetch_att *fetchAtt = 0;
577 mailimap_fetch_type *fetchType = 0; 578 mailimap_fetch_type *fetchType = 0;
578 mailimap_set *set = 0; 579 mailimap_set *set = 0;
579 mailimap_body*body_desc = 0; 580 mailimap_body*body_desc = 0;
580 581
581 mb = mail->getMbox().latin1(); 582 mb = mail->getMbox().latin1();
582 583
583 login(); 584 login();
584 if (!m_imap) { 585 if (!m_imap) {
585 return body; 586 return body;
586 } 587 }
587 err = selectMbox(mail->getMbox()); 588 err = selectMbox(mail->getMbox());
588 if ( err != MAILIMAP_NO_ERROR ) { 589 if ( err != MAILIMAP_NO_ERROR ) {
589 return body; 590 return body;
590 } 591 }
591 592
592 /* the range has to start at 1!!! not with 0!!!! */ 593 /* the range has to start at 1!!! not with 0!!!! */
593 set = mailimap_set_new_interval( mail->getNumber(),mail->getNumber() ); 594 set = mailimap_set_new_interval( mail->getNumber(),mail->getNumber() );
594 fetchAtt = mailimap_fetch_att_new_bodystructure(); 595 fetchAtt = mailimap_fetch_att_new_bodystructure();
595 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); 596 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
596 err = mailimap_fetch( m_imap, set, fetchType, &result ); 597 err = mailimap_fetch( m_imap, set, fetchType, &result );
597 mailimap_set_free( set ); 598 mailimap_set_free( set );
598 mailimap_fetch_type_free( fetchType ); 599 mailimap_fetch_type_free( fetchType );
599 600
600 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 601 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
601 mailimap_msg_att * msg_att; 602 mailimap_msg_att * msg_att;
602 msg_att = (mailimap_msg_att*)current->data; 603 msg_att = (mailimap_msg_att*)current->data;
603 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;
604 QValueList<int> path; 605 QValueList<int> path;
605 body_desc = item->att_data.att_static->att_data.att_body; 606 body_desc = item->att_data.att_static->att_data.att_body;
606 traverseBody(mail,body_desc,body,0,path); 607 traverseBody(mail,body_desc,body,0,path);
607 } else { 608 } else {
608 //odebug << "error fetching body: " << m_imap->imap_response << "" << oendl; 609 //odebug << "error fetching body: " << m_imap->imap_response << "" << oendl;
609 } 610 }
610 if (result) mailimap_fetch_list_free(result); 611 if (result) mailimap_fetch_list_free(result);
611 return body; 612 return body;
612} 613}
613 614
614QStringList IMAPwrapper::address_list_to_stringlist(clist*list) 615QStringList IMAPwrapper::address_list_to_stringlist(clist*list)
615{ 616{
616 QStringList l; 617 QStringList l;
617 QString from; 618 QString from;
618 bool named_from; 619 bool named_from;
619 clistcell *current = NULL; 620 clistcell *current = NULL;
620 mailimap_address * current_address=NULL; 621 mailimap_address * current_address=NULL;
621 if (!list) { 622 if (!list) {
622 return l; 623 return l;
623 } 624 }
624 unsigned int count = 0; 625 unsigned int count = 0;
625 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { 626 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) {
626 from = ""; 627 from = "";
627 named_from = false; 628 named_from = false;
628 current_address=(mailimap_address*)current->data; 629 current_address=(mailimap_address*)current->data;
629 if (current_address->ad_personal_name){ 630 if (current_address->ad_personal_name){
630 from+=convert_String((const char*)current_address->ad_personal_name); 631 from+=convert_String((const char*)current_address->ad_personal_name);
631 from+=" "; 632 from+=" ";
632 named_from = true; 633 named_from = true;
633 } 634 }
634 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)) {
635 from+="<"; 636 from+="<";
636 } 637 }
637 if (current_address->ad_mailbox_name) { 638 if (current_address->ad_mailbox_name) {
638 from+=QString(current_address->ad_mailbox_name); 639 from+=QString(current_address->ad_mailbox_name);
639 from+="@"; 640 from+="@";
640 } 641 }
641 if (current_address->ad_host_name) { 642 if (current_address->ad_host_name) {
642 from+=QString(current_address->ad_host_name); 643 from+=QString(current_address->ad_host_name);
643 } 644 }
644 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)) {
645 from+=">"; 646 from+=">";
646 } 647 }
647 l.append(QString(from)); 648 l.append(QString(from));
648 if (++count > 99) { 649 if (++count > 99) {
649 break; 650 break;
650 } 651 }
651 } 652 }
652 return l; 653 return l;
653} 654}
654 655
655encodedString*IMAPwrapper::fetchRawPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call) 656encodedString*IMAPwrapper::fetchRawPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call)
656{ 657{
657 encodedString*res=new encodedString; 658 encodedString*res=new encodedString;
658 int err; 659 int err;
659 mailimap_fetch_type *fetchType; 660 mailimap_fetch_type *fetchType;
660 mailimap_set *set; 661 mailimap_set *set;
661 clistcell*current,*cur; 662 clistcell*current,*cur;
662 mailimap_section_part * section_part = 0; 663 mailimap_section_part * section_part = 0;
663 mailimap_section_spec * section_spec = 0; 664 mailimap_section_spec * section_spec = 0;
664 mailimap_section * section = 0; 665 mailimap_section * section = 0;
665 mailimap_fetch_att * fetch_att = 0; 666 mailimap_fetch_att * fetch_att = 0;
666 667
667 login(); 668 login();
668 if (!m_imap) { 669 if (!m_imap) {
669 return res; 670 return res;
670 } 671 }
671 if (!internal_call) { 672 if (!internal_call) {
672 err = selectMbox(mail->getMbox()); 673 err = selectMbox(mail->getMbox());
673 if ( err != MAILIMAP_NO_ERROR ) { 674 if ( err != MAILIMAP_NO_ERROR ) {
674 return res; 675 return res;
675 } 676 }
676 } 677 }
677 set = mailimap_set_new_single(mail->getNumber()); 678 set = mailimap_set_new_single(mail->getNumber());
678 679
679 clist*id_list = 0; 680 clist*id_list = 0;
680 681
681 /* 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
682 a "fetch <id> (body[])" statement on imap server */ 683 a "fetch <id> (body[])" statement on imap server */
683 if (path.count()>0 ) { 684 if (path.count()>0 ) {
684 id_list = clist_new(); 685 id_list = clist_new();
685 for (unsigned j=0; j < path.count();++j) { 686 for (unsigned j=0; j < path.count();++j) {
686 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); 687 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id));
687 *p_id = path[j]; 688 *p_id = path[j];
688 clist_append(id_list,p_id); 689 clist_append(id_list,p_id);
689 } 690 }
690 section_part = mailimap_section_part_new(id_list); 691 section_part = mailimap_section_part_new(id_list);
691 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);
692 } 693 }
693 694
694 section = mailimap_section_new(section_spec); 695 section = mailimap_section_new(section_spec);
695 fetch_att = mailimap_fetch_att_new_body_section(section); 696 fetch_att = mailimap_fetch_att_new_body_section(section);
696 fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); 697 fetchType = mailimap_fetch_type_new_fetch_att(fetch_att);
697 698
698 clist*result = 0; 699 clist*result = 0;
699 700
700 err = mailimap_fetch( m_imap, set, fetchType, &result ); 701 err = mailimap_fetch( m_imap, set, fetchType, &result );
701 mailimap_set_free( set ); 702 mailimap_set_free( set );
702 mailimap_fetch_type_free( fetchType ); 703 mailimap_fetch_type_free( fetchType );
703 704
704 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 705 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
705 mailimap_msg_att * msg_att; 706 mailimap_msg_att * msg_att;
706 msg_att = (mailimap_msg_att*)current->data; 707 msg_att = (mailimap_msg_att*)current->data;
707 mailimap_msg_att_item*msg_att_item; 708 mailimap_msg_att_item*msg_att_item;
708 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)) {
709 msg_att_item = (mailimap_msg_att_item*)clist_content(cur); 710 msg_att_item = (mailimap_msg_att_item*)clist_content(cur);
710 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { 711 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) {
711 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) {
712 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;
713 /* detach - we take over the content */ 714 /* detach - we take over the content */
714 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;
715 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);
716 } 717 }
717 } 718 }
718 } 719 }
719 } else { 720 } else {
720 ;//odebug << "error fetching text: " << m_imap->imap_response << "" << oendl; 721 ;//odebug << "error fetching text: " << m_imap->imap_response << "" << oendl;
721 } 722 }
722 if (result) mailimap_fetch_list_free(result); 723 if (result) mailimap_fetch_list_free(result);
723 return res; 724 return res;
724} 725}
725 726
726/* current_recursion is for recursive calls. 727/* current_recursion is for recursive calls.
727 current_count means the position inside the internal loop! */ 728 current_count means the position inside the internal loop! */
728void IMAPwrapper::traverseBody(const RecMailP&mail,mailimap_body*body,RecBodyP&target_body, 729void IMAPwrapper::traverseBody(const RecMailP&mail,mailimap_body*body,RecBodyP&target_body,
729 int current_recursion,QValueList<int>recList,int current_count) 730 int current_recursion,QValueList<int>recList,int current_count)
730{ 731{
731 if (!body || current_recursion>=10) { 732 if (!body || current_recursion>=10) {
732 return; 733 return;
733 } 734 }
734 switch (body->bd_type) { 735 switch (body->bd_type) {
735 case MAILIMAP_BODY_1PART: 736 case MAILIMAP_BODY_1PART:
736 { 737 {
737 QValueList<int>countlist = recList; 738 QValueList<int>countlist = recList;
738 countlist.append(current_count); 739 countlist.append(current_count);
739 RecPartP currentPart = new RecPart(); 740 RecPartP currentPart = new RecPart();
740 mailimap_body_type_1part*part1 = body->bd_data.bd_body_1part; 741 mailimap_body_type_1part*part1 = body->bd_data.bd_body_1part;
741 QString id(""); 742 QString id("");
742 currentPart->setPositionlist(countlist); 743 currentPart->setPositionlist(countlist);
743 for (unsigned int j = 0; j < countlist.count();++j) { 744 for (unsigned int j = 0; j < countlist.count();++j) {
744 id+=(j>0?" ":""); 745 id+=(j>0?" ":"");
745 id+=QString("%1").arg(countlist[j]); 746 id+=QString("%1").arg(countlist[j]);
746 } 747 }
747 //odebug << "ID = " << id.latin1() << "" << oendl; 748 //odebug << "ID = " << id.latin1() << "" << oendl;
748 currentPart->setIdentifier(id); 749 currentPart->setIdentifier(id);
749 fillSinglePart(currentPart,part1); 750 fillSinglePart(currentPart,part1);
750 /* important: Check for is NULL 'cause a body can be empty! 751 /* important: Check for is NULL 'cause a body can be empty!
751 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 */
752 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) {
753 QString body_text = fetchTextPart(mail,countlist,true,currentPart->Encoding()); 754 QString body_text = fetchTextPart(mail,countlist,true,currentPart->Encoding());
754 //qDebug("encoding %d text %s ",currentPart->Encoding().latin1(), body_text.latin1() ); 755 //qDebug("encoding %d text %s ",currentPart->Encoding().latin1(), body_text.latin1() );
755 target_body->setDescription(currentPart); 756 target_body->setDescription(currentPart);
756 target_body->setBodytext(body_text); 757 target_body->setBodytext(body_text);
757 if (countlist.count()>1) { 758 if (countlist.count()>1) {
758 target_body->addPart(currentPart); 759 target_body->addPart(currentPart);
759 } 760 }
760 } else { 761 } else {
761 target_body->addPart(currentPart); 762 target_body->addPart(currentPart);
762 } 763 }
763 if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_MSG) { 764 if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_MSG) {
764 traverseBody(mail,part1->bd_data.bd_type_msg->bd_body,target_body,current_recursion+1,countlist); 765 traverseBody(mail,part1->bd_data.bd_type_msg->bd_body,target_body,current_recursion+1,countlist);
765 } 766 }
766 } 767 }
767 break; 768 break;
768 case MAILIMAP_BODY_MPART: 769 case MAILIMAP_BODY_MPART:
769 { 770 {
770 QValueList<int>countlist = recList; 771 QValueList<int>countlist = recList;
771 clistcell*current=0; 772 clistcell*current=0;
772 mailimap_body*current_body=0; 773 mailimap_body*current_body=0;
773 unsigned int ccount = 1; 774 unsigned int ccount = 1;
774 mailimap_body_type_mpart*mailDescription = body->bd_data.bd_body_mpart; 775 mailimap_body_type_mpart*mailDescription = body->bd_data.bd_body_mpart;
775 for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { 776 for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) {
776 current_body = (mailimap_body*)current->data; 777 current_body = (mailimap_body*)current->data;
777 if (current_body->bd_type==MAILIMAP_BODY_MPART) { 778 if (current_body->bd_type==MAILIMAP_BODY_MPART) {
778 RecPartP targetPart = new RecPart(); 779 RecPartP targetPart = new RecPart();
779 targetPart->setType("multipart"); 780 targetPart->setType("multipart");
780 fillMultiPart(targetPart,mailDescription); 781 fillMultiPart(targetPart,mailDescription);
781 countlist.append(current_count); 782 countlist.append(current_count);
782 targetPart->setPositionlist(countlist); 783 targetPart->setPositionlist(countlist);
783 target_body->addPart(targetPart); 784 target_body->addPart(targetPart);
784 QString id(""); 785 QString id("");
785 for (unsigned int j = 0; j < countlist.count();++j) { 786 for (unsigned int j = 0; j < countlist.count();++j) {
786 id+=(j>0?" ":""); 787 id+=(j>0?" ":"");
787 id+=QString("%1").arg(countlist[j]); 788 id+=QString("%1").arg(countlist[j]);
788 } 789 }
789 // odebug << "ID(mpart) = " << id.latin1() << "" << oendl; 790 // odebug << "ID(mpart) = " << id.latin1() << "" << oendl;
790 } 791 }
791 traverseBody(mail,current_body,target_body,current_recursion+1,countlist,ccount); 792 traverseBody(mail,current_body,target_body,current_recursion+1,countlist,ccount);
792 if (current_body->bd_type==MAILIMAP_BODY_MPART) { 793 if (current_body->bd_type==MAILIMAP_BODY_MPART) {
793 countlist = recList; 794 countlist = recList;
794 } 795 }
795 ++ccount; 796 ++ccount;
796 } 797 }
797 } 798 }
798 break; 799 break;
799 default: 800 default:
800 break; 801 break;
801 } 802 }
802} 803}
803 804
804void IMAPwrapper::fillSinglePart(RecPartP&target_part,mailimap_body_type_1part*Description) 805void IMAPwrapper::fillSinglePart(RecPartP&target_part,mailimap_body_type_1part*Description)
805{ 806{
806 if (!Description) { 807 if (!Description) {
807 return; 808 return;
808 } 809 }
809 switch (Description->bd_type) { 810 switch (Description->bd_type) {
810 case MAILIMAP_BODY_TYPE_1PART_TEXT: 811 case MAILIMAP_BODY_TYPE_1PART_TEXT:
811 target_part->setType("text"); 812 target_part->setType("text");
812 fillSingleTextPart(target_part,Description->bd_data.bd_type_text); 813 fillSingleTextPart(target_part,Description->bd_data.bd_type_text);
813 break; 814 break;
814 case MAILIMAP_BODY_TYPE_1PART_BASIC: 815 case MAILIMAP_BODY_TYPE_1PART_BASIC:
815 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); 816 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic);
816 break; 817 break;
817 case MAILIMAP_BODY_TYPE_1PART_MSG: 818 case MAILIMAP_BODY_TYPE_1PART_MSG:
818 target_part->setType("message"); 819 target_part->setType("message");
819 fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); 820 fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg);
820 break; 821 break;
821 default: 822 default:
822 break; 823 break;
823 } 824 }
824} 825}
825 826
826void IMAPwrapper::fillSingleTextPart(RecPartP&target_part,mailimap_body_type_text*which) 827void IMAPwrapper::fillSingleTextPart(RecPartP&target_part,mailimap_body_type_text*which)
827{ 828{
828 if (!which) { 829 if (!which) {
829 return; 830 return;
830 } 831 }
831 QString sub; 832 QString sub;
832 sub = which->bd_media_text; 833 sub = which->bd_media_text;
833 //odebug << "Type= text/" << which->bd_media_text << "" << oendl; 834 //odebug << "Type= text/" << which->bd_media_text << "" << oendl;
834 target_part->setSubtype(sub.lower()); 835 target_part->setSubtype(sub.lower());
835 target_part->setLines(which->bd_lines); 836 target_part->setLines(which->bd_lines);
836 fillBodyFields(target_part,which->bd_fields); 837 fillBodyFields(target_part,which->bd_fields);
837} 838}
838 839
839void IMAPwrapper::fillSingleMsgPart(RecPartP&target_part,mailimap_body_type_msg*which) 840void IMAPwrapper::fillSingleMsgPart(RecPartP&target_part,mailimap_body_type_msg*which)
840{ 841{
841 if (!which) { 842 if (!which) {
842 return; 843 return;
843 } 844 }
844 target_part->setSubtype("rfc822"); 845 target_part->setSubtype("rfc822");
845 //odebug << "Message part" << oendl; 846 //odebug << "Message part" << oendl;
846 /* we set this type to text/plain */ 847 /* we set this type to text/plain */
847 target_part->setLines(which->bd_lines); 848 target_part->setLines(which->bd_lines);
848 fillBodyFields(target_part,which->bd_fields); 849 fillBodyFields(target_part,which->bd_fields);
849} 850}
850 851
851void IMAPwrapper::fillMultiPart(RecPartP&target_part,mailimap_body_type_mpart*which) 852void IMAPwrapper::fillMultiPart(RecPartP&target_part,mailimap_body_type_mpart*which)
852{ 853{
853 if (!which) return; 854 if (!which) return;
854 QString sub = which->bd_media_subtype; 855 QString sub = which->bd_media_subtype;
855 target_part->setSubtype(sub.lower()); 856 target_part->setSubtype(sub.lower());
856 if (which->bd_ext_mpart && which->bd_ext_mpart->bd_parameter && which->bd_ext_mpart->bd_parameter->pa_list) { 857 if (which->bd_ext_mpart && which->bd_ext_mpart->bd_parameter && which->bd_ext_mpart->bd_parameter->pa_list) {
857 clistcell*cur = 0; 858 clistcell*cur = 0;
858 mailimap_single_body_fld_param*param=0; 859 mailimap_single_body_fld_param*param=0;
859 for (cur = clist_begin(which->bd_ext_mpart->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { 860 for (cur = clist_begin(which->bd_ext_mpart->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) {
860 param = (mailimap_single_body_fld_param*)cur->data; 861 param = (mailimap_single_body_fld_param*)cur->data;
861 if (param) { 862 if (param) {
862 target_part->addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); 863 target_part->addParameter(QString(param->pa_name).lower(),QString(param->pa_value));
863 } 864 }
864 } 865 }
865 } 866 }
866} 867}
867 868
868void IMAPwrapper::fillSingleBasicPart(RecPartP&target_part,mailimap_body_type_basic*which) 869void IMAPwrapper::fillSingleBasicPart(RecPartP&target_part,mailimap_body_type_basic*which)
869{ 870{
870 if (!which) { 871 if (!which) {
871 return; 872 return;
872 } 873 }
873 QString type,sub; 874 QString type,sub;
874 switch (which->bd_media_basic->med_type) { 875 switch (which->bd_media_basic->med_type) {
875 case MAILIMAP_MEDIA_BASIC_APPLICATION: 876 case MAILIMAP_MEDIA_BASIC_APPLICATION:
876 type = "application"; 877 type = "application";
877 break; 878 break;
878 case MAILIMAP_MEDIA_BASIC_AUDIO: 879 case MAILIMAP_MEDIA_BASIC_AUDIO:
879 type = "audio"; 880 type = "audio";
880 break; 881 break;
881 case MAILIMAP_MEDIA_BASIC_IMAGE: 882 case MAILIMAP_MEDIA_BASIC_IMAGE:
882 type = "image"; 883 type = "image";
883 break; 884 break;
884 case MAILIMAP_MEDIA_BASIC_MESSAGE: 885 case MAILIMAP_MEDIA_BASIC_MESSAGE:
885 type = "message"; 886 type = "message";
886 break; 887 break;
887 case MAILIMAP_MEDIA_BASIC_VIDEO: 888 case MAILIMAP_MEDIA_BASIC_VIDEO:
888 type = "video"; 889 type = "video";
889 break; 890 break;
890 case MAILIMAP_MEDIA_BASIC_OTHER: 891 case MAILIMAP_MEDIA_BASIC_OTHER:
891 default: 892 default:
892 if (which->bd_media_basic->med_basic_type) { 893 if (which->bd_media_basic->med_basic_type) {
893 type = which->bd_media_basic->med_basic_type; 894 type = which->bd_media_basic->med_basic_type;
894 } else { 895 } else {
895 type = ""; 896 type = "";
896 } 897 }
897 break; 898 break;
898 } 899 }
899 if (which->bd_media_basic->med_subtype) { 900 if (which->bd_media_basic->med_subtype) {
900 sub = which->bd_media_basic->med_subtype; 901 sub = which->bd_media_basic->med_subtype;
901 } else { 902 } else {
902 sub = ""; 903 sub = "";
903 } 904 }
904 // odebug << "Type = " << type.latin1() << "/" << sub.latin1() << "" << oendl; 905 // odebug << "Type = " << type.latin1() << "/" << sub.latin1() << "" << oendl;
905 target_part->setType(type.lower()); 906 target_part->setType(type.lower());
906 target_part->setSubtype(sub.lower()); 907 target_part->setSubtype(sub.lower());
907 fillBodyFields(target_part,which->bd_fields); 908 fillBodyFields(target_part,which->bd_fields);
908} 909}
909 910
910void IMAPwrapper::fillBodyFields(RecPartP&target_part,mailimap_body_fields*which) 911void IMAPwrapper::fillBodyFields(RecPartP&target_part,mailimap_body_fields*which)
911{ 912{
912 if (!which) return; 913 if (!which) return;
913 if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) { 914 if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) {
914 clistcell*cur; 915 clistcell*cur;
915 mailimap_single_body_fld_param*param=0; 916 mailimap_single_body_fld_param*param=0;
916 for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { 917 for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) {
917 param = (mailimap_single_body_fld_param*)cur->data; 918 param = (mailimap_single_body_fld_param*)cur->data;
918 if (param) { 919 if (param) {
919 target_part->addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); 920 target_part->addParameter(QString(param->pa_name).lower(),QString(param->pa_value));
920 } 921 }
921 } 922 }
922 } 923 }
923 mailimap_body_fld_enc*enc = which->bd_encoding; 924 mailimap_body_fld_enc*enc = which->bd_encoding;
924 QString encoding(""); 925 QString encoding("");
925 switch (enc->enc_type) { 926 switch (enc->enc_type) {
926 case MAILIMAP_BODY_FLD_ENC_7BIT: 927 case MAILIMAP_BODY_FLD_ENC_7BIT:
927 encoding = "7bit"; 928 encoding = "7bit";
928 break; 929 break;
929 case MAILIMAP_BODY_FLD_ENC_8BIT: 930 case MAILIMAP_BODY_FLD_ENC_8BIT:
930 encoding = "8bit"; 931 encoding = "8bit";
931 break; 932 break;
932 case MAILIMAP_BODY_FLD_ENC_BINARY: 933 case MAILIMAP_BODY_FLD_ENC_BINARY:
933 encoding="binary"; 934 encoding="binary";
934 break; 935 break;
935 case MAILIMAP_BODY_FLD_ENC_BASE64: 936 case MAILIMAP_BODY_FLD_ENC_BASE64:
936 encoding="base64"; 937 encoding="base64";
937 break; 938 break;
938 case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: 939 case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE:
939 encoding="quoted-printable"; 940 encoding="quoted-printable";
940 break; 941 break;
941 case MAILIMAP_BODY_FLD_ENC_OTHER: 942 case MAILIMAP_BODY_FLD_ENC_OTHER:
942 default: 943 default:
943 if (enc->enc_value) { 944 if (enc->enc_value) {
944 char*t=enc->enc_value; 945 char*t=enc->enc_value;
945 encoding=QString(enc->enc_value); 946 encoding=QString(enc->enc_value);
946 enc->enc_value=0L; 947 enc->enc_value=0L;
947 free(t); 948 free(t);
948 } 949 }
949 } 950 }
950 if (which->bd_description) { 951 if (which->bd_description) {
951 target_part->setDescription(QString(which->bd_description)); 952 target_part->setDescription(QString(which->bd_description));
952 } 953 }
953 target_part->setEncoding(encoding); 954 target_part->setEncoding(encoding);
954 target_part->setSize(which->bd_size); 955 target_part->setSize(which->bd_size);
955} 956}
956void IMAPwrapper::deleteMailList(const QValueList<RecMailP>&target) 957void IMAPwrapper::deleteMailList(const QValueList<RecMailP>&target)
957{ 958{
958 //#if 0 959 //#if 0
959 mailimap_flag_list*flist; 960 mailimap_flag_list*flist;
960 mailimap_set *set; 961 mailimap_set *set;
961 mailimap_store_att_flags * store_flags; 962 mailimap_store_att_flags * store_flags;
962 int err; 963 int err;
963 login(); 964 login();
964 //#endif 965 //#endif
965 if (!m_imap) { 966 if (!m_imap) {
966 return; 967 return;
967 } 968 }
968 int iii = 0; 969 int iii = 0;
969 int count = target.count(); 970 int count = target.count();
970 // qDebug("imap remove count %d ", count); 971 // qDebug("imap remove count %d ", count);
971 972
972 973
973 mMax = count; 974 mMax = count;
974 progress( i18n("Delete")); 975 progress( i18n("Delete"));
975 976
976 QProgressBar wid ( count ); 977 QProgressBar wid ( count );
977 wid.setCaption( i18n("Deleting ...")); 978 wid.setCaption( i18n("Deleting ..."));
978 wid.show(); 979 wid.show();
979 while (iii < count ) { 980 while (iii < count ) {
980 Global::statusMessage(i18n("Delete message %1 of %2").arg(iii).arg(count)); 981 Global::statusMessage(i18n("Delete message %1 of %2").arg(iii).arg(count));
981 wid.setProgress( iii ); 982 wid.setProgress( iii );
982 wid.raise(); 983 wid.raise();
983 qApp->processEvents(); 984 qApp->processEvents();
984 RecMailP mail = (*target.at( iii )); 985 RecMailP mail = (*target.at( iii ));
985 //#if 0 986 //#if 0
986 //qDebug("IMAP remove %d %d ", iii, mail->getNumber() ); 987 //qDebug("IMAP remove %d %d ", iii, mail->getNumber() );
987 err = selectMbox(mail->getMbox()); 988 err = selectMbox(mail->getMbox());
988 if ( err != MAILIMAP_NO_ERROR ) { 989 if ( err != MAILIMAP_NO_ERROR ) {
989 return; 990 return;
990 } 991 }
991 flist = mailimap_flag_list_new_empty(); 992 flist = mailimap_flag_list_new_empty();
992 mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); 993 mailimap_flag_list_add(flist,mailimap_flag_new_deleted());
993 store_flags = mailimap_store_att_flags_new_set_flags(flist); 994 store_flags = mailimap_store_att_flags_new_set_flags(flist);
994 set = mailimap_set_new_single(mail->getNumber()); 995 set = mailimap_set_new_single(mail->getNumber());
995 err = mailimap_store(m_imap,set,store_flags); 996 err = mailimap_store(m_imap,set,store_flags);
996 mailimap_set_free( set ); 997 mailimap_set_free( set );
997 mailimap_store_att_flags_free(store_flags); 998 mailimap_store_att_flags_free(store_flags);
998 999
999 if (err != MAILIMAP_NO_ERROR) { 1000 if (err != MAILIMAP_NO_ERROR) {
1000 // odebug << "error deleting mail: " << m_imap->imap_response << "" << oendl; 1001 // odebug << "error deleting mail: " << m_imap->imap_response << "" << oendl;
1001 return; 1002 return;
1002 } 1003 }
1003 // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl; 1004 // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl;
1004 /* should we realy do that at this moment? */ 1005 /* should we realy do that at this moment? */
1005 1006
1006 // err = mailimap_expunge(m_imap); 1007 // err = mailimap_expunge(m_imap);
1007 //if (err != MAILIMAP_NO_ERROR) { 1008 //if (err != MAILIMAP_NO_ERROR) {
1008 // Global::statusMessage(i18n("Error deleting mails: %s").arg(m_imap->imap_response)); 1009 // Global::statusMessage(i18n("Error deleting mails: %s").arg(m_imap->imap_response));
1009 // } 1010 // }
1010 //#endif 1011 //#endif
1011 //deleteMail( mail); 1012 //deleteMail( mail);
1012 ++iii; 1013 ++iii;
1013 } 1014 }
1014 //qDebug("Deleting imap mails... "); 1015 //qDebug("Deleting imap mails... ");
1015 err = mailimap_expunge(m_imap); 1016 err = mailimap_expunge(m_imap);
1016 if (err != MAILIMAP_NO_ERROR) { 1017 if (err != MAILIMAP_NO_ERROR) {
1017 Global::statusMessage(i18n("Error deleting mails: %s").arg(m_imap->imap_response)); 1018 Global::statusMessage(i18n("Error deleting mails: %s").arg(m_imap->imap_response));
1018 } 1019 }
1019} 1020}
1020void IMAPwrapper::deleteMail(const RecMailP&mail) 1021void IMAPwrapper::deleteMail(const RecMailP&mail)
1021{ 1022{
1022 mailimap_flag_list*flist; 1023 mailimap_flag_list*flist;
1023 mailimap_set *set; 1024 mailimap_set *set;
1024 mailimap_store_att_flags * store_flags; 1025 mailimap_store_att_flags * store_flags;
1025 int err; 1026 int err;
1026 login(); 1027 login();
1027 if (!m_imap) { 1028 if (!m_imap) {
1028 return; 1029 return;
1029 } 1030 }
1030 err = selectMbox(mail->getMbox()); 1031 err = selectMbox(mail->getMbox());
1031 if ( err != MAILIMAP_NO_ERROR ) { 1032 if ( err != MAILIMAP_NO_ERROR ) {
1032 return; 1033 return;
1033 } 1034 }
1034 flist = mailimap_flag_list_new_empty(); 1035 flist = mailimap_flag_list_new_empty();
1035 mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); 1036 mailimap_flag_list_add(flist,mailimap_flag_new_deleted());
1036 store_flags = mailimap_store_att_flags_new_set_flags(flist); 1037 store_flags = mailimap_store_att_flags_new_set_flags(flist);
1037 set = mailimap_set_new_single(mail->getNumber()); 1038 set = mailimap_set_new_single(mail->getNumber());
1038 err = mailimap_store(m_imap,set,store_flags); 1039 err = mailimap_store(m_imap,set,store_flags);
1039 mailimap_set_free( set ); 1040 mailimap_set_free( set );
1040 mailimap_store_att_flags_free(store_flags); 1041 mailimap_store_att_flags_free(store_flags);
1041 1042
1042 if (err != MAILIMAP_NO_ERROR) { 1043 if (err != MAILIMAP_NO_ERROR) {
1043 // odebug << "error deleting mail: " << m_imap->imap_response << "" << oendl; 1044 // odebug << "error deleting mail: " << m_imap->imap_response << "" << oendl;
1044 return; 1045 return;
1045 } 1046 }
1046 // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl; 1047 // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl;
1047 /* should we realy do that at this moment? */ 1048 /* should we realy do that at this moment? */
1048 1049
1049 err = mailimap_expunge(m_imap); 1050 err = mailimap_expunge(m_imap);
1050 if (err != MAILIMAP_NO_ERROR) { 1051 if (err != MAILIMAP_NO_ERROR) {
1051 Global::statusMessage(i18n("error deleting mail: %s").arg(m_imap->imap_response)); 1052 Global::statusMessage(i18n("error deleting mail: %s").arg(m_imap->imap_response));
1052 } 1053 }
1053 //qDebug("IMAPwrapper::deleteMail 2"); 1054 //qDebug("IMAPwrapper::deleteMail 2");
1054 1055
1055} 1056}
1056 1057
1057void IMAPwrapper::answeredMail(const RecMailP&mail) 1058void IMAPwrapper::answeredMail(const RecMailP&mail)
1058{ 1059{
1059 mailimap_flag_list*flist; 1060 mailimap_flag_list*flist;
1060 mailimap_set *set; 1061 mailimap_set *set;
1061 mailimap_store_att_flags * store_flags; 1062 mailimap_store_att_flags * store_flags;
1062 int err; 1063 int err;
1063 login(); 1064 login();
1064 if (!m_imap) { 1065 if (!m_imap) {
1065 return; 1066 return;
1066 } 1067 }
1067 err = selectMbox(mail->getMbox()); 1068 err = selectMbox(mail->getMbox());
1068 if ( err != MAILIMAP_NO_ERROR ) { 1069 if ( err != MAILIMAP_NO_ERROR ) {
1069 return; 1070 return;
1070 } 1071 }
1071 flist = mailimap_flag_list_new_empty(); 1072 flist = mailimap_flag_list_new_empty();
1072 mailimap_flag_list_add(flist,mailimap_flag_new_answered()); 1073 mailimap_flag_list_add(flist,mailimap_flag_new_answered());
1073 store_flags = mailimap_store_att_flags_new_add_flags(flist); 1074 store_flags = mailimap_store_att_flags_new_add_flags(flist);
1074 set = mailimap_set_new_single(mail->getNumber()); 1075 set = mailimap_set_new_single(mail->getNumber());
1075 err = mailimap_store(m_imap,set,store_flags); 1076 err = mailimap_store(m_imap,set,store_flags);
1076 mailimap_set_free( set ); 1077 mailimap_set_free( set );
1077 mailimap_store_att_flags_free(store_flags); 1078 mailimap_store_att_flags_free(store_flags);
1078 1079
1079 if (err != MAILIMAP_NO_ERROR) { 1080 if (err != MAILIMAP_NO_ERROR) {
1080 // odebug << "error marking mail: " << m_imap->imap_response << "" << oendl; 1081 // odebug << "error marking mail: " << m_imap->imap_response << "" << oendl;
1081 return; 1082 return;
1082 } 1083 }
1083} 1084}
1084 1085
1085QString IMAPwrapper::fetchTextPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call,const QString&enc) 1086QString IMAPwrapper::fetchTextPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call,const QString&enc)
1086{ 1087{
1087 QString body(""); 1088 QString body("");
1088 encodedString*res = fetchRawPart(mail,path,internal_call); 1089 encodedString*res = fetchRawPart(mail,path,internal_call);
1089 encodedString*r = decode_String(res,enc); 1090 encodedString*r = decode_String(res,enc);
1090 delete res; 1091 delete res;
1091 if (r) { 1092 if (r) {
1092 if (r->Length()>0) { 1093 if (r->Length()>0) {
1093 body = r->Content(); 1094 body = r->Content();
1094 } 1095 }
1095 delete r; 1096 delete r;
1096 } 1097 }
1097 return body; 1098 return body;
1098} 1099}
1099 1100
1100QString IMAPwrapper::fetchTextPart(const RecMailP&mail,const RecPartP&part) 1101QString IMAPwrapper::fetchTextPart(const RecMailP&mail,const RecPartP&part)
1101{ 1102{
1102 return fetchTextPart(mail,part->Positionlist(),false,part->Encoding()); 1103 return fetchTextPart(mail,part->Positionlist(),false,part->Encoding());
1103} 1104}
1104 1105
1105encodedString* IMAPwrapper::fetchDecodedPart(const RecMailP&mail,const RecPartP&part) 1106encodedString* IMAPwrapper::fetchDecodedPart(const RecMailP&mail,const RecPartP&part)
1106{ 1107{
1107 encodedString*res = fetchRawPart(mail,part->Positionlist(),false); 1108 encodedString*res = fetchRawPart(mail,part->Positionlist(),false);
1108 encodedString*r = decode_String(res,part->Encoding()); 1109 encodedString*r = decode_String(res,part->Encoding());
1109 delete res; 1110 delete res;
1110 return r; 1111 return r;
1111} 1112}
1112 1113
1113encodedString* IMAPwrapper::fetchRawPart(const RecMailP&mail,const RecPartP&part) 1114encodedString* IMAPwrapper::fetchRawPart(const RecMailP&mail,const RecPartP&part)
1114{ 1115{
1115 return fetchRawPart(mail,part->Positionlist(),false); 1116 return fetchRawPart(mail,part->Positionlist(),false);
1116} 1117}
1117 1118
1118int IMAPwrapper::deleteAllMail(const FolderP&folder) 1119int IMAPwrapper::deleteAllMail(const FolderP&folder)
1119{ 1120{
1120 login(); 1121 login();
1121 if (!m_imap) { 1122 if (!m_imap) {
1122 return 0; 1123 return 0;
1123 } 1124 }
1124 mailimap_flag_list*flist; 1125 mailimap_flag_list*flist;
1125 mailimap_set *set; 1126 mailimap_set *set;
1126 mailimap_store_att_flags * store_flags; 1127 mailimap_store_att_flags * store_flags;
1127 int err = selectMbox(folder->getName()); 1128 int err = selectMbox(folder->getName());
1128 if ( err != MAILIMAP_NO_ERROR ) { 1129 if ( err != MAILIMAP_NO_ERROR ) {
1129 return 0; 1130 return 0;
1130 } 1131 }
1131 1132
1132 int last = m_imap->imap_selection_info->sel_exists; 1133 int last = m_imap->imap_selection_info->sel_exists;
1133 if (last == 0) { 1134 if (last == 0) {
1134 Global::statusMessage(i18n("Mailbox has no mails!")); 1135 Global::statusMessage(i18n("Mailbox has no mails!"));
1135 return 0; 1136 return 0;
1136 } 1137 }
1137 flist = mailimap_flag_list_new_empty(); 1138 flist = mailimap_flag_list_new_empty();
1138 mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); 1139 mailimap_flag_list_add(flist,mailimap_flag_new_deleted());
1139 store_flags = mailimap_store_att_flags_new_set_flags(flist); 1140 store_flags = mailimap_store_att_flags_new_set_flags(flist);
1140 set = mailimap_set_new_interval( 1, last ); 1141 set = mailimap_set_new_interval( 1, last );
1141 err = mailimap_store(m_imap,set,store_flags); 1142 err = mailimap_store(m_imap,set,store_flags);
1142 mailimap_set_free( set ); 1143 mailimap_set_free( set );
1143 mailimap_store_att_flags_free(store_flags); 1144 mailimap_store_att_flags_free(store_flags);
1144 if (err != MAILIMAP_NO_ERROR) { 1145 if (err != MAILIMAP_NO_ERROR) {
1145 Global::statusMessage(i18n("error deleting mail: %s").arg(m_imap->imap_response)); 1146 Global::statusMessage(i18n("error deleting mail: %s").arg(m_imap->imap_response));
1146 return 0; 1147 return 0;
1147 } 1148 }
1148 // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl; 1149 // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl;
1149 /* should we realy do that at this moment? */ 1150 /* should we realy do that at this moment? */
1150 err = mailimap_expunge(m_imap); 1151 err = mailimap_expunge(m_imap);
1151 if (err != MAILIMAP_NO_ERROR) { 1152 if (err != MAILIMAP_NO_ERROR) {
1152 Global::statusMessage(i18n("error deleting mail: %s").arg(m_imap->imap_response)); 1153 Global::statusMessage(i18n("error deleting mail: %s").arg(m_imap->imap_response));
1153 return 0; 1154 return 0;
1154 } 1155 }
1155 // odebug << "Delete successfull " << m_imap->imap_response << "" << oendl; 1156 // odebug << "Delete successfull " << m_imap->imap_response << "" << oendl;
1156 return 1; 1157 return 1;
1157} 1158}
1158 1159
1159int IMAPwrapper::createMbox(const QString&folder,const FolderP&parentfolder,const QString& delemiter,bool getsubfolder) 1160int IMAPwrapper::createMbox(const QString&folder,const FolderP&parentfolder,const QString& delemiter,bool getsubfolder)
1160{ 1161{
1161 if (folder.length()==0) return 0; 1162 if (folder.length()==0) return 0;
1162 login(); 1163 login();
1163 if (!m_imap) {return 0;} 1164 if (!m_imap) {return 0;}
1164 QString pre = account->getPrefix(); 1165 QString pre = account->getPrefix();
1165 if (delemiter.length()>0 && pre.findRev(delemiter)!=pre.length()-1) { 1166 if (delemiter.length()>0 && pre.findRev(delemiter)!=pre.length()-1) {
1166 pre+=delemiter; 1167 pre+=delemiter;
1167 } 1168 }
1168 if (parentfolder) { 1169 if (parentfolder) {
1169 pre += parentfolder->getDisplayName()+delemiter; 1170 pre += parentfolder->getDisplayName()+delemiter;
1170 } 1171 }
1171 pre+=folder; 1172 pre+=folder;
1172 if (getsubfolder) { 1173 if (getsubfolder) {
1173 if (delemiter.length()>0) { 1174 if (delemiter.length()>0) {
1174 pre+=delemiter; 1175 pre+=delemiter;
1175 } else { 1176 } else {
1176 Global::statusMessage(i18n("Cannot create folder %1 for holding subfolders").arg(pre)); 1177 Global::statusMessage(i18n("Cannot create folder %1 for holding subfolders").arg(pre));
1177 return 0; 1178 return 0;
1178 } 1179 }
1179 } 1180 }
1180 // odebug << "Creating " << pre.latin1() << "" << oendl; 1181 // odebug << "Creating " << pre.latin1() << "" << oendl;
1181 int res = mailimap_create(m_imap,pre.latin1()); 1182 int res = mailimap_create(m_imap,pre.latin1());
1182 if (res != MAILIMAP_NO_ERROR) { 1183 if (res != MAILIMAP_NO_ERROR) {
1183 Global::statusMessage(i18n("%1").arg(m_imap->imap_response)); 1184 Global::statusMessage(i18n("%1").arg(m_imap->imap_response));
1184 return 0; 1185 return 0;
1185 } 1186 }
1186 return 1; 1187 return 1;
1187} 1188}
1188 1189
1189int IMAPwrapper::deleteMbox(const FolderP&folder) 1190int IMAPwrapper::deleteMbox(const FolderP&folder)
1190{ 1191{
1191 if (!folder) return 0; 1192 if (!folder) return 0;
1192 login(); 1193 login();
1193 if (!m_imap) {return 0;} 1194 if (!m_imap) {return 0;}
1194 int res = mailimap_delete(m_imap,folder->getName()); 1195 int res = mailimap_delete(m_imap,folder->getName());
1195 if (res != MAILIMAP_NO_ERROR) { 1196 if (res != MAILIMAP_NO_ERROR) {
1196 Global::statusMessage(i18n("%1").arg(m_imap->imap_response)); 1197 Global::statusMessage(i18n("%1").arg(m_imap->imap_response));
1197 return 0; 1198 return 0;
1198 } 1199 }
1199 return 1; 1200 return 1;
1200} 1201}
1201 1202
1202void IMAPwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) 1203void IMAPwrapper::statusFolder(folderStat&target_stat,const QString & mailbox)
1203{ 1204{
1204 mailimap_status_att_list * att_list =0; 1205 mailimap_status_att_list * att_list =0;
1205 mailimap_mailbox_data_status * status=0; 1206 mailimap_mailbox_data_status * status=0;
1206 clistiter * cur = 0; 1207 clistiter * cur = 0;
1207 int r = 0; 1208 int r = 0;
1208 target_stat.message_count = 0; 1209 target_stat.message_count = 0;
1209 target_stat.message_unseen = 0; 1210 target_stat.message_unseen = 0;
1210 target_stat.message_recent = 0; 1211 target_stat.message_recent = 0;
1211 login(); 1212 login();
1212 if (!m_imap) { 1213 if (!m_imap) {
1213 return; 1214 return;
1214 } 1215 }
1215 att_list = mailimap_status_att_list_new_empty(); 1216 att_list = mailimap_status_att_list_new_empty();
1216 if (!att_list) return; 1217 if (!att_list) return;
1217 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_MESSAGES); 1218 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_MESSAGES);
1218 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_RECENT); 1219 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_RECENT);
1219 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_UNSEEN); 1220 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_UNSEEN);
1220 r = mailimap_status(m_imap, mailbox.latin1(), att_list, &status); 1221 r = mailimap_status(m_imap, mailbox.latin1(), att_list, &status);
1221 if (r==MAILIMAP_NO_ERROR&&status->st_info_list!=0) { 1222 if (r==MAILIMAP_NO_ERROR&&status->st_info_list!=0) {
1222 for (cur = clist_begin(status->st_info_list); 1223 for (cur = clist_begin(status->st_info_list);
1223 cur != NULL ; cur = clist_next(cur)) { 1224 cur != NULL ; cur = clist_next(cur)) {
1224 mailimap_status_info * status_info; 1225 mailimap_status_info * status_info;
1225 status_info = (mailimap_status_info *)clist_content(cur); 1226 status_info = (mailimap_status_info *)clist_content(cur);
1226 switch (status_info->st_att) { 1227 switch (status_info->st_att) {
1227 case MAILIMAP_STATUS_ATT_MESSAGES: 1228 case MAILIMAP_STATUS_ATT_MESSAGES:
1228 target_stat.message_count = status_info->st_value; 1229 target_stat.message_count = status_info->st_value;
1229 break; 1230 break;
1230 case MAILIMAP_STATUS_ATT_RECENT: 1231 case MAILIMAP_STATUS_ATT_RECENT:
1231 target_stat.message_recent = status_info->st_value; 1232 target_stat.message_recent = status_info->st_value;
1232 break; 1233 break;
1233 case MAILIMAP_STATUS_ATT_UNSEEN: 1234 case MAILIMAP_STATUS_ATT_UNSEEN:
1234 target_stat.message_unseen = status_info->st_value; 1235 target_stat.message_unseen = status_info->st_value;
1235 break; 1236 break;
1236 } 1237 }
1237 } 1238 }
1238 } else { 1239 } else {
1239 // odebug << "Error retrieving status" << oendl; 1240 // odebug << "Error retrieving status" << oendl;
1240 } 1241 }
1241 if (status) mailimap_mailbox_data_status_free(status); 1242 if (status) mailimap_mailbox_data_status_free(status);
1242 if (att_list) mailimap_status_att_list_free(att_list); 1243 if (att_list) mailimap_status_att_list_free(att_list);
1243} 1244}
1244 1245
1245void IMAPwrapper::storeMessage(const char*msg,size_t length, const QString&folder) 1246void IMAPwrapper::storeMessage(const char*msg,size_t length, const QString&folder)
1246{ 1247{
1247 login(); 1248 login();
1248 if (!m_imap) return; 1249 if (!m_imap) return;
1249 if (!msg) return; 1250 if (!msg) return;
1250 int r = mailimap_append(m_imap,(char*)folder.latin1(),0,0,msg,length); 1251 int r = mailimap_append(m_imap,(char*)folder.latin1(),0,0,msg,length);
1251 if (r != MAILIMAP_NO_ERROR) { 1252 if (r != MAILIMAP_NO_ERROR) {
1252 Global::statusMessage("Error storing mail!"); 1253 Global::statusMessage("Error storing mail!");
1253 } 1254 }
1254} 1255}
1255 1256
1256MAILLIB::ATYPE IMAPwrapper::getType()const 1257MAILLIB::ATYPE IMAPwrapper::getType()const
1257{ 1258{
1258 return account->getType(); 1259 return account->getType();
1259} 1260}
1260 1261
1261const QString&IMAPwrapper::getName()const 1262const QString&IMAPwrapper::getName()const
1262{ 1263{
1263 // odebug << "Get name: " << account->getAccountName().latin1() << "" << oendl; 1264 // odebug << "Get name: " << account->getAccountName().latin1() << "" << oendl;
1264 return account->getAccountName(); 1265 return account->getAccountName();
1265} 1266}
1266 1267
1267encodedString* IMAPwrapper::fetchRawBody(const RecMailP&mail) 1268encodedString* IMAPwrapper::fetchRawBody(const RecMailP&mail)
diff --git a/kmicromail/libmailwrapper/settings.cpp b/kmicromail/libmailwrapper/settings.cpp
index 5d2c0ad..04afe7c 100644
--- a/kmicromail/libmailwrapper/settings.cpp
+++ b/kmicromail/libmailwrapper/settings.cpp
@@ -1,500 +1,501 @@
1#include <stdlib.h> 1#include <stdlib.h>
2#include <qdir.h> 2#include <qdir.h>
3 3
4//#include <opie2/odebug.h> 4//#include <opie2/odebug.h>
5#include <kconfig.h> 5#include <kconfig.h>
6 6
7#include <kstandarddirs.h> 7#include <kstandarddirs.h>
8#include "settings.h" 8#include "settings.h"
9//#include "defines.h" 9//#include "defines.h"
10 10
11#define IMAP_PORT "143" 11#define IMAP_PORT "143"
12#define IMAP_SSL_PORT "993" 12#define IMAP_SSL_PORT "993"
13#define SMTP_PORT "25" 13#define SMTP_PORT "25"
14#define SMTP_SSL_PORT "465" 14#define SMTP_SSL_PORT "465"
15#define POP3_PORT "110" 15#define POP3_PORT "110"
16#define POP3_SSL_PORT "995" 16#define POP3_SSL_PORT "995"
17#define NNTP_PORT "119" 17#define NNTP_PORT "119"
18#define NNTP_SSL_PORT "563" 18#define NNTP_SSL_PORT "563"
19 19
20 20
21Settings::Settings() 21Settings::Settings()
22 : QObject() 22 : QObject()
23{ 23{
24 accounts.setAutoDelete( true ); ;
24 updateAccounts(); 25 updateAccounts();
25 //qDebug("++++++++++++++++++new settings "); 26 //qDebug("++++++++++++++++++new settings ");
26} 27}
27 28
28void Settings::checkDirectory() 29void Settings::checkDirectory()
29{ 30{
30 return; 31 return;
31 locateLocal("data", "kopiemail" ); 32 locateLocal("data", "kopiemail" );
32 /* 33 /*
33 if ( !QDir( (QString) getenv( "HOME" ) + "/Applications/opiemail/" ).exists() ) { 34 if ( !QDir( (QString) getenv( "HOME" ) + "/Applications/opiemail/" ).exists() ) {
34 system( "mkdir -p $HOME/Applications/opiemail" ); 35 system( "mkdir -p $HOME/Applications/opiemail" );
35 qDebug("$HOME/Applications/opiemail created "); 36 qDebug("$HOME/Applications/opiemail created ");
36 } 37 }
37 */ 38 */
38} 39}
39 40
40QList<Account> Settings::getAccounts() 41QList<Account> Settings::getAccounts()
41{ 42{
42 return accounts; 43 return accounts;
43} 44}
44 45
45void Settings::addAccount( Account *account ) 46void Settings::addAccount( Account *account )
46{ 47{
47 accounts.append( account ); 48 accounts.append( account );
48} 49}
49 50
50void Settings::delAccount( Account *account ) 51void Settings::delAccount( Account *account )
51{ 52{
52 accounts.remove( account ); 53 accounts.remove( account );
53 account->remove(); 54 account->remove();
54} 55}
55 56
56void Settings::updateAccounts() 57void Settings::updateAccounts()
57{ 58{
58 accounts.clear(); 59 accounts.clear();
59 QDir dir( locateLocal("data", "kopiemail" ) ); 60 QDir dir( locateLocal("data", "kopiemail" ) );
60 QStringList::Iterator it; 61 QStringList::Iterator it;
61 62
62 QStringList imap = dir.entryList( "imap-*" ); 63 QStringList imap = dir.entryList( "imap-*" );
63 for ( it = imap.begin(); it != imap.end(); it++ ) { 64 for ( it = imap.begin(); it != imap.end(); it++ ) {
64 IMAPaccount *account = new IMAPaccount( (*it).replace(0, 5, "") ); 65 IMAPaccount *account = new IMAPaccount( (*it).replace(0, 5, "") );
65 accounts.append( account ); 66 accounts.append( account );
66 } 67 }
67 68
68 QStringList pop3 = dir.entryList( "pop3-*" ); 69 QStringList pop3 = dir.entryList( "pop3-*" );
69 for ( it = pop3.begin(); it != pop3.end(); it++ ) { 70 for ( it = pop3.begin(); it != pop3.end(); it++ ) {
70 POP3account *account = new POP3account( (*it).replace(0, 5, "") ); 71 POP3account *account = new POP3account( (*it).replace(0, 5, "") );
71 accounts.append( account ); 72 accounts.append( account );
72 } 73 }
73 74
74 QStringList smtp = dir.entryList( "smtp-*" ); 75 QStringList smtp = dir.entryList( "smtp-*" );
75 for ( it = smtp.begin(); it != smtp.end(); it++ ) { 76 for ( it = smtp.begin(); it != smtp.end(); it++ ) {
76 SMTPaccount *account = new SMTPaccount( (*it).replace(0, 5, "") ); 77 SMTPaccount *account = new SMTPaccount( (*it).replace(0, 5, "") );
77 accounts.append( account ); 78 accounts.append( account );
78 } 79 }
79 80
80 QStringList nntp = dir.entryList( "nntp-*" ); 81 QStringList nntp = dir.entryList( "nntp-*" );
81 for ( it = nntp.begin(); it != nntp.end(); it++ ) { 82 for ( it = nntp.begin(); it != nntp.end(); it++ ) {
82 NNTPaccount *account = new NNTPaccount( (*it).replace(0, 5, "") ); 83 NNTPaccount *account = new NNTPaccount( (*it).replace(0, 5, "") );
83 accounts.append( account ); 84 accounts.append( account );
84 } 85 }
85 86
86 readAccounts(); 87 readAccounts();
87} 88}
88 89
89void Settings::saveAccounts() 90void Settings::saveAccounts()
90{ 91{
91 checkDirectory(); 92 checkDirectory();
92 Account *it; 93 Account *it;
93 94
94 for ( it = accounts.first(); it; it = accounts.next() ) { 95 for ( it = accounts.first(); it; it = accounts.next() ) {
95 it->save(); 96 it->save();
96 } 97 }
97} 98}
98 99
99void Settings::readAccounts() 100void Settings::readAccounts()
100{ 101{
101 checkDirectory(); 102 checkDirectory();
102 Account *it; 103 Account *it;
103 104
104 for ( it = accounts.first(); it; it = accounts.next() ) { 105 for ( it = accounts.first(); it; it = accounts.next() ) {
105 it->read(); 106 it->read();
106 } 107 }
107} 108}
108 109
109Account::Account() 110Account::Account()
110{ 111{
111 accountName = "changeMe"; 112 accountName = "changeMe";
112 type = MAILLIB::A_UNDEFINED; 113 type = MAILLIB::A_UNDEFINED;
113 ssl = false; 114 ssl = false;
114 connectionType = 1; 115 connectionType = 1;
115 offline = false; 116 offline = false;
116 maxMailSize = 0; 117 maxMailSize = 0;
117 lastFetch; 118 lastFetch;
118 leaveOnServer = false; 119 leaveOnServer = false;
119} 120}
120 121
121void Account::remove() 122void Account::remove()
122{ 123{
123 QFile file( getFileName() ); 124 QFile file( getFileName() );
124 file.remove(); 125 file.remove();
125} 126}
126 127
127void Account::setPasswordList(const QStringList &str) 128void Account::setPasswordList(const QStringList &str)
128{ 129{
129 password = ""; 130 password = "";
130 int i; 131 int i;
131 for ( i = 0; i < str.count() ; ++i ) { 132 for ( i = 0; i < str.count() ; ++i ) {
132 QChar c ( (str[i].toUInt()-131)/(str.count()- (i%3))); 133 QChar c ( (str[i].toUInt()-131)/(str.count()- (i%3)));
133 password.append( c ); 134 password.append( c );
134 } 135 }
135 //qDebug("password %s ", password.latin1()); 136 //qDebug("password %s ", password.latin1());
136} 137}
137QStringList Account::getPasswordList() 138QStringList Account::getPasswordList()
138{ 139{
139 int i; 140 int i;
140 int len = password.length(); 141 int len = password.length();
141 QStringList str; 142 QStringList str;
142 143
143 for ( i = 0; i < len ; ++i ) { 144 for ( i = 0; i < len ; ++i ) {
144 int val = password.at(i).unicode()*(len-(i%3))+131; 145 int val = password.at(i).unicode()*(len-(i%3))+131;
145 str.append( QString::number( val ) ); 146 str.append( QString::number( val ) );
146 // qDebug("append %s ", str[i].latin1()); 147 // qDebug("append %s ", str[i].latin1());
147 } 148 }
148 return str; 149 return str;
149} 150}
150 151
151IMAPaccount::IMAPaccount() 152IMAPaccount::IMAPaccount()
152 : Account() 153 : Account()
153{ 154{
154 file = IMAPaccount::getUniqueFileName(); 155 file = IMAPaccount::getUniqueFileName();
155 accountName = "New IMAP Account"; 156 accountName = "New IMAP Account";
156 ssl = false; 157 ssl = false;
157 connectionType = 1; 158 connectionType = 1;
158 type = MAILLIB::A_IMAP; 159 type = MAILLIB::A_IMAP;
159 port = IMAP_PORT; 160 port = IMAP_PORT;
160} 161}
161 162
162IMAPaccount::IMAPaccount( QString filename ) 163IMAPaccount::IMAPaccount( QString filename )
163 : Account() 164 : Account()
164{ 165{
165 file = filename; 166 file = filename;
166 accountName = "New IMAP Account"; 167 accountName = "New IMAP Account";
167 ssl = false; 168 ssl = false;
168 connectionType = 1; 169 connectionType = 1;
169 type = MAILLIB::A_IMAP; 170 type = MAILLIB::A_IMAP;
170 port = IMAP_PORT; 171 port = IMAP_PORT;
171} 172}
172 173
173QString IMAPaccount::getUniqueFileName() 174QString IMAPaccount::getUniqueFileName()
174{ 175{
175 int num = 0; 176 int num = 0;
176 QString unique; 177 QString unique;
177 178
178 QDir dir( locateLocal("data", "kopiemail" ) ); 179 QDir dir( locateLocal("data", "kopiemail" ) );
179 180
180 QStringList imap = dir.entryList( "imap-*" ); 181 QStringList imap = dir.entryList( "imap-*" );
181 do { 182 do {
182 unique.setNum( num++ ); 183 unique.setNum( num++ );
183 } while ( imap.contains( "imap-" + unique ) > 0 ); 184 } while ( imap.contains( "imap-" + unique ) > 0 );
184 185
185 return unique; 186 return unique;
186} 187}
187 188
188void IMAPaccount::read() 189void IMAPaccount::read()
189{ 190{
190 KConfig *conf = new KConfig( getFileName() ); 191 KConfig *conf = new KConfig( getFileName() );
191 conf->setGroup( "IMAP Account" ); 192 conf->setGroup( "IMAP Account" );
192 accountName = conf->readEntry( "Account","" ); 193 accountName = conf->readEntry( "Account","" );
193 if (accountName.isNull()) accountName = ""; 194 if (accountName.isNull()) accountName = "";
194 server = conf->readEntry( "Server","" ); 195 server = conf->readEntry( "Server","" );
195 if (server.isNull()) server=""; 196 if (server.isNull()) server="";
196 port = conf->readEntry( "Port","" ); 197 port = conf->readEntry( "Port","" );
197 if (port.isNull()) port="143"; 198 if (port.isNull()) port="143";
198 connectionType = conf->readNumEntry( "ConnectionType" ); 199 connectionType = conf->readNumEntry( "ConnectionType" );
199 ssl = conf->readBoolEntry( "SSL",false ); 200 ssl = conf->readBoolEntry( "SSL",false );
200 user = conf->readEntry( "User","" ); 201 user = conf->readEntry( "User","" );
201 if (user.isNull()) user = ""; 202 if (user.isNull()) user = "";
202 //password = conf->readEntryCrypt( "Password","" ); 203 //password = conf->readEntryCrypt( "Password","" );
203 setPasswordList( conf->readListEntry( "FolderHistory")); 204 setPasswordList( conf->readListEntry( "FolderHistory"));
204 if (password.isNull()) password = ""; 205 if (password.isNull()) password = "";
205 prefix = conf->readEntry("MailPrefix",""); 206 prefix = conf->readEntry("MailPrefix","");
206 if (prefix.isNull()) prefix = ""; 207 if (prefix.isNull()) prefix = "";
207 offline = conf->readBoolEntry("Offline",false); 208 offline = conf->readBoolEntry("Offline",false);
208 localFolder = conf->readEntry( "LocalFolder" ); 209 localFolder = conf->readEntry( "LocalFolder" );
209 maxMailSize = conf->readNumEntry( "MaxSize",0 ); 210 maxMailSize = conf->readNumEntry( "MaxSize",0 );
210 int lf = conf->readNumEntry( "LastFetch",0 ); 211 int lf = conf->readNumEntry( "LastFetch",0 );
211 QDateTime dt ( QDate ( 2004, 1, 1 ), QTime( 0,0,0) ); 212 QDateTime dt ( QDate ( 2004, 1, 1 ), QTime( 0,0,0) );
212 leaveOnServer = conf->readBoolEntry("LeaveOnServer",false); 213 leaveOnServer = conf->readBoolEntry("LeaveOnServer",false);
213 if ( lf < 0 ) lf = 0; 214 if ( lf < 0 ) lf = 0;
214 lastFetch = dt.addSecs( lf ); 215 lastFetch = dt.addSecs( lf );
215 delete conf; 216 delete conf;
216} 217}
217 218
218void IMAPaccount::save() 219void IMAPaccount::save()
219{ 220{
220 221
221 Settings::checkDirectory(); 222 Settings::checkDirectory();
222 223
223 KConfig *conf = new KConfig( getFileName() ); 224 KConfig *conf = new KConfig( getFileName() );
224 conf->setGroup( "IMAP Account" ); 225 conf->setGroup( "IMAP Account" );
225 conf->writeEntry( "Account", accountName ); 226 conf->writeEntry( "Account", accountName );
226 conf->writeEntry( "Server", server ); 227 conf->writeEntry( "Server", server );
227 conf->writeEntry( "Port", port ); 228 conf->writeEntry( "Port", port );
228 conf->writeEntry( "SSL", ssl ); 229 conf->writeEntry( "SSL", ssl );
229 conf->writeEntry( "ConnectionType", connectionType ); 230 conf->writeEntry( "ConnectionType", connectionType );
230 conf->writeEntry( "User", user ); 231 conf->writeEntry( "User", user );
231 //conf->writeEntryCrypt( "Password", password ); 232 //conf->writeEntryCrypt( "Password", password );
232 conf->writeEntry( "FolderHistory",getPasswordList() ); 233 conf->writeEntry( "FolderHistory",getPasswordList() );
233 conf->writeEntry( "MailPrefix",prefix); 234 conf->writeEntry( "MailPrefix",prefix);
234 conf->writeEntry( "Offline",offline); 235 conf->writeEntry( "Offline",offline);
235 conf->writeEntry( "LocalFolder", localFolder ); 236 conf->writeEntry( "LocalFolder", localFolder );
236 conf->writeEntry( "MaxSize", maxMailSize ); 237 conf->writeEntry( "MaxSize", maxMailSize );
237 QDateTime dt ( QDate ( 2004, 1, 1 ), QTime( 0,0,0) ); 238 QDateTime dt ( QDate ( 2004, 1, 1 ), QTime( 0,0,0) );
238 int lf = dt.secsTo ( lastFetch ); 239 int lf = dt.secsTo ( lastFetch );
239 conf->writeEntry( "LastFetch", lf ); 240 conf->writeEntry( "LastFetch", lf );
240 conf->writeEntry( "LeaveOnServer", leaveOnServer); 241 conf->writeEntry( "LeaveOnServer", leaveOnServer);
241 conf->sync(); 242 conf->sync();
242 delete conf; 243 delete conf;
243} 244}
244 245
245 246
246QString IMAPaccount::getFileName() 247QString IMAPaccount::getFileName()
247{ 248{
248 return locateLocal("data", "kopiemail" ) +"/imap-" + file; 249 return locateLocal("data", "kopiemail" ) +"/imap-" + file;
249} 250}
250 251
251POP3account::POP3account() 252POP3account::POP3account()
252 : Account() 253 : Account()
253{ 254{
254 file = POP3account::getUniqueFileName(); 255 file = POP3account::getUniqueFileName();
255 accountName = "New POP3 Account"; 256 accountName = "New POP3 Account";
256 ssl = false; 257 ssl = false;
257 connectionType = 1; 258 connectionType = 1;
258 type = MAILLIB::A_POP3; 259 type = MAILLIB::A_POP3;
259 port = POP3_PORT; 260 port = POP3_PORT;
260} 261}
261 262
262POP3account::POP3account( QString filename ) 263POP3account::POP3account( QString filename )
263 : Account() 264 : Account()
264{ 265{
265 file = filename; 266 file = filename;
266 accountName = "New POP3 Account"; 267 accountName = "New POP3 Account";
267 ssl = false; 268 ssl = false;
268 connectionType = 1; 269 connectionType = 1;
269 type = MAILLIB::A_POP3; 270 type = MAILLIB::A_POP3;
270 port = POP3_PORT; 271 port = POP3_PORT;
271} 272}
272 273
273QString POP3account::getUniqueFileName() 274QString POP3account::getUniqueFileName()
274{ 275{
275 int num = 0; 276 int num = 0;
276 QString unique; 277 QString unique;
277 278
278 QDir dir( locateLocal("data", "kopiemail" ) ); 279 QDir dir( locateLocal("data", "kopiemail" ) );
279 280
280 QStringList imap = dir.entryList( "pop3-*" ); 281 QStringList imap = dir.entryList( "pop3-*" );
281 do { 282 do {
282 unique.setNum( num++ ); 283 unique.setNum( num++ );
283 } while ( imap.contains( "pop3-" + unique ) > 0 ); 284 } while ( imap.contains( "pop3-" + unique ) > 0 );
284 285
285 return unique; 286 return unique;
286} 287}
287 288
288void POP3account::read() 289void POP3account::read()
289{ 290{
290 KConfig *conf = new KConfig( getFileName()); 291 KConfig *conf = new KConfig( getFileName());
291 conf->setGroup( "POP3 Account" ); 292 conf->setGroup( "POP3 Account" );
292 accountName = conf->readEntry( "Account" ); 293 accountName = conf->readEntry( "Account" );
293 server = conf->readEntry( "Server" ); 294 server = conf->readEntry( "Server" );
294 port = conf->readEntry( "Port" ); 295 port = conf->readEntry( "Port" );
295 ssl = conf->readBoolEntry( "SSL" ); 296 ssl = conf->readBoolEntry( "SSL" );
296 connectionType = conf->readNumEntry( "ConnectionType" ); 297 connectionType = conf->readNumEntry( "ConnectionType" );
297 user = conf->readEntry( "User" ); 298 user = conf->readEntry( "User" );
298 //password = conf->readEntryCrypt( "Password" ); 299 //password = conf->readEntryCrypt( "Password" );
299 setPasswordList( conf->readListEntry( "FolderHistory")); 300 setPasswordList( conf->readListEntry( "FolderHistory"));
300 offline = conf->readBoolEntry("Offline",false); 301 offline = conf->readBoolEntry("Offline",false);
301 localFolder = conf->readEntry( "LocalFolder" ); 302 localFolder = conf->readEntry( "LocalFolder" );
302 maxMailSize = conf->readNumEntry( "MaxSize",0 ); 303 maxMailSize = conf->readNumEntry( "MaxSize",0 );
303 int lf = conf->readNumEntry( "LastFetch",0 ); 304 int lf = conf->readNumEntry( "LastFetch",0 );
304 QDateTime dt ( QDate ( 2004, 1, 1 ), QTime( 0,0,0) ); 305 QDateTime dt ( QDate ( 2004, 1, 1 ), QTime( 0,0,0) );
305 leaveOnServer = conf->readBoolEntry("LeaveOnServer",false); 306 leaveOnServer = conf->readBoolEntry("LeaveOnServer",false);
306 lastFetch = dt.addSecs( lf ); 307 lastFetch = dt.addSecs( lf );
307 delete conf; 308 delete conf;
308} 309}
309 310
310void POP3account::save() 311void POP3account::save()
311{ 312{
312 Settings::checkDirectory(); 313 Settings::checkDirectory();
313 314
314 KConfig *conf = new KConfig( getFileName() ); 315 KConfig *conf = new KConfig( getFileName() );
315 conf->setGroup( "POP3 Account" ); 316 conf->setGroup( "POP3 Account" );
316 conf->writeEntry( "Account", accountName ); 317 conf->writeEntry( "Account", accountName );
317 conf->writeEntry( "Server", server ); 318 conf->writeEntry( "Server", server );
318 conf->writeEntry( "Port", port ); 319 conf->writeEntry( "Port", port );
319 conf->writeEntry( "SSL", ssl ); 320 conf->writeEntry( "SSL", ssl );
320 conf->writeEntry( "ConnectionType", connectionType ); 321 conf->writeEntry( "ConnectionType", connectionType );
321 conf->writeEntry( "User", user ); 322 conf->writeEntry( "User", user );
322 //conf->writeEntryCrypt( "Password", password ); 323 //conf->writeEntryCrypt( "Password", password );
323 conf->writeEntry( "FolderHistory",getPasswordList() ); 324 conf->writeEntry( "FolderHistory",getPasswordList() );
324 conf->writeEntry( "Offline",offline); 325 conf->writeEntry( "Offline",offline);
325 conf->writeEntry( "LocalFolder", localFolder ); 326 conf->writeEntry( "LocalFolder", localFolder );
326 conf->writeEntry( "MaxSize", maxMailSize ); 327 conf->writeEntry( "MaxSize", maxMailSize );
327 QDateTime dt ( QDate ( 2004, 1, 1 ), QTime( 0,0,0) ); 328 QDateTime dt ( QDate ( 2004, 1, 1 ), QTime( 0,0,0) );
328 int lf = dt.secsTo ( lastFetch ); 329 int lf = dt.secsTo ( lastFetch );
329 conf->writeEntry( "LastFetch", lf ); 330 conf->writeEntry( "LastFetch", lf );
330 conf->writeEntry( "LeaveOnServer", leaveOnServer); 331 conf->writeEntry( "LeaveOnServer", leaveOnServer);
331 conf->sync(); 332 conf->sync();
332 delete conf; 333 delete conf;
333} 334}
334 335
335 336
336QString POP3account::getFileName() 337QString POP3account::getFileName()
337{ 338{
338 return locateLocal("data", "kopiemail" ) +"/pop3-" + file; 339 return locateLocal("data", "kopiemail" ) +"/pop3-" + file;
339} 340}
340 341
341SMTPaccount::SMTPaccount() 342SMTPaccount::SMTPaccount()
342 : Account() 343 : Account()
343{ 344{
344 file = SMTPaccount::getUniqueFileName(); 345 file = SMTPaccount::getUniqueFileName();
345 accountName = "New SMTP Account"; 346 accountName = "New SMTP Account";
346 ssl = false; 347 ssl = false;
347 connectionType = 1; 348 connectionType = 1;
348 login = false; 349 login = false;
349 useCC = false; 350 useCC = false;
350 useBCC = false; 351 useBCC = false;
351 useReply = false; 352 useReply = false;
352 type = MAILLIB::A_SMTP; 353 type = MAILLIB::A_SMTP;
353 port = SMTP_PORT; 354 port = SMTP_PORT;
354} 355}
355 356
356SMTPaccount::SMTPaccount( QString filename ) 357SMTPaccount::SMTPaccount( QString filename )
357 : Account() 358 : Account()
358{ 359{
359 file = filename; 360 file = filename;
360 accountName = "New SMTP Account"; 361 accountName = "New SMTP Account";
361 ssl = false; 362 ssl = false;
362 connectionType = 1; 363 connectionType = 1;
363 login = false; 364 login = false;
364 type = MAILLIB::A_SMTP; 365 type = MAILLIB::A_SMTP;
365 port = SMTP_PORT; 366 port = SMTP_PORT;
366} 367}
367 368
368QString SMTPaccount::getUniqueFileName() 369QString SMTPaccount::getUniqueFileName()
369{ 370{
370 int num = 0; 371 int num = 0;
371 QString unique; 372 QString unique;
372 373
373 QDir dir( locateLocal("data", "kopiemail" ) ); 374 QDir dir( locateLocal("data", "kopiemail" ) );
374 375
375 QStringList imap = dir.entryList( "smtp-*" ); 376 QStringList imap = dir.entryList( "smtp-*" );
376 do { 377 do {
377 unique.setNum( num++ ); 378 unique.setNum( num++ );
378 } while ( imap.contains( "smtp-" + unique ) > 0 ); 379 } while ( imap.contains( "smtp-" + unique ) > 0 );
379 380
380 return unique; 381 return unique;
381} 382}
382 383
383void SMTPaccount::read() 384void SMTPaccount::read()
384{ 385{
385 KConfig *conf = new KConfig( getFileName() ); 386 KConfig *conf = new KConfig( getFileName() );
386 conf->setGroup( "SMTP Account" ); 387 conf->setGroup( "SMTP Account" );
387 accountName = conf->readEntry( "Account" ); 388 accountName = conf->readEntry( "Account" );
388 server = conf->readEntry( "Server" ); 389 server = conf->readEntry( "Server" );
389 port = conf->readEntry( "Port" ); 390 port = conf->readEntry( "Port" );
390 ssl = conf->readBoolEntry( "SSL" ); 391 ssl = conf->readBoolEntry( "SSL" );
391 connectionType = conf->readNumEntry( "ConnectionType" ); 392 connectionType = conf->readNumEntry( "ConnectionType" );
392 login = conf->readBoolEntry( "Login" ); 393 login = conf->readBoolEntry( "Login" );
393 user = conf->readEntry( "User" ); 394 user = conf->readEntry( "User" );
394 //password = conf->readEntryCrypt( "Password" ); 395 //password = conf->readEntryCrypt( "Password" );
395 setPasswordList( conf->readListEntry( "FolderHistory")); 396 setPasswordList( conf->readListEntry( "FolderHistory"));
396 delete conf; 397 delete conf;
397} 398}
398 399
399void SMTPaccount::save() 400void SMTPaccount::save()
400{ 401{
401 Settings::checkDirectory(); 402 Settings::checkDirectory();
402 403
403 KConfig *conf = new KConfig( getFileName() ); 404 KConfig *conf = new KConfig( getFileName() );
404 conf->setGroup( "SMTP Account" ); 405 conf->setGroup( "SMTP Account" );
405 conf->writeEntry( "Account", accountName ); 406 conf->writeEntry( "Account", accountName );
406 conf->writeEntry( "Server", server ); 407 conf->writeEntry( "Server", server );
407 conf->writeEntry( "Port", port ); 408 conf->writeEntry( "Port", port );
408 conf->writeEntry( "SSL", ssl ); 409 conf->writeEntry( "SSL", ssl );
409 conf->writeEntry( "ConnectionType", connectionType ); 410 conf->writeEntry( "ConnectionType", connectionType );
410 conf->writeEntry( "Login", login ); 411 conf->writeEntry( "Login", login );
411 conf->writeEntry( "User", user ); 412 conf->writeEntry( "User", user );
412 //conf->writeEntryCrypt( "Password", password ); 413 //conf->writeEntryCrypt( "Password", password );
413 conf->writeEntry( "FolderHistory",getPasswordList() ); 414 conf->writeEntry( "FolderHistory",getPasswordList() );
414 conf->sync(); 415 conf->sync();
415 delete conf; 416 delete conf;
416} 417}
417 418
418 419
419QString SMTPaccount::getFileName() 420QString SMTPaccount::getFileName()
420{ 421{
421 return locateLocal("data", "kopiemail" ) +"/smtp-" + file; 422 return locateLocal("data", "kopiemail" ) +"/smtp-" + file;
422} 423}
423 424
424NNTPaccount::NNTPaccount() 425NNTPaccount::NNTPaccount()
425 : Account() 426 : Account()
426{ 427{
427 file = NNTPaccount::getUniqueFileName(); 428 file = NNTPaccount::getUniqueFileName();
428 accountName = "New NNTP Account"; 429 accountName = "New NNTP Account";
429 ssl = false; 430 ssl = false;
430 login = false; 431 login = false;
431 type = MAILLIB::A_NNTP; 432 type = MAILLIB::A_NNTP;
432 port = NNTP_PORT; 433 port = NNTP_PORT;
433} 434}
434 435
435NNTPaccount::NNTPaccount( QString filename ) 436NNTPaccount::NNTPaccount( QString filename )
436 : Account() 437 : Account()
437{ 438{
438 file = filename; 439 file = filename;
439 accountName = "New NNTP Account"; 440 accountName = "New NNTP Account";
440 ssl = false; 441 ssl = false;
441 login = false; 442 login = false;
442 type = MAILLIB::A_NNTP; 443 type = MAILLIB::A_NNTP;
443 port = NNTP_PORT; 444 port = NNTP_PORT;
444} 445}
445 446
446QString NNTPaccount::getUniqueFileName() 447QString NNTPaccount::getUniqueFileName()
447{ 448{
448 int num = 0; 449 int num = 0;
449 QString unique; 450 QString unique;
450 451
451 QDir dir( locateLocal("data", "kopiemail" ) ); 452 QDir dir( locateLocal("data", "kopiemail" ) );
452 453
453 QStringList imap = dir.entryList( "nntp-*" ); 454 QStringList imap = dir.entryList( "nntp-*" );
454 do { 455 do {
455 unique.setNum( num++ ); 456 unique.setNum( num++ );
456 } while ( imap.contains( "nntp-" + unique ) > 0 ); 457 } while ( imap.contains( "nntp-" + unique ) > 0 );
457 458
458 return unique; 459 return unique;
459} 460}
460 461
461void NNTPaccount::read() 462void NNTPaccount::read()
462{ 463{
463 KConfig *conf = new KConfig( getFileName() ); 464 KConfig *conf = new KConfig( getFileName() );
464 conf->setGroup( "NNTP Account" ); 465 conf->setGroup( "NNTP Account" );
465 accountName = conf->readEntry( "Account" ); 466 accountName = conf->readEntry( "Account" );
466 server = conf->readEntry( "Server" ); 467 server = conf->readEntry( "Server" );
467 port = conf->readEntry( "Port" ); 468 port = conf->readEntry( "Port" );
468 ssl = conf->readBoolEntry( "SSL" ); 469 ssl = conf->readBoolEntry( "SSL" );
469 login = conf->readBoolEntry( "Login" ); 470 login = conf->readBoolEntry( "Login" );
470 user = conf->readEntry( "User" ); 471 user = conf->readEntry( "User" );
471 //password = conf->readEntryCrypt( "Password" ); 472 //password = conf->readEntryCrypt( "Password" );
472 setPasswordList( conf->readListEntry( "FolderHistory")); 473 setPasswordList( conf->readListEntry( "FolderHistory"));
473 subscribedGroups = conf->readListEntry( "Subscribed"); 474 subscribedGroups = conf->readListEntry( "Subscribed");
474 delete conf; 475 delete conf;
475} 476}
476 477
477void NNTPaccount::save() 478void NNTPaccount::save()
478{ 479{
479 Settings::checkDirectory(); 480 Settings::checkDirectory();
480 481
481 KConfig *conf = new KConfig( getFileName() ); 482 KConfig *conf = new KConfig( getFileName() );
482 conf->setGroup( "NNTP Account" ); 483 conf->setGroup( "NNTP Account" );
483 conf->writeEntry( "Account", accountName ); 484 conf->writeEntry( "Account", accountName );
484 conf->writeEntry( "Server", server ); 485 conf->writeEntry( "Server", server );
485 conf->writeEntry( "Port", port ); 486 conf->writeEntry( "Port", port );
486 conf->writeEntry( "SSL", ssl ); 487 conf->writeEntry( "SSL", ssl );
487 conf->writeEntry( "Login", login ); 488 conf->writeEntry( "Login", login );
488 conf->writeEntry( "User", user ); 489 conf->writeEntry( "User", user );
489 //conf->writeEntryCrypt( "Password", password ); 490 //conf->writeEntryCrypt( "Password", password );
490 conf->writeEntry( "FolderHistory",getPasswordList() ); 491 conf->writeEntry( "FolderHistory",getPasswordList() );
491 conf->writeEntry( "Subscribed" , subscribedGroups ); 492 conf->writeEntry( "Subscribed" , subscribedGroups );
492 conf->sync(); 493 conf->sync();
493 delete conf; 494 delete conf;
494} 495}
495 496
496 497
497QString NNTPaccount::getFileName() 498QString NNTPaccount::getFileName()
498{ 499{
499 return locateLocal("data", "kopiemail" ) +"/nntp-" + file; 500 return locateLocal("data", "kopiemail" ) +"/nntp-" + file;
500} 501}
diff --git a/kmicromail/opiemail.cpp b/kmicromail/opiemail.cpp
index 8d16ae7..af5376f 100644
--- a/kmicromail/opiemail.cpp
+++ b/kmicromail/opiemail.cpp
@@ -1,535 +1,542 @@
1// CHANGED 2004-09-31 Lutz Rogowski 1// CHANGED 2004-09-31 Lutz Rogowski
2// CHANGED 2004-08-06 Lutz Rogowski 2// CHANGED 2004-08-06 Lutz Rogowski
3 3
4#include "koprefsdialog.h" 4#include "koprefsdialog.h"
5#include <kapplication.h> 5#include <kapplication.h>
6#include <libkdepim/externalapphandler.h> 6#include <libkdepim/externalapphandler.h>
7#include <libkdepim/kpimglobalprefs.h> 7#include <libkdepim/kpimglobalprefs.h>
8#ifdef MINIKDE_KDIALOG_H 8#ifdef MINIKDE_KDIALOG_H
9#undef MINIKDE_KDIALOG_H 9#undef MINIKDE_KDIALOG_H
10#endif 10#endif
11#include "settingsdialog.h" 11#include "settingsdialog.h"
12#include "opiemail.h" 12#include "opiemail.h"
13#include "editaccounts.h" 13#include "editaccounts.h"
14#include "composemail.h" 14#include "composemail.h"
15#include "mailistviewitem.h" 15#include "mailistviewitem.h"
16#include "viewmail.h" 16#include "viewmail.h"
17#include "selectstore.h" 17#include "selectstore.h"
18#include "selectsmtp.h" 18#include "selectsmtp.h"
19#include "accountitem.h" 19#include "accountitem.h"
20#include "klocale.h" 20#include "klocale.h"
21 21
22#include <qmessagebox.h> 22#include <qmessagebox.h>
23#include <qtimer.h> 23#include <qtimer.h>
24#include <qcursor.h> 24#include <qcursor.h>
25#include <qregexp.h> 25#include <qregexp.h>
26#include <qpe/global.h>
26 27
27#ifdef DESKTOP_VERSION 28#ifdef DESKTOP_VERSION
28#include <qapplication.h> 29#include <qapplication.h>
29#else 30#else
30#include <qpe/qpeapplication.h> 31#include <qpe/qpeapplication.h>
31#endif 32#endif
32#include <libmailwrapper/smtpwrapper.h> 33#include <libmailwrapper/smtpwrapper.h>
33#include <libmailwrapper/mailtypes.h> 34#include <libmailwrapper/mailtypes.h>
34#include <libmailwrapper/abstractmail.h> 35#include <libmailwrapper/abstractmail.h>
35 36
36//using namespace Opie::Core; 37//using namespace Opie::Core;
37 38
38OpieMail::OpieMail( QWidget *parent, const char *name ) 39OpieMail::OpieMail( QWidget *parent, const char *name )
39 : MainWindow( parent, name) //, WStyle_ContextHelp ) 40 : MainWindow( parent, name) //, WStyle_ContextHelp )
40{ 41{
41 settings = new Settings(); 42 settings = new Settings();
42 43
43 setIcon(SmallIcon( "kmicromail" ) ); 44 setIcon(SmallIcon( "kmicromail" ) );
44 folderView->populate( settings->getAccounts() ); 45 folderView->populate( settings->getAccounts() );
45 46
46} 47}
47 48
48OpieMail::~OpieMail() 49OpieMail::~OpieMail()
49{ 50{
50 if (settings) delete settings; 51 if (settings) delete settings;
51} 52}
52 53
53void OpieMail::appMessage(const QCString &msg, const QByteArray &data) 54void OpieMail::appMessage(const QCString &msg, const QByteArray &data)
54{ 55{
55 56
56} 57}
57#include <stdlib.h> 58#include <stdlib.h>
58void OpieMail::message(const QCString &msg, const QByteArray &data) 59void OpieMail::message(const QCString &msg, const QByteArray &data)
59{ 60{
60 // copied from old mail2 61 // copied from old mail2
61 static int ii = 0; 62 static int ii = 0;
62 //qDebug("QCOP CALL ############################# %d ", ii); 63 //qDebug("QCOP CALL ############################# %d ", ii);
63 //QString mess ( msg ); 64 //QString mess ( msg );
64 //qDebug("Message = %s ",mess.latin1()); 65 //qDebug("Message = %s ",mess.latin1());
65 ++ii; 66 ++ii;
66 //qDebug("KM:appMessage %d *%s* %x", ii, msg.data(), this); 67 //qDebug("KM:appMessage %d *%s* %x", ii, msg.data(), this);
67 68
68 mPendingEmail = QString::null; 69 mPendingEmail = QString::null;
69 mPendingName = QString::null; 70 mPendingName = QString::null;
70 if (msg == "writeMail(QString,QString)") 71 if (msg == "writeMail(QString,QString)")
71 { 72 {
72 //qDebug("writeMail(QString,QString) "); 73 //qDebug("writeMail(QString,QString) ");
73 QDataStream stream(data,IO_ReadOnly); 74 QDataStream stream(data,IO_ReadOnly);
74 stream >> mPendingName >> mPendingEmail; 75 stream >> mPendingName >> mPendingEmail;
75 // removing the whitespaces at beginning and end is needed! 76 // removing the whitespaces at beginning and end is needed!
76 QTimer::singleShot ( 50, this, SLOT(slotComposeMail() ) ); 77 QTimer::singleShot ( 50, this, SLOT(slotComposeMail() ) );
77 } 78 }
78 else if (msg == "newMail()") 79 else if (msg == "newMail()")
79 { 80 {
80 //qDebug("slotComposeMail() "); 81 //qDebug("slotComposeMail() ");
81 // we cannot call slotComposeMail(); directly, because may be executing a QCOP call 82 // we cannot call slotComposeMail(); directly, because may be executing a QCOP call
82 // and a QCOP call does not like a processevents in his execution 83 // and a QCOP call does not like a processevents in his execution
83 // with the Qtimer we call slotComposeMail() after we reached the main event loop 84 // with the Qtimer we call slotComposeMail() after we reached the main event loop
84 QTimer::singleShot ( 50, this, SLOT(slotComposeMail() ) ); 85 QTimer::singleShot ( 50, this, SLOT(slotComposeMail() ) );
85 // slotComposeMail(); 86 // slotComposeMail();
86 } 87 }
87 else if (msg == "newMail(QString)") 88 else if (msg == "newMail(QString)")
88 { 89 {
89 //qDebug(" newMail(QString)"); 90 //qDebug(" newMail(QString)");
90 QDataStream stream(data,IO_ReadOnly); 91 QDataStream stream(data,IO_ReadOnly);
91 stream >> mPendingName; 92 stream >> mPendingName;
92 // the format is 93 // the format is
93 // NAME <EMAIL>:SUBJECT 94 // NAME <EMAIL>:SUBJECT
94 QTimer::singleShot ( 50, this, SLOT(slotComposeMail() ) ); 95 QTimer::singleShot ( 50, this, SLOT(slotComposeMail() ) );
95 } else { 96 } else {
96 mPendingData = data; 97 mPendingData = data;
97 mPendingMessage = msg; 98 mPendingMessage = msg;
98 QTimer::singleShot ( 50, this, SLOT(slotExtAppHandler() ) ); 99 QTimer::singleShot ( 50, this, SLOT(slotExtAppHandler() ) );
99 } 100 }
100 101
101 //qDebug("END OpieMail::message "); 102 //qDebug("END OpieMail::message ");
102} 103}
103void OpieMail::slotExtAppHandler() 104void OpieMail::slotExtAppHandler()
104{ 105{
105 ExternalAppHandler::instance()->appMessage ( mPendingMessage, mPendingData ); 106 ExternalAppHandler::instance()->appMessage ( mPendingMessage, mPendingData );
106} 107}
107void OpieMail::slotwriteMail2(const QString& namemail ) 108void OpieMail::slotwriteMail2(const QString& namemail )
108{ 109{
109 //qDebug("OpieMail::slotwriteMail2 "); 110 //qDebug("OpieMail::slotwriteMail2 ");
110 //qApp->processEvents(); 111 //qApp->processEvents();
111 ComposeMail compose( settings, this, 0, true ); 112 ComposeMail compose( settings, this, 0, true );
112 if ( !namemail.isEmpty() ) { 113 if ( !namemail.isEmpty() ) {
113 QString to = namemail; 114 QString to = namemail;
114 if ( namemail.find( " <") > 1 ) { 115 if ( namemail.find( " <") > 1 ) {
115 to = "\"" +to.replace( QRegExp( " <"), "\" <") ; 116 to = "\"" +to.replace( QRegExp( " <"), "\" <") ;
116 } else 117 } else
117 if ( namemail.find( "<") > 1 ) { 118 if ( namemail.find( "<") > 1 ) {
118 to = "\"" +to.replace( QRegExp( "<"), "\" <") ; 119 to = "\"" +to.replace( QRegExp( "<"), "\" <") ;
119 } 120 }
120 int sub = to.find( ">:"); 121 int sub = to.find( ">:");
121 if ( sub > 0 ) { 122 if ( sub > 0 ) {
122 compose.setTo( to.left(sub+1) ); 123 compose.setTo( to.left(sub+1) );
123 compose.setSubject( to.mid(sub+2) ); 124 compose.setSubject( to.mid(sub+2) );
124 } else 125 } else
125 compose.setTo( to ); 126 compose.setTo( to );
126 } 127 }
127 compose.slotAdjustColumns(); 128 compose.slotAdjustColumns();
128#ifndef DESKTOP_VERSION 129#ifndef DESKTOP_VERSION
129 compose.showMaximized(); 130 compose.showMaximized();
130#endif 131#endif
131 compose.exec(); 132 compose.exec();
132 raise(); 133 raise();
133 //qDebug("retttich "); 134 //qDebug("retttich ");
134} 135}
135void OpieMail::slotwriteMail(const QString&name,const QString&email) 136void OpieMail::slotwriteMail(const QString&name,const QString&email)
136{ 137{
137 // qDebug("OpieMail::slotwriteMail "); 138 // qDebug("OpieMail::slotwriteMail ");
138 ComposeMail compose( settings, this, 0, true ); 139 ComposeMail compose( settings, this, 0, true );
139 if (!email.isEmpty()) 140 if (!email.isEmpty())
140 { 141 {
141 if (!name.isEmpty()) 142 if (!name.isEmpty())
142 { 143 {
143 compose.setTo("\"" + name + "\"" + " " + "<"+ email + ">"); 144 compose.setTo("\"" + name + "\"" + " " + "<"+ email + ">");
144 } 145 }
145 else 146 else
146 { 147 {
147 compose.setTo(email); 148 compose.setTo(email);
148 } 149 }
149 } 150 }
150 compose.slotAdjustColumns(); 151 compose.slotAdjustColumns();
151#ifndef DESKTOP_VERSION 152#ifndef DESKTOP_VERSION
152 compose.showMaximized(); 153 compose.showMaximized();
153#endif 154#endif
154 compose.exec(); 155 compose.exec();
155 raise(); 156 raise();
156} 157}
157 158
158void OpieMail::slotComposeMail() 159void OpieMail::slotComposeMail()
159{ 160{
160 if ( mPendingEmail == QString::null && mPendingName == QString::null) 161 if ( mPendingEmail == QString::null && mPendingName == QString::null)
161 slotwriteMail2( QString () ); 162 slotwriteMail2( QString () );
162 else { 163 else {
163 if ( mPendingEmail == QString::null ) 164 if ( mPendingEmail == QString::null )
164 slotwriteMail2( mPendingName ); 165 slotwriteMail2( mPendingName );
165 else 166 else
166 slotwriteMail( mPendingName, mPendingEmail ); 167 slotwriteMail( mPendingName, mPendingEmail );
167 } 168 }
168 //slotwriteMail(0l,0l); 169 //slotwriteMail(0l,0l);
169} 170}
170 171
171void OpieMail::slotSendQueued() 172void OpieMail::slotSendQueued()
172{ 173{
173 SMTPaccount *smtp = 0; 174 SMTPaccount *smtp = 0;
174 175
175 QList<Account> list = settings->getAccounts(); 176 QList<Account> list = settings->getAccounts();
176 QList<SMTPaccount> smtpList; 177 QList<SMTPaccount> smtpList;
177 smtpList.setAutoDelete(false); 178 smtpList.setAutoDelete(false);
178 Account *it; 179 Account *it;
179 for ( it = list.first(); it; it = list.next() ) 180 for ( it = list.first(); it; it = list.next() )
180 { 181 {
181 if ( it->getType() == MAILLIB::A_SMTP ) 182 if ( it->getType() == MAILLIB::A_SMTP )
182 { 183 {
183 smtp = static_cast<SMTPaccount *>(it); 184 smtp = static_cast<SMTPaccount *>(it);
184 smtpList.append(smtp); 185 smtpList.append(smtp);
185 } 186 }
186 } 187 }
187 if (smtpList.count()==0) 188 if (smtpList.count()==0)
188 { 189 {
189 QMessageBox::information(0,i18n("Info"),i18n("Define a smtp account first!\n")); 190 QMessageBox::information(0,i18n("Info"),i18n("Define a smtp account first!\n"));
190 return; 191 return;
191 } 192 }
193 if ( QMessageBox::warning(this, i18n("Sending all mails"), i18n("Do you really want to send\nall queued mails?" ) , QMessageBox::Yes, QMessageBox::No ) == QMessageBox::No )
194 return;
192 if (smtpList.count()==1) 195 if (smtpList.count()==1)
193 { 196 {
194 smtp = smtpList.at(0); 197 smtp = smtpList.at(0);
195 } 198 }
196 else 199 else
197 { 200 {
198 smtp = 0; 201 smtp = 0;
199 selectsmtp selsmtp; 202 selectsmtp selsmtp;
200 selsmtp.setSelectionlist(&smtpList); 203 selsmtp.setSelectionlist(&smtpList);
201#ifndef DESKTOP_VERSION 204#ifndef DESKTOP_VERSION
202 selsmtp.showMaximized(); 205 selsmtp.showMaximized();
203#endif 206#endif
204 if ( selsmtp.exec() == QDialog::Accepted ) 207 if ( selsmtp.exec() == QDialog::Accepted )
205 { 208 {
206 smtp = selsmtp.selected_smtp(); 209 smtp = selsmtp.selected_smtp();
207 } 210 }
208 } 211 }
209 if (smtp) 212 if (smtp)
210 { 213 {
214
215 Global::statusMessage("Sending mails...!");
211 SMTPwrapper * wrap = new SMTPwrapper(smtp); 216 SMTPwrapper * wrap = new SMTPwrapper(smtp);
212 if ( wrap->flushOutbox() ) 217 if ( wrap->flushOutbox() )
213 { 218 {
214 QMessageBox::information(0,i18n("Info"),i18n("Mail queue flushed")); 219 Global::statusMessage("Mails sent!");
215 } 220 }
216 delete wrap; 221 delete wrap;
217 } 222 }
223 // pending refresh list view, if outgoing is displayed
218} 224}
219 225
220void OpieMail::slotSearchMails() 226void OpieMail::slotSearchMails()
221{ 227{
222 qDebug("OpieMail::slotSearchMails():not implemented "); 228 qDebug("OpieMail::slotSearchMails():not implemented ");
223} 229}
224 230
225void OpieMail::slotEditSettings() 231void OpieMail::slotEditSettings()
226{ 232{
227 233
228 KOPrefsDialog settingsDialog( this, "koprefs", true ); 234 KOPrefsDialog settingsDialog( this, "koprefs", true );
229#ifndef DESKTOP_VERSION 235#ifndef DESKTOP_VERSION
230 settingsDialog.showMaximized(); 236 settingsDialog.showMaximized();
231#endif 237#endif
232 settingsDialog.exec(); 238 settingsDialog.exec();
233 239
234 // KApplication::execDialog(settingsDialog); 240 // KApplication::execDialog(settingsDialog);
235} 241}
236 242
237void OpieMail::slotEditAccounts() 243void OpieMail::slotEditAccounts()
238{ 244{
239 EditAccounts eaDialog( settings, this, 0, true ); 245 EditAccounts eaDialog( settings, this, 0, true );
240 eaDialog.slotAdjustColumns(); 246 eaDialog.slotAdjustColumns();
241#ifndef DESKTOP_VERSION 247#ifndef DESKTOP_VERSION
242 eaDialog.showMaximized(); 248 eaDialog.showMaximized();
243#endif 249#endif
244 eaDialog.exec(); 250 eaDialog.exec();
245 if ( settings ) delete settings; 251 if ( settings ) delete settings;
246 settings = new Settings(); 252 settings = new Settings();
247 253
248 folderView->populate( settings->getAccounts() ); 254 folderView->populate( settings->getAccounts() );
249} 255}
250void OpieMail::replyMail() 256void OpieMail::replyMail()
251{ 257{
252 258
253 QListViewItem*item = mailView->currentItem(); 259 QListViewItem*item = mailView->currentItem();
254 if (!item) return; 260 if (!item) return;
255 RecMailP mail = ((MailListViewItem*)item)->data(); 261 RecMailP mail = ((MailListViewItem*)item)->data();
256 RecBodyP body = folderView->fetchBody(mail); 262 RecBodyP body = folderView->fetchBody(mail);
257 263
258 QString rtext; 264 QString rtext;
259 rtext += QString("* %1 wrote on %2:\n") // no i18n on purpose 265 rtext += QString("* %1 wrote on %2:\n") // no i18n on purpose
260 .arg( QString::fromUtf8( mail->getFrom().latin1())) 266 .arg( QString::fromUtf8( mail->getFrom().latin1()))
261 .arg( QString::fromUtf8( mail->getDate().latin1() )); 267 .arg( QString::fromUtf8( mail->getDate().latin1() ));
262 268
263 QString text = QString::fromUtf8( body->Bodytext().latin1() ); 269 QString text = QString::fromUtf8( body->Bodytext().latin1() );
264 QStringList lines = QStringList::split(QRegExp("\\n"), text); 270 QStringList lines = QStringList::split(QRegExp("\\n"), text);
265 QStringList::Iterator it; 271 QStringList::Iterator it;
266 for (it = lines.begin(); it != lines.end(); it++) 272 for (it = lines.begin(); it != lines.end(); it++)
267 { 273 {
268 rtext += "> " + *it + "\n"; 274 rtext += "> " + *it + "\n";
269 } 275 }
270 rtext += "\n"; 276 rtext += "\n";
271 277
272 QString prefix; 278 QString prefix;
273 if ( mail->getSubject().find(QRegExp("^Re: .*$")) != -1) prefix = ""; 279 if ( mail->getSubject().find(QRegExp("^Re: .*$")) != -1) prefix = "";
274 else prefix = "Re: "; // no i18n on purpose 280 else prefix = "Re: "; // no i18n on purpose
275 281
276 Settings *settings = new Settings(); 282 Settings *settings = new Settings();
277 ComposeMail composer( settings ,this, 0, true); 283 ComposeMail composer( settings ,this, 0, true);
278 if (mail->Replyto().isEmpty()) { 284 if (mail->Replyto().isEmpty()) {
279 composer.setTo( QString::fromUtf8( mail->getFrom().latin1())); 285 composer.setTo( QString::fromUtf8( mail->getFrom().latin1()));
280 } else { 286 } else {
281 composer.setTo( QString::fromUtf8(mail->Replyto().latin1())); 287 composer.setTo( QString::fromUtf8(mail->Replyto().latin1()));
282 } 288 }
283 composer.setSubject( prefix + QString::fromUtf8( mail->getSubject().latin1() ) ); 289 composer.setSubject( prefix + QString::fromUtf8( mail->getSubject().latin1() ) );
284 composer.setMessage( rtext ); 290 composer.setMessage( rtext );
285 composer.setInReplyTo( QString::fromUtf8(mail->Msgid().latin1())); 291 composer.setInReplyTo( QString::fromUtf8(mail->Msgid().latin1()));
286 292
287 if ( QDialog::Accepted == KApplication::execDialog( &composer ) ) 293 if ( QDialog::Accepted == KApplication::execDialog( &composer ) )
288 { 294 {
289 mail->Wrapper()->answeredMail(mail); 295 mail->Wrapper()->answeredMail(mail);
290 } 296 }
291 delete settings; 297 delete settings;
292 298
293} 299}
294void OpieMail::displayMail() 300void OpieMail::displayMail()
295{ 301{
296 QListViewItem*item = mailView->currentItem(); 302 QListViewItem*item = mailView->currentItem();
297 if (!item) return; 303 if (!item) return;
298 RecMailP mail = ((MailListViewItem*)item)->data(); 304 RecMailP mail = ((MailListViewItem*)item)->data();
299 RecBodyP body = folderView->fetchBody(mail); 305 RecBodyP body = folderView->fetchBody(mail);
300 ViewMail readMail( this,"", Qt::WType_Modal ); 306 ViewMail readMail( this,"", Qt::WType_Modal );
301 readMail.setBody( body ); 307 readMail.setBody( body );
302 readMail.setMail( mail ); 308 readMail.setMail( mail );
303#ifndef DESKTOP_VERSION 309#ifndef DESKTOP_VERSION
304 readMail.showMaximized(); 310 readMail.showMaximized();
305#else 311#else
306 readMail.resize( 640, 480); 312 readMail.resize( 640, 480);
307#endif 313#endif
308 readMail.exec(); 314 readMail.exec();
309 315
310 if ( readMail.deleted ) 316 if ( readMail.deleted )
311 { 317 {
312 folderView->refreshCurrent(); 318 folderView->refreshCurrent();
313 } 319 }
314 else 320 else
315 { 321 {
316 ( (MailListViewItem*)item )->setPixmap( 0, QPixmap() ); 322 ( (MailListViewItem*)item )->setPixmap( 0, QPixmap() );
317 } 323 }
318} 324}
319void OpieMail::slotGetAllMail() 325void OpieMail::slotGetAllMail()
320{ 326{
321 QListViewItem * item = folderView->firstChild(); 327 QListViewItem * item = folderView->firstChild();
322 while ( item ){ 328 while ( item ){
323 ((AccountViewItem *)item)->contextMenuSelected( 101 ); 329 ((AccountViewItem *)item)->contextMenuSelected( 101 );
324 item = item->nextSibling (); 330 item = item->nextSibling ();
325 } 331 }
326} 332}
327void OpieMail::slotGetMail() 333void OpieMail::slotGetMail()
328{ 334{
329 QListViewItem * item = folderView->currentItem(); 335 QListViewItem * item = folderView->currentItem();
330 if ( ! item ) return; 336 if ( ! item ) return;
331 ((AccountViewItem *)item)->contextMenuSelected( 101 ); 337 ((AccountViewItem *)item)->contextMenuSelected( 101 );
332} 338}
333void OpieMail::slotDeleteMail() 339void OpieMail::slotDeleteMail()
334{ 340{
335 if (!mailView->currentItem()) return; 341 if (!mailView->currentItem()) return;
336 RecMailP mail = ((MailListViewItem*)mailView->currentItem() )->data(); 342 RecMailP mail = ((MailListViewItem*)mailView->currentItem() )->data();
337 if ( QMessageBox::warning(this, i18n("Delete Mail"), QString( i18n("<p>Do you really want to delete this mail? <br><br>" ) + mail->getFrom() + " - " + mail->getSubject() ) , QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes ) 343 if ( QMessageBox::warning(this, i18n("Delete Mail"), QString( i18n("<p>Do you really want to delete this mail? <br><br>" ) + mail->getFrom() + " - " + mail->getSubject() ) , QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes )
338 { 344 {
339 mail->Wrapper()->deleteMail( mail ); 345 mail->Wrapper()->deleteMail( mail );
340 folderView->refreshCurrent(); 346 folderView->refreshCurrent();
341 } 347 }
342} 348}
343void OpieMail::slotDeleteAllMail() 349void OpieMail::slotDeleteAllMail()
344{ 350{
345 351
346 QValueList<RecMailP> t; 352 QValueList<RecMailP> t;
347 if ( QMessageBox::warning(this, i18n("Delete All Mails"), i18n("Do you really want to delete\nall selected mails?" ) , QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes ) 353 if ( QMessageBox::warning(this, i18n("Delete All Mails"), i18n("Do you really want to delete\nall selected mails?" ) , QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes )
348 { 354 {
349 MailListViewItem* item = (MailListViewItem*)mailView->firstChild (); 355 MailListViewItem* item = (MailListViewItem*)mailView->firstChild ();
350 while ( item ) { 356 while ( item ) {
351 if ( item->isSelected() ) { 357 if ( item->isSelected() ) {
352 t.append( item->data() ); 358 t.append( item->data() );
353 } 359 }
354 item = (MailListViewItem*)item->nextSibling(); 360 item = (MailListViewItem*)item->nextSibling();
355 } 361 }
356 } 362 }
357 else 363 else
358 return; 364 return;
359 if ( t.count() == 0 ) 365 if ( t.count() == 0 )
360 return; 366 return;
361 RecMailP mail = t.first(); 367 RecMailP mail = t.first();
362 mail->Wrapper()->deleteMailList(t); 368 mail->Wrapper()->deleteMailList(t);
363 folderView->refreshCurrent(); 369 folderView->refreshCurrent();
364 370
365 371
366} 372}
367void OpieMail::clearSelection() 373void OpieMail::clearSelection()
368{ 374{
369 mailView->clearSelection(); 375 mailView->clearSelection();
370 376
371} 377}
372 378
373void OpieMail::mailHold(int button, QListViewItem *item,const QPoint&,int ) 379void OpieMail::mailHold(int button, QListViewItem *item,const QPoint&,int )
374{ 380{
375 if (!mailView->currentItem()) return; 381 if (!mailView->currentItem()) return;
376 MAILLIB::ATYPE mailtype = ((MailListViewItem*)mailView->currentItem() )->wrapperType(); 382 MAILLIB::ATYPE mailtype = ((MailListViewItem*)mailView->currentItem() )->wrapperType();
377 /* just the RIGHT button - or hold on pda */ 383 /* just the RIGHT button - or hold on pda */
378 if (button!=2) {return;} 384 if (button!=2) {return;}
379 if (!item) return; 385 if (!item) return;
380 QPopupMenu *m = new QPopupMenu(0); 386 QPopupMenu *m = new QPopupMenu(0);
381 if (m) 387 if (m)
382 { 388 {
383 if (mailtype==MAILLIB::A_NNTP) { 389 if (mailtype==MAILLIB::A_NNTP) {
384 m->insertItem(i18n("Read this posting"),this,SLOT(displayMail())); 390 m->insertItem(i18n("Read this posting"),this,SLOT(displayMail()));
385 m->insertItem(i18n("Copy this posting"),this,SLOT(slotMoveCopyMail())); 391 m->insertItem(i18n("Copy this posting"),this,SLOT(slotMoveCopyMail()));
386 m->insertSeparator(); 392 m->insertSeparator();
387 m->insertItem(i18n("Copy all selected postings"),this,SLOT(slotMoveCopyAllMail())); 393 m->insertItem(i18n("Copy all selected postings"),this,SLOT(slotMoveCopyAllMail()));
388 m->insertItem(i18n("Clear selection"),this,SLOT(clearSelection())); 394 m->insertItem(i18n("Clear selection"),this,SLOT(clearSelection()));
389 } else { 395 } else {
390 if (folderView->currentisDraft()) { 396 if (folderView->currentisDraft()) {
391 m->insertItem(i18n("Edit this mail"),this,SLOT(reEditMail())); 397 m->insertItem(i18n("Edit this mail"),this,SLOT(reEditMail()));
392 } 398 }
393 m->insertItem(i18n("Reply to this mail"),this,SLOT(replyMail())); 399 m->insertItem(i18n("Reply to this mail"),this,SLOT(replyMail()));
394 m->insertSeparator(); 400 m->insertSeparator();
395 m->insertItem(i18n("Read this mail"),this,SLOT(displayMail())); 401 m->insertItem(i18n("Read this mail"),this,SLOT(displayMail()));
396 m->insertItem(i18n("Move/Copy this mail"),this,SLOT(slotMoveCopyMail())); 402 m->insertItem(i18n("Move/Copy this mail"),this,SLOT(slotMoveCopyMail()));
397 m->insertItem(i18n("Delete this mail"),this,SLOT(slotDeleteMail())); 403 m->insertItem(i18n("Delete this mail"),this,SLOT(slotDeleteMail()));
398 m->insertSeparator(); 404 m->insertSeparator();
399 m->insertItem(i18n("Move/Copy all selected mail"),this,SLOT(slotMoveCopyAllMail())); 405 m->insertItem(i18n("Move/Copy all selected mail"),this,SLOT(slotMoveCopyAllMail()));
400 m->insertItem(i18n("Delete all selected mails"),this,SLOT(slotDeleteAllMail())); 406 m->insertItem(i18n("Delete all selected mails"),this,SLOT(slotDeleteAllMail()));
401 m->insertItem(i18n("Clear selection"),this,SLOT(clearSelection())); 407 m->insertItem(i18n("Clear selection"),this,SLOT(clearSelection()));
402 } 408 }
403 m->setFocus(); 409 m->setFocus();
404 m->exec( QPoint( QCursor::pos().x(), QCursor::pos().y()) ); 410 m->exec( QPoint( QCursor::pos().x(), QCursor::pos().y()) );
405 delete m; 411 delete m;
406 } 412 }
407} 413}
408 414
409void OpieMail::slotShowFolders( bool show ) 415void OpieMail::slotShowFolders( bool show )
410{ 416{
411 if ( show && folderView->isHidden() ) 417 if ( show && folderView->isHidden() )
412 { 418 {
413 folderView->show(); 419 folderView->show();
414 } 420 }
415 else if ( !show && !folderView->isHidden() ) 421 else if ( !show && !folderView->isHidden() )
416 { 422 {
417 folderView->hide(); 423 folderView->hide();
418 } 424 }
419} 425}
420 426
421void OpieMail::refreshMailView(const QValueList<RecMailP>&list) 427void OpieMail::refreshMailView(const QValueList<RecMailP>&list)
422{ 428{
423 MailListViewItem*item = 0; 429 MailListViewItem*item = 0;
424 mailView->clear(); 430 mailView->clear();
425 431
426 QValueList<RecMailP>::ConstIterator it; 432 QValueList<RecMailP>::ConstIterator it;
427 for (it = list.begin(); it != list.end();++it) 433 for (it = list.begin(); it != list.end();++it)
428 { 434 {
429 item = new MailListViewItem(mailView,item); 435 item = new MailListViewItem(mailView,item);
430 item->storeData((*it)); 436 item->storeData((*it));
431 item->showEntry(); 437 item->showEntry();
432 } 438 }
439 mailView->setSorting ( 4, false );
433} 440}
434 441
435void OpieMail::mailLeftClicked( QListViewItem *item ) 442void OpieMail::mailLeftClicked( QListViewItem *item )
436{ 443{
437 mailView->clearSelection(); 444 mailView->clearSelection();
438 /* just LEFT button - or tap with stylus on pda */ 445 /* just LEFT button - or tap with stylus on pda */
439 //if (button!=1) return; 446 //if (button!=1) return;
440 if (!item) return; 447 if (!item) return;
441 if (folderView->currentisDraft()) { 448 if (folderView->currentisDraft()) {
442 reEditMail(); 449 reEditMail();
443 } else { 450 } else {
444 displayMail(); 451 displayMail();
445 } 452 }
446} 453}
447 454
448void OpieMail::slotMoveCopyMail() 455void OpieMail::slotMoveCopyMail()
449{ 456{
450 if (!mailView->currentItem()) return; 457 if (!mailView->currentItem()) return;
451 RecMailP mail = ((MailListViewItem*)mailView->currentItem() )->data(); 458 RecMailP mail = ((MailListViewItem*)mailView->currentItem() )->data();
452 AbstractMail*targetMail = 0; 459 AbstractMail*targetMail = 0;
453 QString targetFolder = ""; 460 QString targetFolder = "";
454 Selectstore sels; 461 Selectstore sels;
455 folderView->setupFolderselect(&sels); 462 folderView->setupFolderselect(&sels);
456 if (!sels.exec()) return; 463 if (!sels.exec()) return;
457 targetMail = sels.currentMail(); 464 targetMail = sels.currentMail();
458 targetFolder = sels.currentFolder(); 465 targetFolder = sels.currentFolder();
459 if ( (mail->Wrapper()==targetMail && mail->getMbox()==targetFolder) || 466 if ( (mail->Wrapper()==targetMail && mail->getMbox()==targetFolder) ||
460 targetFolder.isEmpty()) 467 targetFolder.isEmpty())
461 { 468 {
462 return; 469 return;
463 } 470 }
464 if (sels.newFolder() && !targetMail->createMbox(targetFolder)) 471 if (sels.newFolder() && !targetMail->createMbox(targetFolder))
465 { 472 {
466 QMessageBox::critical(0,i18n("Error creating new Folder"), 473 QMessageBox::critical(0,i18n("Error creating new Folder"),
467 i18n("<center>Error while creating<br>new folder - breaking.</center>")); 474 i18n("<center>Error while creating<br>new folder - breaking.</center>"));
468 return; 475 return;
469 } 476 }
470 sels.hide(); 477 sels.hide();
471 qApp->processEvents(); 478 qApp->processEvents();
472 // qDebug("hiding sels "); 479 // qDebug("hiding sels ");
473 mail->Wrapper()->mvcpMail(mail,targetFolder,targetMail,sels.moveMails()); 480 mail->Wrapper()->mvcpMail(mail,targetFolder,targetMail,sels.moveMails());
474 folderView->refreshCurrent(); 481 folderView->refreshCurrent();
475} 482}
476 483
477void OpieMail::slotMoveCopyAllMail() 484void OpieMail::slotMoveCopyAllMail()
478{ 485{
479 486
480 if (!mailView->currentItem()) return; 487 if (!mailView->currentItem()) return;
481 QValueList<RecMailP> t; 488 QValueList<RecMailP> t;
482 // if ( QMessageBox::warning(this, i18n("Move/Copy all selected mails"), i18n("Do you really want to copy/move\nall selected mails?" ) , QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes ) 489 // if ( QMessageBox::warning(this, i18n("Move/Copy all selected mails"), i18n("Do you really want to copy/move\nall selected mails?" ) , QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes )
483 { 490 {
484 MailListViewItem* item = (MailListViewItem*)mailView->firstChild (); 491 MailListViewItem* item = (MailListViewItem*)mailView->firstChild ();
485 while ( item ) { 492 while ( item ) {
486 if ( item->isSelected() ) { 493 if ( item->isSelected() ) {
487 t.append( item->data() ); 494 t.append( item->data() );
488 } 495 }
489 item = (MailListViewItem*)item->nextSibling(); 496 item = (MailListViewItem*)item->nextSibling();
490 } 497 }
491 } 498 }
492 // else 499 // else
493 // return; 500 // return;
494 if ( t.count() == 0 ) 501 if ( t.count() == 0 )
495 return; 502 return;
496 RecMailP mail = t.first(); 503 RecMailP mail = t.first();
497 AbstractMail*targetMail = 0; 504 AbstractMail*targetMail = 0;
498 QString targetFolder = ""; 505 QString targetFolder = "";
499 Selectstore sels; 506 Selectstore sels;
500 folderView->setupFolderselect(&sels); 507 folderView->setupFolderselect(&sels);
501 if (!sels.exec()) return; 508 if (!sels.exec()) return;
502 targetMail = sels.currentMail(); 509 targetMail = sels.currentMail();
503 targetFolder = sels.currentFolder(); 510 targetFolder = sels.currentFolder();
504 if ( (mail->Wrapper()==targetMail && mail->getMbox()==targetFolder) || 511 if ( (mail->Wrapper()==targetMail && mail->getMbox()==targetFolder) ||
505 targetFolder.isEmpty()) 512 targetFolder.isEmpty())
506 { 513 {
507 return; 514 return;
508 } 515 }
509 if (sels.newFolder() && !targetMail->createMbox(targetFolder)) 516 if (sels.newFolder() && !targetMail->createMbox(targetFolder))
510 { 517 {
511 QMessageBox::critical(0,i18n("Error creating new Folder"), 518 QMessageBox::critical(0,i18n("Error creating new Folder"),
512 i18n("<center>Error while creating<br>new folder - breaking.</center>")); 519 i18n("<center>Error while creating<br>new folder - breaking.</center>"));
513 return; 520 return;
514 } 521 }
515 sels.hide(); 522 sels.hide();
516 qApp->processEvents(); 523 qApp->processEvents();
517 //qDebug("hiding sels "); 524 //qDebug("hiding sels ");
518 mail->Wrapper()->mvcpMailList(t,targetFolder,targetMail,sels.moveMails()); 525 mail->Wrapper()->mvcpMailList(t,targetFolder,targetMail,sels.moveMails());
519 folderView->refreshCurrent(); 526 folderView->refreshCurrent();
520} 527}
521 528
522void OpieMail::reEditMail() 529void OpieMail::reEditMail()
523{ 530{
524 if (!mailView->currentItem()) return; 531 if (!mailView->currentItem()) return;
525 532
526 ComposeMail compose( settings, this, 0, true ); 533 ComposeMail compose( settings, this, 0, true );
527 compose.reEditMail(((MailListViewItem*)mailView->currentItem() )->data()); 534 compose.reEditMail(((MailListViewItem*)mailView->currentItem() )->data());
528 compose.slotAdjustColumns(); 535 compose.slotAdjustColumns();
529#ifndef DESKTOP_VERSION 536#ifndef DESKTOP_VERSION
530 compose.showMaximized(); 537 compose.showMaximized();
531#else 538#else
532 compose.resize(640,480); 539 compose.resize(640,480);
533#endif 540#endif
534 compose.exec(); 541 compose.exec();
535} 542}