Apply a signature to every mail sent from Nethserver

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)

You’re right

It’s very strange. it seems that something goes wrong between decode.pl and iconv in my script…

Someone has ideas?

GOT IT!

in addsignatures script add

export LANG=en_US.UTF-8

after

#!/bin/bash

line

Here’s a v0.12 (a bit tested)

https://drive.google.com/uc?export=download&id=1H3aRrdeekvp-6UFB-SVlc43Gba-re_ax

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

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

1 Like

I have one more thing in mind.

Create signature in client like (–SIGNATURE–)
And then replace this “TAG” with signature on server.
How to do it?

I don’t think it’s easy to do.

For what I’ve seen, each mail client generates the emails in a different way from each other, just see the headers, where I had to insert various controls because everyone does what they want.

Insert the code directly into the body becomes a big problem.

Thank you saitobenkei for your answer.
You did perfect job.

Im facing here with problem that users will love to have signature (how mail client does, answer,signature,reply part). not on the end of email.

Im willing to try insert signature into body… just cant find what where. Can you help me where should i look?

Thanks in advance

Ok, I have a new version to test.

It should works only on Nethserver NG 7.5 with “rspamd” and “maildisclaimer” modules activated

It should works with DKIM enabled too.

Before use it, it’s necessary to remove every trace of the previous versions!
Make a backup of your domain signature directory, you can use it later.

https://drive.google.com/uc?export=download&id=13IKuNR5qvIwS1cJ0hNcPK4Bg1Bas-1SK

Download the file from the link then

cd / 

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

mkdir -p /var/spool/addsignatures
chmod 775 /var/spool/addsignatures
chown root:mail /var/spool/addsignatures

chmod -R 775 /var/lib/nethserver/mail-disclaimers/addsignatures
chown -R root:mail /var/lib/nethserver/mail-disclaimers/addsignatures

signal-event nethserver-mail2-server-update

If you need to activate the debug:

mkdir /test
chmod 775 /test
chown root:mail /test

then change to 1 the value of SDEBUG variable in
/var/lib/nethserver/mail-disclaimers/addsignatures/scripts/addsignatures
script

In dashboard, remember to tick “Append a legal note to sent messages” in email -> domain -> yourdomain.tld

Please test it!

Some tests I made

Webclients on Nethserver NG:

  • Webtop 5 -> ok
  • Roundube -> ok

Windows:

  • Outlook 2010 -> ok
  • Thunderbird (v52.8.0) -> ok

Android:

  • Gmail -> altermime doesn’t apply signature
  • Samsung mail (very old version) -> altermime doesn’t apply signature
  • Aquamail -> ok
  • K9 mail -> ok

iOS

  • iOS mail -> ok
  • Spark -> ok

Clients that don’t work it because they create content email in base64. It seems that altermime doesn’t work at all (despite the parameters) with base64.

1 Like

WOOOOOW. You rock