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: