Bug 737688 - nsMailboxUrl should treat fetch-part URLs as "eDisplay"; r=bienvenu
authorJim Porter <squibblyflabbetydoo@gmail.com>
Sun, 08 Apr 2012 21:00:02 -0500
changeset 11582 104c0b09c8332361292083ba2434d2f20d76bafd
parent 11581 abbe21c88c1aa64976bc16a69a3d476c6c2f448d
child 11583 f5d3b855f29010c766f490b37dcace9fe19bfee0
push id529
push userbugzilla@standard8.plus.com
push dateMon, 04 Jun 2012 19:55:55 +0000
treeherdercomm-beta@109334822255 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbienvenu
bugs737688
Bug 737688 - nsMailboxUrl should treat fetch-part URLs as "eDisplay"; r=bienvenu
mail/test/mozmill/message-header/evil-attached.eml
mail/test/mozmill/message-header/test-phishing-bar.js
mailnews/local/src/nsMailboxService.cpp
mailnews/local/src/nsMailboxUrl.cpp
new file mode 100644
--- /dev/null
+++ b/mail/test/mozmill/message-header/evil-attached.eml
@@ -0,0 +1,22 @@
+Date: Mon, 10 Jan 2011 12:00:00 -0500
+From: phisher@evil.com
+To: user@example.com
+Subject: Please look at this attachment!
+Content-Type: multipart/mixed; boundary="BOUNDARY"
+
+This is a multi-part message in MIME format.
+--BOUNDARY
+Content-Type: text/html
+
+See below.
+--BOUNDARY
+Content-Type: message/rfc822
+
+Date: Mon, 10 Jan 2011 12:00:00 -0500
+From: phisher@evil.com
+To: user@example.com
+Subject: Please click on this link!
+Content-Type: text/html
+
+<a href="http://www.evil.com/google">http://www.google.com</a>
+--BOUNDARY--
--- a/mail/test/mozmill/message-header/test-phishing-bar.js
+++ b/mail/test/mozmill/message-header/test-phishing-bar.js
@@ -31,17 +31,17 @@
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 /*
- *  Test for the most suitable identity in From address for reply-to-list
+ *  Test that the phishing bar behaves properly
  */
 
 var MODULE_NAME = "test-phishing-bar";
 
 var RELATIVE_ROOT = "../shared-modules";
 var MODULE_REQUIRES = ["folder-display-helpers",
                        "window-helpers"];
 
@@ -61,24 +61,37 @@ function setupModule(module) {
   folder = create_folder("PhishingBarA");
   add_message_to_folder(folder, create_message({body: {
     body: '<a href="http://www.evil.com/google/">http://www.google.com</a>',
     contentType: "text/html"
   }}));
 }
 
 /**
+ * Make sure that the phishing bar is currently visible.
+ *
+ * @param msgc the Mozmill controller for the message window
+ */
+function assert_phishing_bar_visible(msgc) {
+  assert_true(!msgc.e("msgNotificationBar").collapsed,
+              "Notification bar is collapsed!");
+  assert_equals(msgc.e("msgNotificationBar").selectedPanel,
+                msgc.e("phishingBar"),
+                "Notification bar not showing phishing bar!");
+}
+
+/**
  * Make sure that the phishing bar gets hidden when the ignore button is
  * clicked.
  *
  * @param msgc the Mozmill controller for the message window
  */
 function help_test_hide_phishing_bar(msgc) {
   let phishingButton = msgc.e("phishingBar").getElementsByTagName("button")[0];
-  assert_true(!msgc.e("msgNotificationBar").collapsed);
+  assert_phishing_bar_visible(msgc);
 
   msgc.click(new elib.Elem(phishingButton));
   wait_for_message_display_completion(msgc, true);
   assert_true(msgc.e("msgNotificationBar").collapsed);
 }
 
 function test_hide_phishing_bar_from_message() {
   be_in_folder(folder);
@@ -93,8 +106,30 @@ function test_hide_phishing_bar_from_eml
   /*
   let thisFilePath = os.getFileForPath(__file__);
   let file = os.getFileForPath(os.abspath("./evil.eml", thisFilePath));
 
   let msgc = open_message_from_file(file);
   help_test_hide_phishing_bar(msgc);
   */
 }
+
+function test_phishing_bar_for_eml_attachment() {
+  let thisFilePath = os.getFileForPath(__file__);
+  let file = os.getFileForPath(os.abspath("./evil-attached.eml", thisFilePath));
+
+  let msgc = open_message_from_file(file);
+
+  // Make sure the root message shows the phishing bar.
+  assert_phishing_bar_visible(msgc);
+
+  // Open the attached message.
+  plan_for_new_window("mail:messageWindow");
+  msgc.e("attachmentList").getItemAtIndex(0).attachment.open();
+  let msg2c = wait_for_new_window("mail:messageWindow");
+  wait_for_message_display_completion(msg2c, true);
+
+  // Now make sure the attached message shows the phishing bar.
+  assert_phishing_bar_visible(msg2c);
+
+  close_window(msg2c);
+  close_window(msgc);
+}
--- a/mailnews/local/src/nsMailboxService.cpp
+++ b/mailnews/local/src/nsMailboxService.cpp
@@ -377,20 +377,16 @@ NS_IMETHODIMP nsMailboxService::OpenAtta
   nsCAutoString urlString(aUrl);
   urlString += "&type=";
   urlString += aContentType;
   urlString += "&filename=";
   urlString += aFileName;
   CreateStartupUrl(urlString.get(), getter_AddRefs(URL));
   nsresult rv;
 
-  nsCOMPtr<nsIMsgMailNewsUrl> mailboxUrl(do_QueryInterface(URL, &rv));
-  if (NS_SUCCEEDED(rv) && mailboxUrl)
-    mailboxUrl->SetMsgWindow(aMsgWindow);
-
   // try to run the url in the docshell...
   nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(aDisplayConsumer, &rv));
   // if we were given a docShell, run the url in the docshell..otherwise just run it normally.
   if (NS_SUCCEEDED(rv) && docShell)
   {
     nsCOMPtr<nsIDocShellLoadInfo> loadInfo;
     // DIRTY LITTLE HACK --> since we are opening an attachment we want the docshell to
     // treat this load as if it were a user click event. Then the dispatching stuff will be much
--- a/mailnews/local/src/nsMailboxUrl.cpp
+++ b/mailnews/local/src/nsMailboxUrl.cpp
@@ -228,17 +228,16 @@ nsresult nsMailboxUrl::GetMsgHdrForKey(n
     else
     {
       nsCOMPtr<nsIMsgWindow> msgWindow(do_QueryReferent(m_msgWindowWeak));
       if (!msgWindow)
       {
         nsCOMPtr<nsIMsgMailSession> mailSession = do_GetService(NS_MSGMAILSESSION_CONTRACTID, &rv);
         NS_ENSURE_SUCCESS(rv, rv);
         mailSession->GetTopmostMsgWindow(getter_AddRefs(msgWindow));
-        SetMsgWindow(msgWindow);
       }
 
       // maybe this is .eml file we're trying to read. See if we can get a header from the header sink.
       if (msgWindow)
       {
         nsCOMPtr<nsIMsgHeaderSink> headerSink;
         msgWindow->GetMsgHeaderSink(getter_AddRefs(headerSink));
         if (headerSink)
@@ -317,17 +316,18 @@ NS_IMETHODIMP nsMailboxUrl::IsUrlType(PR
   {
     case nsIMsgMailNewsUrl::eCopy:
       *isType = (m_mailboxAction == nsIMailboxUrl::ActionCopyMessage);
       break;
     case nsIMsgMailNewsUrl::eMove:
       *isType = (m_mailboxAction == nsIMailboxUrl::ActionMoveMessage);
       break;
     case nsIMsgMailNewsUrl::eDisplay:
-      *isType = (m_mailboxAction == nsIMailboxUrl::ActionFetchMessage);
+      *isType = (m_mailboxAction == nsIMailboxUrl::ActionFetchMessage ||
+                 m_mailboxAction == nsIMailboxUrl::ActionFetchPart);
       break;
     default:
       *isType = false;
   };
 
   return NS_OK;
 
 }