Bug 777581 - Use macros instead of text literal for transfer-encoding. r=mbanner
authorHiroyuki Ikezoe <hiikezoe@mozilla-japan.org>
Sat, 04 Aug 2012 10:14:16 -0400
changeset 13198 25e716ecbc45fc3b28b69275c5cdbdb2cc85653b
parent 13197 2368e7da5f4bd7e2844f896c9afbbe9556f4ab38
child 13199 6856915ce62ba31ae73713896dba686bdd74b00f
push idunknown
push userunknown
push dateunknown
reviewersmbanner
bugs777581
Bug 777581 - Use macros instead of text literal for transfer-encoding. r=mbanner
mailnews/base/search/src/nsMsgBodyHandler.cpp
mailnews/base/util/nsMsgDBFolder.cpp
mailnews/compose/src/nsMsgSend.cpp
--- a/mailnews/base/search/src/nsMsgBodyHandler.cpp
+++ b/mailnews/base/search/src/nsMsgBodyHandler.cpp
@@ -10,16 +10,17 @@
 #include "nsMsgSearchTerm.h"
 #include "nsIMsgHdr.h"
 #include "nsMsgMessageFlags.h"
 #include "nsISeekableStream.h"
 #include "nsIInputStream.h"
 #include "nsIFile.h"
 #include "plbase64.h"
 #include "prmem.h"
+#include "nsMimeTypes.h"
 
 nsMsgBodyHandler::nsMsgBodyHandler (nsIMsgSearchScopeTerm * scope,
                                     PRUint32 numLines,
                                     nsIMsgDBHdr* msg, nsIMsgDatabase * db)
 {
   m_scope = scope;
   m_numLocalLines = numLines;
   PRUint32 flags;
@@ -393,17 +394,17 @@ void nsMsgBodyHandler::SniffPossibleMIME
       end = line.Length();
 
     boundary.Assign("--");
     boundary.Append(Substring(line,start,end-start));
   }
 
   if (StringBeginsWith(lowerCaseLine,
                        NS_LITERAL_CSTRING("content-transfer-encoding:")) &&
-      lowerCaseLine.Find("base64", CaseInsensitiveCompare) != kNotFound)
+      lowerCaseLine.Find(ENCODING_BASE64, CaseInsensitiveCompare) != kNotFound)
     m_base64part = true;
 }
 
 /**
  * Decodes the given base64 string.
  *
  * It returns its decoded string in its input.
  *
--- a/mailnews/base/util/nsMsgDBFolder.cpp
+++ b/mailnews/base/util/nsMsgDBFolder.cpp
@@ -62,16 +62,17 @@
 #include "nsIPK11TokenDB.h"
 #include "nsIPK11Token.h"
 #include "nsMsgLocalFolderHdrs.h"
 #define oneHour 3600000000U
 #include "nsMsgUtils.h"
 #include "nsIMsgFilterService.h"
 #include "nsDirectoryServiceUtils.h"
 #include "mozilla/Services.h"
+#include "nsMimeTypes.h"
 
 static PRTime gtimeOfLastPurgeCheck;    //variable to know when to check for purge_threshhold
 
 #define PREF_MAIL_PROMPT_PURGE_THRESHOLD "mail.prompt_purge_threshhold"
 #define PREF_MAIL_PURGE_THRESHOLD "mail.purge_threshhold"
 #define PREF_MAIL_PURGE_THRESHOLD_MB "mail.purge_threshhold_mb"
 #define PREF_MAIL_PURGE_MIGRATED "mail.purge_threshold_migrated"
 #define PREF_MAIL_PURGE_ASK "mail.purge.ask"
@@ -5498,17 +5499,17 @@ NS_IMETHODIMP nsMsgDBFolder::GetMsgTextF
       }
 
       // Finally, get the encoding
       nsCAutoString encodingHdr;
       mimeHeaders->ExtractHeader("Content-Transfer-Encoding", false, getter_Copies(encodingHdr));
       if (!encodingHdr.IsEmpty())
         mimeHdrParam->GetParameter(encodingHdr, nullptr, EmptyCString(), false, nullptr, encoding);
 
-      if (encoding.LowerCaseEqualsLiteral("base64"))
+      if (encoding.LowerCaseEqualsLiteral(ENCODING_BASE64))
         isBase64 = true;
     }
 
     // We need to consume the rest, until the next headers
     PRUint32 count = boundaryStack.Length();
     nsCAutoString boundary;
     nsCAutoString endBoundary;
     if (count)
@@ -5602,26 +5603,26 @@ NS_IMETHODIMP nsMsgDBFolder::GetMsgTextF
  *                    handle, the message data is passed back unmodified.
  * @param aEncodingType the encoding type (base64, quoted-printable)
  * @param aIsComplete the snippet is actually the entire message so the decoder
  *                           doesn't have to worry about partial data
  * @param aMsgSnippet in/out argument. The encoded msg snippet and then the decoded snippet
  */
 void nsMsgDBFolder::decodeMsgSnippet(const nsACString& aEncodingType, bool aIsComplete, nsCString& aMsgSnippet)
 {
-  if (MsgLowerCaseEqualsLiteral(aEncodingType, "base64"))
+  if (MsgLowerCaseEqualsLiteral(aEncodingType, ENCODING_BASE64))
   {
     PRInt32 base64Len = aMsgSnippet.Length();
     if (aIsComplete)
       base64Len -= base64Len % 4;
     char *decodedBody = PL_Base64Decode(aMsgSnippet.get(), base64Len, nullptr);
     if (decodedBody)
       aMsgSnippet.Adopt(decodedBody);
   }
-  else if (MsgLowerCaseEqualsLiteral(aEncodingType, "quoted-printable"))
+  else if (MsgLowerCaseEqualsLiteral(aEncodingType, ENCODING_QUOTED_PRINTABLE))
   {
     // giant hack - decode in place, and truncate string.
     MsgStripQuotedPrintable((unsigned char *) aMsgSnippet.get());
     aMsgSnippet.SetLength(strlen(aMsgSnippet.get()));
   }
 }
 
 /**
--- a/mailnews/compose/src/nsMsgSend.cpp
+++ b/mailnews/compose/src/nsMsgSend.cpp
@@ -1906,17 +1906,17 @@ nsMsgComposeAndSend::ProcessMultipartRel
       m_attachments[i].m_overrideEncoding = attachment.m_realEncoding;
       m_attachments[i].m_desiredType = attachment.m_desiredType;
       m_attachments[i].m_description = attachment.m_description;
       m_attachments[i].m_realName = attachment.m_realName;
       m_attachments[i].m_xMacType = attachment.m_xMacType;
       m_attachments[i].m_xMacCreator = attachment.m_xMacCreator;
 
       m_attachments[i].m_charset = mCompFields->GetCharacterSet();
-      m_attachments[i].m_encoding = "7bit";
+      m_attachments[i].m_encoding = ENCODING_7BIT;
 
       if (m_attachments[i].mURL)
         msg_pick_real_name(&m_attachments[i], nullptr, mCompFields->GetCharacterSet());
 
       if (m_attachments[i].m_contentId.IsEmpty())
       {
         //
         // Next, generate a content id for use with this part
@@ -2331,17 +2331,17 @@ nsMsgComposeAndSend::AddCompFieldRemoteA
 
           m_attachments[newLoc].mDeleteFile = true;
           m_attachments[newLoc].m_done = false;
           m_attachments[newLoc].SetMimeDeliveryState(this);
 
           if (!isAMessageAttachment)
             nsMsgNewURL(getter_AddRefs(m_attachments[newLoc].mURL), url.get());
 
-          m_attachments[newLoc].m_encoding = "7bit";
+          m_attachments[newLoc].m_encoding = ENCODING_7BIT;
 
           attachment->GetMacType(getter_Copies(m_attachments[newLoc].m_xMacType));
           attachment->GetMacCreator(getter_Copies(m_attachments[newLoc].m_xMacCreator));
 
           /* Count up attachments which are going to come from mail folders
              and from NNTP servers. */
           bool do_add_attachment = false;
           if (isAMessageAttachment)
@@ -2546,17 +2546,17 @@ nsMsgComposeAndSend::HackAttachments(nsI
       attachment->GetRealType(m_attachments[i].m_overrideType);
       m_attachments[i].m_charset = mCompFields->GetCharacterSet();
       attachment->GetRealEncoding(m_attachments[i].m_overrideEncoding);
       attachment->GetDesiredType(m_attachments[i].m_desiredType);
       attachment->GetDescription(m_attachments[i].m_description);
       attachment->GetRealName(m_attachments[i].m_realName);
       attachment->GetXMacType(m_attachments[i].m_xMacType);
       attachment->GetXMacCreator(m_attachments[i].m_xMacCreator);
-      m_attachments[i].m_encoding = "7bit";
+      m_attachments[i].m_encoding = ENCODING_7BIT;
 
       // real name is set in the case of vcard so don't change it.  XXX STILL NEEDED?
       // m_attachments[i].m_real_name = 0;
 
       /* Count up attachments which are going to come from mail folders
       and from NNTP servers. */
     if (m_attachments[i].mURL)
     {
@@ -3217,17 +3217,17 @@ nsMsgComposeAndSend::SnarfAndCopyBody(co
      nsresult rv = EnsureLineBreaks(attachment1_body, attachment1_body_length);
      NS_ENSURE_SUCCESS(rv,rv);
     }
   }
 
   PR_FREEIF(m_attachment1_type);
   m_attachment1_type = PL_strdup (attachment1_type);
   PR_FREEIF(m_attachment1_encoding);
-  m_attachment1_encoding = PL_strdup ("8bit");
+  m_attachment1_encoding = PL_strdup (ENCODING_8BIT);
   return NS_OK;
 }
 
 nsresult
 nsMsgComposeAndSend::Init(
               nsIMsgIdentity  *aUserIdentity,
               const char *aAccountKey,
               nsMsgCompFields *fields,