Saturday, 26 December 2009

The Final Bugzination! Final Release! Et3alemooha ba2a ya Mina!

I just submitted the patch for the thing i donez, i dont really think i did it correctly thought, bass eshta ba2a.. maleesh da3wa ya3ni ana khallasto ba2a.. homma 3ayzeen yestafado be shoghly.. kana beha... mesh 3ayzeen.. wallahi ya3ni...

The difference between the final release and 0.2 is the following:
- user can choose the forwarding headers he wants to include in the mails he forwards, and furthermore, the user can choose to automatically remove all original headers independent of the headers he is using at the moment. The screenshot shall explain more:


How Do ZAT?

(i added the 'forward headers' dropdown and the 'remove existing ...' checkbox, in case you are wondering what's new about this window.)

I Tell you nao!

First you need to add a "preference", which is passed on somehow to the preferences window and can be called to hold certain values for the properties.

A preference is added in the following way:

< id="mail.forward_message_header" name="mail.forward_message_header" type="int">"

< id="mail.forward_remove_headers" name="mail.forward_remove_headers" type="bool">"

The first one is the preference for the dropdown and the second one for the checkbox. I added these two lines to the compose.xul file located under comm-central/mail/components/preferences. Under the last folder you will find .xul files for most of the GUI components like, display.xul, general.xul, which are both tabs in the preferences windows, and so on.

Then, you add the actual box, that is displayed in the preferences window:

< align="center">
< value="&forwardHdr.label;" accesskey="forwardHdr.accesskey;" control="forwardMessageHeader">
< id="forwardMessageHeader" preference="mail.forward_message_header">
<>
< value="3" label="&noHeaders.label;">
< value="0" label="&minHeaders.label;">
< value="1" label="&normHeaders.label;">
< value="2" label="&maxHeaders.label;">

< /menulist>
< id="removeHeaders" label="&removeHeaders.label;" preference="mail.forward_remove_headers" accesskey="&removeHeaders.accesskey;">
< /hbox>

I will explain the labels and accesskeys later although they are really simple, so if you dont understand much from the previous "code" start by ignoring anything, that has label or accesskey.
The preference attribute for menulist just says which preference is controlled by this dropdown menu, and in this case it's the forward headers preference mentioned previously. Then we have some menuitems also with labels.
And next a checkbox which represents the checkbox we have and it is binded to the preference remove headers.

Labels and accesskeys are simple the label of each item or menu, so for example
< label="&removeHeaders.label;"> means that the checkbox has the label of the value inside the variabel removeHeaders. The accesskey defines which hotkey gets you to this menuitem, checkbox, ... . As an example take a look at the previous image, you will see that the 'h' in forward headers is underlined: this means, that its accesskey is 'h', and the label for the whole menu is "forward headers".

I dont know why something like: label="forward headers" is not used, but in all the source code i checked this way was applied.

The labels and accesskeys are all stored in two files:

1.comm-central/mail/locales/en-US/chrome/messenger/preferences/compose.dtd
2.comm-central/suite/locales/en_US/chrome/mailnews/pref/pref-composing-messages.dtd

That is where i added all the labels in the following way:

< !ENTITY forwardHdr.label "Forward headers:">
< !ENTITY noHeaders.label "No Headers">
< !ENTITY minHeaders.label "Minimum Headers">
< !ENTITY normHeaders.label "Normal Headers">
< !ENTITY maxHeaders.label "All Headers">
< !ENTITY removeHeaders.label "Remove existing headers from message">
< !ENTITY removeHeaders.accesskey "X">

That is basically it. The last thing having variables in your actual code, that take the value of the preferences:

(the following code is from mimedraft.cpp)

PRInt32 show_headers;
prefBranch->GetIntPref("mail.forward_message_header", &show_headers);

PRBool removeHeaders = PR_FALSE;
prefBranch->GetBoolPref("mail.forward_remove_headers", &removeHeaders);

This means that show_headers takes the value of the preferences "mail.forward_message_header" and the bool removeHeaders takes the value of "mail.forward_remove_headers".

The design has been changed a bit to be able to use the "remove original headers" function without having to be in anonymous forwarding mode:

if(removeHeaders)
mime_remove_headers(body, headers, composeFormat, mailcharset);

Which means that if the checkbox is ticked, then the function mime_remove_headers is called, and all the headers from the body are removed, then we move on to inserting the headers:

switch (show_headers)
{
case 0:
mime_insert_micro_headers(body, headers, composeFormat, mailcharset);
break;
case 1:
mime_insert_normal_headers(body, headers, composeFormat, mailcharset);
break;
case 2:
mime_insert_all_headers(body, headers, composeFormat, mailcharset);
break;
case 3:
mime_insert_no_headers(body, headers, composeFormat, mailcharset);
break;
}

in case 0 - 2 some headers are inserted (i crtd none of those functions) and in case 3 my function "mime_insert_no_headers" is called, which i changed to the same state it was in in Bug Release 0.1, which is being an empty function.

I am done bugging!

Monday, 21 December 2009

BUGZ BUNNI 0.2

First, I must apologize for the title. And the next coming one, because you think this one is bad? Wait for the final one.

As mentioned in the post "Bug fix Me 0.1" my bug was about forwarding emails and removing the headers.

What I had done in release 0.1 was, simply not inserting any headers for newly created messages, old headers though remained the same.

In release 0.2 we simply remove existing headers. This is done by traversing the body, which saved in a single string, and remove the headers once we find one.

Of course this approach has a flaw, which is removing regular text (not a header) that has a similar format to the header format.



This picture is just awesum by the way. I dont know who the person in the picture is, but I search google images for the word "n00b" and it was the first picture in the results (of course without mozmoz).

Sunday, 13 December 2009

Bug Fix Me 0.1

OK, so I think I just finished release 0.1 for the first bug. It wasn't that hard. NOT! As for the coding you end up changing two lines or something, but the whole work is to actually find these two lines in the omareldeebillion lines of code of the TB source code.

When forwarding you would want to have the choice to include no headers at all. I picked this bug because personally, this is something that really bugs me (WOAH! No pun intended te-he). Having to remove all the headers from the message and so on... So, what I did is giving the ability to forward a message just as is, without having any annoying headers.

The solution or the actual code to have no headers is not as interesting as what I had to go through to get to that, so, I am going to share that with you rather than just the solution. Also, because the solution might look funniiiiiiiii xD (remember, that this is only the first release in a way).

Steps:

1., when forwarding a message, this is intuitively considered composing a new message, even though its not really a “new” message, but still → composing. Which should be – again intuitively – found under mailnews/compose/src/ and then under that I found the c++ file nsMsgCompose.cpp, which looks like a file, that might be useful to me considering my bug.

Link to nsMsgCompose.cpp:

http://mxr.mozilla.org/comm-central/source/mailnews/compose/src/nsMsgCompose.cpp

Searching this file for “forward” got me to the following few lines of code:

1567 nsresult nsMsgCompose::CreateMessage(const char * originalMsgURI, 1568                                      MSG_ComposeType type, 1569                                      nsIMsgCompFields * compFields) 1570 {

1705   // If we are forwarding inline, mime did already setup the compose fields therefore we should stop now

2100 }

which led me to the mime files.

2., Searching mxr for forward under mailnews/mime/src led to the file mimedrft.cpp, where the forward messages are created.

Link to mimedrft.cpp:

http://mxr.mozilla.org/comm-central/source/mailnews/mime/src/mimedrft.cpp

1138 mime_insert_forwarded_message_headers(char            **body, 1139                                       MimeHeaders     *headers, 1140                                       MSG_ComposeFormat composeFormat, 1141                                       char            *mailcharset) 1142 {  ...  1152  1153   switch (show_headers) 1154   { 1155   case 0: 1156     mime_insert_micro_headers(body, headers, composeFormat, mailcharset); 1157     break; 1158   default: 1159   case 1: 1160     mime_insert_normal_headers(body, headers, composeFormat, mailcharset); 1161     break; 1162   case 2: 1163     mime_insert_all_headers(body, headers, composeFormat, mailcharset); 1164     break; 1165   } 1166 } 

led The functions micro_headers, normal_headers and all_headers are the ones responsible for inserting headers into the forwarded message. But as you can notice this does not really work since the “default:” is put at line 1158 before the other cases, and – what can't be seen here - show_headers is initialized to 0, which means that only “mime_insert_micro_headers” is called anyways.

So, the two changes done to this code are:

  1. moving the “default:” to the end of the switch

  2. creating the function static void mime_insert_no_header() and adding it to the switch with “case 3:”

As for the function I created if you are looking for something really impressive now check out any of the following links:

http://www.youtube.com/watch?v=FFnLuqP0LfU

http://www.youtube.com/watch?v=A_hlVrFHE_A&feature=related

http://www.youtube.com/watch?v=yFl-WQAXMto&NR=1&feature=fvwp

http://www.youtube.com/watch?v=pjuoIeXFivw

http://www.youtube.com/watch?v=XnvbyXsbSs8

My function is not in any way impressive as the previous links, it is just an empty function, YES an empty function:

static void

mime_insert_no_headers()

{

}

while setting the show_headers integer to 3.

A more generic way to do this – this part could actually go under help needed under the bug wiki (when I create it te-he) – is to have a drop down menu on the forward stating whether you want to forward the email with minimal, normal, all or no headers, which then sets the show_headers to 0, 1, 2 or 3 accordingly.

An even MOAR generic approach is to be able to set from the preferences which headers you want in your forwarded emails. All the headers are:

Return-Path,

Received,

Message-ID,

Date,

From,

User-Agent,

MIME-Version,

To,

Subject,

Content-Type,

Content-Transfer-Encoding.