From 8e2f648bef202814a022288db38c466accbe0e3d Mon Sep 17 00:00:00 2001 From: totoro Date: Fri, 22 May 2015 23:57:08 +0200 Subject: [PATCH] move the send mail type and some according tools from MailFountain to Calexium_lib because send already out of the box from MailFountain. --- mail/send_mail_type.anubis | 131 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ mail/tools.anubis | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 203 insertions(+), 0 deletions(-) create mode 100644 mail/send_mail_type.anubis create mode 100644 mail/tools.anubis diff --git a/mail/send_mail_type.anubis b/mail/send_mail_type.anubis new file mode 100644 index 0000000..550c5a0 --- /dev/null +++ b/mail/send_mail_type.anubis @@ -0,0 +1,131 @@ +/* + * Created by PyramIDE. + * User: フランスのトトロ + * Date: 16/05/2015 + * Time: 22:50 + * © Calexium + */ + +read system/string.anubis +read system/data_io.anubis +read tools/basis.anubis + +read calexium_lib/mail/smtp_client.anubis + +public type Send_Status: + ready, //ready to send + finished, //the mail is delivered correctly + timeout, //the mail was not sent in enough time, this is a permanent error + general_error, + error(Int code, String enhanced_status, String text), //this is SMTP permanent error 5xx, we can't deliver the mail + warning(Int code, String enhanced_status, String text), //this is SMTP temporary error 4xx, we can retry with same mail later + in_progress. //We are in sending process, it's like a lock + +public define String + to_String + ( + Send_Status snd_st + )= + if snd_st is + { + ready then "READY", + finished then "FINISHED", + timeout then "TIMEOUT", + general_error then "GENERAL_ERROR", + error(_,_,_) then "ERROR", + warning(_,_,_)then "WARNING", + in_progress then "IN PROGRESS" + }. + +public define (String, List((SQLite3Bind))) + to_SQL_query_binds + ( + Send_Status snd_st + )= + with sql_query = "send_status = :status ", + sql_query_ext = ", smtp_r_code = :smtp_r_code, smtp_r_enhanced_code = :smtp_r_enhanced_code, smtp_r_code_text = :smtp_r_code_text", + binds = (List(SQLite3Bind)) [ bind_String(":status", to_String(snd_st))], + + if snd_st is + { + ready then (sql_query, binds), + finished then (sql_query, binds), + timeout then (sql_query, binds), + general_error then (sql_query, binds), + error(code,enhanced,text) then (sql_query + sql_query_ext, + binds + + [ bind_Int(":smtp_r_code", code), + bind_String(":smtp_r_enhanced_code", enhanced), + bind_String(":smtp_r_code_text", text)]), + warning(code,enhanced,text) then (sql_query + sql_query_ext, + binds + + [ bind_Int(":smtp_r_code", code), + bind_String(":smtp_r_enhanced_code", enhanced), + bind_String(":smtp_r_code_text", text)]), + in_progress then (sql_query, binds) + }. + + + + bind_Int(":smtp_r_code", code), + bind_String(":smtp_r_enhanced_code", enhanced), + binf_String(":smtp_r_code_text", text), + ], + +public define Send_Status + to_Send_Status + ( + String status, + Int code, + String enhanced_status, + String message, + )= + if status = "READY" then ready + else if status = "FINISHED" then finished + else if status = "TIMEOUT" then timeout + else if status = "GENERAL_ERROR" then general_error + else if status = "ERROR" then error(code, enhanced_status, message) + else if status = "WARNING" then warning(code, enhanced_status, message) + else if status = "IN PROGRESS" then in_progress + else ready. + +public define String + to_image + ( + Send_Status status, + )= + if status is + { + ready then "/icons/16x16/status_ready.png", + finished then "/icons/16x16/status_valid.png", + timeout then "/icons/16x16/status_error.png", + general_error then "/icons/16x16/status_error.png", + error(_,_,_) then "/icons/16x16/status_error.png", + warning(_,_,_) then "/icons/16x16/status_sandglass.png", + in_progress then "/icons/16x16/status_processing_16x16.gif" + }. + +public define Send_Status + to_Send_Status + ( + Result(SmtpClientResult, One) result + )= + if result is + { + error(smtp_result) then + if smtp_result is + { + error then warning(440, "", "Communication error"), + timeout then warning(441, "", "Communication timeout"), + no_auth_method then error(500, "", "Can't find any suitable authentication method"), + bad_reply then error(500, "", "Bad reply from server"), + reply(code, enhanced_st, lines) then + with join_lines = join(implode([13,10]),lines), + if code >= 400 & code < 500 then + warning(code, enhanced_st, join_lines) + else + error(code, enhanced_st, join_lines) + }, + ok(_) then + finished + }. diff --git a/mail/tools.anubis b/mail/tools.anubis new file mode 100644 index 0000000..3c383b4 --- /dev/null +++ b/mail/tools.anubis @@ -0,0 +1,72 @@ +/* + * Created by PyramIDE. + * User: フランスのトトロ + * Date: 17/05/2015 + * Time: 01:27 + * © Calexium + */ + +transmit tools/basis.anubis +transmit system/string.anubis + +define Maybe(String) + day_name + ( + Int day_num + )= + if day_num = 1 then success("Mon") + else if day_num = 2 then success("Tue") + else if day_num = 3 then success("Wed") + else if day_num = 4 then success("Thu") + else if day_num = 5 then success("Fri") + else if day_num = 6 then success("Sat") + else if day_num = 7 then success("Sun") + else failure + . + +define Maybe(String) + month_name + ( + Int month_num + )= + if month_num = 1 then success("Jan") + else if month_num = 2 then success("Feb") + else if month_num = 3 then success("Mar") + else if month_num = 4 then success("Apr") + else if month_num = 5 then success("May") + else if month_num = 6 then success("Jun") + else if month_num = 7 then success("Jul") + else if month_num = 8 then success("Aug") + else if month_num = 9 then success("Sep") + else if month_num = 10 then success("Oct") + else if month_num = 11 then success("Nov") + else if month_num = 12 then success("Dec") + else failure + . + +public define String + str_utime_send_mail + ( + UTime t + ) = + with date_send = convert_time(t.seconds), + if day_name(date_send.week_day) is + { + failure then "", + success(the_day_name) then the_day_name + ", " + }+ + date_send.day + " " + + if month_name(date_send.month) is + { + failure then to_decimal(date_send.month), + success(the_month_name) then the_month_name + }+ " " + + date_send.year + " " + + zero_pad_n(2, date_send.hour) + ":" + zero_pad_n(2, date_send.minute) + ":" + zero_pad_n(2, date_send.second) + //+ " +0000" + . + +public define String + get_rfc822_date_format + = + str_utime_send_mail(unow). -- libgit2 0.21.4