Skip to content

Commit

Permalink
rde: mail: Add serialization logic to feature-msmtp.
Browse files Browse the repository at this point in the history
  • Loading branch information
abcdw committed Nov 26, 2021
1 parent 7bbe974 commit cb8f195
Showing 1 changed file with 47 additions and 14 deletions.
61 changes: 47 additions & 14 deletions rde/features/mail.scm
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@
#:re-export (l2md-repo))



;;;
;;; Records.
;;;

(define-configuration/no-serialization mail-account
(id
(symbol #f)
Expand Down Expand Up @@ -67,11 +72,6 @@ field."))
(mail-account-pass-cmd mail-account)
(string-append "pass show mail/" (mail-account-fqda mail-account))))

(define (mail-account-smtp-host mail-account)
"smtp.gmail.com")
(define (mail-account-smtp-port mail-account)
587)


(define-configuration/no-serialization mailing-list
(id
Expand All @@ -88,6 +88,12 @@ field."))
(symbol 'l2md)
"Type of application to obtain mailing list."))



;;;
;;; feature-mail-settings.
;;;

(define (list-of-mail-accounts? lst)
(and (list? lst) (not (null? lst)) (every mail-account? lst)))

Expand Down Expand Up @@ -127,6 +133,10 @@ features."
(mailing-lists . ,mailing-lists)
(mail-directory-fn . ,mail-directory-fn)))))


;;;
;;; feature-emacs-message.
;;;

(define* (feature-emacs-message)
"Configure email sending capabilities provided by @file{message.el}."
Expand Down Expand Up @@ -189,8 +199,36 @@ features."
(values `((,f-name . #t)))
(home-services-getter get-home-services)))


;;;
;;; feature-msmtp.
;;;

(define-public %default-msmtp-provider-settings
`((gmail . ((host . "smtp.gmail.com")
(port . 587)))
(generic . #f)))

(define* (feature-msmtp)
(define %default-msmtp-settings
"defaults
tls on
auth on
logfile \"~/.local/var/log/msmtp.log\"\n")

(define (default-msmtp-serializer provider-settings mail-account)
(let* ((account-type (mail-account-type mail-account))
(settings (assoc-ref provider-settings account-type)))
(apply
string-append
(map (lambda (p)
(format #f "~a ~a\n" (car p) (cdr p)))
settings))))

(define* (feature-msmtp
#:key
(msmtp-settings %default-msmtp-settings)
(msmtp-provider-settings %default-msmtp-provider-settings)
(msmtp-serializer default-msmtp-serializer))
"Configure msmtp MTA."
(define (get-home-services config)
(require-value 'mail-accounts config
Expand All @@ -208,21 +246,16 @@ features."
(apply
mixed-text-file
"msmtp-config"
"defaults
tls on
auth on
logfile \"~/.local/var/log/msmtp.log\"\n"
msmtp-settings
(map
(lambda (acc)
(display acc)
(string-append
"\n"
"account " (symbol->string (mail-account-id acc)) "\n"
"host " (mail-account-smtp-host acc) "\n"
"port " (number->string (mail-account-smtp-port acc)) "\n"
"from " (mail-account-fqda acc) "\n"
"user " (mail-account-fqda acc) "\n"
"passwordeval " (mail-account-get-pass-cmd acc) "\n"))
"passwordeval " (mail-account-get-pass-cmd acc) "\n"
(msmtp-serializer msmtp-provider-settings acc)))
mail-accs))
)))
(simple-service
Expand Down

0 comments on commit cb8f195

Please sign in to comment.