Bug 1506800 - Don't sent AppleDouble for files with extension unless whitelisted. r=mkmelin a=jorgk
authorJorg K <jorgk@jorgk.com>
Thu, 15 Nov 2018 15:39:37 +0100
changeset 33496 bb567fd203e4e06517e737316d38ac82307159cb
parent 33495 53151ac733ae41d6620ac80a6d170ad1cc12b7ac
child 33497 228ff50ccd3184b68efb8b26206d659b649bb6ea
push id387
push userclokep@gmail.com
push dateMon, 10 Dec 2018 21:30:47 +0000
reviewersmkmelin, jorgk
bugs1506800
Bug 1506800 - Don't sent AppleDouble for files with extension unless whitelisted. r=mkmelin a=jorgk
mailnews/compose/src/nsMsgAttachmentHandler.cpp
mailnews/mailnews.js
--- a/mailnews/compose/src/nsMsgAttachmentHandler.cpp
+++ b/mailnews/compose/src/nsMsgAttachmentHandler.cpp
@@ -29,16 +29,17 @@
 #include "nsIMimeStreamConverter.h"
 #include "nsMsgMimeCID.h"
 #include "nsNetUtil.h"
 #include "nsNativeCharsetUtils.h"
 #include "nsComposeStrings.h"
 #include "nsIZipWriter.h"
 #include "mozilla/Services.h"
 #include "mozilla/mailnews/MimeEncoder.h"
+#include "mozilla/Preferences.h"
 #include "nsIPrincipal.h"
 #include "nsIURIMutator.h"
 
 ///////////////////////////////////////////////////////////////////////////
 // Mac Specific Attachment Handling for AppleDouble Encoded Files
 ///////////////////////////////////////////////////////////////////////////
 #ifdef XP_MACOSX
 
@@ -846,30 +847,24 @@ nsMsgAttachmentHandler::ConvertToAppleEn
   if (sendResourceFork)
   {
     nsCOMPtr<nsIURL> fileUrl;
     rv = NS_MutateURI(NS_STANDARDURLMUTATOR_CONTRACTID).SetSpec(aFileURI).Finalize(fileUrl);
     if (NS_SUCCEEDED(rv))
     {
       nsAutoCString ext;
       rv = fileUrl->GetFileExtension(ext);
-      if (NS_SUCCEEDED(rv) && !ext.IsEmpty())
-      {
-        sendResourceFork =
-        PL_strcasecmp(ext.get(), "TXT") &&
-        PL_strcasecmp(ext.get(), "JPG") &&
-        PL_strcasecmp(ext.get(), "GIF") &&
-        PL_strcasecmp(ext.get(), "TIF") &&
-        PL_strcasecmp(ext.get(), "HTM") &&
-        PL_strcasecmp(ext.get(), "HTML") &&
-        PL_strcasecmp(ext.get(), "ART") &&
-        PL_strcasecmp(ext.get(), "XUL") &&
-        PL_strcasecmp(ext.get(), "XML") &&
-        PL_strcasecmp(ext.get(), "CSS") &&
-        PL_strcasecmp(ext.get(), "JS");
+      if (NS_SUCCEEDED(rv) && !ext.IsEmpty()) {
+        // Check the preference to see whether AppleDouble was requested for this extension.
+        nsAutoCString extensionWhitelist;
+        mozilla::Preferences::GetCString("mailnews.extensions_using_appledouble", extensionWhitelist);
+        if (extensionWhitelist.IsEmpty() ||
+            (!extensionWhitelist.Equals("*") &&
+             extensionWhitelist.Find(ext, /* ignoreCase = */ true) == kNotFound))
+          sendResourceFork = false;  // Ignore resource fork and don't use AppleDouble.
       }
     }
   }
 
   // Only use appledouble if we aren't uuencoding.
   if( sendResourceFork )
   {
     char *separator;
@@ -978,23 +973,16 @@ nsMsgAttachmentHandler::ConvertToAppleEn
     // Now after conversion, also patch the types.
     char        tmp[128];
     PR_snprintf(tmp, sizeof(tmp), MULTIPART_APPLEDOUBLE ";\r\n boundary=\"%s\"", separator);
     PR_FREEIF(separator);
     m_type = tmp;
   }
   else
   {
-    if ( sendResourceFork )
-    {
-      // For now, just do the encoding, but in the old world we would ask the
-      // user about doing this conversion
-      printf("...we could ask the user about this conversion, but for now, nahh..\n");
-    }
-
     bool      useDefault;
     char      *macType, *macEncoding;
     if (m_type.IsEmpty() || m_type.LowerCaseEqualsLiteral(TEXT_PLAIN))
     {
 # define TEXT_TYPE  0x54455854  /* the characters 'T' 'E' 'X' 'T' */
 # define text_TYPE  0x74657874  /* the characters 't' 'e' 'x' 't' */
 
       if (type != TEXT_TYPE && type != text_TYPE)
--- a/mailnews/mailnews.js
+++ b/mailnews/mailnews.js
@@ -279,16 +279,24 @@ pref("mailnews.force_ascii_search",     
 pref("mailnews.send_default_charset",       "chrome://messenger/locale/messenger.properties");
 pref("mailnews.view_default_charset",       "chrome://messenger/locale/messenger.properties");
 pref("mailnews.force_charset_override",     false); // ignore specified MIME encoding and use the default encoding for display
 pref("mailnews.reply_in_default_charset",   false);
 // mailnews.disable_fallback_to_utf8.<charset>
 // don't fallback from <charset> to UTF-8 even if some characters are not found in <charset>.
 // those characters will be crippled.
 pref("mailnews.disable_fallback_to_utf8.ISO-2022-JP", false);
+
+// AppleDouble is causing problems with some webmail clients and Microsoft mail servers
+// rejecting a MIME part of multipart/appledouble. Mac uses resource forks less and less
+// so we only use AppleDouble if the file has no extension or its extension is whitelisted below.
+// "" (default) - AppleDouble won't be used if the file has an extension
+// "*" - AppleDouble will always be used
+// Comma-separated list of extensions for which to use AppleDouble, for example "doc,xls" (not-case sensitive).
+pref("mailnews.extensions_using_appledouble", "");
 pref("mailnews.localizedRe",                "chrome://messenger-region/locale/region.properties");
 
 pref("mailnews.search_date_format",        "chrome://messenger/locale/messenger.properties");
 pref("mailnews.search_date_separator",     "chrome://messenger/locale/messenger.properties");
 pref("mailnews.search_date_leading_zeros", "chrome://messenger/locale/messenger.properties");
 
 pref("mailnews.quotingPrefs.version",       0);  // used to decide whether to migrate global quoting prefs