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.

1 comment: