Folder+tags

classic Classic list List threaded Threaded
12 messages Options
inwit inwit
Reply | Threaded
Open this post in threaded view
|

Folder+tags

Hi!

This is my first message so I'll start by congratulating all the
community around notmuch. Great piece of work you have here!

I guess that my question must have been surely asked before, but I can't
seem to find it in the lists' archive. My excuses if it is the case that
my search abilities have failed. It has happened before.

So, what I'm trying is to have a notmuch system up and running while
preserving my folder structure fully functional in the IMAP server. I
know that most of you will agree that folders are a thing from the past,
but the fact is that, in the past, I've devoted quite a lot of time to
sort my mails, and now I have a 3-level subfolder structure which is
hard-wired in my brain, so up to now sometimes I'm still keen to
searching messages in their expected folders. I guess it's a matter of
time until I abandon this scheme and dive fully into tag based email,
but for the time being I'm afraid of losing that folder structure for
good.

Anyway, I've been reading all around the web about this, and the closest
I got is using the aerc client, where I can configure a Maildir worker
and a notmuch worker, being able to use the former for reading and
classifying mail into folders and the later for tag-based searching.
This works, but at the same time, no matter how exciting the development
of aerc is (and it is a beautiful little piece of code), it is still
very far from emacs mail-mode.

What I would like to, then, is to use notmuch-el to read and classify my
mail. And the functionality I'm missing at the moment is a way to move
an email from the inbox to its corresponding folder, hopefully updating
its folder tags at the same time. That is: I would (mb)sync my mail from
my company's IMAP server to my Maildir folder structure, then I'd go to
the Inbox tag/folder, I'd read my mail and then, by hitting Shift+m, for
example, I'd be able to move that precise email, both in files and tags,
to its corresponding Maildir folder, so my next call to mbsync actually
moves the message in the IMAP server folders as well.  Does that make
sense?  Does anyone know how would I get to something like that?

Again, sorry if this is redundant, and congratulations on the good work.

Salud,
_______________________________________________
notmuch mailing list -- [hidden email]
To unsubscribe send an email to [hidden email]
Alan Schmitt Alan Schmitt
Reply | Threaded
Open this post in threaded view
|

Re: Folder+tags

On 2020-12-23 12:53, "inwit" <[hidden email]> writes:

> What I would like to, then, is to use notmuch-el to read and classify my
> mail. And the functionality I'm missing at the moment is a way to move
> an email from the inbox to its corresponding folder, hopefully updating
> its folder tags at the same time. That is: I would (mb)sync my mail from
> my company's IMAP server to my Maildir folder structure, then I'd go to
> the Inbox tag/folder, I'd read my mail and then, by hitting Shift+m, for
> example, I'd be able to move that precise email, both in files and tags,
> to its corresponding Maildir folder, so my next call to mbsync actually
> moves the message in the IMAP server folders as well.  Does that make
> sense?  Does anyone know how would I get to something like that?
To move mail I use afew in move mode
(https://afew.readthedocs.io/en/latest/move_mode.html). I use it to move
deleted messages to the trash, and old email to an archive folder. I
guess it could work in your case.

Best,

Alan

_______________________________________________
notmuch mailing list -- [hidden email]
To unsubscribe send an email to [hidden email]

signature.asc (539 bytes) Download Attachment
Jaume Devesa Jaume Devesa
Reply | Threaded
Open this post in threaded view
|

Re: Folder+tags

In reply to this post by inwit
Hello,

> What I would like to, then, is to use notmuch-el to read and classify my
> mail. And the functionality I'm missing at the moment is a way to move
> an email from the inbox to its corresponding folder, hopefully updating
> its folder tags at the same time. That is: I would (mb)sync my mail from
> my company's IMAP server to my Maildir folder structure, then I'd go to
> the Inbox tag/folder, I'd read my mail and then, by hitting Shift+m, for
> example, I'd be able to move that precise email, both in files and tags,
> to its corresponding Maildir folder, so my next call to mbsync actually
> moves the message in the IMAP server folders as well.  Does that make
> sense?  Does anyone know how would I get to something like that?
>
> Again, sorry if this is redundant, and congratulations on the good work.
>
I sync my email with offlineimap and I do something similar, but using
the `presync.sh` hook that offlineimap provides, via simple `xargs`:

        notmuch search --output=files --format=text0 \
        folder:mailbox/INBOX -tag:inbox | xargs -0 --no-run-if-empty \
        mv -t ~/mail/mailbox/Archive/$YEAR/new/

So just before offlineimap starts another round of sync, the emails
tagged as 'not inbox' inside the INBOX folder are being moved to the
Archive/${YEAR} folder.

I've never used emacs, so I ignore if you can do something similar by
binding keys in emacs (but I guess you can).

Hope that helps,
_______________________________________________
notmuch mailing list -- [hidden email]
To unsubscribe send an email to [hidden email]

signature.asc (499 bytes) Download Attachment
inwit inwit
Reply | Threaded
Open this post in threaded view
|

Re: Folder+tags

In reply to this post by Alan Schmitt
On Thu Dec 24, 2020 at 2:59 PM CET, Alan Schmitt wrote:
> To move mail I use afew in move mode
> (https://afew.readthedocs.io/en/latest/move_mode.html). I use it to
> move deleted messages to the trash, and old email to an archive
> folder. I guess it could work in your case.
Thanks! I'll have a look, although the idea of having to code a rule for
each folder doesn't seem very efficient, especially since I have more
than 30 folders and changes in folder structure are conceivable in the
future. I guess it is a possibility, but I was hoping for something more
general.

Salud,

>
> Best,
>
> Alan
_______________________________________________
notmuch mailing list -- [hidden email]
To unsubscribe send an email to [hidden email]
inwit inwit
Reply | Threaded
Open this post in threaded view
|

Re: Folder+tags

In reply to this post by Jaume Devesa
On Fri Dec 25, 2020 at 9:04 AM CET, Jaume Devesa wrote:
> I sync my email with offlineimap and I do something similar, but using
> the `presync.sh` hook that offlineimap provides, via simple `xargs`:
>
> notmuch search --output=files --format=text0 \ folder:mailbox/INBOX
> -tag:inbox | xargs -0 --no-run-if-empty \ mv -t
> ~/mail/mailbox/Archive/$YEAR/new/
This is what I was considering so far, but the truth is that my
emacs lisp programming capabilities are still not that strong.

In any case, I guess I'd need to parameterize the command you propose,
thus making it applicable for any folder/tag. Something like:

notmuch search --output=files --format=text0 tag:$1 AND tag:inbox | \
xargs -0 --no-run-if-empty mv -t ~/mail/$1/new

Then I should plug this somehow into the notmuch-after-tag-hook, where
the recently applied tag and the message id should be available. Does
that sound reasonable to anyone in the list?

> I've never used emacs, so I ignore if you can do something similar by
> binding keys in emacs (but I guess you can).
It is possible for sure, but I'm afraid it'd take an actual lisp
programmer...

> Hope that helps,
It does. Thanks!!

Salud,
_______________________________________________
notmuch mailing list -- [hidden email]
To unsubscribe send an email to [hidden email]
inwit inwit
Reply | Threaded
Open this post in threaded view
|

Re: Folder+tags

In reply to this post by inwit
Ok, I've been thinking more about tag-folder synchronisation and reading
everything I could. However, I need some guidance.

I think that maybe the cleanest way to go is to have an after-tag-hook
which, if the recently added tag corresponds with a folder (as produced
by afew's FolderNameFilter, for example), then moves the file of the
message to its corresponding folder. Does that make sense?

Another alternative is to write a new 'tag-n-move' function which would
do both things, calling 'mv' through 'shell-command'. What do you think?

Salud,




On Wed Dec 23, 2020 at 12:53 PM CET, inwit wrote:

> Hi!
>
> This is my first message so I'll start by congratulating all the
> community around notmuch. Great piece of work you have here!
>
> I guess that my question must have been surely asked before, but I can't
> seem to find it in the lists' archive. My excuses if it is the case that
> my search abilities have failed. It has happened before.
>
> So, what I'm trying is to have a notmuch system up and running while
> preserving my folder structure fully functional in the IMAP server. I
> know that most of you will agree that folders are a thing from the past,
> but the fact is that, in the past, I've devoted quite a lot of time to
> sort my mails, and now I have a 3-level subfolder structure which is
> hard-wired in my brain, so up to now sometimes I'm still keen to
> searching messages in their expected folders. I guess it's a matter of
> time until I abandon this scheme and dive fully into tag based email,
> but for the time being I'm afraid of losing that folder structure for
> good.
>
> Anyway, I've been reading all around the web about this, and the closest
> I got is using the aerc client, where I can configure a Maildir worker
> and a notmuch worker, being able to use the former for reading and
> classifying mail into folders and the later for tag-based searching.
> This works, but at the same time, no matter how exciting the development
> of aerc is (and it is a beautiful little piece of code), it is still
> very far from emacs mail-mode.
>
> What I would like to, then, is to use notmuch-el to read and classify my
> mail. And the functionality I'm missing at the moment is a way to move
> an email from the inbox to its corresponding folder, hopefully updating
> its folder tags at the same time. That is: I would (mb)sync my mail from
> my company's IMAP server to my Maildir folder structure, then I'd go to
> the Inbox tag/folder, I'd read my mail and then, by hitting Shift+m, for
> example, I'd be able to move that precise email, both in files and tags,
> to its corresponding Maildir folder, so my next call to mbsync actually
> moves the message in the IMAP server folders as well. Does that make
> sense? Does anyone know how would I get to something like that?
>
> Again, sorry if this is redundant, and congratulations on the good work.
>
> Salud,
> _______________________________________________
> notmuch mailing list -- [hidden email]
> To unsubscribe send an email to [hidden email]
_______________________________________________
notmuch mailing list -- [hidden email]
To unsubscribe send an email to [hidden email]
Tomi Ollila-2 Tomi Ollila-2
Reply | Threaded
Open this post in threaded view
|

Re: Folder+tags

On Sun, Dec 27 2020, [hidden email] wrote:

> Ok, I've been thinking more about tag-folder synchronisation and reading
> everything I could. However, I need some guidance.
>
> I think that maybe the cleanest way to go is to have an after-tag-hook
> which, if the recently added tag corresponds with a folder (as produced
> by afew's FolderNameFilter, for example), then moves the file of the
> message to its corresponding folder. Does that make sense?
>
> Another alternative is to write a new 'tag-n-move' function which would
> do both things, calling 'mv' through 'shell-command'. What do you think?

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).

whatever way, tags are assigned to Message-Id:, so you'd need to find
the filename. 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).

>
> Salud,

Tomi
_______________________________________________
notmuch mailing list -- [hidden email]
To unsubscribe send an email to [hidden email]
inwit inwit
Reply | Threaded
Open this post in threaded view
|

Re: Folder+tags

On Sun Dec 27, 2020 at 2:12 PM CET, Tomi Ollila wrote:
> On Sun, Dec 27 2020, [hidden email] 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."

>
> whatever 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 -- [hidden email]
To unsubscribe send an email to [hidden email]
Tomi Ollila-2 Tomi Ollila-2
Reply | Threaded
Open this post in threaded view
|

Re: Folder+tags

On Sun, Dec 27 2020, [hidden email] wrote:

> On Sun Dec 27, 2020 at 2:12 PM CET, Tomi Ollila wrote:
>> On Sun, Dec 27 2020, [hidden email] 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 -- [hidden email]
> To unsubscribe send an email to [hidden email]
_______________________________________________
notmuch mailing list -- [hidden email]
To unsubscribe send an email to [hidden email]
inwit inwit
Reply | Threaded
Open this post in threaded view
|

Re: Folder+tags

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, [hidden email] wrote:
>
> > On Sun Dec 27, 2020 at 2:12 PM CET, Tomi Ollila wrote:
> >> On Sun, Dec 27 2020, [hidden email] 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 -- [hidden email]
> > To unsubscribe send an email to [hidden email]
_______________________________________________
notmuch mailing list -- [hidden email]
To unsubscribe send an email to [hidden email]
inwit inwit
Reply | Threaded
Open this post in threaded view
|

Re: Folder+tags

In reply to this post by Tomi Ollila-2
On Sun Dec 27, 2020 at 10:09 PM CET, Tomi Ollila wrote:

> On Sun, Dec 27 2020, [hidden email] wrote:
> > On Sun Dec 27, 2020 at 2:12 PM CET, Tomi Ollila wrote:
> >> On Sun, Dec 27 2020, [hidden email] 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
Coming back to this issue, I was wondering if someone could give me some
advice concerning the notmuch-after-tag-hook (I've tried to find answers
in the docs but I failed).

What I need to know is if, as with pre and post-new, I can write such
hooks in any language (bash would be my choice at the moment) or they
are limited to lisp? In the case I can use bash, how would I access to
'tag-changes' and 'query'?

Also, where should I place my hook once written?

Thanks for your patience.

Regards,

>
> (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 -- [hidden email]
> > To unsubscribe send an email to [hidden email]
_______________________________________________
notmuch mailing list -- [hidden email]
To unsubscribe send an email to [hidden email]
Tomi Ollila-2 Tomi Ollila-2
Reply | Threaded
Open this post in threaded view
|

Re: Folder+tags

On Sun, Jan 03 2021, [hidden email] wrote:

> On Sun Dec 27, 2020 at 10:09 PM CET, Tomi Ollila wrote:
>> On Sun, Dec 27 2020, [hidden email] wrote:
>> > On Sun Dec 27, 2020 at 2:12 PM CET, Tomi Ollila wrote:
>> >> On Sun, Dec 27 2020, [hidden email] 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
> Coming back to this issue, I was wondering if someone could give me some
> advice concerning the notmuch-after-tag-hook (I've tried to find answers
> in the docs but I failed).
>
> What I need to know is if, as with pre and post-new, I can write such
> hooks in any language (bash would be my choice at the moment) or they
> are limited to lisp? In the case I can use bash, how would I access to
> 'tag-changes' and 'query'?

The hooks are lisp code, the variables 'tag-changes' and 'query' are
available in the scope when those hooks are called (bound dynamically).

In your hook you can run shell command (if you wanted to run bash command
line)...

to see some samples how you'd do something like that run e.g.
git grep shell-command  in notmuch source tree and examine found content...

> Also, where should I place my hook once written?

in .emacs.d/notmuch-config.el

>
> Thanks for your patience.

sure, No prob.

Tomi
_______________________________________________
notmuch mailing list -- [hidden email]
To unsubscribe send an email to [hidden email]