From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms9.migadu.com with LMTPS id 8HYZL24xUmR7NgAASxT56A (envelope-from ) for ; Wed, 03 May 2023 12:03:26 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id WJQ0L24xUmSbdgEA9RJhRA (envelope-from ) for ; Wed, 03 May 2023 12:03:26 +0200 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 2B5A4F7A6 for ; Wed, 3 May 2023 12:03:26 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pu9KD-0002XN-Cs; Wed, 03 May 2023 06:03:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pu9KA-0002W2-Tm for guix-patches@gnu.org; Wed, 03 May 2023 06:03:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pu9KA-0006C9-LA for guix-patches@gnu.org; Wed, 03 May 2023 06:03:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pu9KA-0003NB-1o for guix-patches@gnu.org; Wed, 03 May 2023 06:03:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#62969] [PATCH v3] home: Add msmtp service. Resent-From: Tanguy LE CARROUR Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Wed, 03 May 2023 10:03:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 62969 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: Ludovic =?UTF-8?Q?Court=C3=A8s?= Cc: 62969@debbugs.gnu.org, mirai@makinata.eu Received: via spool by 62969-submit@debbugs.gnu.org id=B62969.168310812212855 (code B ref 62969); Wed, 03 May 2023 10:03:02 +0000 Received: (at 62969) by debbugs.gnu.org; 3 May 2023 10:02:02 +0000 Received: from localhost ([127.0.0.1]:45585 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pu9JA-0003L4-QX for submit@debbugs.gnu.org; Wed, 03 May 2023 06:02:01 -0400 Received: from relay1-d.mail.gandi.net ([217.70.183.193]:47857) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pu9J6-0003Ki-79 for 62969@debbugs.gnu.org; Wed, 03 May 2023 06:01:59 -0400 Received: (Authenticated sender: tanguy@bioneland.org) by mail.gandi.net (Postfix) with ESMTPSA id 9317B240008; Wed, 3 May 2023 10:01:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bioneland.org; s=gm1; t=1683108110; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RAThyZkfIauxIbSzLy4zSgq08ZZzY4zLyhVVcFk1Q6Q=; b=YMaQiIT5gdFUZi94xu0InPZg2ay0qz1LgYCQdswnDumjwxJla6MDdIXTcT+SkGvhwrRKAn fmBbatgHKo6u0ccyurnApXFsFtnIfVOo0egeQ32AmrSg0K++acrn1NQCnl5TycvWSYLv6z cDMLPPkxaII0ltnQOoAshApwFLKHlo44amkZ00mVDMBGC0h1FVQ1MMTthc4Nu02IqRpATR 4ljczMFA+RVL1bMg5b0yiKZkWsWBSVEU5tTGgICnehFoZlUrVnlI65GI8n2flH3BoSFcoD 05937yxK3euWlD9CfY2UCo68B6x/241ppjIGzq1ncgRTOwCEkOqtuLTpXa5QMQ== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable References: <20230420144230.9392-1-tanguy@bioneland.org> <20230423171217.14894-1-tanguy@bioneland.org> <87ilddnjml.fsf_-_@gnu.org> From: Tanguy LE CARROUR In-Reply-To: <87ilddnjml.fsf_-_@gnu.org> Date: Wed, 03 May 2023 12:01:48 +0200 Message-ID: <168310810854.1650.852938763274164245@localhost> User-Agent: alot/0.10 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: guix-patches-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US ARC-Seal: i=1; s=key1; d=yhetil.org; t=1683108206; a=rsa-sha256; cv=none; b=U7lBZe9GUPdXFV0CvXQGIL6li0FzYVbosBdVHgfK/+COwcRJupmcGOOxXetR1ReQ8iGsWd dg9hGOGsdHLSM/YxL78wWB6id+t7RJlR+V+KIfV1t2/jaY3ttbXZJldKlA7aHjusrww2Oy /wqjUd7Kt1eynSNALp+9zYSezsvgpYmxqz5YOpeCx8aU1H0j90Gdp22R2hKKdcHn90LFWG 3vsoY7GlcO9XpCIRyiRf+Wbk2fLYMVgFCbHjlvo8mib9pprYJ72lekVPz0mXxke2EH3xg1 rTgL1n5TDgqXZ1n9acXY3d2PG9rIuEcV8qZ1cGQ+UYUT6sCD7g7ZS4LMcTAM4g== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=bioneland.org header.s=gm1 header.b=YMaQiIT5; dmarc=fail reason="SPF not aligned (relaxed)" header.from=bioneland.org (policy=none); spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1683108206; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=RAThyZkfIauxIbSzLy4zSgq08ZZzY4zLyhVVcFk1Q6Q=; b=mRegLi9c3//0peaIjR6IoXs/l23ApxuNepWGrrS1rKE8itCERtd8oJp4vf6DAgJ0Gi/gdp PQf2UB9MyVcWfDtEFK5pT/GT5RhXxqF7TEZPczh2MYMx/YPIf6NcQ9+TmuBG2eyRVr/YB4 6f45ZfDLLl62o8aa1WYIY748o3u+EzFbjp2tMGkwz5FaR/7O5q5/BImGslh9pbjhqB5rch e1Vrk6q92RWPyOZuGBcQYdzW33p0aeRU7+vZw2VZuOJJYACIGbbrAhAWGTlJX1gcSVxB8C h+Qq0qmnY+6QQipPQpf5RAe5NXgOttdafUgr+CnAHZtgzffvu0CY9xeghljb3Q== X-Migadu-Scanner: scn1.migadu.com Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=bioneland.org header.s=gm1 header.b=YMaQiIT5; dmarc=fail reason="SPF not aligned (relaxed)" header.from=bioneland.org (policy=none); spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: 6.20 X-Spam-Score: 6.20 X-Migadu-Queue-Id: 2B5A4F7A6 X-TUID: QabPH5FFTR59 Hi Ludo=E2=80=99, Quoting Ludovic Court=C3=A8s (2023-04-30 23:30:10) > Tanguy Le Carrour skribis: >=20 > > * gnu/home/services/mail.scm: New file. > > * gnu/local.mk (GNU_SYSTEM_MODULES): Add it. > > * doc/guix.texi (Mailing): New node. >=20 > I get: >=20 > --8<---------------cut here---------------start------------->8--- > [ 94%] GUILEC gnu/home/services/mail.go > gnu/home/services/mail.scm:52:0: warning: possibly unbound variable `seri= alize-string' > gnu/home/services/mail.scm:53:0: warning: possibly unbound variable `seri= alize-boolean' > gnu/home/services/mail.scm:54:0: warning: possibly unbound variable `seri= alize-integer' > --8<---------------cut here---------------end--------------->8--- > > I guess these procedures should be provided as well? I also get them when making `gnu/home/services/mail.go`. But aren't those "just" warnings. Everything seems to work as expected and when I `guix home container test.home.scm` I get the expected `.config/msmtp/config` file. > > +@node Mail Home Services > > +@subsection Mail Home Services > > + > > +@cindex msmtp > > +@uref{https://marlam.de/msmtp, MSMTP} is an SMTP client. >=20 > Could you give a bit more context, including @acronym for SMTP? It > would also be nice to provide one commented example that readers might > copy/paste as a starting point. >=20 > You can take inspiration form the =E2=80=9CMcron Home Services=E2=80=9D, = =E2=80=9CSecure Shell=E2=80=9D, > or =E2=80=9CMessaging Home Services=E2=80=9D nodes, for example. >=20 > [...] >=20 > > + (default-value (home-msmtp-configuration)) > > + (description "Configures msmtp."))) >=20 > Likewise, something like =E2=80=9CConfigure msmtp, a simple @acronym{SMTP= , =E2=80=A6} > client that can relay email to SMTP servers.=E2=80=9D I tried to improve it based on your suggestions. No yet perfect, though. Cheers, Tanguy * gnu/home/services/mail.scm: New file. * gnu/local.mk (GNU_SYSTEM_MODULES): Add it. * doc/guix.texi (Mailing): New node. --- doc/guix.texi | 137 +++++++++++++++++++++++ gnu/home/services/mail.scm | 221 +++++++++++++++++++++++++++++++++++++ gnu/local.mk | 1 + 3 files changed, 359 insertions(+) create mode 100644 gnu/home/services/mail.scm diff --git a/doc/guix.texi b/doc/guix.texi index 7af2a85499..2ae815475b 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -114,6 +114,7 @@ Copyright @copyright{} 2023 Giacomo Leidi@* Copyright @copyright{} 2022 Antero Mejr@* Copyright @copyright{} 2023 Karl Hallsby +Copyright @copyright{} 2023 Tanguy Le Carrour Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or @@ -41887,6 +41888,7 @@ Home Services * Guix: Guix Home Services. Services for Guix. * Fonts: Fonts Home Services. Services for managing User's fonts. * Sound: Sound Home Services. Dealing with audio. +* Mail: Mail Home Services. Services for managing mail. * Messaging: Messaging Home Services. Services for managing messaging. * Media: Media Home Services. Services for managing media. @end menu @@ -43110,6 +43112,141 @@ Sound Home Services This is the multicast address used by default by the two services above. @end defvar +@node Mail Home Services +@subsection Mail Home Services + +The @code{(gnu home services mail)} modules provides services that help +you set up the tools to work with emails in your home environment. + +@cindex msmtp +@uref{https://marlam.de/msmtp, MSMTP} is a @acronym{SMTP, Simple Mail +Transfer Protocol} client. It sends mails to a predefined SMTP server +that takes care of proper delivery. + +The service reference is given below. + +@defvar home-msmtp-service-type +This is the service type for @command{msmtp}. Its value must be a +@code{home-msmtp-configuration}, as shown below. It provides the +@code{~/.config/msmtp/config} file. + +As an example, here is how you would configure @code{msmtp} for a single +account: + +@lisp +(service home-msmtp-service-type + (home-msmtp-configuration + (accounts + (list + (msmtp-account + (name "alice") + (configuration + (msmtp-configuration + (host "mail.example.org") + (port 587) + (user "alice") + (passwordeval "pass Mail/alice")))))))) +@end lisp +@end defvar + +@c %start of fragment + +@deftp {Data Type} home-msmtp-configuration +Available @code{home-msmtp-configuration} fields are: + +@table @asis +@item @code{defaults} (type: msmtp-configuration) +The configuration that will be set as default for all accounts. + +@item @code{accounts} (default: @code{()}) (type: list-of-msmtp-accounts) +A list of @code{msmtp-account} records which contain information about +all your accounts. + +@item @code{default-account} (type: maybe-string) +Set the default account. + +@item @code{extra-content} (default: @code{""}) (type: string) +Extra content appended as-is to the configuration file. Run +@command{man msmtp} for more information about the configuration file +format. + +@end table + +@end deftp + +@c %end of fragment + +@c %start of fragment + +@deftp {Data Type} msmtp-account +Available @code{msmtp-account} fields are: + +@table @asis +@item @code{name} (type: string) +The unique name of the account. + +@item @code{configuration} (type: msmtp-configuration) +The configuration for this given account. + +@end table + +@end deftp + +@c %end of fragment + +@c %start of fragment + +@deftp {Data Type} msmtp-configuration +Available @code{msmtp-configuration} fields are: + +@table @asis +@item @code{auth?} (type: maybe-boolean) +Enable or disable authentication. + +@item @code{tls?} (type: maybe-boolean) +Enable or disable TLS (also known as SSL) for secured connections. + +@item @code{tls-starttls?} (type: maybe-boolean) +Choose the TLS variant: start TLS from within the session (=E2=80=98on=E2= =80=99, +default), or tunnel the session through TLS (=E2=80=98off=E2=80=99). + +@item @code{tls-trust-file} (type: maybe-string) +Activate server certificate verification using a list of trusted +Certification Authorities (CAs). + +@item @code{logfile} (type: maybe-string) +Enable logging to the specified file. An empty argument disables +logging. The file name =E2=80=98-=E2=80=99 directs the log information to= standard +output. + +@item @code{host} (type: maybe-string) +The SMTP server to send the mail to. + +@item @code{port} (type: maybe-integer) +The port that the SMTP server listens on. The default is 25 ("smtp"), +unless TLS without STARTTLS is used, in which case it is 465 ("smtps"). + +@item @code{user} (type: maybe-string) +Set the user name for authentication. + +@item @code{from} (type: maybe-string) +Set the envelope-from address. + +@item @code{passwordeval} (type: maybe-string) +Set the password for authentication to the output (stdout) of the +command cmd. + +@item @code{extra-content} (default: @code{""}) (type: string) +Extra content appended as-is to the configuration block. Run +@command{man msmtp} for more information about the configuration file +format. + +@end table + +@end deftp + +@c %end of fragment + @node Messaging Home Services @subsection Messaging Home Services diff --git a/gnu/home/services/mail.scm b/gnu/home/services/mail.scm new file mode 100644 index 0000000000..ec5f869c87 --- /dev/null +++ b/gnu/home/services/mail.scm @@ -0,0 +1,221 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright =C2=A9 2023 Tanguy Le Carrour +;;; +;;; This file is part of GNU Guix. +;;; +;;; GNU Guix is free software; you can redistribute it and/or modify it +;;; under the terms of the GNU General Public License as published by +;;; the Free Software Foundation; either version 3 of the License, or (at +;;; your option) any later version. +;;; +;;; GNU Guix is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; GNU General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with GNU Guix. If not, see . + +(define-module (gnu home services mail) + #:use-module (guix gexp) + #:use-module (gnu packages) + #:use-module (gnu services) + #:use-module (gnu services configuration) + #:use-module (gnu home services) + #:use-module (gnu home services shepherd) + #:use-module (ice-9 string-fun) + #:use-module (srfi srfi-1) + #:use-module (srfi srfi-26) + #:export (home-msmtp-configuration + home-msmtp-configuration? + home-msmtp-configuration-defaults + home-msmtp-configuration-accounts + home-msmtp-configuration-default-account + home-msmtp-configuration-extra-content + home-msmtp-service-type + msmtp-configuration + msmtp-configuration-auth? + msmtp-configuration-tls? + msmtp-configuration-tls-starttls? + msmtp-configuration-tls-trust-file + msmtp-configuration-logfile + msmtp-configuration-host + msmtp-configuration-port + msmtp-configuration-user + msmtp-configuration-from + msmtp-configuration-passwordeval + msmtp-configuration-extra-content + msmtp-account + msmtp-account-name + msmtp-account-configuration)) + +(define-maybe string) +(define-maybe boolean) +(define-maybe integer) + +;; Serialization of 'msmtp'. +(define (uglify-symbol field-name) + (let* ((name (symbol->string field-name)) + (ugly-name (string-replace-substring name "-" "_"))) + (if (string-suffix? "?" ugly-name) + (string-drop-right ugly-name 1) + ugly-name))) + +(define (msmtp-configuration-serialize-maybe-boolean field-name value) + #~(if #$(maybe-value-set? value) + (string-append #$(uglify-symbol field-name) " " (if #$value "on" "of= f") "\n") + "")) + +(define (msmtp-configuration-serialize-maybe-string field-name value) + #~(if #$(maybe-value-set? value) + (string-append #$(uglify-symbol field-name) " " #$value "\n") + "")) + +(define (msmtp-configuration-serialize-maybe-integer field-name value) + #~(if #$(maybe-value-set? value) + (string-append #$(uglify-symbol field-name) " " (number->string #$va= lue) "\n") + "")) + +(define (msmtp-configuration-serialize-extra-content field-name value) + #~(if (string=3D? #$value "") "" (string-append #$value "\n"))) + +(define (msmtp-account-serialize-name field-name value) + #~(string-append "\naccount " #$value "\n")) + +(define (msmtp-account-serialize-msmtp-configuration field-name value) + #~(string-append #$(serialize-configuration value msmtp-configuration-fi= elds))) + +(define (home-msmtp-configuration-serialize-list-of-msmtp-accounts field-n= ame value) + #~(string-append #$@(map (cut serialize-configuration <> msmtp-account-f= ields) + value))) + +(define (home-msmtp-configuration-serialize-msmtp-configuration field-name= value) + #~(string-append "defaults\n" + #$(serialize-configuration value msmtp-configuration-fi= elds))) + +(define (home-msmtp-configuration-serialize-default-account field-name val= ue) + #~(if #$(maybe-value-set? value) + (string-append "\naccount default : " #$value "\n") + "")) + +(define (home-msmtp-configuration-serialize-extra-content field-name value) + #~(if (string=3D? #$value "") "" (string-append #$value "\n"))) + +;; Configuration of 'msmtp'. +;; Source . +(define-configuration msmtp-configuration + (auth? + maybe-boolean + "Enable or disable authentication.") + + (tls? + maybe-boolean + "Enable or disable TLS (also known as SSL) for secured connections.") + + (tls-starttls? + maybe-boolean + "Choose the TLS variant: start TLS from within the session (=E2=80=98on= =E2=80=99, default), +or tunnel the session through TLS (=E2=80=98off=E2=80=99).") + + (tls-trust-file + maybe-string + "Activate server certificate verification using a list of +trusted Certification Authorities (CAs).") + + (logfile + maybe-string + "Enable logging to the specified file. An empty argument disables loggi= ng. +The file name =E2=80=98-=E2=80=99 directs the log information to standard = output.") + + (host + maybe-string + "The SMTP server to send the mail to.") + + (port + maybe-integer + "The port that the SMTP server listens on. The default is 25 (\"smtp\"= ), +unless TLS without STARTTLS is used, in which case it is 465 (\"smtps\").") + + (user + maybe-string + "Set the user name for authentication.") + + (from + maybe-string + "Set the envelope-from address.") + + (passwordeval + maybe-string + "Set the password for authentication to the output (stdout) of the com= mand cmd.") + + (extra-content + (string "") + "Extra content appended as-is to the configuration block. Run +@command{man msmtp} for more information about the configuration file +format." + (serializer msmtp-configuration-serialize-extra-content)) + + (prefix msmtp-configuration-)) + +(define-configuration msmtp-account + (name + (string) + "The unique name of the account." + (serializer msmtp-account-serialize-name)) + + (configuration + (msmtp-configuration) + "The configuration for this given account.") + + (prefix msmtp-account-)) + +(define (list-of-msmtp-accounts? lst) + (every msmtp-account? lst)) + +(define-configuration home-msmtp-configuration + (defaults + (msmtp-configuration (msmtp-configuration)) + "The configuration that will be set as default for all accounts.") + + (accounts + (list-of-msmtp-accounts '()) + "A list of @code{msmtp-account} records which contain +information about all your accounts.") + + (default-account + maybe-string + "Set the default account." + (serializer home-msmtp-configuration-serialize-default-account)) + + (extra-content + (string "") + "Extra content appended as-is to the configuration file. Run +@command{man msmtp} for more information about the configuration file +format." + (serializer home-msmtp-configuration-serialize-extra-content)) + + (prefix home-msmtp-configuration-)) + +(define (home-msmtp-files-service config) + (list + `(".config/msmtp/config" + ,(mixed-text-file "config" + (serialize-configuration config home-msmtp-configur= ation-fields))))) + +(define (home-msmtp-profile-service config) + (specifications->packages (list "msmtp"))) + +(define home-msmtp-service-type + (service-type (name 'home-msmtp) + (extensions + (list + (service-extension + home-profile-service-type + home-msmtp-profile-service) + (service-extension + home-files-service-type + home-msmtp-files-service))) + (default-value (home-msmtp-configuration)) + (description "Configure msmtp, a simple +@acronym{SMTP, Simple Mail Transfer Protocol} client that can relay email +to SMTP servers."))) diff --git a/gnu/local.mk b/gnu/local.mk index 4305bee89c..94ea3a4e8d 100644 --- a/gnu/local.mk +++ b/gnu/local.mk @@ -93,6 +93,7 @@ GNU_SYSTEM_MODULES =3D \ %D%/home/services/fontutils.scm \ %D%/home/services/gnupg.scm \ %D%/home/services/guix.scm \ + %D%/home/services/mail.scm \ %D%/home/services/media.scm \ %D%/home/services/messaging.scm \ %D%/home/services/pm.scm \ base-commit: 94e2e3553440a2a5ac4a312e80b8ea21ddebafeb --=20 2.39.2