Update of /cvsroot/mahogany/M/src/mail
In directory sc8-pr-cvs1:/tmp/cvs-serv18875/src/mail

Modified Files:
        MessageCC.cpp 
Log Message:
MimePart::GetContent() doesn't copy data once again (inefficient!) any more; separate 
GetTextContent() which does it was added; yet another bug in handling base64 data fixed

Index: MessageCC.cpp
===================================================================
RCS file: /cvsroot/mahogany/M/src/mail/MessageCC.cpp,v
retrieving revision 1.141
retrieving revision 1.142
diff -b -u -2 -r1.141 -r1.142
--- MessageCC.cpp       25 Feb 2003 12:58:20 -0000      1.141
+++ MessageCC.cpp       12 Jul 2003 18:57:44 -0000      1.142
@@ -107,4 +107,6 @@
    m_msgText = NULL;
 
+   m_ownsPartContent = false;
+
    m_folder = NULL;
    m_Profile = NULL;
@@ -192,4 +194,5 @@
    delete m_mimePartTop;
 
+   if ( m_ownsPartContent )
    fs_give(&m_partContentPtr);
 
@@ -945,11 +948,11 @@
 MessageCC::GetPartData(const MimePart& mimepart, unsigned long *lenptr)
 {
+   CHECK( lenptr, NULL, _T("MessageCC::GetPartData(): NULL len ptr") );
+
    // first get the raw text
    // ----------------------
 
-   unsigned long len = 0;
-   const char *cptr = GetRawPartData(mimepart, &len);
-
-   if ( !len )
+   const char *cptr = GetRawPartData(mimepart, lenptr);
+   if ( !cptr || !*lenptr )
       return NULL;
 
@@ -957,20 +960,15 @@
    // -------------
 
-   // ensure that lenptr is always valid -- this is simpler than testing it all
-   // the time
-   if ( !lenptr )
-      lenptr = &len;
-
    // free old text
+   if (m_ownsPartContent )
+   {
+      m_ownsPartContent = false;
+
    fs_give(&m_partContentPtr);
+   }
 
    // total size of this message part
    unsigned long size = mimepart.GetSize();
 
-   // the size of possible extra non Base64 encoded text following a Base64
-   // encoded part
-   const unsigned char *startSlack = NULL;
-   size_t sizeSlack = 0;
-
    // just for convenience...
    unsigned char *text = (unsigned char *)cptr;
@@ -978,5 +976,40 @@
    switch ( mimepart.GetTransferEncoding() )
    {
+      case ENCQUOTEDPRINTABLE:   // human-readable 8-as-7 bit data
+         m_partContentPtr = rfc822_qprint(text, size, lenptr);
+
+         // some broken mailers sent messages with QP specified as the content
+         // transfer encoding in the headers but don't encode the message
+         // properly - in this case show it as plain text which is better than
+         // not showing it at all
+         if ( m_partContentPtr )
+         {
+            m_ownsPartContent = true;
+
+            break;
+         }
+         //else: treat it as plain text
+
+         // it was overwritten by rfc822_qprint() above
+         *lenptr = size;
+
+         // fall through
+
+      case ENC7BIT:        // 7 bit SMTP semantic data
+      case ENC8BIT:        // 8 bit SMTP semantic data
+      case ENCBINARY:      // 8 bit binary data
+      case ENCOTHER:       // unknown
+      default:
+         // nothing to do
+         m_partContentPtr = text;
+         break;
+
+
       case ENCBASE64:      // base-64 encoded data
+         // the size of possible extra non Base64 encoded text following a
+         // Base64 encoded part
+         const unsigned char *startSlack = NULL;
+         size_t sizeSlack = 0;
+
          // there is a frequent problem with mail list software appending the
          // mailing list footer (i.e. a standard signature containing the
@@ -1047,47 +1080,24 @@
 
          m_partContentPtr = rfc822_base64(text, size, lenptr);
+         if ( !m_partContentPtr )
+         {
+            FAIL_MSG( _T("rfc822_base64() failed") );
 
+            m_partContentPtr = text;
+         }
+         else // ok
+         {
+            // append the non Base64-encoded chunk, if any, to the end of decoded
+            // data
          if ( sizeSlack )
          {
             fs_resize(&m_partContentPtr, *lenptr + sizeSlack);
             memcpy((char *)m_partContentPtr + *lenptr, startSlack, sizeSlack);
-         }
-         break;
 
-      case  ENCBINARY:     // 8 bit binary data
-         // don't use string functions, string may contain NULs
-         *lenptr = size;
-         m_partContentPtr = fs_get(size + 1);
-         memcpy(m_partContentPtr, cptr, size);
-
-         // still NUL terminate it, though
-         ((char *)m_partContentPtr)[size] = '\0';
-         break;
-
-      case ENCQUOTEDPRINTABLE:   // human-readable 8-as-7 bit data
-         m_partContentPtr = rfc822_qprint(text, size, lenptr);
-
-         // some broken mailers sent messages with QP specified as the content
-         // transfer encoding in the headers but don't encode the message
-         // properly - in this case show it as plain text which is better than
-         // not showing it at all
-         if ( m_partContentPtr )
-            break;
-         //else: treat it as plain text
-
-         // len was overwritten by rfc822_qprint() above
-         len = size;
-
-         // fall through
+               *lenptr += sizeSlack;
+            }
 
-      case ENC7BIT:        // 7 bit SMTP semantic data
-      case ENC8BIT:        // 8 bit SMTP semantic data
-      case ENCOTHER:       // unknown
-      default:
-         // string is not NUL-terminated, use the length returned by c-client!
-         *lenptr = len;
-         m_partContentPtr = fs_get(len + 1);
-         memcpy(m_partContentPtr, cptr, len);
-         ((char *)m_partContentPtr)[len] = '\0';
+            m_ownsPartContent = true;
+         }
    }
 
@@ -1108,4 +1118,18 @@
 {
    return GetMessage()->GetPartHeaders(*this);
+}
+
+String MimePartCC::GetTextContent() const
+{
+   unsigned long len;
+   const char *p = reinterpret_cast<const char *>(GetContent(&len));
+   if ( !p )
+      return wxGetEmptyString();
+
+#if wxUSE_UNICODE
+   #error "We need the original encoding here, TODO"
+#else // ANSI
+   return wxString(p, len);
+#endif // Unicode/ANSI
 }
 



-------------------------------------------------------
This SF.Net email sponsored by: Parasoft
Error proof Web apps, automate testing & more.
Download & eval WebKing and get a free book.
www.parasoft.com/bulletproofapps1
_______________________________________________
Mahogany-cvsupdates mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/mahogany-cvsupdates

Reply via email to