SF.net SVN: mahogany:[7532] trunk/M/src/mail/SendMessageCC.cpp

[email protected] Thu, 07 Aug 2008 20:15:26 +0000
Newsgroups gmane.mail.mahogany.cvs
Message-ID <[email protected]>
Revision: 7532
          http://mahogany.svn.sourceforge.net/mahogany/?rev=7532&view=rev
Author:   vadz
Date:     2008-08-07 20:15:25 +0000 (Thu, 07 Aug 2008)

Log Message:
-----------
fix bug with failing to encode (hence possibly truncating) attachments with embedded nul bytes and just ASCII characters before them

Modified Paths:
--------------
    trunk/M/src/mail/SendMessageCC.cpp

Modified: trunk/M/src/mail/SendMessageCC.cpp
===================================================================
--- trunk/M/src/mail/SendMessageCC.cpp	2008-08-07 20:04:52 UTC (rev 7531)
+++ trunk/M/src/mail/SendMessageCC.cpp	2008-08-07 20:15:25 UTC (rev 7532)
@@ -681,16 +681,20 @@
 // SendMessageCC encodings
 // ----------------------------------------------------------------------------
 
-// Check if text can be sent without encoding it (using QP or Base64): for
-// this it must not contain 8bit chars and must not have too long lines
-static bool NeedsToBeEncoded(const unsigned char *text)
+// Check if the given data can be sent without encoding it (using QP or
+// Base64): for this it must not contain 8bit chars nor embedded NUL chars and
+// must not have too long lines
+static bool Is7BitText(const unsigned char *text, size_t len)
 {
    if ( !text )
-      return false;
+      return true;
 
    size_t lenLine = 0;
-   while ( *text )
+   for ( size_t n = 0; n < len; n++ )
    {
+      if ( *text == '\0' )
+         return false;
+
       if ( *text == '\n' )
       {
          lenLine = 0;
@@ -699,15 +703,15 @@
       }
 
       if ( !isascii(*text++) )
-         return true;
+         return false;
 
       // the real limit is bigger (~990) but chances are that anything with
       // lines of such length is not plain text
       if ( ++lenLine > 800 )
-         return true;
+         return false;
    }
 
-   return false;
+   return true;
 }
 
 // ----------------------------------------------------------------------------
@@ -1396,7 +1400,7 @@
       case TYPETEXT:
          // if the actual message text is in 7 bit, avoid encoding it even if
          // some charset which we would have normally encoded was used
-         if ( !NeedsToBeEncoded(data) )
+         if ( Is7BitText(data, len) )
          {
             bdy->encoding = ENC7BIT;
          }
@@ -1439,7 +1443,7 @@
          break;
 
       default:
-         bdy->encoding = NeedsToBeEncoded(data) ? ENCBINARY : ENC7BIT;
+         bdy->encoding = Is7BitText(data, len) ? ENC7BIT : ENCBINARY;
    }
 
    PARAMETER *lastpar = NULL,


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 the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/