|
This page
Debian Package
|
If you've ever used gmail you'll be familiar with the idea of tagging applied to email. This is something which isn't possible by default with the mutt mail-client. There are some solutions which will let you tag mails to a limited extent. The most popular seems to be "labeling mail with mutt". This solution uses the X-Label header in each message to store the tag(s). This is very clever because it means that the tag is contained inside the message, not outside it (where there is a risk of tags becoming out of sync with the mail contents). The downside to this solution, and all other similar ones, is that it only works on a per-folder basis. That means you may tag messages in your "steve" folder, but then if you try to search for messages by tag you only find results in that folder - not any that might also be present elsewhere. To solve that problem I've written a quick indexer script which makes tags work globally by creating a virtual folder for each tag present within all mailboxes, this folder is populated by hardlinks to each individual message. To get started you'll need your own way of adding the X-Label header to your messages - such as the procmail recipe described below, or the editlabel script contained in the mutt labels page linked to above. Once you have some tags present in your mailboxes you may download the actual tag-indexer script: In order to make the tag-folders appear in a reasonable time I'd suggest adding it to your crontab, once you've verified it works as expected. (The script uses a message cache so it is not terribly slow, providing you've run it once before.) Basic usage would be as simple as this: ~$ rm -rf ~/Maildir/tags-* ~$ index-tags-maildir --maildir=~/Maildir You may also exclude certain folders from being examined: ~$ rm -rf ~/Maildir/tags-* ~$ index-tags-maildir --maildir=~/Maildir \ --exclude=spam,automated,junk,sent-mail The script will read every message beneath ~/Maildir, and look for X-Label headers. Each header will be assumed to contain a comma-separated list of tags. For each tag found the script will create the ~/Maildir/tags-$tagname folder and create a symlink to the real message inside it. As these virtual tag-folders are never deleted I've added the deletion step prior to the rebuild. If you have existing folders named "tags-" then I suggest you don't run that! There are a couple of problems with this indexing solution, each caused by the way that mutt behaves; many operations working on messages do not in fact work on messages, instead they work on copies of them. To make this problem more clear assume you have a mail somewhere tagged "steve". If you edit the orginal message via mutt's <edit> function you end up creating a new file. This means the hardlink is broken until the next time the indexer runs. Worst still if you edit the copy of the message in the virtual folder your change will be lost - because the hardlink will be replaced (and the next run of the indexer will remove it; replacing it with a link to the original unmodified message.) If you don't care about this problem you may safely skip this section. However I want to be able to remove a tag either at the original message, or within the virtual folder, so I've come up with a solution to the problem for that case. My solution involves an "edit-inplace" primitive which, unlike the "edit" primitive, invokes an editor with the original message not with a copy of it.
The mutt configuration looks like this: # # y == edit label. # macro index y '<edit-inplace><refresh>' macro pager y '<edit-inplace><refresh>' Your shell must have previously defined the command that the edit-inplace primitive will use, you may do that by running: export EDITINPLACE=~/bin/editlabel (The edit-inplace primitive simply executes the program specified in $EDITINPLACE, passing the name of the Maildir message to it as a single argument.) Update: There is a Debian Etch package of mutt with this patch applied which you are welcome to use. The following entries come from my ~/.muttrc file and ensure that tags, where present, are visible in the message indexes:
#
# Always show the X-Label header if present, and make it visible.
#
unignore X-Label:
color header brightwhite default '^X-Label:'
#
# Show the label in the index
#
set index_format="%4C %Z %{%b %d} %-15.15L %?M?(#%03M)&(%4l)? %?y?{%.20Y} ?%s"
I generally add tags to messages as I read them, if at all. But there are some cases where I want messages to be delivered pre-tagged. Here is a recipe which applies the tag "root" to several incoming message:
FORMAIL=/usr/bin/formail
:0
*(Subject:).*(LogWatch for )
{
:0 fhw
| $FORMAIL -I "X-label: root"
:0:
.Automated.LogWatch/
}
:0
*(Subject:).*(monit alert)
{
:0 fhw
| $FORMAIL -I "X-label: root"
:0:
.Automated.monit/
}
#
# Root messages.
#
:0
* !^(To:|From:).*(root@example.org)
* !^(To:|From:).*(root@example.com)
* !^(To:|From:).*(root@example.net)
{ }
:0 E
{
:0 fhw
| $FORMAIL -I "X-label: root"
:0:
.Automated.root/
}
|
|
[ Sitemap | Contact Me ]
|