Permalink
Browse files

[feature] smtpClient: Added dryrun flag.

  • Loading branch information...
nrs135 authored and Aqua-Ye committed Feb 29, 2012
1 parent 3796837 commit c572ff19b6d667b6b0cd9ce2cd74a8f8116f6078
Showing with 32 additions and 19 deletions.
  1. +4 −3 libnet/smtpClient.ml
  2. +9 −4 libnet/smtpClientCore.proto
  3. +12 −8 opabsl/mlbsl/bslMail.ml
  4. +7 −4 stdlib/web/mail/email.opa
View
@@ -237,7 +237,7 @@ let analyze_error = Mailerror.parse_mailerror_error
let mail_send_aux ?client_certificate ?verify_params ?(secure=false) sched
?subject mfrom mdst ?mto mdata ?return_path ?html ?files ?custom_headers ?cte ?charset nb_attempt ?(port=25)
- ?via ?addr ?auth ?user ?pass cont () =
+ ?via ?addr ?auth ?user ?pass ?dryrun cont () =
let mto =
match mto with
| Some tos -> tos
@@ -255,6 +255,7 @@ let mail_send_aux ?client_certificate ?verify_params ?(secure=false) sched
dests = [mdst];
body = mdata;
auth = Option.default "" auth; user = Option.default "" user; pass = Option.default "" pass;
+ dryrun = Option.default false dryrun;
}
in
let rec try_mx mail attempt ?ip_list cont =
@@ -336,7 +337,7 @@ let mail_send_aux ?client_certificate ?verify_params ?(secure=false) sched
let mail_send ?client_certificate ?verify_params ?secure sched
?subject mfrom mdst ?mto mdata ?return_path ?html ?files ?cte ?charset nb_attempt
- ?port ?via ?addr ?auth ?user ?pass cont () =
+ ?port ?via ?addr ?auth ?user ?pass ?dryrun cont () =
let files = match files with
| Some l ->
let res =
@@ -348,5 +349,5 @@ let mail_send ?client_certificate ?verify_params ?secure sched
| None -> None in
mail_send_aux ?client_certificate ?verify_params ?secure sched
?subject mfrom mdst ?mto mdata ?return_path ?html ?files ?cte ?charset nb_attempt
- ?port ?via ?addr ?auth ?user ?pass cont ()
+ ?port ?via ?addr ?auth ?user ?pass ?dryrun cont ()
@@ -1,4 +1,4 @@
-% -*-erlang-*-
+% -*-proto-*-
%
% Copyright © 2011 MLstate
@@ -31,7 +31,8 @@
body : string;
auth : string;
user : string;
- pass : string
+ pass : string;
+ dryrun : bool
}
-type result =
@@ -166,8 +167,12 @@ from(mail, tools):
receive
| ENs (250, _) -> from(mail, tools)
| Ns (250, _) ->
- send (From mail.from);
- to(mail, tools)
+ if {{ mail.dryrun }}
+ then
+ quit(tools)
+ else
+ send (From mail.from);
+ to(mail, tools)
| ENs (a, b) ->
debug {{ eprintf "from received ENs: %d %s\n" a b }}
{{ tools.elog a b }} finish_error(tools)
View
@@ -28,11 +28,11 @@
##register [cps-bypass] mail_send_fun : string, string, string, string, string, string, string, \
caml_list(caml_tuple_4(string,string,string,string)), \
caml_list(caml_tuple_2(string,string)), \
- option(string), option(string), option(string), option(string), option(string), \
+ option(string), option(string), option(string), option(string), option(string), opa[bool], \
(opa[email_send_status], continuation(opa[void]) -> void), \
continuation(opa[void]) -> void
let mail_send_fun mfrom mfrom_address_only mdst mto subject mdata html files custom_headers
- via addr auth user pass cont k =
+ via addr auth user pass dryrun cont k =
let cont = BslUtils.proj_cps k cont in
let cont x =
let res =
@@ -55,18 +55,20 @@
in cont (wrap_opa_email_send_status res)
in
let html = if html = "" then None else Some html
- and mto = if mto = "" then None else Some mto in
- SmtpClient.mail_send_aux BslScheduler.opa ~charset:"UTF-8" ~subject mfrom mdst ?mto:mto mdata ?html:html ~files ~custom_headers ~return_path:mfrom_address_only 10 ?via:via ?addr:addr ?auth:auth ?user:user ?pass:pass cont ();
+ and mto = if mto = "" then None else Some mto
+ and dryrun = Some (ServerLib.unwrap_bool dryrun)
+ in
+ SmtpClient.mail_send_aux BslScheduler.opa ~charset:"UTF-8" ~subject mfrom mdst ?mto:mto mdata ?html:html ~files ~custom_headers ~return_path:mfrom_address_only 10 ?via:via ?addr:addr ?auth:auth ?user:user ?pass:pass ?dryrun:dryrun cont ();
QmlCpsServerLib.return k ServerLib.void
##register [cps-bypass] mail_send_fun_secure : string, string, string, string, string, string, string, \
caml_list(caml_tuple_4(string,string,string,string)), \
caml_list(caml_tuple_2(string,string)), \
- option(string), option(string), option(int), option(string), option(string), option(string), SSL.secure_type, \
+ option(string), option(string), option(int), option(string), option(string), option(string), opa[bool], SSL.secure_type, \
(opa[email_send_status], continuation(opa[void]) -> void), \
continuation(opa[void]) -> void
let mail_send_fun_secure mfrom mfrom_address_only mdst mto subject mdata html files custom_headers
- via addr port auth user pass secure_type cont k =
+ via addr port auth user pass dryrun secure_type cont k =
let cont = BslUtils.proj_cps k cont in
let cont x =
let res =
@@ -89,9 +91,11 @@
in cont (wrap_opa_email_send_status res)
in
let html = if html = "" then None else Some html
- and mto = if mto = "" then None else Some mto in
+ and mto = if mto = "" then None else Some mto
+ and dryrun = Some (ServerLib.unwrap_bool dryrun)
+ in
let client_certificate, verify_params = secure_type in
- SmtpClient.mail_send_aux ?client_certificate ?verify_params ~secure:true BslScheduler.opa ~charset:"UTF-8" ~subject mfrom mdst ?mto:mto mdata ?html:html ~files ~custom_headers ~return_path:mfrom_address_only 10 ?port:port ?via:via ?addr:addr ?auth:auth ?user:user ?pass:pass cont ();
+ SmtpClient.mail_send_aux ?client_certificate ?verify_params ~secure:true BslScheduler.opa ~charset:"UTF-8" ~subject mfrom mdst ?mto:mto mdata ?html:html ~files ~custom_headers ~return_path:mfrom_address_only 10 ?port:port ?via:via ?addr:addr ?auth:auth ?user:user ?pass:pass ?dryrun:dryrun cont ();
QmlCpsServerLib.return k ServerLib.void
##endmodule
View
@@ -102,6 +102,7 @@ type Email.options = {
auth : option(string)
user : option(string)
pass : option(string)
+ dryrun : bool
secure_type : option(SSL.secure_type)
}
@@ -157,6 +158,7 @@ Email = {{
auth = none
user = none
pass = none
+ dryrun = false
secure_type = none
} : Email.options
@@ -302,10 +304,10 @@ Email = {{
aux(List.rev(l),%%BslNativeLib.empty_list%%)
@private
- send_mail = %% BslMail.Mailserve.mail_send_fun %% : string , string, string , string , string , string, string, caml_list(caml_tuple_4(string,string,string,string)), caml_list(caml_tuple_2(string, string)), option(string), option(string), option(string), option(string), option(string), (Email.send_status -> void) -> void
+ send_mail = %% BslMail.Mailserve.mail_send_fun %% : string , string, string , string , string , string, string, caml_list(caml_tuple_4(string,string,string,string)), caml_list(caml_tuple_2(string, string)), option(string), option(string), option(string), option(string), option(string), bool, (Email.send_status -> void) -> void
@private
- send_mail_secure = %% BslMail.Mailserve.mail_send_fun_secure %% : string , string, string , string , string , string, string, caml_list(caml_tuple_4(string,string,string,string)), caml_list(caml_tuple_2(string, string)), option(string), option(string), option(int), option(string), option(string), option(string), SSL.secure_type, (Email.send_status -> void) -> void
+ send_mail_secure = %% BslMail.Mailserve.mail_send_fun_secure %% : string , string, string , string , string , string, string, caml_list(caml_tuple_4(string,string,string,string)), caml_list(caml_tuple_2(string, string)), option(string), option(string), option(int), option(string), option(string), option(string), bool, SSL.secure_type, (Email.send_status -> void) -> void
@private
send_async(
@@ -355,13 +357,14 @@ Email = {{
send_mail_secure(
to_string(from), to_string_only_address(from), to_string_only_address(to), mto,
subject, text, html, files, custom_headers,
- options.via, options.server_addr, options.server_port, options.auth, options.user, options.pass, secure_type, k
+ options.via, options.server_addr, options.server_port, options.auth, options.user, options.pass, options.dryrun,
+ secure_type, k
)
| {none} ->
send_mail(
to_string(from), to_string_only_address(from), to_string_only_address(to), mto,
subject, text, html, files, custom_headers,
- options.via, options.server_addr, options.auth, options.user, options.pass, k
+ options.via, options.server_addr, options.auth, options.user, options.pass, options.dryrun, k
)
/**

0 comments on commit c572ff1

Please sign in to comment.