[Evolution] Re: mail forwarding filter

Not Zed notzed@ximian.com
Tue, 01 Mar 2005 10:30:41 +0800


--=-4QWFtPHpAJzQTxu6XKXW
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

On Mon, 2005-02-28 at 08:51 -0500, Gangalino wrote:

> On Mon, 2005-28-02 at 14:24 +0800, Not Zed wrote:
> > 
> > Well, strictly speaking, it is not entirely incorrect.
> > 
> > You can still use filters to do that, by using the filers to run a
> > script which does the forwarding, e.g. via the 'mail' command.
> > 
> > On Sun, 2005-02-27 at 23:48 -0500, Gangalino wrote: 
> > > You think I would lie about something like this?
> > > Check your help- 3.6  Create Rules to Automatically Or Organize Mail:
> > > "For example, your filters could put copies of one message into multiple
> > > folders, or keep one copy and send one to another person."
> > > 
> > > Which would be a perfectly normal use of a filter.
> > > YOUR bug link, however, is untrue. :)
> > 
> Can you provide me with an example of such a script. Unfortunately, I'm
> on this GARBARGE BELL/SYMPATICO ISp that filters out any outgoing mail,
> but I am on a linux machine w/ Postfix/Sendmail, and the address I want
> to forward to mostly is an alias local to my machine.



At the simplest form, for sendmail or postfix, you add an action:

"Pipe to Program"
and use
/usr/sbin/sendmail -f yourreply@address  the.target@address

This will effectively "redirect" or "bounce" the message to
"the.target@address", and send any errors to "yourreply@address".

Then you could add other actions to e.g. mark the mail as read or
whatever.

If you want to form an attachment of the message it gets a bit trickier,
and you need a script.  I've attached an example script - it is a little
more sophisticated than the trivial-case, as it extracts (multiline)
subject to form a destination subject.  It could be changed to take the
target address from the command line or calculate it from the message.

--- begin script ---
#!/bin/sh

# forwards an rfc822 message from stdin to "to" coming from "from" as a
mime attachment

from="not zed <notzed@novell.com>"
errors="notzed@novell.com"
to="mike <notzed@ximian.com>"

msg=~/.forward.$$
date=`date --rfc-2822`

# save message
cat - >$msg

# generate forwarded subject
subject=`cat $msg | sed -e "/^$/ q"  -e "/^Subject:/ s/Subject:/Subject:
Fw:/" -e "/^Subject:/,/^[\t ]/ p" -e "d" -e "/^$/ q"`

# build/send message
( echo "From: $from"
  echo "To: $to"
  echo "$subject"
  echo "Date: $date"
  echo "Mime-Version: 1.0"
  echo "Content-Type: message/rfc822"
  echo ""
  cat $msg ) | /usr/sbin/sendmail -f $errors $to

rm $msg







--=-4QWFtPHpAJzQTxu6XKXW
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: 7bit

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
  <META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
  <META NAME="GENERATOR" CONTENT="GtkHTML/3.5.5">
</HEAD>
<BODY>
On Mon, 2005-02-28 at 08:51 -0500, Gangalino wrote:
<BLOCKQUOTE TYPE=CITE>
<PRE>
<FONT COLOR="#000000">On Mon, 2005-28-02 at 14:24 +0800, Not Zed wrote:</FONT>
<FONT COLOR="#000000">&gt; </FONT>
<FONT COLOR="#000000">&gt; Well, strictly speaking, it is not entirely incorrect.</FONT>
<FONT COLOR="#000000">&gt; </FONT>
<FONT COLOR="#000000">&gt; You can still use filters to do that, by using the filers to run a</FONT>
<FONT COLOR="#000000">&gt; script which does the forwarding, e.g. via the 'mail' command.</FONT>
<FONT COLOR="#000000">&gt; </FONT>
<FONT COLOR="#000000">&gt; On Sun, 2005-02-27 at 23:48 -0500, Gangalino wrote: </FONT>
<FONT COLOR="#000000">&gt; &gt; You think I would lie about something like this?</FONT>
<FONT COLOR="#000000">&gt; &gt; Check your help- 3.6  Create Rules to Automatically Or Organize Mail:</FONT>
<FONT COLOR="#000000">&gt; &gt; &quot;For example, your filters could put copies of one message into multiple</FONT>
<FONT COLOR="#000000">&gt; &gt; folders, or keep one copy and send one to another person.&quot;</FONT>
<FONT COLOR="#000000">&gt; &gt; </FONT>
<FONT COLOR="#000000">&gt; &gt; Which would be a perfectly normal use of a filter.</FONT>
<FONT COLOR="#000000">&gt; &gt; YOUR bug link, however, is untrue. :)</FONT>
<FONT COLOR="#000000">&gt; </FONT>
<FONT COLOR="#000000">Can you provide me with an example of such a script. Unfortunately, I'm</FONT>
<FONT COLOR="#000000">on this GARBARGE BELL/SYMPATICO ISp that filters out any outgoing mail,</FONT>
<FONT COLOR="#000000">but I am on a linux machine w/ Postfix/Sendmail, and the address I want</FONT>
<FONT COLOR="#000000">to forward to mostly is an alias local to my machine.</FONT>
</PRE>
</BLOCKQUOTE>
<PRE>

</PRE>
At the simplest form, for sendmail or postfix, you add an action:<BR>
<BR>
&quot;Pipe to Program&quot;<BR>
and use<BR>
/usr/sbin/sendmail -f <A HREF="mailto:yourreply@address">yourreply@address</A>&nbsp; <A HREF="mailto:the.target@address">the.target@address</A><BR>
<BR>
This will effectively &quot;redirect&quot; or &quot;bounce&quot; the message to &quot;<A HREF="mailto:the.target@address">the.target@address</A>&quot;, and send any errors to &quot;<A HREF="mailto:yourreply@address">yourreply@address</A>&quot;.<BR>
<BR>
Then you could add other actions to e.g. mark the mail as read or whatever.<BR>
<BR>
If you want to form an attachment of the message it gets a bit trickier, and you need a script.&nbsp; I've attached an example script - it is a little more sophisticated than the trivial-case, as it extracts (multiline) subject to form a destination subject.&nbsp; It could be changed to take the target address from the command line or calculate it from the message.<BR>
<BR>
--- begin script ---<BR>
#!/bin/sh<BR>
<BR>
# forwards an rfc822 message from stdin to &quot;to&quot; coming from &quot;from&quot; as a mime attachment<BR>
<BR>
from=&quot;not zed &lt;<A HREF="mailto:notzed@novell.com">notzed@novell.com</A>&gt;&quot;<BR>
errors=&quot;<A HREF="mailto:notzed@novell.com">notzed@novell.com</A>&quot;<BR>
to=&quot;mike &lt;<A HREF="mailto:notzed@ximian.com">notzed@ximian.com</A>&gt;&quot;<BR>
<BR>
msg=~/.forward.$$<BR>
date=`date --rfc-2822`<BR>
<BR>
# save message<BR>
cat - &gt;$msg<BR>
<BR>
# generate forwarded subject<BR>
subject=`cat $msg | sed -e &quot;/^$/ q&quot;&nbsp; -e &quot;/^Subject:/ s/Subject:/Subject: Fw:/&quot; -e &quot;/^Subject:/,/^[\t ]/ p&quot; -e &quot;d&quot; -e &quot;/^$/ q&quot;`<BR>
<BR>
# build/send message<BR>
( echo &quot;From: $from&quot;<BR>
&nbsp; echo &quot;To: $to&quot;<BR>
&nbsp; echo &quot;$subject&quot;<BR>
&nbsp; echo &quot;Date: $date&quot;<BR>
&nbsp; echo &quot;Mime-Version: 1.0&quot;<BR>
&nbsp; echo &quot;Content-Type: message/rfc822&quot;<BR>
&nbsp; echo &quot;&quot;<BR>
&nbsp; cat $msg ) | /usr/sbin/sendmail -f $errors $to<BR>
<BR>
rm $msg<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
</BODY>
</HTML>

--=-4QWFtPHpAJzQTxu6XKXW--