Index: kmail/khtmlparthtmlwriter.cpp
===================================================================
--- kmail/khtmlparthtmlwriter.cpp	(wersja 829730)
+++ kmail/khtmlparthtmlwriter.cpp	(kopia robocza)
@@ -90,6 +90,7 @@
     mHtmlPart->view()->setUpdatesEnabled( true );
     mHtmlPart->view()->viewport()->repaint();
     mState = Ended;
+    emit finished();
   }
 
   void KHtmlPartHtmlWriter::reset() {
Index: kmail/kmreaderwin.cpp
===================================================================
--- kmail/kmreaderwin.cpp	(wersja 829709)
+++ kmail/kmreaderwin.cpp	(kopia robocza)
@@ -481,6 +481,7 @@
     mSelectEncodingAction( 0 ),
     mToggleFixFontAction( 0 ),
     mHtmlWriter( 0 ),
+    mPartHtmlWriter( 0 ),
     mSavedRelativePosition( 0 ),
     mDecrytMessageOverwrite( false ),
     mShowSignatureDetails( false )
@@ -824,6 +825,7 @@
 KMReaderWin::~KMReaderWin()
 {
   delete mHtmlWriter; mHtmlWriter = 0;
+  mPartHtmlWriter = 0;
   delete mCSSHelper;
   if (mAutoDelete) delete message();
   delete mRootNode; mRootNode = 0;
@@ -1047,13 +1049,15 @@
   // register our own event filter for shift-click
   mViewer->view()->viewport()->installEventFilter( this );
 
-  if ( !htmlWriter() )
+  if ( !htmlWriter() ) {
+    mPartHtmlWriter = new KHtmlPartHtmlWriter( mViewer, 0 );
 #ifdef KMAIL_READER_HTML_DEBUG
     mHtmlWriter = new TeeHtmlWriter( new FileHtmlWriter( QString() ),
-                                     new KHtmlPartHtmlWriter( mViewer, 0 ) );
+                                     mPartHtmlWriter );
 #else
-    mHtmlWriter = new KHtmlPartHtmlWriter( mViewer, 0 );
+    mHtmlWriter = mPartHtmlWriter;
 #endif
+  }
 
   connect(mViewer->browserExtension(),
           SIGNAL(openUrlRequest(const KUrl &, const KParts::OpenUrlArguments &, const KParts::BrowserArguments &)),this,
@@ -1736,10 +1740,20 @@
 }
 
 //-----------------------------------------------------------------------------
-void KMReaderWin::printMsg()
+void KMReaderWin::printMsg( KMMessage* aMsg )
 {
+  disconnect( mPartHtmlWriter, SIGNAL( finished() ), this, SLOT( slotPrintMsg() ) );
+  connect( mPartHtmlWriter, SIGNAL( finished() ), this, SLOT( slotPrintMsg() ) );
+  setMsg( aMsg, true );
+}
+
+//-----------------------------------------------------------------------------
+void KMReaderWin::slotPrintMsg()
+{
+  disconnect( mPartHtmlWriter, SIGNAL( finished() ), this, SLOT( slotPrintMsg() ) );
   if (!message()) return;
   mViewer->view()->print();
+  deleteLater();
 }
 
 
Index: kmail/kmcommands.cpp
===================================================================
--- kmail/kmcommands.cpp	(wersja 829709)
+++ kmail/kmcommands.cpp	(kopia robocza)
@@ -122,6 +122,7 @@
 
 #include <kpimutils/kfileio.h>
 #include "calendarinterface.h"
+#include "interfaces/htmlwriter.h"
 
 #include "progressmanager.h"
 using KPIM::ProgressManager;
@@ -1594,19 +1595,25 @@
   mOverrideFont = font;
 }
 
+
+// KMReaderWin object kept here after previous call of execute(); it is deleted 
+QPointer<KMReaderWin> s_printerWin;
+
 KMCommand::Result KMPrintCommand::execute()
 {
-  KMReaderWin printWin( 0, 0, 0 );
-  printWin.setPrinting( true );
-  printWin.readConfig();
-  printWin.setHtmlOverride( mHtmlOverride );
-  printWin.setHtmlLoadExtOverride( mHtmlLoadExtOverride );
-  printWin.setUseFixedFont( mUseFixedFont );
-  printWin.setOverrideEncoding( mEncoding );
-  printWin.setPrintFont( mOverrideFont );
-  printWin.setDecryptMessageOverwrite( true );
-  printWin.setMsg( retrievedMessage(), true );
-  printWin.printMsg();
+  if ( s_printerWin && s_printerWin->htmlWriter() )
+    s_printerWin->htmlWriter()->reset(); // stop any previous processing
+  if ( !s_printerWin )
+    s_printerWin = new KMReaderWin( kmkernel->mainWin(), 0, 0 );
+  s_printerWin->setPrinting( true );
+  s_printerWin->readConfig();
+  s_printerWin->setHtmlOverride( mHtmlOverride );
+  s_printerWin->setHtmlLoadExtOverride( mHtmlLoadExtOverride );
+  s_printerWin->setUseFixedFont( mUseFixedFont );
+  s_printerWin->setOverrideEncoding( mEncoding );
+  s_printerWin->setPrintFont( mOverrideFont );
+  s_printerWin->setDecryptMessageOverwrite( true );
+  s_printerWin->printMsg( retrievedMessage() );
 
   return OK;
 }
Index: kmail/khtmlparthtmlwriter.h
===================================================================
--- kmail/khtmlparthtmlwriter.h	(wersja 829709)
+++ kmail/khtmlparthtmlwriter.h	(kopia robocza)
@@ -62,6 +62,9 @@
     void flush();
     void embedPart( const QByteArray & contentId, const QString & url );
 
+  signals:
+    void finished();
+
   private slots:
     void slotWriteNextHtmlChunk();
 
Index: kmail/kmreaderwin.h
===================================================================
--- kmail/kmreaderwin.h	(wersja 829709)
+++ kmail/kmreaderwin.h	(kopia robocza)
@@ -176,8 +176,8 @@
   /** Re-parse the current message. */
   void update(bool force = false);
 
-  /** Print current message. */
-  virtual void printMsg(void);
+  /** Print message. */
+  virtual void printMsg(  KMMessage* aMsg );
 
   /** Return selected text */
   QString copyText();
@@ -401,6 +401,9 @@
   void slotDelayedResize();
   void slotHandleAttachment( int );
 
+  /** Print message. Called by printMsg() after rendering is finished. */
+  void slotPrintMsg();
+
 protected:
   /** reimplemented in order to update the frame width in case of a changed
       GUI style */
@@ -521,6 +524,8 @@
   KToggleAction *mToggleFixFontAction;
   KUrl mUrlClicked;
   KMail::HtmlWriter * mHtmlWriter;
+  KMail::KHtmlPartHtmlWriter * mPartHtmlWriter;
+
   // an attachment should be updated
   bool mAtmUpdate;
   int mChoice;
