Discussion:
possible? sender rewrite based on regexp and /etc/passwd
(too old to reply)
Jon Bendtsen
2004-05-10 13:59:12 UTC
Permalink
Hi list

After finding address rewritting and regexp's in the postfix
documentation, i tried looking for more information in the FAQ's, but i
was unable to find any questions i find similar to mine

problem:
i want to rewrite the sender address (or add an reply-to header) based
on information stored in the /etc/passwd file.
As most of you probably know, /etc/passwd contains other information
than the name and the email address.
So i need some sort of regexp that pulls the information from the file
or a script that does the sender address rewriting.

But is that possible? i'm not entirely sure if it is, and/or if i
should use regexp or a real script?

Why passwd:
so when i add users i only have to put the information one place



JonB
Magnus Bäck
2004-05-10 14:36:56 UTC
Permalink
On Monday, May 10, 2004 at 15:58 CEST,
Post by Jon Bendtsen
After finding address rewritting and regexp's in the postfix
documentation, i tried looking for more information in the FAQ's, but
i was unable to find any questions i find similar to mine
=20
i want to rewrite the sender address (or add an reply-to header) based
on information stored in the /etc/passwd file.
As most of you probably know, /etc/passwd contains other information=20
than the name and the email address.
So i need some sort of regexp that pulls the information from the file
or a script that does the sender address rewriting.
Use canonical address mapping and use a script to generate a suitable
map file from the password file. That's the general idea, and I can't
say more without any details.

[...]

--=20
Magnus B=E4ck
***@dsek.lth.se
Jon Bendtsen
2004-05-10 14:45:22 UTC
Permalink
Post by Magnus Bäck
On Monday, May 10, 2004 at 15:58 CEST,
Post by Jon Bendtsen
After finding address rewritting and regexp's in the postfix
documentation, i tried looking for more information in the FAQ's, but
i was unable to find any questions i find similar to mine
i want to rewrite the sender address (or add an reply-to header) =
based
Post by Magnus Bäck
Post by Jon Bendtsen
on information stored in the /etc/passwd file.
As most of you probably know, /etc/passwd contains other information
than the name and the email address.
So i need some sort of regexp that pulls the information from the =
file
Post by Magnus Bäck
Post by Jon Bendtsen
or a script that does the sender address rewriting.
Use canonical address mapping and use a script to generate a suitable
map file from the password file. That's the general idea, and I can't
say more without any details.
What kind of details where you looking for?
I would prefer to not have one extra file for maintaining a list of=20
email addresses and usernames.



JonB
Magnus Bäck
2004-05-10 14:51:18 UTC
Permalink
On Monday, May 10, 2004 at 16:44 CEST,
Post by Jon Bendtsen
=20
Post by Magnus Bäck
Use canonical address mapping and use a script to generate a
suitable map file from the password file. That's the general idea,
and I can't say more without any details.
=20
What kind of details where you looking for?
Without knowing exactly how the addresses should be rewritten, I can't
provide an example of how to do it.
Post by Jon Bendtsen
I would prefer to not have one extra file for maintaining a list of=20
email addresses and usernames.
Because you use a script to generate this file, no extra maintenence
work is involved.

Depending on how you create the users, there might be a simple way to
automate the running of the script. For example, the Debian adduser
program attempts to invoke /usr/local/sbin/adduser.local when a user
has been added.

--=20
Magnus B=E4ck
***@dsek.lth.se
Jon Bendtsen
2004-05-10 15:00:22 UTC
Permalink
Post by Magnus Bäck
On Monday, May 10, 2004 at 16:44 CEST,
Post by Jon Bendtsen
Post by Magnus Bäck
Use canonical address mapping and use a script to generate a
suitable map file from the password file. That's the general idea,
and I can't say more without any details.
What kind of details where you looking for?
Without knowing exactly how the addresses should be rewritten, I can't
provide an example of how to do it.
Well, lets take an example...
the username is jbendtsen, and with the added domain it looks like this=20=

***@laerdal.dk

For some reason the mailserver can look into /etc/passwd and grab the=20
name field, turning the
final from into:
From: "Jon Bendtsen" <***@laerdal.dk>

I want to make the =46rom header look like this

From: "Jon Bendtsen" <***@example.com>

or similar.
Post by Magnus Bäck
Post by Jon Bendtsen
I would prefer to not have one extra file for maintaining a list of
email addresses and usernames.
Because you use a script to generate this file, no extra maintenence
work is involved.
Depending on how you create the users, there might be a simple way to
automate the running of the script. For example, the Debian adduser
program attempts to invoke /usr/local/sbin/adduser.local when a user
has been added.
allright :) i am running debian, so it would surely be a posibility
But, for now i would like to pretend that the extra file is not an=20
option. Can i run a script, a filter, a ... on the headers or the=20
entire email before sending it ?



JonB=
Magnus Bäck
2004-05-10 15:24:34 UTC
Permalink
On Monday, May 10, 2004 at 17:00 CEST,
Post by Jon Bendtsen
=20
Post by Magnus Bäck
Without knowing exactly how the addresses should be rewritten, I
can't provide an example of how to do it.
=20
Well, lets take an example...
the username is jbendtsen, and with the added domain it looks like this=
=20
Post by Jon Bendtsen
=20
For some reason the mailserver can look into /etc/passwd and grab the
name field, turning the
=20
I want to make the From header look like this
=20
=20
or similar.
That's a few lines of Perl, or awk, or whatever scripting language you
prefer. Very crude Perl example:

#!/usr/bin/perl -w

while (<>) {
chomp;
@_ =3D split /:/;
next unless ($_[2] >=3D 1000);
$_[4] =3D~ tr/A-Z /a-z./;
print sprintf("%-30s %s\n", "$_[0]\@laerdal.dk", "$_[4]\@example.com"=
);
}
Post by Jon Bendtsen
Post by Magnus Bäck
Depending on how you create the users, there might be a simple way
to automate the running of the script. For example, the Debian
adduser program attempts to invoke /usr/local/sbin/adduser.local
when a user has been added.
=20
allright :) i am running debian, so it would surely be a posibility
But, for now i would like to pretend that the extra file is not an
option. Can i run a script, a filter, a ... on the headers or the
entire email before sending it ?
You would need a fully-fledged content filter, but using a content
filter for such a task would be ridiculous. Another solution would
be to implement a new dictionary type for the purpose, but that's
*beyond* ridiculous.

--=20
Magnus B=E4ck
***@dsek.lth.se
Jon Bendtsen
2004-05-10 15:29:35 UTC
Permalink
Post by Magnus Bäck
On Monday, May 10, 2004 at 17:00 CEST,
Post by Jon Bendtsen
Post by Magnus Bäck
Without knowing exactly how the addresses should be rewritten, I
can't provide an example of how to do it.
Well, lets take an example...
the username is jbendtsen, and with the added domain it looks like=20
this
For some reason the mailserver can look into /etc/passwd and grab the
name field, turning the
I want to make the =46rom header look like this
or similar.
That's a few lines of Perl, or awk, or whatever scripting language you
#!/usr/bin/perl -w
while (<>) {
chomp;
@_ =3D split /:/;
next unless ($_[2] >=3D 1000);
$_[4] =3D~ tr/A-Z /a-z./;
}
yes, but how do i get postfix to run that?
Post by Magnus Bäck
Post by Jon Bendtsen
Post by Magnus Bäck
Depending on how you create the users, there might be a simple way
to automate the running of the script. For example, the Debian
adduser program attempts to invoke /usr/local/sbin/adduser.local
when a user has been added.
allright :) i am running debian, so it would surely be a posibility
But, for now i would like to pretend that the extra file is not an
option. Can i run a script, a filter, a ... on the headers or the
entire email before sending it ?
You would need a fully-fledged content filter, but using a content
filter for such a task would be ridiculous. Another solution would
be to implement a new dictionary type for the purpose, but that's
*beyond* ridiculous.
i suppose so. So you are still saying that i should create the extra=20
file ?



JonB
Magnus Bäck
2004-05-10 15:36:14 UTC
Permalink
On Monday, May 10, 2004 at 17:29 CEST,
Post by Jon Bendtsen
=20
Post by Magnus Bäck
That's a few lines of Perl, or awk, or whatever scripting language
=20
#!/usr/bin/perl -w
=20
while (<>) {
chomp;
@_ =3D split /:/;
next unless ($_[2] >=3D 1000);
$_[4] =3D~ tr/A-Z /a-z./;
}
=20
yes, but how do i get postfix to run that?
You don't. A script similar to this would be run every time you add
or change a user. There is no point in having Postfix look up this
information every time a mail passes through the system.
Post by Jon Bendtsen
Post by Magnus Bäck
You would need a fully-fledged content filter, but using a content
filter for such a task would be ridiculous. Another solution would
be to implement a new dictionary type for the purpose, but that's
*beyond* ridiculous.
=20
i suppose so. So you are still saying that i should create the extra
file ?
Yes. If you have your users stored in LDAP or in a database table,
that's another alternative.

--=20
Magnus B=E4ck
***@dsek.lth.se
Jon Bendtsen
2004-05-10 15:42:21 UTC
Permalink
Post by Magnus Bäck
On Monday, May 10, 2004 at 17:29 CEST,
Post by Jon Bendtsen
Post by Magnus Bäck
That's a few lines of Perl, or awk, or whatever scripting language
#!/usr/bin/perl -w
while (<>) {
chomp;
@_ =3D split /:/;
next unless ($_[2] >=3D 1000);
$_[4] =3D~ tr/A-Z /a-z./;
}
yes, but how do i get postfix to run that?
You don't. A script similar to this would be run every time you add
or change a user. There is no point in having Postfix look up this
information every time a mail passes through the system.
oh, i thought you ment at the time of sending email
Post by Magnus Bäck
Post by Jon Bendtsen
Post by Magnus Bäck
You would need a fully-fledged content filter, but using a content
filter for such a task would be ridiculous. Another solution would
be to implement a new dictionary type for the purpose, but that's
*beyond* ridiculous.
i suppose so. So you are still saying that i should create the extra
file ?
Yes. If you have your users stored in LDAP or in a database table,
that's another alternative.
okay, i will listen to your advice



JonB
V***@MorganStanley.com
2004-05-10 15:49:16 UTC
Permalink
Post by Jon Bendtsen
Well, lets take an example...
the username is jbendtsen, and with the added domain it looks like this
For some reason the mailserver can look into /etc/passwd and grab the
name field, turning the
I want to make the From header look like this
or similar.
Setting the display name is the MUA's job. There are no mechanisms in
Postfix for adding/changing display names in existing "From:" headers.

When a message is submitted locally (via the "sendmail" command) without a
"From:" header, the full name from the password file is used to construct
the automatically generated From: header.
--
Viktor.

Disclaimer: off-list followups get on-list replies or get ignored.
Please do not ignore the "Reply-To" header.

To unsubscribe from the postfix-users list, visit
http://www.postfix.org/lists.html or click the link below:
<mailto:***@postfix.org?body=unsubscribe%20postfix-users>
Eddy Beliveau
2004-05-10 16:03:40 UTC
Permalink
Hi!

Your discussion is very interesting and informative :-)

I have a similar need, suppose that:

My domain is acme.com
Our users are stored on ldap
Outlook is displaying the content of the From header below the From colum=
n.

I'm using two postfix instances:
- one for internal user only, sasl authentication is mandatory, using smt=
pd_sender_login_maps
- one for external user (users from outside are allowed to use @acme.com =
as their From address)

When receiving an email with the following header
From: John Travolta <***@acme.com>

I would like to have it rewritten as:
From: John Travolta (authenticated) <***@acme.com>
if it passed thru the instance # one (main1.cf)
or
From: John Travolta (NOT authenticated) <***@acme.com>
if it passed thru the instance # two (main2.cf)

Is there a way to do it ?

Thanks and have a very nice day
Eddy

----- Original Message -----=20
From: "Jon Bendtsen" <***@laerdal.dk>
To: <postfix-***@postfix.org>
Sent: Monday, May 10, 2004 11:42 AM
Subject: Re: possible? sender rewrite based on regexp and /etc/passwd
Post by Magnus Bäck
On Monday, May 10, 2004 at 17:29 CEST,
Post by Jon Bendtsen
Post by Magnus Bäck
That's a few lines of Perl, or awk, or whatever scripting language
#!/usr/bin/perl -w
while (<>) {
chomp;
@_ =3D split /:/;
next unless ($_[2] >=3D 1000);
$_[4] =3D~ tr/A-Z /a-z./;
}
yes, but how do i get postfix to run that?
You don't. A script similar to this would be run every time you add
or change a user. There is no point in having Postfix look up this
information every time a mail passes through the system.
oh, i thought you ment at the time of sending email
Post by Magnus Bäck
Post by Jon Bendtsen
Post by Magnus Bäck
You would need a fully-fledged content filter, but using a content
filter for such a task would be ridiculous. Another solution would
be to implement a new dictionary type for the purpose, but that's
*beyond* ridiculous.
i suppose so. So you are still saying that i should create the extra
file ?
Yes. If you have your users stored in LDAP or in a database table,
that's another alternative.
okay, i will listen to your advice



JonB
Jon Bendtsen
2004-05-10 16:04:46 UTC
Permalink
Post by V***@MorganStanley.com
Post by Jon Bendtsen
Well, lets take an example...
the username is jbendtsen, and with the added domain it looks like
this
For some reason the mailserver can look into /etc/passwd and grab the
name field, turning the
I want to make the From header look like this
or similar.
Setting the display name is the MUA's job. There are no mechanisms in
Postfix for adding/changing display names in existing "From:" headers.
When a message is submitted locally (via the "sendmail" command)
without a
"From:" header, the full name from the password file is used to
construct
the automatically generated From: header.
well, the MUA is cvsmail.py, and bugzilla, and other such tools. I'd
rather add this in the MTA (one place)
rather than all the others.



JonB
V***@MorganStanley.com
2004-05-10 16:26:39 UTC
Permalink
Post by V***@MorganStanley.com
Setting the display name is the MUA's job. There are no mechanisms in
Postfix for adding/changing display names in existing "From:" headers.
When a message is submitted locally (via the "sendmail" command)
without a "From:" header, the full name from the password file is used
to construct the automatically generated From: header.
Well, the MUA is cvsmail.py, and bugzilla, and other such tools. I'd
rather add this in the MTA (one place) rather than all the others.
Sorry, Postfix has no mechanisms for canonicalizing display names in
message headers.

The only exception is for mail submitted via the unix command line via
minimal MUAs that are just thin wrappers around the "sendmail" command.
Only in this case can the MUA delegate the creation of the "From: address
(display name)" header to the Postfix MTA. The relevant address and
fullname are taken from the passwd entry for the uid that submitted the
message.
--
Viktor.

Disclaimer: off-list followups get on-list replies or get ignored.
Please do not ignore the "Reply-To" header.

To unsubscribe from the postfix-users list, visit
http://www.postfix.org/lists.html or click the link below:
<mailto:***@postfix.org?body=unsubscribe%20postfix-users>
Magnus Bäck
2004-05-10 17:17:25 UTC
Permalink
On Monday, May 10, 2004 at 18:03 CEST,
Post by Eddy Beliveau
My domain is acme.com
Our users are stored on ldap
Outlook is displaying the content of the From header below the From col=
umn.
Post by Eddy Beliveau
=20
- one for internal user only, sasl authentication is mandatory, using
smtpd_sender_login_maps
- one for external user (users from outside are allowed to use
@acme.com as their From address)
=20
When receiving an email with the following header
=20
if it passed thru the instance # one (main1.cf)
or
if it passed thru the instance # two (main2.cf)
=20
Is there a way to do it ?
Yes, with two content filters (one for each instance).

--=20
Magnus B=E4ck
***@dsek.lth.se
Eddy Beliveau
2004-05-10 20:25:07 UTC
Permalink
Post by Magnus Bäck
Yes, with two content filters (one for each instance).
Hi! Magnus,
Many thanks for your reply, it is very appreciated

On my Postfix 2.0.16, I'm currently using
content_filter =3D smtp-amavis:[127.0.0.1]:10025

Do you know if I can add my own code before or within amavisd-new 2003061=
6-p8-rc3 ?

What would you recommend ?

Any pointers will be appreciated.

Thanks,
Eddy
PS: I'm very familiar with Perl

----- Original Message -----=20
From: "Magnus B=E4ck" <***@dsek.lth.se>
To: <postfix-***@postfix.org>
Sent: Monday, May 10, 2004 1:17 PM
Subject: Re: possible? sender rewrite based on regexp and /etc/passwd


On Monday, May 10, 2004 at 18:03 CEST,
Post by Magnus Bäck
My domain is acme.com
Our users are stored on ldap
Outlook is displaying the content of the From header below the From col=
umn.
Post by Magnus Bäck
- one for internal user only, sasl authentication is mandatory, using
smtpd_sender_login_maps
- one for external user (users from outside are allowed to use
@acme.com as their From address)
When receiving an email with the following header
if it passed thru the instance # one (main1.cf)
or
if it passed thru the instance # two (main2.cf)
Is there a way to do it ?
Magnus Bäck
2004-05-10 22:04:25 UTC
Permalink
On Monday, May 10, 2004 at 22:24 CEST,
Post by Eddy Beliveau
Post by Magnus Bäck
Yes, with two content filters (one for each instance).
=20
Hi! Magnus,
Many thanks for your reply, it is very appreciated
=20
On my Postfix 2.0.16, I'm currently using
content_filter =3D smtp-amavis:[127.0.0.1]:10025
=20
Do you know if I can add my own code before or within amavisd-new
20030616-p8-rc3 ?
AFAIK, amavisd-new does not support "plug-in extra filtering" which is
what one might call your needs. You'll have to chain several content
filters using Postfix, which can tend to get pretty ugly. Example:

Postfix -> amavisd-new -> Postfix -> your script -> Postfix -> delivery

--=20
Magnus B=E4ck
***@dsek.lth.se
Eddy Beliveau
2004-05-11 12:32:26 UTC
Permalink
Post by Magnus Bäck
AFAIK, amavisd-new does not support "plug-in extra filtering" which is
what one might call your needs. You'll have to chain several content
Postfix -> amavisd-new -> Postfix -> your script -> Postfix -> delivery
Many thanks for your reply

This should be the last question:
Do you know where I can find an example of content filter written in perl ?

Many thanks again for yout time and patience :-)

Cheers,
Eddy
Magnus Bäck
2004-05-11 13:56:20 UTC
Permalink
On Tuesday, May 11, 2004 at 14:32 CEST,
Post by Eddy Beliveau
Do you know where I can find an example of content filter written in
perl ?
Not on the top of my head, but you can look at the shell-script example
in FILTER_README. The script shows the general idea and is easy to adapt
to Perl.

--=20
Magnus B=E4ck
***@dsek.lth.se
Eddy Beliveau
2004-05-11 14:18:29 UTC
Permalink
Many thanks,

I will follow your recommendation

Thanks again,
I do appreciate your time and patience.

Eddy
----- Original Message -----=20
From: "Magnus B=E4ck" <***@dsek.lth.se>
To: <postfix-***@postfix.org>
Sent: Tuesday, May 11, 2004 9:56 AM
Subject: Re: possible? sender rewrite based on regexp and /etc/passwd


On Tuesday, May 11, 2004 at 14:32 CEST,
Post by Eddy Beliveau
Do you know where I can find an example of content filter written in
perl ?
Not on the top of my head, but you can look at the shell-script example
in FILTER_README. The script shows the general idea and is easy to adapt
to Perl.

--=20
Magnus B=E4ck
***@dsek.lth.se
V***@MorganStanley.com
2004-05-11 14:30:07 UTC
Permalink
Post by Eddy Beliveau
Many thanks,
I will follow your recommendation
Also look for Bennett Todd's Perl SMTP proxy.
--
Viktor.

Disclaimer: off-list followups get on-list replies or get ignored.
Please do not ignore the "Reply-To" header.

To unsubscribe from the postfix-users list, visit
http://www.postfix.org/lists.html or click the link below:
<mailto:***@postfix.org?body=unsubscribe%20postfix-users>
Eddy Beliveau
2004-05-11 14:57:07 UTC
Permalink
Post by V***@MorganStanley.com
Also look for Bennett Todd's Perl SMTP proxy.
--
Viktor.
Thanks,
Your help is appreciated :-)

Eddy

Loading...