[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kmail-devel
Subject:    nested messages patch
From:       Sven Carstens <s.carstens () gmx ! de>
Date:       2000-12-18 12:26:24
[Download RAW message or body]

This is a Multipart-Message in MIME format.


As always my fault :(.

Here is the (now better) updated patch.
With an extra bonus: uuencoded parts.

The todo list stays the same (mAtmCurrent).

CU Sven

["kmail.patch" (TEXT/X-C++)]

diff -u /usr/src/kde-2.0/kdenetwork/kmail/kmmessage.cpp ./kmmessage.cpp
--- /usr/src/kde-2.0/kdenetwork/kmail/kmmessage.cpp	Fri Dec  8 20:02:50 2000
+++ ./kmmessage.cpp	Sat Dec 16 17:40:26 2000
@@ -1768,6 +1768,9 @@
     else
       aPart->setContentDisposition("");
 
+    // original Headerfields
+    aPart->setHeader(headers->AsString().c_str());
+
     // Body
     aPart->setBody(part->Body().AsString().c_str());
   }
diff -u /usr/src/kde-2.0/kdenetwork/kmail/kmmsgpart.cpp ./kmmsgpart.cpp
--- /usr/src/kde-2.0/kdenetwork/kmail/kmmsgpart.cpp	Wed Nov 29 18:19:03 2000
+++ ./kmmsgpart.cpp	Sat Dec 16 17:40:26 2000
@@ -9,6 +9,7 @@
 #include <kstddirs.h>
 #include <kiconloader.h>
 #include <kdebug.h>
+#include <kmimetype.h>
 
 #include "kmmsgbase.h"
 #include "kmmsgpart.h"
@@ -49,6 +50,15 @@
   return mBodySize;
 }
 
+//-----------------------------------------------------------------------------
+void KMMessagePart::setHeader(const QString aStr)
+{
+  int len = aStr.length();
+
+  mHeader.truncate(len+1);
+  memcpy(mHeader.data(), (const char *)aStr, len);
+  mHeader[len] = 0;
+}
 
 //-----------------------------------------------------------------------------
 void KMMessagePart::setBody(const QString aStr)
@@ -223,9 +233,12 @@
 const QString KMMessagePart::iconName(void) const
 {
   QString fileName;
-  fileName = KGlobal::instance()->iconLoader()->iconPath( mType.lower(), \
                KIcon::Desktop );
-  if (fileName.isEmpty())
-    fileName = KGlobal::instance()->iconLoader()->iconPath( "unknown", \
KIcon::Desktop ); +
+	fileName = KMimeType::mimeType(typeStr().lower()+"/"+subtypeStr().lower())->icon(QString::null,false);
 +	fileName = KGlobal::instance()->iconLoader()->iconPath( fileName, KIcon::Desktop \
); +//  fileName = KGlobal::instance()->iconLoader()->iconPath( mType.lower(), \
KIcon::Desktop ); +//  if (fileName.isEmpty())
+//    fileName = KGlobal::instance()->iconLoader()->iconPath( "unknown", \
KIcon::Desktop );  return fileName;
 }
 
@@ -388,11 +401,16 @@
 
  
 //-----------------------------------------------------------------------------
+const QString KMMessagePart::header(void) const
+{
+  return mHeader;
+}
+
+//-----------------------------------------------------------------------------
 const QString KMMessagePart::body(void) const
 {
   return mBody;
 }
-
 
 //-----------------------------------------------------------------------------
 const QString KMMessagePart::name(void) const
diff -u /usr/src/kde-2.0/kdenetwork/kmail/kmmsgpart.h ./kmmsgpart.h
--- /usr/src/kde-2.0/kdenetwork/kmail/kmmsgpart.h	Wed Nov 29 10:14:57 2000
+++ ./kmmsgpart.h	Sat Dec 16 17:40:26 2000
@@ -20,6 +20,10 @@
   const QString body(void) const;
   void setBody(const QString aStr);
 
+  /** Get or set the original headers body */
+  const QString header(void) const;
+  void setHeader(const QString aStr);
+
   /** Returns body as decoded string. Assumes that content-transfer-encoding
     contains the correct encoding. This routine is meant for binary data.
     No trailing 0 is appended. */
@@ -112,6 +116,7 @@
                      // misuse it as a QCString. Really the callers
                      // should be fixed like in kmreaderwin.cpp.
                      // mBody should not be QCString since it can be binary.
+  QByteArray mHeader;
   QString mName;
   QString mCharset;
   int mBodySize;
diff -u /usr/src/kde-2.0/kdenetwork/kmail/kmreaderwin.cpp ./kmreaderwin.cpp
--- /usr/src/kde-2.0/kdenetwork/kmail/kmreaderwin.cpp	Sun Dec 17 20:37:41 2000
+++ ./kmreaderwin.cpp	Mon Dec 18 13:19:59 2000
@@ -549,17 +549,7 @@
 void KMReaderWin::parseMsg(KMMessage* aMsg)
 {
   KMMessagePart msgPart;
-  int i, numParts;
-  QString type, subtype, contDisp;
-  QByteArray str;
-  bool asIcon = false;
-  inlineImage = false;
   VCard *vc;
-
-  assert(aMsg!=NULL);
-  type = aMsg->typeStr();
-  numParts = aMsg->numBodyParts();
-
   // Hrm we have to iterate this twice with the current design.  This
   // should really be fixed.  (FIXME)
   int vcnum = -1;
@@ -578,132 +568,215 @@
         }
     }
   }
+	mViewer->write(getMsgHeader(aMsg,vcnum));
+
+	mViewer->write(getMsg(aMsg,""));
+}
+
+//-----------------------------------------------------------------------------
+QString KMReaderWin::getMsg(KMMessage* aMsg,QString prefix)
+{
+  KMMessagePart msgPart;
+  int i, numParts;
+  QString type, subtype, contDisp;
+  QByteArray str;
+  bool asIcon = false;
+  inlineImage = false;
+  QString retVal;
+  
+  assert(aMsg!=NULL);
+  type = aMsg->typeStr().lower();
+  subtype = aMsg->subtypeStr().lower();
+  numParts = aMsg->numBodyParts();
+
+
+	kdDebug() << "parseMsg: type: " << type.data() << endl;
+	kdDebug() << "parseMsg: subtype: " << subtype.data() << endl;
+	kdDebug() << "parseMsg: #attachments " << numParts << endl;
+
 
-  writeMsgHeader(vcnum);
 
   if (numParts > 0)
   {
-    // ---sven: handle multipart/alternative start ---
-    // This is for multipart/alternative messages WITHOUT attachments
-    // main header has type=multipart/alternative and one attachment is
-    // text/html
-    if (type.find("multipart/alternative") != -1 && numParts == 2)
+	QStringList ourParts;
+	QString alternativPartStr;
+	QString alternativType;
+	int alternativPart = -1;
+		
+    for (i=0; i<numParts; i++)
     {
-      kdDebug() << "Alternative message, type: " << type.data() << endl;
-      //Now: Only two attachments one of them is html
-      for (i=0; i<2; i++)                   // count parts...
-      {
-        aMsg->bodyPart(i, &msgPart);        // set part...
-        subtype = msgPart.subtypeStr();     // get subtype...
-        if (htmlMail() && stricmp(subtype, "html")==0)    // is it html?
-        {                                   // yes...
-          str = msgPart.bodyDecoded();      // decode it...
-          mViewer->write(mCodec->toUnicode(str.data()));    // write it...
-          return;                           // return, finshed.
-        }
-	else if (!htmlMail() && (stricmp(subtype, "plain")==0))
-	                                    // wasn't html show only if
-	{                                   // support for html is turned off
-          str = msgPart.bodyDecoded();      // decode it...
-          writeBodyStr(str.data());
-          return;
+		switch (mAttachmentStyle)
+		{
+			case IconicAttmnt:
+				asIcon=TRUE; break;
+			case InlineAttmnt:
+				asIcon=FALSE; break;
+			case SmartAttmnt:
+				asIcon=(contDisp.find("inline")<0);
+		}
+
+		aMsg->bodyPart(i, &msgPart);
+		if(type.find("multipart/alternative",0,false) == 0 && \
msgPart.typeStr().find("text",0,false)==0) +		{
+			// append it iconified
+			ourParts.append(getMsgPart(msgPart,prefix+QString().setNum(i+1),true));
+
+			// choose one alternative text part
+			if(alternativPart == -1)
+			{
+				alternativPart = i;
+				alternativPartStr = getMsgPart(msgPart,prefix+QString().setNum(i+1),false);
+				alternativType = msgPart.subtypeStr();
+			}
+			else
+			{
+				// see if it is something we prefer
+		        if (htmlMail() && (msgPart.subtypeStr().find("html",0,false)==0))    // is \
it html? +				{
+					alternativPart = i;
+					alternativPartStr = getMsgPart(msgPart,prefix+QString().setNum(i+1),false);
+					alternativType = msgPart.subtypeStr();
+				} else if (!htmlMail() && (msgPart.subtypeStr().find("plain",0,false)==0)) {
+					alternativPart = i;
+					alternativPartStr = getMsgPart(msgPart,prefix+QString().setNum(i+1),false);
+					alternativType = msgPart.subtypeStr();
+				}
+			}
+		} else if(type.find("multipart/",0,false) == 0 && \
msgPart.typeStr().find("text",0,false)==0) { +			// show any text in all other parts
+			ourParts.append(getMsgPart(msgPart,prefix+QString().setNum(i+1),false));
+		} else {
+			// this is the default choice
+			ourParts.append(getMsgPart(msgPart,prefix+QString().setNum(i+1),asIcon));
+		}
+	}
+	//remove the alternativ part of our choice from the list
+	//and add the not iconified representation to the front
+	if(alternativPart != -1)
+	{
+		ourParts.remove(ourParts.at(alternativPart));
+		ourParts.prepend(alternativPartStr);
 	}
-      }
-      // if we are here we didnt find any html part. Handle it normaly then
-    }
-    // This works only for alternative msgs without attachments. Alternative
-    // messages with attachments are broken with or without this. No need
-    // to bother with strib </body> or </html> here, because if any part
-    // follows this will not be shown correctly. You'll still be able to read the
-    // main message and deal with attachments. Nothing I can do now :-(
-    // ---sven: handle multipart/alternative end ---
 
-    for (i=0; i<numParts; i++)
-    {
-      aMsg->bodyPart(i, &msgPart);
-      type = msgPart.typeStr();
-      subtype = msgPart.subtypeStr();
-      contDisp = msgPart.contentDisposition();
-      kdDebug() << "type: " << type.data() << endl;
-      kdDebug() << "subtye: " << subtype.data() << endl;
-      kdDebug() << "contDisp " << contDisp.data() << endl;
+	//finally assemble it
+	if(!prefix.isEmpty()) retVal += "<TABLE BORDER=1>";
+	for ( QStringList::Iterator it = ourParts.begin(); it != ourParts.end(); ++it ) {
+		if(!prefix.isEmpty()) retVal += "<TR><TD>";
+		retVal += (*it);
+		if(!prefix.isEmpty()) retVal += "</TD></TR>";
+	}
+	if(!prefix.isEmpty()) retVal += "</TABLE>";
+  }
+  else // if numBodyParts <= 0
+  {
+    if (htmlMail() && ((type == "text/html") || (type.find("text/html") != -1)))
+      retVal += aMsg->bodyDecoded();
+    else
+      retVal += getBodyStr(aMsg->bodyDecoded());
+  }
 
-      if (i <= 0) asIcon = FALSE;
-      else switch (mAttachmentStyle)
-      {
-      case IconicAttmnt:
-        asIcon=TRUE; break;
-      case InlineAttmnt:
-        asIcon=FALSE; break;
-      case SmartAttmnt:
-        asIcon=(contDisp.find("inline")<0);
-      }
+  return retVal;
+}
 
-      if (!asIcon)
-      {
-//	if (i<=0 || stricmp(type, "text")==0)//||stricmp(type, "message")==0)
-//	if (stricmp(type, "text")==0)//||stricmp(type, "message")==0)
-	if ((type == "") || (stricmp(type, "text")==0))
+
+// returns the HTML representation of a part
+//-----------------------------------------------------------------------------
+QString KMReaderWin::getMsgPart(KMMessagePart &msgPart,QString partSpecifier,bool \
asIcon) +{
+	QString type,subtype,contDisp,retVal;
+		
+	type = msgPart.typeStr();
+	subtype = msgPart.subtypeStr();
+	contDisp = msgPart.contentDisposition();
+	kdDebug() << "type: " << type.data() << endl;
+	kdDebug() << "subtye: " << subtype.data() << endl;
+	kdDebug() << "contDisp " << contDisp.data() << endl;
+
+	// see if we should parse it recursively
+	if(!stricmp(type,"multipart"))
 	{
-          QCString cstr(msgPart.bodyDecoded());
-	  if (i>0)
-	      mViewer->write("<br><hr><br>");
-
-	  if (htmlMail() && (stricmp(subtype, "html")==0))
-          {
-            // ---Sven's strip </BODY> and </HTML> from end of attachment start-
-            // We must fo this, or else we will see only 1st inlined html attachment
-            // It is IMHO enough to search only for </BODY> and put \0 there.
-            int i;
-            i = cstr.findRev("</body>", -1, false); //case insensitive
-            if (i>0)
-              cstr.truncate(i);
-            else // just in case - search for </html>
-            {
-              i = cstr.findRev("</html>", -1, false); //case insensitive
-              if (i>0) cstr.truncate(i);
-            }
-            // ---Sven's strip </BODY> and </HTML> from end of attachment end-
-            mViewer->write(mCodec->toUnicode(cstr.data()));
-	  }
-          else writeBodyStr(cstr);
+		KMMessage* msg = new KMMessage;
+		msg->fromString(msgPart.header() + msgPart.body());
+		retVal = getMsg(msg,partSpecifier+".");
+		delete msg;
+		return retVal;
+	}
+	else if(!stricmp(type,"message") && !stricmp(subtype,"rfc822") && !asIcon)
+	{
+		KMMessage* msg = new KMMessage;
+		msg->fromString(msgPart.body());
+		retVal += getPartIcon(&msgPart, partSpecifier);
+		retVal += "<TABLE BORDER=1>";
+		retVal += getMsgHeader(msg);
+		retVal += getMsg(msg,partSpecifier+".");
+		retVal += "</TABLE>";
+		delete msg;
+		return retVal;
 	}
+	if (!asIcon)
+	{
+		if ((type == "") || (stricmp(type, "text")==0))
+		{
+			QCString cstr(msgPart.bodyDecoded());
+
+			if ( partSpecifier != "1" && partSpecifier.right(2) != ".1")
+				retVal = "<br><hr><br>";
+
+			if (htmlMail() && (stricmp(subtype, "html")==0))
+			{
+				// ---Sven's strip </BODY> and </HTML> from end of attachment start-
+				// We must fo this, or else we will see only 1st inlined html attachment
+				// It is IMHO enough to search only for </BODY> and put \0 there.
+				int i;
+				i = cstr.findRev("</body>", -1, false); //case insensitive
+				if (i>0)
+					cstr.truncate(i);
+				else // just in case - search for </html>
+				{
+					i = cstr.findRev("</html>", -1, false); //case insensitive
+					if (i>0) cstr.truncate(i);
+				}
+				// ---Sven's strip </BODY> and </HTML> from end of attachment end-
+				retVal += cstr.data();
+			} // end of strip body and html tag
+			else 
+				retVal += getBodyStr(cstr);
+		} // end of text type
         // ---Sven's view smart or inline image attachments in kmail start---
         else if (stricmp(type, "image")==0)
         {
-          inlineImage=true;
-          writePartIcon(&msgPart, i);
-          inlineImage=false;
+			inlineImage=true;
+			retVal += getPartIcon(&msgPart, partSpecifier);
+			inlineImage=false;
         }
         // ---Sven's view smart or inline image attachments in kmail end---
-	else asIcon = TRUE;
-      }
-      if (asIcon)
-      {
-        writePartIcon(&msgPart, i);
-      }
-    }
-  }
-  else // if numBodyParts <= 0
-  {
-    if (htmlMail() && ((type == "text/html") || (type.find("text/html") != -1)))
-      mViewer->write(mCodec->toUnicode(aMsg->bodyDecoded().data()));
-    else
-      writeBodyStr(aMsg->bodyDecoded());
-  }
-}
+		else asIcon = TRUE;
+	} // end of !asIcon
+	if (asIcon)
+	{
+		retVal += getPartIcon(&msgPart, partSpecifier);
+	}
 
+	return retVal;
+}
 
 //-----------------------------------------------------------------------------
 void KMReaderWin::writeMsgHeader(int vcpartnum)
 {
+	mViewer->write(getMsgHeader(mMsg,vcpartnum));
+}
+
+//-----------------------------------------------------------------------------
+QString KMReaderWin::getMsgHeader(KMMessage *aMsg,int vcpartnum)
+{
   QString str;
   QString vcname;
   KMMessagePart aMsgPart;
   QString vcFileName;
-
+  QString retVal;
+  
   if (vcpartnum >= 0) {
-    mMsg->bodyPart(vcpartnum, &aMsgPart);
+    aMsg->bodyPart(vcpartnum, &aMsgPart);
     vcFileName = aMsgPart.fileName();
     if (vcFileName.isEmpty()) {
       vcFileName = "/unnamed";
@@ -723,118 +796,127 @@
   switch (mHeaderStyle)
   {
     case HdrBrief:
-    mViewer->write("<font size=\"+1\"><b>" + strToHtml(mMsg->subject()) +
+    retVal += QString("<font size=\"+1\"><b>" + strToHtml(aMsg->subject()) +
                    "</b></font>&nbsp; (" +
-                   KMMessage::emailAddrAsAnchor(mMsg->from(),TRUE) + ", ");
-    if (!mMsg->cc().isEmpty())
-      mViewer->write(i18n("Cc: ")+
-                     KMMessage::emailAddrAsAnchor(mMsg->cc(),TRUE) + ", ");
-    mViewer->write("&nbsp;"+strToHtml(mMsg->dateShortStr()) + ")");
+                   KMMessage::emailAddrAsAnchor(aMsg->from(),TRUE) + ", ");
+    if (!aMsg->cc().isEmpty())
+      retVal += QString(i18n("Cc: ")+
+                     KMMessage::emailAddrAsAnchor(aMsg->cc(),TRUE) + ", ");
+    retVal += QString("&nbsp;"+strToHtml(aMsg->dateShortStr()) + ")");
     if (vcpartnum >= 0) {
-      mViewer->write("&nbsp;&nbsp;<a href=\""+vcname+"\">"+i18n("[vCard]")+"</a>");
+      retVal += QString("&nbsp;&nbsp;<a \
href=\""+vcname+"\">"+i18n("[vCard]")+"</a>");  }
-    mViewer->write("<br>\n");
+    retVal += QString("<br>\n");
     break;
 
   case HdrStandard:
-    mViewer->write("<font size=\"+1\"><b>" +
-                   strToHtml(mMsg->subject()) + "</b></font><br>\n");
-    mViewer->write(i18n("From: ") +
-                   KMMessage::emailAddrAsAnchor(mMsg->from(),FALSE));
+    retVal += QString("<font size=\"+1\"><b>" +
+                   strToHtml(aMsg->subject()) + "</b></font><br>\n");
+    retVal += QString(i18n("From: ") +
+                   KMMessage::emailAddrAsAnchor(aMsg->from(),FALSE));
     if (vcpartnum >= 0) {
-      mViewer->write("&nbsp;&nbsp;<a href=\""+vcname+"\">"+i18n("[vCard]")+"</a>");
+      retVal += QString("&nbsp;&nbsp;<a \
href=\""+vcname+"\">"+i18n("[vCard]")+"</a>");  }
-    mViewer->write("<br>\n");
-    mViewer->write(i18n("To: ") +
-                   KMMessage::emailAddrAsAnchor(mMsg->to(),FALSE) + "<br>\n");
-    if (!mMsg->cc().isEmpty())
-      mViewer->write(i18n("Cc: ")+
-                     KMMessage::emailAddrAsAnchor(mMsg->cc(),FALSE) + "<br>\n");
+    retVal += QString("<br>\n");
+    retVal += QString(i18n("To: ") +
+                   KMMessage::emailAddrAsAnchor(aMsg->to(),FALSE) + "<br>\n");
+    if (!aMsg->cc().isEmpty())
+      retVal += QString(i18n("Cc: ")+
+                     KMMessage::emailAddrAsAnchor(aMsg->cc(),FALSE) + "<br>\n");
 #ifdef KRN
-    if (!mMsg->references().isEmpty())
-        mViewer->write(i18n("References: ") +
-                       KMMessage::refsAsAnchor(mMsg->references()) + "<br>");
+    if (!aMsg->references().isEmpty())
+        retVal += QString(i18n("References: ") +
+                       KMMessage::refsAsAnchor(aMsg->references()) + "<br>");
 #endif
-    mViewer->write("<br>");
+    retVal += QString("<br>");
     break;
 
   case HdrFancy:
-    mViewer->write(QString("<table><tr><td><img src=") +
+    retVal += QString(QString("<table><tr><td><img src=") +
 		   locate("data", "kmail/pics/kdelogo.xpm") +
                    "></td><td hspace=\"50\"><b><font size=\"+2\">");
-    mViewer->write(strToHtml(mMsg->subject()) + "</font></b><br>");
-    mViewer->write(i18n("From: ")+
-                   KMMessage::emailAddrAsAnchor(mMsg->from(),FALSE));
+    retVal += QString(strToHtml(aMsg->subject()) + "</font></b><br>");
+    retVal += QString(i18n("From: ")+
+                   KMMessage::emailAddrAsAnchor(aMsg->from(),FALSE));
     if (vcpartnum >= 0) {
-      mViewer->write("&nbsp;&nbsp;<a href=\""+vcname+"\">"+i18n("[vCard]")+"</a>");
+      retVal += QString("&nbsp;&nbsp;<a \
href=\""+vcname+"\">"+i18n("[vCard]")+"</a>");  }
-    mViewer->write("<br>\n");
-    mViewer->write(i18n("To: ")+
-                   KMMessage::emailAddrAsAnchor(mMsg->to(),FALSE) + "<br>\n");
-    if (!mMsg->cc().isEmpty())
-      mViewer->write(i18n("Cc: ")+
-                     KMMessage::emailAddrAsAnchor(mMsg->cc(),FALSE) + "<br>\n");
-    mViewer->write(i18n("Date: ")+
-                   strToHtml(mMsg->dateStr()) + "<br>\n");
+    retVal += QString("<br>\n");
+    retVal += QString(i18n("To: ")+
+                   KMMessage::emailAddrAsAnchor(aMsg->to(),FALSE) + "<br>\n");
+    if (!aMsg->cc().isEmpty())
+      retVal += QString(i18n("Cc: ")+
+                     KMMessage::emailAddrAsAnchor(aMsg->cc(),FALSE) + "<br>\n");
+    retVal += QString(i18n("Date: ")+
+                   strToHtml(aMsg->dateStr()) + "<br>\n");
 #ifdef KRN
-    if (!mMsg->references().isEmpty())
-        mViewer->write(i18n("References: ") +
-                       KMMessage::refsAsAnchor(mMsg->references()) + "<br><br>\n");
+    if (!aMsg->references().isEmpty())
+        retVal += QString(i18n("References: ") +
+                       KMMessage::refsAsAnchor(aMsg->references()) + "<br><br>\n");
 #endif
-    mViewer->write("</b></td></tr></table><br>\n");
+    retVal += QString("</b></td></tr></table><br>\n");
     break;
 
   case HdrLong:
-    mViewer->write("<font size=\"+1\"><b>" +
-                   strToHtml(mMsg->subject()) + "</B></font><br>");
-    mViewer->write(i18n("Date: ")+strToHtml(mMsg->dateStr())+"<br>");
-    mViewer->write(i18n("From: ")+
-		   KMMessage::emailAddrAsAnchor(mMsg->from(),FALSE));
+    retVal += QString("<font size=\"+1\"><b>" +
+                   strToHtml(aMsg->subject()) + "</B></font><br>");
+    retVal += QString(i18n("Date: ")+strToHtml(aMsg->dateStr())+"<br>");
+    retVal += QString(i18n("From: ")+
+		   KMMessage::emailAddrAsAnchor(aMsg->from(),FALSE));
     if (vcpartnum >= 0) {
-      mViewer->write("&nbsp;&nbsp;<a href=\""+vcname+"\">"+i18n("[vCard]")+"</a>");
+      retVal += QString("&nbsp;&nbsp;<a \
href=\""+vcname+"\">"+i18n("[vCard]")+"</a>");  }
-    mViewer->write("<br>\n");
-    mViewer->write(i18n("To: ")+
-                   KMMessage::emailAddrAsAnchor(mMsg->to(),FALSE) + "<br>");
-    if (!mMsg->cc().isEmpty())
-      mViewer->write(i18n("Cc: ")+
-		     KMMessage::emailAddrAsAnchor(mMsg->cc(),FALSE) + "<br>");
-    if (!mMsg->bcc().isEmpty())
-      mViewer->write(i18n("Bcc: ")+
-		     KMMessage::emailAddrAsAnchor(mMsg->bcc(),FALSE) + "<br>");
-    if (!mMsg->replyTo().isEmpty())
-      mViewer->write(i18n("Reply to: ")+
-		     KMMessage::emailAddrAsAnchor(mMsg->replyTo(),FALSE) + "<br>");
+    retVal += QString("<br>\n");
+    retVal += QString(i18n("To: ")+
+                   KMMessage::emailAddrAsAnchor(aMsg->to(),FALSE) + "<br>");
+    if (!aMsg->cc().isEmpty())
+      retVal += QString(i18n("Cc: ")+
+		     KMMessage::emailAddrAsAnchor(aMsg->cc(),FALSE) + "<br>");
+    if (!aMsg->bcc().isEmpty())
+      retVal += QString(i18n("Bcc: ")+
+		     KMMessage::emailAddrAsAnchor(aMsg->bcc(),FALSE) + "<br>");
+    if (!aMsg->replyTo().isEmpty())
+      retVal += QString(i18n("Reply to: ")+
+		     KMMessage::emailAddrAsAnchor(aMsg->replyTo(),FALSE) + "<br>");
 #ifdef KRN
-    if (!mMsg->references().isEmpty())
-        mViewer->write(i18n("References: ")+
-                       KMMessage::refsAsAnchor(mMsg->references()) + "<br>\n");
-    if (!mMsg->groups().isEmpty())
-        mViewer->write(i18n("Groups: ") + mMsg->groups()+"<br>\n");
+    if (!aMsg->references().isEmpty())
+        retVal += QString(i18n("References: ")+
+                       KMMessage::refsAsAnchor(aMsg->references()) + "<br>\n");
+    if (!aMsg->groups().isEmpty())
+        retVal += QString(i18n("Groups: ") + aMsg->groups()+"<br>\n");
 #endif
-    mViewer->write("<br>\n");
+    retVal += QString("<br>\n");
     break;
 
   case HdrAll:
-    str = strToHtml(mMsg->headerAsString());
-    mViewer->write(str);
-    mViewer->write("\n<br>\n");
+    str = strToHtml(aMsg->headerAsString());
+    retVal += QString(str);
+    retVal += QString("\n<br>\n");
     if (vcpartnum >= 0) {
-      mViewer->write("<a href=\""+vcname+"\">"+i18n("[vCard]")+"</a>");
+      retVal += QString("<a href=\""+vcname+"\">"+i18n("[vCard]")+"</a>");
     }
-    mViewer->write("\n<br>\n");
+    retVal += QString("\n<br>\n");
     break;
 
   default:
     qWarning("Unsupported header style %d", mHeaderStyle);
   }
-  mViewer->write("<br>\n");
+  retVal += QString("<br>\n");
+  
+  return retVal;
 }
 
 
 //-----------------------------------------------------------------------------
 void KMReaderWin::writeBodyStr(const QCString aStr)
 {
+	mViewer->write(getBodyStr(aStr));
+}
+
+//-----------------------------------------------------------------------------
+QString KMReaderWin::getBodyStr(const QCString inStr)
+{
+	QCString aStr = inStr;
   QString line, sig, htmlStr = "";
   Kpgp* pgp = Kpgp::getKpgp();
   assert(pgp != NULL);
@@ -896,8 +978,31 @@
     } // if (!pgpMessage) then the message only looked similar to a pgp message
     else htmlStr = mCodec->toUnicode(quotedHTML(aStr));
   }
-  else htmlStr += mCodec->toUnicode(quotedHTML(aStr));
-  mViewer->write(htmlStr);
+  else if(!aStr.isEmpty())
+  {
+	QString aFileName,aIcon,aHref,aMimeType;
+	int startPos;
+	QString aAnchor;
+
+	if(getUUPart(aStr,&aFileName,&aHref,&aIcon,&aMimeType,&startPos))
+	{
+	  	aStr.insert(startPos,"THANXFORALLTHEFISH");
+  		htmlStr += mCodec->toUnicode(quotedHTML(aStr.data()));
+  		aAnchor = aIcon;
+  		if(!strncmp("image",aMimeType,5))
+  		{
+    	  aAnchor += "<IMG SRC=\"";
+    	  aAnchor += aHref;
+    	  aAnchor += "\"></IMG>";
+  		}
+
+  		htmlStr.replace(QRegExp("THANXFORALLTHEFISH"),aAnchor);
+	} else {
+  	  htmlStr += mCodec->toUnicode(quotedHTML(aStr.data()));
+	}
+  }
+
+  return htmlStr;
 }
 
 
@@ -995,15 +1100,21 @@
 //-----------------------------------------------------------------------------
 void KMReaderWin::writePartIcon(KMMessagePart* aMsgPart, int aPartNum)
 {
+	mViewer->write(getPartIcon(aMsgPart,QString().setNum(aPartNum+1)));
+}
+
+//-----------------------------------------------------------------------------
+QString KMReaderWin::getPartIcon(KMMessagePart* aMsgPart, QString partSpecifier)
+{
   QString iconName, href, label, comment, contDisp;
   QString fileName;
 
   if(aMsgPart == NULL) {
     kdDebug() << "writePartIcon: aMsgPart == NULL\n" << endl;
-    return;
+    return QString::null;
   }
 
-  kdDebug() << "writePartIcon: PartNum: " << aPartNum << endl;
+  kdDebug() << "writePartIcon: PartNum: " << partSpecifier << endl;
 
   comment = aMsgPart->contentDescription();
 
@@ -1018,7 +1129,7 @@
 //--- Sven's save attachments to /tmp start ---
   bool ok = true;
 
-  QString fname = QString("%1part%2").arg(mAttachDir).arg(aPartNum+1);
+  QString fname = QString("%1part%2").arg(mAttachDir).arg(partSpecifier);
   if (access(fname.data(), W_OK) != 0) // Not there or not writable
     if (mkdir(fname.data(), 0) != 0 || chmod (fname.data(), S_IRWXU) != 0)
       ok = false; //failed create
@@ -1047,11 +1158,13 @@
   if (ok)
   {
     href = QString("file:")+fname;
-    //debug ("Wrote attachment to %s", href.data());
+    kdDebug() << "Wrote attachment to " << href << endl;
+    kdDebug() << "fileName " << fileName << endl;
+    kdDebug() << "label " << label << endl;
   }
   else {
     //--- Sven's save attachments to /tmp end ---
-    href = QString("part://%1").arg(aPartNum+1);
+    href = QString("part://%1").arg(partSpecifier);
   }
 
   // sven: for viewing images inline
@@ -1064,7 +1177,7 @@
     aMsgPart->magicSetType();
     iconName = aMsgPart->iconName();
   }
-  mViewer->write("<table><tr><td><a href=\"" + href + "\"><img src=\"" +
+  return QString("<table><tr><td><a href=\"" + href + "\"><img src=\"" +
 		 iconName + "\" border=\"0\">" + label +
 		 "</a></td></tr></table>" + comment + "<br>");
 }
@@ -1233,6 +1346,7 @@
     if (i > 0)
        num = num.left(i);
 
+	if(num.find('.') != -1) return -1;
     return num.toInt();
   }
   return -1;
@@ -1727,6 +1841,68 @@
 bool KMReaderWin::htmlMail()
 {
   return ((mHtmlMail && !mHtmlOverride) || (!mHtmlMail && mHtmlOverride));
+}
+
+//-----------------------------------------------------------------------------
+bool KMReaderWin::getUUPart(QCString &aStr,QString *aFilename,QString \
*aLocation,QString *aIcon,QString *aMimeType,int *aPosition) +{		
+		QRegExp uuBegin("\r?\nbegin [0-9][0-9][0-9] [^ \r\n]+\r?\n");
+		int posBegin,lenBegin;
+		QCString uuPart;
+				
+		posBegin = uuBegin.match(aStr,0,&lenBegin);
+		if( posBegin != -1 )
+		{
+			int curLine = posBegin+lenBegin;
+			int lenLine,posLine;
+			QRegExp uuLine("M............................................................");
+			QRegExp uuLast(".*\r?\n\x60\r?\nend");
+			
+			kdDebug() << "KMReaderWin::getUUPart - matched uudecode begin at " << posBegin << \
" - " << lenBegin << endl; +			uuPart = aStr.mid(posBegin,lenBegin);
+			posLine = uuLine.match(aStr,curLine,&lenLine);
+			while( posLine != -1 )
+			{
+//				debug("KMReaderWin::getUUPart - matched uudecode line at %d \
[%d]",posLine,lenLine); +				curLine = posLine+lenLine;
+				posLine = uuLine.match(aStr,curLine,&lenLine);
+			}
+			posLine = uuLast.match(aStr,curLine,&lenLine);
+			if( posLine != -1 )
+			{
+				kdDebug() << "KMReaderWin::getUUPart - matched uudecode end at " << posLine << " \
- " <<lenLine << endl; +				DwUuencode mEncoder;
+				QString aHref,mMimeType;
+				KMMessagePart aMsgPart;
+				QByteArray body;
+				
+				mEncoder.SetAsciiChars( DwString( aStr.mid(posBegin,posLine+lenLine-posBegin) ) \
); +				mEncoder.Decode();
+				body.duplicate(mEncoder.BinaryChars().data(),mEncoder.BinaryChars().size());
+		        aMsgPart.setName( mEncoder.FileName() );
+      			aMsgPart.setCteStr("8bit");
+		        aMsgPart.setBodyEncodedBinary(body);
+		        aMsgPart.setContentDisposition("inline");
+//      		aMsgPart.setFilename(mEncoder.FileName() );
+				aMsgPart.magicSetType();
+				mMimeType = aMsgPart.typeStr() + "/" + aMsgPart.subtypeStr();
+		    	kByteArrayToFile(aMsgPart.bodyDecodedBinary(), aHref, false, false, false);
+				
+				aStr.replace(posBegin,posLine+lenLine-posBegin,"");
+			  if(aPosition) *aPosition = posBegin;
+			  if(aMimeType) *aMimeType = mMimeType;
+			  inlineImage = !(mAttachmentStyle == IconicAttmnt);
+			  if(aIcon) *aIcon = getPartIcon(&aMsgPart,"uuencoded");
+			  inlineImage=false;
+			  if(aLocation) *aLocation = aHref;
+			  if(aFilename) *aFilename = mEncoder.FileName();
+				kdDebug() << "KMReaderWin::getUUPart - " << mEncoder.FileName() << " as " << \
aHref << " " << mMimeType << endl; +			  return true;
+			} else {
+			  return false;
+			}
+		}
+	  return false;
 }
 
 //-----------------------------------------------------------------------------
diff -u /usr/src/kde-2.0/kdenetwork/kmail/kmreaderwin.h ./kmreaderwin.h
--- /usr/src/kde-2.0/kdenetwork/kmail/kmreaderwin.h	Wed Dec  6 11:06:23 2000
+++ ./kmreaderwin.h	Mon Dec 18 13:20:07 2000
@@ -176,19 +176,25 @@
 
   /** Parse given message and add it's contents to the reader window. */
   virtual void parseMsg(KMMessage* msg);
+  virtual QString getMsg(KMMessage* msg,QString prefix);
+
+  virtual QString getMsgPart(KMMessagePart &msgPart,QString partSpecifier,bool \
asIcon);  
   /** Creates a nice mail header depending on the current selected
     header style. */
   virtual void writeMsgHeader(int vcpartnum = -1);
+  virtual QString getMsgHeader(KMMessage *aMsg,int vcpartnum = -1);
 
   /** Feeds the HTML widget with the contents of the given message-body
     string. May contain body parts. */
   virtual void writeBodyStr(const QCString bodyString);
+  virtual QString getBodyStr(const QCString bodyString);
 
   /** Create a nice icon with comment and name for the given
     body part, appended to the HTML view. Content type and subtype
     are set afterwards if they were not before. */
   virtual void writePartIcon(KMMessagePart* msgPart, int partNumber);
+  virtual QString getPartIcon(KMMessagePart* msgPart, QString partSpecifier);
 
   /** Convert given string to HTML. Converts blanks and tabs at
     beginning of line to non-breakable spaces if preserveLeadingBlanks
@@ -217,6 +223,8 @@
 protected:
   QString colorToString(const QColor&);
   QString getAtmFilename(QString pname, QString msgpartname);
+
+  bool getUUPart(QCString &aStr,QString *aFilename=NULL,QString \
*aLocation=NULL,QString *aIcon=NULL,QString *aMimeType=NULL,int *aPosition=NULL);  
   bool mHtmlMail, mHtmlOverride;
   int mAtmInline;



_______________________________________________
Kmail Developers mailing list
Kmail@master.kde.org
http://master.kde.org/mailman/listinfo/kmail


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic