Sunday, November 8, 2009

Fixing the Thunderbird bug

The first step in fixing the bug is finding it in the source code, in my approach I used MXR (Cross-Reference), and you have to cleverly choose the very specific keywords used for searching, because the source code isn’t small. I used "mailto" as my searching keyword, the code related to the bug was in the mozTXTToHTMLConv.cpp file between lines 194 to 204.

if (aInString[pos] == '@')
{
// only pre-pend a mailto url if the string contains a .domain in it..
//i.e. we want to linkify johndoe@foo.com but not "let's meet @8pm"
nsDependentString inString(aInString, aInLength);
if (inString.FindChar('.', pos) != kNotFound) // if we have a '.' after the @ sign....
{
aOutString.AssignLiteral("mailto:");
aOutString += aInString;
}
}

This part of the code just checks if there is an '.' after the '@' sign and ignores a lot of other invalid cases of an email address.

Invalid Addresses
a@.
a@..
a@..f
a@....f
@.
@.com
@a.com
@a
@a.
@a..
@a...com
a@a.a..a

So we must add more conditions to the if-statement in line 199, the first one is to check if we have a '.' right after the '@', the second condition is to check if we have more than one consecutive '.' after the '@' sign, the third condition is to check if the address ends with '.', finally we must check if the address starts with the '@' sign.
So this is my modified code:

if (aInString[pos] == '@')
{
nsDependentString inString(aInString, aInLength);
if ( (inString.FindChar('.', pos) != kNotFound) &&
(inString.CharAt(pos+1) != '.') &&
(inString.Find("..", pos) == kNotFound) &&
(inString.CharAt(inString.length()-1) != '.')&&
(pos!=0))
{
aOutString.AssignLiteral("mailto:");
aOutString += aInString;
}
}


Unfortunately I didn’t test or patch it :( for a well known reason :D, so can some one test it for me ??

No comments:

Post a Comment