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
|
||||
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
|
||||
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)
|
||||
|
||||
(import util-set-list)
|
||||
|
|
|
@ -330,7 +330,8 @@ util-proc.o: util-proc.import.scm
|
|||
util-proc.import.scm: $(UTIL-PROC-SOURCES)
|
||||
|
||||
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.import.scm: $(UTIL-MAIL-SOURCES)
|
||||
|
|
|
@ -31,4 +31,5 @@
|
|||
util-format
|
||||
util-tag
|
||||
util-string
|
||||
util-mail
|
||||
)
|
||||
|
|
|
@ -25,8 +25,11 @@
|
|||
|
||||
(declare (unit util-mail))
|
||||
|
||||
(module
|
||||
(import duck)
|
||||
|
||||
(module*
|
||||
util-mail
|
||||
#:doc ("A simple wrapper module to send emails from UNIX system.")
|
||||
(
|
||||
*mailto-override*
|
||||
send-mail
|
||||
|
@ -38,10 +41,17 @@
|
|||
(chicken string)
|
||||
util-io
|
||||
util-utf8
|
||||
util-string)
|
||||
util-string
|
||||
racket-kwargs)
|
||||
|
||||
;; 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
|
||||
(define (encode-subject subj)
|
||||
|
@ -52,14 +62,17 @@
|
|||
subj))
|
||||
|
||||
;; Sends an email using the UNIX mail(1) utility.
|
||||
(define (send-mail body-lines . args)
|
||||
(let ((from (get-keyword #:from args))
|
||||
(to (get-keyword #:to args))
|
||||
(subject (get-keyword #:subject args)))
|
||||
(when (not to)
|
||||
(error 'send-mail "requires #:to argument"))
|
||||
(when (not subject)
|
||||
(error 'send-mail "requires #:subject argument"))
|
||||
(define*/doc (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.")
|
||||
(let* ((tos (if (list? to)
|
||||
to
|
||||
(list to)))
|
||||
|
@ -73,6 +86,6 @@
|
|||
'())
|
||||
(list "-s" (encode-subject subject))
|
||||
real-tos)
|
||||
body-lines))))
|
||||
body-lines)))
|
||||
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue