Commit c91bb36337e4fb0b67f6e4d8d83be54116b6dcf8
1 parent
e413a2e0
Fix for smtp_client.anubis
Showing
1 changed file
with
26 additions
and
32 deletions
Show diff stats
calexium_lib/mail/smtp_client.anubis
| ... | ... | @@ -406,9 +406,9 @@ define Maybe(One) |
| 406 | 406 | { |
| 407 | 407 | failure then failure, |
| 408 | 408 | success(nb_write) then |
| 409 | - if now - buffer_start_time > 3600 then | |
| 409 | + if now - buffer_start_time > 120 then | |
| 410 | 410 | // security to avoid queue blocking |
| 411 | - logger(logError, "sm_flush: TIMEOUT sending a 64kb buffer (taking more than 1 hour). SendMail canceled."); | |
| 411 | + logger(logError, "sm_flush: TIMEOUT sending a " + length(buffer) + " byte-length buffer (taking more than 2 minutes). SendMail canceled."); | |
| 412 | 412 | failure |
| 413 | 413 | else |
| 414 | 414 | with buffer_size = length(buffer), |
| ... | ... | @@ -427,44 +427,38 @@ define SendContentResult |
| 427 | 427 | SmtpClientSession session, |
| 428 | 428 | Int start_time, |
| 429 | 429 | Int so_far, |
| 430 | + Int last_reply_check, | |
| 430 | 431 | (Int) -> One progress_report, |
| 431 | 432 | (LogLevel, String) -> One logger |
| 432 | 433 | ) = |
| 433 | - if receive_reply(weaken(target), [], session.enhanced_status, 0, logger) is | |
| 434 | - { | |
| 435 | - error then copy_error(so_far), | |
| 436 | - timeout then | |
| 437 | - if read_bytes(source, 65536) is | |
| 434 | + if last_reply_check + 60 < now then | |
| 435 | + if receive_reply(weaken(target), [], session.enhanced_status, 0, logger) is | |
| 436 | + { | |
| 437 | + error then copy_error(so_far), | |
| 438 | + timeout then | |
| 439 | + sm_copy_Data_IO_to_Stream(source, target, session, start_time, so_far, now, progress_report, logger) | |
| 440 | + no_auth_method then copy_error(so_far), // impossible | |
| 441 | + bad_reply then copy_error(so_far), | |
| 442 | + reply(code, status, lines) then | |
| 443 | + smtp_reply(reply(code, status, lines)) | |
| 444 | + } | |
| 445 | + else | |
| 446 | + if read_line(source, 1024) is | |
| 438 | 447 | { |
| 439 | - failure then logger(logError, "send_content: failed to read input data_io"); copy_error(so_far), | |
| 440 | - time_out then logger(logError, "send_content: timeout reading input data_io"); copy_error(so_far), | |
| 441 | - success(buffer) then | |
| 448 | + error then logger(logError, "send_content: failed to read input data_io"); copy_error(so_far), | |
| 449 | + timeout then logger(logError, "send_content: timeout reading input data_io"); copy_error(so_far), | |
| 450 | + eof then copy_ok(so_far), | |
| 451 | + ok(line) then | |
| 452 | + with buffer = to_byte_array((if nth(0, line) is success(char) then if char = '.' then "." + line else line else line)), | |
| 442 | 453 | if sm_flush( buffer, weaken(target), now, logger ) is |
| 443 | 454 | { |
| 444 | 455 | failure then copy_error(so_far), |
| 445 | 456 | success(_) then |
| 446 | - progress_report(so_far + 65536); | |
| 447 | - sm_copy_Data_IO_to_Stream(source, target, session, start_time, so_far + 65536, progress_report, logger) | |
| 457 | + with len = length(line) + 2, // 2 is for the CRLF | |
| 458 | + progress_report(so_far + len); | |
| 459 | + sm_copy_Data_IO_to_Stream(source, target, session, start_time, so_far + len, last_reply_check, progress_report, logger) | |
| 448 | 460 | }, |
| 449 | - | |
| 450 | - truncated(buffer) then | |
| 451 | - with len = length(buffer), | |
| 452 | - if len = 0 then | |
| 453 | - copy_ok(so_far) | |
| 454 | - else | |
| 455 | - if sm_flush( buffer, weaken(target), now, logger ) is | |
| 456 | - { | |
| 457 | - failure then copy_error(so_far), | |
| 458 | - success(_) then | |
| 459 | - progress_report(so_far + len); | |
| 460 | - copy_ok(so_far + len) | |
| 461 | - } | |
| 462 | - }, | |
| 463 | - no_auth_method then copy_error(so_far), // impossible | |
| 464 | - bad_reply then copy_error(so_far), | |
| 465 | - reply(code, status, lines) then | |
| 466 | - smtp_reply(reply(code, status, lines)) | |
| 467 | - }. | |
| 461 | + }. | |
| 468 | 462 | |
| 469 | 463 | define SendContentResult |
| 470 | 464 | sm_copy_Data_IO_List_to_Stream |
| ... | ... | @@ -482,7 +476,7 @@ define SendContentResult |
| 482 | 476 | [] then copy_ok(so_far), |
| 483 | 477 | [ h . t ] then |
| 484 | 478 | if rewind(h)(unique) then |
| 485 | - with result = sm_copy_Data_IO_to_Stream(h, target, session, start_time, 0, progress_report, logger), | |
| 479 | + with result = sm_copy_Data_IO_to_Stream(h, target, session, start_time, 0, now, progress_report, logger), | |
| 486 | 480 | if result is copy_ok(written) then |
| 487 | 481 | sm_copy_Data_IO_List_to_Stream(t, target, session, start_time, so_far + written, progress_report, logger) |
| 488 | 482 | else | ... | ... |