Mailing List Archive

rewrite incorrect date headers from email clients
How I do to rewrite the date header from email clients in exim4 config
so it are replaced with the server date/time?

The problem is that some clients and software are submitting an
incorrect date header (like 1 jan 1960) causing the email to be
delivered to the bottom of user's clients and sometimes sorted as spam
due to the incorrect date.

So I would want to replace the incorrect header with an correct one
fetched from the server time.
How can this be accomplished?

--
## List details at https://lists.exim.org/mailman/listinfo/exim-users
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/
Re: rewrite incorrect date headers from email clients [ In reply to ]
On 26/05/18 20:52, Sebastian Nielsen via Exim-users wrote:
> How I do to rewrite the date header from email clients in exim4 config
> so it are replaced with the server date/time?
>
> The problem is that some clients and software are submitting an
> incorrect date header (like 1 jan 1960) causing the email to be
> delivered to the bottom of user's clients and sometimes sorted as spam
> due to the incorrect date.
>
> So I would want to replace the incorrect header with an correct one
> fetched from the server time.
> How can this be accomplished?
>

Your main problem will be deciding when to do this.
Date/time formats are notoriously fluid.

However, once you've made that decision, remove-header
and add-header operations are available in ACLs. Look in
the ACL chapter in the manual. Obviously for the add
you will need to construct something; look at the
string-expansions chapter.
--
Cheers,
Jeremy

--
## List details at https://lists.exim.org/mailman/listinfo/exim-users
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/
Re: rewrite incorrect date headers from email clients [ In reply to ]
On Sat, May 26, 2018 at 09:52:28PM +0200, Sebastian Nielsen via Exim-users wrote:
> How I do to rewrite the date header from email clients in exim4 config
> so it are replaced with the server date/time?
>
> The problem is that some clients and software are submitting an
> incorrect date header (like 1 jan 1960) causing the email to be
> delivered to the bottom of user's clients and sometimes sorted as spam
> due to the incorrect date.
>
> So I would want to replace the incorrect header with an correct one
> fetched from the server time.
> How can this be accomplished?

1. It's not clear how you would decide that date header is incorrect.
Which creteria would be used for such decision?

2. Header rewriting means delivery of wrong (false) information to
recipient, that is a Bad Thing. If you want to deliver a mail with
"correct date", you have better to make a special mail message
for user and attach a copy of the original mail to it.

3. Alternative approach is to reject mails with incorrect date header.
There is no problem to write ACL which check, for example, presence
of current year in date header, as "2018" substring. Do not forget
to reject with some informative message for sender, say, "This message
was rejected because it has invalid date header "$h_date:"".
--
Eugene Berdnikov

--
## List details at https://lists.exim.org/mailman/listinfo/exim-users
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/
Re: rewrite incorrect date headers from email clients [ In reply to ]
1: By simply dropping the date header and inserting a new with the
server time. Problem solved. If the header was correct, it will still
be correct when replaced.
2: Yeah, but many clients handle date: header astonishly bad too. For
example sorting the email by date: header instead of actual received
date, which messes up sorting if the date: header in mail is just a
few hours or Days off. So fixing the date: header is a good thing,
both when sending and receiving emails. Makes every client happy. And
if there is doubt about the email's actual transmit date, its easy to
check in the headers anyways and use the Received: lines to find out
if any delay happened.
3: naah.

So I solved it with a ACL similiar to this:

accept
condition = ${if def:h_date:{yes}{no}}
remove_header = date
add_header = Date: $tod_full
accept
add_header = Date: $tod_full

The first one deletes any old date header and inserts a new date
header with the server time.
The second one just inserts a date header if the original mail misses one.

2018-05-27 0:09 GMT+02:00 Evgeniy Berdnikov via Exim-users
<exim-users@exim.org>:
> On Sat, May 26, 2018 at 09:52:28PM +0200, Sebastian Nielsen via Exim-users wrote:
>> How I do to rewrite the date header from email clients in exim4 config
>> so it are replaced with the server date/time?
>>
>> The problem is that some clients and software are submitting an
>> incorrect date header (like 1 jan 1960) causing the email to be
>> delivered to the bottom of user's clients and sometimes sorted as spam
>> due to the incorrect date.
>>
>> So I would want to replace the incorrect header with an correct one
>> fetched from the server time.
>> How can this be accomplished?
>
> 1. It's not clear how you would decide that date header is incorrect.
> Which creteria would be used for such decision?
>
> 2. Header rewriting means delivery of wrong (false) information to
> recipient, that is a Bad Thing. If you want to deliver a mail with
> "correct date", you have better to make a special mail message
> for user and attach a copy of the original mail to it.
>
> 3. Alternative approach is to reject mails with incorrect date header.
> There is no problem to write ACL which check, for example, presence
> of current year in date header, as "2018" substring. Do not forget
> to reject with some informative message for sender, say, "This message
> was rejected because it has invalid date header "$h_date:"".
> --
> Eugene Berdnikov
>
> --
> ## List details at https://lists.exim.org/mailman/listinfo/exim-users
> ## Exim details at http://www.exim.org/
> ## Please use the Wiki with this list - http://wiki.exim.org/

--
## List details at https://lists.exim.org/mailman/listinfo/exim-users
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/
Re: rewrite incorrect date headers from email clients [ In reply to ]
On Sun, May 27, 2018 at 01:12:14AM +0200, Sebastian Nielsen wrote:
> 2: Yeah, but many clients handle date: header astonishly bad too. For
> example sorting the email by date: header instead of actual received
> date, which messes up sorting if the date: header in mail is just a
> few hours or Days off. So fixing the date: header is a good thing,

If user does not want this behaviour, just configure other sorting
method in his client.

If you change date header then you are delivering something different from
the original message, i.e. FALSE information, without any notification
to user. I think it's completely inacceptable.

> The second one just inserts a date header if the original mail misses one.

Exim inserts date header automatically unless "suppress_local_fixups"
is set to true.
--
Eugene Berdnikov

--
## List details at https://lists.exim.org/mailman/listinfo/exim-users
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/
Re: rewrite incorrect date headers from email clients [ In reply to ]
On 26 May 2018, at 16:14, Jeremy Harris via Exim-users wrote:

> Your main problem will be deciding when to do this.
> Date/time formats are notoriously fluid.

Thankfully, this should not be a problem in identifying bad date
headers, since the *correct* format for a date header in mail is very
narrowly defined.

--
## List details at https://lists.exim.org/mailman/listinfo/exim-users
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/