From fee299ef36a26f004010dd723ef3c63c5d8c9879 Mon Sep 17 00:00:00 2001 From: "rhp%netscape.com" Date: Wed, 11 Aug 1999 03:28:22 +0000 Subject: [PATCH] Fix for auto detecting charset on HTML docs when sending git-svn-id: svn://10.0.0.236/trunk@43137 18797224-902f-48f8-a5cc-f745e15eee43 --- .../mailnews/compose/src/nsMsgCompUtils.cpp | 49 ++++++++++--------- mozilla/mailnews/compose/src/nsMsgSend.cpp | 15 ++++++ 2 files changed, 41 insertions(+), 23 deletions(-) diff --git a/mozilla/mailnews/compose/src/nsMsgCompUtils.cpp b/mozilla/mailnews/compose/src/nsMsgCompUtils.cpp index 6eb3a6d20a1..573192772a5 100644 --- a/mozilla/mailnews/compose/src/nsMsgCompUtils.cpp +++ b/mozilla/mailnews/compose/src/nsMsgCompUtils.cpp @@ -817,30 +817,33 @@ mime_generate_attachment_headers (const char *type, const char *encoding, PUSH_STRING ("Content-Type: "); PUSH_STRING (type); - if (mime_type_needs_charset (type)) { - - char charset_label[65]; // Content-Type: charset + if (mime_type_needs_charset (type)) + { + + char charset_label[65] = ""; // Content-Type: charset PL_strcpy(charset_label, charset); - - /* If the characters are all 7bit, then it's better (and true) to - claim the charset to be US- rather than Latin1. Should we - do this all the time, for all charsets? I'm not sure. But we - should definitely do it for Latin1. */ - if (encoding && - !PL_strcasecmp (encoding, "7bit") && - !PL_strcasecmp (charset, "iso-8859-1")) - PL_strcpy (charset_label, "us-ascii"); - - // If charset is JIS and and type is HTML - // then no charset to be specified (apply base64 instead) - // in order to avoid mismatch META_TAG (bug#104255). - if ((PL_strcasecmp(charset, "iso-2022-jp") != 0) || - (PL_strcasecmp(type, TEXT_HTML) != 0) || - (PL_strcasecmp(encoding, ENCODING_BASE64) != 0)) { - PUSH_STRING ("; charset="); - PUSH_STRING (charset_label); - } - } + + /* If the characters are all 7bit, then it's better (and true) to + claim the charset to be US- rather than Latin1. Should we + do this all the time, for all charsets? I'm not sure. But we + should definitely do it for Latin1. */ + if (encoding && + !PL_strcasecmp (encoding, "7bit") && + !PL_strcasecmp (charset, "iso-8859-1")) + PL_strcpy (charset_label, "us-ascii"); + + // If charset is JIS and and type is HTML + // then no charset to be specified (apply base64 instead) + // in order to avoid mismatch META_TAG (bug#104255). + if ( ((PL_strcasecmp(charset, "iso-2022-jp") != 0) || + (PL_strcasecmp(type, TEXT_HTML) != 0) || + (PL_strcasecmp(encoding, ENCODING_BASE64) != 0)) && + (*charset_label)) + { + PUSH_STRING ("; charset="); + PUSH_STRING (charset_label); + } + } if (x_mac_type && *x_mac_type) { PUSH_STRING ("; x-mac-type=\""); diff --git a/mozilla/mailnews/compose/src/nsMsgSend.cpp b/mozilla/mailnews/compose/src/nsMsgSend.cpp index 052fcb5def4..cd612b00fdf 100644 --- a/mozilla/mailnews/compose/src/nsMsgSend.cpp +++ b/mozilla/mailnews/compose/src/nsMsgSend.cpp @@ -1494,6 +1494,21 @@ nsMsgComposeAndSend::AddCompFieldLocalAttachments() if ((!m_attachments[newLoc].m_type) || (!*m_attachments[newLoc].m_type)) m_attachments[newLoc].m_type = PL_strdup(APPLICATION_OCTET_STREAM); + // For local files, if they are HTML docs and we don't have a charset, we should + // sniff the file and see if we can figure it out. + if ( (m_attachments[newLoc].m_type) && (*m_attachments[newLoc].m_type) ) + { + if (PL_strcasecmp(m_attachments[newLoc].m_type, TEXT_HTML) == 0) + { + char *tmpCharset = (char *)nsMsgI18NParseMetaCharset(m_attachments[newLoc].mFileSpec); + if (tmpCharset[0] != '\0') + { + PR_FREEIF(m_attachments[newLoc].m_charset); + m_attachments[newLoc].m_charset = PL_strdup(tmpCharset); + } + } + } + ++newLoc; }