diff -rupN --exclude=.svn --exclude=TAGS kmail.ori/CMakeLists.txt kmail/CMakeLists.txt
--- kmail.ori/CMakeLists.txt	2009-10-22 12:52:43.000000000 +0200
+++ kmail/CMakeLists.txt	2009-10-23 17:45:01.000000000 +0200
@@ -238,6 +238,7 @@ set(kmailprivate_LIB_SRCS
    messageactions.cpp
    statusbarlabel.cpp
    groupware_types.cpp
+   proxyobject.cpp
    kleojobexecutor.cpp
    messagetree.cpp
    procmailparser.cpp
diff -rupN --exclude=.svn --exclude=TAGS kmail.ori/kmail_options.h kmail/kmail_options.h
--- kmail.ori/kmail_options.h	2009-10-22 12:52:43.000000000 +0200
+++ kmail/kmail_options.h	2009-10-23 17:05:42.000000000 +0200
@@ -22,6 +22,7 @@ static KCmdLineOptions kmail_options ()
   options.add("check",			ki18n("Only check for new mail"));
   options.add("composer",		ki18n("Only open composer window"));
   options.add("view <url>",		ki18n("View the given message file" ));
+  options.add("viewid <msg id>",		ki18n("View the given message corresponding to the kmail id" ));
   options.add("+[address|URL]",		ki18n("Send message to 'address' resp. "
                                           "attach the file the 'URL' points "
                                           "to"));
diff -rupN --exclude=.svn --exclude=TAGS kmail.ori/kmcommands.cpp kmail/kmcommands.cpp
--- kmail.ori/kmcommands.cpp	2009-10-22 12:52:43.000000000 +0200
+++ kmail/kmcommands.cpp	2009-10-23 17:28:00.000000000 +0200
@@ -135,6 +135,7 @@ using namespace KMime;
 #include <QList>
 #include <QTextCodec>
 #include <QProgressBar>
+#include <QDBusInterface>
 
 #include <memory>
 
@@ -244,8 +245,8 @@ void KMCommand::slotStart()
   if ( mMsgList.size() > 0 )
     mb = *(mMsgList.begin());
 
-  if ( ( mb ) && ( mMsgList.count() == 1 ) && ( mb->isMessage() ) &&
-       ( mb->parent() == 0 ) )
+  if ( ( mb ) && ( mMsgList.count() == 1 )
+       && ( mb->isMessage() ) && ( mb->parent() == 0 ) )
   {
     // Special case of operating on message that isn't in a folder
     mRetrievedMsgs.append((KMMessage*)mMsgList.takeFirst());
@@ -989,6 +990,16 @@ KMOpenMsgCommand::KMOpenMsgCommand( QWid
   setDeletesItself( true );
 }
 
+KMOpenMsgCommand2::KMOpenMsgCommand2( QWidget *parent, KMMsgBase* message,
+                                    const QString & encoding )
+  : KMCommand( parent, message ),
+    mMsgBase( message ),
+    mEncoding( encoding )
+{
+  Q_ASSERT(message != NULL );
+  setDeletesItself( false );
+}
+
 KMCommand::Result KMOpenMsgCommand::execute()
 {
   if ( mUrl.isEmpty() ) {
@@ -1009,6 +1020,31 @@ KMCommand::Result KMOpenMsgCommand::exec
   return OK;
 }
 
+KMCommand::Result KMOpenMsgCommand2::execute()
+{
+    KMReaderMainWin *win = new KMReaderMainWin();
+    KMMessage* msg = retrievedMessage();
+    msg->setReadyToShow( true );
+    Q_ASSERT( msg != NULL );
+    win->showMsg( mEncoding, msg);
+    win->show();
+
+    setResult( OK );
+    emit completed( this );
+    // deleteLater();
+
+    connect(win, SIGNAL( destroyed() ), 
+	    this, SLOT(closeFolder() ));
+    mMsgBase = msg;
+    return OK;
+}
+
+void KMOpenMsgCommand2::closeFolder()
+{
+  kDebug() << "destruction called";
+  mMsgBase->parent()->close("viewid", true);
+}
+
 void KMOpenMsgCommand::slotDataArrived( KIO::Job *, const QByteArray & data )
 {
   if ( data.isEmpty() )
@@ -2122,6 +2158,7 @@ KMCommand::Result KMMoveCommand::execute
               undoId = kmkernel->undoStack()->newUndoAction( srcFolder, mDestFolder );
             kmkernel->undoStack()->addMsgToAction( undoId, mb->getMsgSerNum() );
           }
+
         } else if (rc != 0) {
           // Something  went wrong. Stop processing here, it is likely that the
           // other moves would fail as well.
diff -rupN --exclude=.svn --exclude=TAGS kmail.ori/kmcommands.h kmail/kmcommands.h
--- kmail.ori/kmcommands.h	2009-10-22 12:52:43.000000000 +0200
+++ kmail/kmcommands.h	2009-10-23 17:05:20.000000000 +0200
@@ -373,6 +373,26 @@ private:
   const QString mEncoding;
 };
 
+class KMAIL_EXPORT KMOpenMsgCommand2 : public KMCommand
+{
+  Q_OBJECT
+public:
+  explicit KMOpenMsgCommand2( QWidget *parent, KMMsgBase* msgbase,
+                             const QString & encoding = QString() );
+private:
+  virtual KMCommand::Result execute();
+
+private slots:
+  void closeFolder();
+
+ // private slots:
+ //  void slotResult();
+
+ private:
+  KMMsgBase* mMsgBase;
+  const QString mEncoding;
+};
+
 class KMAIL_EXPORT KMSaveAttachmentsCommand : public KMCommand
 {
   Q_OBJECT
diff -rupN --exclude=.svn --exclude=TAGS kmail.ori/kmkernel.cpp kmail/kmkernel.cpp
--- kmail.ori/kmkernel.cpp	2009-10-22 12:52:43.000000000 +0200
+++ kmail/kmkernel.cpp	2009-10-23 17:05:05.000000000 +0200
@@ -2,6 +2,8 @@
 
 #include "kmkernel.h"
 
+#include "proxyobject.h"
+
 #include <config-kmail.h>
 
 #include "globalsettings.h"
@@ -214,10 +216,12 @@ bool KMKernel::handleCommandLine( bool n
   QString to, cc, bcc, subj, body;
   QStringList customHeaders;
   KUrl messageFile;
+  unsigned long msgSerNum = 0;
   KUrl::List attachURLs;
   bool mailto = false;
   bool checkMail = false;
   bool viewOnly = false;
+  bool viewOnlyId = false;
   bool calledWithSession = false; // for ignoring '-session foo'
 
   // process args:
@@ -301,6 +305,15 @@ bool KMKernel::handleCommandLine( bool n
     }
   }
 
+  if (args->isSet( "viewid" ) ) {
+    viewOnlyId = true;
+    const QString MsgSerNum = args->getOption( "viewid" );
+    bool conv_ok;
+     msgSerNum = MsgSerNum.toInt(&conv_ok);
+    Q_ASSERT(conv_ok != false);
+    //kDebug() << "MESSAGE SERIAL NUM:" << MsgSerNum;
+  }
+
   if ( !calledWithSession ) {
     // only read additional command line arguments if kmail/kontact is
     // not called with "-session foo"
@@ -340,7 +353,9 @@ bool KMKernel::handleCommandLine( bool n
   if ( !noArgsOpensReader && !mailto && !checkMail && !viewOnly )
     return false;
 
-  if ( viewOnly )
+  if ( viewOnlyId )
+    viewMessage( msgSerNum );
+  else if ( viewOnly )
     viewMessage( messageFile );
   else
     action( mailto, checkMail, to, cc, bcc, subj, body, messageFile,
@@ -706,6 +721,14 @@ int KMKernel::viewMessage( const KUrl & 
   return 1;
 }
 
+int KMKernel::viewMessage( unsigned long msgSerNum )
+{
+  proxyObject* prox = new proxyObject(msgSerNum, this);
+  QTimer::singleShot(2000, prox, SLOT( Proxy() ));
+
+  return 1;
+}
+
 int KMKernel::sendCertificate( const QString& to, const QByteArray& certData )
 {
   KMMessage *msg = new KMMessage;
diff -rupN --exclude=.svn --exclude=TAGS kmail.ori/kmkernel.h kmail/kmkernel.h
--- kmail.ori/kmkernel.h	2009-10-22 12:52:43.000000000 +0200
+++ kmail/kmkernel.h	2009-10-23 17:05:05.000000000 +0200
@@ -14,6 +14,7 @@
 #include <kconfig.h>
 #include <kurl.h>
 
+#include "kmmsgbase.h"
 #include "kmail_export.h"
 #include "kmmsgbase.h"
 #include "kmmessagetag.h"
@@ -229,6 +230,7 @@ public Q_SLOTS:
   Q_SCRIPTABLE QString debugSernum( quint32 serialNumber );
 
   Q_SCRIPTABLE int viewMessage( const KUrl & messageFile );
+  Q_SCRIPTABLE int viewMessage( unsigned long msgSerNum );
 
 Q_SIGNALS:
 
diff -rupN --exclude=.svn --exclude=TAGS kmail.ori/proxyobject.cpp kmail/proxyobject.cpp
--- kmail.ori/proxyobject.cpp	1970-01-01 01:00:00.000000000 +0100
+++ kmail/proxyobject.cpp	2009-10-23 17:21:06.000000000 +0200
@@ -0,0 +1,25 @@
+#include "proxyobject.h"
+#include "kmmsgbase.h"
+#include "kmmsgdict.h"
+#include "kmcommands.h"
+#include "kmfolder.h"
+
+void    proxyObject::Proxy()
+{
+    KMFolder* folder;
+    KMMsgBase* msgbase;
+    int index;
+
+    KMMsgDict::instance()->getLocation( msgSerNum, &folder, &index );
+    if ( folder != NULL && index != -1 ) {
+      kFatal("msg serial number not found ; the serial number provided may incorrect");
+    }
+    folder->open("viewid");
+    msgbase = folder->getMsgBase( index );
+    Q_ASSERT( msgbase != NULL );
+
+    KMOpenMsgCommand2 *openCommand = new KMOpenMsgCommand2( 0, msgbase );
+    openCommand->start();
+}
+
+#include "proxyobject.moc"
diff -rupN --exclude=.svn --exclude=TAGS kmail.ori/proxyobject.h kmail/proxyobject.h
--- kmail.ori/proxyobject.h	1970-01-01 01:00:00.000000000 +0100
+++ kmail/proxyobject.h	2009-10-23 17:21:06.000000000 +0200
@@ -0,0 +1,21 @@
+#ifndef _PROXYOBJECT_H_
+#define _PROXYOBJECT_H_
+
+#include <QObject>
+
+class   proxyObject : public QObject
+{
+  Q_OBJECT
+  unsigned long msgSerNum;
+
+public:
+  proxyObject( unsigned long serNum, QObject* parent = 0 ) :
+    QObject( parent ), msgSerNum( serNum)
+  {
+  }
+
+public slots:
+  void  Proxy();
+};
+
+#endif
