0

I have a relay server on Exim. I need the full sender's name in the messages going through it to be changed. For example, it was 'Иванов Иван i.ivanon@domain.com' and it became 'Ivanov Ivan i.ivanon@domain.com'. How can it be done?

With the help of 'Exime rewrite' i can only change the email address

It should be done only for certain senders

Thank you

init0
  • 29
  • 4

2 Answers2

0

Exim Rewriting with w flag

It is possible to use exim to rewrite only the email address working part or the entire address including the RFC 2822 “phrase” (display name):

Sometimes there is a need to replace the whole address item, and this can be done by adding the flag letter “w” to a rule.

https://www.exim.org/exim-html-current/doc/html/spec_html/ch-address_rewriting.html#SECID155

The rewriting normally applies only to the working part of the address, and not the display name. Using the following with w and f flags should rewrite they way you're looking for (see other flags e.g. F to set envelope-from):

Example

begin rewrite

i.ivanon@domain.com    "\"Ivanov Ivan\" <i.ivanon@domain.com>"    wf

Test

Check result using exim -brw '"Иванов Иван" <i.ivanon@domain.com>'

0

You can remove or add headers in the smtp_data ACL. So let's suppose you have a mysql table somewhere, containing two columns, one for the original address, one for the replacement. In this case, you can use something like this (probably you'll want to modify it, but it's something to give you the idea):

warn condition=${if eq {1}{ \
                       ${lookup mysql {SELECT 1 FROM the_table WHERE \
                         original_column='${quote_mysql:${sg{$h_From:}{ *<.*>\$}{}}}' } \
                   } \
                   {yes}{no} \
               }
     add_header = From: ${lookup mysql {SELECT replacement_column FROM the_table WHERE \
                         original_column='${quote_mysql:${sg{$h_From:}{ *<.*>\$}{}}}' } ${sg{$h_From:}{.*(<[^>]+>)}{\$1}}
     remove_header = From:

Or, supposing you have a file /etc/exim4/fullnames.txt in which the substitutions reside (keep in mind, howewer, that this will sequentially read the file):

   warn condition=${if eq \
                {${lookup{${sg{$h_From:}{ *<.*>\$}{}}}lsearch{/etc/exim4/fullname.txt}}}\
                {}\
                {no}{yes}}
            add_header = From: ${lookup{${sg{$h_From:}{ *<.*>\$}{}}}lsearch{/etc/exim4/fullname.txt}} ${sg{$h_From:}{.*(<[^>]+>)}{\$1}}
            remove_header = From:

Note that you want to enclose the full names used as search keys in quotes, in order to escape the space between the family name and given name. So the file should look like this:

"Иванов Иван":Ivanov Ivan

Now, this approach is not the nicest one, but it should work. It adds a From: header (which will be the last header in the message), and removes a From: header (the first it encounters, which will be the original one). It does so only if the mysql table or the file contains a suitable replacement.

For the replacement, it assumes that the address is in the form of "Display name ", according to RFC2822 3.4. For the replacement, it cuts the <...> part, and for the new header, it puts it back from the original From: header.

More about lookups in exim: File and database lookups

Lacek
  • 6,585
  • 22
  • 28
  • Hi, thank you is it possible not to use a database? choose names for the replacement from file? – init0 May 25 '16 at 06:21
  • Yes, it is. I've edited the answer to contain an example of a file-based lookup. – Lacek May 25 '16 at 08:02
  • Do i get it right, i need just one single line to make it work? :) – init0 May 25 '16 at 12:57
  • You need at least two. One for adding a second From: header, and one for removing the original one. Also, usually you want to restrict the header replacement to some kind of condition, so you'll probably need three lines after all :) – Lacek May 25 '16 at 14:24
  • I got this configuration but i'm not sure whether it's correct, Exim has very complicated syntax %) Can ask you to help me correct mistakes that i've made? And i don't fully understand where exactly i should add that part of configuration My config http://pastebin.com/ZSUU4Yg1 – init0 May 27 '16 at 11:49
  • I've included the corrected config in the solution text. If you use a flat file, you have to use a different condition. Also, the solution I posted had some errors of bad escaping (oops), which is corrected. – Lacek May 27 '16 at 12:26
  • You've done a great job and i'm very grateful for it! I have just one stupid question - where exactly should i add that part of configuration? i tried adding it to different files of configuration, it doesn't work. My structure of files http://pastebin.com/hpUqEBNx Once again, thanks a lot! – init0 May 27 '16 at 12:53
  • The `main/0000-localmacros` file should contain an option called `CHECK_DATA_LOCAL_ACL_FILE` (if it doesn't, edit the file, adding this option). It should point to a file, which should contain the `warn` snippet. Reconfigure exim after making the changes (e.g. on a Debian system, sun `dpkg-reconfigure exim4-config`) – Lacek May 27 '16 at 13:18
  • I added config in main/000_localmacros and run `dpkg-reconfigure exim4-config`, but still not working :( sreenshot http://joxi.ru/gmvR389uxDzPZm this is a my test server, no MySQL on production server :) – init0 May 27 '16 at 13:46
  • Actual screenshot http://joxi.ru/vAWD4XpskZDdJr – init0 May 27 '16 at 13:56
  • You should define a `CHECK_DATA_LOCAL_ACL_FILE` macro in order to make it work. See the "how to enable this rule" part of an [other answer](http://serverfault.com/questions/770269/minimal-exim-router-which-simply-adds-custom-header). Also, you should check out the (http://www.exim.org/exim-html-current/doc/html/spec_html/index.html)[exim documentation], it is quite good, although maybe a little too "technical". – Lacek May 27 '16 at 14:59