Sunday, January 17, 2010

el talta tabta

Finally, after installing Ubuntu and Thunderbird for the third time, it finally worked as it should.
So I tried the code I did for the user interface of the mini-project, and I t also worked. This made me excited to work on the final project bug and the mailto bug also. I started with the mailto bug just to be sure that it really worked :D.

I 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.

After testing I found out that the code had an error

(inString.CharAt(inString.Length()-1) != '.')

The letter ‘L’ in the method Length was in lower case and it should be in upper case.

So this is my final 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;
}
}

After testing it I worked :), I also tested it for common errors, afterwards I created a dummy bug and attached my patch to it. Finally I requested a review from Dr. Fatma.



As with the Final project bug, it was about checking all mail address in each one of the address fields (to, cc, bcc) before sending a mail.

In case we write invalid mail address (say, invalidmailaddress) in To/Cc/Bcc etc field, we'll see error dialog saying:

invalidmailaddress is not a valid e-mail address because it is not of
the form user@host. You must correct it before sending the e-mail.

But if we input at least one valid mail address, other fields will not be checked and thunderbird will send to the invalid mail address.
These are the examples of the normal and invalid behaviors:






* found the command that checks for each field (to, cc, bcc)
* edited the code so that it checks for all the emails in each field using the split method and for-loops.

function CheckValidEmailAddress(to, cc, bcc)
{
var invalidStr = null;
var i=0;
var j=0;
var k=0;
var arraybcc= bcc.split(",");
var arraycc= cc.split(",");
var arrayto= to.split(",");
if (arraybcc!=null)
{
for (k=0;k {
if (arraybcc[k].length > 0 && (arraybcc[k].indexOf("@") <= 0 ||
arraybcc[k].indexOf("@") == arraybcc[k].length - 1))
invalidStr = arraybcc[k];
}
}
if (arraycc!=null)
{
for (j=0;j {
if (arraycc[j].length > 0 && (arraycc[j].indexOf("@") <= 0 ||
arraycc[j].indexOf("@") == arraycc[j].length - 1))
invalidStr = arraycc[j];
}
}
if (arrayto!=null)
{
for (i=0;i {
if (arrayto[i].length > 0 && (arrayto[i].indexOf("@") <= 0 ||
arrayto[i].indexOf("@") == arrayto[i].length - 1))
invalidStr = arrayto[i];
}
}
if (invalidStr)
{
var bundle = document.getElementById("bundle_composeMsgs");
if (gPromptService)
gPromptService.alert(window, bundle.getString("addressInvalidTitle"),
bundle.getFormattedString("addressInvalid",
[invalidStr], 1));
return false;
}
return true;
}

* tested the code using the Thunderbird build.
* the compose window stopped working when I try to send any email.
* after testing the code [http://writecodeonline.com/javascript/ here] if found out that the error was caused because the method is passed null for each empty field.
* edited the code to avoided null exceptions.

function CheckValidEmailAddress(to, cc, bcc)
{
var invalidStr = null;
var i=0;
var j=0;
var k=0;
if (bcc!=null)
{
var arraybcc= bcc.split(",");
for (k=0;k {
if (arraybcc[k].length > 0 && (arraybcc[k].indexOf("@") <= 0 ||
arraybcc[k].indexOf("@") == arraybcc[k].length - 1))
invalidStr = arraybcc[k];
}
}
if (cc!=null)
{
var arraycc= cc.split(",");
for (j=0;j {
if (arraycc[j].length > 0 && (arraycc[j].indexOf("@") <= 0 ||
arraycc[j].indexOf("@") == arraycc[j].length - 1))
invalidStr = arraycc[j];
}
}
if (to!=null)
{
var arrayto= to.split(",");
for (i=0;i {
if (arrayto[i].length > 0 && (arrayto[i].indexOf("@") <= 0 ||
arrayto[i].indexOf("@") == arrayto[i].length - 1))
invalidStr = arrayto[i];
}
}
if (invalidStr)
{
var bundle = document.getElementById("bundle_composeMsgs");
if (gPromptService)
gPromptService.alert(window, bundle.getString("addressInvalidTitle"),
bundle.getFormattedString("addressInvalid",
[invalidStr], 1));
return false;
}
return true;
}

* tested the code again. (worked)
* created the patch.
* tested the patch for common errors [http://beaufour.dk/jst-review/ here].
* submitted the patch.
* bug fixed.