Commit 0dc379d0705ad786fb1cba66339894712786af46

Authored by Cédric RICARD
1 parent 6741024f

send_mail(): Automatically adding '<' and '>' to sender and recipient emails

Showing 1 changed file with 22 additions and 6 deletions   Show diff stats
calexium_lib/mail/send_mail.anubis
@@ -244,6 +244,20 @@ define Reply_Result @@ -244,6 +244,20 @@ define Reply_Result
244 }. 244 }.
245 245
246 The same one for 'MAIL FROM': 246 The same one for 'MAIL FROM':
  247 +
  248 +define String
  249 + check_email_syntax
  250 + (
  251 + String email
  252 + ) =
  253 + if nth(0, email) is
  254 + {
  255 + failure then "<>",
  256 + success(b) then
  257 + if b = '<' then email
  258 + else "<" + email + ">"
  259 + }.
  260 +
247 261
248 define Reply_Result 262 define Reply_Result
249 send_mail_from 263 send_mail_from
@@ -251,9 +265,10 @@ define Reply_Result @@ -251,9 +265,10 @@ define Reply_Result
251 RWStream conn, 265 RWStream conn,
252 String sender 266 String sender
253 ) = 267 ) =
254 - if smtp_send_line(conn,"MAIL FROM:"+sender) is 268 + with rfc_sender = check_email_syntax(sender),
  269 + if smtp_send_line(conn,"MAIL FROM:"+rfc_sender) is
255 { 270 {
256 - failure then logError(send_mail_log, "error sending 'MAIL FROM:" + sender + "'"); error, 271 + failure then logError(send_mail_log, "error sending 'MAIL FROM:" + rfc_sender + "'"); error,
257 success(_) then receive_reply(conn) 272 success(_) then receive_reply(conn)
258 }. 273 }.
259 274
@@ -263,11 +278,12 @@ define Reply_Result @@ -263,11 +278,12 @@ define Reply_Result
263 send_recipient 278 send_recipient
264 ( 279 (
265 RWStream conn, 280 RWStream conn,
266 - String recipient, 281 + String recipient,
267 ) = 282 ) =
268 - if smtp_send_line(conn,"RCPT TO:<"+recipient+">") is 283 + with rfc_recipient = check_email_syntax(recipient),
  284 + if smtp_send_line(conn,"RCPT TO:"+rfc_recipient) is
269 { 285 {
270 - failure then logError(send_mail_log, "error sending 'RCPT TO:<"+recipient+">'"); error, 286 + failure then logError(send_mail_log, "error sending 'RCPT TO:"+rfc_recipient+"'"); error,
271 success(_) then receive_reply(conn) 287 success(_) then receive_reply(conn)
272 }. 288 }.
273 289
@@ -400,7 +416,7 @@ define SendMailResult @@ -400,7 +416,7 @@ define SendMailResult
400 Bool enhanced_status 416 Bool enhanced_status
401 )= 417 )=
402 418
403 - with plain_str = "AUTH PLAIN "+ to_string(base64_encode(to_byte_array(login)+ 419 + with plain_str = "AUTH PLAIN "+ to_string(base64_encode(to_byte_array("")+
404 constant_byte_array(1,0)+ 420 constant_byte_array(1,0)+
405 to_byte_array(login)+ 421 to_byte_array(login)+
406 constant_byte_array(1,0)+ 422 constant_byte_array(1,0)+