Copy-to-sent bug finally fixed after two years!

From Organic Design wiki
Posted by Nad on 21 December 2024 at 17:16
This post has the following tags : Server


A couple of years ago I configured the server to do the process of copying user's sent emails into the "Sent" mail folder on the server-side rather than the client having to do it since that effectively involves sending the whole message to the server twice. Not only does it have to be sent twice, but for some reason the Thunderbird email client tends to lock up during the copying to sent process for some reason. So I created this addition to our email configuration procedure which gets the server to do the job instead.

But there's one complication. The message that's copied doesn't have the Bcc header as it's been stripped by the time the message gets to the stage of being copied. It's very important that the messages in the "Sent" folder have their Bcc header because you want to know who the message was sent to, and you may also want to modify and re-send the message again.

So the Exim system-filter that copies the message also calls this copy-to-sent.pl Perl script which finds the message that was just copied to the "Sent" folder and then re-builds its Bcc header by getting all the recipients from the Exim $recipients variable and removing the ones found in the To or Cc headers of the message.

The only problem is that it hasn't worked properly ever since it was made two years ago! It's always added the Bcc header even if there wasn't one and put all the recipients in there including those from the To and Cc headers. I finally got around to adding detailed logging into the script so I could track down the problem - which turned out to be nothing more than a "+" symbol needing to be added into the regular expressions that extract the email addresses from the To and Cc headers.