Duck util-mail.
This commit is contained in:
parent
23db356dec
commit
b9a563d4ac
5 changed files with 73 additions and 49 deletions
|
@ -405,3 +405,35 @@ quoted-printable sequences.
|
||||||
|
|
||||||
Returns the ```str``` with all characters converted to upper case
|
Returns the ```str``` with all characters converted to upper case
|
||||||
using ```char-upcase```. Does not work with UTF-8.
|
using ```char-upcase```. Does not work with UTF-8.
|
||||||
|
|
||||||
|
## util-mail [module]
|
||||||
|
|
||||||
|
(import util-mail)
|
||||||
|
|
||||||
|
A simple wrapper module to send emails from UNIX system.
|
||||||
|
|
||||||
|
### *mailto-override* [parameter]
|
||||||
|
|
||||||
|
(define *mailto-override* (make-parameter #f))
|
||||||
|
(*mailto-override*)
|
||||||
|
(*mailto-override* email)
|
||||||
|
|
||||||
|
* ```email``` - email address string
|
||||||
|
|
||||||
|
If this parameter is non-```#f```, all outgoing emails are actually
|
||||||
|
sent to the address stored within.
|
||||||
|
|
||||||
|
### send-mail [procedure]
|
||||||
|
|
||||||
|
(send-mail body-lines
|
||||||
|
#:from (from #f)
|
||||||
|
#:to to
|
||||||
|
#:subject subject)
|
||||||
|
|
||||||
|
* ```body-lines``` - lines of the email
|
||||||
|
* ```from``` - email address from string
|
||||||
|
* ```to``` - email address to string
|
||||||
|
* ```subject``` - email subject string
|
||||||
|
|
||||||
|
Sends email using mail(1) command. The arguments ```#:to``` and
|
||||||
|
```#:subject``` are mandatory. Argument ```#:from``` is optional.
|
||||||
|
|
23
doc/utils.md
23
doc/utils.md
|
@ -125,29 +125,6 @@ Returns ```#t``` if both dictionaries contain the same keys and their
|
||||||
values are equal according to the provided ```equality?``` predicate
|
values are equal according to the provided ```equality?``` predicate
|
||||||
which defaults to ```equal?```.
|
which defaults to ```equal?```.
|
||||||
|
|
||||||
### Mail
|
|
||||||
|
|
||||||
(import util-mail)
|
|
||||||
|
|
||||||
A simple wrapper module to send emails from UNIX system.
|
|
||||||
|
|
||||||
(*mailto-override* [email])
|
|
||||||
|
|
||||||
* ```email``` - email address string
|
|
||||||
|
|
||||||
If this parameter is non-```#f```, all outgoing emails are actually
|
|
||||||
sent to the address stored within.
|
|
||||||
|
|
||||||
(send-mail body-lines [#:from from] [#:to to] [#:subject subject])
|
|
||||||
|
|
||||||
* ```body-lines``` - lines of the email
|
|
||||||
* ```from``` - email address from string
|
|
||||||
* ```to``` - email address to string
|
|
||||||
* ```subject``` - email subject string
|
|
||||||
|
|
||||||
Sends email using mail(1) command. The arguments ```#:to``` and
|
|
||||||
```#:subject``` are mandatory. Argument ```#:from``` is optional.
|
|
||||||
|
|
||||||
### Set (List)
|
### Set (List)
|
||||||
|
|
||||||
(import util-set-list)
|
(import util-set-list)
|
||||||
|
|
|
@ -330,7 +330,8 @@ util-proc.o: util-proc.import.scm
|
||||||
util-proc.import.scm: $(UTIL-PROC-SOURCES)
|
util-proc.import.scm: $(UTIL-PROC-SOURCES)
|
||||||
|
|
||||||
UTIL-MAIL-SOURCES=util-mail.scm util-io.import.scm \
|
UTIL-MAIL-SOURCES=util-mail.scm util-io.import.scm \
|
||||||
util-string.import.scm util-utf8.import.scm
|
util-string.import.scm util-utf8.import.scm \
|
||||||
|
racket-kwargs.import.scm duck.import.scm
|
||||||
|
|
||||||
util-mail.o: util-mail.import.scm
|
util-mail.o: util-mail.import.scm
|
||||||
util-mail.import.scm: $(UTIL-MAIL-SOURCES)
|
util-mail.import.scm: $(UTIL-MAIL-SOURCES)
|
||||||
|
|
|
@ -31,4 +31,5 @@
|
||||||
util-format
|
util-format
|
||||||
util-tag
|
util-tag
|
||||||
util-string
|
util-string
|
||||||
|
util-mail
|
||||||
)
|
)
|
||||||
|
|
|
@ -25,8 +25,11 @@
|
||||||
|
|
||||||
(declare (unit util-mail))
|
(declare (unit util-mail))
|
||||||
|
|
||||||
(module
|
(import duck)
|
||||||
|
|
||||||
|
(module*
|
||||||
util-mail
|
util-mail
|
||||||
|
#:doc ("A simple wrapper module to send emails from UNIX system.")
|
||||||
(
|
(
|
||||||
*mailto-override*
|
*mailto-override*
|
||||||
send-mail
|
send-mail
|
||||||
|
@ -38,10 +41,17 @@
|
||||||
(chicken string)
|
(chicken string)
|
||||||
util-io
|
util-io
|
||||||
util-utf8
|
util-utf8
|
||||||
util-string)
|
util-string
|
||||||
|
racket-kwargs)
|
||||||
|
|
||||||
;; All emails go to this override
|
;; All emails go to this override
|
||||||
(define *mailto-override* (make-parameter #f))
|
(define/doc *mailto-override*
|
||||||
|
("* ```email``` - email address string
|
||||||
|
|
||||||
|
If this parameter is non-```#f```, all outgoing emails are actually
|
||||||
|
sent to the address stored within.")
|
||||||
|
email
|
||||||
|
(make-parameter #f))
|
||||||
|
|
||||||
;; Ensures the subject has proper encoding
|
;; Ensures the subject has proper encoding
|
||||||
(define (encode-subject subj)
|
(define (encode-subject subj)
|
||||||
|
@ -52,27 +62,30 @@
|
||||||
subj))
|
subj))
|
||||||
|
|
||||||
;; Sends an email using the UNIX mail(1) utility.
|
;; Sends an email using the UNIX mail(1) utility.
|
||||||
(define (send-mail body-lines . args)
|
(define*/doc (send-mail body-lines
|
||||||
(let ((from (get-keyword #:from args))
|
#:from (from #f)
|
||||||
(to (get-keyword #:to args))
|
#:to to
|
||||||
(subject (get-keyword #:subject args)))
|
#:subject subject)
|
||||||
(when (not to)
|
("* ```body-lines``` - lines of the email
|
||||||
(error 'send-mail "requires #:to argument"))
|
* ```from``` - email address from string
|
||||||
(when (not subject)
|
* ```to``` - email address to string
|
||||||
(error 'send-mail "requires #:subject argument"))
|
* ```subject``` - email subject string
|
||||||
(let* ((tos (if (list? to)
|
|
||||||
to
|
Sends email using mail(1) command. The arguments ```#:to``` and
|
||||||
(list to)))
|
```#:subject``` are mandatory. Argument ```#:from``` is optional.")
|
||||||
(real-tos (if (*mailto-override*)
|
(let* ((tos (if (list? to)
|
||||||
(list (*mailto-override*))
|
to
|
||||||
tos)))
|
(list to)))
|
||||||
(apply process-send/recv
|
(real-tos (if (*mailto-override*)
|
||||||
"mail"
|
(list (*mailto-override*))
|
||||||
(append (if from
|
tos)))
|
||||||
(list "-r" from)
|
(apply process-send/recv
|
||||||
'())
|
"mail"
|
||||||
(list "-s" (encode-subject subject))
|
(append (if from
|
||||||
real-tos)
|
(list "-r" from)
|
||||||
body-lines))))
|
'())
|
||||||
|
(list "-s" (encode-subject subject))
|
||||||
|
real-tos)
|
||||||
|
body-lines)))
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue