From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id ULx0GggtjGIa5AAAbAwnHQ (envelope-from ) for ; Tue, 24 May 2022 02:55:36 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id AA1HGggtjGIqewAAauVa8A (envelope-from ) for ; Tue, 24 May 2022 02:55:36 +0200 Received: from mail.notmuchmail.org (yantan.tethera.net [IPv6:2a01:4f9:c011:7a79::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id EF63420EBA for ; Tue, 24 May 2022 02:55:35 +0200 (CEST) Received: from yantan.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id E63045F6CC; Tue, 24 May 2022 00:48:28 +0000 (UTC) Received: from mail-oa1-x2e.google.com (mail-oa1-x2e.google.com [IPv6:2001:4860:4864:20::2e]) by mail.notmuchmail.org (Postfix) with ESMTPS id B10925F6BC for ; Tue, 24 May 2022 00:48:25 +0000 (UTC) Received: by mail-oa1-x2e.google.com with SMTP id 586e51a60fabf-d39f741ba0so20464031fac.13 for ; Mon, 23 May 2022 17:48:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:in-reply-to:references:date:message-id:mime-version; bh=Pt7IZHlIkui/SVXUQ/b2c+B2JTlSlH/jJ9ehQTdLPtc=; b=SpLocXfPvJyPh14+fuI1zpIaVK8Wvq8Lokcr5XjG01AGbY2Rj3SZWWDmDs15BqJxzG m9+9muEX1LOgCxW3v4o+fkyyCNFkYoJiW7NOaKbti7rHD9MHoVvkw1VApxcbNDtghZWX wj/T9kJtj0aoTFBzD7KPS5pP+/nABfCiOgjXljZVx3IWq1lz3msX7o8DrorOU7btycvX 3GC6TcXgv9/zEakMrEhTK3dFkwKlEs5q4/9DoNwGh6/WEkKxPFtVs20lPGMmOf9+jG+u h1TekU0MZSV2NkgZKZhecQ4jzvZVKkwtFzogP9LvzWSzBG6gIUidbm+4vqcRERkGsaB2 sWFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:in-reply-to:references:date :message-id:mime-version; bh=Pt7IZHlIkui/SVXUQ/b2c+B2JTlSlH/jJ9ehQTdLPtc=; b=TWQwi4RmksSdJMDjBmD8Dvs0v0V7cSfsaRMb71btt22DrxrSmC9hbheHH6N2JZ0lSc c3JpYtVwEO/RmYDX4ZA0XqPPJkYX7myYimHUb5NFJIDEEz2Hn++Djih21Yy257G4A6EM gkjHydIxAdRqCEE3PbVJuLSiUU073xQJhAxKZLy8S8XL4C+XOJAlq9wEK3cAfz1XLAXM 2GEXH3mpYoHPdjK/V2TIbV8/0yXOdCp0SQIjNdmuDC5Rkolv18JE7B7c9PiRyP6f4GNJ 1J9kuHV6CQ4YKQ2C2m9IiuiErAe6AcQL8GsPCSlWagbEIGs/b1Sf30oQllgxnhfVhlHK qLKg== X-Gm-Message-State: AOAM5326lGVphe9QAJBCLS82obEyZgWosnbUMwrgdxvXnTRiO8lXJQXU Y+yLL9v2CBA/yHwzhcChZ0g0RLg/jLo= X-Google-Smtp-Source: ABdhPJzKg7pfawuOo22ikkSE1UsUawF3o1uWgnDXSy3sGOt2K23L+ZDtxETn5kihtWFX+10W3gTE5Q== X-Received: by 2002:a05:6870:9a09:b0:e9:20a7:6cf6 with SMTP id fo9-20020a0568709a0900b000e920a76cf6mr1039571oab.122.1653353303625; Mon, 23 May 2022 17:48:23 -0700 (PDT) Received: from ergo ([186.236.209.77]) by smtp.gmail.com with ESMTPSA id h18-20020a056830401200b0060603221278sm4495128ots.72.2022.05.23.17.48.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 May 2022 17:48:22 -0700 (PDT) From: =?utf-8?Q?Jo=C3=A3o?= Pedro To: erik colson , notmuch@notmuchmail.org Subject: Re: moving mail to another maildir based on tags and renaming files In-Reply-To: <87ilpwc68x.fsf@beavernet.be> References: <87ilpwc68x.fsf@beavernet.be> Date: Mon, 23 May 2022 21:48:19 -0300 Message-ID: <871qwjbvsc.fsf@gmail.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Message-ID-Hash: F7GQDXN4QJLTZ2TNXJ3AHDO2UF53PSM7 X-Message-ID-Hash: F7GQDXN4QJLTZ2TNXJ3AHDO2UF53PSM7 X-MailFrom: jpedrodeamorim@gmail.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-notmuch.notmuchmail.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.3 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Migadu-Flow: FLOW_IN X-Migadu-To: larch@yhetil.org X-Migadu-Country: DE ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1653353736; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references:list-id:list-help: list-owner:list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=IdOEuX5FlToskGej+rRrF8dx1FURdi/imQ1YVhWaWWI=; b=QyLxabIJJGeINJU6M4AcCjBq80sGTigmSy71PCjpv8CkPmqQyxRGmL4bFqMoyrmDQ48q8+ KLMYVZDRRaGHOniW9yS/QJNlVgeryvo9aYfyUsPbteptqSlT2lliYTDTj68004wvWxNnUZ CV3M7MOMNYh2ryrEzpiUPvZSzuBErbSYwTrgCDRRNm4WE69tv3EdNBgGasnv3trPHK6FZt eBqKj+QKOuaEQIGvNGITGh4lbaXlyamjbNaEzgkccJdoMJ+lEsTXNOPEOSkOJYM3HX8e50 6v5G/sO6+FNI2/PZXVmE+iSXxO/7/lYsiSzaw+sGkngKJeuQA1uQQHeutttm7w== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1653353736; a=rsa-sha256; cv=none; b=I3QF88+0jAUAwsu5MRdvaHlZIbOu+tRtUqQmLuz7TDHDCzoFSSoVU+QLvRhr4C6Gpigwcj V/fDzylqAxaoa/jZyCcIxxS+CbKCvF5lLQJjcaRp1zIdbOSUdjGlTOyWaCZmCj3G8TZQTs WG4nz8KwhEpkKL2QOofMjh6icD6J0UVYbwoeU9eHH9jW0TMQPF6qRjyVgRBk63kqrK05zZ wrzBMaZlgNaFshh32MZ1QDwh+CRvTvEhGnwyOVz3vpFxWNOucjk9Ez8wkqwyfUm07Apd9Q EWVVWNMP3sU78EDdmZvVSy780Wc+lwH9inD2epuHpeTNGng4pQy6nizJkIpRSg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=gmail.com header.s=20210112 header.b=SpLocXfP; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 2a01:4f9:c011:7a79::1 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Spam-Score: 6.08 Authentication-Results: aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=gmail.com header.s=20210112 header.b=SpLocXfP; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 2a01:4f9:c011:7a79::1 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Queue-Id: EF63420EBA X-Spam-Score: 6.08 X-Migadu-Scanner: scn0.migadu.com X-TUID: AteIx7F3LCo/ --=-=-= Content-Type: text/plain On Mon, May 23 2022 23:02, erik colson wrote: > Hi, > > I would like to move mails selected by a notmuch query > (i.e. "tag:movethismailtobox-ThisBox") to *ThisBox* > I need this to somewhat still have usable access through my phone IMAP > client. What I have is tags that represent IMAP folders, namedely "inbox", "sent", "trash", "spam" and "all" (representing "All Mail" from Gmail). And I use a similar set of functions as "inwit ", albeit a bit shorter. I'll be attaching the file. > I am actually using afew already, but as I have 1000+ mailboxes it is > unmaintainable to create the rules manually. I never used afew, but the way I do it doesn't require any manual rules on the =pre-new= side of things, where I do the moving/renaming. I do have to do some manual tagging, though, but that's manageable mainly because I only have 6 mailboxes to handle and they all have similar structure (and I seem to be able to replicate this structure in most Mailbox mail providers). > It wouldn't be very difficult to generate the necessary > notmuch search --output=files ... | xargs mv ... That's pretty much the crux of if, and you should be able to come up with your own way to suit your own needs. All its needed is basically to remove the UID part of the filename indeed, though I do it with `sed` instead of just using string expansion. My setup is basically me trying to translate Andrew Tropin's setup [1]; see both where he defines `move-out-untagged-messages` and `move-in-tagged-messages`. Notice that they both have arguments which I haven't respected, and it would be much easier to implement it in a proper programming language, but I don't like to rely on having any language installed cause I'd rather have my setup work on any Unix-like computer I have to deal with in different contexts, in which some of them I have a restriction on the installation of packages). There he is using Guile on Guix Home to generate configuration files, sort of doing what you alluded as being your first option, though not really scripting, and with that he has the power of a general purpose programming language which so happens to also be a Lisp. > but, there is a catch: I use isync to synchronize my mails with my IMAP > server and therefor I must rename every message file when moving it. As > I am not enough aware of maildir and IMAP servers, I am pretty ignorant > to what the new filename should be. I also use isync, and I seem to have been able to keep my phone's mail structure (looking through a mail app) largely in sync with my personal files. All I haven't been able to do, mostly because I haven't finished my mail server setup yet (also doesn't apply to my phone), is to also sync the notmuch tags, since only a handful of tags are responsible for moving away my mail. Also, one other caveat is that you'd best have tagging shortcuts that remove all other tags that map to a folder, since that may cause confusion and continuous moving of files, e.g. if you have +inbox +sent in your mail, on one sync it might be moved to the inbox/ folder and on the other to the sent/ folder, depending on the order of the tags on your script. Keep in mind that this only applies to my case, in which I want to keep 5 different folders in sync. If you just want to move from inbox/ to somewhere else, especially if you're only concerned with trash/, junk/ or whatever, it should be simpler, needing only to search for mails with such tags. I'll also be attaching my tagging configuration for notmuch in Emacs. [1] https://github.com/abcdw/rde/blob/master/rde/features/mail.scm#L547 I have a file for the moving of mail portion, given that I use it in both =pre-new= and =post-new= hooks: --=-=-= Content-Type: text/plain Content-Disposition: inline; filename=move-mail Content-Description: move-mail script #!/bin/sh # # moving mail rules for notmuch # # the moving of mails is adapted from: # https://github.com/abcdw/rde/blob/master/rde/features/mail.scm alias nmsearch="$(command -v notmuch) search --exclude=false --output=files -- not folder:queued and" # move out untagged messages move_out() { for tag in inbox sent trash spam; do # if the $tag was removed, but the file still is in the folder, move it out for f in $(nmsearch path:"/.*\/${tag}\//" and not tag:"$tag" | grep "/${tag}/"); do new=$(echo "$f" | sed "s;/${tag}/;/all/;" | sed 's/,U=[0-9]*:/:/') [ -f "$f" ] && mv -v "$f" "$new" done done } # move in tagged messages move_in() { for tag in inbox sent trash spam; do # if the $tag was added, and the file is not on the folder, move it in for f in $(nmsearch not path:"/.*\/${tag}\//" and tag:"$tag"); do new=$(echo "$f" | sed "s;/[[:alnum:]]*/cur/;/${tag}/cur/;" | sed 's/,U=[0-9]*:/:/') [ -f "$f" ] && mv -v "$f" "$new" done done } case $1 in out) move_out ;; in) move_in ;; *) move_out move_in ;; esac --=-=-= Content-Type: text/plain And this is my =pre-new= hook: --=-=-= Content-Type: text/plain Content-Disposition: inline; filename=pre-new Content-Description: pre-new hook #!/bin/sh # # commands/hooks to run before `notmuch new` # alias nmsearch="$(command -v notmuch) search --exclude=false --output=files -- not folder:queued and" # do the moving things ~/.config/notmuch/hooks/move-mail # remove files tagged with 'rm', a tag i use to actually delete emails for f in $(nmsearch --output=files -- tag:rm); do [ -f "$f" ] && echo rm -i "$f"; done mbsync -c "${XDG_CONFIG_HOME:-${HOME}/.config}/isync/mbsyncrc" -a --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: base64 DQpUaGUgcmVsZXZhbnQgcGFydCBvZiBteSBFbWFjcyBjb25maWd1cmF0aW9uIGZvciBub3RtdWNo IGlzIHRoZQ0KZm9sbG93aW5nOg0KDQojK2JlZ2luX3NyYyBlbWFjcy1saXNwDQooZGVmY29uc3Qg bm90bXVjaC1tYXJrLWRlbGV0ZWQtdGFncyAnKCIrdHJhc2giICItaW5ib3giICItYXJjaGl2ZWQi ICItc2VudCIgIi1zcGFtIikNCiAgIkxpc3Qgb2YgdGFncyB0byBtYXJrIGZvciBkZWxldGlvbi4i KQ0KDQooZGVmY29uc3Qgbm90bXVjaC1tYXJrLXJlbW92ZWQtdGFncyAoY29ucyAiK3JtIiBub3Rt dWNoLW1hcmstZGVsZXRlZC10YWdzKQ0KICAiTGlzdCBvZiB0YWdzIHRvIG1hcmsgZm9yIHJlbW92 YWwuIikNCg0KKGRlZmNvbnN0IG5vdG11Y2gtbWFyay1zcGFtLXRhZ3MgJygiK3NwYW0iICItaW5i b3giICItdHJhc2giICItc2VudCIgIi1hcmNoaXZlZCIpDQogICJMaXN0IG9mIHRhZ3MgdG8gbWFy ayBhcyBzcGFtLiIpDQoNCihkZWZjb25zdCBub3RtdWNoLW1hcmstZmxhZ2dlZC10YWdzICcoIitm bGFnZ2VkIikNCiAgIkxpc3Qgb2YgdGFncyB0byBtYXJrIGFzIGltcG9ydGFudCAoZmxhZ2dlZCku IikNCg0KKGRlZmNvbnN0IG5vdG11Y2gtbWFyay1zaG9wcGluZy10YWdzICcoIi1pbmJveCIgIitz aG9wcGluZyIpDQogICJMaXN0IG9mIHRhZ3MgdG8gbWFyayBhcyBzaG9wcGluZy4NClRoaXMgaXMg cmVsYXRlZCB0byBlbWFpbHMgZnJvbSBzdHVmZiBJIGJ1eSBvbmxpbmUuIikNCg0KKGRlZmNvbnN0 IG5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oVUZSTikN Cg== --=-=-= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline --=-=-=--