Commit 8e2f648bef202814a022288db38c466accbe0e3d

Authored by totoro
1 parent 77699754

move the send mail type and some according tools from MailFountain to Calexium_l…

…ib because send already out of the box from MailFountain.
Showing 2 changed files with 203 additions and 0 deletions   Show diff stats
mail/send_mail_type.anubis 0 → 100644
  1 +/*
  2 + * Created by PyramIDE.
  3 + * User: フランスのトトロ
  4 + * Date: 16/05/2015
  5 + * Time: 22:50
  6 + * © Calexium
  7 + */
  8 +
  9 +read system/string.anubis
  10 +read system/data_io.anubis
  11 +read tools/basis.anubis
  12 +
  13 +read calexium_lib/mail/smtp_client.anubis
  14 +
  15 +public type Send_Status:
  16 + ready, //ready to send
  17 + finished, //the mail is delivered correctly
  18 + timeout, //the mail was not sent in enough time, this is a permanent error
  19 + general_error,
  20 + error(Int code, String enhanced_status, String text), //this is SMTP permanent error 5xx, we can't deliver the mail
  21 + warning(Int code, String enhanced_status, String text), //this is SMTP temporary error 4xx, we can retry with same mail later
  22 + in_progress. //We are in sending process, it's like a lock
  23 +
  24 +public define String
  25 + to_String
  26 + (
  27 + Send_Status snd_st
  28 + )=
  29 + if snd_st is
  30 + {
  31 + ready then "READY",
  32 + finished then "FINISHED",
  33 + timeout then "TIMEOUT",
  34 + general_error then "GENERAL_ERROR",
  35 + error(_,_,_) then "ERROR",
  36 + warning(_,_,_)then "WARNING",
  37 + in_progress then "IN PROGRESS"
  38 + }.
  39 +
  40 +public define (String, List((SQLite3Bind)))
  41 + to_SQL_query_binds
  42 + (
  43 + Send_Status snd_st
  44 + )=
  45 + with sql_query = "send_status = :status ",
  46 + 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",
  47 + binds = (List(SQLite3Bind)) [ bind_String(":status", to_String(snd_st))],
  48 +
  49 + if snd_st is
  50 + {
  51 + ready then (sql_query, binds),
  52 + finished then (sql_query, binds),
  53 + timeout then (sql_query, binds),
  54 + general_error then (sql_query, binds),
  55 + error(code,enhanced,text) then (sql_query + sql_query_ext,
  56 + binds +
  57 + [ bind_Int(":smtp_r_code", code),
  58 + bind_String(":smtp_r_enhanced_code", enhanced),
  59 + bind_String(":smtp_r_code_text", text)]),
  60 + warning(code,enhanced,text) then (sql_query + sql_query_ext,
  61 + binds +
  62 + [ bind_Int(":smtp_r_code", code),
  63 + bind_String(":smtp_r_enhanced_code", enhanced),
  64 + bind_String(":smtp_r_code_text", text)]),
  65 + in_progress then (sql_query, binds)
  66 + }.
  67 +
  68 +
  69 +
  70 + bind_Int(":smtp_r_code", code),
  71 + bind_String(":smtp_r_enhanced_code", enhanced),
  72 + binf_String(":smtp_r_code_text", text),
  73 + ],
  74 +
  75 +public define Send_Status
  76 + to_Send_Status
  77 + (
  78 + String status,
  79 + Int code,
  80 + String enhanced_status,
  81 + String message,
  82 + )=
  83 + if status = "READY" then ready
  84 + else if status = "FINISHED" then finished
  85 + else if status = "TIMEOUT" then timeout
  86 + else if status = "GENERAL_ERROR" then general_error
  87 + else if status = "ERROR" then error(code, enhanced_status, message)
  88 + else if status = "WARNING" then warning(code, enhanced_status, message)
  89 + else if status = "IN PROGRESS" then in_progress
  90 + else ready.
  91 +
  92 +public define String
  93 + to_image
  94 + (
  95 + Send_Status status,
  96 + )=
  97 + if status is
  98 + {
  99 + ready then "/icons/16x16/status_ready.png",
  100 + finished then "/icons/16x16/status_valid.png",
  101 + timeout then "/icons/16x16/status_error.png",
  102 + general_error then "/icons/16x16/status_error.png",
  103 + error(_,_,_) then "/icons/16x16/status_error.png",
  104 + warning(_,_,_) then "/icons/16x16/status_sandglass.png",
  105 + in_progress then "/icons/16x16/status_processing_16x16.gif"
  106 + }.
  107 +
  108 +public define Send_Status
  109 + to_Send_Status
  110 + (
  111 + Result(SmtpClientResult, One) result
  112 + )=
  113 + if result is
  114 + {
  115 + error(smtp_result) then
  116 + if smtp_result is
  117 + {
  118 + error then warning(440, "", "Communication error"),
  119 + timeout then warning(441, "", "Communication timeout"),
  120 + no_auth_method then error(500, "", "Can't find any suitable authentication method"),
  121 + bad_reply then error(500, "", "Bad reply from server"),
  122 + reply(code, enhanced_st, lines) then
  123 + with join_lines = join(implode([13,10]),lines),
  124 + if code >= 400 & code < 500 then
  125 + warning(code, enhanced_st, join_lines)
  126 + else
  127 + error(code, enhanced_st, join_lines)
  128 + },
  129 + ok(_) then
  130 + finished
  131 + }.
... ...
mail/tools.anubis 0 → 100644
  1 +/*
  2 + * Created by PyramIDE.
  3 + * User: フランスのトトロ
  4 + * Date: 17/05/2015
  5 + * Time: 01:27
  6 + * © Calexium
  7 + */
  8 +
  9 +transmit tools/basis.anubis
  10 +transmit system/string.anubis
  11 +
  12 +define Maybe(String)
  13 + day_name
  14 + (
  15 + Int day_num
  16 + )=
  17 + if day_num = 1 then success("Mon")
  18 + else if day_num = 2 then success("Tue")
  19 + else if day_num = 3 then success("Wed")
  20 + else if day_num = 4 then success("Thu")
  21 + else if day_num = 5 then success("Fri")
  22 + else if day_num = 6 then success("Sat")
  23 + else if day_num = 7 then success("Sun")
  24 + else failure
  25 + .
  26 +
  27 +define Maybe(String)
  28 + month_name
  29 + (
  30 + Int month_num
  31 + )=
  32 + if month_num = 1 then success("Jan")
  33 + else if month_num = 2 then success("Feb")
  34 + else if month_num = 3 then success("Mar")
  35 + else if month_num = 4 then success("Apr")
  36 + else if month_num = 5 then success("May")
  37 + else if month_num = 6 then success("Jun")
  38 + else if month_num = 7 then success("Jul")
  39 + else if month_num = 8 then success("Aug")
  40 + else if month_num = 9 then success("Sep")
  41 + else if month_num = 10 then success("Oct")
  42 + else if month_num = 11 then success("Nov")
  43 + else if month_num = 12 then success("Dec")
  44 + else failure
  45 + .
  46 +
  47 +public define String
  48 + str_utime_send_mail
  49 + (
  50 + UTime t
  51 + ) =
  52 + with date_send = convert_time(t.seconds),
  53 + if day_name(date_send.week_day) is
  54 + {
  55 + failure then "",
  56 + success(the_day_name) then the_day_name + ", "
  57 + }+
  58 + date_send.day + " " +
  59 + if month_name(date_send.month) is
  60 + {
  61 + failure then to_decimal(date_send.month),
  62 + success(the_month_name) then the_month_name
  63 + }+ " " +
  64 + date_send.year + " " +
  65 + zero_pad_n(2, date_send.hour) + ":" + zero_pad_n(2, date_send.minute) + ":" + zero_pad_n(2, date_send.second)
  66 + //+ " +0000"
  67 + .
  68 +
  69 +public define String
  70 + get_rfc822_date_format
  71 + =
  72 + str_utime_send_mail(unow).
... ...