Commit e1285ef5dee13ddb79fc00d3fe61dc1695029bef
1 parent
f24835f8
Add Email_Address type into send mail
Showing
2 changed files
with
70 additions
and
2 deletions
Show diff stats
mail/send_mail.anubis
| ... | ... | @@ -37,7 +37,6 @@ define Int _sendmail_time_out = 300. //5 minutes of timeout |
| 37 | 37 | |
| 38 | 38 | public type Smtp_Recipient: |
| 39 | 39 | smtp_recipient(String email, //email address of the recipient |
| 40 | - | |
| 41 | 40 | Send_Tries nb_tries, |
| 42 | 41 | Int uid, //parameter used by handle_status (mail_uid) |
| 43 | 42 | Int uid2 //same (contact_id) | ... | ... |
mail/send_mail_type.anubis
| ... | ... | @@ -9,8 +9,10 @@ |
| 9 | 9 | read system/string.anubis |
| 10 | 10 | read system/data_io.anubis |
| 11 | 11 | read tools/basis.anubis |
| 12 | - | |
| 12 | +read web/mime.anubis | |
| 13 | 13 | read calexium_lib/mail/smtp_client.anubis |
| 14 | +transmit types/generated/email_address.anubis | |
| 15 | +transmit types/generated/email_to_send.anubis | |
| 14 | 16 | |
| 15 | 17 | public type Str_HostName: |
| 16 | 18 | str_host_name(String str). |
| ... | ... | @@ -144,3 +146,70 @@ public define Send_Status |
| 144 | 146 | ok(_) then |
| 145 | 147 | finished |
| 146 | 148 | }. |
| 149 | + | |
| 150 | + /***** Email_Address utilities *****/ | |
| 151 | + | |
| 152 | +public define Email_Address | |
| 153 | + email_address | |
| 154 | + ( | |
| 155 | + String address_only | |
| 156 | + )= | |
| 157 | + email_address("", address_only) | |
| 158 | +. | |
| 159 | + | |
| 160 | +public define String | |
| 161 | + to_String | |
| 162 | + ( | |
| 163 | + Email_Address email_addr | |
| 164 | + )= | |
| 165 | + with string_name = | |
| 166 | + if email_addr.name = "" then | |
| 167 | + "" | |
| 168 | + else | |
| 169 | + to_MIME_text("UTF-8", email_addr.name) + " ", | |
| 170 | + | |
| 171 | + string_name + "<" + email_addr.address + ">" | |
| 172 | +. | |
| 173 | + | |
| 174 | +public define Email_Address | |
| 175 | + to_Email_Address | |
| 176 | + ( | |
| 177 | + String header_address //email header in decoded version | |
| 178 | + )= | |
| 179 | + if split_by_token(header_address, '<') is | |
| 180 | + { | |
| 181 | + [] then email_address("",""), | |
| 182 | + [first . t] then | |
| 183 | + if t is | |
| 184 | + { | |
| 185 | + [] then email_address("", trim_tokens(first,['<','>',' '])), | |
| 186 | + [second . t] then email_address(first, trim_tokens(second,['<','>',' '])) | |
| 187 | + } | |
| 188 | + } | |
| 189 | +. | |
| 190 | + | |
| 191 | +public define String | |
| 192 | + String s + Email_Address email_addr = | |
| 193 | + s + to_String(email_addr) | |
| 194 | +. | |
| 195 | + | |
| 196 | +public define String | |
| 197 | + Email_Address email_addr +String s = | |
| 198 | + to_String(email_addr) + s | |
| 199 | +. | |
| 200 | + | |
| 201 | +public define Maybe((String, String)) | |
| 202 | + extract_user_domain | |
| 203 | + ( | |
| 204 | + Email_Address email_addr | |
| 205 | + )= | |
| 206 | + extract_user_domain(email_addr.address) | |
| 207 | +. | |
| 208 | + | |
| 209 | +public define Maybe(String) | |
| 210 | + extract_domain_name | |
| 211 | + ( | |
| 212 | + Email_Address email_addr | |
| 213 | + )= | |
| 214 | + extract_domain_name(email_addr.address) | |
| 215 | +. | ... | ... |