From: "inwit" <inwit@sindominio.net>
To: "Tomi Ollila" <tomi.ollila@iki.fi>, <notmuch@notmuchmail.org>
Subject: Re: Folder+tags
Date: Mon, 28 Dec 2020 17:51:15 +0100 [thread overview]
Message-ID: <C84KO8MALMPD.3634V4SXSKC5U@bisio> (raw)
In-Reply-To: <m2lfdjj6rm.fsf@guru.guru-group.fi>
Thanks, Tomi.
While I learn enough elisp to dive into those hooks, I've solved my
need to move files according to tags with the following pre-new script,
which recycles parts from other scripts around:
#!/bin/bash
echo "[pre-new] Syncronizing tags and folders... "
path=/home/jlaznarte/mail/UNED/
exclude='signed attachment spam draft flagged passed replied unread encrypted deleted'
count=$(notmuch count 'folder:Inbox and not tag:inbox')
# Move a message file while removing its UID-part
function safeMove { s=${1##*/}; s=${s%%,*}; mv -f $1 $2/$s; }
if [ $count = 0 ]; then
echo "[pre-new] No messages needed moving."
else
echo "[pre-new] Moving" $count "messages to their corresponding folder."
for message_id in $(notmuch search --output=messages \
'folder:Inbox and not tag:inbox')
do
# Find the tags of the message that we need to move
tags_orig=$(notmuch search --output=tags $message_id)
# Remove notmuch special tags
# (do not correspond to folders)
tags=$(tr ' ' '\n' <<< "$tags_orig" \
| grep -vf <(tr ' ' '\n' <<< "$exclude") | paste -sd ' ')
# Get the path and filename for the message
filename=$(notmuch search --output=files $message_id)
echo "Moving message to" $tags
safeMove $filename $path$tags"/cur/"
done
fi && mbsync
On Sun Dec 27, 2020 at 10:09 PM CET, Tomi Ollila wrote:
> On Sun, Dec 27 2020, inwit@sindominio.net wrote:
>
> > On Sun Dec 27, 2020 at 2:12 PM CET, Tomi Ollila wrote:
> >> On Sun, Dec 27 2020, inwit@sindominio.net wrote:
> >>
> >> There sure is notmuch-after-tag-hook (in emacs MUA), but -hooks don't
> >> take argument(s) so how does it know what was tagged (cannot remember
> >> if there are let-bound (dynamically bound!) variables that could have
> >> such information).
> > Apparently (I'm a total noob wrt elisp), the hook should know what was
> > tagged and how it was tagged. In its documentation it reads:
> > «'tag-changes' will contain the tags that were added or removed as a
> > list of strings of the form "+TAG" or "-TAG". 'query' will be a string
> > containing the search query that determines the messages that were
> > tagged."
>
> nos that you said it, query is a variable the hook can access to know
> what
> was tgged. filnames it doesn't contain. with the query you can find the
> filenames with 'notmuch search --output=files query
>
> (writing on mobiledvice in a moving train, therefore terse)
>
> Tomi
>
> >
> >>
> >> Whateveruuuuuuch way, tags are assigned to Message-Id:, so you'd need to find
> >> the filename.
> > Having the 'query' mentioned above should be enough to find the
> > filename, shouldn't it?
> >
> >> With shell-command you can do notmuch | xargs pipeline
> >> (plain 'mv' w/ 'shell-command' would have been easily replaced w/
> >> 'rename-file' if that were enough).
> > I'm not sure if I get what you're trying to say: is rename-file not
> > enough?
> >
> > In any case, if there's really a way to pass 'tag-changes' and 'query'
> > to such a hook, I could use that hook to move the file with either 'mv'
> > with 'shell-command' or directly with rename-file, am I wrong?
> >
> > In any case, I first need to actually learn elisp. This seems as the
> > right reason to finally get into it.
> >
> > Thanks for your help.
> >
> > Salud,
> >
> >>
> >> >
> >> > Salud,
> >>
> >> Tomi
> > _______________________________________________
> > notmuch mailing list -- notmuch@notmuchmail.org
> > To unsubscribe send an email to notmuch-leave@notmuchmail.org\r
next prev parent reply other threads:[~2020-12-28 16:51 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-23 11:53 Folder+tags inwit
2020-12-24 13:59 ` Folder+tags Alan Schmitt
2020-12-25 16:41 ` Folder+tags inwit
2020-12-25 8:04 ` Folder+tags Jaume Devesa
2020-12-25 17:27 ` Folder+tags inwit
2020-12-27 11:59 ` Folder+tags inwit
2020-12-27 13:12 ` Folder+tags Tomi Ollila
2020-12-27 17:14 ` Folder+tags inwit
2020-12-27 21:09 ` Folder+tags Tomi Ollila
2020-12-28 16:51 ` inwit [this message]
2021-01-03 18:09 ` Folder+tags inwit
2021-01-03 20:01 ` Folder+tags Tomi Ollila
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=C84KO8MALMPD.3634V4SXSKC5U@bisio \
--to=inwit@sindominio.net \
--cc=notmuch@notmuchmail.org \
--cc=tomi.ollila@iki.fi \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).