From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms8.migadu.com with LMTPS id +LLFDKqkbGX1EQEAauVa8A:P1 (envelope-from ) for ; Sun, 03 Dec 2023 16:54:18 +0100 Received: from aspmx1.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id +LLFDKqkbGX1EQEAauVa8A (envelope-from ) for ; Sun, 03 Dec 2023 16:54:18 +0100 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 B0D1C5B88E for ; Sun, 3 Dec 2023 16:54:17 +0100 (CET) Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=landt.email header.s=MBO0001 header.b=gDtTTGVh; dmarc=fail reason="SPF not aligned (relaxed)" header.from=landt.email (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=1701618858; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: 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=GfrsF1iXYxj/13n8u7vaLX+3kQ67+hfR9DkpWUbjmdc=; b=qLcbLb5BB7OrEXC3TJftWwG2wddyRkqOjm8UWBaoNhKiX2rLgvQNdaSIdd9ufIRry85AsG zUilNMjn3AW+8Fr/XF6W/0RqIVvclGrFpdNQErQgAjv0AHI258FINQtqp3VVckbgb5zbiu dVnEKAq+nOnrWJXrDs3Cg31L1aR2D7aNk5rejbS/TKZX9rtdIlkC4JnwmYQY/5elbBmzXo IWnyWMII+rXIzvjwm3/1qvMTP3VqLYCHeJISQhCUU2Ty9hXb6L3Fmg/q8kQvzhJT9Dw361 GXBjawVRlifybXXosSx6xJ8BHxdRJUjKUUuFze7zkiZMXWPVrDhUaACrtJBLUQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1701618858; a=rsa-sha256; cv=none; b=JZQm9we43y7khxo2ciEL5nkFH/w+p3bUoRS4drftfRRItCRBMU1fvfqC1SHxZImL+DQeGP v9gOVgQcbXavGB2OEN9ms7rYE5NpF9Q8zLFUVowOFEMrW8Y9iIL7YinomDtzkDqAjLJMo/ N4KfMX7qQ2UXwXpBA0WzdjUyKY09dQfCS+TmTIJk4maX5kgS99t8d5zMnbOPPveJ1IdS+s JMBXwEYFrK3p8TdYNGT09QQqz3ZfBFJIljYjfD0+JPKyp5YRoTcpPkfPsz1a33Mdr1zy7J mrTky1KrA/hy/xER40llNSszOGe5RZPaez8KFS9RT0kO18luOcT3TjPEvj90hA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=landt.email header.s=MBO0001 header.b=gDtTTGVh; dmarc=fail reason="SPF not aligned (relaxed)" header.from=landt.email (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" Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r9on6-00078Y-In; Sun, 03 Dec 2023 10:53:56 -0500 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 1r9on2-00078O-Tk for guix-patches@gnu.org; Sun, 03 Dec 2023 10:53:53 -0500 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r9on2-0004fJ-Lb for guix-patches@gnu.org; Sun, 03 Dec 2023 10:53:52 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1r9onC-0004Y0-Js for guix-patches@gnu.org; Sun, 03 Dec 2023 10:54:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#66557] [PATCH] home: services: Add goimapnotify service. References: In-Reply-To: Resent-From: Nils Landt Original-Sender: "Debbugs-submit" Resent-CC: , guix-patches@gnu.org Resent-Date: Sun, 03 Dec 2023 15:54:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 66557 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 66557@debbugs.gnu.org Cc: ( , Andrew Tropin , Ludovic =?UTF-8?Q?Court=C3=A8s?= X-Debbugs-Original-Xcc: ( , Andrew Tropin , Ludovic =?UTF-8?Q?Court=C3=A8s?= Received: via spool by 66557-submit@debbugs.gnu.org id=B66557.170161883917470 (code B ref 66557); Sun, 03 Dec 2023 15:54:02 +0000 Received: (at 66557) by debbugs.gnu.org; 3 Dec 2023 15:53:59 +0000 Received: from localhost ([127.0.0.1]:60650 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r9on8-0004Xf-BH for submit@debbugs.gnu.org; Sun, 03 Dec 2023 10:53:59 -0500 Received: from mout-p-103.mailbox.org ([2001:67c:2050:0:465::103]:37878) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r9on6-0004XO-74 for 66557@debbugs.gnu.org; Sun, 03 Dec 2023 10:53:57 -0500 Received: from smtp202.mailbox.org (smtp202.mailbox.org [IPv6:2001:67c:2050:b231:465::202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-103.mailbox.org (Postfix) with ESMTPS id 4Sjrtm3qMpz9sch for <66557@debbugs.gnu.org>; Sun, 3 Dec 2023 16:53:36 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=landt.email; s=MBO0001; t=1701618816; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=GfrsF1iXYxj/13n8u7vaLX+3kQ67+hfR9DkpWUbjmdc=; b=gDtTTGVh4QRNIu47TE3hzF4f5dSQtQNMtPHkBEuCvTXrpwze0jc0M1GIncczRDMkHwyaui o3mc2Vt+MujKCpPMORuoef4kNxD7OMhJjlAqV6T4q4GOxYqIIB7xc7x426lOHM8aZPPalp 9fJykJ1rzzlzOiySrtVKeScCb+orrl9Kk1mPX0gf2KGmCouBl8mj47PcR6wgoi1r11aO4P 52K6B9Ji1I3I0AIXremAM+qIxfglgSm2NQ/UbpeFdN5DoYkjES4mNVjCRYG1sGgKLHT//b 5YW03BjTWuH1ADsTP+v9SOegTWm7KzHIi2qJe33C0+LiygLLT47LIGITa/EOHQ== From: Nils Landt Date: Sun, 3 Dec 2023 16:53:08 +0100 Message-ID: <1679639d1f2c9792da58baa9f93474b0b0b96956.1701618788.git.nils@landt.email> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-MBO-RS-ID: f3a2acd0c06ba58bc81 X-MBO-RS-META: 88djdhhofpephzbntt6kc4g9bj4adtqp X-Rspamd-Queue-Id: 4Sjrtm3qMpz9sch 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 X-Migadu-Scanner: mx11.migadu.com X-Migadu-Spam-Score: -3.75 X-Spam-Score: -3.75 X-Migadu-Queue-Id: B0D1C5B88E X-TUID: PnVji/n9VQs8 * gnu/home/services/mail.scm: (home-goimapnotify-configuration, home-goimapnotify-service-type, goimapnotify-account, goimapnotify-tls-options): New variables. (goimapnotify-format-field, goimapnotify-serialize-field, goimapnotify-serialize-goimapnotify-tls-options): New procedures. * doc/guix.texi (Mail Home Services): New node. --- doc/guix.texi | 139 +++++++++++++++++++++++++++ gnu/home/services/mail.scm | 186 ++++++++++++++++++++++++++++++++++++- 2 files changed, 324 insertions(+), 1 deletion(-) diff --git a/doc/guix.texi b/doc/guix.texi index 1fd2e21608..aed15685e5 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -44996,6 +44996,145 @@ Mail Home Services The @code{(gnu home services mail)} module provides services that help you set up the tools to work with emails in your home environment. +@cindex goimapnotify +@uref{https://gitlab.com/shackra/goimapnotify, goimapnotify} watches your +mailbox(es) and executes a script on (new / deleted / updated) messages. + +Using @code{home-goimapnotify-configuration}, you can generate a config file +for each account you want to watch (file name relative to @code{$HOME}), e.g.: + +@lisp +(simple-service 'mail-imapnotify-config-examples + home-goimapnotify-service-type + (home-goimapnotify-configuration + (accounts (list + `(".config/goimapnotify/private-account.conf" + ,(goimapnotify-account + (host "imap.example.org") + (port 993) + (tls #t) + (username "example") + (password-cmd + (file-append password-store + "/bin/pass my-private-email-account") + (on-new-mail + (file-append mbsync "/bin/mbsync private-account")) + (on-new-mail-post + (file-append mu "/bin/mu index")) + (boxes '("INBOX")))) + `(".config/goimapnotify/work-account.conf" + ,(goimapnotify-account + (host "imap.work.example.org") + (port 993) + (tls #t) + (username "example") + (password "12345") + (on-new-mail + (file-append mbsync "/bin/mbsync work-account")) + (on-new-mail-post + "notify-send 'New mail'") + (boxes '("INBOX" + "On Call"))))))))) +@end lisp + +Note: to utilize the config files, you need to start a separate goimapnotify +process for each one. Continuing the example above: +@code{goimapnotify -conf "$HOME/.config/goimapnotify/private-account.conf"} and +@code{goimapnotify -conf "$HOME/.config/goimapnotify/work-account.conf"}. + +@c %start of fragment +@deftp {Data Type} home-goimapnotify-configuration +Available @code{home-goimapnotify-configuration} fields are: + +@table @asis +@item @code{accounts} (default: @code{()}) (type: list-of-goimapnotify-accounts) +List of accounts that goimapnotify should watch. For each account, a +separate configuration file will be generated. +@end table + +@end deftp +@c %end of fragment + +@c %start of fragment + +@deftp {Data Type} goimapnotify-account +Available @code{goimapnotify-account} fields are: + +@table @asis +@item @code{host} (type: maybe-string) +Address of the IMAP server to connect to. + +@item @code{host-cmd} (type: maybe-string-or-file-like) +An executable or script that retrieves your host from somewhere, we +cannot pass arguments to this command from stdin. + +@item @code{port} (type: maybe-integer) +Port of the IMAP server to connect to. + +@item @code{tls?} (type: maybe-boolean) + +Use TLS? + +@item @code{tls-options} (type: maybe-goimapnotify-tls-options) +Option(s) for the TLS connection. Currently, only one option is +supported. + +@item @code{username} (type: maybe-string) +Username for authentication. + +@item @code{username-cmd} (type: maybe-string-or-file-like) +An executable or script that retrieves your username from +somewhere, we cannot pass arguments to this command from stdin. + +@item @code{password} (type: maybe-string) +Password for authentication. + +@item @code{password-cmd} (type: + maybe-string-or-file-like) +An executable or script that retrieves your password from somewhere, we +cannot pass arguments to this command from stdin. + +@item @code{xoauth2?} +(type: maybe-boolean) +You can also use xoauth2 instead of password based authentication by +setting the xoauth2 option to true and the output of a tool which can +provide xoauth2 encoded tokens in passwordCmd. Examples: +@uref{https://github.com/google/oauth2l,Google oauth2l} or +@uref{https://github.com/harishkrupo/oauth2ms,xoauth2 fetcher for O36 +5}. + +@item @code{on-new-mail} (type: maybe-string-or-file-like) +An executable or script to run when new mail has arrived. + +@item @code{on-new-mail-post} (type: maybe-string-or-file-like) +An executable or script to run after onNewMail has ran. + +@item @code{wait} (type: maybe-integer) +The delay in seconds before the mail syncing is triggered. + +@item @code{boxes} (type: maybe-list-of-strings) +Mailboxes to watch. + +@end table + +@end deftp + +@c %end of fragment + +@c %start of fragment + +@deftp {Data Type} goimapnotify-tls-options +Available @code{goimapnotify-tls-options} fields are: + +@table @asis +@item @code{reject-unauthorized?} (type: maybe-boolean) +Skip verifying CA server identify? + +@end table + +@end deftp +@c %end of fragment + @cindex msmtp @uref{https://marlam.de/msmtp, MSMTP} is a @acronym{SMTP, Simple Mail Transfer Protocol} client. It sends mail to a predefined SMTP server diff --git a/gnu/home/services/mail.scm b/gnu/home/services/mail.scm index 5445c82c67..60042be8d4 100644 --- a/gnu/home/services/mail.scm +++ b/gnu/home/services/mail.scm @@ -18,15 +18,45 @@ (define-module (gnu home services mail) #:use-module (guix gexp) + #:use-module (guix records) #:use-module (gnu services) #:use-module (gnu services configuration) #:use-module (gnu home services) #:use-module (gnu home services shepherd) + #:use-module (gnu home services utils) #:use-module (gnu packages mail) + #:use-module (gnu packages guile) + #:use-module (ice-9 match) #:use-module (ice-9 string-fun) #:use-module (srfi srfi-1) #:use-module (srfi srfi-26) - #:export (home-msmtp-configuration + #:use-module (srfi srfi-171) + #:export (home-goimapnotify-configuration + home-goimapnotify-configuration-fields + home-goimapnotify-configuration? + home-goimapnotify-configuration-accounts + home-goimapnotify-service-type + goimapnotify-account + goimapnotify-account-fields + goimapnotify-account-host + goimapnotify-account-host-cmd + goimapnotify-account-port + goimapnotify-account-tls + goimapnotify-account-tls-options + goimapnotify-account-username + goimapnotify-account-username-cmd + goimapnotify-account-password + goimapnotify-account-password-cmd + goimapnotify-account-xoauth2 + goimapnotify-account-on-new-mail + goimapnotify-account-on-new-mail-post + goimapnotify-account-wait + goimapnotify-account-boxes + goimapnotify-tls-options + goimapnotify-tls-options-fields + goimapnotify-tls-options-reject-unauthorized + + home-msmtp-configuration home-msmtp-configuration? home-msmtp-configuration-defaults home-msmtp-configuration-accounts @@ -220,3 +250,157 @@ (define home-msmtp-service-type (description "Configure msmtp, a simple @acronym{SMTP, Simple Mail Transfer Protocol} client that can relay email to SMTP servers."))) + +; Configuration for goimapnotify from (gnu packages mail) + +(define-maybe string + (prefix goimapnotify-)) +(define-maybe integer + (prefix goimapnotify-)) +(define-maybe boolean + (prefix goimapnotify-)) +(define-maybe list-of-strings + (prefix goimapnotify-)) +(define-maybe string-or-file-like + (prefix goimapnotify-)) + +(define (string-or-file-like? value) + (or (string? value) + (file-like? value))) + +(define (goimapnotify-format-field field-name) + (object->camel-case-string + (string-trim-right + (object->string field-name) + #\?))) + +(define (goimapnotify-serialize-field field-name value) + "This is converted to JSON later, so we don't return a string here" + #~(#$(goimapnotify-format-field field-name) . #$value)) + +(define goimapnotify-serialize-string goimapnotify-serialize-field) +(define goimapnotify-serialize-string-or-file-like goimapnotify-serialize-string) +(define goimapnotify-serialize-string goimapnotify-serialize-field) +(define goimapnotify-serialize-integer goimapnotify-serialize-field) +(define goimapnotify-serialize-boolean goimapnotify-serialize-field) +(define (goimapnotify-serialize-list-of-strings field-name value) + (goimapnotify-serialize-field field-name (list->array 1 value))) + +(define-configuration goimapnotify-tls-options + (reject-unauthorized? + maybe-boolean + "Skip verifying CA server identify?") + (prefix goimapnotify-)) + +(define-maybe goimapnotify-tls-options + (prefix goimapnotify-)) + +; See https://gitlab.com/shackra/goimapnotify/-/blob/423f0e65350f7e042edbd2c373f252c5a0d31dc2/config.go#L46-62 +(define-configuration goimapnotify-account + (host + maybe-string + "Address of the IMAP server to connect to.") + (host-cmd + maybe-string-or-file-like + "An executable or script that retrieves your host from somewhere, + we cannot pass arguments to this command from stdin.") + (port + maybe-integer + "Port of the IMAP server to connect to.") + (tls? + maybe-boolean + "Use TLS?") + (tls-options + maybe-goimapnotify-tls-options + "Option(s) for the TLS connection. Currently, only one option is + supported.") + (username + maybe-string + "Username for authentication.") + (username-cmd + maybe-string-or-file-like + "An executable or script that retrieves your username from + somewhere, we cannot pass arguments to this command from stdin.") + (password + maybe-string + "Password for authentication.") + (password-cmd + maybe-string-or-file-like + "An executable or script that retrieves your password from + somewhere, we cannot pass arguments to this command from stdin.") + (xoauth2? + maybe-boolean + "You can also use xoauth2 instead of password based authentication + by setting the xoauth2 option to true and the output of a tool + which can provide xoauth2 encoded tokens in passwordCmd. + Examples: @url{https://github.com/google/oauth2l, Google oauth2l} + or + @url{https://github.com/harishkrupo/oauth2ms, xoauth2 fetcher for O365}.") + (on-new-mail + maybe-string-or-file-like + "An executable or script to run when new mail has arrived.") + (on-new-mail-post + maybe-string-or-file-like + "An executable or script to run after on-new-mail has ran.") + (wait + maybe-integer + "The delay in seconds before the mail syncing is triggered.") + (boxes + maybe-list-of-strings + "Mailboxes to watch.") + (prefix goimapnotify-)) + +(define list-of-goimapnotify-accounts? + (list-of (match-lambda (? string?) ($ )))) + +(define-configuration/no-serialization home-goimapnotify-configuration + (accounts + (list-of-goimapnotify-accounts '()) + "List of accounts that goimapnotify should watch. + For each account, a separate configuration file + will be generated.")) + +(define (home-goimapnotify-extension old-config extensions) + (match-record old-config + (accounts) + (home-goimapnotify-configuration + (inherit old-config) + (accounts (append accounts + (append-map + home-goimapnotify-configuration-accounts + extensions)))))) + +(define (goimapnotify-files config) + (match-record config + (accounts) + (map (match-lambda + ((path account) + (list path + (computed-file + (string-append "mail-imapnotify-config-" + (goimapnotify-account-host account)) + (with-extensions (list guile-json-4) + #~(begin + (use-modules (json builder)) + (with-output-to-file #$output + (lambda () + (scm->json + '(#$@(list-transduce + (base-transducer account) + rcons + goimapnotify-account-fields)) + #:pretty #t))))))))) + accounts))) + +(define home-goimapnotify-service-type + (service-type + (name 'home-goimapnotify-service) + (extensions + (list (service-extension + home-files-service-type + goimapnotify-files))) + (compose identity) + (extend home-goimapnotify-extension) + (default-value (home-goimapnotify-configuration)) + (description "Configure goimapnotify to execute scripts on IMAP + mailbox changes."))) base-commit: 513bf164592e2b44e3e556cc5099a19bd6977790 -- 2.41.0