Mailing List Archive

qmail-alias env vars?
Hey everyone,

I'm trying to setup a perl script ala qmail-command which will only allow
certain addresses to send to a particular address. For example,
jeff-blah@apex.net will bounce everybody that sends to it except for me
(jeff@apex.net).

Now, I understand that qmail-alias provides environment variables to a
command in .qmail (such as |my-script.pl). The one I'm interested in
(obviously) is the SENDER environment variable. However, I can't seem to
get my script to find it. What exactly do I have to do to get to that
variable?

'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'
`' Jeff Carneal / Sys Admin \ Apex Internet `'
`' jeff@apex.net http://www.apex.net `'
`' The opinions expressed above aren't really mine. They belong to `'
`' someone else who also refuses to take responsibility for them. `'
'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'
Re: qmail-alias env vars? [ In reply to ]
Jeff T. Carneal <jeff@apex.apex.net> writes:
>On Sun, 16 Feb 1997, Greg Andrews wrote:
>>
>> This sounds like more of a Perl question than a qmail one, but the
>> answer is fairly simple. In Perl, environment variables are found
>> in the %ENV hash (associative array). So a statement like:
>>
>> $sender_address = $ENV{'SENDER'};
>
>Well, that's what I thought too, but that's not how life works. For the
>interested (and to my chagrin) I found the answer about 10 minutes after
>posting (sorry).
>
>$sender = $ENV{"SENDER"} doesn't work because there is not environment
>variable "SENDER". Here's what does work:
>
>In your .qmail-whatever file, put the command like this:
>
>| my-script.pl "SENDER"
>
>and then get it from $ARGV. It won't work the other way, so don't even
>try it :)
>

Jeff, I *have* tried it. Since I don't do local delivery to users on my
qmail machine, I created a file in ~alias named .qmail-testit:

echo '| ./testit.pl' > ~alias/.qmail-testit
chown alias ~alias/.qmail-testit
chgrp nofiles ~alias/.qmail-testit
chmod 600 ~alias/.qmail-testit

The perl script was also chowned to alias and chmodded to 700.
It opened a file and wrote the SENDER variable to it:

#!/usr/local/bin/perl
open(OUT, '> sender-var') || die "Can't open sender-var file: $!\n";
$sender_address = $ENV{'SENDER'};
print OUT "SENDER $sender_address\n";
close(OUT);
exit(0);


I sent it a test message, and here were the contents of the
resulting "sender-var" file:

SENDER root@virtmail.wco.com


Try it yourself.

-Greg
--
Greg Andrews West Coast Online
Unix System Administrator 5800 Redwood Drive
gerg@wco.com Rohnert Park CA 94928
(yes, 'greg' backwards) 1-800-WCO-INTERNET
Re: qmail-alias env vars? [ In reply to ]
At 06:17 AM 2/17/97 -0600, you wrote:
>On Sun, 16 Feb 1997, Greg Andrews wrote:
>> $sender_address = $ENV{'SENDER'};
>
>> Jeff T. Carneal <jeff@apex.apex.net> asks:
>Well, that's what I thought too, but that's not how life works. For the
>interested (and to my chagrin) I found the answer about 10 minutes after
>posting (sorry).
>
>$sender = $ENV{"SENDER"} doesn't work because there is not environment
>variable "SENDER". Here's what does work:

Maybe I can help here... I have not yet written Perl scripts to interact
with Q-mail (I will very soon, however) but in Perl there is a difference
between "" and ''. What Jeff shows as $ENV{"SENDER"} is different from
$ENV{'SENDER'} and may very well be why one works and the other does not.

Please keep in mind that I have not tested this, and your mileage may vary.

Hope this helps,
"Merch"
Roger "Merch" Merchberger | On the first day of Christmas my True Love
Programmer, NorthernWay | gave to me: A Beer. -- Bob & Doug McKenzie
zmerch@northernway.net | ====> Like, take off, eh hoser!!!! <====
http://home.northernway.net/~zmerch/
Re: qmail-alias env vars? [ In reply to ]
On Sun, 16 Feb 1997, Greg Andrews wrote:

> Jeff T. Carneal <jeff@apex.apex.net> writes:
> >On Sun, 16 Feb 1997, Greg Andrews wrote:
> >>
> >> This sounds like more of a Perl question than a qmail one, but the
> >> answer is fairly simple. In Perl, environment variables are found
> >> in the %ENV hash (associative array). So a statement like:
> >>
> >> $sender_address = $ENV{'SENDER'};
> >
> >Well, that's what I thought too, but that's not how life works. For the
> >interested (and to my chagrin) I found the answer about 10 minutes after
> >posting (sorry).
> >
> >$sender = $ENV{"SENDER"} doesn't work because there is not environment
> >variable "SENDER". Here's what does work:
> >
> >In your .qmail-whatever file, put the command like this:
> >
> >| my-script.pl "SENDER"
> >
> >and then get it from $ARGV. It won't work the other way, so don't even
> >try it :)
> >
>
> Jeff, I *have* tried it. Since I don't do local delivery to users on my
> qmail machine, I created a file in ~alias named .qmail-testit:
>
> echo '| ./testit.pl' > ~alias/.qmail-testit
> chown alias ~alias/.qmail-testit
> chgrp nofiles ~alias/.qmail-testit
> chmod 600 ~alias/.qmail-testit
>
> The perl script was also chowned to alias and chmodded to 700.
> It opened a file and wrote the SENDER variable to it:
>
> #!/usr/local/bin/perl
> open(OUT, '> sender-var') || die "Can't open sender-var file: $!\n";
> $sender_address = $ENV{'SENDER'};
> print OUT "SENDER $sender_address\n";
> close(OUT);
> exit(0);

Greg, I *have* tried it too :-) And I'm here to tell you, it doesn't work
under RedHat linux 4.0 running kernel 2.0.28. I set up the box
jeff-blah@apex.net with a .qmail-blah file in my home directory with the
following in it:

|/usr/local/home/jeff/perl/qmail-filter.pl
./Mailbox

then I did the following:

$sender = ENV{"SENDER"}
which doesn't work (the " and ' are the same with associative arrays)
Then, frowning, I wanted to know what all env vars there were. I did the
following to find out:

foreach $var (keys %ENV) {
print MYLOGFILE "$var:\t$ENV{$var}\n";
}

and there was no SENDER in there. There were only the variables you see
when you type "env" at the prompt. That's why I asked the list, cuz I new
the %ENV array, but I couldn't find SENDER in it.

At any rate, it yours works for you, great. But what I tried didn't work
on our mail server....thanks for your help anyway :)

'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'
`' Jeff Carneal / Sys Admin \ Apex Internet `'
`' jeff@apex.net http://www.apex.net `'
`' The opinions expressed above aren't really mine. They belong to `'
`' someone else who also refuses to take responsibility for them. `'
'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'
Re: qmail-alias env vars? [ In reply to ]
Jeff T. Carneal <jeff@apex.apex.net> writes:
>
>Then, frowning, I wanted to know what all env vars there were. I did the
>following to find out:
>
>foreach $var (keys %ENV) {
> print MYLOGFILE "$var:\t$ENV{$var}\n";
>}
>
>and there was no SENDER in there. There were only the variables you see
>when you type "env" at the prompt.
>

You had *only* the variables that you normally see when you type 'env'
with an interactive shell?!?

Then something is VERY wrong. Qmail-alias supplies a number of variables
I've never seen before:

DTLINE=Delivered-To: testit@virtmail.wco.com
EXT=testit
EXT2=
EXT3=
EXT4=
HOME=/var/qmail/alias
HOST=virtmail.wco.com
LOCAL=testit
NEWSENDER=root@virtmail.wco.com
PATH=/var/qmail/bin:/usr/sbin:/usr/bin
RECIPIENT=testit@virtmail.wco.com
RPLINE=Return-Path: <root@virtmail.wco.com>
SENDER=root@virtmail.wco.com
UFLINE=From root@virtmail.wco.com Mon Feb 17 21:14:57 1997
USER=alias


If you're not seeing those variables, then I have to wonder whether
qmail-alias is really delivering the messages to your mailbox.
What version of qmail are you running? How are you feeding test
messages to qmail (via smtp or | qmail-inject)?

-Greg
--
Greg Andrews West Coast Online
Unix System Administrator 5800 Redwood Drive
gerg@wco.com Rohnert Park CA 94928
(yes, 'greg' backwards) 1-800-WCO-INTERNET
Re: qmail-alias env vars? [ In reply to ]
On Mon, 17 Feb 1997, Greg Andrews wrote:

> Jeff T. Carneal <jeff@apex.apex.net> writes:
> >
> >Then, frowning, I wanted to know what all env vars there were. I did the
> >following to find out:
> >
> >foreach $var (keys %ENV) {
> > print MYLOGFILE "$var:\t$ENV{$var}\n";
> >}
> >
> >and there was no SENDER in there. There were only the variables you see
> >when you type "env" at the prompt.
> >
> You had *only* the variables that you normally see when you type 'env'
> with an interactive shell?!?
>
> Then something is VERY wrong. Qmail-alias supplies a number of variables
> I've never seen before:
>
> DTLINE=Delivered-To: testit@virtmail.wco.com
> EXT=testit
> EXT2=
> EXT3=

[snipped]

Yes, I understood from the man page that that was supposed to happen, but
I didn't see them. Has anybody verified if it makes a difference using
the '' quotes or the "" quotes? Possibly that was one problem...

> If you're not seeing those variables, then I have to wonder whether
> qmail-alias is really delivering the messages to your mailbox.
> What version of qmail are you running? How are you feeding test
> messages to qmail (via smtp or | qmail-inject)?

qmail-inject on 0.96

'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'
`' Jeff Carneal / Sys Admin \ Apex Internet `'
`' jeff@apex.net http://www.apex.net `'
`' The opinions expressed above aren't really mine. They belong to `'
`' someone else who also refuses to take responsibility for them. `'
'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'
Re: qmail-alias env vars? [ In reply to ]
Jeff T. Carneal <jeff@apex.apex.net> writes:
>
>Yes, I understood from the man page that that was supposed to happen, but
>I didn't see them. Has anybody verified if it makes a difference using
>the '' quotes or the "" quotes? Possibly that was one problem...
>

I ran some tests on perl 5.003 and it didn't seem to make a difference.
I even tested the case that I thought would give double-quotes a problem
(where SENDER is also the name of an open file descriptor), but perl
did the right thing and retrieved the environment variable instead.

If you're using a significantly older version of Perl (like 5.000 or
4.036), then the quotes might make a difference.

>> What version of qmail are you running? How are you feeding test
>> messages to qmail (via smtp or | qmail-inject)?
>
>qmail-inject on 0.96
>

Do the variables show up if you telnet to the SMTP port and type in
a message that way?

-Greg
--
Greg Andrews West Coast Online
Unix System Administrator 5800 Redwood Drive
gerg@wco.com Rohnert Park CA 94928
(yes, 'greg' backwards) 1-800-WCO-INTERNET
Re: qmail-alias env vars? [ In reply to ]
On Mon, 17 Feb 1997, Greg Andrews wrote:

> Jeff T. Carneal <jeff@apex.apex.net> writes:
> >
> >Yes, I understood from the man page that that was supposed to happen, but
> >I didn't see them. Has anybody verified if it makes a difference using
> >the '' quotes or the "" quotes? Possibly that was one problem...
> >
>
> I ran some tests on perl 5.003 and it didn't seem to make a difference.
> I even tested the case that I thought would give double-quotes a problem
> (where SENDER is also the name of an open file descriptor), but perl
> did the right thing and retrieved the environment variable instead.
>
> If you're using a significantly older version of Perl (like 5.000 or
> 4.036), then the quotes might make a difference.

Nope, I've got 5.003 as well. Could you send me your code and I'll see
what it does on mine? Currently what I've done works, but now I'm just
curious :)

> Do the variables show up if you telnet to the SMTP port and type in
> a message that way?

I don't know, but I know that qmail-alias is supplying the variables to
*something* because when I put '|myscript "$SENDER"' in the .qmail file,
it works like a champ (I just retrieve $SENDER via @ARGV).

'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'
`' Jeff Carneal / Sys Admin \ Apex Internet `'
`' jeff@apex.net http://www.apex.net `'
`' The opinions expressed above aren't really mine. They belong to `'
`' someone else who also refuses to take responsibility for them. `'
'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'