Bug 581940 - Do not truncate filename of dragged messages if subject contains '&' and handle empty or too long subject. r=mkmelin, ui-r=Josiah
authoraceman <acelists@atlas.sk>
Mon, 07 Apr 2014 09:07:25 -0400
changeset 15987 15c1bea389b211d04dbed2edcf5132d710693aad
parent 15986 82de126cc39026d221fa10714866d20430c86c83
child 15988 fce1dc971d43e3318bce1b89d839a4fc16f8c0f7
push id10015
push userryanvm@gmail.com
push dateMon, 07 Apr 2014 13:10:16 +0000
treeherdercomm-central@e16ffc0bb97c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmkmelin, Josiah
bugs581940
Bug 581940 - Do not truncate filename of dragged messages if subject contains '&' and handle empty or too long subject. r=mkmelin, ui-r=Josiah
mail/base/content/msgMail3PaneWindow.js
mail/locales/en-US/chrome/messenger/messenger.properties
--- a/mail/base/content/msgMail3PaneWindow.js
+++ b/mail/base/content/msgMail3PaneWindow.js
@@ -1366,35 +1366,52 @@ function ThreadPaneOnDragStart(aEvent) {
   let msgUrls = {};
 
   // Dragging multiple messages to desktop does not currently work.
   // When core fixes for multiple-drop-on-desktop support
   // (e.g. bug 513464, bug 270292) are landed, generating of
   // "application/x-moz-file-promise" values for i > 0 can be enabled.
   // But first ensure suggestUniqueFileName is efficient enough on 10000+ dragged
   // messages.
+  let messengerBundle = document.getElementById("bundle_messenger");
+  let noSubjectString = messengerBundle.getString("defaultSaveMessageAsFileName");
+  if (noSubjectString.endsWith(".eml"))
+    noSubjectString = noSubjectString.slice(0, -4);
+  let longSubjectTruncator = messengerBundle.getString("longMsgSubjectTruncator");
+  // Clip the subject string to 124 chars to avoid problems on Windows,
+  // see NS_MAX_FILEDESCRIPTOR in m-c/widget/windows/nsDataObj.cpp .
+  const maxUncutNameLength = 124;
+  let maxCutNameLength = maxUncutNameLength - longSubjectTruncator.length;
   for (let i in messages) {
     messenger.messageServiceFromURI(messages[i])
              .GetUrlForUri(messages[i], msgUrls, null);
     aEvent.dataTransfer.mozSetDataAt("text/x-moz-message", messages[i], i);
     aEvent.dataTransfer.mozSetDataAt("text/x-moz-url",msgUrls.value.spec, i);
 
     if (i > 0)
       continue;
 
     // Generate file name in case the object is dropped onto the desktop.
     let subject = messenger.messageServiceFromURI(messages[i])
                            .messageURIToMsgHdr(messages[i]).mime2DecodedSubject;
-    let uniqueFileName = suggestUniqueFileName(subject.substr(0, 124), ".eml",
-                                               fileNames);
+    let uniqueFileName;
+    // If there is no subject, use a default name.
+    // If subject needs to be truncated, add a truncation character to indicate it.
+    if (!subject) {
+      uniqueFileName = noSubjectString;
+    } else {
+      uniqueFileName = (subject.length <= maxUncutNameLength) ?
+                       subject : subject.substr(0, maxCutNameLength) + longSubjectTruncator;
+    }
+    uniqueFileName = suggestUniqueFileName(uniqueFileName, ".eml", fileNames);
     fileNames.add(uniqueFileName);
 
     aEvent.dataTransfer.mozSetDataAt("application/x-moz-file-promise-url",
                                      msgUrls.value.spec + "?fileName=" +
-                                     uniqueFileName, i);
+                                     encodeURIComponent(uniqueFileName), i);
     aEvent.dataTransfer.mozSetDataAt("application/x-moz-file-promise", null, i);
   }
   aEvent.dataTransfer.effectAllowed = "copyMove";
   aEvent.dataTransfer.addElement(aEvent.originalTarget);
 }
 
 /**
  * Returns a new filename that is guaranteed to not be in the Set
--- a/mail/locales/en-US/chrome/messenger/messenger.properties
+++ b/mail/locales/en-US/chrome/messenger/messenger.properties
@@ -26,16 +26,19 @@ advanceNextPrompt=Advance to next unread
 titleNewsPreHost=on
 replyToSender=Reply to Sender
 reply=Reply
 EMLFiles=Mail Files
 OpenEMLFiles=Open Message
 # LOCALIZATION NOTE(defaultSaveMessageAsFileName): Do not translate ".eml"
 # in the line below. Also, the complete file name should be 8.3.
 defaultSaveMessageAsFileName=message.eml
+# LOCALIZATION NOTE(longMsgSubjectTruncator): A suffix string appended to the filename
+# (created from message subject) if it needed to be truncated due to length.
+longMsgSubjectTruncator=...
 SaveMailAs=Save Message As
 SaveAttachment=Save Attachment
 SaveAllAttachments=Save All Attachments
 ChooseFolder=Choose Folder
 LoadingMessageToPrint=Loading message to print…
 MessageLoaded=Message loaded…
 PrintingMessage=Printing message…
 PrintPreviewMessage=Print Previewing message…