<<< Date Index >>>     <<< Thread Index >>>

Re: Dynamic macro



Hi Ben!

On Mon, 23 Jul 2007, Ben Gladwell wrote:

> dumps them all into the same mbox, which is the way I like it. I want to
> create a macro that creates a limit based on the host of the sender of
> the current email in the index - in my case its the name of the server
> that emailed me. This way, I could quickly see all the emails from each
> server.
> 
> So, if the current email iss from root@xxxxxxxxxxxxxxxxxxxx i'd like a
> limit like:
> ~L server

I created once a quick and dirty mapping, that would limit the view to
all the mails from the author of the mail which was selected.  Since I
tend to remember mails by the name of the author which sent it.

,----[ $ grep -m1 -B3 .mutt/macros.conf ]-
| macro index A "<enter-command>unset wait_key<enter><pipe-message>\
| ~/bin/mutt_address.sh ~/temp/mutt_source.txt<enter><enter-command>\
| set wait_key<enter><enter-command>source ~/temp/mutt_source.txt<enter>" 
"limit message view by selected author"
`----

And mutt_address.sh looks like this:

#!/bin/sh

FORM=`which formail`
ARGS="`cat`"

# The sed statement will cut out only the relevant part from
# the e-mail address between <> (e.g. for "Foo" <foo.bar@xxxxxxxxxx> it 
# will only print foo\.bar@foobar\.xyz) and will also translate
# allowed characters like "." or "+" by escaping them
OUTPUT=`echo "${ARGS}"|"${FORM}" -tzx "From:" | sed 
's/.*<//;s/>//;s/\./\\\\\\\\&/g;s/+/\\\\\\\\\\\\\\\\&/g'`  
if [ -n "$1" ]; then
    TEMP="$1"
    exec >"${TEMP}" || { echo "Could not output to $1, exiting..." &&  exit 1; }

    cat <<EOF
    push "<limit>~f \"${OUTPUT}\"<enter>"'
EOF
else
    echo "You must supply a filename in which to store the result!" && exit 2
fi

This is probably pretty ugly, especially the escaping was hard to
figure out. But so far, I have not had any problems. 


regards,
Christian
-- 
hundred-and-one symptoms of being an internet addict:
175. You send yourself e-mail before you go to bed to remind you
     what to do when you wake up.