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 SApIJJOXW2WpAQAAauVa8A:P1 (envelope-from ) for ; Mon, 20 Nov 2023 18:29:55 +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 SApIJJOXW2WpAQAAauVa8A (envelope-from ) for ; Mon, 20 Nov 2023 18:29:55 +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 DD3F544E89 for ; Mon, 20 Nov 2023 18:29:54 +0100 (CET) Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=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-Seal: i=1; s=key1; d=yhetil.org; t=1700501395; a=rsa-sha256; cv=none; b=Q6v2XA0MrRbadBAfOOcvQ02CdFLWicb5tu3gM606nxuLCyECiSKlv5Fq01+xw0nnb54dfT x3b4OQjPOp71+9astmkLkUS66nZKDdhqObxsk1dPkjIGfXK+f6S2w4zButlb1ugh4Iys+5 ohVpi79wPlDmPursSo9n4L7owkgt9BXj67XTS/E+Qw/hqEP5gTO0AE5ia+s4kajx9Bsshe GIMYapcdkWYdGDQPnsK2SoKd73tOzT2SXv3+oje/68TI5cwuzxUFJsb5sILqJj+V8ZjmBW Z+q8IzKT9gbB/059hcOKEgtcx7d4Ru6sFRDZIlgC1kxZyay5keR2o2QMwStdIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1700501395; 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: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; bh=qYIQTFpyfFXl9TSEz05RWb3o5LwpKCSgCdfv7oEnPi8=; b=UAZqD9937IpNYlE7IqqrYb1FHOj4XD/gB/Rux43pEvIG/Qi1dqMnPROiSzA+QNarue+LSJ /gxq2ccubej7Hi2UWaoV7zkHswsst5CljoAc4LR2v0uCMuGPxNQOqwcK9PllPcoB0fRzd6 4votpxImtGaik/jPE0pG7JCc2wEZ2HmHaFzj32NzlOyzuMNdr1RdIZPv/ijzO5jJPViYHR M2NcZaXkApU4YeP2NS5KFTvKSRdtFm8ppnPvmgoN84HruM+5KoOSHbyDuBV+QtNd2kAvl1 7cdaleI6mvoTGdMg8d//qeyTh7iCj5EsYrSv4Km91G8lathngDePYBhY8nPWNg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=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 1r57tN-0005yT-RA; Mon, 20 Nov 2023 12:17:01 -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 1r57tM-0005xu-AE for guix-patches@gnu.org; Mon, 20 Nov 2023 12:17:00 -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 1r57tL-0004Hv-I6 for guix-patches@gnu.org; Mon, 20 Nov 2023 12:17:00 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1r57tN-00006a-LD for guix-patches@gnu.org; Mon, 20 Nov 2023 12:17:01 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#66557] [PATCH] home: services: Add goimapnotify service. Resent-From: Bruno Victal Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 20 Nov 2023 17:17:01 +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: Nils Landt Cc: 66557@debbugs.gnu.org Received: via spool by 66557-submit@debbugs.gnu.org id=B66557.1700500599364 (code B ref 66557); Mon, 20 Nov 2023 17:17:01 +0000 Received: (at 66557) by debbugs.gnu.org; 20 Nov 2023 17:16:39 +0000 Received: from localhost ([127.0.0.1]:54360 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r57t0-00005m-1Q for submit@debbugs.gnu.org; Mon, 20 Nov 2023 12:16:38 -0500 Received: from smtpm3.myservices.hosting ([185.26.105.234]:59420) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r57sx-00005Q-EX for 66557@debbugs.gnu.org; Mon, 20 Nov 2023 12:16:36 -0500 Received: from mail1.netim.hosting (unknown [185.26.106.173]) by smtpm3.myservices.hosting (Postfix) with ESMTP id CB79C20FA7; Mon, 20 Nov 2023 18:16:30 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by mail1.netim.hosting (Postfix) with ESMTP id 443CF80092; Mon, 20 Nov 2023 18:16:27 +0100 (CET) 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 C8dHNtBGiehZ; Mon, 20 Nov 2023 18:16:26 +0100 (CET) Received: from [192.168.1.116] (unknown [10.192.1.83]) (Authenticated sender: lumen@makinata.eu) by mail1.netim.hosting (Postfix) with ESMTPSA id 5BF6780079; Mon, 20 Nov 2023 18:16:26 +0100 (CET) Message-ID: Date: Mon, 20 Nov 2023 17:16:25 +0000 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird From: Bruno Victal References: Content-Language: en-US In-Reply-To: Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="------------ktqh07dFjGbp4K27zTEBzkDk" 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 X-Migadu-Scanner: mx11.migadu.com X-Spam-Score: -8.20 X-Migadu-Queue-Id: DD3F544E89 X-Migadu-Spam-Score: -8.20 X-TUID: bW2dzYzKWD6B This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --------------ktqh07dFjGbp4K27zTEBzkDk Content-Type: multipart/mixed; boundary="------------1nSCjVH3KzEBNhKYYg95Fy7I"; protected-headers="v1" From: Bruno Victal To: Nils Landt Cc: 66557@debbugs.gnu.org Message-ID: Subject: Re: [bug#66557] [PATCH] home: services: Add goimapnotify service. References: In-Reply-To: --------------1nSCjVH3KzEBNhKYYg95Fy7I Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hi Nils, On 2023-10-15 15:01, Nils Landt wrote: > This patch adds a home service for generating goimapnotify JSON > configuration files. [=E2=80=A6] > +@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 "pass my-private-ema= il-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.con= f" > + ,(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 goimap= notify > +process for each one. Continuing the example above: > +@code{goimapnotify -conf "$HOME/.config/goimapnotify/private-account.c= onf"} and > +@code{goimapnotify -conf "$HOME/.config/goimapnotify/work-account.conf= "}. Not a goimapnotify user but this looks like a daemon application. I don't like this design much, I think goimapnotify should be launched an= d managed using shepherd instead of simply exposing these files to the user. > +@item @code{tls} (type: maybe-boolean) > + > +Use TLS? Boolean fields are generally suffixed with '?'. (e.g. 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. I'd prefer to write it as =E2=80=9Cstdin=E2=80=9D (lowercase) or expand i= t to =E2=80=9Cstandard input=E2=80=9D. > +@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}. Same remark as 'tls' option. > +@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. =E2=80=9CAn executable or script to run after @code{on-new-mail} has ran.= =E2=80=9D > +@table @asis > +@item @code{reject-unauthorized} (type: maybe-boolean) > +Skip verifying CA server identify? Same remark as 'tls' option. > @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 > 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 > @file{~/.config/msmtp/config} file. > - > + > As an example, here is how you would configure @code{msmtp} for a sing= le > account: > - > + > @lisp > (service home-msmtp-service-type > (home-msmtp-configuration > @@ -44739,101 +44876,101 @@ Mail Home Services > @end defvar >=20 > @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-accou= nts) > 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 >=20 > @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{log-file} (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 informatio= n 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")= =2E > - > + > @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{password-eval} (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 These are unrelated changes, can you drop these hunks? > +(define (goimapnotify-maybe-serialize field-name value serialization-f= unction) > + (if (maybe-value-set? value) > + (serialization-function field-name value) > + "")) > + > +(define (goimapnotify-serialize-maybe-string-or-file-like field-name v= alue) > + (goimapnotify-maybe-serialize field-name value > + goimapnotify-serialize-string-or-file-l= ike)) > + > +(define goimapnotify-serialize-string goimapnotify-serialize-field) > +(define (goimapnotify-serialize-maybe-string field-name value) > + (goimapnotify-maybe-serialize field-name value goimapnotify-serialize= -string)) > + > +(define (goimapnotify-serialize-maybe-integer field-name value) > + (goimapnotify-maybe-serialize field-name value goimapnotify-serialize= -integer)) > +(define goimapnotify-serialize-integer goimapnotify-serialize-field) > + > +(define (goimapnotify-serialize-maybe-boolean field-name value) > + (goimapnotify-maybe-serialize field-name value goimapnotify-serializ= e-boolean)) > +(define goimapnotify-serialize-boolean goimapnotify-serialize-field) > + > +(define (goimapnotify-serialize-maybe-list-of-strings field-name value= ) > + (goimapnotify-maybe-serialize field-name value goimapnotify-serializ= e-list-of-strings)) > +(define (goimapnotify-serialize-list-of-strings field-name value) > + (goimapnotify-serialize-field field-name (list->array 1 value))) > + > +(define (goimapnotify-serialize-maybe-goimapnotify-tls-options field-n= ame config) > + (goimapnotify-maybe-serialize field-name config > + goimapnotify-serialize-goimapnotify-tl= s-options)) This isn't needed, fields whose maybe-values are unset don't call the serializing procedures. > +(define (goimapnotify-serialize-goimapnotify-tls-options field-name co= nfig) > + (goimapnotify-serialize-field > + field-name > + (prepare-configuration-for-json config goimapnotify-tls-options-fi= elds))) > + > +(define (prepare-configuration-for-json config fields) > + "Convert the configuration to the format expected by guile-json. > + Unset maybe-values do not appear in the configuration file." > + (filter > + (lambda (val) > + (not (unspecified? val))) > + (map > + (lambda (field) > + (let ((value ((configuration-field-getter field) config))) > + (if (maybe-value-set? value) > + ((configuration-field-serializer field) > + (configuration-field-name field) > + value) > + *unspecified*))) > + fields))) You can use 'serialize-configuration' instead which accounts for the unse= t maybe-values. > + > +(define-configuration goimapnotify-tls-options > + (reject-unauthorized > + (maybe-boolean) > + "Skip verifying CA server identify?") > + (prefix goimapnotify-)) > + > +(define-maybe goimapnotify-tls-options) > + > +; See https://gitlab.com/shackra/goimapnotify/-/blob/master/config.go?= ref_type=3Dheads#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 h= ost 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 u= sername from > + somewhere, we cannot pass arguments to this co= mmand from Stdin.") > + (password > + (maybe-string) > + "Password for authentication.") > + (password-cmd > + (maybe-string-or-file-like) > + "An executable or script that retrieves your p= assword from > + somewhere, we cannot pass arguments to this co= mmand 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 pa= sswordCmd. > + Examples: @url{https://github.com/google/oauth= 2l, 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 onNewMai= l 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-)) You can omit the parentheses around the field-type. > +(define (list-of-goimapnotify-accounts? lst) > + "List is in the form of '((file-name file-like))" > + (every (lambda (element) > + (match element > + ((string ($ )) > + #t) > + (_ #f))) > + lst)) You can replace this with: --8<---------------cut here---------------start------------->8--- (define list-of-goimapnotify-accounts? (list-of goimapnotify-account?)) --8<---------------cut here---------------end--------------->8--- > +(define-configuration/no-serialization home-goimapnotify-configuration= > + (accounts > + (list-of-goimapnotify-account= s '()) > + "List of accounts that goimap= notify 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)))))) This looks misindented, the .dir-locals file automatically handles this if you are using emacs. > + > +(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 script= s on IMAP > + mailbox changes."))) Stylistically, I'd indent this as: --8<---------------cut here---------------start------------->8--- (define home-goimapnotify-service-type (service-type (name 'home-goimapnotify-service) (extensions =E2=80=A6 --8<---------------cut here---------------end--------------->8--- My 2=C2=A2! --=20 Furthermore, I consider that nonfree software must be eradicated. Cheers, Bruno. --------------1nSCjVH3KzEBNhKYYg95Fy7I-- --------------ktqh07dFjGbp4K27zTEBzkDk Content-Type: application/pgp-signature; name="OpenPGP_signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="OpenPGP_signature.asc" -----BEGIN PGP SIGNATURE----- iHUEARYKAB0WIQTAPCseV0HOaN0YFheobOGDL+spVQUCZVuUaQAKCRCobOGDL+sp VWwCAQD6kYQ+nXCnGPvvjLKWDmroNSYXo7bG15CuPkqIgBvs4wEAjIg+HbbC8utF Kce+ACMm6sPsUJuv+T10WJ6LF5PZpgM= =Xd5Z -----END PGP SIGNATURE----- --------------ktqh07dFjGbp4K27zTEBzkDk--