GNU bug report logs - #62969
[PATCH] home: Add msmtp service.

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: guix-patches; Reported by: Tanguy Le Carrour <tanguy@HIDDEN>; Keywords: patch; dated Thu, 20 Apr 2023 14:44:02 UTC; Maintainer for guix-patches is guix-patches@HIDDEN.

Message received at 62969 <at> debbugs.gnu.org:


Received: (at 62969) by debbugs.gnu.org; 23 Apr 2023 17:12:56 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Apr 23 13:12:56 2023
Received: from localhost ([127.0.0.1]:46930 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1pqdGh-0000st-Tp
	for submit <at> debbugs.gnu.org; Sun, 23 Apr 2023 13:12:56 -0400
Received: from relay7-d.mail.gandi.net ([217.70.183.200]:55249)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <tanguy@HIDDEN>) id 1pqdGf-0000sb-TR
 for 62969 <at> debbugs.gnu.org; Sun, 23 Apr 2023 13:12:55 -0400
Received: (Authenticated sender: tanguy@HIDDEN)
 by mail.gandi.net (Postfix) with ESMTPSA id 3F2ED20007;
 Sun, 23 Apr 2023 17:12:46 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bioneland.org;
 s=gm1; t=1682269967;
 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;
 bh=C9bCfE1Az/hhR3M+gCPlHidxSfle2VzUVD48EQ7puuM=;
 b=he1ZodKrpGKXxbNXYJmHdjNN4MHTT68ZIN/rCbOqvyOikmh32EpEf+8qvYXobZRocynjz3
 f4egVYx66Q/NRq4XSLSQBcR3UV5yA8RdCKxN/woYIm4zUlQ6nlF9WSZ7VVMCbiRKpBku7A
 qmSe3eRnymqRzDVpqmhr+OEFxb98FWdlOadY9FsJlbZ9j8u1Y0p23LOaZ4bYlInvDkOmOm
 ENguyVPb9e4iODZJFGZuqptHqdU01yHcQy6z9RjBC4+YCC2TYyHpw1hJ2tc8uOhkn5o+Z6
 M1SCJdLxOzB5XoMAaeQurYyZG7ld6TjnsnAuGupHQztTCOv6ffVohx7FftT19w==
From: Tanguy Le Carrour <tanguy@HIDDEN>
To: 62969 <at> debbugs.gnu.org
Subject: [PATCH v2] home: Add msmtp service.
Date: Sun, 23 Apr 2023 19:12:17 +0200
Message-Id: <20230423171217.14894-1-tanguy@HIDDEN>
X-Mailer: git-send-email 2.39.2
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Spam-Score: -0.7 (/)
X-Debbugs-Envelope-To: 62969
Cc: mirai@HIDDEN, Tanguy Le Carrour <tanguy@HIDDEN>
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.7 (-)

* gnu/home/services/mail.scm: New file.
* gnu/local.mk (GNU_SYSTEM_MODULES): Add it.
* doc/guix.texi (Mailing): New node.
---
 doc/guix.texi              | 106 ++++++++++++++++++
 gnu/home/services/mail.scm | 219 +++++++++++++++++++++++++++++++++++++
 gnu/local.mk               |   1 +
 3 files changed, 326 insertions(+)
 create mode 100644 gnu/home/services/mail.scm

diff --git a/doc/guix.texi b/doc/guix.texi
index adb1975935..78efa822f9 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -114,6 +114,7 @@ Copyright @copyright{} 2022 Ivan Vilata-i-Balaguer@*
 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
@@ -41880,6 +41881,7 @@ 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
@@ -43082,6 +43084,110 @@ Stopping the Shepherd service turns off broadcasting.
 This is the multicast address used by default by the two services above.
 @end defvar
 
+@node Mail Home Services
+@subsection Mail Home Services
+
+@cindex msmtp
+@uref{https://marlam.de/msmtp, MSMTP} is an SMTP client.
+
+@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 (‘on’,
+default), or tunnel the session through TLS (‘off’).
+
+@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 ‘-’ 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..e151cf8607
--- /dev/null
+++ b/gnu/home/services/mail.scm
@@ -0,0 +1,219 @@
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2023 Tanguy Le Carrour <tanguy@HIDDEN>
+;;;
+;;; 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 <http://www.gnu.org/licenses/>.
+
+(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" "off") "\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 #$value) "\n")
+      ""))
+
+(define (msmtp-configuration-serialize-extra-content field-name value)
+  #~(if (string=? #$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-fields)))
+
+(define (home-msmtp-configuration-serialize-list-of-msmtp-accounts field-name value)
+  #~(string-append #$@(map (cut serialize-configuration <> msmtp-account-fields)
+                           value)))
+
+(define (home-msmtp-configuration-serialize-msmtp-configuration field-name value)
+  #~(string-append "defaults\n"
+                   #$(serialize-configuration value msmtp-configuration-fields)))
+
+(define (home-msmtp-configuration-serialize-default-account field-name value)
+  #~(if #$(maybe-value-set? value)
+      (string-append "\naccount default : " #$value "\n")
+      ""))
+
+(define (home-msmtp-configuration-serialize-extra-content field-name value)
+  #~(if (string=? #$value "") "" (string-append #$value "\n")))
+
+;; Configuration of 'msmtp'.
+;; Source <https://marlam.de/msmtp/msmtp.html#Configuration-files>.
+(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 (‘on’, default),
+or tunnel the session through TLS (‘off’).")
+
+  (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 logging.
+The file name ‘-’ 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 command 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-configuration-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 "Configures msmtp.")))
diff --git a/gnu/local.mk b/gnu/local.mk
index 01ffe3fdb6..3f57ca3c98 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -93,6 +93,7 @@ GNU_SYSTEM_MODULES =				\
   %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			\
-- 
2.39.2





Information forwarded to guix-patches@HIDDEN:
bug#62969; Package guix-patches. Full text available.

Message received at 62969 <at> debbugs.gnu.org:


Received: (at 62969) by debbugs.gnu.org; 23 Apr 2023 17:10:29 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Apr 23 13:10:29 2023
Received: from localhost ([127.0.0.1]:46902 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1pqdEK-0000ne-VS
	for submit <at> debbugs.gnu.org; Sun, 23 Apr 2023 13:10:29 -0400
Received: from relay1-d.mail.gandi.net ([217.70.183.193]:43487)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <tanguy@HIDDEN>) id 1pqdEF-0000nL-AX
 for 62969 <at> debbugs.gnu.org; Sun, 23 Apr 2023 13:10:27 -0400
Received: (Authenticated sender: tanguy@HIDDEN)
 by mail.gandi.net (Postfix) with ESMTPSA id DCD81240003;
 Sun, 23 Apr 2023 17:10:16 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bioneland.org;
 s=gm1; t=1682269817;
 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=ZauskUDCZCuaAPW5eyLhpF5SHYG40mrFyL537YbkF+Q=;
 b=cvB3bzA1QOCp0ndIg0XPPcuo38NBciD7tWO/2379XCHBSbC0CFk7QlnbAK1VwauKieE9Hf
 f63Vj8VL+TTvEpLUkiMjbIeh1P9oTdXacmUuCcsZhqy4mhPLntieTqmYngcZ1LkgawQm5S
 K3V8ZCtKDaeDkopdb5Uc+//uxtJBtClGleZhbO3/AlQyO6rfAFXMy/PbjkW0DSWixm9mXS
 zA+8PXR9ou5529BvuDOuUlNHSeEDylGsD65nwnoI8HvZ40olucOPhzRUZWLu7UedzcLmHk
 MCLAnDbrTtCxCbVZHzPNCw+6D83BCT/8NuT2rGKdvh38S6YIW6bXSZcd7Oom4A==
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
References: <20230420144230.9392-1-tanguy@HIDDEN>
 <4f8624a0-31fe-1ea5-733a-b2e1917291b4@HIDDEN>
Subject: Re: [bug#62969] [PATCH] home: Add msmtp service.
From: Tanguy LE CARROUR <tanguy@HIDDEN>
To: Bruno Victal <mirai@HIDDEN>
In-Reply-To: <4f8624a0-31fe-1ea5-733a-b2e1917291b4@HIDDEN>
Date: Sun, 23 Apr 2023 19:10:15 +0200
Message-ID: <168226981597.13515.12105199384744750840@localhost>
User-Agent: alot/0.10
X-Spam-Score: -0.7 (/)
X-Debbugs-Envelope-To: 62969
Cc: 62969 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.7 (-)

Hi Bruno,

Thank you so much for you comments!
I've applied (almost, see below) all of your suggestions and I will send a =
v2.


Quoting Bruno Victal (2023-04-20 18:36:59)
> On 2023-04-20 15:42, Tanguy Le Carrour wrote:
> > +(define (configuration-serialize-maybe-string field-name value)
> > +  #~(if #$(maybe-value-set? value)
> > +      (string-append #$(uglify-symbol field-name) " " #$value "\n")
> > +      ""))> +
> > +(define (configuration-serialize-maybe-integer field-name value)
> > +  #~(if #$(maybe-value-set? value)
> > +      (string-append #$(uglify-symbol field-name) " " (number->string =
#$value) "\n")
> > +      ""))
> > +
> > +(define (configuration-serialize-maybe-boolean field-name value)
> > +  #~(if #$(maybe-value-set? value)
> > +      (string-append #$(uglify-symbol field-name) " " (if #$value "on"=
 "off") "\n")
> > +      ""))
> You don't have to perform the maybe-value-set? checks, it is automaticall=
y done for you.
> The only cases where this isn't true is if you explicitly override the se=
rializer in
> define-configuration. [2]

This is the only thing I can't figure out how to make work?!
When I remove the `(if #$(maybe-value-set? value) =E2=80=A6)` I get the
following error:

```
Backtrace:
          10 (primitive-load "/gnu/store/ajcf46q8yr9sb9n90psa5ay96jw?")
In ice-9/ports.scm:
   433:17  9 (call-with-output-file _ _ #:binary _ #:encoding _)
In ice-9/eval.scm:
    159:9  8 (_ #(#(#<directory (guile-user) 7ffff3fd7c80>) #<outp?>))
    155:9  7 (_ #(#(#<directory (guile-user) 7ffff3fd7c80>) #<outp?>))
   173:39  6 (_ #(#(#<directory (guile-user) 7ffff3fd7c80>) #<outp?>))
    159:9  5 (_ #(#(#<directory (guile-user) 7ffff3fd7c80>) #<outp?>))
   173:55  4 (_ #(#(#<directory (guile-user) 7ffff3fd7c80>) #<outp?>))
   173:55  3 (_ #(#(#<directory (guile-user) 7ffff3fd7c80>) #<outp?>))
   279:15  2 (_ #(#(#<directory (guile-user) 7ffff3fd7c80>) #<outp?>))
   223:20  1 (proc #(#(#<directory (guile-user) 7ffff3fd7c80>) #<o?>))
In unknown file:
           0 (%resolve-variable (7 . %unset-marker%) #<directory (gu?>)

ERROR: In procedure %resolve-variable:
Unbound variable: %unset-marker%
```


> > +  (prefix configuration-))
> These are poor prefix choices for a module named (gnu home services mail).
> If it were (gnu home services msmtp) or (gnu home services mail msmtp) it=
 would be acceptable
> but a module named (gnu home services mail) is expected to eventually con=
tain multiple services that
> have to co-exist. These prefixes are too non-specific and confusion prone=
 for such circumstances.
>=20
> I'd set this to (prefix msmtp-configuration-). (the same logic applies to=
 the remaining (prefix ...) lines)

I totally agree! You guessed correctly, this home service was living
inside `(bioneland home services msmtp)`, so the naming seemed to make
sense at the time, but not any more!

Thanks again for your time and help!

--=20
Tanguy




Information forwarded to guix-patches@HIDDEN:
bug#62969; Package guix-patches. Full text available.

Message received at 62969 <at> debbugs.gnu.org:


Received: (at 62969) by debbugs.gnu.org; 20 Apr 2023 16:37:09 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Apr 20 12:37:09 2023
Received: from localhost ([127.0.0.1]:38594 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1ppXHQ-0004tB-Sl
	for submit <at> debbugs.gnu.org; Thu, 20 Apr 2023 12:37:09 -0400
Received: from smtpm1.myservices.hosting ([185.26.105.232]:40236)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <mirai@HIDDEN>) id 1ppXHO-0004t2-21
 for 62969 <at> debbugs.gnu.org; Thu, 20 Apr 2023 12:37:07 -0400
Received: from mail1.netim.hosting (unknown [185.26.106.173])
 by smtpm1.myservices.hosting (Postfix) with ESMTP id BEAEA205C3;
 Thu, 20 Apr 2023 18:37:04 +0200 (CEST)
Received: from localhost (localhost [127.0.0.1])
 by mail1.netim.hosting (Postfix) with ESMTP id 65FBB8009A;
 Thu, 20 Apr 2023 18:37:04 +0200 (CEST)
X-Virus-Scanned: Debian amavisd-new at mail1.netim.hosting
Received: from mail1.netim.hosting ([127.0.0.1])
 by localhost (mail1-2.netim.hosting [127.0.0.1]) (amavisd-new, port 10026)
 with ESMTP id tOZB9B-xqsJv; Thu, 20 Apr 2023 18:37:03 +0200 (CEST)
Received: from [192.168.1.239] (unknown [10.192.1.83])
 (Authenticated sender: lumen@HIDDEN)
 by mail1.netim.hosting (Postfix) with ESMTPSA id BB58780098;
 Thu, 20 Apr 2023 18:37:03 +0200 (CEST)
Message-ID: <4f8624a0-31fe-1ea5-733a-b2e1917291b4@HIDDEN>
Date: Thu, 20 Apr 2023 17:36:59 +0100
MIME-Version: 1.0
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
 Thunderbird/102.9.1
Subject: Re: [bug#62969] [PATCH] home: Add msmtp service.
Content-Language: en-US
To: Tanguy Le Carrour <tanguy@HIDDEN>
References: <20230420144230.9392-1-tanguy@HIDDEN>
From: Bruno Victal <mirai@HIDDEN>
In-Reply-To: <20230420144230.9392-1-tanguy@HIDDEN>
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Spam-Score: -1.1 (-)
X-Debbugs-Envelope-To: 62969
Cc: 62969 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -2.1 (--)

Hi Tanguy,

On 2023-04-20 15:42, Tanguy Le Carrour wrote:
> - one that I don't know how to solve
> ```
> +  ;; FIXME `In procedure every: Wrong type argument: #<syntax-transformer msmtp-account?>`
> +  ;(every msmtp-account? lst))
> ```

Place this after '(define-configuration mstmp-account ...)'. You might want to place this block
before '(define-configuration msmtp-configuration ...)'.

> +@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: raw-configuration-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

You should preserve the @c lines from configuration->documentation to make it clear that
the block of text was generated.

> +
> +(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-26)
> +  #:export (home-msmtp-configuration
> +            home-msmtp-configuration?
> +            home-msmtp-service-type
> +            msmtp-account
> +            msmtp-configuration))

You should export the accessors for the fields.
You can use this snippet within 'guix repl' to automate the typing for you:

--8<---------------cut here---------------start------------->8---
(define (helper-configuration-exports fields)
  (map
   (lambda (s)
     (let* ((f (compose object->string configuration-field-getter))
           (g (compose cadr string-tokenize))
           (s* ((compose g f) s)))
       (string->symbol (substring s* 1 (string-contains s* "-procedure")))))
   fields))

(define (helper-formatted-exports fields)
  (format #t "~{~a~%~}" (helper-configuration-exports fields)))
--8<---------------cut here---------------end--------------->8---

Example usage:

--8<---------------cut here---------------start------------->8---
;; paste snippet above into repl

scheme@(guix-user)> ,m (gnu services audio)
scheme@(gnu services audio)> (helper-formatted-exports mpd-configuration-fields)
mpd-configuration-user
mpd-configuration-group
mpd-configuration-shepherd-requirement
mpd-configuration-environment-variables
mpd-configuration-log-file
mpd-configuration-log-level
mpd-configuration-music-directory
mpd-configuration-music-dir
mpd-configuration-playlist-directory
mpd-configuration-playlist-dir
mpd-configuration-db-file
mpd-configuration-state-file
mpd-configuration-sticker-file
mpd-configuration-default-port
mpd-configuration-endpoints
mpd-configuration-address
mpd-configuration-database
mpd-configuration-partitions
mpd-configuration-neighbors
mpd-configuration-inputs
mpd-configuration-archive-plugins
mpd-configuration-input-cache-size
mpd-configuration-decoders
mpd-configuration-resampler
mpd-configuration-filters
mpd-configuration-outputs
mpd-configuration-playlist-plugins
mpd-configuration-extra-options
$1 = #t
--8<---------------cut here---------------end--------------->8---

> +
> +(define raw-configuration-string? string?)

This isn't necessary, continued below. [1]

> +
> +(define (configuration-serialize-maybe-string field-name value)
> +  #~(if #$(maybe-value-set? value)
> +      (string-append #$(uglify-symbol field-name) " " #$value "\n")
> +      ""))> +
> +(define (configuration-serialize-maybe-integer field-name value)
> +  #~(if #$(maybe-value-set? value)
> +      (string-append #$(uglify-symbol field-name) " " (number->string #$value) "\n")
> +      ""))
> +
> +(define (configuration-serialize-maybe-boolean field-name value)
> +  #~(if #$(maybe-value-set? value)
> +      (string-append #$(uglify-symbol field-name) " " (if #$value "on" "off") "\n")
> +      ""))
You don't have to perform the maybe-value-set? checks, it is automatically done for you.
The only cases where this isn't true is if you explicitly override the serializer in
define-configuration. [2]


> +(define (account-serialize-string field-name value)
> +  #~(string-append " " #$(uglify-symbol field-name) " " #$value "\n"))
> +
> +(define (account-serialize-string field-name value)
> +  #~(string-append " " #$(uglify-symbol field-name) " " #$value "\n"))

Duplicated?

> +
> +(define (account-serialize-msmtp-configuration field-name value)
> +  ; FIXME Begin each line inside an account section with a space.
> +  #~(string-append #$(serialize-configuration value msmtp-configuration-fields)))

This doesn't do anything and since it's a cosmetic change I'd just ignore it, since
the file is managed with guix anyways.

> +(define (home-configuration-serialize-default-account field-name value)
> +  #~(if #$(maybe-value-set? value)
> +      (string-append "\naccount default : " #$value "\n")
> +      ""))

See [2] above.

> +;; Source <https://marlam.de/msmtp/msmtp.html#Configuration-files>.
> +(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 (‘on’, default),
> +or tunnel the session through TLS (‘off’).")
> +  (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 logging.
> +The file name ‘-’ 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 command cmd.")
> +  (extra-content
> +   (raw-configuration-string "")
> +   "Extra content appended as-is to the configuration block.  Run
> +@command{man msmtp} for more information about the configuration file
> +format.")

Instead of defining a raw-configuration-string? predicate, simply use string?
and set the serializer to '(serializer my-custom-string-serializer)' or '(serializer (lambda ...))'. [1]

> +  (prefix configuration-))

These are poor prefix choices for a module named (gnu home services mail).
If it were (gnu home services msmtp) or (gnu home services mail msmtp) it would be acceptable
but a module named (gnu home services mail) is expected to eventually contain multiple services that
have to co-exist. These prefixes are too non-specific and confusion prone for such circumstances.

I'd set this to (prefix msmtp-configuration-). (the same logic applies to the remaining (prefix ...) lines)

> +
> +(define-configuration msmtp-account
> +  (name
> +   (string)
> +   "The unique name of the account."
> +   (serializer account-serialize-name))
> +  (configuration
> +   (msmtp-configuration)
> +   "The configuration for this given account.")
> +  (prefix account-))
> +
> +(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-configuration-serialize-default-account))
> +  (extra-content
> +   (raw-configuration-string "")
> +   "Extra content appended as-is to the configuration file.  Run
> +@command{man msmtp} for more information about the configuration file
> +format.")
> +  (prefix home-configuration-))

You might want to separate each field with a space to make things easier to read but this is optional.


Cheers,
Bruno





Information forwarded to guix-patches@HIDDEN:
bug#62969; Package guix-patches. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 20 Apr 2023 14:43:16 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Apr 20 10:43:16 2023
Received: from localhost ([127.0.0.1]:38493 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1ppVVD-0001Ld-8S
	for submit <at> debbugs.gnu.org; Thu, 20 Apr 2023 10:43:16 -0400
Received: from lists.gnu.org ([209.51.188.17]:39822)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <tanguy@HIDDEN>) id 1ppVV9-0001LS-8S
 for submit <at> debbugs.gnu.org; Thu, 20 Apr 2023 10:43:13 -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 <tanguy@HIDDEN>)
 id 1ppVV8-0004U3-FC
 for guix-patches@HIDDEN; Thu, 20 Apr 2023 10:43:10 -0400
Received: from relay9-d.mail.gandi.net ([217.70.183.199])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <tanguy@HIDDEN>)
 id 1ppVV3-00060b-Ng
 for guix-patches@HIDDEN; Thu, 20 Apr 2023 10:43:10 -0400
Received: (Authenticated sender: tanguy@HIDDEN)
 by mail.gandi.net (Postfix) with ESMTPSA id 9C641FF80E;
 Thu, 20 Apr 2023 14:42:57 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bioneland.org;
 s=gm1; t=1682001778;
 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;
 bh=SL3RDr/qmSnadDCjGRybNGIo8pHLrz539jB/k2k8F9s=;
 b=pO4TbeYC0HLMDWWmpnco9qtTqX5VBncti7sCFpffcNrHIMsJJbarxGZh3EIIP0Oj2KFcCt
 OB2wjvTUKRwEl8rcm/UitMcfSWdUp35Q1DQE5NL7mSQW8YaSOCiGhCJD6WVXPnZOESc3oN
 9jnSw8cSwoV3AERahjG7y2CgW6L2NPROd/9XAKH+4IJKpM5mBPBAHkpogF4/gypjzQk6c8
 FtHvoKcARHZMpZcQ4n5uy1p37DPtIpHg35lXQWDlV9h9ySZlmChTXugBzO2KjDDJHAWgPg
 NTNnjjts/PXP1TK5kfy0yfq+gwlAjFOH6+ekcv15x9VwiaI8EQWA7NuUmaGUCw==
From: Tanguy Le Carrour <tanguy@HIDDEN>
To: guix-patches@HIDDEN
Subject: [PATCH] home: Add msmtp service.
Date: Thu, 20 Apr 2023 16:42:30 +0200
Message-Id: <20230420144230.9392-1-tanguy@HIDDEN>
X-Mailer: git-send-email 2.39.2
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Received-SPF: pass client-ip=217.70.183.199; envelope-from=tanguy@HIDDEN;
 helo=relay9-d.mail.gandi.net
X-Spam_score_int: -27
X-Spam_score: -2.8
X-Spam_bar: --
X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,
 DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
 RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001,
 SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no
X-Spam_action: no action
X-Spam-Score: -1.6 (-)
X-Debbugs-Envelope-To: submit
Cc: Tanguy Le Carrour <tanguy@HIDDEN>
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -2.6 (--)

Hi Guix,

It's my first time 1) submitting a patch for a home service and
2) editing a `.texi` file, so please be understanding and…
pay special attention! :-)

Be aware that the code contains two FIXMEs:

- one that I don't know how to solve
```
+  ;; FIXME `In procedure every: Wrong type argument: #<syntax-transformer msmtp-account?>`
+  ;(every msmtp-account? lst))
```

- one that is a cosmetic change, and probabliy doesn't need fixing
```
+  ; FIXME Begin each line inside an account section with a space.
+  #~(string-append #$(serialize-configuration value msmtp-configuration-fields)))
```

And the documentation could probably be more detailed!

This being said… thanks for reading!


* gnu/home/services/mail.scm: New file.
* gnu/local.mk (GNU_SYSTEM_MODULES): Add it.
* doc/guix.texi (Mailing): New node.
---
 doc/guix.texi              |  95 ++++++++++++++++++
 gnu/home/services/mail.scm | 196 +++++++++++++++++++++++++++++++++++++
 gnu/local.mk               |   1 +
 3 files changed, 292 insertions(+)
 create mode 100644 gnu/home/services/mail.scm

diff --git a/doc/guix.texi b/doc/guix.texi
index adb1975935..5a1e215d17 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -114,6 +114,7 @@ Copyright @copyright{} 2022 Ivan Vilata-i-Balaguer@*
 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
@@ -41880,6 +41881,7 @@ 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
@@ -43082,6 +43084,99 @@ Stopping the Shepherd service turns off broadcasting.
 This is the multicast address used by default by the two services above.
 @end defvar
 
+@node Mail Home Services
+@subsection Mail Home Services
+
+@cindex msmtp
+@uref{https://marlam.de/msmtp, MSMTP} is an SMTP client.
+
+@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: raw-configuration-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
+
+@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
+
+@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 (‘on’,
+default), or tunnel the session through TLS (‘off’).
+
+@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 ‘-’ 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: raw-configuration-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
+
+
 @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..b31f68d2ca
--- /dev/null
+++ b/gnu/home/services/mail.scm
@@ -0,0 +1,196 @@
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2023 Tanguy Le Carrour <tanguy@HIDDEN>
+;;;
+;;; 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 <http://www.gnu.org/licenses/>.
+
+(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-26)
+  #:export (home-msmtp-configuration
+            home-msmtp-configuration?
+            home-msmtp-service-type
+            msmtp-account
+            msmtp-configuration))
+
+(define raw-configuration-string? string?)
+
+(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 (configuration-serialize-maybe-string field-name value)
+  #~(if #$(maybe-value-set? value)
+      (string-append #$(uglify-symbol field-name) " " #$value "\n")
+      ""))
+
+(define (configuration-serialize-maybe-integer field-name value)
+  #~(if #$(maybe-value-set? value)
+      (string-append #$(uglify-symbol field-name) " " (number->string #$value) "\n")
+      ""))
+
+(define (configuration-serialize-maybe-boolean field-name value)
+  #~(if #$(maybe-value-set? value)
+      (string-append #$(uglify-symbol field-name) " " (if #$value "on" "off") "\n")
+      ""))
+
+(define (configuration-serialize-raw-configuration-string field-name value)
+  #~(if #$(string=? value "") "" (string-append #$value "\n")))
+
+(define (account-serialize-name field-name value)
+  #~(string-append "\naccount " #$value "\n"))
+
+(define (account-serialize-string field-name value)
+  #~(string-append " " #$(uglify-symbol field-name) " " #$value "\n"))
+
+(define (account-serialize-string field-name value)
+  #~(string-append " " #$(uglify-symbol field-name) " " #$value "\n"))
+
+(define (account-serialize-msmtp-configuration field-name value)
+  ; FIXME Begin each line inside an account section with a space.
+  #~(string-append #$(serialize-configuration value msmtp-configuration-fields)))
+
+(define (home-configuration-serialize-list-of-msmtp-accounts field-name value)
+  #~(string-append #$@(map (cut serialize-configuration <> msmtp-account-fields)
+                           value)))
+
+(define (home-configuration-serialize-msmtp-configuration field-name value)
+  #~(string-append "defaults\n"
+                   #$(serialize-configuration value msmtp-configuration-fields)))
+
+(define (home-configuration-serialize-string field-name value)
+  #~(string-append #$(uglify-symbol field-name) " " #$value "\n"))
+
+(define (home-configuration-serialize-default-account field-name value)
+  #~(if #$(maybe-value-set? value)
+      (string-append "\naccount default : " #$value "\n")
+      ""))
+
+(define (home-configuration-serialize-raw-configuration-string field-name value)
+  #~(if #$(string=? value "") "" (string-append #$value "\n")))
+
+;; Configuration of 'msmtp'.
+(define (list-of-msmtp-accounts? lst)
+  ;; FIXME `In procedure every: Wrong type argument: #<syntax-transformer msmtp-account?>`
+  ;(every msmtp-account? lst))
+  #t)
+
+;; Source <https://marlam.de/msmtp/msmtp.html#Configuration-files>.
+(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 (‘on’, default),
+or tunnel the session through TLS (‘off’).")
+  (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 logging.
+The file name ‘-’ 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 command cmd.")
+  (extra-content
+   (raw-configuration-string "")
+   "Extra content appended as-is to the configuration block.  Run
+@command{man msmtp} for more information about the configuration file
+format.")
+  (prefix configuration-))
+
+(define-configuration msmtp-account
+  (name
+   (string)
+   "The unique name of the account."
+   (serializer account-serialize-name))
+  (configuration
+   (msmtp-configuration)
+   "The configuration for this given account.")
+  (prefix account-))
+
+(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-configuration-serialize-default-account))
+  (extra-content
+   (raw-configuration-string "")
+   "Extra content appended as-is to the configuration file.  Run
+@command{man msmtp} for more information about the configuration file
+format.")
+  (prefix home-configuration-))
+
+(define (home-msmtp-files-service config)
+  (list
+   `(".config/msmtp/config"
+     ,(mixed-text-file "config"
+                       (serialize-configuration config home-msmtp-configuration-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 "Configures msmtp.")))
diff --git a/gnu/local.mk b/gnu/local.mk
index 01ffe3fdb6..3f57ca3c98 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -93,6 +93,7 @@ GNU_SYSTEM_MODULES =				\
   %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			\
-- 
2.39.2





Acknowledgement sent to Tanguy Le Carrour <tanguy@HIDDEN>:
New bug report received and forwarded. Copy sent to guix-patches@HIDDEN. Full text available.
Report forwarded to guix-patches@HIDDEN:
bug#62969; Package guix-patches. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Sun, 23 Apr 2023 17:15:01 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.