Bug 334356 - Remove unused nsIImportMimeEncode.idl and related code. r=mkmelin
authorSomu Bhargava <somubhargava97@gmail.com>
Mon, 03 Jun 2019 18:06:58 +0530
changeset 35749 7389c579b86823526669b8831696635b09cf4c27
parent 35748 8503388a38449367ce7316ac33e49cc1f76fe9fc
child 35750 3adb373a816afe236275baee53713a7447b33cbe
push id392
push userclokep@gmail.com
push dateMon, 02 Sep 2019 20:17:19 +0000
reviewersmkmelin
bugs334356
Bug 334356 - Remove unused nsIImportMimeEncode.idl and related code. r=mkmelin
mailnews/import/build/nsImportModule.cpp
mailnews/import/public/moz.build
mailnews/import/public/nsIImportMimeEncode.idl
mailnews/import/src/moz.build
mailnews/import/src/nsImportMimeEncode.cpp
mailnews/import/src/nsImportMimeEncode.h
--- a/mailnews/import/build/nsImportModule.cpp
+++ b/mailnews/import/build/nsImportModule.cpp
@@ -8,20 +8,18 @@
 ////////////////////////////////////////////////////////////////////////////////
 #include "nsCOMPtr.h"
 #include "mozilla/ModuleUtils.h"
 
 ////////////////////////////////////////////////////////////////////////////////
 // core import Include Files
 ////////////////////////////////////////////////////////////////////////////////
 #include "nsImportService.h"
-#include "nsImportMimeEncode.h"
 
 NS_DEFINE_NAMED_CID(NS_IMPORTSERVICE_CID);
-NS_DEFINE_NAMED_CID(NS_IMPORTMIMEENCODE_CID);
 ////////////////////////////////////////////////////////////////////////////////
 // text import Include Files
 ////////////////////////////////////////////////////////////////////////////////
 #include "nsTextImport.h"
 
 NS_DEFINE_NAMED_CID(NS_TEXTIMPORT_CID);
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -67,17 +65,16 @@ NS_DEFINE_NAMED_CID(NS_OUTLOOKIMPORT_CID
 
 NS_DEFINE_NAMED_CID(NS_BECKYIMPORT_CID);
 #endif  // XP_WIN
 
 ////////////////////////////////////////////////////////////////////////////////
 // core import factories
 ////////////////////////////////////////////////////////////////////////////////
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsImportService)
-NS_GENERIC_FACTORY_CONSTRUCTOR(nsIImportMimeEncodeImpl)
 
 ////////////////////////////////////////////////////////////////////////////////
 // text import factories
 ////////////////////////////////////////////////////////////////////////////////
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsTextImport)
 
 ////////////////////////////////////////////////////////////////////////////////
 // vcard import factories
@@ -130,18 +127,16 @@ static const mozilla::Module::CategoryEn
 #if defined(XP_MACOSX)
     {"mailnewsimport", "{6d3f101c-70ec-4e04-b68d-9908d1aeddf3}",
      kAppleMailSupportsString},
 #endif
     {NULL}};
 
 const mozilla::Module::CIDEntry kMailNewsImportCIDs[] = {
     {&kNS_IMPORTSERVICE_CID, false, NULL, nsImportServiceConstructor},
-    {&kNS_IMPORTMIMEENCODE_CID, false, NULL,
-     nsIImportMimeEncodeImplConstructor},
     {&kNS_TEXTIMPORT_CID, false, NULL, nsTextImportConstructor},
     {&kNS_VCARDIMPORT_CID, false, NULL, nsVCardImportConstructor},
 #if defined(XP_MACOSX)
     {&kNS_APPLEMAILIMPORT_CID, false, NULL, nsAppleMailImportModuleConstructor},
     {&kNS_APPLEMAILIMPL_CID, false, NULL, nsAppleMailImportMailConstructor},
 #endif
 
 #ifdef XP_WIN
@@ -150,17 +145,16 @@ const mozilla::Module::CIDEntry kMailNew
 #  ifdef MOZ_MAPI_SUPPORT
     {&kNS_OUTLOOKIMPORT_CID, false, NULL, nsOutlookImportConstructor},
 #  endif
 #endif
     {NULL}};
 
 const mozilla::Module::ContractIDEntry kMailNewsImportContracts[] = {
     {NS_IMPORTSERVICE_CONTRACTID, &kNS_IMPORTSERVICE_CID},
-    {"@mozilla.org/import/import-mimeencode;1", &kNS_IMPORTMIMEENCODE_CID},
     {"@mozilla.org/import/import-text;1", &kNS_TEXTIMPORT_CID},
     {"@mozilla.org/import/import-vcard;1", &kNS_VCARDIMPORT_CID},
 #if defined(XP_MACOSX)
     {"@mozilla.org/import/import-applemail;1", &kNS_APPLEMAILIMPORT_CID},
     {NS_APPLEMAILIMPL_CONTRACTID, &kNS_APPLEMAILIMPL_CID},
 #endif
 
 #ifdef XP_WIN
--- a/mailnews/import/public/moz.build
+++ b/mailnews/import/public/moz.build
@@ -6,16 +6,15 @@
 XPIDL_SOURCES += [
     'nsIImportABDescriptor.idl',
     'nsIImportAddressBooks.idl',
     'nsIImportFieldMap.idl',
     'nsIImportFilters.idl',
     'nsIImportGeneric.idl',
     'nsIImportMail.idl',
     'nsIImportMailboxDescriptor.idl',
-    'nsIImportMimeEncode.idl',
     'nsIImportModule.idl',
     'nsIImportService.idl',
     'nsIImportSettings.idl',
 ]
 
 XPIDL_MODULE = 'import'
 
deleted file mode 100644
--- a/mailnews/import/public/nsIImportMimeEncode.idl
+++ /dev/null
@@ -1,42 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-/*
-  Encodes a file from disk into an output stream including properly
-  encoded mime headers.
-*/
-
-#include "nsISupports.idl"
-
-interface nsIFile;
-
-[noscript, uuid(1d63892f-f660-465c-a550-95d4cb089de4)]
-interface nsIImportMimeEncode : nsISupports
-{
-
-  void  EncodeFile( in nsIFile inFile, in nsIFile outFile, [const] in string fileName, [const] in string mimeType);
-
-  boolean  DoWork( out boolean done);
-
-  long  NumBytesProcessed();
-
-  boolean  DoEncoding();
-  void  Initialize( in nsIFile inFile, in nsIFile outFile, [const] in string fileName, [const] in string mimeType);
-
-};
-
-
-
-%{ C++
-
-#define NS_IMPORTMIMEENCODE_CID                      \
-{ /* e4a1a340-8de2-11d3-a206-00a0cc26da63 */         \
-    0xe4a1a340,                                      \
-    0x8de2,                                          \
-    0x11d3,                                          \
-    {0xa2, 0x06, 0x00, 0xa0, 0xcc, 0x26, 0xda, 0x63} \
-}
-
-%}
--- a/mailnews/import/src/moz.build
+++ b/mailnews/import/src/moz.build
@@ -9,17 +9,16 @@ SOURCES += [
     'ImportTranslate.cpp',
     'nsImportABDescriptor.cpp',
     'nsImportAddressBooks.cpp',
     'nsImportEmbeddedImageData.cpp',
     'nsImportEncodeScan.cpp',
     'nsImportFieldMap.cpp',
     'nsImportMail.cpp',
     'nsImportMailboxDescriptor.cpp',
-    'nsImportMimeEncode.cpp',
     'nsImportScanFile.cpp',
     'nsImportService.cpp',
     'nsImportStringBundle.cpp',
     'nsImportTranslator.cpp',
 ]
 
 EXPORTS += [
     'ImportDebug.h',
deleted file mode 100644
--- a/mailnews/import/src/nsImportMimeEncode.cpp
+++ /dev/null
@@ -1,367 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "nscore.h"
-#include "nsImportMimeEncode.h"
-
-#include "ImportCharSet.h"
-#include "ImportTranslate.h"
-
-#define kNoState 0
-#define kStartState 1
-#define kEncodeState 2
-#define kDoneState 3
-
-#define kEncodeBufferSz (8192 * 8)
-
-nsImportMimeEncode::nsImportMimeEncode() {
-  m_pOut = nullptr;
-  m_state = kNoState;
-  m_bytesProcessed = 0;
-  m_pInputBuf = nullptr;
-}
-
-nsImportMimeEncode::~nsImportMimeEncode() { delete[] m_pInputBuf; }
-
-void nsImportMimeEncode::EncodeFile(nsIFile *pInFile, ImportOutFile *pOut,
-                                    const char *pFileName,
-                                    const char *pMimeType) {
-  m_fileName = pFileName;
-  m_mimeType = pMimeType;
-
-  m_pMimeFile = pInFile;
-
-  m_pOut = pOut;
-  m_state = kStartState;
-}
-
-void nsImportMimeEncode::CleanUp(void) { CleanUpEncodeScan(); }
-
-bool nsImportMimeEncode::SetUpEncode(void) {
-  nsCString errStr;
-  if (!m_pInputBuf) {
-    m_pInputBuf = new uint8_t[kEncodeBufferSz];
-  }
-
-  m_appleSingle = false;
-
-#ifdef _MAC_IMPORT_CODE
-  // First let's see just what kind of beast we have?
-  // For files with only a data fork and a known mime type
-  // proceed with normal mime encoding just as on the PC.
-  // For unknown mime types and files with both forks,
-  // encode as AppleSingle format.
-  if (m_filePath.GetMacFileSize(UFileLocation::eResourceFork) || !pMimeType) {
-    m_appleSingle = TRUE;
-    m_mimeType = "application/applefile";
-  }
-#endif
-
-  if (!InitEncodeScan(m_appleSingle, m_pMimeFile, m_fileName.get(), m_pInputBuf,
-                      kEncodeBufferSz)) {
-    return false;
-  }
-
-  m_state = kEncodeState;
-  m_lineLen = 0;
-
-  // Write out the boundary header
-  bool bResult = true;
-  bResult = m_pOut->WriteStr("Content-type: ");
-  if (bResult) bResult = m_pOut->WriteStr(m_mimeType.get());
-
-#ifdef _MAC_IMPORT_CODE
-  // include the type an creator here
-  if (bResult) bResult = m_pOut->WriteStr("; x-mac-type=\"");
-  U8 hex[8];
-  LongToHexBytes(m_filePath.GetFileType(), hex);
-  if (bResult) bResult = m_pOut->WriteData(hex, 8);
-  LongToHexBytes(m_filePath.GetFileCreator(), hex);
-  if (bResult) bResult = m_pOut->WriteStr("\"; x-mac-creator=\"");
-  if (bResult) bResult = m_pOut->WriteData(hex, 8);
-  if (bResult) bResult = m_pOut->WriteStr("\"");
-#endif
-
-  /*
-  if (bResult)
-    bResult = m_pOut->WriteStr(gMimeTypeFileName);
-  */
-  if (bResult) bResult = m_pOut->WriteStr(";\x0D\x0A");
-
-  nsCString fName;
-  bool trans = TranslateFileName(m_fileName, fName);
-  if (bResult) bResult = WriteFileName(fName, trans, "name");
-  if (bResult) bResult = m_pOut->WriteStr("Content-transfer-encoding: base64");
-  if (bResult) bResult = m_pOut->WriteEol();
-  if (bResult)
-    bResult = m_pOut->WriteStr("Content-Disposition: attachment;\x0D\x0A");
-  if (bResult) bResult = WriteFileName(fName, trans, "filename");
-  if (bResult) bResult = m_pOut->WriteEol();
-
-  if (!bResult) {
-    CleanUp();
-  }
-
-  return bResult;
-}
-
-bool nsImportMimeEncode::DoWork(bool *pDone) {
-  *pDone = false;
-  switch (m_state) {
-    case kNoState:
-      return false;
-      break;
-    case kStartState:
-      return SetUpEncode();
-      break;
-    case kEncodeState:
-      if (!Scan(pDone)) {
-        CleanUp();
-        return false;
-      }
-      if (*pDone) {
-        *pDone = false;
-        m_state = kDoneState;
-      }
-      break;
-    case kDoneState:
-      CleanUp();
-      m_state = kNoState;
-      *pDone = true;
-      break;
-  }
-
-  return true;
-}
-
-static uint8_t gBase64[] =
-    "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
-
-bool nsImportMimeEncode::ScanBuffer(bool *pDone) {
-  uint32_t pos = m_pos;
-  uint32_t start = pos;
-  uint8_t *pChar = m_pBuf + pos;
-  uint32_t max = m_bytesInBuf;
-  uint8_t byte[4];
-  uint32_t lineLen = m_lineLen;
-
-  while ((pos + 2) < max) {
-    // Encode 3 bytes
-    byte[0] = gBase64[*pChar >> 2];
-    byte[1] = gBase64[(((*pChar) & 0x3) << 4) | (((*(pChar + 1)) & 0xF0) >> 4)];
-    pChar++;
-    byte[2] = gBase64[(((*pChar) & 0xF) << 2) | (((*(pChar + 1)) & 0xC0) >> 6)];
-    pChar++;
-    byte[3] = gBase64[(*pChar) & 0x3F];
-    if (!m_pOut->WriteData(byte, 4)) return false;
-    pos += 3;
-    pChar++;
-    lineLen += 4;
-    if (lineLen > 71) {
-      if (!m_pOut->WriteEol()) return false;
-      lineLen = 0;
-    }
-  }
-
-  if ((pos < max) && m_eof) {
-    // Get the last few bytes!
-    byte[0] = gBase64[*pChar >> 2];
-    pos++;
-    if (pos < max) {
-      byte[1] =
-          gBase64[(((*pChar) & 0x3) << 4) | (((*(pChar + 1)) & 0xF0) >> 4)];
-      pChar++;
-      pos++;
-      if (pos < max) {
-        // Should be dead code!! (Then why is it here doofus?)
-        byte[2] =
-            gBase64[(((*pChar) & 0xF) << 2) | (((*(pChar + 1)) & 0xC0) >> 6)];
-        pChar++;
-        byte[3] = gBase64[(*pChar) & 0x3F];
-        pos++;
-      } else {
-        byte[2] = gBase64[(((*pChar) & 0xF) << 2)];
-        byte[3] = '=';
-      }
-    } else {
-      byte[1] = gBase64[(((*pChar) & 0x3) << 4)];
-      byte[2] = '=';
-      byte[3] = '=';
-    }
-
-    if (!m_pOut->WriteData(byte, 4)) return false;
-    if (!m_pOut->WriteEol()) return false;
-  } else if (m_eof) {
-    /*
-    byte[0] = '=';
-    if (!m_pOut->WriteData(byte, 1))
-      return FALSE;
-    */
-    if (!m_pOut->WriteEol()) return false;
-  }
-
-  m_lineLen = (int)lineLen;
-  m_pos = pos;
-  m_bytesProcessed += (pos - start);
-  return true;
-}
-
-bool nsImportMimeEncode::TranslateFileName(nsCString &inFile,
-                                           nsCString &outFile) {
-  const uint8_t *pIn = (const uint8_t *)inFile.get();
-  int len = inFile.Length();
-
-  while (len) {
-    if (!ImportCharSet::IsUSAscii(*pIn)) break;
-    len--;
-    pIn++;
-  }
-  if (len) {
-    // non US ascii!
-    // assume this string needs translating...
-    if (!ImportTranslate::ConvertString(inFile, outFile, true)) {
-      outFile = inFile;
-      return false;
-    } else {
-      return true;
-    }
-  } else {
-    outFile = inFile;
-    return false;
-  }
-}
-
-bool nsImportMimeEncode::WriteFileName(nsCString &fName, bool wasTrans,
-                                       const char *pTag) {
-  int tagNum = 0;
-  int idx = 0;
-  bool result = true;
-  int len;
-  nsCString numStr;
-
-  while ((((fName.Length() - idx) + strlen(pTag)) > 70) && result) {
-    len = 68 - strlen(pTag) - 5;
-    if (wasTrans) {
-      if (fName.CharAt(idx + len - 1) == '%')
-        len--;
-      else if (fName.CharAt(idx + len - 2) == '%')
-        len -= 2;
-    }
-
-    if (result) result = m_pOut->WriteStr("\x09");
-    if (result) result = m_pOut->WriteStr(pTag);
-    numStr = "*";
-    numStr.AppendInt(tagNum);
-    if (result) result = m_pOut->WriteStr(numStr.get());
-    if (wasTrans && result)
-      result = m_pOut->WriteStr("*=");
-    else if (result)
-      result = m_pOut->WriteStr("=\"");
-    if (result)
-      result = m_pOut->WriteData(((const uint8_t *)fName.get()) + idx, len);
-    if (wasTrans && result)
-      result = m_pOut->WriteStr("\x0D\x0A");
-    else if (result)
-      result = m_pOut->WriteStr("\"\x0D\x0A");
-    idx += len;
-    tagNum++;
-  }
-
-  if (idx) {
-    if ((fName.Length() - idx) > 0) {
-      if (result) result = m_pOut->WriteStr("\x09");
-      if (result) result = m_pOut->WriteStr(pTag);
-      numStr = "*";
-      numStr.AppendInt(tagNum);
-      if (result) result = m_pOut->WriteStr(numStr.get());
-      if (wasTrans && result)
-        result = m_pOut->WriteStr("*=");
-      else if (result)
-        result = m_pOut->WriteStr("=\"");
-      if (result)
-        result = m_pOut->WriteData(((const uint8_t *)fName.get()) + idx,
-                                   fName.Length() - idx);
-      if (wasTrans && result)
-        result = m_pOut->WriteStr("\x0D\x0A");
-      else if (result)
-        result = m_pOut->WriteStr("\"\x0D\x0A");
-    }
-  } else {
-    if (result) result = m_pOut->WriteStr("\x09");
-    if (result) result = m_pOut->WriteStr(pTag);
-    if (wasTrans && result)
-      result = m_pOut->WriteStr("*=");
-    else if (result)
-      result = m_pOut->WriteStr("=\"");
-    if (result) result = m_pOut->WriteStr(fName.get());
-    if (wasTrans && result)
-      result = m_pOut->WriteStr("\x0D\x0A");
-    else if (result)
-      result = m_pOut->WriteStr("\"\x0D\x0A");
-  }
-
-  return result;
-}
-
-//////////////////////////////////////////////////////////////////////////////
-//////////////////////////////////////////////////////////////////////////////
-nsIImportMimeEncodeImpl::nsIImportMimeEncodeImpl() {
-  m_pOut = nullptr;
-  m_pEncode = nullptr;
-}
-
-nsIImportMimeEncodeImpl::~nsIImportMimeEncodeImpl() {
-  if (m_pOut) delete m_pOut;
-  if (m_pEncode) delete m_pEncode;
-}
-
-NS_IMPL_ISUPPORTS(nsIImportMimeEncodeImpl, nsIImportMimeEncode)
-
-NS_IMETHODIMP nsIImportMimeEncodeImpl::EncodeFile(nsIFile *inFile,
-                                                  nsIFile *outFile,
-                                                  const char *fileName,
-                                                  const char *mimeType) {
-  return Initialize(inFile, outFile, fileName, mimeType);
-}
-
-NS_IMETHODIMP nsIImportMimeEncodeImpl::DoWork(bool *done, bool *_retval) {
-  if (done && _retval && m_pEncode) {
-    *_retval = m_pEncode->DoWork(done);
-    return NS_OK;
-  }
-  return NS_ERROR_FAILURE;
-}
-
-NS_IMETHODIMP nsIImportMimeEncodeImpl::NumBytesProcessed(int32_t *_retval) {
-  if (m_pEncode && _retval) *_retval = m_pEncode->NumBytesProcessed();
-  return NS_OK;
-}
-
-NS_IMETHODIMP nsIImportMimeEncodeImpl::DoEncoding(bool *_retval) {
-  if (_retval && m_pEncode) {
-    bool done = false;
-    while (m_pEncode->DoWork(&done) && !done)
-      ;
-    *_retval = done;
-    return NS_OK;
-  }
-  return NS_ERROR_FAILURE;
-}
-
-NS_IMETHODIMP nsIImportMimeEncodeImpl::Initialize(nsIFile *inFile,
-                                                  nsIFile *outFile,
-                                                  const char *fileName,
-                                                  const char *mimeType) {
-  delete m_pEncode;
-  delete m_pOut;
-
-  m_pOut = new ImportOutFile();
-  m_pOut->InitOutFile(outFile);
-
-  m_pEncode = new nsImportMimeEncode();
-  m_pEncode->EncodeFile(inFile, m_pOut, fileName, mimeType);
-
-  return NS_OK;
-}
deleted file mode 100644
--- a/mailnews/import/src/nsImportMimeEncode.h
+++ /dev/null
@@ -1,72 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#ifndef nsImportMimeEncode_h__
-#define nsImportMimeEncode_h__
-
-#include "mozilla/Attributes.h"
-#include "ImportOutFile.h"
-#include "nsImportEncodeScan.h"
-#include "nsString.h"
-#include "nsIImportMimeEncode.h"
-
-// Content-Type: image/gif; name="blah.xyz"
-// Content-Transfer-Encoding: base64
-// Content-Disposition: attachment; filename="blah.xyz"
-
-class nsImportMimeEncode : public nsImportEncodeScan {
- public:
-  nsImportMimeEncode();
-  ~nsImportMimeEncode();
-
-  void EncodeFile(nsIFile *pInFile, ImportOutFile *pOut, const char *pFileName,
-                  const char *pMimeType);
-
-  bool DoWork(bool *pDone);
-
-  long NumBytesProcessed(void) {
-    long val = m_bytesProcessed;
-    m_bytesProcessed = 0;
-    return val;
-  }
-
- protected:
-  void CleanUp(void);
-  bool SetUpEncode(void);
-  bool WriteFileName(nsCString &fName, bool wasTrans, const char *pTag);
-  bool TranslateFileName(nsCString &inFile, nsCString &outFile);
-
-  virtual bool ScanBuffer(bool *pDone) override;
-
- protected:
-  nsCString m_fileName;
-  nsCOMPtr<nsIFile> m_pMimeFile;
-  ImportOutFile *m_pOut;
-  nsCString m_mimeType;
-
-  int m_state;
-  long m_bytesProcessed;
-  uint8_t *m_pInputBuf;
-  bool m_appleSingle;
-
-  // Actual encoding variables
-  int m_lineLen;
-};
-
-class nsIImportMimeEncodeImpl : public nsIImportMimeEncode {
- public:
-  NS_DECL_ISUPPORTS
-
-  NS_DECL_NSIIMPORTMIMEENCODE
-
-  nsIImportMimeEncodeImpl();
-
- private:
-  virtual ~nsIImportMimeEncodeImpl();
-  ImportOutFile *m_pOut;
-  nsImportMimeEncode *m_pEncode;
-};
-
-#endif /* nsImportMimeEncode_h__ */