Addresses are converted to lowercase

Swift Mailer is a fantastic library for sending email with php. Discuss this library or ask any questions about it here.

Moderators: Chris Corbyn, General Moderators

Post Reply
vanchuck
Forum Newbie
Posts: 6
Joined: Fri Apr 20, 2007 3:56 pm
Location: Vancouver, BC, Canada

Addresses are converted to lowercase

Post by vanchuck »

Hi there, first off:

Swift Mailer Version 3.3.2
PHP 5.2.0

I ran into a problem today with an email address that had mixed-case in the local-part (to the left of the @). The problem was actually caused by my custom Decorator class, because it was indexing the substitutions with the email address, which had mixed-case. But the Swift_RecipientList object's addresses is indexed by an address that has been passed through strtolower(). Therefore the two indexes didn't match up. No big deal though, that was easy to fix. I just put a strtolower() in my Decorator code so it'd match up.

But, then I sent out the email to this troublesome recipient and it got bounced back. joe.smith@pickyserver.com did not work. But Joe.Smith@pickyserver.com DID! This email server is for a large government-operated utility, so it's not some random hackish email server. Apparently some email servers DO care about case, since it IS just a local account name.

RFC2822 (Internet Message Format) includes no specifications about case sensitivity.
RFC821 (SMTP) seems to implies mixed-case local-parts should be allowed:
Commands and replies are not case sensitive. That is, a command or
reply word may be upper case, lower case, or any mixture of upper and
lower case. Note that this is not true of mailbox user names. For
some hosts the user name is case sensitive, and SMTP implementations
must take care to preserve the case of user names as they appear in
mailbox arguments. Host names are not case sensitive.
Luckily the fix for this is quite easy. Simply remove all the calls to strtolower() from lib/Swift/RecipientList.php

I've made this change in my version, and all works fine. I'd recommend this make it to the next version as well. Or perhaps you'd prefer to just strtolower() the domain/host name and leave the local-part untouched.

Cheers,
Dave
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: Addresses are converted to lowercase

Post by Chris Corbyn »

The way addresses are stored in v4 is a little differently. They're indexed by lowercase address name, but that's not what actually gets used. The reason the lowercasing was added was because some people were having issues with duplicate emails being accepted by swift, although with hindsight it would have been more appropriate to fix that outside of Swift rather than in it's innards.

Thanks for the pointer. Interestingly, RFC 2822 (email) doesn't mention anything to do with the casing in the address... maybe RFC 2821 (smtp) mentions this.
Post Reply