-rw-r--r-- | kmicromail/libetpan/generic/pop3driver.c | 9 | ||||
-rw-r--r-- | kmicromail/libetpan/pop3/mailpop3.c | 5 | ||||
-rw-r--r-- | kmicromail/libetpan/tools/mailstream_helper.c | 11 |
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 | |||
@@ -225,100 +225,103 @@ static int pop3driver_starttls(mailsession * session) | |||
225 | 225 | ||
226 | static int pop3driver_parameters(mailsession * session, | 226 | static 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 | ||
248 | static int pop3driver_login(mailsession * session, | 248 | static 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 | ||
279 | static int pop3driver_logout(mailsession * session) | 282 | static 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 | ||
288 | static int pop3driver_noop(mailsession * session) | 291 | static 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 | ||
297 | static int pop3driver_status_folder(mailsession * session, char * mb, | 300 | static 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 | ||
316 | static int pop3driver_messages_number(mailsession * session, char * mb, | 319 | static 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; |
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 | |||
@@ -463,98 +463,101 @@ int mailpop3_apop(mailpop3 * f, | |||
463 | int mailpop3_user(mailpop3 * f, const char * user) | 463 | int 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 | ||
490 | int mailpop3_pass(mailpop3 * f, const char * password) | 490 | int 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 | ||
519 | static int read_list(mailpop3 * f, carray ** result); | 522 | static int read_list(mailpop3 * f, carray ** result); |
520 | 523 | ||
521 | 524 | ||
522 | 525 | ||
523 | static int read_uidl(mailpop3 * f, carray * msg_tab); | 526 | static int read_uidl(mailpop3 * f, carray * msg_tab); |
524 | 527 | ||
525 | 528 | ||
526 | 529 | ||
527 | static int mailpop3_do_uidl(mailpop3 * f, carray * msg_tab) | 530 | static 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 | ||
560 | static int mailpop3_do_list(mailpop3 * f) | 563 | static int mailpop3_do_list(mailpop3 * f) |
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 | |||
@@ -53,98 +53,105 @@ static void remove_trailing_eol(MMAPString * mmapstr) | |||
53 | char * mailstream_read_line(mailstream * stream, MMAPString * line) | 53 | char * 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 | ||
61 | static char * mailstream_read_len_append(mailstream * stream, | 61 | static 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 | ||
75 | char * mailstream_read_line_append(mailstream * stream, MMAPString * line) | 75 | char * 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 | ||
110 | char * mailstream_read_line_remove_eol(mailstream * stream, MMAPString * line) | 117 | char * 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 | ||
120 | int mailstream_is_end_multiline(const char * line) | 127 | int 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 |
130 | char * mailstream_read_multiline(mailstream * s, size_t size, | 137 | char * 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] == '.') { |