Revision: 7337
http://mahogany.svn.sourceforge.net/mahogany/?rev=7337&view=rev
Author: vadz
Date: 2007-08-24 15:36:20 -0700 (Fri, 24 Aug 2007)
Log Message:
-----------
recode message text to user-specified encoding in Unicode build
Modified Paths:
--------------
trunk/M/src/classes/MessageView.cpp
Modified: trunk/M/src/classes/MessageView.cpp
===================================================================
--- trunk/M/src/classes/MessageView.cpp 2007-08-24 22:35:53 UTC (rev 7336)
+++ trunk/M/src/classes/MessageView.cpp 2007-08-24 22:36:20 UTC (rev 7337)
@@ -155,6 +155,30 @@
return norm;
}
+// recode the contents of a string in the specified destination encoding,
+// assuming that the current contents was obtained from the source encoding
+#if wxUSE_UNICODE
+
+static void
+RecodeText(String *text, wxFontEncoding encSrc, wxFontEncoding encDst)
+{
+ // recode the text to the user-specified encoding
+ const wxCharBuffer textMB(text->mb_str(wxCSConv(encSrc)));
+ CHECK_RET( textMB, "string not in source encoding?" );
+
+ *text = String(textMB, wxCSConv(encDst));
+}
+
+#else // !wxUSE_UNICODE
+
+static inline void RecodeText(String *, wxFontEncoding, wxFontEncoding)
+{
+ // do nothing in ANSI build: the string always contains the same bytes,
+ // independently of the encoding being used
+}
+
+#endif // wxUSE_UNICODE/!wxUSE_UNICODE
+
// ----------------------------------------------------------------------------
// private classes
// ----------------------------------------------------------------------------
@@ -1316,15 +1340,19 @@
{
HeaderIterator headers(m_mailMessage->GetHeader());
- const wxFontEncoding encHeaders = m_encodingUser ==
wxFONTENCODING_DEFAULT
- ? wxFONTENCODING_SYSTEM
- : m_encodingUser;
-
String name,
value;
while ( headers.GetNext(&name, &value, HeaderIterator::MultiLineOk) )
{
- ShowHeader(name, value, encHeaders);
+ wxFontEncoding encHeader = wxFONTENCODING_SYSTEM;
+ if ( m_encodingUser != wxFONTENCODING_DEFAULT )
+ {
+ RecodeText(&value, wxFONTENCODING_ISO8859_1, m_encodingUser);
+
+ encHeader = m_encodingUser;
+ }
+
+ ShowHeader(name, value, encHeader);
}
}
else // show just a few standard headers
@@ -1624,16 +1652,13 @@
// use the user specified encoding if none specified in the
header
// itself
encHeader = m_encodingUser;
+
+ RecodeText(&value, wxFONTENCODING_ISO8859_1, m_encodingUser);
}
else if ( m_encodingAuto != wxFONTENCODING_SYSTEM )
{
encHeader = m_encodingAuto;
}
-
-#if wxUSE_UNICODE
- if ( encHeader != wxFONTENCODING_SYSTEM )
- value = wxString(value.To8BitData(), wxCSConv(encHeader));
-#endif // wxUSE_UNICODE
}
#if !wxUSE_UNICODE
@@ -1693,26 +1718,29 @@
{
// get the encoding of the text
wxFontEncoding encPart;
- if( m_encodingUser != wxFONTENCODING_DEFAULT )
+ if ( m_encodingUser != wxFONTENCODING_DEFAULT )
{
// user-specified encoding overrides everything
encPart = m_encodingUser;
+
+ RecodeText(&textPart, textEnc, m_encodingUser);
}
else // determine the encoding ourselves
{
encPart = textEnc;
+#if !wxUSE_UNICODE
if ( encPart == wxFONTENCODING_UTF8 || encPart == wxFONTENCODING_UTF7 )
{
m_encodingAuto = encPart;
-#if !wxUSE_UNICODE
// convert from UTF-8|7 to environment's default encoding
encPart = ConvertUTFToMB(&textPart, encPart);
+ }
+ else
#endif // wxUSE_UNICODE
- }
- else if ( encPart == wxFONTENCODING_SYSTEM ||
- encPart == wxFONTENCODING_DEFAULT )
+ if ( encPart == wxFONTENCODING_SYSTEM ||
+ encPart == wxFONTENCODING_DEFAULT )
{
// use the encoding of the last part which had it
encPart = m_encodingAuto;
@@ -1727,11 +1755,8 @@
if ( encPart == wxFONTENCODING_SYSTEM )
{
// autodetecting encoding didn't work, use the fall back encoding, if any
- if ( m_encodingUser != wxFONTENCODING_DEFAULT )
- {
- encPart = (wxFontEncoding)(long)
- READ_CONFIG(GetProfile(), MP_MSGVIEW_DEFAULT_ENCODING);
- }
+ encPart = (wxFontEncoding)(long)
+ READ_CONFIG(GetProfile(), MP_MSGVIEW_DEFAULT_ENCODING);
}
// init the style we're going to use
@@ -2009,7 +2034,10 @@
#if wxUSE_UNICODE
if ( mimepart->GetType().IsText() )
{
- s = wxCSConv(mimepart->GetTextEncoding()).cMB2WC(data, len,
NULL);
+ wxFontEncoding enc = m_encodingUser == wxFONTENCODING_DEFAULT
+ ? mimepart->GetTextEncoding()
+ : m_encodingUser;
+ s = wxCSConv(enc).cMB2WC(data, len, NULL);
}
if ( s.empty() )
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Mahogany-cvsupdates mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mahogany-cvsupdates