On Fri, Feb 02, 2001 at 03:56:45PM +0100 or so it is rumoured hereabouts, 
Marco Fioretti thought:
> 
> > >
> > > What would REALLY do the trick is some "shell excape" which just makes
> > > mutt
> > > do the following:
> > >
> > >       echo subject_and_From_header >> some_file
> > >
> > > I did read the whole manual some time ago, but I can't remember any
> > > "shell-excape", i.e. something that make mutt execute shell commands
> > > with dynamic arguments. Is something like that available?
> > No time now, will think...
> 
> Idea:
> 
> we may achieve the desired effect ( i.e. passing information to some 
> external program) if it were possible to define (within mutt or from the
> prompt) a mailbox which is actually a pipe, right? As in
> 
> set MAIL_TO_BE_DISCARDED = "| my_program.pl"
> 
> Maybe named pipes would do it, what do you think?
> 
>       Marco
I'm not familiar enough with the mutt "set" capabilities to comment on
that.  How do you get the message into the pipe?  "save" perhaps?   

Did some thinking though...

What I had been thinking about was to do something with 
"set editor" and use a send-hook and macro to _forward_ the unwanted
message to the filtering script.  Something like:

macro index <esc>D <forward-message>bitbucket@localhost<enter>
with
send-hook bitbucket set editor="~/bin/maildump"

Now, using that, the ~/bin/maildump looks like

#!/bin/bash
######## maildump ###########
# get "From" and "Subject" lines to use for filtering from pop server
# We're masquerading as an editor here for mutt so we get the message
# filename on $1.  That's kinda handy since we don't need to worry about
# cat or anything.

grep -A10 ----- Forwarded message $1 > /tmp/maildump$$.tmp 2>/dev/null
grep From /tmp/maildump$$.tmp > /tmp/dump$$.tmp
grep Subject /tmp/maildump$$.tmp >> /tmp/dump$$.tmp

# command to incorporate /tmp/dump$$.tmp into the pop3 filter script
# You already know how to do this don't you?

rm -f /tmp/maildump$$.tmp /tmp/dump$$.tmp
exit 0
######## end maildump ##########

Once this returns, mutt sees that the temporary file it used for the
message hasn't changed and just "aborts unmodified message" which is just
the desired effect.  
Since forwarding includes the original incoming "From" and "Subject"
headers we'll pick them up just after the "Forwarded message" line.  My
problem here has been not knowing *quite* how to set the send-hook
correctly.  With the example quoted above, the editor variable gets left
as "~/bin/maildump" for ordinary mails but if I include a default
send-hook for "set editor", it gets used even for "bitbucket" mails which
should trigger the "bitbucket" send-hook.  I used 

send-hook . set editor="vim +\'set tw=74\' +\'/^$\'"
send-hook bitbucket set editor="~/bin/maildump"

but the default hook gets used for all mails.  I thought I would solve it 
by using the following:

send-hook !bitbucket@localhost set editor="vim +\'set tw=74\' +\'/^$\'"
send-hook bitbucket@localhost set editor="~/bin/maildump"

but that wouldn't behave correctly with the "set tw=74" for the default 
editor command so I used:

send-hook !bitbucket@localhost source ~/.muttrc

which contains (among other stuff):

set editor="vim +'set tw=74' +'/^$'" 

as the default editor.  A bit crude and kludgey but it works.

#######################
So, in summary, ~/.muttrc contains the following:

set editor="vim +'set tw=74' +'/^$'"
send-hook !bitbucket@localhost source ~/.muttrc
send-hook bitbucket@localhost set editor="~/bin/maildump"
macro index <esc>D <forward-message>bitbucket@localhost<enter>
macro pager <esc>D <forward-message>bitbucket@localhost<enter>

using <esc>D on a message will "forward" the message to ~/bin/maildump for
processing.  This will extract the "From" and "Subject" lines and push
them to a .conf file for the pop3 filter script and will then return
unmodified to mutt which will just discard the "forwarded" message.

The exact method of extraction of the necessary info is left as an
exercise for the reader (Marco :-) who will then post the full set of
scripts (won't you?) 'cos I don't know any perl to go hacking the pop
filter.

<feature request for perl pop filter>

A nice method to check for message size and get headers only but leave the
message on the server for later review.  OH!  Could you get the "body" and
leave the attachments on the server?  Probably not.

</feature request for perl pop filter>


Howsat?

Conor
-- 
Conor Daly <[EMAIL PROTECTED]>

Domestic Sysadmin :-)
---------------------
faenor.cod.ie
  9:21pm  up 102 days,  3:50,  0 users,  load average: 0.08, 0.02, 0.01

Hobbiton.cod.ie
  9:19pm  up 7 days, 11:08,  1 user,  load average: 0.01, 0.00, 0.00

Reply via email to