summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kmicromail/libetpan/generic/pop3driver.c9
-rw-r--r--kmicromail/libetpan/pop3/mailpop3.c5
-rw-r--r--kmicromail/libetpan/tools/mailstream_helper.c11
3 files changed, 19 insertions, 6 deletions
diff --git a/kmicromail/libetpan/generic/pop3driver.c b/kmicromail/libetpan/generic/pop3driver.c
index 375879e..475dfcc 100644
--- a/kmicromail/libetpan/generic/pop3driver.c
+++ b/kmicromail/libetpan/generic/pop3driver.c
@@ -209,132 +209,135 @@ static int pop3driver_starttls(mailsession * session)
209 return pop3driver_pop3_error_to_mail_error(r); 209 return pop3driver_pop3_error_to_mail_error(r);
210 } 210 }
211 211
212 low = mailstream_get_low(pop3->pop3_stream); 212 low = mailstream_get_low(pop3->pop3_stream);
213 fd = mailstream_low_get_fd(low); 213 fd = mailstream_low_get_fd(low);
214 if (fd == -1) 214 if (fd == -1)
215 return MAIL_ERROR_STREAM; 215 return MAIL_ERROR_STREAM;
216 216
217 new_low = mailstream_low_ssl_open(fd); 217 new_low = mailstream_low_ssl_open(fd);
218 if (new_low == NULL) 218 if (new_low == NULL)
219 return MAIL_ERROR_STREAM; 219 return MAIL_ERROR_STREAM;
220 mailstream_low_free(low); 220 mailstream_low_free(low);
221 mailstream_set_low(pop3->pop3_stream, new_low); 221 mailstream_set_low(pop3->pop3_stream, new_low);
222 222
223 return MAIL_NO_ERROR; 223 return MAIL_NO_ERROR;
224} 224}
225 225
226static int pop3driver_parameters(mailsession * session, 226static int pop3driver_parameters(mailsession * session,
227 int id, void * value) 227 int id, void * value)
228{ 228{
229 struct pop3_session_state_data * data; 229 struct pop3_session_state_data * data;
230 230
231 data = get_data(session); 231 data = get_data(session);
232 232
233 switch (id) { 233 switch (id) {
234 case POP3DRIVER_SET_AUTH_TYPE: 234 case POP3DRIVER_SET_AUTH_TYPE:
235 { 235 {
236 int * param; 236 int * param;
237 237
238 param = value; 238 param = value;
239 239
240 data->pop3_auth_type = * param; 240 data->pop3_auth_type = * param;
241 return MAIL_NO_ERROR; 241 return MAIL_NO_ERROR;
242 } 242 }
243 } 243 }
244 244
245 return MAIL_ERROR_INVAL; 245 return MAIL_ERROR_INVAL;
246} 246}
247 247
248static int pop3driver_login(mailsession * session, 248static int pop3driver_login(mailsession * session,
249 char * userid, char * password) 249 char * userid, char * password)
250{ 250{
251 int r; 251 int r;
252 carray * msg_tab; 252 carray * msg_tab;
253 struct pop3_session_state_data * data; 253 struct pop3_session_state_data * data;
254 254
255 data = get_data(session); 255 data = get_data(session);
256 256
257 switch (data->pop3_auth_type) { 257 switch (data->pop3_auth_type) {
258 case POP3DRIVER_AUTH_TYPE_TRY_APOP: 258 case POP3DRIVER_AUTH_TYPE_TRY_APOP:
259 r = mailpop3_login_apop(get_pop3_session(session), userid, password); 259 r = mailpop3_login_apop(get_pop3_session(session), userid, password);
260 if (r != MAILPOP3_NO_ERROR) 260 if (r != MAILPOP3_NO_ERROR)
261 r = mailpop3_login(get_pop3_session(session), userid, password); 261 r = mailpop3_login(get_pop3_session(session), userid, password);
262 break; 262 break;
263 263
264 case POP3DRIVER_AUTH_TYPE_APOP: 264 case POP3DRIVER_AUTH_TYPE_APOP:
265 r = mailpop3_login_apop(get_pop3_session(session), userid, password); 265 r = mailpop3_login_apop(get_pop3_session(session), userid, password);
266 break; 266 break;
267 267
268 default: 268 default:
269 case POP3DRIVER_AUTH_TYPE_PLAIN: 269 case POP3DRIVER_AUTH_TYPE_PLAIN:
270 r = mailpop3_login(get_pop3_session(session), userid, password); 270 r = mailpop3_login(get_pop3_session(session), userid, password);
271 break; 271 break;
272 } 272 }
273 // LR 2 lines
274 int ret = pop3driver_pop3_error_to_mail_error(r);
275 if ( ret == MAIL_NO_ERROR )
276 mailpop3_list(get_pop3_session(session), &msg_tab);
273 277
274 mailpop3_list(get_pop3_session(session), &msg_tab); 278 // LR
275 279 return ret;
276 return pop3driver_pop3_error_to_mail_error(r);
277} 280}
278 281
279static int pop3driver_logout(mailsession * session) 282static int pop3driver_logout(mailsession * session)
280{ 283{
281 int r; 284 int r;
282 285
283 r = mailpop3_quit(get_pop3_session(session)); 286 r = mailpop3_quit(get_pop3_session(session));
284 287
285 return pop3driver_pop3_error_to_mail_error(r); 288 return pop3driver_pop3_error_to_mail_error(r);
286} 289}
287 290
288static int pop3driver_noop(mailsession * session) 291static int pop3driver_noop(mailsession * session)
289{ 292{
290 int r; 293 int r;
291 294
292 r = mailpop3_noop(get_pop3_session(session)); 295 r = mailpop3_noop(get_pop3_session(session));
293 296
294 return pop3driver_pop3_error_to_mail_error(r); 297 return pop3driver_pop3_error_to_mail_error(r);
295} 298}
296 299
297static int pop3driver_status_folder(mailsession * session, char * mb, 300static int pop3driver_status_folder(mailsession * session, char * mb,
298 uint32_t * result_messages, 301 uint32_t * result_messages,
299 uint32_t * result_recent, 302 uint32_t * result_recent,
300 uint32_t * result_unseen) 303 uint32_t * result_unseen)
301{ 304{
302 uint32_t count; 305 uint32_t count;
303 int r; 306 int r;
304 307
305 r = pop3driver_messages_number(session, mb, &count); 308 r = pop3driver_messages_number(session, mb, &count);
306 if (r != MAIL_NO_ERROR) 309 if (r != MAIL_NO_ERROR)
307 return r; 310 return r;
308 311
309 * result_messages = count; 312 * result_messages = count;
310 * result_recent = count; 313 * result_recent = count;
311 * result_unseen = count; 314 * result_unseen = count;
312 315
313 return MAIL_NO_ERROR; 316 return MAIL_NO_ERROR;
314} 317}
315 318
316static int pop3driver_messages_number(mailsession * session, char * mb, 319static int pop3driver_messages_number(mailsession * session, char * mb,
317 uint32_t * result) 320 uint32_t * result)
318{ 321{
319 carray * msg_tab; 322 carray * msg_tab;
320 323
321 mailpop3_list(get_pop3_session(session), &msg_tab); 324 mailpop3_list(get_pop3_session(session), &msg_tab);
322 325
323 * result = carray_count(msg_tab) - 326 * result = carray_count(msg_tab) -
324 get_pop3_session(session)->pop3_deleted_count; 327 get_pop3_session(session)->pop3_deleted_count;
325 328
326 return MAIL_NO_ERROR; 329 return MAIL_NO_ERROR;
327} 330}
328 331
329 332
330/* messages operations */ 333/* messages operations */
331 334
332static int pop3driver_remove_message(mailsession * session, uint32_t num) 335static int pop3driver_remove_message(mailsession * session, uint32_t num)
333{ 336{
334 mailpop3 * pop3; 337 mailpop3 * pop3;
335 int r; 338 int r;
336 339
337 pop3 = get_pop3_session(session); 340 pop3 = get_pop3_session(session);
338 341
339 r = mailpop3_dele(pop3, num); 342 r = mailpop3_dele(pop3, num);
340 switch (r) { 343 switch (r) {
diff --git a/kmicromail/libetpan/pop3/mailpop3.c b/kmicromail/libetpan/pop3/mailpop3.c
index 28fafe9..691b07a 100644
--- a/kmicromail/libetpan/pop3/mailpop3.c
+++ b/kmicromail/libetpan/pop3/mailpop3.c
@@ -447,130 +447,133 @@ int mailpop3_apop(mailpop3 * f,
447 if (r == -1) 447 if (r == -1)
448 return MAILPOP3_ERROR_STREAM; 448 return MAILPOP3_ERROR_STREAM;
449 449
450 response = read_line(f); 450 response = read_line(f);
451 451
452 if (response == NULL) 452 if (response == NULL)
453 return MAILPOP3_ERROR_STREAM; 453 return MAILPOP3_ERROR_STREAM;
454 r = parse_response(f, response); 454 r = parse_response(f, response);
455 if (r != RESPONSE_OK) 455 if (r != RESPONSE_OK)
456 return MAILPOP3_ERROR_DENIED; 456 return MAILPOP3_ERROR_DENIED;
457 457
458 f->pop3_state = POP3_STATE_TRANSACTION; 458 f->pop3_state = POP3_STATE_TRANSACTION;
459 459
460 return MAILPOP3_NO_ERROR; 460 return MAILPOP3_NO_ERROR;
461} 461}
462 462
463int mailpop3_user(mailpop3 * f, const char * user) 463int mailpop3_user(mailpop3 * f, const char * user)
464{ 464{
465 char command[POP3_STRING_SIZE]; 465 char command[POP3_STRING_SIZE];
466 int r; 466 int r;
467 char * response; 467 char * response;
468 468
469 if (f->pop3_state != POP3_STATE_AUTHORIZATION) 469 if (f->pop3_state != POP3_STATE_AUTHORIZATION)
470 return MAILPOP3_ERROR_BAD_STATE; 470 return MAILPOP3_ERROR_BAD_STATE;
471 471
472 /* send user command */ 472 /* send user command */
473 473
474 snprintf(command, POP3_STRING_SIZE, "USER %s\r\n", user); 474 snprintf(command, POP3_STRING_SIZE, "USER %s\r\n", user);
475 r = send_command(f, command); 475 r = send_command(f, command);
476 if (r == -1) 476 if (r == -1)
477 return MAILPOP3_ERROR_STREAM; 477 return MAILPOP3_ERROR_STREAM;
478 478
479 response = read_line(f); 479 response = read_line(f);
480 if (response == NULL) 480 if (response == NULL)
481 return MAILPOP3_ERROR_STREAM; 481 return MAILPOP3_ERROR_STREAM;
482 r = parse_response(f, response); 482 r = parse_response(f, response);
483 483
484 if (r != RESPONSE_OK) 484 if (r != RESPONSE_OK)
485 return MAILPOP3_ERROR_BAD_USER; 485 return MAILPOP3_ERROR_BAD_USER;
486 486
487 return MAILPOP3_NO_ERROR; 487 return MAILPOP3_NO_ERROR;
488} 488}
489 489
490int mailpop3_pass(mailpop3 * f, const char * password) 490int mailpop3_pass(mailpop3 * f, const char * password)
491{ 491{
492 char command[POP3_STRING_SIZE]; 492 char command[POP3_STRING_SIZE];
493 int r; 493 int r;
494 char * response; 494 char * response;
495 495
496 if (f->pop3_state != POP3_STATE_AUTHORIZATION) 496 if (f->pop3_state != POP3_STATE_AUTHORIZATION)
497 return MAILPOP3_ERROR_BAD_STATE; 497 return MAILPOP3_ERROR_BAD_STATE;
498 498
499 /* send password command */ 499 /* send password command */
500 500
501 snprintf(command, POP3_STRING_SIZE, "PASS %s\r\n", password); 501 snprintf(command, POP3_STRING_SIZE, "PASS %s\r\n", password);
502 r = send_command(f, command); 502 r = send_command(f, command);
503 if (r == -1) 503 if (r == -1)
504 return MAILPOP3_ERROR_STREAM; 504 return MAILPOP3_ERROR_STREAM;
505 505
506 response = read_line(f); 506 response = read_line(f);
507 if (response == NULL) 507 if (response == NULL)
508 return MAILPOP3_ERROR_STREAM; 508 return MAILPOP3_ERROR_STREAM;
509 r = parse_response(f, response); 509 r = parse_response(f, response);
510 510
511 if (r != RESPONSE_OK) 511 if (r != RESPONSE_OK) {
512 // LR
513 fprintf(stderr,"POP3 login error. Response from server:\n%s\n",response );
512 return MAILPOP3_ERROR_BAD_PASSWORD; 514 return MAILPOP3_ERROR_BAD_PASSWORD;
515 }
513 516
514 f->pop3_state = POP3_STATE_TRANSACTION; 517 f->pop3_state = POP3_STATE_TRANSACTION;
515 518
516 return MAILPOP3_NO_ERROR; 519 return MAILPOP3_NO_ERROR;
517} 520}
518 521
519static int read_list(mailpop3 * f, carray ** result); 522static int read_list(mailpop3 * f, carray ** result);
520 523
521 524
522 525
523static int read_uidl(mailpop3 * f, carray * msg_tab); 526static int read_uidl(mailpop3 * f, carray * msg_tab);
524 527
525 528
526 529
527static int mailpop3_do_uidl(mailpop3 * f, carray * msg_tab) 530static int mailpop3_do_uidl(mailpop3 * f, carray * msg_tab)
528{ 531{
529 char command[POP3_STRING_SIZE]; 532 char command[POP3_STRING_SIZE];
530 int r; 533 int r;
531 char * response; 534 char * response;
532 535
533 if (f->pop3_state != POP3_STATE_TRANSACTION) 536 if (f->pop3_state != POP3_STATE_TRANSACTION)
534 return MAILPOP3_ERROR_BAD_STATE; 537 return MAILPOP3_ERROR_BAD_STATE;
535 538
536 /* send list command */ 539 /* send list command */
537 540
538 snprintf(command, POP3_STRING_SIZE, "UIDL\r\n"); 541 snprintf(command, POP3_STRING_SIZE, "UIDL\r\n");
539 r = send_command(f, command); 542 r = send_command(f, command);
540 if (r == -1) 543 if (r == -1)
541 return MAILPOP3_ERROR_STREAM; 544 return MAILPOP3_ERROR_STREAM;
542 545
543 response = read_line(f); 546 response = read_line(f);
544 if (response == NULL) 547 if (response == NULL)
545 return MAILPOP3_ERROR_STREAM; 548 return MAILPOP3_ERROR_STREAM;
546 r = parse_response(f, response); 549 r = parse_response(f, response);
547 550
548 if (r != RESPONSE_OK) 551 if (r != RESPONSE_OK)
549 return MAILPOP3_ERROR_CANT_LIST; 552 return MAILPOP3_ERROR_CANT_LIST;
550 553
551 r = read_uidl(f, msg_tab); 554 r = read_uidl(f, msg_tab);
552 if (r != MAILPOP3_NO_ERROR) 555 if (r != MAILPOP3_NO_ERROR)
553 return r; 556 return r;
554 557
555 return MAILPOP3_NO_ERROR; 558 return MAILPOP3_NO_ERROR;
556} 559}
557 560
558 561
559 562
560static int mailpop3_do_list(mailpop3 * f) 563static int mailpop3_do_list(mailpop3 * f)
561{ 564{
562 char command[POP3_STRING_SIZE]; 565 char command[POP3_STRING_SIZE];
563 int r; 566 int r;
564 carray * msg_tab; 567 carray * msg_tab;
565 char * response; 568 char * response;
566 569
567 if (f->pop3_msg_tab != NULL) { 570 if (f->pop3_msg_tab != NULL) {
568 mailpop3_msg_info_tab_free(f->pop3_msg_tab); 571 mailpop3_msg_info_tab_free(f->pop3_msg_tab);
569 f->pop3_msg_tab = NULL; 572 f->pop3_msg_tab = NULL;
570 } 573 }
571 574
572 if (f->pop3_state != POP3_STATE_TRANSACTION) 575 if (f->pop3_state != POP3_STATE_TRANSACTION)
573 return MAILPOP3_ERROR_BAD_STATE; 576 return MAILPOP3_ERROR_BAD_STATE;
574 577
575 /* send list command */ 578 /* send list command */
576 579
diff --git a/kmicromail/libetpan/tools/mailstream_helper.c b/kmicromail/libetpan/tools/mailstream_helper.c
index 146f955..92f4ffe 100644
--- a/kmicromail/libetpan/tools/mailstream_helper.c
+++ b/kmicromail/libetpan/tools/mailstream_helper.c
@@ -37,130 +37,137 @@
37#include <string.h> 37#include <string.h>
38#include <stdio.h> 38#include <stdio.h>
39#include "mail.h" 39#include "mail.h"
40 40
41static void remove_trailing_eol(MMAPString * mmapstr) 41static void remove_trailing_eol(MMAPString * mmapstr)
42{ 42{
43 if (mmapstr->str[mmapstr->len - 1] == '\n') { 43 if (mmapstr->str[mmapstr->len - 1] == '\n') {
44 mmapstr->len --; 44 mmapstr->len --;
45 mmapstr->str[mmapstr->len] = '\0'; 45 mmapstr->str[mmapstr->len] = '\0';
46 } 46 }
47 if (mmapstr->str[mmapstr->len - 1] == '\r') { 47 if (mmapstr->str[mmapstr->len - 1] == '\r') {
48 mmapstr->len --; 48 mmapstr->len --;
49 mmapstr->str[mmapstr->len] = '\0'; 49 mmapstr->str[mmapstr->len] = '\0';
50 } 50 }
51} 51}
52 52
53char * mailstream_read_line(mailstream * stream, MMAPString * line) 53char * mailstream_read_line(mailstream * stream, MMAPString * line)
54{ 54{
55 if (mmap_string_assign(line, "") == NULL) 55 if (mmap_string_assign(line, "") == NULL)
56 return NULL; 56 return NULL;
57 57
58 return mailstream_read_line_append(stream, line); 58 return mailstream_read_line_append(stream, line);
59} 59}
60 60
61static char * mailstream_read_len_append(mailstream * stream, 61static char * mailstream_read_len_append(mailstream * stream,
62 MMAPString * line, 62 MMAPString * line,
63 size_t i) 63 size_t i)
64{ 64{
65 size_t cur_size; 65 size_t cur_size;
66 66
67 cur_size = line->len; 67 cur_size = line->len;
68 if (mmap_string_set_size(line, line->len + i) == NULL) 68 if (mmap_string_set_size(line, line->len + i) == NULL)
69 return NULL; 69 return NULL;
70 if (mailstream_read(stream, line->str + cur_size, i) < 0) 70 if (mailstream_read(stream, line->str + cur_size, i) < 0)
71 return NULL; 71 return NULL;
72 return line->str; 72 return line->str;
73} 73}
74 74
75char * mailstream_read_line_append(mailstream * stream, MMAPString * line) 75char * mailstream_read_line_append(mailstream * stream, MMAPString * line)
76{ 76{
77 if (stream == NULL) 77 if (stream == NULL)
78 return NULL; 78 return NULL;
79 79
80 do { 80 do {
81 if (stream->read_buffer_len > 0) { 81 if (stream->read_buffer_len > 0) {
82 size_t i; 82 size_t i;
83 83
84 i = 0; 84 i = 0;
85 while (i < stream->read_buffer_len) { 85 while (i < stream->read_buffer_len) {
86 if (stream->read_buffer[i] == '\n') 86 if (stream->read_buffer[i] == '\n')
87 return mailstream_read_len_append(stream, line, i + 1); 87 return mailstream_read_len_append(stream, line, i + 1);
88 i++; 88 i++;
89 } 89 }
90 if (mailstream_read_len_append(stream, line, 90 if (mailstream_read_len_append(stream, line,
91 stream->read_buffer_len) == NULL) 91 stream->read_buffer_len) == NULL)
92 return NULL; 92 return NULL;
93 } 93 }
94 else { 94 else {
95 ssize_t r; 95 ssize_t r;
96 96
97 r = mailstream_feed_read_buffer(stream); 97 r = mailstream_feed_read_buffer(stream);
98 if (r == -1) 98 if (r == -1)
99 return NULL; 99 return NULL;
100 100
101 if (r == 0) 101 if (r == 0) {
102 break; 102 // LR
103 // this avoids a memory access violation later when trying
104 // to remove_trailing_eol from a null string
105 if ( line->len == 0 )
106 return NULL;
107 else
108 break;
109 }
103 } 110 }
104 } 111 }
105 while (1); 112 while (1);
106 113
107 return line->str; 114 return line->str;
108} 115}
109 116
110char * mailstream_read_line_remove_eol(mailstream * stream, MMAPString * line) 117char * mailstream_read_line_remove_eol(mailstream * stream, MMAPString * line)
111{ 118{
112 if (!mailstream_read_line(stream, line)) 119 if (!mailstream_read_line(stream, line))
113 return NULL; 120 return NULL;
114 121
115 remove_trailing_eol(line); 122 remove_trailing_eol(line);
116 123
117 return line->str; 124 return line->str;
118} 125}
119 126
120int mailstream_is_end_multiline(const char * line) 127int mailstream_is_end_multiline(const char * line)
121{ 128{
122 if (line[0] != '.') 129 if (line[0] != '.')
123 return FALSE; 130 return FALSE;
124 if (line[1] != 0) 131 if (line[1] != 0)
125 return FALSE; 132 return FALSE;
126 return TRUE; 133 return TRUE;
127} 134}
128 135
129#if 1 136#if 1
130char * mailstream_read_multiline(mailstream * s, size_t size, 137char * mailstream_read_multiline(mailstream * s, size_t size,
131 MMAPString * stream_buffer, 138 MMAPString * stream_buffer,
132 MMAPString * multiline_buffer, 139 MMAPString * multiline_buffer,
133 size_t progr_rate, 140 size_t progr_rate,
134 progress_function * progr_fun) 141 progress_function * progr_fun)
135{ 142{
136 size_t count; 143 size_t count;
137 char * line; 144 char * line;
138 size_t last; 145 size_t last;
139 146
140 if (mmap_string_assign(multiline_buffer, "") == NULL) 147 if (mmap_string_assign(multiline_buffer, "") == NULL)
141 return NULL; 148 return NULL;
142 149
143 count = 0; 150 count = 0;
144 last = 0; 151 last = 0;
145 152
146 while ((line = mailstream_read_line_remove_eol(s, stream_buffer)) != NULL) { 153 while ((line = mailstream_read_line_remove_eol(s, stream_buffer)) != NULL) {
147 if (mailstream_is_end_multiline(line)) 154 if (mailstream_is_end_multiline(line))
148 return multiline_buffer->str; 155 return multiline_buffer->str;
149 156
150 if (line[0] == '.') { 157 if (line[0] == '.') {
151 if (mmap_string_append(multiline_buffer, line + 1) == NULL) 158 if (mmap_string_append(multiline_buffer, line + 1) == NULL)
152 return NULL; 159 return NULL;
153 } 160 }
154 else { 161 else {
155 if (mmap_string_append(multiline_buffer, line) == NULL) 162 if (mmap_string_append(multiline_buffer, line) == NULL)
156 return NULL; 163 return NULL;
157 } 164 }
158 if (mmap_string_append(multiline_buffer, "\r\n") == NULL) 165 if (mmap_string_append(multiline_buffer, "\r\n") == NULL)
159 return NULL; 166 return NULL;
160 167
161 count += strlen(line); 168 count += strlen(line);
162 if ((size != 0) && (progr_rate != 0) && (progr_fun != NULL)) 169 if ((size != 0) && (progr_rate != 0) && (progr_fun != NULL))
163 if (count - last >= progr_rate) { 170 if (count - last >= progr_rate) {
164 (* progr_fun)(count, size); 171 (* progr_fun)(count, size);
165 last = count; 172 last = count;
166 } 173 }