Bug 1188306: Use default system characterset if characterset can't be determined; r=mkmelin, a=rkent
authorJorg K <mozilla@jorgk.com>
Mon, 10 Aug 2015 15:10:32 -0700
changeset 22887 9d3eefbed90e77133c834eabf0d578c0f297b6e7
parent 22886 4f1d6e940fc4a328db80e28fac4f1e22aa1a563e
child 22888 11097c52b2716277c3e61d67f4eaa5da6ba47333
push id1465
push userkent@caspia.com
push dateMon, 14 Sep 2015 21:51:35 +0000
treeherdercomm-beta@48e8ee8813e3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmkmelin, rkent
bugs1188306
Bug 1188306: Use default system characterset if characterset can't be determined; r=mkmelin, a=rkent
mailnews/base/util/nsMsgUtils.cpp
mailnews/import/text/src/nsTextAddress.cpp
--- a/mailnews/base/util/nsMsgUtils.cpp
+++ b/mailnews/base/util/nsMsgUtils.cpp
@@ -2426,16 +2426,20 @@ MsgDetectCharsetFromFile(nsIFile *aFile,
       isUTF8Compat = MsgIsUTF8(buffer);
     }
 
     // If the file content is UTF-8 compatible, use that. Otherwise let's not
     // make a bad guess.
     if (isUTF8Compat)
       aCharset.AssignLiteral("UTF-8");
   }
+
+  if (aCharset.IsEmpty()) {
+    return NS_ERROR_FAILURE;
+  }
   return NS_OK;
 }
 
 /*
  * Converts a buffer to plain text. Some conversions may
  * or may not work with certain end charsets which is why we
  * need that as an argument to the function. If charset is
  * unknown or deemed of no importance NULL could be passed.
--- a/mailnews/import/text/src/nsTextAddress.cpp
+++ b/mailnews/import/text/src/nsTextAddress.cpp
@@ -6,16 +6,17 @@
 
 #include "nsTextAddress.h"
 #include "nsIAddrDatabase.h"
 #include "nsNativeCharsetUtils.h"
 #include "nsIFile.h"
 #include "nsIInputStream.h"
 #include "nsILineInputStream.h"
 #include "nsNetUtil.h"
+#include "nsMsgI18N.h"
 #include "nsMsgUtils.h"
 #include "mdb.h"
 #include "nsIConverterInputStream.h"
 #include "nsIUnicharLineInputStream.h"
 #include "nsMsgUtils.h"
 
 #include "TextDebugLog.h"
 #include "plstr.h"
@@ -46,18 +47,17 @@ nsTextAddress::~nsTextAddress()
 
 nsresult nsTextAddress::GetUnicharLineStreamForFile(nsIFile *aFile,
                                                     nsIInputStream *aInputStream,
                                                     nsIUnicharLineInputStream **aStream)
 {
   nsAutoCString charset;
   nsresult rv = MsgDetectCharsetFromFile(aFile, charset);
   if (NS_FAILED(rv)) {
-    IMPORT_LOG0( "*** Error checking address file for charset detection\n");
-    return rv;
+    charset.Assign(nsMsgI18NFileSystemCharset());
   }
 
   nsCOMPtr<nsIConverterInputStream> converterStream =
     do_CreateInstance("@mozilla.org/intl/converter-input-stream;1", &rv);
   if (NS_SUCCEEDED(rv)) {
     rv = converterStream->Init(aInputStream,
                                charset.get(),
                                8192,