<?xml version="1.0" encoding="utf-8" ?>

<rss version="2.0" 
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:admin="http://webns.net/mvcb/"
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
   xmlns:wfw="http://wellformedweb.org/CommentAPI/"
   xmlns:content="http://purl.org/rss/1.0/modules/content/"
   xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule">
<channel>
    <title>freebsd.munk.me.uk - Mutt</title>
    <link>http://freebsd.munk.me.uk/</link>
    <description>FreeBSD System Administration</description>
    <dc:language>en</dc:language>
    <generator>Serendipity 1.5.2 - http://www.s9y.org/</generator>
    
    <image>
        <url>http://freebsd.munk.me.uk/templates/default/img/s9y_banner_small.png</url>
        <title>RSS: freebsd.munk.me.uk - Mutt - FreeBSD System Administration</title>
        <link>http://freebsd.munk.me.uk/</link>
        <width>100</width>
        <height>21</height>
    </image>

<item>
    <title>Mutt Auto Save Hooks</title>
    <link>http://freebsd.munk.me.uk/archives/184-Mutt-Auto-Save-Hooks.html</link>
            <category>Email</category>
            <category>Mutt</category>
    
    <comments>http://freebsd.munk.me.uk/archives/184-Mutt-Auto-Save-Hooks.html#comments</comments>
    <wfw:comment>http://freebsd.munk.me.uk/wfwcomment.php?cid=184</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://freebsd.munk.me.uk/rss.php?version=2.0&amp;type=comments&amp;cid=184</wfw:commentRss>
    

    <author>nospam@example.com (munk)</author>
    <content:encoded>
    &lt;strong&gt;UPDATE:&lt;/strong&gt;&lt;br /&gt;
I&#039;ve updated the perl script to allow user input of the save hook.&lt;br /&gt;
Also importantly I forgot to mention in the article originally that you must add the string &#039;#SAVE AND FCC HOOKS&#039; at the place in your ~/.muttrc file where you want the save hooks to be saved!&lt;br /&gt;
&lt;br /&gt;
This is a recipe for automatically creating save-hooks in the Mutt mail client.  The recipe allows you to bind the function to a key - I use &#039;esc H&#039; - so when you receive mail say from &#039;munk @ munk.me.uk&#039;, you hit &#039;esc H&#039; and mutt will create a save-hook that saves any mail from that address to &#039;munk.me.uk&#039;.  That way when you hit &#039;s&#039; to save the mail to a folder, mutt will automatically prompt you to save the mail to &#039;munk.me.uk&#039;.&lt;br /&gt;
&lt;br /&gt;
The recipe involves editing the ~/.muttrc file and the creation of a perl script to do the work.  It also requires formail (part of procmail iirc).  The script is based on an original script by &lt;a href=&quot;http://marc.10east.com/?l=mutt-users&amp;m=104422326212956&amp;w=2&quot;  title=&quot;Script for adding save hooks on Mutt mailing list&quot;&gt;Eric Smith on the mutt mailing list&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
First add this to your ~/.muttrc file:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;bb-code-title&quot;&gt;CODE:&lt;/div&gt;&lt;div class=&quot;bb-code&quot;&gt;#&amp;#160;Notes&amp;#58;&lt;br /&gt;
#&amp;#160;&lt;br /&gt;
#&amp;#160;Modify&amp;#160;the&amp;#160;paths&amp;#160;to&amp;#160;the&amp;#160;&#039;hookgen.pl&#039;&amp;#160;script&amp;#160;as&amp;#160;needed&amp;#160;&lt;br /&gt;
#&amp;#160;-&amp;#160;it&amp;#160;should&amp;#160;be&amp;#160;the&amp;#160;location&amp;#160;you&amp;#160;decide&amp;#160;to&amp;#160;save&amp;#160;the&amp;#160;perl&amp;#160;script&amp;#160;as.&lt;br /&gt;
#&lt;br /&gt;
#&amp;#160;Modify&amp;#160;the&amp;#160;temp&amp;#160;file&amp;#160;path&amp;#160;if&amp;#160;you&amp;#160;want.&amp;#160;&amp;#160;&lt;br /&gt;
#&amp;#160;/tmp&amp;#160;should&amp;#160;be&amp;#160;fine&amp;#160;though&amp;#160;unless&amp;#160;you&amp;#160;have&amp;#160;a&amp;#160;busy&amp;#160;server&amp;#160;and&amp;#160;don&#039;t&amp;#160;want&amp;#160;to&amp;#160;&lt;br /&gt;
#&amp;#160;risk&amp;#160;others&amp;#160;seeing&amp;#160;who&amp;#160;you&amp;#160;receive&amp;#160;mail&amp;#160;from.&lt;br /&gt;
#&lt;br /&gt;
#&amp;#160;The&amp;#160;file&amp;#160;after&amp;#160;the&amp;#160;&#039;&amp;#58;source&#039;&amp;#160;command&amp;#160;should&amp;#160;be&amp;#160;the&amp;#160;file&amp;#160;that&amp;#160;you&amp;#160;want&amp;#160;to&amp;#160;contain&amp;#160;the&amp;#160;save&amp;#160;hooks&amp;#160;in.&lt;br /&gt;
#&amp;#160;In&amp;#160;my&amp;#160;setup&amp;#160;I&amp;#160;have&amp;#160;all&amp;#160;my&amp;#160;hooks&amp;#160;in&amp;#160;a&amp;#160;separate&amp;#160;file,&amp;#160;~/.mutt/mutt.hooks,&amp;#160;which&amp;#160;is&amp;#160;sourced&amp;#160;from&amp;#160;my&amp;#160;main&lt;br /&gt;
#&amp;#160;~/.muttrc&amp;#160;file.&lt;br /&gt;
#&lt;br /&gt;
#&amp;#160;There&amp;#160;are&amp;#160;3&amp;#160;bindings,&amp;#160;one&amp;#160;for&amp;#160;each&amp;#160;mutt&amp;#160;&#039;view&#039;&amp;#58;&lt;br /&gt;
macro&amp;#160;index&amp;#160;\eH&amp;#160;&quot;&amp;#60;pipe-message&amp;#62;formail&amp;#160;-X&amp;#160;\&lt;br /&gt;
From&amp;#58;&amp;#62;/tmp/hookgen.pl_cache\n&amp;#60;shell-escape&amp;#62;/home/munk/bin/perl/mutt/hookgen.pl\n&amp;#58;source&amp;#160;\&lt;br /&gt;
~/.mutt/mutt.hooks\n&quot;&amp;#160;&quot;Edit&amp;#160;mutt&amp;#160;hooks&amp;#160;file&amp;#160;and&amp;#160;reload&amp;#160;it&quot;&lt;br /&gt;
macro&amp;#160;pager&amp;#160;\eH&amp;#160;\&lt;br /&gt;
&quot;&amp;#60;pipe-message&amp;#62;formail&amp;#160;-X&amp;#160;\&lt;br /&gt;
From&amp;#58;&amp;#62;/tmp/hookgen.pl_cache\n&amp;#60;shell-escape&amp;#62;/home/munk/bin/perl/mutt/hookgen.pl\n&amp;#58;source&amp;#160;\&lt;br /&gt;
~/.mutt/mutt.hooks\n&quot;&amp;#160;&quot;Edit&amp;#160;mutt&amp;#160;hooks&amp;#160;file&amp;#160;and&amp;#160;reload&amp;#160;it&quot;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
This presumes you&#039;re using the key sequence &#039;ESC H&#039; - the escape key followed by a capital H - to bind the function.  Feel free to use another keystroke.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
At the point in your ~/.muttrc file that you want the save-hook saving, add the following:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;bb-code-title&quot;&gt;CODE:&lt;/div&gt;&lt;div class=&quot;bb-code&quot;&gt;&#039;#SAVE&amp;#160;AND&amp;#160;FCC&amp;#160;HOOKS&#039;&amp;#160;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
Now create and save the following perl script for the above macro binding to use.  Please note I didn&#039;t originally write this script, I based it on a script by Eric Smith in the URL below.  You might want to read the original mail because he uses a slightly different approach.  You can debug the script on the commandline by uncommenting the line starting &#039;#$debug&#039;.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s the script:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;bb-code-title&quot;&gt;CODE:&lt;/div&gt;&lt;div class=&quot;bb-code&quot;&gt;#!/usr/bin/perl&amp;#160;-w&lt;br /&gt;
#&amp;#160;Original&amp;#160;idea&amp;#160;with&amp;#160;thanks&amp;#160;to&amp;#160;Eric&amp;#160;Smith.&lt;br /&gt;
#&amp;#160;see&amp;#160;here&amp;#58;&amp;#160;http&amp;#58;//marc.10east.com/?l=mutt-users&amp;amp;m=104422326212956&amp;amp;w=2&lt;br /&gt;
&lt;br /&gt;
#&amp;#160;Overview&amp;#58;&lt;br /&gt;
#&amp;#160;This&amp;#160;script&amp;#160;allows&amp;#160;you&amp;#160;to&amp;#160;create&amp;#160;save&amp;#160;hooks&amp;#160;in&amp;#160;mutt.&amp;#160;&amp;#160;Add&amp;#160;the&amp;#160;following&amp;#160;to&lt;br /&gt;
#&amp;#160;your&amp;#160;~/.muttrc&amp;#160;file&amp;#58;&lt;br /&gt;
#&lt;br /&gt;
#&amp;#160;macro&amp;#160;index&amp;#160;\eH&amp;#160;&quot;&amp;#60;pipe-message&amp;#62;formail&amp;#160;-X&amp;#160;From&amp;#58;&amp;#62;/tmp/hookgen.pl_cache\n&amp;#160;\&lt;br /&gt;
#&amp;#160;&amp;#60;shell-escape&amp;#62;/home/munk/bin/perl/mutt/hookgen.pl\n&amp;#58;source&amp;#160;~/.mutt/mutt.hooks\n&quot;&amp;#160;\&lt;br /&gt;
#&amp;#160;&quot;Edit&amp;#160;mutt&amp;#160;hooks&amp;#160;file&amp;#160;and&amp;#160;reload&amp;#160;it&quot;&lt;br /&gt;
#&amp;#160;macro&amp;#160;pager&amp;#160;\eH&amp;#160;#&amp;#160;&quot;&amp;#60;pipe-message&amp;#62;formail&amp;#160;-X&amp;#160;#&amp;#160;From&amp;#58;&amp;#62;/tmp/hookgen.pl_cache\n&amp;#160;\&amp;#160;&lt;br /&gt;
#&amp;#160;&amp;#60;shell-escape&amp;#62;/home/munk/bin/perl/mutt/hookgen.pl\n&amp;#58;source&amp;#160;~/.mutt/mutt.hooks\n&quot;&amp;#160;\&lt;br /&gt;
#&amp;#160;&quot;Edit&amp;#160;mutt&amp;#160;hooks&amp;#160;file&amp;#160;and&amp;#160;reload&amp;#160;it&quot;&lt;br /&gt;
#&lt;br /&gt;
#&amp;#160;substituting&amp;#58;&lt;br /&gt;
#&amp;#160;/tmp/hookgen.pl_cache&amp;#160;for&amp;#160;the&amp;#160;location&amp;#160;you&amp;#160;want&amp;#160;to&amp;#160;store&amp;#160;the&amp;#160;&#039;From&#039;&amp;#160;header&lt;br /&gt;
#&amp;#160;temporarily&lt;br /&gt;
#&amp;#160;&lt;br /&gt;
#&amp;#160;/home/munk/bin/perl/hookgen.pl&amp;#160;for&amp;#160;the&amp;#160;location&amp;#160;of&amp;#160;this&amp;#160;script.&lt;br /&gt;
#&lt;br /&gt;
#&amp;#160;~/.mutt/mutt.hooks&amp;#160;for&amp;#160;the&amp;#160;file&amp;#160;you&amp;#160;want&amp;#160;to&amp;#160;save&amp;#160;the&amp;#160;hooks&amp;#160;into,&amp;#160;normally&amp;#160;this&amp;#160;will&amp;#160;be&amp;#160;your&amp;#160;~/.muttrc&lt;br /&gt;
#&amp;#160;&lt;br /&gt;
#&amp;#160;IMPORTANTLY&amp;#58;&amp;#160;add&amp;#160;the&amp;#160;following&amp;#160;in&amp;#160;the&amp;#160;file&amp;#160;you&amp;#160;want&amp;#160;to&amp;#160;save&amp;#160;the&amp;#160;hooks&amp;#160;to&amp;#58;&lt;br /&gt;
#&amp;#160;&#039;#SAVE&amp;#160;AND&amp;#160;FCC&amp;#160;HOOKS&#039;&amp;#160;&amp;#40;everything&amp;#160;inside&amp;#160;the&amp;#160;quotes&amp;#41;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
use&amp;#160;strict;&lt;br /&gt;
my&amp;#160;$cmd&amp;#160;=&amp;#160;undef;&lt;br /&gt;
my&amp;#160;$regexp&amp;#160;=&amp;#160;undef;&lt;br /&gt;
my&amp;#160;$folder&amp;#160;=&amp;#160;undef;&lt;br /&gt;
my&amp;#160;$alt_hook&amp;#160;=&amp;#160;undef;&lt;br /&gt;
my&amp;#160;$domain&amp;#160;=&amp;#160;undef;&lt;br /&gt;
my&amp;#160;$save_hook&amp;#160;=&amp;#160;undef;&lt;br /&gt;
my&amp;#160;$debug&amp;#160;=&amp;#160;undef;&lt;br /&gt;
&lt;br /&gt;
#&amp;#160;set&amp;#160;this&amp;#160;to&amp;#160;the&amp;#160;name&amp;#160;of&amp;#160;the&amp;#160;temp&amp;#160;file&amp;#160;used&amp;#160;in&amp;#160;the&amp;#160;muttrc&amp;#160;bind&amp;#160;directive&amp;#160;for&lt;br /&gt;
#&amp;#160;this&amp;#160;macro&amp;#58;&lt;br /&gt;
my&amp;#160;$tmp_file&amp;#160;=&amp;#160;&#039;/tmp/hookgen.pl_cache&#039;;&lt;br /&gt;
&lt;br /&gt;
#&amp;#160;set&amp;#160;this&amp;#160;to&amp;#160;the&amp;#160;file&amp;#160;you&amp;#160;want&amp;#160;to&amp;#160;save&amp;#160;the&amp;#160;hooks&amp;#160;to&amp;#160;-&amp;#160;make&amp;#160;sure&amp;#160;the&amp;#160;hook&amp;#160;file&lt;br /&gt;
#&amp;#160;has&amp;#160;the&amp;#160;text&amp;#160;&#039;#SAVE&amp;#160;AND&amp;#160;FCC&amp;#160;HOOKS&#039;&amp;#160;in&amp;#160;it!&amp;#58;&lt;br /&gt;
my&amp;#160;$hook_file&amp;#160;=&amp;#160;&#039;/home/munk/.mutt/mutt.hooks&#039;;&lt;br /&gt;
&lt;br /&gt;
#&amp;#160;To&amp;#160;debug&amp;#160;the&amp;#160;script,&amp;#160;uncomment&amp;#160;the&amp;#160;following&amp;#160;line&amp;#58;&lt;br /&gt;
#&amp;#160;$debug&amp;#160;=&amp;#160;&#039;From&amp;#58;&amp;#160;&quot;John&amp;#160;Smith&quot;&amp;#160;&amp;#60;john.smith@example.com&amp;#62;&#039;;&lt;br /&gt;
&lt;br /&gt;
`echo&amp;#160;&#039;$debug&#039;&amp;#160;&amp;#62;&amp;#160;$tmp_file`&amp;#160;if&amp;#160;$debug;&lt;br /&gt;
&lt;br /&gt;
open&amp;#160;CACHE,&amp;#160;&quot;&amp;#60;/tmp/hookgen.pl_cache&quot;&amp;#160;or&amp;#160;die&amp;#160;&quot;Cannot&amp;#160;open&amp;#160;/tmp/hookgen.pl_cache&amp;#160;$!&quot;;&lt;br /&gt;
while&amp;#160;&amp;#40;&amp;#60;CACHE&amp;#62;&amp;#41;&amp;#160;{&lt;br /&gt;
	if&amp;#40;/^from&amp;#58;/i&amp;#41;{&lt;br /&gt;
		chomp;&lt;br /&gt;
		/.&amp;#42;\@&amp;#40;&amp;#91;^&amp;#62;&amp;#93;&amp;#42;&amp;#41;/i;&lt;br /&gt;
		$domain&amp;#160;=&amp;#160;$1;&lt;br /&gt;
&amp;#160;&amp;#160;}&lt;br /&gt;
}&lt;br /&gt;
$regexp&amp;#160;=&amp;#160;$folder&amp;#160;=&amp;#160;$domain;&lt;br /&gt;
close&amp;#160;CACHE;&lt;br /&gt;
&lt;br /&gt;
$save_hook=&quot;save-hook&amp;#160;&#039;~f&amp;#160;$regexp&#039;&amp;#160;+/$folder&quot;;&lt;br /&gt;
&lt;br /&gt;
while&amp;#40;&amp;#41;{&lt;br /&gt;
	print&amp;#160;&quot;Save&amp;#160;hook&amp;#160;to&amp;#160;be&amp;#160;added&amp;#58;\n\n$save_hook\n\n&quot;;&lt;br /&gt;
	print&amp;#160;&quot;Hit&amp;#160;enter&amp;#160;to&amp;#160;save,&amp;#160;enter&amp;#160;an&amp;#160;alternative&amp;#160;save-hook,&amp;#160;or&amp;#160;hit&amp;#160;ctrl-c&amp;#160;to&amp;#160;exit&amp;#58;\n&quot;;&lt;br /&gt;
&lt;br /&gt;
	chomp&amp;#40;$alt_hook&amp;#160;=&amp;#160;&amp;#60;STDIN&amp;#62;&amp;#41;;&lt;br /&gt;
&lt;br /&gt;
	if&amp;#160;&amp;#40;$alt_hook&amp;#160;eq&amp;#160;&quot;&quot;&amp;#41;{&lt;br /&gt;
		last;&lt;br /&gt;
	}&amp;#160;else&amp;#160;{&lt;br /&gt;
		$save_hook&amp;#160;=&amp;#160;$alt_hook&amp;#160;;&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
$cmd&amp;#160;=&amp;#160;&#039;perl&amp;#160;-pi&amp;#160;-e&amp;#160;&quot;s@&amp;#40;?&amp;#60;=#SAVE&amp;#160;AND&amp;#160;FCC&amp;#160;HOOKS&amp;#41;@\n&#039;&amp;#160;.&amp;#160;$save_hook&amp;#160;.&amp;#160;&#039;@&quot;&amp;#160;&#039;&amp;#160;.&amp;#160;$hook_file;&lt;br /&gt;
&lt;br /&gt;
if&amp;#40;$debug&amp;#41;{&lt;br /&gt;
	print&amp;#160;&quot;Running&amp;#160;in&amp;#160;debug&amp;#160;mode&amp;#58;\n\n&quot;;&lt;br /&gt;
	print&amp;#160;&quot;Would&amp;#160;have&amp;#160;saved&amp;#160;this&amp;#160;hook&amp;#58;\n\n$save_hook\n\n&quot;;&lt;br /&gt;
	print&amp;#160;&quot;to&amp;#160;this&amp;#160;hook&amp;#160;file&amp;#58;\n\n$hook_file\n&quot;;&lt;br /&gt;
	print&amp;#160;&quot;Using&amp;#160;this&amp;#160;command&amp;#58;\n\n$cmd\n&quot;;&lt;br /&gt;
}&amp;#160;else&amp;#160;{&lt;br /&gt;
	system&amp;#160;qq|$cmd|;&lt;br /&gt;
}&lt;/div&gt; 
    </content:encoded>

    <pubDate>Wed, 13 Sep 2006 17:51:02 +0000</pubDate>
    <guid isPermaLink="false">http://freebsd.munk.me.uk/archives/184-guid.html</guid>
    <creativeCommons:license>http://creativecommons.org/licenses/by/2.5/</creativeCommons:license>
</item>

</channel>
</rss>