Skip to content

Commit 5dab0cd

Browse files
committed
FEAT: including first version of higher level mail scheme for sending emails
So far it is possible to use Rebol2 like `send` function: ```rebol import 'mail ; sending just a plain message: send you@example.com "Hello^/ this is just simple message" ; sending single file: send you@example.com %path/to/file ; sending more files: send you@example.com [%path/to/file1 %path/to/file2] ; sending more complete message: send friends [ subject: "Invitation" message: "Hi friends, check the invitation!" attach: %path/to/invitation ] ``` It is also possible to use the scheme directly, like: ```rebol write mail:// [ From: ["Oldes" oldes@example.com] To: ["Bob" bob@example.com "Eva" eva@example.com] subject: "Invitation" message: "Hi friends, check the invitation!" attach: %path/to/invitation ] ``` In all cases above is expected, that `system/user` is configured and that there is available `smtp` specification (host/user/password) under `system/users/data`! This is still just the initial version. So far it works only in sync mode, but the idea is, to be able use it in async mode as well (for example from a server instance).
1 parent f842682 commit 5dab0cd

File tree

4 files changed

+481
-6
lines changed

4 files changed

+481
-6
lines changed

make/rebol3.nest

+10-6
Original file line numberDiff line numberDiff line change
@@ -730,16 +730,13 @@ include-codec-plist: [mezz-lib-files: %mezz/codec-plist.reb ]
730730
include-codec-swf: [mezz-lib-files: %mezz/codec-swf.reb ]
731731
include-codec-wav: [mezz-lib-files: %mezz/codec-wav.reb ]
732732
include-codec-unixtime: [mezz-lib-files: %mezz/codec-unixtime.reb ]
733-
include-codec-mime-field: [mezz-lib-files: %mezz/codec-mime-field.reb ]
734-
include-codec-quoted-printable: [mezz-lib-files: %mezz/codec-quoted-printable.reb]
735733
; mezzanines:
736734
include-mezz-ansi: [mezz-lib-files: %mezz/mezz-ansi.reb ]
737735
include-mezz-date: [mezz-lib-files: %mezz/mezz-date.reb ]
738736
include-mezz-colors: [mezz-lib-files: %mezz/mezz-colors.reb ]
739737
; protocols:
740738
include-prot-whois: [mezz-prot-files: %mezz/prot-whois.reb ]
741739
include-prot-mysql: [mezz-prot-files: %mezz/prot-mysql.reb ]
742-
include-prot-smtp: [mezz-prot-files: %mezz/prot-smtp.reb :include-prot-tls]
743740
include-prot-https: [mezz-prot-files: %mezz/prot-http.reb :include-prot-tls]
744741
include-prot-tls: [
745742
:include-bincode
@@ -750,6 +747,15 @@ include-prot-tls: [
750747
mezz-prot-files: %mezz/prot-tls.reb
751748
]
752749

750+
include-mail: [
751+
:include-prot-tls
752+
mezz-prot-files: %mezz/prot-smtp.reb
753+
mezz-lib-files: %mezz/prot-mail.reb
754+
mezz-lib-files: %mezz/codec-mime-field.reb
755+
mezz-lib-files: %mezz/codec-mime-types.reb
756+
mezz-lib-files: %mezz/codec-quoted-printable.reb
757+
]
758+
753759

754760
include-prebol: [mezz-lib-files: %modules/prebol.reb ]
755761

@@ -764,16 +770,14 @@ include-rebol-core: [
764770
:include-cryptography
765771
:include-bincode
766772
:include-iconv
773+
:include-mail
767774
:include-prot-https
768-
:include-prot-smtp
769775

770776
:include-codec-unixtime
771777
:include-codec-ar
772778
:include-codec-gzip
773779
:include-codec-zip
774780
:include-codec-tar
775-
:include-codec-mime-field
776-
:include-codec-quoted-printable
777781

778782
config: INCLUDE_SHA224
779783
config: INCLUDE_SHA384

src/boot/sysobj.reb

+4
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ options: object [ ; Options supplied to REBOL during startup
5454
module-paths: [%./]
5555
default-suffix: %.reb ; Used by IMPORT if no suffix is provided
5656
file-types: []
57+
mime-types: none
5758
result-types: none
5859

5960
; verbosity of logs per service (codecs, schemes)
@@ -152,6 +153,7 @@ modules: object [
152153
;; optional modules, protocol and codecs
153154
httpd: https://src.rebol.tech/modules/httpd.reb
154155
prebol: https://src.rebol.tech/modules/prebol.reb
156+
mail: https://src.rebol.tech/mezz/prot-mail.reb
155157
mysql: https://src.rebol.tech/mezz/prot-mysql.reb
156158
csv: https://src.rebol.tech/mezz/codec-csv.reb
157159
ico: https://src.rebol.tech/mezz/codec-ico.reb
@@ -163,6 +165,7 @@ modules: object [
163165
bbcode: https://src.rebol.tech/mezz/codec-bbcode.reb
164166
html-entities: https://src.rebol.tech/mezz/codec-html-entities.reb
165167
mime-field: https://src.rebol.tech/mezz/codec-mime-field.reb
168+
mime-types: https://src.rebol.tech/mezz/codec-mime-types.reb
166169
quoted-printable: https://src.rebol.tech/mezz/codec-quoted-printable.reb
167170
;; and..
168171
window: none ;- internal extension for gui (on Windows so far!)
@@ -185,6 +188,7 @@ ports: object [
185188
input: ; Port for user input.
186189
output: ; Port for user output
187190
echo: ; Port for echoing output
191+
mail: ; Port for sending and receiving emails
188192
system: ; Port for system events
189193
callback: none ; Port for callback events
190194
; serial: none ; serial device name block

src/mezz/codec-mime-types.reb

+128
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
REBOL [
2+
Name: mime-types
3+
Type: module
4+
Options: [delay]
5+
Version: 1.0.0
6+
Date: 13-Jul-2022
7+
File: %mezz-mime-types.reb
8+
Title: "Codec: MIME (media) types"
9+
Author: @Oldes
10+
Rights: "Copyright (C) 2022 Oldes. All rights reserved."
11+
License: MIT
12+
Exports: [mime-type?]
13+
]
14+
15+
; temporary function used just for the initialization...
16+
mime-type?: func[/local types type files][
17+
unless find system/options 'mime-types [
18+
put system/options 'mime-types #[none]
19+
]
20+
types: any [system/options/mime-types make map! 110]
21+
parse [
22+
;- collected from https://github.com/nginx/nginx/blob/master/conf/mime.types
23+
;; full list: https://www.iana.org/assignments/media-types/media-types.xhtml
24+
"text/html" %.html %.htm %.shtml
25+
"text/css" %.css
26+
"text/xml" %.xml
27+
"text/mathml" %.mml
28+
"text/plain" %.txt
29+
"text/vnd.sun.j2me.app-descriptor" %.jad
30+
"text/vnd.wap.wml" %.wml
31+
"text/x-component" %.htc
32+
"image/gif" %.gif
33+
"image/jpeg" %.jpeg %.jpg
34+
"image/avif" %.avif
35+
"image/png" %.png
36+
"image/svg+xml" %.svg %.svgz
37+
"image/tiff" %.tif %.tiff
38+
"image/vnd.wap.wbmp" %.wbmp
39+
"image/webp" %.webp
40+
"image/x-icon" %.ico
41+
"image/x-jng" %.jng
42+
"image/x-ms-bmp" %.bmp
43+
"font/woff" %.woff
44+
"font/woff2" %.woff2
45+
"application/javascript" %.js
46+
"application/atom+xml" %.atom
47+
"application/rss+xml" %.rss
48+
"application/java-archive" %.jar %.war %.ear
49+
"application/json" %.json
50+
"application/mac-binhex40" %.hqx
51+
"application/msword" %.doc
52+
"application/pdf" %.pdf
53+
"application/postscript" %.ps %.eps %.ai
54+
"application/rtf" %.rtf
55+
"application/vnd.apple.mpegurl" %.m3u8
56+
"application/vnd.google-earth.kml+xml" %.kml
57+
"application/vnd.google-earth.kmz" %.kmz
58+
"application/vnd.ms-excel" %.xls
59+
"application/vnd.ms-fontobject" %.eot
60+
"application/vnd.ms-powerpoint" %.ppt
61+
"application/vnd.oasis.opendocument.graphics" %.odg
62+
"application/vnd.oasis.opendocument.presentation" %.odp
63+
"application/vnd.oasis.opendocument.spreadsheet" %.ods
64+
"application/vnd.oasis.opendocument.text" %.odt
65+
"application/vnd.openxmlformats-officedocument.presentationml.presentation" %.pptx
66+
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" %.xlsx
67+
"application/vnd.openxmlformats-officedocument.wordprocessingml.document" %.docx
68+
"application/vnd.wap.wmlc" %.wmlc
69+
"application/wasm" %.wasm
70+
"application/x-7z-compressed" %.7z
71+
"application/x-cocoa" %.cco
72+
"application/x-java-archive-diff" %.jardiff
73+
"application/x-java-jnlp-file" %.jnlp
74+
"application/x-makeself" %.run
75+
"application/x-perl" %.pl %.pm
76+
"application/x-pilot" %.prc %.pdb
77+
"application/x-rar-compressed" %.rar
78+
"application/x-redhat-package-manager" %.rpm
79+
"application/x-sea" %.sea
80+
"application/x-shockwave-flash" %.swf
81+
"application/x-stuffit" %.sit
82+
"application/x-tcl" %.tcl %.tk
83+
"application/x-x509-ca-cert" %.der %.pem %.crt
84+
"application/x-xpinstall" %.xpi
85+
"application/xhtml+xml" %.xhtml
86+
"application/xspf+xml" %.xspf
87+
"application/zip" %.zip
88+
"application/octet-stream" %.bin %.exe %.dll
89+
"application/octet-stream" %.deb
90+
"application/octet-stream" %.dmg
91+
"application/octet-stream" %.iso %.img
92+
"application/octet-stream" %.msi %.msp %.msm
93+
"audio/midi" %.mid %.midi %.kar
94+
"audio/mpeg" %.mp3
95+
"audio/ogg" %.ogg
96+
"audio/x-m4a" %.m4a
97+
"audio/x-realaudio" %.ra
98+
"video/3gpp" %.3gpp %.3gp
99+
"video/mp2t" %.ts
100+
"video/mp4" %.mp4
101+
"video/mpeg" %.mpeg %.mpg
102+
"video/quicktime" %.mov
103+
"video/webm" %.webm
104+
"video/x-flv" %.flv
105+
"video/x-m4v" %.m4v
106+
"video/x-mng" %.mng
107+
"video/x-ms-asf" %.asx %.asf
108+
"video/x-ms-wmv" %.wmv
109+
"video/x-msvideo" %.avi
110+
"message/rfc822" %.eml ;=> https://www.w3.org/Protocols/rfc1341/7_3_Message.html
111+
][
112+
some [
113+
set type string! copy files some file! (
114+
foreach file files [ types/:file: type ]
115+
)
116+
]
117+
]
118+
system/options/mime-types: :types
119+
]
120+
; initialize...
121+
mime-type?
122+
; redefine the function into something useful...
123+
mime-type?: func[
124+
"Returns file's MIME's content-type"
125+
file [file!]
126+
][
127+
select system/options/mime-types find/last file #"."
128+
]

0 commit comments

Comments
 (0)