Commit cf51ddb0dfdc300aa1d11aac8687c50c333d3605

Authored by Cédric RICARD
1 parent 3a3efadd

Added 2 new kind of SMTP error : no_auth_method and bad_reply

calexium_lib/mail/send_mail.anubis
@@ -119,6 +119,8 @@ public define Result(SmtpClientResult, One) @@ -119,6 +119,8 @@ public define Result(SmtpClientResult, One)
119 { 119 {
120 error then error(error), 120 error then error(error),
121 timeout then error(timeout), 121 timeout then error(timeout),
  122 + no_auth_method then error(no_auth_method),
  123 + bad_reply then error(bad_reply),
122 reply(code, status, lines) then 124 reply(code, status, lines) then
123 if code = 220 then 125 if code = 220 then
124 //send EHLO 126 //send EHLO
calexium_lib/mail/smtp_client.anubis
@@ -24,6 +24,8 @@ define ByteArray crlf_dot_crlf = to_byte_array(implode([13,10,'.',13,10])). @@ -24,6 +24,8 @@ define ByteArray crlf_dot_crlf = to_byte_array(implode([13,10,'.',13,10])).
24 public type SmtpClientResult: 24 public type SmtpClientResult:
25 error, 25 error,
26 timeout, 26 timeout,
  27 + no_auth_method,
  28 + bad_reply,
27 reply(Int code, String enhanced_status, List(String) lines). 29 reply(Int code, String enhanced_status, List(String) lines).
28 30
29 public type SmtpClientSession: 31 public type SmtpClientSession:
@@ -149,12 +151,12 @@ define SmtpClientResult @@ -149,12 +151,12 @@ define SmtpClientResult
149 if length(line) =< 3 then 151 if length(line) =< 3 then
150 if decimal_scan(line) is 152 if decimal_scan(line) is
151 { 153 {
152 - failure then logger(logError, "receive_reply: can't extract reply code from '" + line + "'"); error, 154 + failure then logger(logError, "receive_reply: can't extract reply code from '" + line + "'"); bad_reply,
153 success(code) then reply_handling(code, reverse(so_far), enhanced_status) 155 success(code) then reply_handling(code, reverse(so_far), enhanced_status)
154 } 156 }
155 else if nth(3, line) is 157 else if nth(3, line) is
156 { 158 {
157 - failure then logger(logError, "receive_reply: error getting 4th character from '" + line +"'"); error, 159 + failure then logger(logError, "receive_reply: error getting 4th character from '" + line +"'"); bad_reply,
158 success(char) then 160 success(char) then
159 if char = '-' then 161 if char = '-' then
160 receive_reply(conn, [line . so_far], enhanced_status, time_out, logger) 162 receive_reply(conn, [line . so_far], enhanced_status, time_out, logger)
@@ -162,11 +164,11 @@ define SmtpClientResult @@ -162,11 +164,11 @@ define SmtpClientResult
162 //decode the code 164 //decode the code
163 if sub_string(line, 0, 3) is 165 if sub_string(line, 0, 3) is
164 { 166 {
165 - failure then logger(logError, "receive_reply: error extracting reply code from '" + line+"'"); error, // should never occure 167 + failure then logger(logError, "receive_reply: error extracting reply code from '" + line+"'"); bad_reply, // should never occure
166 success(code_str) then 168 success(code_str) then
167 if decimal_scan(code_str) is 169 if decimal_scan(code_str) is
168 { 170 {
169 - failure then logger(logError, "receive_reply: can't extract reply code from '" + code_str + "'"); error, //unreadable code 171 + failure then logger(logError, "receive_reply: can't extract reply code from '" + code_str + "'"); bad_reply, //unreadable code
170 success(code) then 172 success(code) then
171 reply_handling(code , reverse([line . so_far]), enhanced_status) 173 reply_handling(code , reverse([line . so_far]), enhanced_status)
172 } 174 }
@@ -458,6 +460,8 @@ define SendContentResult @@ -458,6 +460,8 @@ define SendContentResult
458 copy_ok(so_far + len) 460 copy_ok(so_far + len)
459 } 461 }
460 }, 462 },
  463 + no_auth_method then copy_error(so_far), // impossible
  464 + bad_reply then copy_error(so_far),
461 reply(code, status, lines) then 465 reply(code, status, lines) then
462 smtp_reply(reply(code, status, lines)) 466 smtp_reply(reply(code, status, lines))
463 }. 467 }.
@@ -633,6 +637,8 @@ public define Result(SmtpClientResult, One) @@ -633,6 +637,8 @@ public define Result(SmtpClientResult, One)
633 { 637 {
634 error then "", 638 error then "",
635 timeout then "", 639 timeout then "",
  640 + no_auth_method then "",
  641 + bad_reply then "",
636 reply(code, status, lines) then 642 reply(code, status, lines) then
637 if lines is [h . _] then 643 if lines is [h . _] then
638 if split(h, ' ') is [_ . t] then 644 if split(h, ' ') is [_ . t] then
@@ -672,7 +678,7 @@ public define Result(SmtpClientResult, One) @@ -672,7 +678,7 @@ public define Result(SmtpClientResult, One)
672 do_auth_login(conn, login, password, session, timeout, logger) 678 do_auth_login(conn, login, password, session, timeout, logger)
673 679
674 else 680 else
675 - logger(logError, "do_login: none of CRAM-MD5, LOGIN or PLAIN method available"); error(error). 681 + logger(logError, "do_login: none of CRAM-MD5, LOGIN or PLAIN method available"); error(no_auth_method).
676 682
677 public define Result(SmtpClientResult, One) 683 public define Result(SmtpClientResult, One)
678 do_auth 684 do_auth
@@ -690,7 +696,7 @@ public define Result(SmtpClientResult, One) @@ -690,7 +696,7 @@ public define Result(SmtpClientResult, One)
690 with auth_list = get_auth_method(session.ehlo_answer, []), 696 with auth_list = get_auth_method(session.ehlo_answer, []),
691 if auth_list is 697 if auth_list is
692 { 698 {
693 - [] then logger(logError, "do_auth error"); error(error), 699 + [] then logger(logError, "do_auth error"); error(no_auth_method),
694 [_ . _] then do_login(conn, auth_list, user, password, session, timeout, logger) 700 [_ . _] then do_login(conn, auth_list, user, password, session, timeout, logger)
695 } 701 }
696 }. 702 }.