From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.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 MICJFrpPQWSIOQEASxT56A (envelope-from ) for ; Thu, 20 Apr 2023 16:44:10 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id +LVKFrpPQWQcRAEAauVa8A (envelope-from ) for ; Thu, 20 Apr 2023 16:44:10 +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 D5C026E8D for ; Thu, 20 Apr 2023 16:44:09 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ppVW0-0004mo-Bk; Thu, 20 Apr 2023 10:44:04 -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 1ppVVy-0004mc-UI for guix-patches@gnu.org; Thu, 20 Apr 2023 10:44: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 1ppVVy-0006RX-MF for guix-patches@gnu.org; Thu, 20 Apr 2023 10:44:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ppVVy-0001Mu-Gg for guix-patches@gnu.org; Thu, 20 Apr 2023 10:44:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#62969] [PATCH] home: Add msmtp service. Resent-From: Tanguy Le Carrour Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 20 Apr 2023 14:44:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 62969 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 62969@debbugs.gnu.org Cc: Tanguy Le Carrour X-Debbugs-Original-To: guix-patches@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.16820017965190 (code B ref -1); Thu, 20 Apr 2023 14:44:02 +0000 Received: (at submit) by debbugs.gnu.org; 20 Apr 2023 14:43:16 +0000 Received: from localhost ([127.0.0.1]:38493 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ppVVD-0001Ld-8S for submit@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 ) id 1ppVV9-0001LS-8S for submit@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 ) id 1ppVV8-0004U3-FC for guix-patches@gnu.org; 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 ) id 1ppVV3-00060b-Ng for guix-patches@gnu.org; Thu, 20 Apr 2023 10:43:10 -0400 Received: (Authenticated sender: tanguy@bioneland.org) 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 Date: Thu, 20 Apr 2023 16:42:30 +0200 Message-Id: <20230420144230.9392-1-tanguy@bioneland.org> 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@bioneland.org; 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-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-Country: US X-Migadu-Flow: FLOW_IN ARC-Seal: i=1; s=key1; d=yhetil.org; t=1682001850; a=rsa-sha256; cv=none; b=ME30ANrc9g8CTYixM8Mze0PR2zjqsOwScpwFgfDp4RKkppdCPhHS5TRqBsq86qKGO86z9k 5rfPEWbGivHu9OAqk9w3XlDf3V1DiwroOo01kc4lFMSCWiTxNNeBOibI71SEDDwXjnLdcu JLPdUhgcIna5UrI3WRNnP44i5Hp17FewjZNdXlYYbsDetvkmUJtQMQ5ikhvV5vGxWR7F4S AHXq7iFojmua5IxX7UNGHbAB5ORq83UV//AeePC2GFrroVzQVBvyV/kz8by2rHqOarmojV 9KvXsf7peoxLDWSvM+9TycIiMMG8aD52MOvtOsDrRFQMa6pf43nAezds6WfIYg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=bioneland.org header.s=gm1 header.b=pO4TbeYC; 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=1682001850; 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:list-id:list-help: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=SL3RDr/qmSnadDCjGRybNGIo8pHLrz539jB/k2k8F9s=; b=JIqepy3h4A+EcQ4YP80MnEni9iuDfvpDEPP9i+oRfKxgmZ7atoSjeGerz/duF/1ez1dz4M FcHRsEzpHJzK/Eg86c9Suhmn6U7gu3hVaQePLnCz+UjzEyPOp5PW+Srj3D7TYE3xXDTS6D R5dFE9Fvqbxc71axddoB9JwSgmSU40L4V8dY/Gr6SBrQ5TqDWIMoGOntYKzUPp4iVQgSWa xCbP6ED5MwzCxu+4nWrxyuA62dvPFDmj80JGQpbn678THFehJQ4pmLPHm/pLsbqTJkxUtm nMETJhtOxZ5bdy9r86qdfV5U/P/zLhwDhZo/nxO+GguM+a5EVYrQ9FrqDzyj7A== X-Migadu-Spam-Score: 0.09 X-Spam-Score: 0.09 X-Migadu-Queue-Id: D5C026E8D X-Migadu-Scanner: scn0.migadu.com Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=bioneland.org header.s=gm1 header.b=pO4TbeYC; 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-TUID: e18Fcwahag+h 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: #` + ;(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 +;;; +;;; 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-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: #` + ;(every msmtp-account? lst)) + #t) + +;; 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 (‘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