[Bug 94724] Integrate ktnef into kmail

Volker Krause <[email protected]>
Newsgroups gmane.comp.kde.devel.kmail,gmane.spam.detected
Message-ID <[email protected]>
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.
         
http://bugs.kde.org/show_bug.cgi?id=94724         
vkrause kde org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |FIXED



------- Additional Comments From vkrause kde org  2007-04-03 23:01 -------
SVN commit 650109 by vkrause:

Merge inline-viewing of TNEF attachments from the KDE PIM enterprise
branch.

FEATURE: 94724

Approved by Ingo and Allen.


 M  +1 -0      Makefile.am  
 M  +4 -2      bodypartformatter.cpp  
 M  +21 -14    kmreaderwin.cpp  
 M  +8 -1      kmreaderwin.h  
 M  +73 -0     objecttreeparser.cpp  
 M  +2 -1      objecttreeparser.h  


--- branches/KDE/3.5/kdepim/kmail/Makefile.am #650108:650109
 @ -14,6 +14,7  @
 	-I$(top_srcdir)/certmanager/lib \
         -I$(top_srcdir)/certmanager/lib/ui \
         -I$(top_srcdir)/indexlib \
+        -I$(top_srcdir)/ktnef \
         -I$(top_srcdir) \
         $(GPGME_CFLAGS) \
         $(all_includes)
--- branches/KDE/3.5/kdepim/kmail/bodypartformatter.cpp #650108:650109
 @ -114,6 +114,7  @
   CREATE_BODY_PART_FORMATTER(ApplicationPkcs7Mime)
   CREATE_BODY_PART_FORMATTER(ApplicationChiasmusText)
   //CREATE_BODY_PART_FORMATTER(ApplicationPgp)
+  CREATE_BODY_PART_FORMATTER(ApplicationMsTnef)
 
   CREATE_BODY_PART_FORMATTER(MessageRfc822)
 
 @ -147,6 +148,7  @
   { "x-pkcs7-mime", &ApplicationPkcs7MimeBodyPartFormatter::create },
   { "vnd.de.bund.bsi.chiasmus-text", &ApplicationChiasmusTextBodyPartFormatter::create },
   { "pgp", &ApplicationPgpBodyPartFormatter::create },
+  { "ms-tnef", &ApplicationMsTnefBodyPartFormatter::create }
 };
 
 static const SubtypeBuiltin textSubtypeBuiltins[] = {
 @ -286,8 +288,8  @
       break;
     case 'm':
     case 'M':
-      //if ( kasciistricmp( subtype, "ms-tnef" ) == 0 )
-      //  return ApplicationMsTnefBodyPartFormatter::create();
+      if ( kasciistricmp( subtype, "ms-tnef" ) == 0 )
+        return ApplicationMsTnefBodyPartFormatter::create();
       break;
     case 'v':
     case 'V':
--- branches/KDE/3.5/kdepim/kmail/kmreaderwin.cpp #650108:650109
 @ -1679,21 +1679,10  @
     fileName = aMsgPart->name();
 
   //--- Sven's save attachments to /tmp start ---
-  KTempFile *tempFile = new KTempFile( QString::null,
-                                       "." + QString::number( aPartNum ) );
-  tempFile->setAutoDelete( true );
-  QString fname = tempFile->name();
-  delete tempFile;
+  QString fname = createTempDir( QString::number( aPartNum ) );
+  if ( fname.isEmpty() )
+    return QString();
 
-  if( ::access( QFile::encodeName( fname ), W_OK ) != 0 )
-    // Not there or not writable
-    if( ::mkdir( QFile::encodeName( fname ), 0 ) != 0
-        || ::chmod( QFile::encodeName( fname ), S_IRWXU ) != 0 )
-      return QString::null; //failed create
-
-  assert( !fname.isNull() );
-
-  mTempDirs.append( fname );
   // strip off a leading path
   int slashPos = fileName.findRev( '/' );
   if( -1 != slashPos )
 @ -1719,7 +1708,25  @
   return fname;
 }
 
+QString KMReaderWin::createTempDir( const QString &param )
+{
+  KTempFile *tempFile = new KTempFile( QString::null, "." + param );
+  tempFile->setAutoDelete( true );
+  QString fname = tempFile->name();
+  delete tempFile;
 
+  if( ::access( QFile::encodeName( fname ), W_OK ) != 0 )
+    // Not there or not writable
+    if( ::mkdir( QFile::encodeName( fname ), 0 ) != 0
+        || ::chmod( QFile::encodeName( fname ), S_IRWXU ) != 0 )
+      return QString::null; //failed create
+
+  assert( !fname.isNull() );
+
+  mTempDirs.append( fname );
+  return fname;
+}
+
 //-----------------------------------------------------------------------------
 void KMReaderWin::showVCard( KMMessagePart * msgPart ) {
   const QString vCard = msgPart->bodyToUnicode( overrideCodec() );
--- branches/KDE/3.5/kdepim/kmail/kmreaderwin.h #650108:650109
 @ -65,7 +65,7  @
   struct URLArgs;
 }
 
-/** 
+/**
    This class implements a "reader window", that is a window
    used for reading or viewing messages.
 */
 @ -406,6 +406,13  @
   */
   QString writeMessagePartToTempFile( KMMessagePart* msgPart, int partNumber );
 
+  /**
+    Creates a temporary dir for saving attachments, etc.
+    Will be automatically deleted when another message is viewed.
+     param param Optional part of the directory name.
+  */
+  QString createTempDir( const QString &param = QString() );
+
   /** show window containing infos about a vCard. */
   void showVCard(KMMessagePart *msgPart);
 
--- branches/KDE/3.5/kdepim/kmail/objecttreeparser.cpp #650108:650109
 @ -72,9 +72,14  @
 #include <kpgp.h>
 #include <linklocator.h>
 
+#include <ktnef/ktnefparser.h>
+#include <ktnef/ktnefmessage.h>
+#include <ktnef/ktnefattach.h>
+
 // other KDE headers
 #include <kdebug.h>
 #include <klocale.h>
+#include <kmimetype.h>
 #include <kglobal.h>
 #include <khtml_part.h>
 #include <ktempfile.h>
 @ -86,6 +91,7  @
 
 // other Qt headers
 #include <qtextcodec.h>
+#include <qdir.h>
 #include <qfile.h>
 #include <qapplication.h>
 #include <kstyle.h>
 @ -1703,6 +1709,73  @
   return true;
 }
 
+bool ObjectTreeParser::processApplicationMsTnefSubtype( partNode *node, ProcessResult &result )
+{
+  Q_UNUSED( result );
+  if ( !mReader )
+    return false;
+
+  const QString fileName = mReader->writeMessagePartToTempFile( &node->msgPart(), node->nodeId() );
+  KTNEFParser parser;
+  if ( !parser.openFile( fileName ) || !parser.message()) {
+    kdDebug() << k_funcinfo << "Could not parse " << fileName << endl;
+    return false;
+  }
+
+  QPtrList<KTNEFAttach> tnefatts = parser.message()->attachmentList();
+  if ( tnefatts.isEmpty() ) {
+    kdDebug() << k_funcinfo << "No attachments found in " << fileName << endl;
+    return false;
+  }
+
+  if ( !showOnlyOneMimePart() ) {
+    QString label = node->msgPart().fileName().stripWhiteSpace();
+    if ( label.isEmpty() )
+      label = node->msgPart().name().stripWhiteSpace();
+    label = KMMessage::quoteHtmlChars( label, true );
+    const QString comment = KMMessage::quoteHtmlChars( node->msgPart().contentDescription(), true );
+    const QString dir = QApplication::reverseLayout() ? "rtl" : "ltr" ;
+
+    QString htmlStr = "<table cellspacing=\"1\" class=\"textAtm\">"
+                "<tr class=\"textAtmH\"><td dir=\"" + dir + "\">";
+    if ( !fileName.isEmpty() )
+      htmlStr += "<a href=\"" + QString("file:")
+        + KURL::encode_string( fileName ) + "\">"
+        + label + "</a>";
+    else
+      htmlStr += label;
+    if ( !comment.isEmpty() )
+      htmlStr += "<br>" + comment;
+    htmlStr += "</td></tr><tr class=\"textAtmB\"><td>";
+    htmlWriter()->queue( htmlStr );
+  }
+
+  for ( uint i = 0; i < tnefatts.count(); ++i ) {
+    KTNEFAttach *att = tnefatts.at( i );
+    QString label = att->displayName();
+    if( label.isEmpty() )
+      label = att->name();
+    label = KMMessage::quoteHtmlChars( label, true );
+
+    QString dir = mReader->createTempDir( "ktnef-" + QString::number( i ) );
+    parser.extractFileTo( att->name(), dir );
+    mReader->mTempFiles.append( dir + QDir::separator() + att->name() );
+    QString href = "file:" + KURL::encode_string( dir + QDir::separator() + att->name() );
+
+    KMimeType::Ptr mimeType = KMimeType::mimeType( att->mimeTag() );
+    QString iconName = KGlobal::instance()->iconLoader()->iconPath( mimeType->icon( QString(), false ), KIcon::Desktop );
+
+    htmlWriter()->queue( "<div><a href=\"" + href + "\"><img src=\"" +
+                          iconName + "\" border=\"0\" style=\"max-width: 100%\">" + label +
+                          "</a></div><br>" );
+  }
+
+  if ( !showOnlyOneMimePart() )
+    htmlWriter()->queue( "</td></tr></table>" );
+
+  return true;
+}
+
   void ObjectTreeParser::writeBodyString( const QCString & bodyString,
                                           const QString & fromAddress,
                                           const QTextCodec * codec,
--- branches/KDE/3.5/kdepim/kmail/objecttreeparser.h #650108:650109
 @ -2,7 +2,7  @
     objecttreeparser.h
 
     This file is part of KMail, the KDE mail client.
-    Copyright (c) 2002-2003 Klarälvdalens Datakonsult AB
+    Copyright (c) 2002-2003 Klarälvdalens Datakonsult AB
     Copyright (c) 2003      Marc Mutz <mutz kde org>
 
     KMail is free software; you can redistribute it and/or modify it
 @ -222,6 +222,7  @
     bool processApplicationOctetStreamSubtype( partNode * node, ProcessResult & result );
     bool processApplicationPkcs7MimeSubtype( partNode * node, ProcessResult & result );
     bool processApplicationChiasmusTextSubtype( partNode * node, ProcessResult & result );
+    bool processApplicationMsTnefSubtype( partNode *node, ProcessResult &result );
 
   private:
     bool decryptChiasmus( const QByteArray& data, QByteArray& bodyDecoded, QString& errorText );

_______________________________________________
KMail developers mailing list
[email protected]
https://mail.kde.org/mailman/listinfo/kmail-devel
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.