Bug 507804 - nsMsgComposeSecure.cpp: 3 strings to localize; r=kaie
authorEdmund Wong <ewong@pw-wspx.org>
Tue, 24 Aug 2010 15:20:57 +0100
changeset 6254 b753634d4b8b
parent 6253 0525d26920e0
child 6255 a219ce33c927
push idunknown
push userunknown
push dateunknown
reviewerskaie
bugs507804
Bug 507804 - nsMsgComposeSecure.cpp: 3 strings to localize; r=kaie
mail/locales/en-US/chrome/messenger/am-smime.properties
mailnews/extensions/smime/src/nsMsgComposeSecure.cpp
suite/locales/en-US/chrome/mailnews/smime/am-smime.properties
--- a/mail/locales/en-US/chrome/messenger/am-smime.properties
+++ b/mail/locales/en-US/chrome/messenger/am-smime.properties
@@ -12,8 +12,13 @@ NoSigningCert=Certificate Manager can't 
 NoEncryptionCert=Certificate Manager can't locate a valid certificate that other people can use to send you encrypted email messages.
 
 encryption_needCertWantSame=You should also specify a certificate for other people to use when they send you encrypted messages. Do you want to use the same certificate to encrypt & decrypt messages sent to you?
 encryption_wantSame=Do you want to use the same certificate to encrypt & decrypt messages sent to you?
 encryption_needCertWantToSelect=You should also specify a certificate for other people to use when they send you encrypted messages. Do you want to configure an encryption certificate now?
 signing_needCertWantSame=You should also specify a certificate to use for digitally signing your messages. Do you want to use the same certificate to digitally sign your messages?
 signing_wantSame=Do you want to use the same certificate to digitally sign your messages?
 signing_needCertWantToSelect=You should also specify a certificate to use for digitally signing your messages. Do you want to configure a certificate for digitally signing messages now?
+
+## Strings used by nsMsgComposeSecure
+mime_multipartSignedBlurb=This is a cryptographically signed message in MIME format.
+mime_smimeEncryptedContentDesc=S/MIME Encrypted Message
+mime_smimeSignatureContentDesc=S/MIME Cryptographic Signature
--- a/mailnews/extensions/smime/src/nsMsgComposeSecure.cpp
+++ b/mailnews/extensions/smime/src/nsMsgComposeSecure.cpp
@@ -48,21 +48,17 @@
 #include "nsIX509CertDB.h"
 #include "nsMimeTypes.h"
 #include "nsMsgMimeCID.h"
 #include "nspr.h"
 #include "nsComponentManagerUtils.h"
 #include "nsServiceManagerUtils.h"
 #include "nsMemory.h"
 #include "nsAlgorithm.h"
-
-// XXX These strings should go in properties file XXX //
-#define MIME_MULTIPART_SIGNED_BLURB "This is a cryptographically signed message in MIME format."
-#define MIME_SMIME_ENCRYPTED_CONTENT_DESCRIPTION "S/MIME Encrypted Message"
-#define MIME_SMIME_SIGNATURE_CONTENT_DESCRIPTION "S/MIME Cryptographic Signature"
+#include "nsString.h"
 
 #define MK_MIME_ERROR_WRITING_FILE -1
 
 #define SMIME_STRBUNDLE_URL "chrome://messenger/locale/am-smime.properties"
 
 static void mime_crypto_write_base64 (void *closure, const char *buf,
               unsigned long size);
 static nsresult mime_encoder_output_fn(const char *buf, PRInt32 size, void *closure);
@@ -544,29 +540,45 @@ nsresult nsMsgComposeSecure::MimeInitMul
   PR_SetError(0,0);
  FAIL:
   return rv;
 }
 
 nsresult nsMsgComposeSecure::MimeInitEncryption(PRBool aSign, nsIMsgSendReport *sendReport)
 {
   nsresult rv;
+  nsCOMPtr<nsIStringBundleService> bundleSvc =
+                  do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  nsCOMPtr<nsIStringBundle> sMIMEBundle;
+  nsXPIDLString mime_smime_enc_content_desc;
+
+  bundleSvc->CreateBundle(SMIME_STRBUNDLE_URL, getter_AddRefs(sMIMEBundle));
+
+  if (!sMIMEBundle)
+    return NS_ERROR_FAILURE;
+ 
+  sMIMEBundle->GetStringFromName(NS_LITERAL_STRING("mime_smimeEncryptedContentDesc").get(),
+                                 getter_Copies(mime_smime_enc_content_desc));
+  NS_ConvertUTF16toUTF8 enc_content_desc_utf8(mime_smime_enc_content_desc);
 
   /* First, construct and write out the opaque-crypto-blob MIME header data.
    */
 
   char *s =
   PR_smprintf("Content-Type: " APPLICATION_PKCS7_MIME
           "; name=\"smime.p7m\"" CRLF
         "Content-Transfer-Encoding: " ENCODING_BASE64 CRLF
         "Content-Disposition: attachment"
           "; filename=\"smime.p7m\"" CRLF
         "Content-Description: %s" CRLF
         CRLF,
-        MIME_SMIME_ENCRYPTED_CONTENT_DESCRIPTION);
+        enc_content_desc_utf8.get());
+
   PRUint32 L;
   if (!s) return NS_ERROR_OUT_OF_MEMORY;
   L = strlen(s);
   PRUint32 n;
   rv = mStream->Write(s, L, &n);
   if (NS_FAILED(rv) || n < L) {
     return NS_ERROR_FAILURE;
   }
@@ -632,18 +644,38 @@ nsresult nsMsgComposeSecure::MimeInitEnc
   return rv;
 }
 
 nsresult nsMsgComposeSecure::MimeFinishMultipartSigned (PRBool aOuter, nsIMsgSendReport *sendReport)
 {
   int status;
   nsresult rv;
   nsCOMPtr<nsICMSMessage> cinfo = do_CreateInstance(NS_CMSMESSAGE_CONTRACTID, &rv);
+  NS_ENSURE_SUCCESS(rv, rv);
+
   nsCOMPtr<nsICMSEncoder> encoder = do_CreateInstance(NS_CMSENCODER_CONTRACTID, &rv);
+  NS_ENSURE_SUCCESS(rv, rv);
+
   char * header = nsnull;
+  nsCOMPtr<nsIStringBundleService> bundleSvc =
+                  do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  nsCOMPtr<nsIStringBundle> sMIMEBundle;
+  nsXPIDLString mime_smime_sig_content_desc;
+
+  bundleSvc->CreateBundle(SMIME_STRBUNDLE_URL, getter_AddRefs(sMIMEBundle));
+
+  if (!sMIMEBundle)
+    return NS_ERROR_FAILURE;
+  
+  sMIMEBundle->GetStringFromName(NS_LITERAL_STRING("mime_smimeSignatureContentDesc").get(),
+                                 getter_Copies(mime_smime_sig_content_desc));
+
+  NS_ConvertUTF16toUTF8 sig_content_desc_utf8(mime_smime_sig_content_desc);
 
   /* Compute the hash...
    */
 
   nsCAutoString hashString;
   mDataHash->Finish(PR_FALSE, hashString);
 
   mDataHash = 0;
@@ -660,17 +692,18 @@ nsresult nsMsgComposeSecure::MimeFinishM
           "Content-Type: " APPLICATION_PKCS7_SIGNATURE
             "; name=\"smime.p7s\"" CRLF
           "Content-Transfer-Encoding: " ENCODING_BASE64 CRLF
           "Content-Disposition: attachment; "
             "filename=\"smime.p7s\"" CRLF
           "Content-Description: %s" CRLF
           CRLF,
           mMultipartSignedBoundary,
-          MIME_SMIME_SIGNATURE_CONTENT_DESCRIPTION);
+          sig_content_desc_utf8.get());
+          
   if (!header) {
     rv = NS_ERROR_OUT_OF_MEMORY;
     goto FAIL;
   }
 
   L = strlen(header);
   if (aOuter) {
     /* If this is the outer block, write it to the file. */
@@ -1025,37 +1058,50 @@ NS_IMETHODIMP nsMsgComposeSecure::MimeCr
  */
 static int
 make_multipart_signed_header_string(PRBool outer_p,
 									char **header_return,
 									char **boundary_return)
 {
   *header_return = 0;
   *boundary_return = mime_make_separator("ms");
-  const char * crypto_multipart_blurb = nsnull;
+  nsresult rv;
+
+  nsCOMPtr<nsIStringBundleService> bundleSvc =
+                  do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  nsCOMPtr<nsIStringBundle> sMIMEBundle;
+  nsXPIDLString crypto_multipart_blurb;
+
+  bundleSvc->CreateBundle(SMIME_STRBUNDLE_URL, getter_AddRefs(sMIMEBundle));
+  if (!sMIMEBundle)
+    return NS_ERROR_FAILURE;
 
   if (!*boundary_return)
 	return NS_ERROR_OUT_OF_MEMORY;
 
   if (outer_p) {
-	  crypto_multipart_blurb = MIME_MULTIPART_SIGNED_BLURB;
+	  sMIMEBundle->GetStringFromName(NS_LITERAL_STRING("mime_multipartSignedBlurb").get(),
+                                    getter_Copies(crypto_multipart_blurb));
   }
+  NS_ConvertUTF16toUTF8 multipart_blurb_utf8(crypto_multipart_blurb);
 
   *header_return = PR_smprintf(
         "Content-Type: " MULTIPART_SIGNED "; "
         "protocol=\"" APPLICATION_PKCS7_SIGNATURE "\"; "
 				"micalg=" PARAM_MICALG_SHA1 "; "
 				"boundary=\"%s\"" CRLF
 				CRLF
 				"%s%s"
 				"--%s" CRLF,
 
 				*boundary_return,
-				(crypto_multipart_blurb ? crypto_multipart_blurb : ""),
-				(crypto_multipart_blurb ? CRLF CRLF : ""),
+				(crypto_multipart_blurb.IsEmpty() ? "" : multipart_blurb_utf8.get()),
+				(crypto_multipart_blurb.IsEmpty() ? "" : CRLF CRLF),
 				*boundary_return);
 
   if (!*header_return) {
 	  PR_Free(*boundary_return);
 	  *boundary_return = 0;
 	  return NS_ERROR_OUT_OF_MEMORY;
 	}
 
--- a/suite/locales/en-US/chrome/mailnews/smime/am-smime.properties
+++ b/suite/locales/en-US/chrome/mailnews/smime/am-smime.properties
@@ -12,8 +12,13 @@ NoSigningCert=Certificate Manager can't 
 NoEncryptionCert=Certificate Manager can't locate a valid certificate that other people can use to send you encrypted email messages.
 
 encryption_needCertWantSame=You should also specify a certificate for other people to use when they send you encrypted messages. Do you want to use the same certificate to encrypt & decrypt messages sent to you?
 encryption_wantSame=Do you want to use the same certificate to encrypt & decrypt messages sent to you?
 encryption_needCertWantToSelect=You should also specify a certificate for other people to use when they send you encrypted messages. Do you want to configure an encryption certificate now?
 signing_needCertWantSame=You should also specify a certificate to use for digitally signing your messages. Do you want to use the same certificate to digitally sign your messages?
 signing_wantSame=Do you want to use the same certificate to digitally sign your messages?
 signing_needCertWantToSelect=You should also specify a certificate to use for digitally signing your messages. Do you want to configure a certificate for digitally signing messages now?
+
+## Strings used by nsMsgComposeSecure
+mime_multipartSignedBlurb=This is a cryptographically signed message in MIME format.
+mime_smimeEncryptedContentDesc=S/MIME Encrypted Message
+mime_smimeSignatureContentDesc=S/MIME Cryptographic Signature