Apply a signature to every mail sent from Nethserver

it’s what I suggested in my first answer… the problem is that there’s no way to force any device to use that signature

The next step is to automagically create a signature file of it and inject it in every outgoing mail. Still not a fully personalized signature. It is a tradeoff, but in a company environment I don’t think it is a bad idea to have signatures in a company wide policy.

1 Like

I think if I capture every outgoing mail from Nethserver (I can check the from field and apply the correct template), and smartphones and desktop apps use Nethserver as smtp server, I have that any device uses the signature.

Ok, at the moment I sketched out something that works:

It extracts parameter form “from” header, puts a signature with variables (at the moment it reports only values of “from” header), and it embeds a image (logo) that it’s visible on Thunderbird, Outlook and Aquamail (Android client).

More work to do…

Once done, don’t be shy and release what you found

There’s a new version:

It’s important to remove the old template-custom that are present in previous versions.

https://drive.google.com/uc?export=download&id=13pNUfqY75aiEBf4XTd4KHgAupgUb-Z16

For the installation:

cd /

tar xvjf /path/where/install/package/is/copied.tar.bz2

mkdir -p /var/spool/addsignatures
chmod 750 /var/spool/addsignatures
chown mail:mail /var/spool/addsignatures

signal-event nethserver-mail-server-update

Docs in /var/lib/nethserver/mail-disclaimers/docs

Please note that this script works modifying /etc/postfix/master.cf where amavisd re-inject messages into postfix (30postfix-queue section). When amavisd will be gone (beacuse adoption of rspamd), we will find another point where to apply the filter “-o content_filter=disclaimer:”.

3 Likes

There’s an open PR for that

My script is based/modified on the same script that @stephdl uses in “Disclaimer by altemime” above and already doesn’t use amavisd to work.

At the moment I put the filter on the “30postifx-queue” section of /etc/postfix/master.cf because I find that’s the only place where the filter is called.

I think that when amavisd is removed, the section will also be removed or modified. So I don’t know if it will be the right position for the filter.

If the new mail implementation (rspamd) reaches feature parity with the old one (amavisd) it’s possible to ship it as a replacement in a normal update run.

Until we reach that point, the two alternatives will be both available.

1 Like

The script working perfect, only one question. Is it possible to set signature by Sender Real name or some other data what can have only one user. We have here e-mails what are used from more users, but the signatures must be (different) from the user.

O_o

First thing: I’m amazed that someone uses that script :slight_smile:

The only thing that comes in my mind is to use the descriptive part of the From: header

For example, if the From header is

From: Saito Benkei <saitobenkei@domain.tld>

I can make the user comparison on the “Saito Benkei” part and not on “saitobenkei” mail address part.

It is however necessary that each client of that user produces an equal header description (same spaces, lower/uppercases, etc…)

For example:, if the user has Thunderbird on the PC and another mail client on his/her smartphone, both must fill in the From field with the same description.

So, i can’t have Thunderbird that produces “Saito Benkei <saitobenkei@domain.tld>” and smartphone’s email client that produces “Saito Benkei Mobile <saitobenkei@domain.tld>”.

Both clients have to compile the From header with “Saito Benkei <saitobenkei@domain.tld>

So you have to configure in Thunderbird the “Your Name” field in the account as “Saito Benkei”. Same thing in the smartphone’s email-client.

Here there’s a untested version of the script (v0.10):

https://drive.google.com/uc?export=download&id=13vRm3K-9RX0QuUNXfopxo8UANbHT_1uY

extract the script (it’s contain addsignatures script only) and copy on

/var/lib/nethserver/mail-disclaimers/scripts

then

chown root:adm /var/lib/nethserver/mail-disclaimers/scripts/addsignatures
chmod 755 /var/lib/nethserver/mail-disclaimers/scripts/addsignatures

edit the file addsignatures and change the READFROMDESC variable’s value to 1

then modify your /var/lib/nethserver/mail-disclaimers/domain.tld/users/users.txt changing the first field of every line with the exact description that you put in your email client

For example:

If your line was
saitobenkei|mr.|Saito|Benkei|saitobenkei@domain.tld|...

You have to change in
Saito Benkei|mr.|Saito|Benkei|saitobenkei@domain.tld|...
Minnie Pluto|mrs.|Minnie|Pluto|saitobenkei@domain.tld|...

So you can have multiple lines with the same email address but different users.

Please, tell me if it works!

As usuaI have no responsibility for the loss of data, blah, blah blah…

3 Likes

Thank you for answering rly detailed post.
Im going to test your (new) scrip to see how it goes, mine also not tested to much, need more testing.
i actually did this (down) today (Had problem with UTF-8 coding in field From):

//add signatures
if [[ $HEADERFROM =~ .UTF-8. ]]
then
FROMADDRESSUSER=echo ${HEADERFROM} | cut -d "?" -f 4 | cut -d "?" -f 4 | tr '[:upper:]' '[:lower:]'
else
FROMADDRESSUSER=echo ${HEADERFROM} | cut -d "<" -f 1 | tr '[:upper:]' '[:lower:]'
fi

//extractuser

if [ “${SACCOUNT}” == “${FROMADDRESSUSER}” ]

for info UTF8 (it should be “G Š”)
From: =?UTF-8?Q?G_=C5=A0?= <administrator@…>

Im having problem decoding this, any suggestion?
for now i did:
#!/usr/bin/perl

use MIME::QuotedPrint;

while (<>) {
	s/_/=20/g;
	print decode_qp($_);
}

FROMADDRESSUSER=`echo ${FROMADDRESSUSER} | perl /var/lib/nethserver/mail-disclaimers/scripts/qp_decode.pl

This is my last script:

if [[ $HEADERFROM =~ .*UTF-8.* ]]
then
FROMADDRESSUSER=`echo ${HEADERFROM} | cut -d "?" -f 4 | cut -d "?" -f 4`

else
FROMADDRESSUSER=`echo ${HEADERFROM} | cut -d "<" -f 1 | cut -c 7-1000`
fi

FROMADDRESSUSER=`echo ${FROMADDRESSUSER} | perl /var/lib/nethserver/mail-disclaimers/scripts/qp_decode.pl`
FROMADDRESSUSER=`echo ${FROMADDRESSUSER} | iconv -f UTF-8 -t ASCII//TRANSLIT`

but im having problems that type of encoding eat from utf char to end.
Is there any solution?

Hi,

I found this:

https://superuser.com/questions/972233/how-do-i-convert-utf-8-special-characters-in-bash

(And I also discovered the existence of the formail command ( https://linux.die.net/man/1/formail ). Maybe I can replace a lot of mess in the script for the extraction of “From:” header with one line…:slight_smile: )

AA nice finding for RFC 2047
Yes, you can do what ever to make it work better

https://drive.google.com/uc?export=download&id=1JWwEn1alN7P-6trRnexBfgLc6149khFS

Here’s a v0.11 that take cares of UTF8 encoded (Untested).

Extract addsignatures and decode.pl in

/var/lib/nethserver/mail-disclaimers/scripts

then

chown root:adm /var/lib/nethserver/mail-disclaimers/scripts/addsignatures
chown root:adm /var/lib/nethserver/mail-disclaimers/scripts/decode.pl
chmod 755 /var/lib/nethserver/mail-disclaimers/scripts/addsignatures
chmod 755 /var/lib/nethserver/mail-disclaimers/scripts/decode.pl

Remember to edit the file addsignatures and change the READFROMDESC variable’s value to 1

Please note that letters not included in the English alphabet will be converted to the nearest English letter.
This is true for email address too.

Example:

Desirèé -> Desiree
pàé@domain.tld -> pae@domain.tld

So take care when you insert the field in users.txt

To see how to convert letters you can create a text file containing the names to be covered (for example a file called list.txt) then give the following command.

cat list.txt | iconv -f UTF-8 -t ASCII//TRANSLIT

As usuaI have no responsibility for the loss of data, blah, blah, blah…

Thanks, but problem is here “iconv -f UTF-8 -t ASCII//TRANSLIT” the string get cut on "special char"
call from console working fine but in script not…

Ideas ?

I don’t have “From:” headers with special chars.

If you have some samples let’s send to me (in PM If you want)

Thank you

for info UTF8 (it should be “G Š”)
From: =?UTF-8?Q?G_=C5=A0?= <administrator@…>

I put in a file called test.txt your FROM String:

test.txt
From: =?UTF-8?Q?G_=C5=A0?= <administrator@…>

then i create a script called test

test:
HEADERFROM=cat test.txt
echo $HEADERFROM
HEADERFROM=echo ${HEADERFROM} | /var/lib/nethserver/mail-disclaimers/scripts/decode.pl | iconv -f UTF-8 -t ASCII//TRANSLIT
echo $HEADERFROM

(Why this board doesn’t permit to write ALTGR+96 char? :thinking:)

cat test.txt and echo ${... .... ... ASCII/TRANSLIT strings are sourronded by ALTGR+96 char tha I can’t print here…

This is the output of the script

From: =?UTF-8?Q?G_=C5=A0?= <administrator@...>
From: G S <administrator@...>

I don’t see any error…

Š is replaced with S as expected

same here in console but not in addsignatures script…

this is my final addsignatures

.......
    FROMADDRESSUSER=`echo ${HEADERFROM} | perl /var/lib/nethserver/mail-disclaimers/scripts/decode.pl`
    if [[ $HEADERFROM =~ .*UTF-8.* ]]
    then
    FROMADDRESSUSER=`echo ${FROMADDRESSUSER} | cut -d "<" -f 1 | cut -c 7-1000`

    else
    FROMADDRESSUSER=`echo ${FROMADDRESSUSER} | cut -d "<" -f 1 | cut -c 7-1000`
    fi
.....

this is extractuser

......
do
SACCOUNT1=`echo ${SACCOUNT} | perl /var/lib/nethserver/mail-disclaimers/scripts/qp_decode.pl`
FROMADDRESSUSER=`echo ${FROMADDRESSUSER} | perl /var/lib/nethserver/mail-disclaimers/scripts/qp_decodeutf.pl`

	if [ "${SACCOUNT1}" == "${FROMADDRESSUSER}" ]
.......

this is qp_decode.pl

#!/usr/bin/perl
binmode STDOUT, ":utf8";
use Encode qw(encode decode);
 $decode = decode("WINDOWS-1250",<STDIN>);
 print $decode;

this is qp_decodeutf.pl

#!/usr/bin/perl
binmode STDOUT, ":utf8";
use Encode qw(encode decode);
 $decode = decode("UTF-8",<STDIN>);
 print $decode;

this is decode.pl

#!/usr/bin/perl
use Encode qw(encode decode);
 $decode = decode("MIME-Header",<STDIN>);
 print $decode;

working like this (decoded wrong but * IF * working)