Revision: 7356
          http://mahogany.svn.sourceforge.net/mahogany/?rev=7356&view=rev
Author:   vadz
Date:     2007-09-01 14:37:53 -0700 (Sat, 01 Sep 2007)

Log Message:
-----------
fixed handling of US-ASCII charset in encoded words

Modified Paths:
--------------
    trunk/M/src/mail/MimeDecode.cpp
    trunk/M/tests/mime/decode.cpp

Modified: trunk/M/src/mail/MimeDecode.cpp
===================================================================
--- trunk/M/src/mail/MimeDecode.cpp     2007-09-01 21:30:01 UTC (rev 7355)
+++ trunk/M/src/mail/MimeDecode.cpp     2007-09-01 21:37:53 UTC (rev 7356)
@@ -32,11 +32,25 @@
 // ----------------------------------------------------------------------------
 
 // this should only be used for const-incorrect c-client functions
-inline unsigned char *UCHAR_CCAST(const char *s)
+static inline unsigned char *UCHAR_CCAST(const char *s)
 {
    return reinterpret_cast<unsigned char *>(const_cast<char *>(s));
 }
 
+// hide differences between wxString::FromAscii() in 2.8 and 2.9
+static inline String FromAscii(const char *p, size_t len)
+{
+   wxUnusedVar(len); // unused only with 2.8
+
+   return wxString::FromAscii
+                    (
+                        p
+#if wxCHECK_VERSION(2, 9, 0)
+                        , len
+#endif
+                    );
+}
+
 // ============================================================================
 // implementation
 // ============================================================================
@@ -298,8 +312,19 @@
 
             if ( text )
             {
-               textDecoded = wxString((char *)text, wxCSConv(encodingWord), 
len);
+               const char * const ctext = static_cast<char *>(text);
 
+               if ( encodingWord == wxFONTENCODING_DEFAULT )
+               {
+                  // CharsetToEncoding() returns this for US-ASCII but
+                  // wxCSConv() doesn't accept it
+                  textDecoded = FromAscii(ctext, len);
+               }
+               else // real conversion needed
+               {
+                  textDecoded = wxString(ctext, wxCSConv(encodingWord), len);
+               }
+
                fs_give(&text);
             }
          }
@@ -515,11 +540,7 @@
       }
 
       // put into string as we might want to do some more replacements...
-      String encword(wxString::FromAscii(CHAR_CAST(textEnc)
-#if wxCHECK_VERSION(2, 9, 0)
-                                         , lenEnc
-#endif
-                                        ));
+      String encword(FromAscii(CHAR_CAST(textEnc), lenEnc));
 
       // hack: rfc822_8bit() doesn't encode spaces normally but we must
       // do it inside the headers

Modified: trunk/M/tests/mime/decode.cpp
===================================================================
--- trunk/M/tests/mime/decode.cpp       2007-09-01 21:30:01 UTC (rev 7355)
+++ trunk/M/tests/mime/decode.cpp       2007-09-01 21:37:53 UTC (rev 7356)
@@ -382,7 +382,13 @@
             "=?UTF-8?Q?=D0=92_=D0=A6?= 2007",
             "\xD0\x92 \xD0\xA6 2007",
             wxFONTENCODING_UTF8
-        }
+        },
+
+        {
+            "=?us-ascii?Q?Foo=20bar?=",
+            "Foo bar",
+            wxFONTENCODING_DEFAULT
+        },
     };
 
     int rc = EXIT_SUCCESS;
@@ -397,6 +403,11 @@
             rc = EXIT_FAILURE;
         }
 
+        // wxFONTENCODING_DEFAULT is used in the test data to indicate that we
+        // don't want to test the encoding
+        if ( d.enc == wxFONTENCODING_DEFAULT )
+            continue;
+
         const wxCharBuffer buf = MIME::EncodeHeader(s, d.enc);
         if ( strcmp(buf, d.encoded) != 0 )
         {


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

Reply via email to