Commit 0bc9bea2e565928be5799db673d608b1e1d08126
1 parent
051e674f
[+] File_ref type which is use by send_mail
Showing
3 changed files
with
114 additions
and
14 deletions
Show diff stats
ds_files/ds_types.anubis
| @@ -106,7 +106,16 @@ public define List(DS_Type_File) calexium_lib_types_description = | @@ -106,7 +106,16 @@ public define List(DS_Type_File) calexium_lib_types_description = | ||
| 106 | // String from, | 106 | // String from, |
| 107 | // String reply_to | 107 | // String reply_to |
| 108 | // ). | 108 | // ). |
| 109 | - | 109 | + ds_type("File_ref", [ |
| 110 | + alternative("file_ref", [ | ||
| 111 | + component(string, "path", comment("access ptah to the file on the original machine")), | ||
| 112 | + component(string, "name", comment("name of the file")), | ||
| 113 | + component(ds_type("MIME"), "mime", comment("mime type of the file")), | ||
| 114 | + component(string, "key", comment("key is a SHA1 gave by sender to certify it when it will be downloaded")), | ||
| 115 | + component(int, "size", comment("size of the file in Bytes")) | ||
| 116 | + ]) | ||
| 117 | + ]), | ||
| 118 | + | ||
| 110 | ds_type("Email_to_send", [ | 119 | ds_type("Email_to_send", [ |
| 111 | alternative("data_to_send", [ | 120 | alternative("data_to_send", [ |
| 112 | component(ds_type("Email_Address"), "from", comment("email sent from that sender")), | 121 | component(ds_type("Email_Address"), "from", comment("email sent from that sender")), |
| @@ -115,7 +124,7 @@ public define List(DS_Type_File) calexium_lib_types_description = | @@ -115,7 +124,7 @@ public define List(DS_Type_File) calexium_lib_types_description = | ||
| 115 | component(list, ds_type("Email_Address"), "bcc", comment("email sent as blank carbon copy to that list of recipients")), | 124 | component(list, ds_type("Email_Address"), "bcc", comment("email sent as blank carbon copy to that list of recipients")), |
| 116 | component(string, "subject", comment("subject of email. Supposed to be UTF8")), | 125 | component(string, "subject", comment("subject of email. Supposed to be UTF8")), |
| 117 | component(string, "content", comment("content of the email")), | 126 | component(string, "content", comment("content of the email")), |
| 118 | - component(list, string, "files", comment("list of files")), | 127 | + component(list, ds_type("File_ref"), "attached_files", comment("list of files to attach to this email")), |
| 119 | component(bool, "send_copy",comment("send copy to sender by bcc (useful when the email is sent by an automat)")), | 128 | component(bool, "send_copy",comment("send copy to sender by bcc (useful when the email is sent by an automat)")), |
| 120 | component(string, "reply_to", comment("reply to !!")) | 129 | component(string, "reply_to", comment("reply to !!")) |
| 121 | ]) | 130 | ]) |
mail/types/generated/email_to_send.anubis
| 1 | -/* | 1 | +/* |
| 2 | * Created by 伝作 (Densaku). | 2 | * Created by 伝作 (Densaku). |
| 3 | * Types & Messages generator written by フランスのトトロ aka (David RENÉ) | 3 | * Types & Messages generator written by フランスのトトロ aka (David RENÉ) |
| 4 | - * Date: 2018-12-07 | ||
| 5 | - * Time: 01:14:06 | 4 | + * Date: 2019-05-17 |
| 5 | + * Time: 19:05:20 | ||
| 6 | * | 6 | * |
| 7 | */ | 7 | */ |
| 8 | 8 | ||
| @@ -10,7 +10,8 @@ transmit system/muscle.anubis | @@ -10,7 +10,8 @@ transmit system/muscle.anubis | ||
| 10 | transmit system/convert.anubis | 10 | transmit system/convert.anubis |
| 11 | transmit tools/basis.anubis | 11 | transmit tools/basis.anubis |
| 12 | 12 | ||
| 13 | -transmit calexium_lib/mail/types/generated/email_address.anubis | 13 | +transmit types/generated/file_ref.anubis |
| 14 | +transmit types/generated/email_address.anubis | ||
| 14 | 15 | ||
| 15 | 16 | ||
| 16 | 17 | ||
| @@ -22,7 +23,7 @@ public type Email_to_send: | @@ -22,7 +23,7 @@ public type Email_to_send: | ||
| 22 | List(Email_Address) bcc, //email sent as blank carbon copy to that list of recipients | 23 | List(Email_Address) bcc, //email sent as blank carbon copy to that list of recipients |
| 23 | String subject, //subject of email. Supposed to be UTF8 | 24 | String subject, //subject of email. Supposed to be UTF8 |
| 24 | String content, //content of the email | 25 | String content, //content of the email |
| 25 | - List(String) files, //list of files | 26 | + List(File_ref) attached_files, //list of files to attach to this email |
| 26 | Bool send_copy, //send copy to sender by bcc (useful when the email is sent by an automat) | 27 | Bool send_copy, //send copy to sender by bcc (useful when the email is sent by an automat) |
| 27 | String reply_to //reply to !! | 28 | String reply_to //reply to !! |
| 28 | ) | 29 | ) |
| @@ -42,7 +43,7 @@ public define Message | @@ -42,7 +43,7 @@ public define Message | ||
| 42 | if _email_to_send is | 43 | if _email_to_send is |
| 43 | { | 44 | { |
| 44 | //Alternative data_to_send | 45 | //Alternative data_to_send |
| 45 | - data_to_send(_from, __to, __cc, __bcc, _subject, _content, __files, _send_copy, _reply_to) then | 46 | + data_to_send(_from, __to, __cc, __bcc, _subject, _content, __attached_files, _send_copy, _reply_to) then |
| 46 | forget(add_string(_email_to_send_message, "__TYPE_ALT__", "data_to_send")); | 47 | forget(add_string(_email_to_send_message, "__TYPE_ALT__", "data_to_send")); |
| 47 | // [type = Email_Address] data_to_send.from | 48 | // [type = Email_Address] data_to_send.from |
| 48 | forget(add_message(_email_to_send_message, "from", to_Message(_from))); | 49 | forget(add_message(_email_to_send_message, "from", to_Message(_from))); |
| @@ -56,8 +57,8 @@ public define Message | @@ -56,8 +57,8 @@ public define Message | ||
| 56 | forget(add_string(_email_to_send_message, "subject", _subject)); | 57 | forget(add_string(_email_to_send_message, "subject", _subject)); |
| 57 | // [type = String] data_to_send.content | 58 | // [type = String] data_to_send.content |
| 58 | forget(add_string(_email_to_send_message, "content", _content)); | 59 | forget(add_string(_email_to_send_message, "content", _content)); |
| 59 | - // [type = List(String)] data_to_send.files | ||
| 60 | - map_forget((String _files) |-> add_string(_email_to_send_message, "files", _files), __files); | 60 | + // [type = List(File_ref)] data_to_send.attached_files |
| 61 | + map_forget((File_ref _attached_files) |-> add_message(_email_to_send_message, "attached_files", to_Message(_attached_files)), __attached_files); | ||
| 61 | // [type = Bool] data_to_send.send_copy | 62 | // [type = Bool] data_to_send.send_copy |
| 62 | forget(add_bool(_email_to_send_message, "send_copy", _send_copy)); | 63 | forget(add_bool(_email_to_send_message, "send_copy", _send_copy)); |
| 63 | // [type = String] data_to_send.reply_to | 64 | // [type = String] data_to_send.reply_to |
| @@ -93,15 +94,16 @@ public define Maybe(Email_to_send) | @@ -93,15 +94,16 @@ public define Maybe(Email_to_send) | ||
| 93 | if find_string(_email_to_send_message, "subject") is {failure then failure, success(_subject_) then | 94 | if find_string(_email_to_send_message, "subject") is {failure then failure, success(_subject_) then |
| 94 | // [type = String] data_to_send.content | 95 | // [type = String] data_to_send.content |
| 95 | if find_string(_email_to_send_message, "content") is {failure then failure, success(_content_) then | 96 | if find_string(_email_to_send_message, "content") is {failure then failure, success(_content_) then |
| 96 | - // [type = List(String)] data_to_send.files | ||
| 97 | - with _files_ = find_string_list(_email_to_send_message, "files"), | 97 | + // [type = List(File_ref)] data_to_send.attached_files |
| 98 | + with mb__attached_files_ = map_escape(( Message msg ) |-> (Maybe(File_ref)) from_Message(msg), find_messages(_email_to_send_message, "attached_files")), | ||
| 99 | + if mb__attached_files_ is {failure then failure, success(_attached_files_) then | ||
| 98 | // [type = Bool] data_to_send.send_copy | 100 | // [type = Bool] data_to_send.send_copy |
| 99 | if find_bool(_email_to_send_message, "send_copy") is {failure then failure, success(_send_copy_) then | 101 | if find_bool(_email_to_send_message, "send_copy") is {failure then failure, success(_send_copy_) then |
| 100 | // [type = String] data_to_send.reply_to | 102 | // [type = String] data_to_send.reply_to |
| 101 | if find_string(_email_to_send_message, "reply_to") is {failure then failure, success(_reply_to_) then | 103 | if find_string(_email_to_send_message, "reply_to") is {failure then failure, success(_reply_to_) then |
| 102 | 104 | ||
| 103 | - success(data_to_send(_from_, _to_, _cc_, _bcc_, _subject_, _content_, _files_, _send_copy_, _reply_to_)) | ||
| 104 | - }}}}}}}}} | 105 | + success(data_to_send(_from_, _to_, _cc_, _bcc_, _subject_, _content_, _attached_files_, _send_copy_, _reply_to_)) |
| 106 | + }}}}}}}}}} | ||
| 105 | else | 107 | else |
| 106 | failure //No valid Alternative found ! | 108 | failure //No valid Alternative found ! |
| 107 | else | 109 | else |
| 1 | +/* | ||
| 2 | + * Created by 伝作 (Densaku). | ||
| 3 | + * Types & Messages generator written by フランスのトトロ aka (David RENÉ) | ||
| 4 | + * Date: 2019-05-17 | ||
| 5 | + * Time: 19:05:20 | ||
| 6 | + * | ||
| 7 | + */ | ||
| 8 | + | ||
| 9 | +transmit system/muscle.anubis | ||
| 10 | +transmit system/convert.anubis | ||
| 11 | +transmit tools/basis.anubis | ||
| 12 | + | ||
| 13 | +transmit types/generated/mime.anubis | ||
| 14 | + | ||
| 15 | + | ||
| 16 | + | ||
| 17 | +public type File_ref: | ||
| 18 | + file_ref( | ||
| 19 | + String path, //access ptah to the file on the original machine | ||
| 20 | + String name, //name of the file | ||
| 21 | + MIME mime, //mime type of the file | ||
| 22 | + String key, //key is a SHA1 gave by sender to certify it when it will be downloaded | ||
| 23 | + Int size //size of the file in Bytes | ||
| 24 | + ) | ||
| 25 | +. | ||
| 26 | + | ||
| 27 | + File_ref message format | ||
| 28 | + ======================= | ||
| 29 | + | ||
| 30 | + | ||
| 31 | +public define Message | ||
| 32 | + to_Message | ||
| 33 | + ( | ||
| 34 | + File_ref _file_ref | ||
| 35 | + )= | ||
| 36 | + with _file_ref_message = message((Word32)0), // | ||
| 37 | + forget(add_string(_file_ref_message, "__TYPE__", "File_ref")); | ||
| 38 | + if _file_ref is | ||
| 39 | + { | ||
| 40 | + //Alternative file_ref | ||
| 41 | + file_ref(_path, _name, _mime, _key, _size) then | ||
| 42 | + forget(add_string(_file_ref_message, "__TYPE_ALT__", "file_ref")); | ||
| 43 | + // [type = String] file_ref.path | ||
| 44 | + forget(add_string(_file_ref_message, "path", _path)); | ||
| 45 | + // [type = String] file_ref.name | ||
| 46 | + forget(add_string(_file_ref_message, "name", _name)); | ||
| 47 | + // [type = MIME] file_ref.mime | ||
| 48 | + forget(add_message(_file_ref_message, "mime", to_Message(_mime))); | ||
| 49 | + // [type = String] file_ref.key | ||
| 50 | + forget(add_string(_file_ref_message, "key", _key)); | ||
| 51 | + // [type = Int] file_ref.size | ||
| 52 | + forget(add_string(_file_ref_message, "size", to_String(_size))), | ||
| 53 | + | ||
| 54 | + }; | ||
| 55 | + _file_ref_message | ||
| 56 | +. | ||
| 57 | + | ||
| 58 | +public define Maybe(File_ref) | ||
| 59 | + from_Message | ||
| 60 | + ( | ||
| 61 | + Message _file_ref_message | ||
| 62 | + )= | ||
| 63 | + if find_string(_file_ref_message, "__TYPE__") is {failure then failure, success(__type__) then | ||
| 64 | + if find_string(_file_ref_message, "__TYPE_ALT__") is {failure then failure, success(__type_alt__) then | ||
| 65 | + if __type__ = "File_ref" then | ||
| 66 | + //Alternative file_ref | ||
| 67 | + if __type_alt__ = "file_ref" then //Alternative file_ref | ||
| 68 | + // [type = String] file_ref.path | ||
| 69 | + if find_string(_file_ref_message, "path") is {failure then failure, success(_path_) then | ||
| 70 | + // [type = String] file_ref.name | ||
| 71 | + if find_string(_file_ref_message, "name") is {failure then failure, success(_name_) then | ||
| 72 | + // [type = MIME] file_ref.mime | ||
| 73 | + if find_message(_file_ref_message, "mime") is {failure then failure, success(_mime__msg) then | ||
| 74 | + if (Maybe(MIME))from_Message(_mime__msg) is {failure then failure, success(_mime_) then | ||
| 75 | + // [type = String] file_ref.key | ||
| 76 | + if find_string(_file_ref_message, "key") is {failure then failure, success(_key_) then | ||
| 77 | + // [type = Int] file_ref.size | ||
| 78 | + if find_string(_file_ref_message, "size") is {failure then failure, success(__size_) then | ||
| 79 | + if decimal_scan(__size_) is { failure then failure, success(_size_) then | ||
| 80 | + | ||
| 81 | + success(file_ref(_path_, _name_, _mime_, _key_, _size_)) | ||
| 82 | + }}}}}}} | ||
| 83 | + else | ||
| 84 | + failure //No valid Alternative found ! | ||
| 85 | + else | ||
| 86 | + failure //Type not found in message ! | ||
| 87 | + }} | ||
| 88 | +. | ||
| 89 | + |