From: ludo@gnu.org (Ludovic Courtès)
To: Ricardo Wurmus <rekado@elephly.net>
Cc: 32514@debbugs.gnu.org
Subject: bug#32514: mailutils Guile bindings are broken
Date: Fri, 24 Aug 2018 12:39:24 +0200 [thread overview]
Message-ID: <87pny8oxpf.fsf@gnu.org> (raw)
In-Reply-To: <87bm9ssuxm.fsf@elephly.net> (Ricardo Wurmus's message of "Thu, 23 Aug 2018 22:13:25 +0200")
[-- Attachment #1: Type: text/plain, Size: 3273 bytes --]
Hi!
Ricardo Wurmus <rekado@elephly.net> skribis:
> Are the bindings not usable with Guile 2.2?
No, but I have good news: those in Mailutils master are usable. Here’s
a recipe:
--8<---------------cut here---------------start------------->8---
(define-public mailutils-next
;; This version of Mailutils supports Guile 2.2, unlike version <= 3.4.
(let ((commit "62666075e3c7276d308dffef42c7c50dc526925b")
(revision "0"))
(package
(inherit mailutils)
(version (string-append (package-version mailutils)
"-" revision "." (string-take commit 7)))
(source (origin
(method git-fetch)
(uri (git-reference
(url "https://git.savannah.gnu.org/git/mailutils.git")
(commit commit)
(recursive? #t))) ;for Gnulib & co.
(sha256
(base32
"1m4cbjn02hklp6li14ajfzfg29ibbk38n0c3g8vyfx71iy0pxpnb"))
(file-name (string-append "mailutils-" version "-checkout"))))
(outputs '("out" "debug"))
(inputs
`(("guile" ,guile-2.2)
("gsasl" ,gsasl) ;for SMTP authentication
,@(alist-delete "guile" (package-inputs mailutils))))
(native-inputs
`(("autoconf" ,autoconf-wrapper)
("automake" ,automake)
("libtool" ,libtool)
("gettext" ,gnu-gettext)
,@(package-native-inputs mailutils)))
(arguments
(substitute-keyword-arguments (package-arguments mailutils)
((#:modules modules %gnu-build-system-modules)
`((srfi srfi-1) ,@modules))
((#:configure-flags flags ''())
`(cons* "--disable-radius"
;; Add "/2.2" to the installation directory.
(string-append "--with-guile-site-dir="
(assoc-ref %outputs "out")
"/share/guile/site/2.2")
,flags))
((#:phases phases)
`(modify-phases ,phases
(replace 'bootstrap
(lambda* (#:key inputs #:allow-other-keys)
(for-each patch-shebang
'("bootstrap" "gnulib/gnulib-tool"))
(substitute* "bootstrap.conf"
(("git submodule" all)
(string-append "#" all)))
(for-each make-file-writable (find-files "gnulib"))
(substitute* "configure.ac"
(("AM_GNU_RADIUS") ""))
(invoke "./bootstrap" "--no-git" "--skip-po"
(string-append "--gnulib-srcdir=gnulib"))
#t))
(delete 'prepare-test-suite)))
((#:parallel-build? _ #f) ;due to parser.y
#f)
((#:tests? _ #f) ;XXX
#f))))))
--8<---------------cut here---------------end--------------->8---
Below is a simple example to get started. The Mailutils API is not this
complicated but it took me a while to figure it out, so you might find
that module helpful.
Happy emailing! :-)
Ludo’.
[-- Attachment #2: the email module --]
[-- Type: text/plain, Size: 3114 bytes --]
;;; This module is licensed under the same terms, those of the GNU GPL
;;; version 3 or (at your option) any later version.
;;;
;;; Copyright © 2018 Ludovic Courtès <ludo@gnu.org>
(define-module (email)
#:use-module ((guix build utils) #:select (dump-port))
#:use-module (guix base64)
#:use-module (rnrs io ports)
#:use-module (rnrs bytevectors)
#:use-module (mailutils mailutils)
#:export (compose-message
send-message))
;; This variable is looked up by 'mu-message-send', uh!
(define-public mu-debug 0)
(define* (insert-newlines str #:optional (line-length 76))
"Insert newlines in STR every LINE-LENGTH characters."
(let loop ((result '())
(str str))
(if (string-null? str)
(string-concatenate-reverse result)
(let* ((length (min (string-length str) line-length))
(prefix (string-take str length))
(suffix (string-drop str length)))
(loop (cons (string-append prefix "\n") result)
suffix)))))
(define* (compose-message from to
#:key text subject file)
"Compose a message, and return a message object."
(let* ((mime (mu-mime-create))
(message (mu-message-create))
(body (mu-message-get-port message "w")))
(mu-message-set-header message
"Content-Type"
"text/plain; charset=utf-8")
(put-bytevector body (string->utf8 text))
(close-port body)
(mu-mime-add-part mime message)
(when file
(let* ((attach (mu-message-create))
(port (mu-message-get-port attach "w")))
(display (insert-newlines
(base64-encode (call-with-input-file file
get-bytevector-all)))
port)
(close-port port)
(mu-message-set-header attach
"Content-Transfer-Encoding"
"base64")
(mu-message-set-header attach
"Content-Type" "image/jpeg")
(mu-message-set-header attach
"Content-Disposition" "inline")
(mu-mime-add-part mime attach)))
(let ((result (mu-mime-get-message mime)))
(mu-message-set-header result "From" from)
(mu-message-set-header result "To" to)
(when subject
(mu-message-set-header result "Subject" subject))
result)))
(define (display-body message) ;debug
(let ((port (mu-message-get-port message "r")))
(dump-port port (current-error-port))
(close-port port)))
(define (send-message message)
"Send MESSAGE, a message returned by 'compose-message', using the SMTP
parameters found in ~/.config/smtp."
(define uri
;; Something like "smtp://USER:SECRET@SERVER:PORT" (info "(mailutils)
;; SMTP Mailboxes").
(call-with-input-file (string-append (getenv "HOME") "/.config/smtp")
read))
(mu-register-format "smtp")
(mu-message-send message uri))
next prev parent reply other threads:[~2018-08-24 10:40 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-23 20:13 bug#32514: mailutils Guile bindings are broken Ricardo Wurmus
2018-08-24 10:39 ` Ludovic Courtès [this message]
2018-08-24 18:05 ` Ricardo Wurmus
2018-08-24 10:39 ` Ludovic Courtès
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87pny8oxpf.fsf@gnu.org \
--to=ludo@gnu.org \
--cc=32514@debbugs.gnu.org \
--cc=rekado@elephly.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/guix.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.