send_mail_type.anubis
4.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/*
* 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 Str_HostName:
str_host_name(String str).
public type Str_Sender:
str_sender(String str).
public type Str_Recipient:
str_recipient(String str).
public type Str_UID:
str_UID(String str).
public type Send_Tries:
send_tries(Int number).
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_sandglass.png",
general_error then "/icons/16x16/status_error.png",
error(_,_,_) then "/icons/16x16/status_error.png",
warning(_,_,_) then "/icons/16x16/status_warning.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
}.