unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* Using procmail to set tags
@ 2012-05-14 23:34 Robert Horn
  2012-05-15  7:20 ` Jani Nikula
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Robert Horn @ 2012-05-14 23:34 UTC (permalink / raw)
  To: notmuch

Is it practical (and has anyone documented) using a procmail setup to
set initial tags for messages using notmuch?

I've just started using emacs-notmuch to read mail, and I'm using a
system where I have procmail filters to bin mail by category into
folders.  I can continue this using folder:value for searching, but one
reason notmuch interests me is the potential to do more.

It's practical for me to assign potentially overlapping tags with a more
sophisticated procmail setup.  Notmuch tags enable having multiple tags
on one email.

I don't know enough about the procmail/notmuch process to see just how
to make this happen.  I'm hoping that someone has already done something
similar.

R Horn
rjhorn@alum.mit.edu

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Using procmail to set tags
  2012-05-14 23:34 Using procmail to set tags Robert Horn
@ 2012-05-15  7:20 ` Jani Nikula
  2012-05-15 10:14 ` bryan hunt
  2012-05-15 13:22 ` Austin Clements
  2 siblings, 0 replies; 7+ messages in thread
From: Jani Nikula @ 2012-05-15  7:20 UTC (permalink / raw)
  To: Robert Horn, notmuch

On Mon, 14 May 2012 19:34:55 -0400, Robert Horn <rjhorn@alum.mit.edu> wrote:
> Is it practical (and has anyone documented) using a procmail setup to
> set initial tags for messages using notmuch?

Can you express your initial tags in terms of notmuch searches? If you
can, I'd use the post-new hook of 'notmuch new' to do the initial
tagging. See http://notmuchmail.org/initial_tagging/ and 'man
notmuch-hooks' for some tips. OTOH, there's no real need for tags based
purely on notmuch searches in the emacs ui, because you can setup
notmuch-saved-searches. But YMMV.

If you can't express your tags in terms of notmuch searches (perhaps
because you want to tag based on List-Id: or some other header notmuch
does not index) you may need to look into notmuch-deliver. It's in the
contrib directory of the notmuch repository:
http://git.notmuchmail.org/git/notmuch/tree/HEAD:/contrib/notmuch-deliver

Tagging anything in notmuch requires that the message has been
delivered, and 'notmuch new' has been run, which might not be practical
within procmail. IIUC notmuch-deliver combines delivery, 'notmuch new',
and tagging. Disclaimer: I haven't used it myself.

> I've just started using emacs-notmuch to read mail, and I'm using a
> system where I have procmail filters to bin mail by category into
> folders.  I can continue this using folder:value for searching, but one
> reason notmuch interests me is the potential to do more.

You can, of course, combine folder searches with other searches, and
include them in notmuch-saved-searces.

HTH,
Jani.

> It's practical for me to assign potentially overlapping tags with a more
> sophisticated procmail setup.  Notmuch tags enable having multiple tags
> on one email.
> 
> I don't know enough about the procmail/notmuch process to see just how
> to make this happen.  I'm hoping that someone has already done something
> similar.
> 
> R Horn
> rjhorn@alum.mit.edu
> 
> _______________________________________________
> notmuch mailing list
> notmuch@notmuchmail.org
> http://notmuchmail.org/mailman/listinfo/notmuch

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Using procmail to set tags
  2012-05-14 23:34 Using procmail to set tags Robert Horn
  2012-05-15  7:20 ` Jani Nikula
@ 2012-05-15 10:14 ` bryan hunt
  2012-05-15 10:57   ` Jani Nikula
  2012-05-15 13:22 ` Austin Clements
  2 siblings, 1 reply; 7+ messages in thread
From: bryan hunt @ 2012-05-15 10:14 UTC (permalink / raw)
  To: Robert Horn; +Cc: notmuch

On Mon, 2012-05-14 at 19:34 -0400, Robert Horn wrote:
> Is it practical (and has anyone documented) using a procmail setup to
> set initial tags for messages using notmuch?
> 
> I've just started using emacs-notmuch to read mail, and I'm using a
> system where I have procmail filters to bin mail by category into
> folders.  I can continue this using folder:value for searching, but one
> reason notmuch interests me is the potential to do more.
> 
> It's practical for me to assign potentially overlapping tags with a more
> sophisticated procmail setup.  Notmuch tags enable having multiple tags
> on one email.
> 
> I don't know enough about the procmail/notmuch process to see just how
> to make this happen.  I'm hoping that someone has already done something
> similar.
> 
> R Horn
> rjhorn@alum.mit.edu

You could have procmail fire a python script to add or remove tags based
upon message content. 

Here's a python script I tried using to untag messages from the Lift
mailing list, there was a problem when I wrote it, but it's probably
been fixed by now.

#!/usr/bin/env python

from notmuch import *

'''
The idea of this script is that it will untag mailing list messages,
keeping them from my inbox unless they are directly related to me.

The problem is that the tag removal isn't being saved. 
I've created a bug report with the developer:

https://bitbucket.org/spaetz/cnotmuch/issue/1/removing-tags-doesnt-seem-to-be-saving

'''
db = Database('/home/bryan/.maildb',False, 'READ_WRITE')
q=db.create_query("'[lift]' -from:bryan tag:inbox")

for msg in q.search_messages():
    print msg.get_tags()
    msg.freeze()
    msg.remove_tag("inbox")
    print msg.get_tags()
    msg.remove_tag("unread")
    print msg.get_tags()
    msg.add_tag("lift")
    print msg.get_tags()
    msg.thaw()
exit()

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Using procmail to set tags
  2012-05-15 10:14 ` bryan hunt
@ 2012-05-15 10:57   ` Jani Nikula
  0 siblings, 0 replies; 7+ messages in thread
From: Jani Nikula @ 2012-05-15 10:57 UTC (permalink / raw)
  To: bryan hunt, Robert Horn; +Cc: notmuch

On Tue, 15 May 2012 11:14:50 +0100, bryan hunt <mafubryan@gmail.com> wrote:
> On Mon, 2012-05-14 at 19:34 -0400, Robert Horn wrote:
> > Is it practical (and has anyone documented) using a procmail setup to
> > set initial tags for messages using notmuch?
> > 
> > I've just started using emacs-notmuch to read mail, and I'm using a
> > system where I have procmail filters to bin mail by category into
> > folders.  I can continue this using folder:value for searching, but one
> > reason notmuch interests me is the potential to do more.
> > 
> > It's practical for me to assign potentially overlapping tags with a more
> > sophisticated procmail setup.  Notmuch tags enable having multiple tags
> > on one email.
> > 
> > I don't know enough about the procmail/notmuch process to see just how
> > to make this happen.  I'm hoping that someone has already done something
> > similar.
> > 
> > R Horn
> > rjhorn@alum.mit.edu
> 
> You could have procmail fire a python script to add or remove tags based
> upon message content. 

Note that you need to run 'notmuch new' after the message has been
delivered in order to modify the tags. Otherwise notmuch does not know
about the message.

> The problem is that the tag removal isn't being saved. 
> I've created a bug report with the developer:
> 
> https://bitbucket.org/spaetz/cnotmuch/issue/1/removing-tags-doesnt-seem-to-be-saving

That repository is obsolete; the notmuch python bindings have been
merged into upstream notmuch. If you still have problems, please report
them on this list.


J.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Using procmail to set tags
  2012-05-14 23:34 Using procmail to set tags Robert Horn
  2012-05-15  7:20 ` Jani Nikula
  2012-05-15 10:14 ` bryan hunt
@ 2012-05-15 13:22 ` Austin Clements
  2012-05-15 13:43   ` Tomi Ollila
  2 siblings, 1 reply; 7+ messages in thread
From: Austin Clements @ 2012-05-15 13:22 UTC (permalink / raw)
  To: Robert Horn; +Cc: notmuch

Quoth Robert Horn on May 14 at  7:34 pm:
> Is it practical (and has anyone documented) using a procmail setup to
> set initial tags for messages using notmuch?
> 
> I've just started using emacs-notmuch to read mail, and I'm using a
> system where I have procmail filters to bin mail by category into
> folders.  I can continue this using folder:value for searching, but one
> reason notmuch interests me is the potential to do more.
> 
> It's practical for me to assign potentially overlapping tags with a more
> sophisticated procmail setup.  Notmuch tags enable having multiple tags
> on one email.
> 
> I don't know enough about the procmail/notmuch process to see just how
> to make this happen.  I'm hoping that someone has already done something
> similar.

I second Jani's suggestion of using notmuch tag commands from
notmuch's post-new hook if possible (or switching to using searches
instead of tags where that makes sense).  However, if you really need
the flexibility of procmail, I can think of two solutions:

You can let procmail deliver to folders, like usual, and then use
  notmuch tag tag:inbox folder:X +/-tags
in notmuch's post-new hook to apply tags based on folders (you might
want to add the tag 'new' to your new.tags in ~/.notmuch-config and
filter on tag:new instead of tag:inbox).  If you need multiple tags on
a message, let procmail deliver it to multiple folders.

Alternatively, you can have procmail record the message ID and desired
tags of the message in a file and then apply those recorded tags in
your post-new hook.  This would achieve the tagging you want more
directly, without mixing in folders and multiple delivery.  The
difficulty would be getting a message ID you could later use in an id:
query.  Simply grabbing the value of the message-id header would work
most of the time, but there's a fair bit of logic for dealing with
strangely formed or completely malformed message-id headers
(see _parse_message_id).

As far as I know, nobody has tried my second suggestion.  Most people
just switch to using notmuch queries (either to tag or simply to
search).

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Using procmail to set tags
  2012-05-15 13:22 ` Austin Clements
@ 2012-05-15 13:43   ` Tomi Ollila
  2012-05-18 14:48     ` Robert Horn
  0 siblings, 1 reply; 7+ messages in thread
From: Tomi Ollila @ 2012-05-15 13:43 UTC (permalink / raw)
  To: Austin Clements, Robert Horn; +Cc: notmuch

On Tue, May 15 2012, Austin Clements <amdragon@MIT.EDU> wrote:

>
> Alternatively, you can have procmail record the message ID and desired
> tags of the message in a file and then apply those recorded tags in
> your post-new hook.  This would achieve the tagging you want more
> directly, without mixing in folders and multiple delivery.  The
> difficulty would be getting a message ID you could later use in an id:
> query.  Simply grabbing the value of the message-id header would work
> most of the time, but there's a fair bit of logic for dealing with
> strangely formed or completely malformed message-id headers
> (see _parse_message_id).

If procmail is delivering one mail at a time (without parallerism) and
notmuch new is executed after each email delivered one could try

  * put desired tags into environment (export NEW_TAGS='+foo +bar')
  * execute notmuch new
  * use the environment variables in post-new hook 
      (notmuch tags $NEW_TAGS -new tag:new)

The risk with this approach (when not recording message-id) is that there
ie not just one new mail (with 'new' tag) delivered...

Then I sidedtacked to... wouldn't something like
         notmuch new +<tags> -<tags> [path/to/filename]
be so cool... ;) (yes, so non-trivial...)

>
> As far as I know, nobody has tried my second suggestion.  Most people
> just switch to using notmuch queries (either to tag or simply to
> search).

Tomi

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Using procmail to set tags
  2012-05-15 13:43   ` Tomi Ollila
@ 2012-05-18 14:48     ` Robert Horn
  0 siblings, 0 replies; 7+ messages in thread
From: Robert Horn @ 2012-05-18 14:48 UTC (permalink / raw)
  To: Tomi Ollila, Austin Clements; +Cc: notmuch

Tomi Ollila <tomi.ollila@iki.fi> writes:

> On Tue, May 15 2012, Austin Clements <amdragon@MIT.EDU> wrote:
>   * execute notmuch new
>   * use the environment variables in post-new hook 
>       (notmuch tags $NEW_TAGS -new tag:new)
>
Thanks to all, that gave me enough hints to make progress.

It looks like adding a new tag in the config, "needsProcessing", and
then a post-new hook to a script that I write should do the job.
Instead of dealing an even more complex and arcane procmail setup, I
write a script that runs as the post-new hook.  I'm finding the "new"
flagging works correctly for simple mail drop from postfix, so the extra
flag will work.  I don't want to work off "new" because that's also
useful for mail reading and other uses.  The post-new hook can start by
finding the emails that are tagged "needsProcessing", parse and tag them
appropriately, and remove the needsProcessing tag.  It just needs to
start with a query and be written to work on all the messages found, so it
doesn't matter how many are new.

At the moment it looks like a simple python script using the notmuch
library binding may be easiest. If not, there are other tools to do the
job.

R Horn
rjhorn@alum.mit.edu

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2012-05-18 14:48 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-05-14 23:34 Using procmail to set tags Robert Horn
2012-05-15  7:20 ` Jani Nikula
2012-05-15 10:14 ` bryan hunt
2012-05-15 10:57   ` Jani Nikula
2012-05-15 13:22 ` Austin Clements
2012-05-15 13:43   ` Tomi Ollila
2012-05-18 14:48     ` Robert Horn

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