Dave Robbins wrote:
Thanks for the great recipe.
You're welcome. I am glad to have been able to assist.
I slightly modified the recipe written by wadem(_at_)suwanneevalley(_dot_)net
because I want to put this recipe in /etc/procmailrc so that it works
for any user on a system. To get the "best" from address,
I used Alan Stebbins' get-from.rc from his procmail-lib.
What I don't like about the recipe is that I get the original email
in my mailbox. I want it to just being deleted
and only the 'quota -v' results getting sent to the user.
e.g. I get:
N146 Dave Robbins Mon May 14 16:37 11/400 show diskquota
N147 Dave Robbins Mon May 14 16:37 21/874 Re: show diskquota
I only want the reply.
If this is no longer the "best" from address, I'd appreciate
knowing a better method of obtaining it because
FROM=`formail -xFrom:` doesn't work.
No,... but this should work:
:0 c
FROM=|formail -xfrom:
Or,...
:0 c
* ^from:\/.*
FROM=|echo $MATCH
Dave
--
SHELL=/bin/sh # whatever shell you want it to use
SENDMAIL=/usr/lib/sendmail # where to look for the MTA
# get-from.rc from Alan Stebbins
:0
* ! ^Reply-to: *\/[^ ].*
* ! ^From: *\/[^ ].*
* ! ^Sender: *\/[^ ].*
* ! ^From +\/[^ ]+
* ! ^X-Envelope: *\/[^ ].*
{ FROM=nobody }
:0E
{ FROM=$MATCH }
# diskquota autoresponder from Mr. Wade <wadem(_at_)suwanneevalley(_dot_)net>
SELF=$FROM # the sender's email address
:0 iW
* $ !^x-loop: $SELF
* $ ^from:.*\<$SELF
* ^subject:.*\<show diskquota
| ( formail -r -X "" -A "X-Loop: $SELF"; \
echo "Below, 'limit' indicates your diskquota in kilobytes"; \
echo ""; echo "quota -v" | $SHELL ) \
| $SENDMAIL -oi -f $SELF -- $SELF
For one thing, if you are just going to "SELF=$FROM", then you
might as well just replace all the "SELF"s with "FROM"s and
eliminate the "SELF=$FROM".
Other than that, there are at least two issues here which need
addressing:
1. The diskquota autoresponder recipe from the above seems to be
choking when $SELF contains more than just an email address,
this is if it contains a real name, as well. It seems
especially broken if that From: line contains quote marks,
like this:
From: "Mr. Wade" <wadem(_at_)suwanneevalley(_dot_)net>
This is why you are getting the original email in your DEFAULT
mailbox. If you have no real name and only an email address I
imagine it might work as expected.
Perhaps a solution to this problem is to find an elegant way
to extract the email address portion from the $FROM variable.
Maybe something like this will serve:
:0 c
* ^from:\/.*
FROM=| echo $MATCH | sed -e "s/.*<\(.*\)>.*/\1/"
2. By writing it the way you have, even if you get it to work
properly, you have introduced a security problem in that
anyone can request the disk quota results for any user
by sending the request to them.
i.e., IF nosey-fool(_at_)somewhere-else(_dot_)com sends:
From: nosey-fool(_at_)somewhere-else(_dot_)com
To: nice_user(_at_)your-host(_dot_)org
Subject: show diskquota
THEN the results of `quota -v` as executed by nice_user will
be sent to nosey-fool(_at_)somewhere-else(_dot_)com, or even more
confusing: if the "From:" line is forged, someone could
effectively cause the report go to a third party.
I doubt you wanted to do that. Therefore, something else must
be done to fix that.
Maybe this will do for you:
-----
SHELL=/bin/sh # whatever shell you want it to use
SENDMAIL=/usr/lib/sendmail # where to look for the MTA
:0 c
* ^from:\/.*
FROM=| echo $MATCH | sed -e "s/.*<\(.*\)>.*/\1/"
:0 iW
* $ !^x-loop: $FROM
* $ ^from:.*\<$FROM
* $ ^to:.*\<$FROM
* ^subject:.*\<show diskquota
| ( formail -r -X "" -A "X-Loop: $FROM"; \
echo "Below, 'limit' indicates your diskquota in kilobytes"; \
echo ""; echo "uptime" | $SHELL ) \
| $SENDMAIL -oi -f $FROM -- $FROM
-----
This is a little better, but still not right. :( The recipe can
still be "tricked" into responding to a different address with:
From: "nice_user(_at_)your-host(_dot_)org"
<nosey-fool(_at_)somewhere-else(_dot_)com>
To: nice_user(_at_)your-host(_dot_)org
Subject: show diskquota
*sigh* Maybe someone else has a better idea or a fix for this.
It's late where I am; I'm going to bed! =) I hope I have at
least helped get you going in the right direction.
Good luck!
-- Mr. Wade
--
Linux: The Choice of the GNU Generation
_______________________________________________
procmail mailing list
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail