Domanda

I have a webmail system and for some time now have noticed that emails originating from a few servers come with an extra line break in the headers.

First was with the occasional Dmarc report from Google. About one a week. Then other automated emails from Bluebottle. Other occasional come from various senders.

The extra line in the one from Google and Bluebottle it is always in the same place. For the rest it's not. That is the problem. I can run a nice regex to fix the ones that come in the same place but for the others I wouldn't like to tempt faith and cause more harm then good.

I have noticed major providers usually just don't bother with this, but I'd like to bother.

I have built this regex: (\r[a-z-]*:.*)+(\r\r)+([a-z-]*:.*\r)+ So far it seems to work, but I feel a bit concerned it might cause me problems.

Since regular expressions this broad are not recommended I would like some opinions if anyone has encountered this issue.

È stato utile?

Soluzione

After a month of testing.

This appears to work quite well without issues so far.

$data = preg_replace("/(\r\n)([a-z-]*)(:)(.*)(\r\n)(\r\n)([a-z-]*):(.*)(\r\n)/i", "$1$2$3$4$6$7$8$9", $data);
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top