This article is intended for software developers or those interested in the code behind GMass.
Over the weekend, we updated some of the software components that GMass is built on in preparation for a big feature launch, and in doing so, we updated MimeKit from version 1.12 to the latest release 1.18. That upgrade unfortunately broke some of our email address validation code, and many users saw a “token offset” error as a result.
Here’s what happened. Previously, in version 1.12, the following scenarios would pass without throwing an exception:
After updating to version 1.18, the top two of the three scenarios do throw an exception:
The impact on GMass is such that if you’re connecting to a Google Sheets spreadsheet, and your column containing email addresses has a bad data value that is an invalid email address, such as “firstname.lastname@example.org;email@example.com”, whereas before our code would handle this appropriately and eventually filter the bad entry out, now all of a sudden, our code was throwing an exception.
Making matters more complex was that the MimeKit TryParse didn’t always catch a string that could not be converted into a MimeKit.MailboxAddress object. For example:
In the above samples, TryParse returns false for “firstname.lastname@example.org;email@example.com” but returns true for “test<firstname.lastname@example.org>”. It returns true for the latter because it assumes that the part outside the angle brackets is the Name, and so Name=test and Addressemail@example.com. Our code though attempts to create a MailboxAddress object from the whole string, and in this case, the parse into Name and Address doesn’t happen, as the constructor assumes that the entire string represents just the Address portion of the object.
We did check the Release Notes for MimeKit before deploying the update, but there was nothing indicating the change in email parsing rules. Still however, we are eternally grateful to Jeffrey Stedfast for building and maintaining the MimeKit library for the .NET framework. Without it, my job as a software developer parsing and assembling email messages would be far more difficult.