Sophie

Sophie

distrib > Mandriva > 2008.1 > x86_64 > by-pkgid > 98d6b53e11e983e268c3e19f14e091a0 > files > 2390

kdepim-devel-doc-3.5.9-9mdv2008.1.x86_64.rpm

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en_US" xml:lang="en_US">

<head>
  <title>kmail: kmcommands.cpp Source File (kmail)</title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

  <meta http-equiv="Content-Style-Type" content="text/css" />

  <meta http-equiv="pics-label" content='(pics-1.1 "http://www.icra.org/ratingsv02.html" comment "ICRAonline DE v2.0" l gen true for "http://www.kde.org"  r (nz 1 vz 1 lz 1 oz 1 cb 1) "http://www.rsac.org/ratingsv01.html" l gen true for "http://www.kde.org"  r (n 0 s 0 v 0 l 0))' />

  <meta name="trademark" content="KDE e.V." />
  <meta name="description" content="K Desktop Environment Homepage, KDE.org" />
  <meta name="MSSmartTagsPreventParsing" content="true" />
  <meta name="robots" content="all" />

  <link rel="shortcut icon" href="../../favicon.ico" />

<link rel="stylesheet" media="screen" type="text/css" title="APIDOX" href="doxygen.css" />



<style type="text/css">
<!--
hr { display: none; }
#content h2 { margin-left: 0px; }
table.mdTable { background-color: #f8f8f8; border: .2em solid #d7d7d7; }
td.mdRow { padding: 8px 20px; }
td.md { font-weight: bold; }
td.mdname1 { font-weight: bold; color: #602020; }
td.mdname { font-weight: bold; color: #602020;  }

-->
</style>

</head>

<body>

<div id="nav_header_top" align="right">
  <a href="#content" class="doNotDisplay" accesskey="2">Skip to main content ::</a>

  <a href="../.."><img id="nav_header_logo" alt="Home" align="left" src="../../kde_gear_64.png" border="0" /></a>
  <span class="doNotDisplay">::</span>
  <img id="nav_header_logo_right" alt="" align="right" src="../../pimlogo.png" border="0" />

  <div id="nav_header_title" align="left">KDE PIM API Reference</div>


</div>

<div id="nav_header_bottom" align="right">
  <span class="doNotDisplay">:: <a href="#navigation" accesskey="5">Skip to Link Menu</a><br/></span>
  <div id="nav_header_bottom_left" style="text-align: left;">
/ <a href="../../">API Reference</a>
 / <a href=".">kmail</a>
  </div>
</div>


<table id="main" border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
      <td valign="top" class="menuheader" height="0"></td>

  <td id="contentcolumn" valign="top" rowspan="2" >
    <div id="content" style="padding-top: 0px;"><div style="width:100%; margin: 0px; padding: 0px;">
    <h2><a name="content"></a>kmail</h2>


<!-- Generated by Doxygen 1.5.5 -->
<h1>kmcommands.cpp</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* -*- mode: C++; c-file-style: "gnu" -*-</span>
<a name="l00002"></a>00002 <span class="comment">    This file is part of KMail, the KDE mail client.</span>
<a name="l00003"></a>00003 <span class="comment">    Copyright (c) 2002 Don Sanders &lt;sanders@kde.org&gt;</span>
<a name="l00004"></a>00004 <span class="comment"></span>
<a name="l00005"></a>00005 <span class="comment">    KMail is free software; you can redistribute it and/or modify it</span>
<a name="l00006"></a>00006 <span class="comment">    under the terms of the GNU General Public License, version 2, as</span>
<a name="l00007"></a>00007 <span class="comment">    published by the Free Software Foundation.</span>
<a name="l00008"></a>00008 <span class="comment"></span>
<a name="l00009"></a>00009 <span class="comment">    KMail is distributed in the hope that it will be useful, but</span>
<a name="l00010"></a>00010 <span class="comment">    WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<a name="l00011"></a>00011 <span class="comment">    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU</span>
<a name="l00012"></a>00012 <span class="comment">    General Public License for more details.</span>
<a name="l00013"></a>00013 <span class="comment"></span>
<a name="l00014"></a>00014 <span class="comment">    You should have received a copy of the GNU General Public License</span>
<a name="l00015"></a>00015 <span class="comment">    along with this program; if not, write to the Free Software</span>
<a name="l00016"></a>00016 <span class="comment">    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA</span>
<a name="l00017"></a>00017 <span class="comment">*/</span>
<a name="l00018"></a>00018 
<a name="l00019"></a>00019 <span class="comment">//</span>
<a name="l00020"></a>00020 <span class="comment">// This file implements various "command" classes. These command classes</span>
<a name="l00021"></a>00021 <span class="comment">// are based on the command design pattern.</span>
<a name="l00022"></a>00022 <span class="comment">//</span>
<a name="l00023"></a>00023 <span class="comment">// Historically various operations were implemented as slots of KMMainWin.</span>
<a name="l00024"></a>00024 <span class="comment">// This proved inadequate as KMail has multiple top level windows</span>
<a name="l00025"></a>00025 <span class="comment">// (KMMainWin, KMReaderMainWin, SearchWindow, KMComposeWin) that may</span>
<a name="l00026"></a>00026 <span class="comment">// benefit from using these operations. It is desirable that these</span>
<a name="l00027"></a>00027 <span class="comment">// classes can operate without depending on or altering the state of</span>
<a name="l00028"></a>00028 <span class="comment">// a KMMainWin, in fact it is possible no KMMainWin object even exists.</span>
<a name="l00029"></a>00029 <span class="comment">//</span>
<a name="l00030"></a>00030 <span class="comment">// Now these operations have been rewritten as KMCommand based classes,</span>
<a name="l00031"></a>00031 <span class="comment">// making them independent of KMMainWin.</span>
<a name="l00032"></a>00032 <span class="comment">//</span>
<a name="l00033"></a>00033 <span class="comment">// The base command class KMCommand is async, which is a difference</span>
<a name="l00034"></a>00034 <span class="comment">// from the conventional command pattern. As normal derived classes implement</span>
<a name="l00035"></a>00035 <span class="comment">// the execute method, but client classes call start() instead of</span>
<a name="l00036"></a>00036 <span class="comment">// calling execute() directly. start() initiates async operations,</span>
<a name="l00037"></a>00037 <span class="comment">// and on completion of these operations calls execute() and then deletes</span>
<a name="l00038"></a>00038 <span class="comment">// the command. (So the client must not construct commands on the stack).</span>
<a name="l00039"></a>00039 <span class="comment">//</span>
<a name="l00040"></a>00040 <span class="comment">// The type of async operation supported by KMCommand is retrieval</span>
<a name="l00041"></a>00041 <span class="comment">// of messages from an IMAP server.</span>
<a name="l00042"></a>00042 
<a name="l00043"></a>00043 <span class="preprocessor">#include "kmcommands.h"</span>
<a name="l00044"></a>00044 
<a name="l00045"></a>00045 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
<a name="l00046"></a>00046 <span class="preprocessor"></span><span class="preprocessor">#include &lt;config.h&gt;</span>
<a name="l00047"></a>00047 <span class="preprocessor">#endif</span>
<a name="l00048"></a>00048 <span class="preprocessor"></span>
<a name="l00049"></a>00049 <span class="preprocessor">#include &lt;errno.h&gt;</span>
<a name="l00050"></a>00050 <span class="preprocessor">#include &lt;mimelib/enum.h&gt;</span>
<a name="l00051"></a>00051 <span class="preprocessor">#include &lt;mimelib/field.h&gt;</span>
<a name="l00052"></a>00052 <span class="preprocessor">#include &lt;mimelib/mimepp.h&gt;</span>
<a name="l00053"></a>00053 <span class="preprocessor">#include &lt;mimelib/string.h&gt;</span>
<a name="l00054"></a>00054 <span class="preprocessor">#include &lt;kapplication.h&gt;</span>
<a name="l00055"></a>00055 <span class="preprocessor">#include &lt;dcopclient.h&gt;</span>
<a name="l00056"></a>00056 
<a name="l00057"></a>00057 <span class="preprocessor">#include &lt;qtextcodec.h&gt;</span>
<a name="l00058"></a>00058 <span class="preprocessor">#include &lt;qpopupmenu.h&gt;</span>
<a name="l00059"></a>00059 <span class="preprocessor">#include &lt;qeventloop.h&gt;</span>
<a name="l00060"></a>00060 
<a name="l00061"></a>00061 <span class="preprocessor">#include &lt;libemailfunctions/email.h&gt;</span>
<a name="l00062"></a>00062 <span class="preprocessor">#include &lt;kdcopservicestarter.h&gt;</span>
<a name="l00063"></a>00063 <span class="preprocessor">#include &lt;kdebug.h&gt;</span>
<a name="l00064"></a>00064 <span class="preprocessor">#include &lt;kfiledialog.h&gt;</span>
<a name="l00065"></a>00065 <span class="preprocessor">#include &lt;kabc/stdaddressbook.h&gt;</span>
<a name="l00066"></a>00066 <span class="preprocessor">#include &lt;kabc/addresseelist.h&gt;</span>
<a name="l00067"></a>00067 <span class="preprocessor">#include &lt;kdirselectdialog.h&gt;</span>
<a name="l00068"></a>00068 <span class="preprocessor">#include &lt;klocale.h&gt;</span>
<a name="l00069"></a>00069 <span class="preprocessor">#include &lt;kmessagebox.h&gt;</span>
<a name="l00070"></a>00070 <span class="preprocessor">#include &lt;kparts/browserextension.h&gt;</span>
<a name="l00071"></a>00071 <span class="preprocessor">#include &lt;kprogress.h&gt;</span>
<a name="l00072"></a>00072 <span class="preprocessor">#include &lt;krun.h&gt;</span>
<a name="l00073"></a>00073 <span class="preprocessor">#include &lt;kbookmarkmanager.h&gt;</span>
<a name="l00074"></a>00074 <span class="preprocessor">#include &lt;kstandarddirs.h&gt;</span>
<a name="l00075"></a>00075 <span class="preprocessor">#include &lt;ktempfile.h&gt;</span>
<a name="l00076"></a>00076 <span class="preprocessor">#include &lt;kimproxy.h&gt;</span>
<a name="l00077"></a>00077 <span class="preprocessor">#include &lt;kuserprofile.h&gt;</span>
<a name="l00078"></a>00078 <span class="comment">// KIO headers</span>
<a name="l00079"></a>00079 <span class="preprocessor">#include &lt;kio/job.h&gt;</span>
<a name="l00080"></a>00080 <span class="preprocessor">#include &lt;kio/netaccess.h&gt;</span>
<a name="l00081"></a>00081 
<a name="l00082"></a>00082 <span class="preprocessor">#include &lt;libkpimidentities/identitymanager.h&gt;</span>
<a name="l00083"></a>00083 
<a name="l00084"></a>00084 <span class="preprocessor">#include "actionscheduler.h"</span>
<a name="l00085"></a>00085 <span class="keyword">using</span> KMail::ActionScheduler;
<a name="l00086"></a>00086 <span class="preprocessor">#include "mailinglist-magic.h"</span>
<a name="l00087"></a>00087 <span class="preprocessor">#include "kmaddrbook.h"</span>
<a name="l00088"></a>00088 <span class="preprocessor">#include &lt;kaddrbook.h&gt;</span>
<a name="l00089"></a>00089 <span class="preprocessor">#include "composer.h"</span>
<a name="l00090"></a>00090 <span class="preprocessor">#include "kmfiltermgr.h"</span>
<a name="l00091"></a>00091 <span class="preprocessor">#include "kmfoldermbox.h"</span>
<a name="l00092"></a>00092 <span class="preprocessor">#include "kmfolderimap.h"</span>
<a name="l00093"></a>00093 <span class="preprocessor">#include "kmfoldermgr.h"</span>
<a name="l00094"></a>00094 <span class="preprocessor">#include "kmheaders.h"</span>
<a name="l00095"></a>00095 <span class="preprocessor">#include "headeritem.h"</span>
<a name="l00096"></a>00096 <span class="preprocessor">#include "kmmainwidget.h"</span>
<a name="l00097"></a>00097 <span class="preprocessor">#include "kmmsgdict.h"</span>
<a name="l00098"></a>00098 <span class="preprocessor">#include "messagesender.h"</span>
<a name="l00099"></a>00099 <span class="preprocessor">#include "kmmsgpartdlg.h"</span>
<a name="l00100"></a>00100 <span class="preprocessor">#include "undostack.h"</span>
<a name="l00101"></a>00101 <span class="preprocessor">#include "kcursorsaver.h"</span>
<a name="l00102"></a>00102 <span class="preprocessor">#include "partNode.h"</span>
<a name="l00103"></a>00103 <span class="preprocessor">#include "objecttreeparser.h"</span>
<a name="l00104"></a>00104 <span class="keyword">using</span> KMail::ObjectTreeParser;
<a name="l00105"></a>00105 <span class="keyword">using</span> KMail::FolderJob;
<a name="l00106"></a>00106 <span class="preprocessor">#include "chiasmuskeyselector.h"</span>
<a name="l00107"></a>00107 <span class="preprocessor">#include "mailsourceviewer.h"</span>
<a name="l00108"></a>00108 <span class="keyword">using</span> KMail::MailSourceViewer;
<a name="l00109"></a>00109 <span class="preprocessor">#include "kmreadermainwin.h"</span>
<a name="l00110"></a>00110 <span class="preprocessor">#include "secondarywindow.h"</span>
<a name="l00111"></a>00111 <span class="keyword">using</span> <a class="code" href="classKMail_1_1SecondaryWindow.html" title="Window class for secondary KMail window like the composer window and the separate...">KMail::SecondaryWindow</a>;
<a name="l00112"></a>00112 <span class="preprocessor">#include "redirectdialog.h"</span>
<a name="l00113"></a>00113 <span class="keyword">using</span> <a class="code" href="classKMail_1_1RedirectDialog.html" title="KMail message redirection dialog.">KMail::RedirectDialog</a>;
<a name="l00114"></a>00114 <span class="preprocessor">#include "util.h"</span>
<a name="l00115"></a>00115 <span class="preprocessor">#include "templateparser.h"</span>
<a name="l00116"></a>00116 <span class="preprocessor">#include "editorwatcher.h"</span>
<a name="l00117"></a>00117 <span class="preprocessor">#include "korghelper.h"</span>
<a name="l00118"></a>00118 
<a name="l00119"></a>00119 <span class="preprocessor">#include "broadcaststatus.h"</span>
<a name="l00120"></a>00120 <span class="preprocessor">#include "globalsettings.h"</span>
<a name="l00121"></a>00121 
<a name="l00122"></a>00122 <span class="preprocessor">#include &lt;libkdepim/kfileio.h&gt;</span>
<a name="l00123"></a>00123 <span class="preprocessor">#include "kcalendariface_stub.h"</span>
<a name="l00124"></a>00124 
<a name="l00125"></a>00125 <span class="preprocessor">#include "progressmanager.h"</span>
<a name="l00126"></a>00126 <span class="keyword">using</span> KPIM::ProgressManager;
<a name="l00127"></a>00127 <span class="keyword">using</span> KPIM::ProgressItem;
<a name="l00128"></a>00128 <span class="preprocessor">#include &lt;kmime_mdn.h&gt;</span>
<a name="l00129"></a>00129 <span class="keyword">using namespace </span>KMime;
<a name="l00130"></a>00130 
<a name="l00131"></a>00131 <span class="preprocessor">#include &lt;kleo/specialjob.h&gt;</span>
<a name="l00132"></a>00132 <span class="preprocessor">#include &lt;kleo/cryptobackend.h&gt;</span>
<a name="l00133"></a>00133 <span class="preprocessor">#include &lt;kleo/cryptobackendfactory.h&gt;</span>
<a name="l00134"></a>00134 
<a name="l00135"></a>00135 <span class="preprocessor">#include &lt;qclipboard.h&gt;</span>
<a name="l00136"></a>00136 
<a name="l00137"></a>00137 <span class="preprocessor">#include &lt;memory&gt;</span>
<a name="l00138"></a>00138 
<a name="l00139"></a>00139 <span class="keyword">class </span>LaterDeleterWithCommandCompletion : <span class="keyword">public</span> KMail::Util::LaterDeleter
<a name="l00140"></a>00140 {
<a name="l00141"></a>00141 <span class="keyword">public</span>:
<a name="l00142"></a>00142   LaterDeleterWithCommandCompletion( KMCommand* command )
<a name="l00143"></a>00143     :LaterDeleter( command ), m_result( KMCommand::Failed )
<a name="l00144"></a>00144   {
<a name="l00145"></a>00145   }
<a name="l00146"></a>00146   ~LaterDeleterWithCommandCompletion()
<a name="l00147"></a>00147   {
<a name="l00148"></a>00148     setResult( m_result );
<a name="l00149"></a>00149     KMCommand *command = <span class="keyword">static_cast&lt;</span>KMCommand*<span class="keyword">&gt;</span>( m_object );
<a name="l00150"></a>00150     emit command-&gt;completed( command );
<a name="l00151"></a>00151   }
<a name="l00152"></a>00152   <span class="keywordtype">void</span> setResult( KMCommand::Result v ) { m_result = v; }
<a name="l00153"></a>00153 <span class="keyword">private</span>:
<a name="l00154"></a>00154   KMCommand::Result m_result;
<a name="l00155"></a>00155 };
<a name="l00156"></a>00156 
<a name="l00157"></a>00157 
<a name="l00158"></a>00158 KMCommand::KMCommand( QWidget *parent )
<a name="l00159"></a>00159   : mProgressDialog( 0 ), mResult( Undefined ), mDeletesItself( false ),
<a name="l00160"></a>00160     mEmitsCompletedItself( false ), mParent( parent )
<a name="l00161"></a>00161 {
<a name="l00162"></a>00162 }
<a name="l00163"></a>00163 
<a name="l00164"></a>00164 KMCommand::KMCommand( QWidget *parent, <span class="keyword">const</span> QPtrList&lt;KMMsgBase&gt; &amp;msgList )
<a name="l00165"></a>00165   : mProgressDialog( 0 ), mResult( Undefined ), mDeletesItself( false ),
<a name="l00166"></a>00166     mEmitsCompletedItself( false ), mParent( parent ), mMsgList( msgList )
<a name="l00167"></a>00167 {
<a name="l00168"></a>00168 }
<a name="l00169"></a>00169 
<a name="l00170"></a>00170 KMCommand::KMCommand( QWidget *parent, KMMsgBase *msgBase )
<a name="l00171"></a>00171   : mProgressDialog( 0 ), mResult( Undefined ), mDeletesItself( false ),
<a name="l00172"></a>00172     mEmitsCompletedItself( false ), mParent( parent )
<a name="l00173"></a>00173 {
<a name="l00174"></a>00174   mMsgList.append( msgBase );
<a name="l00175"></a>00175 }
<a name="l00176"></a>00176 
<a name="l00177"></a>00177 KMCommand::KMCommand( QWidget *parent, <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> *msg )
<a name="l00178"></a>00178   : mProgressDialog( 0 ), mResult( Undefined ), mDeletesItself( false ),
<a name="l00179"></a>00179     mEmitsCompletedItself( false ), mParent( parent )
<a name="l00180"></a>00180 {
<a name="l00181"></a>00181   <span class="keywordflow">if</span> (msg)
<a name="l00182"></a>00182     mMsgList.append( &amp;msg-&gt;<a class="code" href="classKMMessage.html#d8a3687b6c8e690a6225b59fdf80eeb8" title="Get KMMsgBase for this object.">toMsgBase</a>() );
<a name="l00183"></a>00183 }
<a name="l00184"></a>00184 
<a name="l00185"></a>00185 KMCommand::~KMCommand()
<a name="l00186"></a>00186 {
<a name="l00187"></a>00187   QValueListIterator&lt;QGuardedPtr&lt;KMFolder&gt; &gt; fit;
<a name="l00188"></a>00188   <span class="keywordflow">for</span> ( fit = mFolders.begin(); fit != mFolders.end(); ++fit ) {
<a name="l00189"></a>00189     <span class="keywordflow">if</span> (!(*fit))
<a name="l00190"></a>00190       <span class="keywordflow">continue</span>;
<a name="l00191"></a>00191     (*fit)-&gt;close(<span class="stringliteral">"kmcommand"</span>);
<a name="l00192"></a>00192   }
<a name="l00193"></a>00193 }
<a name="l00194"></a>00194 
<a name="l00195"></a>00195 KMCommand::Result KMCommand::result()
<a name="l00196"></a>00196 {
<a name="l00197"></a>00197   <span class="keywordflow">if</span> ( mResult == Undefined )
<a name="l00198"></a>00198     kdDebug(5006) &lt;&lt; k_funcinfo &lt;&lt; <span class="stringliteral">"mResult is Undefined"</span> &lt;&lt; endl;
<a name="l00199"></a>00199   <span class="keywordflow">return</span> mResult;
<a name="l00200"></a>00200 }
<a name="l00201"></a>00201 
<a name="l00202"></a>00202 <span class="keywordtype">void</span> KMCommand::start()
<a name="l00203"></a>00203 {
<a name="l00204"></a>00204   QTimer::singleShot( 0, <span class="keyword">this</span>, SLOT( slotStart() ) );
<a name="l00205"></a>00205 }
<a name="l00206"></a>00206 
<a name="l00207"></a>00207 
<a name="l00208"></a>00208 <span class="keyword">const</span> QPtrList&lt;KMMessage&gt; KMCommand::retrievedMsgs()<span class="keyword"> const</span>
<a name="l00209"></a>00209 <span class="keyword"></span>{
<a name="l00210"></a>00210   <span class="keywordflow">return</span> mRetrievedMsgs;
<a name="l00211"></a>00211 }
<a name="l00212"></a>00212 
<a name="l00213"></a>00213 <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> *KMCommand::retrievedMessage()<span class="keyword"> const</span>
<a name="l00214"></a>00214 <span class="keyword"></span>{
<a name="l00215"></a>00215   <span class="keywordflow">return</span> mRetrievedMsgs.getFirst();
<a name="l00216"></a>00216 }
<a name="l00217"></a>00217 
<a name="l00218"></a>00218 QWidget *KMCommand::parentWidget()<span class="keyword"> const</span>
<a name="l00219"></a>00219 <span class="keyword"></span>{
<a name="l00220"></a>00220   <span class="keywordflow">return</span> mParent;
<a name="l00221"></a>00221 }
<a name="l00222"></a>00222 
<a name="l00223"></a>00223 <span class="keywordtype">int</span> KMCommand::mCountJobs = 0;
<a name="l00224"></a>00224 
<a name="l00225"></a>00225 <span class="keywordtype">void</span> KMCommand::slotStart()
<a name="l00226"></a>00226 {
<a name="l00227"></a>00227   connect( <span class="keyword">this</span>, SIGNAL( messagesTransfered( KMCommand::Result ) ),
<a name="l00228"></a>00228            <span class="keyword">this</span>, SLOT( slotPostTransfer( KMCommand::Result ) ) );
<a name="l00229"></a>00229   kmkernel-&gt;filterMgr()-&gt;ref();
<a name="l00230"></a>00230 
<a name="l00231"></a>00231   <span class="keywordflow">if</span> (mMsgList.find(0) != -1) {
<a name="l00232"></a>00232       emit messagesTransfered( Failed );
<a name="l00233"></a>00233       <span class="keywordflow">return</span>;
<a name="l00234"></a>00234   }
<a name="l00235"></a>00235 
<a name="l00236"></a>00236   <span class="keywordflow">if</span> ((mMsgList.count() == 1) &amp;&amp;
<a name="l00237"></a>00237       (mMsgList.getFirst()-&gt;isMessage()) &amp;&amp;
<a name="l00238"></a>00238       (mMsgList.getFirst()-&gt;parent() == 0))
<a name="l00239"></a>00239   {
<a name="l00240"></a>00240     <span class="comment">// Special case of operating on message that isn't in a folder</span>
<a name="l00241"></a>00241     mRetrievedMsgs.append((<a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a>*)mMsgList.getFirst());
<a name="l00242"></a>00242     emit messagesTransfered( OK );
<a name="l00243"></a>00243     <span class="keywordflow">return</span>;
<a name="l00244"></a>00244   }
<a name="l00245"></a>00245 
<a name="l00246"></a>00246   <span class="keywordflow">for</span> (KMMsgBase *mb = mMsgList.first(); mb; mb = mMsgList.next())
<a name="l00247"></a>00247     <span class="keywordflow">if</span> (!mb-&gt;parent()) {
<a name="l00248"></a>00248       emit messagesTransfered( Failed );
<a name="l00249"></a>00249       <span class="keywordflow">return</span>;
<a name="l00250"></a>00250     } <span class="keywordflow">else</span> {
<a name="l00251"></a>00251       keepFolderOpen( mb-&gt;parent() );
<a name="l00252"></a>00252     }
<a name="l00253"></a>00253 
<a name="l00254"></a>00254   <span class="comment">// transfer the selected messages first</span>
<a name="l00255"></a>00255   transferSelectedMsgs();
<a name="l00256"></a>00256 }
<a name="l00257"></a>00257 
<a name="l00258"></a>00258 <span class="keywordtype">void</span> KMCommand::slotPostTransfer( KMCommand::Result result )
<a name="l00259"></a>00259 {
<a name="l00260"></a>00260   disconnect( <span class="keyword">this</span>, SIGNAL( messagesTransfered( KMCommand::Result ) ),
<a name="l00261"></a>00261               <span class="keyword">this</span>, SLOT( slotPostTransfer( KMCommand::Result ) ) );
<a name="l00262"></a>00262   <span class="keywordflow">if</span> ( result == OK )
<a name="l00263"></a>00263     result = execute();
<a name="l00264"></a>00264   mResult = result;
<a name="l00265"></a>00265   QPtrListIterator&lt;KMMessage&gt; it( mRetrievedMsgs );
<a name="l00266"></a>00266   <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a>* msg;
<a name="l00267"></a>00267   <span class="keywordflow">while</span> ( (msg = it.current()) != 0 )
<a name="l00268"></a>00268   {
<a name="l00269"></a>00269     ++it;
<a name="l00270"></a>00270     <span class="keywordflow">if</span> (msg-&gt;parent())
<a name="l00271"></a>00271       msg-&gt;<a class="code" href="classKMMessage.html#32cc9d6f53648fd997efcc4f9d043197" title="Set that the message shall not be deleted because it is still required.">setTransferInProgress</a>(<span class="keyword">false</span>);
<a name="l00272"></a>00272   }
<a name="l00273"></a>00273   kmkernel-&gt;filterMgr()-&gt;deref();
<a name="l00274"></a>00274   <span class="keywordflow">if</span> ( !emitsCompletedItself() )
<a name="l00275"></a>00275     emit completed( <span class="keyword">this</span> );
<a name="l00276"></a>00276   <span class="keywordflow">if</span> ( !deletesItself() )
<a name="l00277"></a>00277     deleteLater();
<a name="l00278"></a>00278 }
<a name="l00279"></a>00279 
<a name="l00280"></a>00280 <span class="keywordtype">void</span> KMCommand::transferSelectedMsgs()
<a name="l00281"></a>00281 {
<a name="l00282"></a>00282   <span class="comment">// make sure no other transfer is active</span>
<a name="l00283"></a>00283   <span class="keywordflow">if</span> (KMCommand::mCountJobs &gt; 0) {
<a name="l00284"></a>00284     emit messagesTransfered( Failed );
<a name="l00285"></a>00285     <span class="keywordflow">return</span>;
<a name="l00286"></a>00286   }
<a name="l00287"></a>00287 
<a name="l00288"></a>00288   <span class="keywordtype">bool</span> complete = <span class="keyword">true</span>;
<a name="l00289"></a>00289   KMCommand::mCountJobs = 0;
<a name="l00290"></a>00290   mCountMsgs = 0;
<a name="l00291"></a>00291   mRetrievedMsgs.clear();
<a name="l00292"></a>00292   mCountMsgs = mMsgList.count();
<a name="l00293"></a>00293   uint totalSize = 0;
<a name="l00294"></a>00294   <span class="comment">// the KProgressDialog for the user-feedback. Only enable it if it's needed.</span>
<a name="l00295"></a>00295   <span class="comment">// For some commands like KMSetStatusCommand it's not needed. Note, that</span>
<a name="l00296"></a>00296   <span class="comment">// for some reason the KProgressDialog eats the MouseReleaseEvent (if a</span>
<a name="l00297"></a>00297   <span class="comment">// command is executed after the MousePressEvent), cf. bug #71761.</span>
<a name="l00298"></a>00298   <span class="keywordflow">if</span> ( mCountMsgs &gt; 0 ) {
<a name="l00299"></a>00299     mProgressDialog = <span class="keyword">new</span> KProgressDialog(mParent, <span class="stringliteral">"transferProgress"</span>,
<a name="l00300"></a>00300       i18n(<span class="stringliteral">"Please wait"</span>),
<a name="l00301"></a>00301       i18n(<span class="stringliteral">"Please wait while the message is transferred"</span>,
<a name="l00302"></a>00302         <span class="stringliteral">"Please wait while the %n messages are transferred"</span>, mMsgList.count()),
<a name="l00303"></a>00303       <span class="keyword">true</span>);
<a name="l00304"></a>00304     mProgressDialog-&gt;setMinimumDuration(1000);
<a name="l00305"></a>00305   }
<a name="l00306"></a>00306   <span class="keywordflow">for</span> (KMMsgBase *mb = mMsgList.first(); mb; mb = mMsgList.next())
<a name="l00307"></a>00307   {
<a name="l00308"></a>00308     <span class="comment">// check if all messages are complete</span>
<a name="l00309"></a>00309     <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> *thisMsg = 0;
<a name="l00310"></a>00310     <span class="keywordflow">if</span> ( mb-&gt;isMessage() )
<a name="l00311"></a>00311       thisMsg = static_cast&lt;KMMessage*&gt;(mb);
<a name="l00312"></a>00312     <span class="keywordflow">else</span>
<a name="l00313"></a>00313     {
<a name="l00314"></a>00314       <a class="code" href="classKMFolder.html" title="Mail folder.">KMFolder</a> *folder = mb-&gt;parent();
<a name="l00315"></a>00315       <span class="keywordtype">int</span> idx = folder-&gt;<a class="code" href="classKMFolder.html#27adedd629ece306415faf3cf5fbc617" title="Returns the index of the given message or -1 if not found.">find</a>(mb);
<a name="l00316"></a>00316       <span class="keywordflow">if</span> (idx &lt; 0) <span class="keywordflow">continue</span>;
<a name="l00317"></a>00317       thisMsg = folder-&gt;<a class="code" href="classKMFolder.html#a0fdfeeed6e8e20eff1cd6445309b2f4" title="Read message at given index.">getMsg</a>(idx);
<a name="l00318"></a>00318     }
<a name="l00319"></a>00319     <span class="keywordflow">if</span> (!thisMsg) <span class="keywordflow">continue</span>;
<a name="l00320"></a>00320     <span class="keywordflow">if</span> ( thisMsg-&gt;<a class="code" href="classKMMessage.html#e1adf17b8b22a8343ed60da3c12ecdb7" title="Return, if the message should not be deleted.">transferInProgress</a>() &amp;&amp;
<a name="l00321"></a>00321          thisMsg-&gt;parent()-&gt;folderType() == KMFolderTypeImap )
<a name="l00322"></a>00322     {
<a name="l00323"></a>00323       thisMsg-&gt;<a class="code" href="classKMMessage.html#32cc9d6f53648fd997efcc4f9d043197" title="Set that the message shall not be deleted because it is still required.">setTransferInProgress</a>( <span class="keyword">false</span>, <span class="keyword">true</span> );
<a name="l00324"></a>00324       thisMsg-&gt;parent()-&gt;ignoreJobsForMessage( thisMsg );
<a name="l00325"></a>00325     }
<a name="l00326"></a>00326 
<a name="l00327"></a>00327     <span class="keywordflow">if</span> ( thisMsg-&gt;parent() &amp;&amp; !thisMsg-&gt;<a class="code" href="classKMMessage.html#03cc096943ae864dd06ad23b05122777" title="Return true if the complete message is available without referring to the backing...">isComplete</a>() &amp;&amp;
<a name="l00328"></a>00328          ( !mProgressDialog || !mProgressDialog-&gt;wasCancelled() ) )
<a name="l00329"></a>00329     {
<a name="l00330"></a>00330       kdDebug(5006)&lt;&lt;<span class="stringliteral">"### INCOMPLETE\n"</span>;
<a name="l00331"></a>00331       <span class="comment">// the message needs to be transferred first</span>
<a name="l00332"></a>00332       complete = <span class="keyword">false</span>;
<a name="l00333"></a>00333       KMCommand::mCountJobs++;
<a name="l00334"></a>00334       FolderJob *job = thisMsg-&gt;parent()-&gt;createJob(thisMsg);
<a name="l00335"></a>00335       job-&gt;setCancellable( <span class="keyword">false</span> );
<a name="l00336"></a>00336       totalSize += thisMsg-&gt;<a class="code" href="classKMMessage.html#a2c7bb7de2908ff534a6c34d8538dffa" title="Get/set size on server.">msgSizeServer</a>();
<a name="l00337"></a>00337       <span class="comment">// emitted when the message was transferred successfully</span>
<a name="l00338"></a>00338       connect(job, SIGNAL(messageRetrieved(<a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a>*)),
<a name="l00339"></a>00339               <span class="keyword">this</span>, SLOT(slotMsgTransfered(<a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a>*)));
<a name="l00340"></a>00340       <span class="comment">// emitted when the job is destroyed</span>
<a name="l00341"></a>00341       connect(job, SIGNAL(finished()),
<a name="l00342"></a>00342               <span class="keyword">this</span>, SLOT(slotJobFinished()));
<a name="l00343"></a>00343       connect(job, SIGNAL(progress(<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span>, <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span>)),
<a name="l00344"></a>00344               <span class="keyword">this</span>, SLOT(slotProgress(<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span>, <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span>)));
<a name="l00345"></a>00345       <span class="comment">// msg musn't be deleted</span>
<a name="l00346"></a>00346       thisMsg-&gt;<a class="code" href="classKMMessage.html#32cc9d6f53648fd997efcc4f9d043197" title="Set that the message shall not be deleted because it is still required.">setTransferInProgress</a>(<span class="keyword">true</span>);
<a name="l00347"></a>00347       job-&gt;start();
<a name="l00348"></a>00348     } <span class="keywordflow">else</span> {
<a name="l00349"></a>00349       thisMsg-&gt;<a class="code" href="classKMMessage.html#32cc9d6f53648fd997efcc4f9d043197" title="Set that the message shall not be deleted because it is still required.">setTransferInProgress</a>(<span class="keyword">true</span>);
<a name="l00350"></a>00350       mRetrievedMsgs.append(thisMsg);
<a name="l00351"></a>00351     }
<a name="l00352"></a>00352   }
<a name="l00353"></a>00353 
<a name="l00354"></a>00354   <span class="keywordflow">if</span> (complete)
<a name="l00355"></a>00355   {
<a name="l00356"></a>00356     <span class="keyword">delete</span> mProgressDialog;
<a name="l00357"></a>00357     mProgressDialog = 0;
<a name="l00358"></a>00358     emit messagesTransfered( OK );
<a name="l00359"></a>00359   } <span class="keywordflow">else</span> {
<a name="l00360"></a>00360     <span class="comment">// wait for the transfer and tell the progressBar the necessary steps</span>
<a name="l00361"></a>00361     <span class="keywordflow">if</span> ( mProgressDialog ) {
<a name="l00362"></a>00362       connect(mProgressDialog, SIGNAL(cancelClicked()),
<a name="l00363"></a>00363               <span class="keyword">this</span>, SLOT(slotTransferCancelled()));
<a name="l00364"></a>00364       mProgressDialog-&gt;progressBar()-&gt;setTotalSteps(totalSize);
<a name="l00365"></a>00365     }
<a name="l00366"></a>00366   }
<a name="l00367"></a>00367 }
<a name="l00368"></a>00368 
<a name="l00369"></a>00369 <span class="keywordtype">void</span> KMCommand::slotMsgTransfered(<a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a>* msg)
<a name="l00370"></a>00370 {
<a name="l00371"></a>00371   <span class="keywordflow">if</span> ( mProgressDialog &amp;&amp; mProgressDialog-&gt;wasCancelled() ) {
<a name="l00372"></a>00372     emit messagesTransfered( Canceled );
<a name="l00373"></a>00373     <span class="keywordflow">return</span>;
<a name="l00374"></a>00374   }
<a name="l00375"></a>00375 
<a name="l00376"></a>00376   <span class="comment">// save the complete messages</span>
<a name="l00377"></a>00377   mRetrievedMsgs.append(msg);
<a name="l00378"></a>00378 }
<a name="l00379"></a>00379 
<a name="l00380"></a>00380 <span class="keywordtype">void</span> KMCommand::slotProgress( <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> done, <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> <span class="comment">/*total*/</span> )
<a name="l00381"></a>00381 {
<a name="l00382"></a>00382   mProgressDialog-&gt;progressBar()-&gt;setProgress( done );
<a name="l00383"></a>00383 }
<a name="l00384"></a>00384 
<a name="l00385"></a>00385 <span class="keywordtype">void</span> KMCommand::slotJobFinished()
<a name="l00386"></a>00386 {
<a name="l00387"></a>00387   <span class="comment">// the job is finished (with / without error)</span>
<a name="l00388"></a>00388   KMCommand::mCountJobs--;
<a name="l00389"></a>00389 
<a name="l00390"></a>00390   <span class="keywordflow">if</span> ( mProgressDialog &amp;&amp; mProgressDialog-&gt;wasCancelled() ) <span class="keywordflow">return</span>;
<a name="l00391"></a>00391 
<a name="l00392"></a>00392   <span class="keywordflow">if</span> ( (mCountMsgs - static_cast&lt;int&gt;(mRetrievedMsgs.count())) &gt; KMCommand::mCountJobs )
<a name="l00393"></a>00393   {
<a name="l00394"></a>00394     <span class="comment">// the message wasn't retrieved before =&gt; error</span>
<a name="l00395"></a>00395     <span class="keywordflow">if</span> ( mProgressDialog )
<a name="l00396"></a>00396       mProgressDialog-&gt;hide();
<a name="l00397"></a>00397     slotTransferCancelled();
<a name="l00398"></a>00398     <span class="keywordflow">return</span>;
<a name="l00399"></a>00399   }
<a name="l00400"></a>00400   <span class="comment">// update the progressbar</span>
<a name="l00401"></a>00401   <span class="keywordflow">if</span> ( mProgressDialog ) {
<a name="l00402"></a>00402     mProgressDialog-&gt;setLabel(i18n(<span class="stringliteral">"Please wait while the message is transferred"</span>,
<a name="l00403"></a>00403           <span class="stringliteral">"Please wait while the %n messages are transferred"</span>, KMCommand::mCountJobs));
<a name="l00404"></a>00404   }
<a name="l00405"></a>00405   <span class="keywordflow">if</span> (KMCommand::mCountJobs == 0)
<a name="l00406"></a>00406   {
<a name="l00407"></a>00407     <span class="comment">// all done</span>
<a name="l00408"></a>00408     <span class="keyword">delete</span> mProgressDialog;
<a name="l00409"></a>00409     mProgressDialog = 0;
<a name="l00410"></a>00410     emit messagesTransfered( OK );
<a name="l00411"></a>00411   }
<a name="l00412"></a>00412 }
<a name="l00413"></a>00413 
<a name="l00414"></a>00414 <span class="keywordtype">void</span> KMCommand::slotTransferCancelled()
<a name="l00415"></a>00415 {
<a name="l00416"></a>00416   <span class="comment">// kill the pending jobs</span>
<a name="l00417"></a>00417   QValueListIterator&lt;QGuardedPtr&lt;KMFolder&gt; &gt; fit;
<a name="l00418"></a>00418   <span class="keywordflow">for</span> ( fit = mFolders.begin(); fit != mFolders.end(); ++fit ) {
<a name="l00419"></a>00419     <span class="keywordflow">if</span> (!(*fit))
<a name="l00420"></a>00420       <span class="keywordflow">continue</span>;
<a name="l00421"></a>00421     <a class="code" href="classKMFolder.html" title="Mail folder.">KMFolder</a> *folder = *fit;
<a name="l00422"></a>00422     KMFolderImap *imapFolder = <span class="keyword">dynamic_cast&lt;</span>KMFolderImap*<span class="keyword">&gt;</span>(folder);
<a name="l00423"></a>00423     <span class="keywordflow">if</span> (imapFolder &amp;&amp; imapFolder-&gt;account()) {
<a name="l00424"></a>00424       imapFolder-&gt;account()-&gt;killAllJobs();
<a name="l00425"></a>00425     }
<a name="l00426"></a>00426   }
<a name="l00427"></a>00427 
<a name="l00428"></a>00428   KMCommand::mCountJobs = 0;
<a name="l00429"></a>00429   mCountMsgs = 0;
<a name="l00430"></a>00430   <span class="comment">// unget the transfered messages</span>
<a name="l00431"></a>00431   QPtrListIterator&lt;KMMessage&gt; it( mRetrievedMsgs );
<a name="l00432"></a>00432   <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a>* msg;
<a name="l00433"></a>00433   <span class="keywordflow">while</span> ( (msg = it.current()) != 0 )
<a name="l00434"></a>00434   {
<a name="l00435"></a>00435     <a class="code" href="classKMFolder.html" title="Mail folder.">KMFolder</a> *folder = msg-&gt;parent();
<a name="l00436"></a>00436     ++it;
<a name="l00437"></a>00437     <span class="keywordflow">if</span> (!folder)
<a name="l00438"></a>00438       <span class="keywordflow">continue</span>;
<a name="l00439"></a>00439     msg-&gt;<a class="code" href="classKMMessage.html#32cc9d6f53648fd997efcc4f9d043197" title="Set that the message shall not be deleted because it is still required.">setTransferInProgress</a>(<span class="keyword">false</span>);
<a name="l00440"></a>00440     <span class="keywordtype">int</span> idx = folder-&gt;<a class="code" href="classKMFolder.html#27adedd629ece306415faf3cf5fbc617" title="Returns the index of the given message or -1 if not found.">find</a>(msg);
<a name="l00441"></a>00441     <span class="keywordflow">if</span> (idx &gt; 0) folder-&gt;<a class="code" href="classKMFolder.html#55d936471c71f7d03f6e54d2f83a0b52" title="Replace KMMessage with KMMsgInfo and delete KMMessage.">unGetMsg</a>(idx);
<a name="l00442"></a>00442   }
<a name="l00443"></a>00443   mRetrievedMsgs.clear();
<a name="l00444"></a>00444   emit messagesTransfered( Canceled );
<a name="l00445"></a>00445 }
<a name="l00446"></a>00446 
<a name="l00447"></a>00447 <span class="keywordtype">void</span> KMCommand::keepFolderOpen( <a class="code" href="classKMFolder.html" title="Mail folder.">KMFolder</a> *folder )
<a name="l00448"></a>00448 {
<a name="l00449"></a>00449   folder-&gt;<a class="code" href="classKMFolder.html#c12a4bb5f265447d87b3e0e9a9482cc6" title="Open folder for access.">open</a>(<span class="stringliteral">"kmcommand"</span>);
<a name="l00450"></a>00450   mFolders.append( folder );
<a name="l00451"></a>00451 }
<a name="l00452"></a>00452 
<a name="l00453"></a>00453 KMMailtoComposeCommand::KMMailtoComposeCommand( <span class="keyword">const</span> KURL &amp;url,
<a name="l00454"></a>00454                                                 <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> *msg )
<a name="l00455"></a>00455   :mUrl( url ), mMessage( msg )
<a name="l00456"></a>00456 {
<a name="l00457"></a>00457 }
<a name="l00458"></a>00458 
<a name="l00459"></a>00459 KMCommand::Result KMMailtoComposeCommand::execute()
<a name="l00460"></a>00460 {
<a name="l00461"></a>00461   <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> *msg = <span class="keyword">new</span> <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a>;
<a name="l00462"></a>00462   uint <span class="keywordtype">id</span> = 0;
<a name="l00463"></a>00463 
<a name="l00464"></a>00464   <span class="keywordflow">if</span> ( mMessage &amp;&amp; mMessage-&gt;parent() )
<a name="l00465"></a>00465     <span class="keywordtype">id</span> = mMessage-&gt;parent()-&gt;identity();
<a name="l00466"></a>00466 
<a name="l00467"></a>00467   msg-&gt;<a class="code" href="classKMMessage.html#f3fe6794874214ffa4ad07a3992590e7" title="Initialize header fields.">initHeader</a>(<span class="keywordtype">id</span>);
<a name="l00468"></a>00468   msg-&gt;<a class="code" href="classKMMessage.html#6c6413b3690538964ac810f4c6755a5b" title="Set the message charset.">setCharset</a>(<span class="stringliteral">"utf-8"</span>);
<a name="l00469"></a>00469   msg-&gt;<a class="code" href="classKMMessage.html#5bb40f8b006d66c80cff9a43fa3018d6">setTo</a>( <a class="code" href="classKMMessage.html#e8dca5f50d21a63908d4026e2683ac60" title="Decodes a mailto URL.">KMMessage::decodeMailtoUrl</a>( mUrl.path() ) );
<a name="l00470"></a>00470 
<a name="l00471"></a>00471   KMail::Composer * win = KMail::makeComposer( msg, <span class="keywordtype">id</span> );
<a name="l00472"></a>00472   win-&gt;setCharset(<span class="stringliteral">""</span>, <span class="keyword">true</span>);
<a name="l00473"></a>00473   win-&gt;setFocusToSubject();
<a name="l00474"></a>00474   win-&gt;show();
<a name="l00475"></a>00475 
<a name="l00476"></a>00476   <span class="keywordflow">return</span> OK;
<a name="l00477"></a>00477 }
<a name="l00478"></a>00478 
<a name="l00479"></a>00479 
<a name="l00480"></a>00480 KMMailtoReplyCommand::KMMailtoReplyCommand( QWidget *parent,
<a name="l00481"></a>00481    <span class="keyword">const</span> KURL &amp;url, <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> *msg, <span class="keyword">const</span> QString &amp;selection )
<a name="l00482"></a>00482   :KMCommand( parent, msg ), mUrl( url ), mSelection( selection  )
<a name="l00483"></a>00483 {
<a name="l00484"></a>00484 }
<a name="l00485"></a>00485 
<a name="l00486"></a>00486 KMCommand::Result KMMailtoReplyCommand::execute()
<a name="l00487"></a>00487 {
<a name="l00488"></a>00488   <span class="comment">//TODO : consider factoring createReply into this method.</span>
<a name="l00489"></a>00489   <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> *msg = retrievedMessage();
<a name="l00490"></a>00490   <span class="keywordflow">if</span> ( !msg || !msg-&gt;<a class="code" href="classKMMessage.html#91762b3880f42da72185c59c40b28cac" title="Get a QTextCodec suitable for this message part.">codec</a>() ) {
<a name="l00491"></a>00491     <span class="keywordflow">return</span> Failed;
<a name="l00492"></a>00492   }
<a name="l00493"></a>00493   <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> *rmsg = msg-&gt;<a class="code" href="classKMMessage.html#bb0171befe57c922617b37bd58a35002" title="Create a new message that is a reply to this message, filling all required header...">createReply</a>( KMail::ReplyNone, mSelection );
<a name="l00494"></a>00494   rmsg-&gt;<a class="code" href="classKMMessage.html#5bb40f8b006d66c80cff9a43fa3018d6">setTo</a>( <a class="code" href="classKMMessage.html#e8dca5f50d21a63908d4026e2683ac60" title="Decodes a mailto URL.">KMMessage::decodeMailtoUrl</a>( mUrl.path() ) );
<a name="l00495"></a>00495 
<a name="l00496"></a>00496   KMail::Composer * win = KMail::makeComposer( rmsg, 0 );
<a name="l00497"></a>00497   win-&gt;setCharset(msg-&gt;<a class="code" href="classKMMessage.html#91762b3880f42da72185c59c40b28cac" title="Get a QTextCodec suitable for this message part.">codec</a>()-&gt;mimeName(), <span class="keyword">true</span>);
<a name="l00498"></a>00498   win-&gt;setReplyFocus();
<a name="l00499"></a>00499   win-&gt;show();
<a name="l00500"></a>00500 
<a name="l00501"></a>00501   <span class="keywordflow">return</span> OK;
<a name="l00502"></a>00502 }
<a name="l00503"></a>00503 
<a name="l00504"></a>00504 
<a name="l00505"></a>00505 KMMailtoForwardCommand::KMMailtoForwardCommand( QWidget *parent,
<a name="l00506"></a>00506    <span class="keyword">const</span> KURL &amp;url, <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> *msg )
<a name="l00507"></a>00507   :KMCommand( parent, msg ), mUrl( url )
<a name="l00508"></a>00508 {
<a name="l00509"></a>00509 }
<a name="l00510"></a>00510 
<a name="l00511"></a>00511 KMCommand::Result KMMailtoForwardCommand::execute()
<a name="l00512"></a>00512 {
<a name="l00513"></a>00513   <span class="comment">//TODO : consider factoring createForward into this method.</span>
<a name="l00514"></a>00514   <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> *msg = retrievedMessage();
<a name="l00515"></a>00515   <span class="keywordflow">if</span> ( !msg || !msg-&gt;<a class="code" href="classKMMessage.html#91762b3880f42da72185c59c40b28cac" title="Get a QTextCodec suitable for this message part.">codec</a>() ) {
<a name="l00516"></a>00516     <span class="keywordflow">return</span> Failed;
<a name="l00517"></a>00517   }
<a name="l00518"></a>00518   <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> *fmsg = msg-&gt;<a class="code" href="classKMMessage.html#86a19707a3ab205ef6272b2acc0181c9" title="Create a new message that is a forward of this message, filling all required header...">createForward</a>();
<a name="l00519"></a>00519   fmsg-&gt;<a class="code" href="classKMMessage.html#5bb40f8b006d66c80cff9a43fa3018d6">setTo</a>( <a class="code" href="classKMMessage.html#e8dca5f50d21a63908d4026e2683ac60" title="Decodes a mailto URL.">KMMessage::decodeMailtoUrl</a>( mUrl.path() ) );
<a name="l00520"></a>00520 
<a name="l00521"></a>00521   KMail::Composer * win = KMail::makeComposer( fmsg );
<a name="l00522"></a>00522   win-&gt;setCharset(msg-&gt;<a class="code" href="classKMMessage.html#91762b3880f42da72185c59c40b28cac" title="Get a QTextCodec suitable for this message part.">codec</a>()-&gt;mimeName(), <span class="keyword">true</span>);
<a name="l00523"></a>00523   win-&gt;show();
<a name="l00524"></a>00524 
<a name="l00525"></a>00525   <span class="keywordflow">return</span> OK;
<a name="l00526"></a>00526 }
<a name="l00527"></a>00527 
<a name="l00528"></a>00528 
<a name="l00529"></a>00529 KMAddBookmarksCommand::KMAddBookmarksCommand( <span class="keyword">const</span> KURL &amp;url, QWidget *parent )
<a name="l00530"></a>00530   : KMCommand( parent ), mUrl( url )
<a name="l00531"></a>00531 {
<a name="l00532"></a>00532 }
<a name="l00533"></a>00533 
<a name="l00534"></a>00534 KMCommand::Result KMAddBookmarksCommand::execute()
<a name="l00535"></a>00535 {
<a name="l00536"></a>00536   QString filename = locateLocal( <span class="stringliteral">"data"</span>, QString::fromLatin1(<span class="stringliteral">"konqueror/bookmarks.xml"</span>) );
<a name="l00537"></a>00537   KBookmarkManager *bookManager = KBookmarkManager::managerForFile( filename,
<a name="l00538"></a>00538                                                                     <span class="keyword">false</span> );
<a name="l00539"></a>00539   KBookmarkGroup group = bookManager-&gt;root();
<a name="l00540"></a>00540   group.addBookmark( bookManager, mUrl.path(), KURL( mUrl ) );
<a name="l00541"></a>00541   <span class="keywordflow">if</span>( bookManager-&gt;save() ) {
<a name="l00542"></a>00542     bookManager-&gt;emitChanged( group );
<a name="l00543"></a>00543   }
<a name="l00544"></a>00544 
<a name="l00545"></a>00545   <span class="keywordflow">return</span> OK;
<a name="l00546"></a>00546 }
<a name="l00547"></a>00547 
<a name="l00548"></a>00548 KMMailtoAddAddrBookCommand::KMMailtoAddAddrBookCommand( <span class="keyword">const</span> KURL &amp;url,
<a name="l00549"></a>00549    QWidget *parent )
<a name="l00550"></a>00550   : KMCommand( parent ), mUrl( url )
<a name="l00551"></a>00551 {
<a name="l00552"></a>00552 }
<a name="l00553"></a>00553 
<a name="l00554"></a>00554 KMCommand::Result KMMailtoAddAddrBookCommand::execute()
<a name="l00555"></a>00555 {
<a name="l00556"></a>00556   KAddrBookExternal::addEmail( <a class="code" href="classKMMessage.html#e8dca5f50d21a63908d4026e2683ac60" title="Decodes a mailto URL.">KMMessage::decodeMailtoUrl</a>( mUrl.path() ),
<a name="l00557"></a>00557                                parentWidget() );
<a name="l00558"></a>00558 
<a name="l00559"></a>00559   <span class="keywordflow">return</span> OK;
<a name="l00560"></a>00560 }
<a name="l00561"></a>00561 
<a name="l00562"></a>00562 
<a name="l00563"></a>00563 KMMailtoOpenAddrBookCommand::KMMailtoOpenAddrBookCommand( <span class="keyword">const</span> KURL &amp;url,
<a name="l00564"></a>00564    QWidget *parent )
<a name="l00565"></a>00565   : KMCommand( parent ), mUrl( url )
<a name="l00566"></a>00566 {
<a name="l00567"></a>00567 }
<a name="l00568"></a>00568 
<a name="l00569"></a>00569 KMCommand::Result KMMailtoOpenAddrBookCommand::execute()
<a name="l00570"></a>00570 {
<a name="l00571"></a>00571   KAddrBookExternal::openEmail( <a class="code" href="classKMMessage.html#e8dca5f50d21a63908d4026e2683ac60" title="Decodes a mailto URL.">KMMessage::decodeMailtoUrl</a>( mUrl.path() ),
<a name="l00572"></a>00572                                 parentWidget() );
<a name="l00573"></a>00573 
<a name="l00574"></a>00574   <span class="keywordflow">return</span> OK;
<a name="l00575"></a>00575 }
<a name="l00576"></a>00576 
<a name="l00577"></a>00577 
<a name="l00578"></a>00578 KMUrlCopyCommand::KMUrlCopyCommand( <span class="keyword">const</span> KURL &amp;url, KMMainWidget *mainWidget )
<a name="l00579"></a>00579   :mUrl( url ), mMainWidget( mainWidget )
<a name="l00580"></a>00580 {
<a name="l00581"></a>00581 }
<a name="l00582"></a>00582 
<a name="l00583"></a>00583 KMCommand::Result KMUrlCopyCommand::execute()
<a name="l00584"></a>00584 {
<a name="l00585"></a>00585   QClipboard* clip = QApplication::clipboard();
<a name="l00586"></a>00586 
<a name="l00587"></a>00587   <span class="keywordflow">if</span> (mUrl.protocol() == <span class="stringliteral">"mailto"</span>) {
<a name="l00588"></a>00588     <span class="comment">// put the url into the mouse selection and the clipboard</span>
<a name="l00589"></a>00589     QString address = <a class="code" href="classKMMessage.html#e8dca5f50d21a63908d4026e2683ac60" title="Decodes a mailto URL.">KMMessage::decodeMailtoUrl</a>( mUrl.path() );
<a name="l00590"></a>00590     clip-&gt;setSelectionMode( <span class="keyword">true</span> );
<a name="l00591"></a>00591     clip-&gt;setText( address );
<a name="l00592"></a>00592     clip-&gt;setSelectionMode( <span class="keyword">false</span> );
<a name="l00593"></a>00593     clip-&gt;setText( address );
<a name="l00594"></a>00594     KPIM::BroadcastStatus::instance()-&gt;setStatusMsg( i18n( <span class="stringliteral">"Address copied to clipboard."</span> ));
<a name="l00595"></a>00595   } <span class="keywordflow">else</span> {
<a name="l00596"></a>00596     <span class="comment">// put the url into the mouse selection and the clipboard</span>
<a name="l00597"></a>00597     clip-&gt;setSelectionMode( <span class="keyword">true</span> );
<a name="l00598"></a>00598     clip-&gt;setText( mUrl.url() );
<a name="l00599"></a>00599     clip-&gt;setSelectionMode( <span class="keyword">false</span> );
<a name="l00600"></a>00600     clip-&gt;setText( mUrl.url() );
<a name="l00601"></a>00601     KPIM::BroadcastStatus::instance()-&gt;setStatusMsg( i18n( <span class="stringliteral">"URL copied to clipboard."</span> ));
<a name="l00602"></a>00602   }
<a name="l00603"></a>00603 
<a name="l00604"></a>00604   <span class="keywordflow">return</span> OK;
<a name="l00605"></a>00605 }
<a name="l00606"></a>00606 
<a name="l00607"></a>00607 
<a name="l00608"></a>00608 KMUrlOpenCommand::KMUrlOpenCommand( <span class="keyword">const</span> KURL &amp;url, <a class="code" href="classKMReaderWin.html" title="This class implements a &amp;quot;reader window&amp;quot;, that is a window used for reading...">KMReaderWin</a> *readerWin )
<a name="l00609"></a>00609   :mUrl( url ), mReaderWin( readerWin )
<a name="l00610"></a>00610 {
<a name="l00611"></a>00611 }
<a name="l00612"></a>00612 
<a name="l00613"></a>00613 KMCommand::Result KMUrlOpenCommand::execute()
<a name="l00614"></a>00614 {
<a name="l00615"></a>00615   <span class="keywordflow">if</span> ( !mUrl.isEmpty() )
<a name="l00616"></a>00616     mReaderWin-&gt;slotUrlOpen( mUrl, KParts::URLArgs() );
<a name="l00617"></a>00617 
<a name="l00618"></a>00618   <span class="keywordflow">return</span> OK;
<a name="l00619"></a>00619 }
<a name="l00620"></a>00620 
<a name="l00621"></a>00621 
<a name="l00622"></a>00622 KMUrlSaveCommand::KMUrlSaveCommand( <span class="keyword">const</span> KURL &amp;url, QWidget *parent )
<a name="l00623"></a>00623   : KMCommand( parent ), mUrl( url )
<a name="l00624"></a>00624 {
<a name="l00625"></a>00625 }
<a name="l00626"></a>00626 
<a name="l00627"></a>00627 KMCommand::Result KMUrlSaveCommand::execute()
<a name="l00628"></a>00628 {
<a name="l00629"></a>00629   <span class="keywordflow">if</span> ( mUrl.isEmpty() )
<a name="l00630"></a>00630     <span class="keywordflow">return</span> OK;
<a name="l00631"></a>00631   KURL saveUrl = KFileDialog::getSaveURL(mUrl.fileName(), QString::null,
<a name="l00632"></a>00632                                          parentWidget() );
<a name="l00633"></a>00633   <span class="keywordflow">if</span> ( saveUrl.isEmpty() )
<a name="l00634"></a>00634     <span class="keywordflow">return</span> Canceled;
<a name="l00635"></a>00635   <span class="keywordflow">if</span> ( KIO::NetAccess::exists( saveUrl, <span class="keyword">false</span>, parentWidget() ) )
<a name="l00636"></a>00636   {
<a name="l00637"></a>00637     <span class="keywordflow">if</span> (KMessageBox::warningContinueCancel(0,
<a name="l00638"></a>00638         i18n(<span class="stringliteral">"&lt;qt&gt;File &lt;b&gt;%1&lt;/b&gt; exists.&lt;br&gt;Do you want to replace it?&lt;/qt&gt;"</span>)
<a name="l00639"></a>00639         .arg(saveUrl.prettyURL()), i18n(<span class="stringliteral">"Save to File"</span>), i18n(<span class="stringliteral">"&amp;Replace"</span>))
<a name="l00640"></a>00640         != KMessageBox::Continue)
<a name="l00641"></a>00641       <span class="keywordflow">return</span> Canceled;
<a name="l00642"></a>00642   }
<a name="l00643"></a>00643   KIO::Job *job = KIO::file_copy(mUrl, saveUrl, -1, <span class="keyword">true</span>);
<a name="l00644"></a>00644   connect(job, SIGNAL(result(KIO::Job*)), SLOT(slotUrlSaveResult(KIO::Job*)));
<a name="l00645"></a>00645   setEmitsCompletedItself( <span class="keyword">true</span> );
<a name="l00646"></a>00646   <span class="keywordflow">return</span> OK;
<a name="l00647"></a>00647 }
<a name="l00648"></a>00648 
<a name="l00649"></a>00649 <span class="keywordtype">void</span> KMUrlSaveCommand::slotUrlSaveResult( KIO::Job *job )
<a name="l00650"></a>00650 {
<a name="l00651"></a>00651   <span class="keywordflow">if</span> ( job-&gt;error() ) {
<a name="l00652"></a>00652     job-&gt;showErrorDialog();
<a name="l00653"></a>00653     setResult( Failed );
<a name="l00654"></a>00654     emit completed( <span class="keyword">this</span> );
<a name="l00655"></a>00655   }
<a name="l00656"></a>00656   <span class="keywordflow">else</span> {
<a name="l00657"></a>00657     setResult( OK );
<a name="l00658"></a>00658     emit completed( <span class="keyword">this</span> );
<a name="l00659"></a>00659   }
<a name="l00660"></a>00660 }
<a name="l00661"></a>00661 
<a name="l00662"></a>00662 
<a name="l00663"></a>00663 KMEditMsgCommand::KMEditMsgCommand( QWidget *parent, <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> *msg )
<a name="l00664"></a>00664   :KMCommand( parent, msg )
<a name="l00665"></a>00665 {
<a name="l00666"></a>00666 }
<a name="l00667"></a>00667 
<a name="l00668"></a>00668 KMCommand::Result KMEditMsgCommand::execute()
<a name="l00669"></a>00669 {
<a name="l00670"></a>00670   <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> *msg = retrievedMessage();
<a name="l00671"></a>00671   <span class="keywordflow">if</span> ( !msg || !msg-&gt;parent() ||
<a name="l00672"></a>00672        ( !kmkernel-&gt;folderIsDraftOrOutbox( msg-&gt;parent() ) &amp;&amp;
<a name="l00673"></a>00673          !kmkernel-&gt;folderIsTemplates( msg-&gt;parent() ) ) )
<a name="l00674"></a>00674     <span class="keywordflow">return</span> Failed;
<a name="l00675"></a>00675 
<a name="l00676"></a>00676   <span class="comment">// Remember the old parent, we need it a bit further down to be able</span>
<a name="l00677"></a>00677   <span class="comment">// to put the unchanged messsage back in the original folder if the nth</span>
<a name="l00678"></a>00678   <span class="comment">// edit is discarded, for n &gt; 1.</span>
<a name="l00679"></a>00679   <a class="code" href="classKMFolder.html" title="Mail folder.">KMFolder</a> *parent = msg-&gt;parent();
<a name="l00680"></a>00680   <span class="keywordflow">if</span> ( parent )
<a name="l00681"></a>00681     parent-&gt;<a class="code" href="classKMFolder.html#84bce28aea6c2d1638427bb81cded547" title="Detach message from this folder.">take</a>( parent-&gt;<a class="code" href="classKMFolder.html#27adedd629ece306415faf3cf5fbc617" title="Returns the index of the given message or -1 if not found.">find</a>( msg ) );
<a name="l00682"></a>00682 
<a name="l00683"></a>00683   KMail::Composer * win = KMail::makeComposer();
<a name="l00684"></a>00684   msg-&gt;<a class="code" href="classKMMessage.html#32cc9d6f53648fd997efcc4f9d043197" title="Set that the message shall not be deleted because it is still required.">setTransferInProgress</a>(<span class="keyword">false</span>); <span class="comment">// From here on on, the composer owns the message.</span>
<a name="l00685"></a>00685   win-&gt;setMsg(msg, <span class="keyword">false</span>, <span class="keyword">true</span>);
<a name="l00686"></a>00686   win-&gt;setFolder( parent );
<a name="l00687"></a>00687   win-&gt;show();
<a name="l00688"></a>00688 
<a name="l00689"></a>00689   <span class="keywordflow">return</span> OK;
<a name="l00690"></a>00690 }
<a name="l00691"></a>00691 
<a name="l00692"></a>00692 KMUseTemplateCommand::KMUseTemplateCommand( QWidget *parent, <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> *msg )
<a name="l00693"></a>00693   :KMCommand( parent, msg )
<a name="l00694"></a>00694 {
<a name="l00695"></a>00695 }
<a name="l00696"></a>00696 
<a name="l00697"></a>00697 KMCommand::Result KMUseTemplateCommand::execute()
<a name="l00698"></a>00698 {
<a name="l00699"></a>00699   <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> *msg = retrievedMessage();
<a name="l00700"></a>00700   <span class="keywordflow">if</span> ( !msg || !msg-&gt;parent() ||
<a name="l00701"></a>00701        !kmkernel-&gt;folderIsTemplates( msg-&gt;parent() ) )
<a name="l00702"></a>00702     <span class="keywordflow">return</span> Failed;
<a name="l00703"></a>00703 
<a name="l00704"></a>00704   <span class="comment">// Take a copy of the original message, which remains unchanged.</span>
<a name="l00705"></a>00705   <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> *newMsg = <span class="keyword">new</span> <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a>( <span class="keyword">new</span> DwMessage( *msg-&gt;<a class="code" href="classKMMessage.html#dc5c9ceacb31f0149307e693de6fed65">asDwMessage</a>() ) );
<a name="l00706"></a>00706   newMsg-&gt;<a class="code" href="classKMMessage.html#abd4c5528d72e909766b5aff2bb4ac68" title="Set if the message is a complete message.">setComplete</a>( msg-&gt;<a class="code" href="classKMMessage.html#03cc096943ae864dd06ad23b05122777" title="Return true if the complete message is available without referring to the backing...">isComplete</a>() );
<a name="l00707"></a>00707 
<a name="l00708"></a>00708   <span class="comment">// these fields need to be regenerated for the new message</span>
<a name="l00709"></a>00709   newMsg-&gt;<a class="code" href="classKMMessage.html#d01b9784ec819c2aa44e916098e76f78" title="Remove header field with given name.">removeHeaderField</a>(<span class="stringliteral">"Date"</span>);
<a name="l00710"></a>00710   newMsg-&gt;<a class="code" href="classKMMessage.html#d01b9784ec819c2aa44e916098e76f78" title="Remove header field with given name.">removeHeaderField</a>(<span class="stringliteral">"Message-ID"</span>);
<a name="l00711"></a>00711 
<a name="l00712"></a>00712   KMail::Composer *win = KMail::makeComposer();
<a name="l00713"></a>00713   newMsg-&gt;<a class="code" href="classKMMessage.html#32cc9d6f53648fd997efcc4f9d043197" title="Set that the message shall not be deleted because it is still required.">setTransferInProgress</a>( <span class="keyword">false</span> ); <span class="comment">// From here on on, the composer owns the message.</span>
<a name="l00714"></a>00714   win-&gt;setMsg( newMsg, <span class="keyword">false</span>, <span class="keyword">true</span> );
<a name="l00715"></a>00715   win-&gt;show();
<a name="l00716"></a>00716 
<a name="l00717"></a>00717   <span class="keywordflow">return</span> OK;
<a name="l00718"></a>00718 }
<a name="l00719"></a>00719 
<a name="l00720"></a>00720 KMShowMsgSrcCommand::KMShowMsgSrcCommand( QWidget *parent,
<a name="l00721"></a>00721   <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> *msg, <span class="keywordtype">bool</span> fixedFont )
<a name="l00722"></a>00722   :KMCommand( parent, msg ), mFixedFont( fixedFont )
<a name="l00723"></a>00723 {
<a name="l00724"></a>00724   <span class="comment">// remember complete state</span>
<a name="l00725"></a>00725   mMsgWasComplete = msg-&gt;<a class="code" href="classKMMessage.html#03cc096943ae864dd06ad23b05122777" title="Return true if the complete message is available without referring to the backing...">isComplete</a>();
<a name="l00726"></a>00726 }
<a name="l00727"></a>00727 
<a name="l00728"></a>00728 KMCommand::Result KMShowMsgSrcCommand::execute()
<a name="l00729"></a>00729 {
<a name="l00730"></a>00730   <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> *msg = retrievedMessage();
<a name="l00731"></a>00731   <span class="keywordflow">if</span> ( !msg || !msg-&gt;<a class="code" href="classKMMessage.html#91762b3880f42da72185c59c40b28cac" title="Get a QTextCodec suitable for this message part.">codec</a>() ) {
<a name="l00732"></a>00732     <span class="keywordflow">return</span> Failed;
<a name="l00733"></a>00733   }
<a name="l00734"></a>00734   <span class="keywordflow">if</span> ( msg-&gt;<a class="code" href="classKMMessage.html#03cc096943ae864dd06ad23b05122777" title="Return true if the complete message is available without referring to the backing...">isComplete</a>() &amp;&amp; !mMsgWasComplete )
<a name="l00735"></a>00735     msg-&gt;notify(); <span class="comment">// notify observers as msg was transfered</span>
<a name="l00736"></a>00736   QString str = msg-&gt;<a class="code" href="classKMMessage.html#91762b3880f42da72185c59c40b28cac" title="Get a QTextCodec suitable for this message part.">codec</a>()-&gt;toUnicode( msg-&gt;<a class="code" href="classKMMessage.html#b9b4e74c3446bce61e34201fd1e793d8" title="Return the entire message contents as a string.">asString</a>() );
<a name="l00737"></a>00737 
<a name="l00738"></a>00738   MailSourceViewer *viewer = <span class="keyword">new</span> MailSourceViewer(); <span class="comment">// deletes itself upon close</span>
<a name="l00739"></a>00739   viewer-&gt;setCaption( i18n(<span class="stringliteral">"Message as Plain Text"</span>) );
<a name="l00740"></a>00740   viewer-&gt;setText(str);
<a name="l00741"></a>00741   <span class="keywordflow">if</span>( mFixedFont )
<a name="l00742"></a>00742     viewer-&gt;setFont(KGlobalSettings::fixedFont());
<a name="l00743"></a>00743 
<a name="l00744"></a>00744   <span class="comment">// Well, there is no widget to be seen here, so we have to use QCursor::pos()</span>
<a name="l00745"></a>00745   <span class="comment">// Update: (GS) I'm not going to make this code behave according to Xinerama</span>
<a name="l00746"></a>00746   <span class="comment">//         configuration because this is quite the hack.</span>
<a name="l00747"></a>00747   <span class="keywordflow">if</span> (QApplication::desktop()-&gt;isVirtualDesktop()) {
<a name="l00748"></a>00748     <span class="keywordtype">int</span> scnum = QApplication::desktop()-&gt;screenNumber(QCursor::pos());
<a name="l00749"></a>00749     viewer-&gt;resize(QApplication::desktop()-&gt;screenGeometry(scnum).width()/2,
<a name="l00750"></a>00750                   2*QApplication::desktop()-&gt;screenGeometry(scnum).height()/3);
<a name="l00751"></a>00751   } <span class="keywordflow">else</span> {
<a name="l00752"></a>00752     viewer-&gt;resize(QApplication::desktop()-&gt;geometry().width()/2,
<a name="l00753"></a>00753                   2*QApplication::desktop()-&gt;geometry().height()/3);
<a name="l00754"></a>00754   }
<a name="l00755"></a>00755   viewer-&gt;show();
<a name="l00756"></a>00756 
<a name="l00757"></a>00757   <span class="keywordflow">return</span> OK;
<a name="l00758"></a>00758 }
<a name="l00759"></a>00759 
<a name="l00760"></a>00760 <span class="keyword">static</span> KURL subjectToUrl( <span class="keyword">const</span> QString &amp; subject ) {
<a name="l00761"></a>00761     <span class="keywordflow">return</span> KFileDialog::getSaveURL( subject.stripWhiteSpace()
<a name="l00762"></a>00762                                            .replace( QDir::separator(), <span class="charliteral">'_'</span> ),
<a name="l00763"></a>00763                                     <span class="stringliteral">"*.mbox"</span> );
<a name="l00764"></a>00764 }
<a name="l00765"></a>00765 
<a name="l00766"></a>00766 KMSaveMsgCommand::KMSaveMsgCommand( QWidget *parent, <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> * msg )
<a name="l00767"></a>00767   : KMCommand( parent ),
<a name="l00768"></a>00768     mMsgListIndex( 0 ),
<a name="l00769"></a>00769     mStandAloneMessage( 0 ),
<a name="l00770"></a>00770     mOffset( 0 ),
<a name="l00771"></a>00771     mTotalSize( msg ? msg-&gt;msgSize() : 0 )
<a name="l00772"></a>00772 {
<a name="l00773"></a>00773   <span class="keywordflow">if</span> ( !msg ) <span class="keywordflow">return</span>;
<a name="l00774"></a>00774   setDeletesItself( <span class="keyword">true</span> );
<a name="l00775"></a>00775   <span class="comment">// If the mail has a serial number, operate on sernums, if it does not</span>
<a name="l00776"></a>00776   <span class="comment">// we need to work with the pointer, but can be reasonably sure it won't</span>
<a name="l00777"></a>00777   <span class="comment">// go away, since it'll be an encapsulated message or one that was opened</span>
<a name="l00778"></a>00778   <span class="comment">// from an .eml file.</span>
<a name="l00779"></a>00779   <span class="keywordflow">if</span> ( msg-&gt;getMsgSerNum() != 0 ) {
<a name="l00780"></a>00780     mMsgList.append( msg-&gt;getMsgSerNum() );
<a name="l00781"></a>00781     <span class="keywordflow">if</span> ( msg-&gt;parent() ) {
<a name="l00782"></a>00782       msg-&gt;parent()-&gt;open( <span class="stringliteral">"kmsavemsgcommand"</span> );
<a name="l00783"></a>00783     }
<a name="l00784"></a>00784   } <span class="keywordflow">else</span> {
<a name="l00785"></a>00785     mStandAloneMessage = msg;
<a name="l00786"></a>00786   }
<a name="l00787"></a>00787   mUrl = subjectToUrl( msg-&gt;cleanSubject() );
<a name="l00788"></a>00788 }
<a name="l00789"></a>00789 
<a name="l00790"></a>00790 KMSaveMsgCommand::KMSaveMsgCommand( QWidget *parent,
<a name="l00791"></a>00791                                     <span class="keyword">const</span> QPtrList&lt;KMMsgBase&gt; &amp;msgList )
<a name="l00792"></a>00792   : KMCommand( parent ),
<a name="l00793"></a>00793     mMsgListIndex( 0 ),
<a name="l00794"></a>00794     mStandAloneMessage( 0 ),
<a name="l00795"></a>00795     mOffset( 0 ),
<a name="l00796"></a>00796     mTotalSize( 0 )
<a name="l00797"></a>00797 {
<a name="l00798"></a>00798   <span class="keywordflow">if</span> (!msgList.getFirst())
<a name="l00799"></a>00799     <span class="keywordflow">return</span>;
<a name="l00800"></a>00800   setDeletesItself( <span class="keyword">true</span> );
<a name="l00801"></a>00801   KMMsgBase *msgBase = msgList.getFirst();
<a name="l00802"></a>00802 
<a name="l00803"></a>00803   <span class="comment">// We operate on serNums and not the KMMsgBase pointers, as those can</span>
<a name="l00804"></a>00804   <span class="comment">// change, or become invalid when changing the current message, switching</span>
<a name="l00805"></a>00805   <span class="comment">// folders, etc.</span>
<a name="l00806"></a>00806   QPtrListIterator&lt;KMMsgBase&gt; it(msgList);
<a name="l00807"></a>00807   <span class="keywordflow">while</span> ( it.current() ) {
<a name="l00808"></a>00808     mMsgList.append( (*it)-&gt;getMsgSerNum() );
<a name="l00809"></a>00809     mTotalSize += (*it)-&gt;msgSize();
<a name="l00810"></a>00810     <span class="keywordflow">if</span> ((*it)-&gt;parent() != 0)
<a name="l00811"></a>00811       (*it)-&gt;parent()-&gt;open(<span class="stringliteral">"kmcommand"</span>);
<a name="l00812"></a>00812     ++it;
<a name="l00813"></a>00813   }
<a name="l00814"></a>00814   mMsgListIndex = 0;
<a name="l00815"></a>00815   mUrl = subjectToUrl( msgBase-&gt;cleanSubject() );
<a name="l00816"></a>00816 }
<a name="l00817"></a>00817 
<a name="l00818"></a>00818 KURL KMSaveMsgCommand::url()
<a name="l00819"></a>00819 {
<a name="l00820"></a>00820   <span class="keywordflow">return</span> mUrl;
<a name="l00821"></a>00821 }
<a name="l00822"></a>00822 
<a name="l00823"></a>00823 KMCommand::Result KMSaveMsgCommand::execute()
<a name="l00824"></a>00824 {
<a name="l00825"></a>00825   mJob = KIO::put( mUrl, S_IRUSR|S_IWUSR, <span class="keyword">false</span>, <span class="keyword">false</span> );
<a name="l00826"></a>00826   mJob-&gt;slotTotalSize( mTotalSize );
<a name="l00827"></a>00827   mJob-&gt;setAsyncDataEnabled( <span class="keyword">true</span> );
<a name="l00828"></a>00828   mJob-&gt;setReportDataSent( <span class="keyword">true</span> );
<a name="l00829"></a>00829   connect(mJob, SIGNAL(dataReq(KIO::Job*, QByteArray &amp;)),
<a name="l00830"></a>00830     SLOT(slotSaveDataReq()));
<a name="l00831"></a>00831   connect(mJob, SIGNAL(result(KIO::Job*)),
<a name="l00832"></a>00832     SLOT(slotSaveResult(KIO::Job*)));
<a name="l00833"></a>00833   setEmitsCompletedItself( <span class="keyword">true</span> );
<a name="l00834"></a>00834   <span class="keywordflow">return</span> OK;
<a name="l00835"></a>00835 }
<a name="l00836"></a>00836 
<a name="l00837"></a>00837 <span class="keywordtype">void</span> KMSaveMsgCommand::slotSaveDataReq()
<a name="l00838"></a>00838 {
<a name="l00839"></a>00839   <span class="keywordtype">int</span> remainingBytes = mData.size() - mOffset;
<a name="l00840"></a>00840   <span class="keywordflow">if</span> ( remainingBytes &gt; 0 ) {
<a name="l00841"></a>00841     <span class="comment">// eat leftovers first</span>
<a name="l00842"></a>00842     <span class="keywordflow">if</span> ( remainingBytes &gt; MAX_CHUNK_SIZE )
<a name="l00843"></a>00843       remainingBytes = MAX_CHUNK_SIZE;
<a name="l00844"></a>00844 
<a name="l00845"></a>00845     QByteArray data;
<a name="l00846"></a>00846     data.duplicate( mData.data() + mOffset, remainingBytes );
<a name="l00847"></a>00847     mJob-&gt;sendAsyncData( data );
<a name="l00848"></a>00848     mOffset += remainingBytes;
<a name="l00849"></a>00849     <span class="keywordflow">return</span>;
<a name="l00850"></a>00850   }
<a name="l00851"></a>00851   <span class="comment">// No leftovers, process next message.</span>
<a name="l00852"></a>00852   <span class="keywordflow">if</span> ( mMsgListIndex &lt; mMsgList.size() ) {
<a name="l00853"></a>00853     <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> *msg = 0;
<a name="l00854"></a>00854     <span class="keywordtype">int</span> idx = -1;
<a name="l00855"></a>00855     <a class="code" href="classKMFolder.html" title="Mail folder.">KMFolder</a> * p = 0;
<a name="l00856"></a>00856     <a class="code" href="classKMMsgDict.html#c39553f1139eff6c27e06082c625d067" title="Access the globally unique MessageDict.">KMMsgDict::instance</a>()-&gt;<a class="code" href="classKMMsgDict.html#c5d3159ddfbc5935322acd5602fb06ef" title="Returns the folder the message represented by the serial number key is in and the...">getLocation</a>( mMsgList[mMsgListIndex], &amp;p, &amp;idx );
<a name="l00857"></a>00857     assert( p );
<a name="l00858"></a>00858     assert( idx &gt;= 0 );
<a name="l00859"></a>00859     <span class="comment">//kdDebug() &lt;&lt; "SERNUM: " &lt;&lt; mMsgList[mMsgListIndex] &lt;&lt; " idx: " &lt;&lt; idx &lt;&lt; " folder: " &lt;&lt; p-&gt;prettyURL() &lt;&lt; endl;</span>
<a name="l00860"></a>00860     msg = p-&gt;<a class="code" href="classKMFolder.html#a0fdfeeed6e8e20eff1cd6445309b2f4" title="Read message at given index.">getMsg</a>(idx);
<a name="l00861"></a>00861 
<a name="l00862"></a>00862     <span class="keywordflow">if</span> ( msg ) {
<a name="l00863"></a>00863       <span class="keywordflow">if</span> ( msg-&gt;<a class="code" href="classKMMessage.html#e1adf17b8b22a8343ed60da3c12ecdb7" title="Return, if the message should not be deleted.">transferInProgress</a>() ) {
<a name="l00864"></a>00864         QByteArray data = QByteArray();
<a name="l00865"></a>00865         mJob-&gt;sendAsyncData( data );
<a name="l00866"></a>00866       }
<a name="l00867"></a>00867       msg-&gt;<a class="code" href="classKMMessage.html#32cc9d6f53648fd997efcc4f9d043197" title="Set that the message shall not be deleted because it is still required.">setTransferInProgress</a>( <span class="keyword">true</span> );
<a name="l00868"></a>00868       <span class="keywordflow">if</span> (msg-&gt;<a class="code" href="classKMMessage.html#03cc096943ae864dd06ad23b05122777" title="Return true if the complete message is available without referring to the backing...">isComplete</a>() ) {
<a name="l00869"></a>00869       slotMessageRetrievedForSaving( msg );
<a name="l00870"></a>00870       } <span class="keywordflow">else</span> {
<a name="l00871"></a>00871         <span class="comment">// retrieve Message first</span>
<a name="l00872"></a>00872         <span class="keywordflow">if</span> ( msg-&gt;parent()  &amp;&amp; !msg-&gt;<a class="code" href="classKMMessage.html#03cc096943ae864dd06ad23b05122777" title="Return true if the complete message is available without referring to the backing...">isComplete</a>() ) {
<a name="l00873"></a>00873           FolderJob *job = msg-&gt;parent()-&gt;createJob( msg );
<a name="l00874"></a>00874           job-&gt;setCancellable( <span class="keyword">false</span> );
<a name="l00875"></a>00875           connect(job, SIGNAL( messageRetrieved( <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a>* ) ),
<a name="l00876"></a>00876                   <span class="keyword">this</span>, SLOT( slotMessageRetrievedForSaving( <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a>* ) ) );
<a name="l00877"></a>00877           job-&gt;start();
<a name="l00878"></a>00878         }
<a name="l00879"></a>00879       }
<a name="l00880"></a>00880     } <span class="keywordflow">else</span> {
<a name="l00881"></a>00881       mJob-&gt;slotError( KIO::ERR_ABORTED,
<a name="l00882"></a>00882                        i18n(<span class="stringliteral">"The message was removed while saving it. "</span>
<a name="l00883"></a>00883                             <span class="stringliteral">"It has not been saved."</span>) );
<a name="l00884"></a>00884     }
<a name="l00885"></a>00885   } <span class="keywordflow">else</span> {
<a name="l00886"></a>00886     <span class="keywordflow">if</span> ( mStandAloneMessage ) {
<a name="l00887"></a>00887       <span class="comment">// do the special case of a standalone message</span>
<a name="l00888"></a>00888       slotMessageRetrievedForSaving( mStandAloneMessage );
<a name="l00889"></a>00889       mStandAloneMessage = 0;
<a name="l00890"></a>00890     } <span class="keywordflow">else</span> {
<a name="l00891"></a>00891       <span class="comment">// No more messages. Tell the putjob we are done.</span>
<a name="l00892"></a>00892       QByteArray data = QByteArray();
<a name="l00893"></a>00893       mJob-&gt;sendAsyncData( data );
<a name="l00894"></a>00894     }
<a name="l00895"></a>00895   }
<a name="l00896"></a>00896 }
<a name="l00897"></a>00897 
<a name="l00898"></a>00898 <span class="keywordtype">void</span> KMSaveMsgCommand::slotMessageRetrievedForSaving(<a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> *msg)
<a name="l00899"></a>00899 {
<a name="l00900"></a>00900   <span class="keywordflow">if</span> ( msg ) {
<a name="l00901"></a>00901     mData = KMFolderMbox::escapeFrom( msg-&gt;<a class="code" href="classKMMessage.html#49c5b4223492f2d81dcc97bb9462f728" title="Return the entire message contents in the DwString.">asDwString</a>() );
<a name="l00902"></a>00902     KMail::Util::insert( mData, 0, msg-&gt;<a class="code" href="classKMMessage.html#fa8e5a3da9c8c364ccbf80773b01c424" title="Returns an mbox message separator line for this message, i.e.">mboxMessageSeparator</a>() );
<a name="l00903"></a>00903     <a class="code" href="namespaceKMail_1_1Util.html#fe88142bebcaf57181c661999f9a0d17" title="Append a bytearray to a bytearray.">KMail::Util::append</a>( mData, <span class="stringliteral">"\n"</span> );
<a name="l00904"></a>00904     msg-&gt;<a class="code" href="classKMMessage.html#32cc9d6f53648fd997efcc4f9d043197" title="Set that the message shall not be deleted because it is still required.">setTransferInProgress</a>(<span class="keyword">false</span>);
<a name="l00905"></a>00905 
<a name="l00906"></a>00906     mOffset = 0;
<a name="l00907"></a>00907     QByteArray data;
<a name="l00908"></a>00908     <span class="keywordtype">int</span> size;
<a name="l00909"></a>00909     <span class="comment">// Unless it is great than 64 k send the whole message. kio buffers for us.</span>
<a name="l00910"></a>00910     <span class="keywordflow">if</span>( mData.size() &gt; (<span class="keywordtype">unsigned</span> int) MAX_CHUNK_SIZE )
<a name="l00911"></a>00911       size = MAX_CHUNK_SIZE;
<a name="l00912"></a>00912     <span class="keywordflow">else</span>
<a name="l00913"></a>00913       size = mData.size();
<a name="l00914"></a>00914 
<a name="l00915"></a>00915     data.duplicate( mData, size );
<a name="l00916"></a>00916     mJob-&gt;sendAsyncData( data );
<a name="l00917"></a>00917     mOffset += size;
<a name="l00918"></a>00918   }
<a name="l00919"></a>00919   ++mMsgListIndex;
<a name="l00920"></a>00920   <span class="comment">// Get rid of the message.</span>
<a name="l00921"></a>00921   <span class="keywordflow">if</span> ( msg &amp;&amp; msg-&gt;parent() &amp;&amp; msg-&gt;getMsgSerNum() ) {
<a name="l00922"></a>00922     <span class="keywordtype">int</span> idx = -1;
<a name="l00923"></a>00923     <a class="code" href="classKMFolder.html" title="Mail folder.">KMFolder</a> * p = 0;
<a name="l00924"></a>00924     <a class="code" href="classKMMsgDict.html#c39553f1139eff6c27e06082c625d067" title="Access the globally unique MessageDict.">KMMsgDict::instance</a>()-&gt;<a class="code" href="classKMMsgDict.html#c5d3159ddfbc5935322acd5602fb06ef" title="Returns the folder the message represented by the serial number key is in and the...">getLocation</a>( msg, &amp;p, &amp;idx );
<a name="l00925"></a>00925     assert( p == msg-&gt;parent() ); assert( idx &gt;= 0 );
<a name="l00926"></a>00926     p-&gt;<a class="code" href="classKMFolder.html#55d936471c71f7d03f6e54d2f83a0b52" title="Replace KMMessage with KMMsgInfo and delete KMMessage.">unGetMsg</a>( idx );
<a name="l00927"></a>00927     p-&gt;<a class="code" href="classKMFolder.html#8d167662bca3ad6315fa5ad67bb9e4dd" title="Close folder.">close</a>(<span class="stringliteral">"kmcommand"</span>);
<a name="l00928"></a>00928   }
<a name="l00929"></a>00929 }
<a name="l00930"></a>00930 
<a name="l00931"></a>00931 <span class="keywordtype">void</span> KMSaveMsgCommand::slotSaveResult(KIO::Job *job)
<a name="l00932"></a>00932 {
<a name="l00933"></a>00933   <span class="keywordflow">if</span> (job-&gt;error())
<a name="l00934"></a>00934   {
<a name="l00935"></a>00935     <span class="keywordflow">if</span> (job-&gt;error() == KIO::ERR_FILE_ALREADY_EXIST)
<a name="l00936"></a>00936     {
<a name="l00937"></a>00937       <span class="keywordflow">if</span> (KMessageBox::warningContinueCancel(0,
<a name="l00938"></a>00938         i18n(<span class="stringliteral">"File %1 exists.\nDo you want to replace it?"</span>)
<a name="l00939"></a>00939         .arg(mUrl.prettyURL()), i18n(<span class="stringliteral">"Save to File"</span>), i18n(<span class="stringliteral">"&amp;Replace"</span>))
<a name="l00940"></a>00940         == KMessageBox::Continue) {
<a name="l00941"></a>00941         mOffset = 0;
<a name="l00942"></a>00942 
<a name="l00943"></a>00943         mJob = KIO::put( mUrl, S_IRUSR|S_IWUSR, <span class="keyword">true</span>, <span class="keyword">false</span> );
<a name="l00944"></a>00944         mJob-&gt;slotTotalSize( mTotalSize );
<a name="l00945"></a>00945         mJob-&gt;setAsyncDataEnabled( <span class="keyword">true</span> );
<a name="l00946"></a>00946         mJob-&gt;setReportDataSent( <span class="keyword">true</span> );
<a name="l00947"></a>00947         connect(mJob, SIGNAL(dataReq(KIO::Job*, QByteArray &amp;)),
<a name="l00948"></a>00948             SLOT(slotSaveDataReq()));
<a name="l00949"></a>00949         connect(mJob, SIGNAL(result(KIO::Job*)),
<a name="l00950"></a>00950             SLOT(slotSaveResult(KIO::Job*)));
<a name="l00951"></a>00951       }
<a name="l00952"></a>00952     }
<a name="l00953"></a>00953     <span class="keywordflow">else</span>
<a name="l00954"></a>00954     {
<a name="l00955"></a>00955       job-&gt;showErrorDialog();
<a name="l00956"></a>00956       setResult( Failed );
<a name="l00957"></a>00957       emit completed( <span class="keyword">this</span> );
<a name="l00958"></a>00958       deleteLater();
<a name="l00959"></a>00959     }
<a name="l00960"></a>00960   } <span class="keywordflow">else</span> {
<a name="l00961"></a>00961     setResult( OK );
<a name="l00962"></a>00962     emit completed( <span class="keyword">this</span> );
<a name="l00963"></a>00963     deleteLater();
<a name="l00964"></a>00964   }
<a name="l00965"></a>00965 }
<a name="l00966"></a>00966 
<a name="l00967"></a>00967 <span class="comment">//-----------------------------------------------------------------------------</span>
<a name="l00968"></a>00968 
<a name="l00969"></a>00969 KMOpenMsgCommand::KMOpenMsgCommand( QWidget *parent, <span class="keyword">const</span> KURL &amp; url,
<a name="l00970"></a>00970                                     <span class="keyword">const</span> QString &amp; encoding )
<a name="l00971"></a>00971   : KMCommand( parent ),
<a name="l00972"></a>00972     mUrl( url ),
<a name="l00973"></a>00973     mEncoding( encoding )
<a name="l00974"></a>00974 {
<a name="l00975"></a>00975   setDeletesItself( <span class="keyword">true</span> );
<a name="l00976"></a>00976 }
<a name="l00977"></a>00977 
<a name="l00978"></a>00978 KMCommand::Result KMOpenMsgCommand::execute()
<a name="l00979"></a>00979 {
<a name="l00980"></a>00980   <span class="keywordflow">if</span> ( mUrl.isEmpty() ) {
<a name="l00981"></a>00981     mUrl = KFileDialog::getOpenURL( <span class="stringliteral">":OpenMessage"</span>, <span class="stringliteral">"message/rfc822 application/mbox"</span>,
<a name="l00982"></a>00982                                     parentWidget(), i18n(<span class="stringliteral">"Open Message"</span>) );
<a name="l00983"></a>00983   }
<a name="l00984"></a>00984   <span class="keywordflow">if</span> ( mUrl.isEmpty() ) {
<a name="l00985"></a>00985     setDeletesItself( <span class="keyword">false</span> );
<a name="l00986"></a>00986     <span class="keywordflow">return</span> Canceled;
<a name="l00987"></a>00987   }
<a name="l00988"></a>00988   mJob = KIO::get( mUrl, <span class="keyword">false</span>, <span class="keyword">false</span> );
<a name="l00989"></a>00989   mJob-&gt;setReportDataSent( <span class="keyword">true</span> );
<a name="l00990"></a>00990   connect( mJob, SIGNAL( data( KIO::Job *, <span class="keyword">const</span> QByteArray &amp; ) ),
<a name="l00991"></a>00991            <span class="keyword">this</span>, SLOT( slotDataArrived( KIO::Job*, <span class="keyword">const</span> QByteArray &amp; ) ) );
<a name="l00992"></a>00992   connect( mJob, SIGNAL( result( KIO::Job * ) ),
<a name="l00993"></a>00993            SLOT( slotResult( KIO::Job * ) ) );
<a name="l00994"></a>00994   setEmitsCompletedItself( <span class="keyword">true</span> );
<a name="l00995"></a>00995   <span class="keywordflow">return</span> OK;
<a name="l00996"></a>00996 }
<a name="l00997"></a>00997 
<a name="l00998"></a>00998 <span class="keywordtype">void</span> KMOpenMsgCommand::slotDataArrived( KIO::Job *, <span class="keyword">const</span> QByteArray &amp; data )
<a name="l00999"></a>00999 {
<a name="l01000"></a>01000   <span class="keywordflow">if</span> ( data.isEmpty() )
<a name="l01001"></a>01001     <span class="keywordflow">return</span>;
<a name="l01002"></a>01002 
<a name="l01003"></a>01003   mMsgString.append( data.data(), data.size() );
<a name="l01004"></a>01004 }
<a name="l01005"></a>01005 
<a name="l01006"></a>01006 <span class="keywordtype">void</span> KMOpenMsgCommand::slotResult( KIO::Job *job )
<a name="l01007"></a>01007 {
<a name="l01008"></a>01008   <span class="keywordflow">if</span> ( job-&gt;error() ) {
<a name="l01009"></a>01009     <span class="comment">// handle errors</span>
<a name="l01010"></a>01010     job-&gt;showErrorDialog();
<a name="l01011"></a>01011     setResult( Failed );
<a name="l01012"></a>01012     emit completed( <span class="keyword">this</span> );
<a name="l01013"></a>01013   }
<a name="l01014"></a>01014   <span class="keywordflow">else</span> {
<a name="l01015"></a>01015     <span class="keywordtype">int</span> startOfMessage = 0;
<a name="l01016"></a>01016     <span class="keywordflow">if</span> ( mMsgString.compare( 0, 5, <span class="stringliteral">"From "</span>, 5 ) == 0 ) {
<a name="l01017"></a>01017       startOfMessage = mMsgString.find( <span class="charliteral">'\n'</span> );
<a name="l01018"></a>01018       <span class="keywordflow">if</span> ( startOfMessage == -1 ) {
<a name="l01019"></a>01019         KMessageBox::sorry( parentWidget(),
<a name="l01020"></a>01020                             i18n( <span class="stringliteral">"The file does not contain a message."</span> ) );
<a name="l01021"></a>01021         setResult( Failed );
<a name="l01022"></a>01022         emit completed( <span class="keyword">this</span> );
<a name="l01023"></a>01023         <span class="comment">// Emulate closing of a secondary window so that KMail exits in case it</span>
<a name="l01024"></a>01024         <span class="comment">// was started with the --view command line option. Otherwise an</span>
<a name="l01025"></a>01025         <span class="comment">// invisible KMail would keep running.</span>
<a name="l01026"></a>01026         <a class="code" href="classKMail_1_1SecondaryWindow.html" title="Window class for secondary KMail window like the composer window and the separate...">SecondaryWindow</a> *win = <span class="keyword">new</span> <a class="code" href="classKMail_1_1SecondaryWindow.html" title="Window class for secondary KMail window like the composer window and the separate...">SecondaryWindow</a>();
<a name="l01027"></a>01027         win-&gt;close();
<a name="l01028"></a>01028         win-&gt;deleteLater();
<a name="l01029"></a>01029         deleteLater();
<a name="l01030"></a>01030         <span class="keywordflow">return</span>;
<a name="l01031"></a>01031       }
<a name="l01032"></a>01032       startOfMessage += 1; <span class="comment">// the message starts after the '\n'</span>
<a name="l01033"></a>01033     }
<a name="l01034"></a>01034     <span class="comment">// check for multiple messages in the file</span>
<a name="l01035"></a>01035     <span class="keywordtype">bool</span> multipleMessages = <span class="keyword">true</span>;
<a name="l01036"></a>01036     <span class="keywordtype">int</span> endOfMessage = mMsgString.find( <span class="stringliteral">"\nFrom "</span> );
<a name="l01037"></a>01037     <span class="keywordflow">if</span> ( endOfMessage == -1 ) {
<a name="l01038"></a>01038       endOfMessage = mMsgString.length();
<a name="l01039"></a>01039       multipleMessages = <span class="keyword">false</span>;
<a name="l01040"></a>01040     }
<a name="l01041"></a>01041     DwMessage *dwMsg = <span class="keyword">new</span> DwMessage;
<a name="l01042"></a>01042     dwMsg-&gt;FromString( mMsgString.substr( startOfMessage,
<a name="l01043"></a>01043                                           endOfMessage - startOfMessage ) );
<a name="l01044"></a>01044     dwMsg-&gt;Parse();
<a name="l01045"></a>01045     <span class="comment">// check whether we have a message ( no headers =&gt; this isn't a message )</span>
<a name="l01046"></a>01046     <span class="keywordflow">if</span> ( dwMsg-&gt;Headers().NumFields() == 0 ) {
<a name="l01047"></a>01047       KMessageBox::sorry( parentWidget(),
<a name="l01048"></a>01048                           i18n( <span class="stringliteral">"The file does not contain a message."</span> ) );
<a name="l01049"></a>01049       <span class="keyword">delete</span> dwMsg; dwMsg = 0;
<a name="l01050"></a>01050       setResult( Failed );
<a name="l01051"></a>01051       emit completed( <span class="keyword">this</span> );
<a name="l01052"></a>01052       <span class="comment">// Emulate closing of a secondary window (see above).</span>
<a name="l01053"></a>01053       <a class="code" href="classKMail_1_1SecondaryWindow.html" title="Window class for secondary KMail window like the composer window and the separate...">SecondaryWindow</a> *win = <span class="keyword">new</span> <a class="code" href="classKMail_1_1SecondaryWindow.html" title="Window class for secondary KMail window like the composer window and the separate...">SecondaryWindow</a>();
<a name="l01054"></a>01054       win-&gt;close();
<a name="l01055"></a>01055       win-&gt;deleteLater();
<a name="l01056"></a>01056       deleteLater();
<a name="l01057"></a>01057       <span class="keywordflow">return</span>;
<a name="l01058"></a>01058     }
<a name="l01059"></a>01059     <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> *msg = <span class="keyword">new</span> <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a>( dwMsg );
<a name="l01060"></a>01060     msg-&gt;<a class="code" href="classKMMessage.html#2312a56537b9b6ceefa0c2b4b17c387f" title="Set if the message is ready to be shown.">setReadyToShow</a>( <span class="keyword">true</span> );
<a name="l01061"></a>01061     KMReaderMainWin *win = <span class="keyword">new</span> KMReaderMainWin();
<a name="l01062"></a>01062     win-&gt;showMsg( mEncoding, msg );
<a name="l01063"></a>01063     win-&gt;show();
<a name="l01064"></a>01064     <span class="keywordflow">if</span> ( multipleMessages )
<a name="l01065"></a>01065       KMessageBox::information( win,
<a name="l01066"></a>01066                                 i18n( <span class="stringliteral">"The file contains multiple messages. "</span>
<a name="l01067"></a>01067                                       <span class="stringliteral">"Only the first message is shown."</span> ) );
<a name="l01068"></a>01068     setResult( OK );
<a name="l01069"></a>01069     emit completed( <span class="keyword">this</span> );
<a name="l01070"></a>01070   }
<a name="l01071"></a>01071   deleteLater();
<a name="l01072"></a>01072 }
<a name="l01073"></a>01073 
<a name="l01074"></a>01074 <span class="comment">//-----------------------------------------------------------------------------</span>
<a name="l01075"></a>01075 
<a name="l01076"></a>01076 <span class="comment">//TODO: ReplyTo, NoQuoteReplyTo, ReplyList, ReplyToAll, ReplyAuthor</span>
<a name="l01077"></a>01077 <span class="comment">//      are all similar and should be factored</span>
<a name="l01078"></a>01078 KMReplyToCommand::KMReplyToCommand( QWidget *parent, <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> *msg,
<a name="l01079"></a>01079                                     <span class="keyword">const</span> QString &amp;selection )
<a name="l01080"></a>01080   : KMCommand( parent, msg ), mSelection( selection )
<a name="l01081"></a>01081 {
<a name="l01082"></a>01082 }
<a name="l01083"></a>01083 
<a name="l01084"></a>01084 KMCommand::Result KMReplyToCommand::execute()
<a name="l01085"></a>01085 {
<a name="l01086"></a>01086   <a class="code" href="classKCursorSaver.html" title="sets a cursor and makes sure it&amp;#39;s restored on destruction Create a KCursorSaver...">KCursorSaver</a> busy(KBusyPtr::busy());
<a name="l01087"></a>01087   <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> *msg = retrievedMessage();
<a name="l01088"></a>01088   <span class="keywordflow">if</span> ( !msg || !msg-&gt;<a class="code" href="classKMMessage.html#91762b3880f42da72185c59c40b28cac" title="Get a QTextCodec suitable for this message part.">codec</a>() ) {
<a name="l01089"></a>01089     <span class="keywordflow">return</span> Failed;
<a name="l01090"></a>01090   }
<a name="l01091"></a>01091   <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> *reply = msg-&gt;<a class="code" href="classKMMessage.html#bb0171befe57c922617b37bd58a35002" title="Create a new message that is a reply to this message, filling all required header...">createReply</a>( KMail::ReplySmart, mSelection );
<a name="l01092"></a>01092   KMail::Composer * win = KMail::makeComposer( reply );
<a name="l01093"></a>01093   win-&gt;setCharset( msg-&gt;<a class="code" href="classKMMessage.html#91762b3880f42da72185c59c40b28cac" title="Get a QTextCodec suitable for this message part.">codec</a>()-&gt;mimeName(), true );
<a name="l01094"></a>01094   win-&gt;setReplyFocus();
<a name="l01095"></a>01095   win-&gt;show();
<a name="l01096"></a>01096 
<a name="l01097"></a>01097   <span class="keywordflow">return</span> OK;
<a name="l01098"></a>01098 }
<a name="l01099"></a>01099 
<a name="l01100"></a>01100 
<a name="l01101"></a>01101 KMNoQuoteReplyToCommand::KMNoQuoteReplyToCommand( QWidget *parent,
<a name="l01102"></a>01102                                                   <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> *msg )
<a name="l01103"></a>01103   : KMCommand( parent, msg )
<a name="l01104"></a>01104 {
<a name="l01105"></a>01105 }
<a name="l01106"></a>01106 
<a name="l01107"></a>01107 KMCommand::Result KMNoQuoteReplyToCommand::execute()
<a name="l01108"></a>01108 {
<a name="l01109"></a>01109   <a class="code" href="classKCursorSaver.html" title="sets a cursor and makes sure it&amp;#39;s restored on destruction Create a KCursorSaver...">KCursorSaver</a> busy(KBusyPtr::busy());
<a name="l01110"></a>01110   <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> *msg = retrievedMessage();
<a name="l01111"></a>01111   <span class="keywordflow">if</span> ( !msg || !msg-&gt;<a class="code" href="classKMMessage.html#91762b3880f42da72185c59c40b28cac" title="Get a QTextCodec suitable for this message part.">codec</a>() ) {
<a name="l01112"></a>01112     <span class="keywordflow">return</span> Failed;
<a name="l01113"></a>01113   }
<a name="l01114"></a>01114   <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> *reply = msg-&gt;<a class="code" href="classKMMessage.html#bb0171befe57c922617b37bd58a35002" title="Create a new message that is a reply to this message, filling all required header...">createReply</a>( KMail::ReplySmart, <span class="stringliteral">""</span>, <span class="keyword">true</span>);
<a name="l01115"></a>01115   KMail::Composer * win = KMail::makeComposer( reply );
<a name="l01116"></a>01116   win-&gt;setCharset(msg-&gt;<a class="code" href="classKMMessage.html#91762b3880f42da72185c59c40b28cac" title="Get a QTextCodec suitable for this message part.">codec</a>()-&gt;mimeName(), <span class="keyword">true</span>);
<a name="l01117"></a>01117   win-&gt;setReplyFocus(<span class="keyword">false</span>);
<a name="l01118"></a>01118   win-&gt;show();
<a name="l01119"></a>01119 
<a name="l01120"></a>01120   <span class="keywordflow">return</span> OK;
<a name="l01121"></a>01121 }
<a name="l01122"></a>01122 
<a name="l01123"></a>01123 
<a name="l01124"></a>01124 KMReplyListCommand::KMReplyListCommand( QWidget *parent,
<a name="l01125"></a>01125   <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> *msg, <span class="keyword">const</span> QString &amp;selection )
<a name="l01126"></a>01126  : KMCommand( parent, msg ), mSelection( selection )
<a name="l01127"></a>01127 {
<a name="l01128"></a>01128 }
<a name="l01129"></a>01129 
<a name="l01130"></a>01130 KMCommand::Result KMReplyListCommand::execute()
<a name="l01131"></a>01131 {
<a name="l01132"></a>01132   <a class="code" href="classKCursorSaver.html" title="sets a cursor and makes sure it&amp;#39;s restored on destruction Create a KCursorSaver...">KCursorSaver</a> busy(KBusyPtr::busy());
<a name="l01133"></a>01133   <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> *msg = retrievedMessage();
<a name="l01134"></a>01134   <span class="keywordflow">if</span> ( !msg || !msg-&gt;<a class="code" href="classKMMessage.html#91762b3880f42da72185c59c40b28cac" title="Get a QTextCodec suitable for this message part.">codec</a>() ) {
<a name="l01135"></a>01135     <span class="keywordflow">return</span> Failed;
<a name="l01136"></a>01136   }
<a name="l01137"></a>01137   <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> *reply = msg-&gt;<a class="code" href="classKMMessage.html#bb0171befe57c922617b37bd58a35002" title="Create a new message that is a reply to this message, filling all required header...">createReply</a>( KMail::ReplyList, mSelection);
<a name="l01138"></a>01138   KMail::Composer * win = KMail::makeComposer( reply );
<a name="l01139"></a>01139   win-&gt;setCharset(msg-&gt;<a class="code" href="classKMMessage.html#91762b3880f42da72185c59c40b28cac" title="Get a QTextCodec suitable for this message part.">codec</a>()-&gt;mimeName(), <span class="keyword">true</span>);
<a name="l01140"></a>01140   win-&gt;setReplyFocus(<span class="keyword">false</span>);
<a name="l01141"></a>01141   win-&gt;show();
<a name="l01142"></a>01142 
<a name="l01143"></a>01143   <span class="keywordflow">return</span> OK;
<a name="l01144"></a>01144 }
<a name="l01145"></a>01145 
<a name="l01146"></a>01146 
<a name="l01147"></a>01147 KMReplyToAllCommand::KMReplyToAllCommand( QWidget *parent,
<a name="l01148"></a>01148   <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> *msg, <span class="keyword">const</span> QString &amp;selection )
<a name="l01149"></a>01149   :KMCommand( parent, msg ), mSelection( selection )
<a name="l01150"></a>01150 {
<a name="l01151"></a>01151 }
<a name="l01152"></a>01152 
<a name="l01153"></a>01153 KMCommand::Result KMReplyToAllCommand::execute()
<a name="l01154"></a>01154 {
<a name="l01155"></a>01155   <a class="code" href="classKCursorSaver.html" title="sets a cursor and makes sure it&amp;#39;s restored on destruction Create a KCursorSaver...">KCursorSaver</a> busy(KBusyPtr::busy());
<a name="l01156"></a>01156   <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> *msg = retrievedMessage();
<a name="l01157"></a>01157   <span class="keywordflow">if</span> ( !msg || !msg-&gt;<a class="code" href="classKMMessage.html#91762b3880f42da72185c59c40b28cac" title="Get a QTextCodec suitable for this message part.">codec</a>() ) {
<a name="l01158"></a>01158     <span class="keywordflow">return</span> Failed;
<a name="l01159"></a>01159   }
<a name="l01160"></a>01160   <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> *reply = msg-&gt;<a class="code" href="classKMMessage.html#bb0171befe57c922617b37bd58a35002" title="Create a new message that is a reply to this message, filling all required header...">createReply</a>( KMail::ReplyAll, mSelection );
<a name="l01161"></a>01161   KMail::Composer * win = KMail::makeComposer( reply );
<a name="l01162"></a>01162   win-&gt;setCharset( msg-&gt;<a class="code" href="classKMMessage.html#91762b3880f42da72185c59c40b28cac" title="Get a QTextCodec suitable for this message part.">codec</a>()-&gt;mimeName(), true );
<a name="l01163"></a>01163   win-&gt;setReplyFocus();
<a name="l01164"></a>01164   win-&gt;show();
<a name="l01165"></a>01165 
<a name="l01166"></a>01166   <span class="keywordflow">return</span> OK;
<a name="l01167"></a>01167 }
<a name="l01168"></a>01168 
<a name="l01169"></a>01169 
<a name="l01170"></a>01170 KMReplyAuthorCommand::KMReplyAuthorCommand( QWidget *parent, <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> *msg,
<a name="l01171"></a>01171                                             <span class="keyword">const</span> QString &amp;selection )
<a name="l01172"></a>01172   : KMCommand( parent, msg ), mSelection( selection )
<a name="l01173"></a>01173 {
<a name="l01174"></a>01174 }
<a name="l01175"></a>01175 
<a name="l01176"></a>01176 KMCommand::Result KMReplyAuthorCommand::execute()
<a name="l01177"></a>01177 {
<a name="l01178"></a>01178   <a class="code" href="classKCursorSaver.html" title="sets a cursor and makes sure it&amp;#39;s restored on destruction Create a KCursorSaver...">KCursorSaver</a> busy(KBusyPtr::busy());
<a name="l01179"></a>01179   <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> *msg = retrievedMessage();
<a name="l01180"></a>01180   <span class="keywordflow">if</span> ( !msg || !msg-&gt;<a class="code" href="classKMMessage.html#91762b3880f42da72185c59c40b28cac" title="Get a QTextCodec suitable for this message part.">codec</a>() ) {
<a name="l01181"></a>01181     <span class="keywordflow">return</span> Failed;
<a name="l01182"></a>01182   }
<a name="l01183"></a>01183   <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> *reply = msg-&gt;<a class="code" href="classKMMessage.html#bb0171befe57c922617b37bd58a35002" title="Create a new message that is a reply to this message, filling all required header...">createReply</a>( KMail::ReplyAuthor, mSelection );
<a name="l01184"></a>01184   KMail::Composer * win = KMail::makeComposer( reply );
<a name="l01185"></a>01185   win-&gt;setCharset( msg-&gt;<a class="code" href="classKMMessage.html#91762b3880f42da72185c59c40b28cac" title="Get a QTextCodec suitable for this message part.">codec</a>()-&gt;mimeName(), true );
<a name="l01186"></a>01186   win-&gt;setReplyFocus();
<a name="l01187"></a>01187   win-&gt;show();
<a name="l01188"></a>01188 
<a name="l01189"></a>01189   <span class="keywordflow">return</span> OK;
<a name="l01190"></a>01190 }
<a name="l01191"></a>01191 
<a name="l01192"></a>01192 
<a name="l01193"></a>01193 KMForwardInlineCommand::KMForwardInlineCommand( QWidget *parent,
<a name="l01194"></a>01194   <span class="keyword">const</span> QPtrList&lt;KMMsgBase&gt; &amp;msgList, uint identity )
<a name="l01195"></a>01195   : KMCommand( parent, msgList ),
<a name="l01196"></a>01196     mIdentity( identity )
<a name="l01197"></a>01197 {
<a name="l01198"></a>01198 }
<a name="l01199"></a>01199 
<a name="l01200"></a>01200 KMForwardInlineCommand::KMForwardInlineCommand( QWidget *parent,
<a name="l01201"></a>01201   <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> *msg, uint identity )
<a name="l01202"></a>01202   : KMCommand( parent, msg ),
<a name="l01203"></a>01203     mIdentity( identity )
<a name="l01204"></a>01204 {
<a name="l01205"></a>01205 }
<a name="l01206"></a>01206 
<a name="l01207"></a>01207 KMCommand::Result KMForwardInlineCommand::execute()
<a name="l01208"></a>01208 {
<a name="l01209"></a>01209   QPtrList&lt;KMMessage&gt; msgList = retrievedMsgs();
<a name="l01210"></a>01210 
<a name="l01211"></a>01211   <span class="keywordflow">if</span> (msgList.count() &gt;= 2) { <span class="comment">// Multiple forward</span>
<a name="l01212"></a>01212 
<a name="l01213"></a>01213     uint <span class="keywordtype">id</span> = 0;
<a name="l01214"></a>01214     QPtrList&lt;KMMessage&gt; linklist;
<a name="l01215"></a>01215     <span class="keywordflow">for</span> ( <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> *msg = msgList.first(); msg; msg = msgList.next() ) {
<a name="l01216"></a>01216       <span class="comment">// set the identity</span>
<a name="l01217"></a>01217       <span class="keywordflow">if</span> (<span class="keywordtype">id</span> == 0)
<a name="l01218"></a>01218         <span class="keywordtype">id</span> = msg-&gt;<a class="code" href="classKMMessage.html#082d31ece170fb19cd5402a34a3f6727" title="Returns the value of a header field with the given name.">headerField</a>( <span class="stringliteral">"X-KMail-Identity"</span> ).stripWhiteSpace().toUInt();
<a name="l01219"></a>01219 
<a name="l01220"></a>01220       <span class="comment">// msgText += msg-&gt;createForwardBody();</span>
<a name="l01221"></a>01221       linklist.append( msg );
<a name="l01222"></a>01222     }
<a name="l01223"></a>01223     <span class="keywordflow">if</span> ( <span class="keywordtype">id</span> == 0 )
<a name="l01224"></a>01224       <span class="keywordtype">id</span> = mIdentity; <span class="comment">// use folder identity if no message had an id set</span>
<a name="l01225"></a>01225     <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> *fwdMsg = <span class="keyword">new</span> <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a>;
<a name="l01226"></a>01226     fwdMsg-&gt;<a class="code" href="classKMMessage.html#f3fe6794874214ffa4ad07a3992590e7" title="Initialize header fields.">initHeader</a>( <span class="keywordtype">id</span> );
<a name="l01227"></a>01227     fwdMsg-&gt;<a class="code" href="classKMMessage.html#3d877210924a2a0ba380e0ef11ff4e10" title="Set fields that are either automatically set (Message-id) or that do not change from...">setAutomaticFields</a>( <span class="keyword">true</span> );
<a name="l01228"></a>01228     fwdMsg-&gt;<a class="code" href="classKMMessage.html#6c6413b3690538964ac810f4c6755a5b" title="Set the message charset.">setCharset</a>( <span class="stringliteral">"utf-8"</span> );
<a name="l01229"></a>01229     <span class="comment">// fwdMsg-&gt;setBody( msgText );</span>
<a name="l01230"></a>01230 
<a name="l01231"></a>01231     <span class="keywordflow">for</span> ( <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> *msg = linklist.first(); msg; msg = linklist.next() ) {
<a name="l01232"></a>01232       TemplateParser parser( fwdMsg, TemplateParser::Forward,
<a name="l01233"></a>01233         msg-&gt;<a class="code" href="classKMMessage.html#00680f46ef6e512a0febc53fa671c6a9" title="Get the message body.">body</a>(), <span class="keyword">false</span>, <span class="keyword">false</span>, <span class="keyword">false</span>, <span class="keyword">false</span>);
<a name="l01234"></a>01234         parser.process( msg, 0, <span class="keyword">true</span> );
<a name="l01235"></a>01235 
<a name="l01236"></a>01236       fwdMsg-&gt;<a class="code" href="classKMMessage.html#03dc17ebd4de0cad4977d28040ed16fd" title="Links this message to aMsg, setting link type to aStatus.">link</a>( msg, KMMsgStatusForwarded );
<a name="l01237"></a>01237     }
<a name="l01238"></a>01238 
<a name="l01239"></a>01239     <a class="code" href="classKCursorSaver.html" title="sets a cursor and makes sure it&amp;#39;s restored on destruction Create a KCursorSaver...">KCursorSaver</a> busy( KBusyPtr::busy() );
<a name="l01240"></a>01240     KMail::Composer * win = KMail::makeComposer( fwdMsg, <span class="keywordtype">id</span> );
<a name="l01241"></a>01241     win-&gt;setCharset(<span class="stringliteral">""</span>);
<a name="l01242"></a>01242     win-&gt;show();
<a name="l01243"></a>01243 
<a name="l01244"></a>01244   } <span class="keywordflow">else</span> { <span class="comment">// forward a single message at most</span>
<a name="l01245"></a>01245 
<a name="l01246"></a>01246     <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> *msg = msgList.getFirst();
<a name="l01247"></a>01247     <span class="keywordflow">if</span> ( !msg || !msg-&gt;<a class="code" href="classKMMessage.html#91762b3880f42da72185c59c40b28cac" title="Get a QTextCodec suitable for this message part.">codec</a>() )
<a name="l01248"></a>01248       <span class="keywordflow">return</span> Failed;
<a name="l01249"></a>01249 
<a name="l01250"></a>01250     <a class="code" href="classKCursorSaver.html" title="sets a cursor and makes sure it&amp;#39;s restored on destruction Create a KCursorSaver...">KCursorSaver</a> busy( KBusyPtr::busy() );
<a name="l01251"></a>01251     <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> *fwdMsg = msg-&gt;<a class="code" href="classKMMessage.html#86a19707a3ab205ef6272b2acc0181c9" title="Create a new message that is a forward of this message, filling all required header...">createForward</a>();
<a name="l01252"></a>01252 
<a name="l01253"></a>01253     uint <span class="keywordtype">id</span> = msg-&gt;<a class="code" href="classKMMessage.html#082d31ece170fb19cd5402a34a3f6727" title="Returns the value of a header field with the given name.">headerField</a>( <span class="stringliteral">"X-KMail-Identity"</span> ).stripWhiteSpace().toUInt();
<a name="l01254"></a>01254     <span class="keywordflow">if</span> ( <span class="keywordtype">id</span> == 0 )
<a name="l01255"></a>01255       <span class="keywordtype">id</span> = mIdentity;
<a name="l01256"></a>01256     {
<a name="l01257"></a>01257       KMail::Composer * win = KMail::makeComposer( fwdMsg, <span class="keywordtype">id</span> );
<a name="l01258"></a>01258       win-&gt;setCharset( fwdMsg-&gt;<a class="code" href="classKMMessage.html#91762b3880f42da72185c59c40b28cac" title="Get a QTextCodec suitable for this message part.">codec</a>()-&gt;mimeName(), true );
<a name="l01259"></a>01259       win-&gt;setBody( fwdMsg-&gt;<a class="code" href="classKMMessage.html#178d0a93482282bad41cfa9031c93e5a" title="Returns the body part decoded to unicode.">bodyToUnicode</a>() );
<a name="l01260"></a>01260       win-&gt;show();
<a name="l01261"></a>01261     }
<a name="l01262"></a>01262   }
<a name="l01263"></a>01263   <span class="keywordflow">return</span> OK;
<a name="l01264"></a>01264 }
<a name="l01265"></a>01265 
<a name="l01266"></a>01266 
<a name="l01267"></a>01267 KMForwardAttachedCommand::KMForwardAttachedCommand( QWidget *parent,
<a name="l01268"></a>01268            <span class="keyword">const</span> QPtrList&lt;KMMsgBase&gt; &amp;msgList, uint identity, KMail::Composer *win )
<a name="l01269"></a>01269   : KMCommand( parent, msgList ), mIdentity( identity ),
<a name="l01270"></a>01270     mWin( QGuardedPtr&lt;KMail::Composer&gt;( win ))
<a name="l01271"></a>01271 {
<a name="l01272"></a>01272 }
<a name="l01273"></a>01273 
<a name="l01274"></a>01274 KMForwardAttachedCommand::KMForwardAttachedCommand( QWidget *parent,
<a name="l01275"></a>01275            <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> * msg, uint identity, KMail::Composer *win )
<a name="l01276"></a>01276   : KMCommand( parent, msg ), mIdentity( identity ),
<a name="l01277"></a>01277     mWin( QGuardedPtr&lt; KMail::Composer &gt;( win ))
<a name="l01278"></a>01278 {
<a name="l01279"></a>01279 }
<a name="l01280"></a>01280 
<a name="l01281"></a>01281 KMCommand::Result KMForwardAttachedCommand::execute()
<a name="l01282"></a>01282 {
<a name="l01283"></a>01283   QPtrList&lt;KMMessage&gt; msgList = retrievedMsgs();
<a name="l01284"></a>01284   <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> *fwdMsg = <span class="keyword">new</span> <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a>;
<a name="l01285"></a>01285 
<a name="l01286"></a>01286   <span class="keywordflow">if</span> (msgList.count() &gt;= 2) {
<a name="l01287"></a>01287     <span class="comment">// don't respect X-KMail-Identity headers because they might differ for</span>
<a name="l01288"></a>01288     <span class="comment">// the selected mails</span>
<a name="l01289"></a>01289     fwdMsg-&gt;<a class="code" href="classKMMessage.html#f3fe6794874214ffa4ad07a3992590e7" title="Initialize header fields.">initHeader</a>(mIdentity);
<a name="l01290"></a>01290   }
<a name="l01291"></a>01291   <span class="keywordflow">else</span> <span class="keywordflow">if</span> (msgList.count() == 1) {
<a name="l01292"></a>01292     <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> *msg = msgList.getFirst();
<a name="l01293"></a>01293     fwdMsg-&gt;<a class="code" href="classKMMessage.html#bf1ee113db641a10046e49c3986e00ca" title="Initialize headers fields according to the identity and the transport header of the...">initFromMessage</a>(msg);
<a name="l01294"></a>01294     fwdMsg-&gt;<a class="code" href="classKMMessage.html#dc02d16017d248f9f7c9dc980aee25b4">setSubject</a>( msg-&gt;forwardSubject() );
<a name="l01295"></a>01295   }
<a name="l01296"></a>01296 
<a name="l01297"></a>01297   fwdMsg-&gt;<a class="code" href="classKMMessage.html#3d877210924a2a0ba380e0ef11ff4e10" title="Set fields that are either automatically set (Message-id) or that do not change from...">setAutomaticFields</a>(<span class="keyword">true</span>);
<a name="l01298"></a>01298 
<a name="l01299"></a>01299   <a class="code" href="classKCursorSaver.html" title="sets a cursor and makes sure it&amp;#39;s restored on destruction Create a KCursorSaver...">KCursorSaver</a> busy(KBusyPtr::busy());
<a name="l01300"></a>01300   <span class="keywordflow">if</span> (!mWin)
<a name="l01301"></a>01301     mWin = KMail::makeComposer(fwdMsg, mIdentity);
<a name="l01302"></a>01302 
<a name="l01303"></a>01303   <span class="comment">// iterate through all the messages to be forwarded</span>
<a name="l01304"></a>01304   <span class="keywordflow">for</span> (<a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> *msg = msgList.first(); msg; msg = msgList.next()) {
<a name="l01305"></a>01305     <span class="comment">// remove headers that shouldn't be forwarded</span>
<a name="l01306"></a>01306     msg-&gt;<a class="code" href="classKMMessage.html#9e40cfc4b8ab3360e2a0ef71fd77b932" title="Remove all private header fields: *Status: and X-KMail-*.">removePrivateHeaderFields</a>();
<a name="l01307"></a>01307     msg-&gt;<a class="code" href="classKMMessage.html#d01b9784ec819c2aa44e916098e76f78" title="Remove header field with given name.">removeHeaderField</a>(<span class="stringliteral">"BCC"</span>);
<a name="l01308"></a>01308     <span class="comment">// set the part</span>
<a name="l01309"></a>01309     KMMessagePart *msgPart = <span class="keyword">new</span> KMMessagePart;
<a name="l01310"></a>01310     msgPart-&gt;setTypeStr(<span class="stringliteral">"message"</span>);
<a name="l01311"></a>01311     msgPart-&gt;setSubtypeStr(<span class="stringliteral">"rfc822"</span>);
<a name="l01312"></a>01312     msgPart-&gt;setCharset(msg-&gt;<a class="code" href="classKMMessage.html#5bfe73d1c397910fedfa770f6d869a57" title="Get the message charset.">charset</a>());
<a name="l01313"></a>01313     msgPart-&gt;setName(<span class="stringliteral">"forwarded message"</span>);
<a name="l01314"></a>01314     msgPart-&gt;setContentDescription(msg-&gt;<a class="code" href="classKMMessage.html#8c90e62a192cb4a42b53458d82697cbe" title="Get or set the &amp;#39;From&amp;#39; header field.">from</a>()+<span class="stringliteral">": "</span>+msg-&gt;<a class="code" href="classKMMessage.html#8f39a479d6704ce51bcdb1de1fc28bda" title="Get or set the &amp;#39;Subject&amp;#39; header field.">subject</a>());
<a name="l01315"></a>01315     msgPart-&gt;setContentDisposition( <span class="stringliteral">"inline"</span> );
<a name="l01316"></a>01316     <span class="comment">// THIS HAS TO BE AFTER setCte()!!!!</span>
<a name="l01317"></a>01317     msgPart-&gt;setMessageBody( <a class="code" href="namespaceKMail_1_1Util.html#62cdb963731a7eeaeca528f2e2651844" title="Construct a QByteArray from a DwString.">KMail::Util::ByteArray</a>( msg-&gt;<a class="code" href="classKMMessage.html#49c5b4223492f2d81dcc97bb9462f728" title="Return the entire message contents in the DwString.">asDwString</a>() ) );
<a name="l01318"></a>01318     msgPart-&gt;setCharset(<span class="stringliteral">""</span>);
<a name="l01319"></a>01319 
<a name="l01320"></a>01320     fwdMsg-&gt;<a class="code" href="classKMMessage.html#03dc17ebd4de0cad4977d28040ed16fd" title="Links this message to aMsg, setting link type to aStatus.">link</a>(msg, KMMsgStatusForwarded);
<a name="l01321"></a>01321     mWin-&gt;addAttach(msgPart);
<a name="l01322"></a>01322   }
<a name="l01323"></a>01323 
<a name="l01324"></a>01324   mWin-&gt;show();
<a name="l01325"></a>01325 
<a name="l01326"></a>01326   <span class="keywordflow">return</span> OK;
<a name="l01327"></a>01327 }
<a name="l01328"></a>01328 
<a name="l01329"></a>01329 
<a name="l01330"></a>01330 KMForwardDigestCommand::KMForwardDigestCommand( QWidget *parent,
<a name="l01331"></a>01331            <span class="keyword">const</span> QPtrList&lt;KMMsgBase&gt; &amp;msgList, uint identity, KMail::Composer *win )
<a name="l01332"></a>01332   : KMCommand( parent, msgList ), mIdentity( identity ),
<a name="l01333"></a>01333     mWin( QGuardedPtr&lt;KMail::Composer&gt;( win ))
<a name="l01334"></a>01334 {
<a name="l01335"></a>01335 }
<a name="l01336"></a>01336 
<a name="l01337"></a>01337 KMForwardDigestCommand::KMForwardDigestCommand( QWidget *parent,
<a name="l01338"></a>01338            <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> * msg, uint identity, KMail::Composer *win )
<a name="l01339"></a>01339   : KMCommand( parent, msg ), mIdentity( identity ),
<a name="l01340"></a>01340     mWin( QGuardedPtr&lt; KMail::Composer &gt;( win ))
<a name="l01341"></a>01341 {
<a name="l01342"></a>01342 }
<a name="l01343"></a>01343 
<a name="l01344"></a>01344 KMCommand::Result KMForwardDigestCommand::execute()
<a name="l01345"></a>01345 {
<a name="l01346"></a>01346   QPtrList&lt;KMMessage&gt; msgList = retrievedMsgs();
<a name="l01347"></a>01347 
<a name="l01348"></a>01348   <span class="keywordflow">if</span> ( msgList.count() &lt; 2 )
<a name="l01349"></a>01349     <span class="keywordflow">return</span> Undefined; <span class="comment">// must have more than 1 for a digest</span>
<a name="l01350"></a>01350 
<a name="l01351"></a>01351   uint <span class="keywordtype">id</span> = 0;
<a name="l01352"></a>01352   <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> *fwdMsg = <span class="keyword">new</span> <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a>;
<a name="l01353"></a>01353   KMMessagePart *msgPart = <span class="keyword">new</span> KMMessagePart;
<a name="l01354"></a>01354   QString msgPartText;
<a name="l01355"></a>01355   <span class="keywordtype">int</span> msgCnt = 0; <span class="comment">// incase there are some we can't forward for some reason</span>
<a name="l01356"></a>01356 
<a name="l01357"></a>01357   <span class="comment">// dummy header initialization; initialization with the correct identity</span>
<a name="l01358"></a>01358   <span class="comment">// is done below</span>
<a name="l01359"></a>01359   fwdMsg-&gt;<a class="code" href="classKMMessage.html#f3fe6794874214ffa4ad07a3992590e7" title="Initialize header fields.">initHeader</a>( <span class="keywordtype">id</span> );
<a name="l01360"></a>01360   fwdMsg-&gt;<a class="code" href="classKMMessage.html#3d877210924a2a0ba380e0ef11ff4e10" title="Set fields that are either automatically set (Message-id) or that do not change from...">setAutomaticFields</a>( <span class="keyword">true</span> );
<a name="l01361"></a>01361   fwdMsg-&gt;<a class="code" href="classKMMessage.html#b0fca7fbd1cd9f106f8b3cf6106bbf5c">mMsg</a>-&gt;Headers().ContentType().CreateBoundary( 1 );
<a name="l01362"></a>01362   QCString boundary( fwdMsg-&gt;<a class="code" href="classKMMessage.html#b0fca7fbd1cd9f106f8b3cf6106bbf5c">mMsg</a>-&gt;Headers().ContentType().Boundary().c_str() );
<a name="l01363"></a>01363   msgPartText = i18n(<span class="stringliteral">"\nThis is a MIME digest forward. The content of the"</span>
<a name="l01364"></a>01364                      <span class="stringliteral">" message is contained in the attachment(s).\n\n\n"</span>);
<a name="l01365"></a>01365   <span class="comment">// iterate through all the messages to be forwarded</span>
<a name="l01366"></a>01366   <span class="keywordflow">for</span> ( <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> *msg = msgList.first(); msg; msg = msgList.next() ) {
<a name="l01367"></a>01367     <span class="comment">// set the identity</span>
<a name="l01368"></a>01368     <span class="keywordflow">if</span> ( <span class="keywordtype">id</span> == 0 )
<a name="l01369"></a>01369       <span class="keywordtype">id</span> = msg-&gt;<a class="code" href="classKMMessage.html#082d31ece170fb19cd5402a34a3f6727" title="Returns the value of a header field with the given name.">headerField</a>( <span class="stringliteral">"X-KMail-Identity"</span> ).stripWhiteSpace().toUInt();
<a name="l01370"></a>01370     <span class="comment">// set the part header</span>
<a name="l01371"></a>01371     msgPartText += <span class="stringliteral">"--"</span>;
<a name="l01372"></a>01372     msgPartText += QString::fromLatin1( boundary );
<a name="l01373"></a>01373     msgPartText += <span class="stringliteral">"\nContent-Type: MESSAGE/RFC822"</span>;
<a name="l01374"></a>01374     msgPartText += QString( <span class="stringliteral">"; CHARSET=%1"</span> ).arg( msg-&gt;<a class="code" href="classKMMessage.html#5bfe73d1c397910fedfa770f6d869a57" title="Get the message charset.">charset</a>() );
<a name="l01375"></a>01375     msgPartText += <span class="charliteral">'\n'</span>;
<a name="l01376"></a>01376     DwHeaders dwh;
<a name="l01377"></a>01377     dwh.MessageId().CreateDefault();
<a name="l01378"></a>01378     msgPartText += QString( <span class="stringliteral">"Content-ID: %1\n"</span> ).arg( dwh.MessageId().AsString().c_str() );
<a name="l01379"></a>01379     msgPartText += QString( <span class="stringliteral">"Content-Description: %1"</span> ).arg( msg-&gt;<a class="code" href="classKMMessage.html#8f39a479d6704ce51bcdb1de1fc28bda" title="Get or set the &amp;#39;Subject&amp;#39; header field.">subject</a>() );
<a name="l01380"></a>01380     <span class="keywordflow">if</span> ( !msg-&gt;<a class="code" href="classKMMessage.html#8f39a479d6704ce51bcdb1de1fc28bda" title="Get or set the &amp;#39;Subject&amp;#39; header field.">subject</a>().contains( <span class="stringliteral">"(fwd)"</span> ) )
<a name="l01381"></a>01381       msgPartText += <span class="stringliteral">" (fwd)"</span>;
<a name="l01382"></a>01382     msgPartText += <span class="stringliteral">"\n\n"</span>;
<a name="l01383"></a>01383     <span class="comment">// remove headers that shouldn't be forwarded</span>
<a name="l01384"></a>01384     msg-&gt;<a class="code" href="classKMMessage.html#9e40cfc4b8ab3360e2a0ef71fd77b932" title="Remove all private header fields: *Status: and X-KMail-*.">removePrivateHeaderFields</a>();
<a name="l01385"></a>01385     msg-&gt;<a class="code" href="classKMMessage.html#d01b9784ec819c2aa44e916098e76f78" title="Remove header field with given name.">removeHeaderField</a>( <span class="stringliteral">"BCC"</span> );
<a name="l01386"></a>01386     <span class="comment">// set the part</span>
<a name="l01387"></a>01387     msgPartText += msg-&gt;<a class="code" href="classKMMessage.html#81a56c11d9920301421152b9e0afc45d" title="Return header as string.">headerAsString</a>();
<a name="l01388"></a>01388     msgPartText += <span class="charliteral">'\n'</span>;
<a name="l01389"></a>01389     msgPartText += msg-&gt;<a class="code" href="classKMMessage.html#00680f46ef6e512a0febc53fa671c6a9" title="Get the message body.">body</a>();
<a name="l01390"></a>01390     msgPartText += <span class="charliteral">'\n'</span>;     <span class="comment">// eot</span>
<a name="l01391"></a>01391     msgCnt++;
<a name="l01392"></a>01392     fwdMsg-&gt;<a class="code" href="classKMMessage.html#03dc17ebd4de0cad4977d28040ed16fd" title="Links this message to aMsg, setting link type to aStatus.">link</a>( msg, KMMsgStatusForwarded );
<a name="l01393"></a>01393   }
<a name="l01394"></a>01394 
<a name="l01395"></a>01395   <span class="keywordflow">if</span> ( <span class="keywordtype">id</span> == 0 )
<a name="l01396"></a>01396     <span class="keywordtype">id</span> = mIdentity; <span class="comment">// use folder identity if no message had an id set</span>
<a name="l01397"></a>01397   fwdMsg-&gt;<a class="code" href="classKMMessage.html#f3fe6794874214ffa4ad07a3992590e7" title="Initialize header fields.">initHeader</a>( <span class="keywordtype">id</span> );
<a name="l01398"></a>01398   msgPartText += <span class="stringliteral">"--"</span>;
<a name="l01399"></a>01399   msgPartText += QString::fromLatin1( boundary );
<a name="l01400"></a>01400   msgPartText += <span class="stringliteral">"--\n"</span>;
<a name="l01401"></a>01401   QCString tmp;
<a name="l01402"></a>01402   msgPart-&gt;setTypeStr( <span class="stringliteral">"MULTIPART"</span> );
<a name="l01403"></a>01403   tmp.sprintf( <span class="stringliteral">"Digest; boundary=\"%s\""</span>, boundary.data() );
<a name="l01404"></a>01404   msgPart-&gt;setSubtypeStr( tmp );
<a name="l01405"></a>01405   msgPart-&gt;setName( <span class="stringliteral">"unnamed"</span> );
<a name="l01406"></a>01406   msgPart-&gt;setCte( DwMime::kCte7bit );   <span class="comment">// does it have to be 7bit?</span>
<a name="l01407"></a>01407   msgPart-&gt;setContentDescription( QString( <span class="stringliteral">"Digest of %1 messages."</span> ).arg( msgCnt ) );
<a name="l01408"></a>01408   <span class="comment">// THIS HAS TO BE AFTER setCte()!!!!</span>
<a name="l01409"></a>01409   msgPart-&gt;setBodyEncoded( QCString( msgPartText.ascii() ) );
<a name="l01410"></a>01410   <a class="code" href="classKCursorSaver.html" title="sets a cursor and makes sure it&amp;#39;s restored on destruction Create a KCursorSaver...">KCursorSaver</a> busy( KBusyPtr::busy() );
<a name="l01411"></a>01411   KMail::Composer * win = KMail::makeComposer( fwdMsg, <span class="keywordtype">id</span> );
<a name="l01412"></a>01412   win-&gt;addAttach( msgPart );
<a name="l01413"></a>01413   win-&gt;show();
<a name="l01414"></a>01414   <span class="keywordflow">return</span> OK;
<a name="l01415"></a>01415 }
<a name="l01416"></a>01416 
<a name="l01417"></a>01417 KMRedirectCommand::KMRedirectCommand( QWidget *parent,
<a name="l01418"></a>01418                                       <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> *msg )
<a name="l01419"></a>01419   : KMCommand( parent, msg )
<a name="l01420"></a>01420 {
<a name="l01421"></a>01421 }
<a name="l01422"></a>01422 
<a name="l01423"></a>01423 KMCommand::Result KMRedirectCommand::execute()
<a name="l01424"></a>01424 {
<a name="l01425"></a>01425   <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> *msg = retrievedMessage();
<a name="l01426"></a>01426   <span class="keywordflow">if</span> ( !msg || !msg-&gt;<a class="code" href="classKMMessage.html#91762b3880f42da72185c59c40b28cac" title="Get a QTextCodec suitable for this message part.">codec</a>() )
<a name="l01427"></a>01427     <span class="keywordflow">return</span> Failed;
<a name="l01428"></a>01428 
<a name="l01429"></a>01429   <a class="code" href="classKMail_1_1RedirectDialog.html" title="KMail message redirection dialog.">RedirectDialog</a> dlg( parentWidget(), <span class="stringliteral">"redirect"</span>, <span class="keyword">true</span>,
<a name="l01430"></a>01430                       kmkernel-&gt;msgSender()-&gt;sendImmediate() );
<a name="l01431"></a>01431   <span class="keywordflow">if</span> (dlg.exec()==QDialog::Rejected) <span class="keywordflow">return</span> Failed;
<a name="l01432"></a>01432 
<a name="l01433"></a>01433   <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> *newMsg = msg-&gt;<a class="code" href="classKMMessage.html#75c36eac5a71cbf40330d7648e19baf9" title="Create a new message that is a redirect to this message, filling all required header...">createRedirect</a>( dlg.to() );
<a name="l01434"></a>01434   <a class="code" href="classKMFilterAction.html#10118125dadcf8f2f9f1d979952d7e5e" title="Automates the sending of MDNs from filter actions.">KMFilterAction::sendMDN</a>( msg, KMime::MDN::Dispatched );
<a name="l01435"></a>01435 
<a name="l01436"></a>01436   <span class="keyword">const</span> KMail::MessageSender::SendMethod method = dlg.sendImmediate()
<a name="l01437"></a>01437     ? KMail::MessageSender::SendImmediate
<a name="l01438"></a>01438     : KMail::MessageSender::SendLater;
<a name="l01439"></a>01439   <span class="keywordflow">if</span> ( !kmkernel-&gt;msgSender()-&gt;send( newMsg, method ) ) {
<a name="l01440"></a>01440     kdDebug(5006) &lt;&lt; <span class="stringliteral">"KMRedirectCommand: could not redirect message (sending failed)"</span> &lt;&lt; endl;
<a name="l01441"></a>01441     <span class="keywordflow">return</span> Failed; <span class="comment">// error: couldn't send</span>
<a name="l01442"></a>01442   }
<a name="l01443"></a>01443   <span class="keywordflow">return</span> OK;
<a name="l01444"></a>01444 }
<a name="l01445"></a>01445 
<a name="l01446"></a>01446 
<a name="l01447"></a>01447 KMCustomReplyToCommand::KMCustomReplyToCommand( QWidget *parent, <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> *msg,
<a name="l01448"></a>01448                                                 <span class="keyword">const</span> QString &amp;selection,
<a name="l01449"></a>01449                                                 <span class="keyword">const</span> QString &amp;tmpl )
<a name="l01450"></a>01450   : KMCommand( parent, msg ), mSelection( selection ), mTemplate( tmpl )
<a name="l01451"></a>01451 {
<a name="l01452"></a>01452 }
<a name="l01453"></a>01453 
<a name="l01454"></a>01454 KMCommand::Result KMCustomReplyToCommand::execute()
<a name="l01455"></a>01455 {
<a name="l01456"></a>01456   <a class="code" href="classKCursorSaver.html" title="sets a cursor and makes sure it&amp;#39;s restored on destruction Create a KCursorSaver...">KCursorSaver</a> busy(KBusyPtr::busy());
<a name="l01457"></a>01457   <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> *msg = retrievedMessage();
<a name="l01458"></a>01458   <span class="keywordflow">if</span> ( !msg || !msg-&gt;<a class="code" href="classKMMessage.html#91762b3880f42da72185c59c40b28cac" title="Get a QTextCodec suitable for this message part.">codec</a>() ) {
<a name="l01459"></a>01459     <span class="keywordflow">return</span> Failed;
<a name="l01460"></a>01460   }
<a name="l01461"></a>01461   <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> *reply = msg-&gt;<a class="code" href="classKMMessage.html#bb0171befe57c922617b37bd58a35002" title="Create a new message that is a reply to this message, filling all required header...">createReply</a>( KMail::ReplySmart, mSelection,
<a name="l01462"></a>01462                                        <span class="keyword">false</span>, <span class="keyword">true</span>, <span class="keyword">false</span>, mTemplate );
<a name="l01463"></a>01463   KMail::Composer * win = KMail::makeComposer( reply );
<a name="l01464"></a>01464   win-&gt;setCharset( msg-&gt;<a class="code" href="classKMMessage.html#91762b3880f42da72185c59c40b28cac" title="Get a QTextCodec suitable for this message part.">codec</a>()-&gt;mimeName(), true );
<a name="l01465"></a>01465   win-&gt;setReplyFocus();
<a name="l01466"></a>01466   win-&gt;show();
<a name="l01467"></a>01467 
<a name="l01468"></a>01468   <span class="keywordflow">return</span> OK;
<a name="l01469"></a>01469 }
<a name="l01470"></a>01470 
<a name="l01471"></a>01471 
<a name="l01472"></a>01472 KMCustomReplyAllToCommand::KMCustomReplyAllToCommand( QWidget *parent, <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> *msg,
<a name="l01473"></a>01473                                                       <span class="keyword">const</span> QString &amp;selection,
<a name="l01474"></a>01474                                                       <span class="keyword">const</span> QString &amp;tmpl )
<a name="l01475"></a>01475   : KMCommand( parent, msg ), mSelection( selection ), mTemplate( tmpl )
<a name="l01476"></a>01476 {
<a name="l01477"></a>01477 }
<a name="l01478"></a>01478 
<a name="l01479"></a>01479 KMCommand::Result KMCustomReplyAllToCommand::execute()
<a name="l01480"></a>01480 {
<a name="l01481"></a>01481   <a class="code" href="classKCursorSaver.html" title="sets a cursor and makes sure it&amp;#39;s restored on destruction Create a KCursorSaver...">KCursorSaver</a> busy(KBusyPtr::busy());
<a name="l01482"></a>01482   <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> *msg = retrievedMessage();
<a name="l01483"></a>01483   <span class="keywordflow">if</span> ( !msg || !msg-&gt;<a class="code" href="classKMMessage.html#91762b3880f42da72185c59c40b28cac" title="Get a QTextCodec suitable for this message part.">codec</a>() ) {
<a name="l01484"></a>01484     <span class="keywordflow">return</span> Failed;
<a name="l01485"></a>01485   }
<a name="l01486"></a>01486   <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> *reply = msg-&gt;<a class="code" href="classKMMessage.html#bb0171befe57c922617b37bd58a35002" title="Create a new message that is a reply to this message, filling all required header...">createReply</a>( KMail::ReplyAll, mSelection,
<a name="l01487"></a>01487                                        <span class="keyword">false</span>, <span class="keyword">true</span>, <span class="keyword">false</span>, mTemplate );
<a name="l01488"></a>01488   KMail::Composer * win = KMail::makeComposer( reply );
<a name="l01489"></a>01489   win-&gt;setCharset( msg-&gt;<a class="code" href="classKMMessage.html#91762b3880f42da72185c59c40b28cac" title="Get a QTextCodec suitable for this message part.">codec</a>()-&gt;mimeName(), true );
<a name="l01490"></a>01490   win-&gt;setReplyFocus();
<a name="l01491"></a>01491   win-&gt;show();
<a name="l01492"></a>01492 
<a name="l01493"></a>01493   <span class="keywordflow">return</span> OK;
<a name="l01494"></a>01494 }
<a name="l01495"></a>01495 
<a name="l01496"></a>01496 
<a name="l01497"></a>01497 KMCustomForwardCommand::KMCustomForwardCommand( QWidget *parent,
<a name="l01498"></a>01498   <span class="keyword">const</span> QPtrList&lt;KMMsgBase&gt; &amp;msgList, uint identity, <span class="keyword">const</span> QString &amp;tmpl )
<a name="l01499"></a>01499   : KMCommand( parent, msgList ),
<a name="l01500"></a>01500     mIdentity( identity ), mTemplate( tmpl )
<a name="l01501"></a>01501 {
<a name="l01502"></a>01502 }
<a name="l01503"></a>01503 
<a name="l01504"></a>01504 KMCustomForwardCommand::KMCustomForwardCommand( QWidget *parent,
<a name="l01505"></a>01505   <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> *msg, uint identity, <span class="keyword">const</span> QString &amp;tmpl )
<a name="l01506"></a>01506   : KMCommand( parent, msg ),
<a name="l01507"></a>01507     mIdentity( identity ), mTemplate( tmpl )
<a name="l01508"></a>01508 {
<a name="l01509"></a>01509 }
<a name="l01510"></a>01510 
<a name="l01511"></a>01511 KMCommand::Result KMCustomForwardCommand::execute()
<a name="l01512"></a>01512 {
<a name="l01513"></a>01513   QPtrList&lt;KMMessage&gt; msgList = retrievedMsgs();
<a name="l01514"></a>01514 
<a name="l01515"></a>01515   <span class="keywordflow">if</span> (msgList.count() &gt;= 2) { <span class="comment">// Multiple forward</span>
<a name="l01516"></a>01516 
<a name="l01517"></a>01517     uint <span class="keywordtype">id</span> = 0;
<a name="l01518"></a>01518     QPtrList&lt;KMMessage&gt; linklist;
<a name="l01519"></a>01519     <span class="keywordflow">for</span> ( <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> *msg = msgList.first(); msg; msg = msgList.next() ) {
<a name="l01520"></a>01520       <span class="comment">// set the identity</span>
<a name="l01521"></a>01521       <span class="keywordflow">if</span> (<span class="keywordtype">id</span> == 0)
<a name="l01522"></a>01522         <span class="keywordtype">id</span> = msg-&gt;<a class="code" href="classKMMessage.html#082d31ece170fb19cd5402a34a3f6727" title="Returns the value of a header field with the given name.">headerField</a>( <span class="stringliteral">"X-KMail-Identity"</span> ).stripWhiteSpace().toUInt();
<a name="l01523"></a>01523 
<a name="l01524"></a>01524       <span class="comment">// msgText += msg-&gt;createForwardBody();</span>
<a name="l01525"></a>01525       linklist.append( msg );
<a name="l01526"></a>01526     }
<a name="l01527"></a>01527     <span class="keywordflow">if</span> ( <span class="keywordtype">id</span> == 0 )
<a name="l01528"></a>01528       <span class="keywordtype">id</span> = mIdentity; <span class="comment">// use folder identity if no message had an id set</span>
<a name="l01529"></a>01529     <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> *fwdMsg = <span class="keyword">new</span> <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a>;
<a name="l01530"></a>01530     fwdMsg-&gt;<a class="code" href="classKMMessage.html#f3fe6794874214ffa4ad07a3992590e7" title="Initialize header fields.">initHeader</a>( <span class="keywordtype">id</span> );
<a name="l01531"></a>01531     fwdMsg-&gt;<a class="code" href="classKMMessage.html#3d877210924a2a0ba380e0ef11ff4e10" title="Set fields that are either automatically set (Message-id) or that do not change from...">setAutomaticFields</a>( <span class="keyword">true</span> );
<a name="l01532"></a>01532     fwdMsg-&gt;<a class="code" href="classKMMessage.html#6c6413b3690538964ac810f4c6755a5b" title="Set the message charset.">setCharset</a>( <span class="stringliteral">"utf-8"</span> );
<a name="l01533"></a>01533     <span class="comment">// fwdMsg-&gt;setBody( msgText );</span>
<a name="l01534"></a>01534 
<a name="l01535"></a>01535     <span class="keywordflow">for</span> ( <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> *msg = linklist.first(); msg; msg = linklist.next() ) {
<a name="l01536"></a>01536       TemplateParser parser( fwdMsg, TemplateParser::Forward,
<a name="l01537"></a>01537         msg-&gt;<a class="code" href="classKMMessage.html#00680f46ef6e512a0febc53fa671c6a9" title="Get the message body.">body</a>(), <span class="keyword">false</span>, <span class="keyword">false</span>, <span class="keyword">false</span>, <span class="keyword">false</span>);
<a name="l01538"></a>01538         parser.process( msg, 0, <span class="keyword">true</span> );
<a name="l01539"></a>01539 
<a name="l01540"></a>01540       fwdMsg-&gt;<a class="code" href="classKMMessage.html#03dc17ebd4de0cad4977d28040ed16fd" title="Links this message to aMsg, setting link type to aStatus.">link</a>( msg, KMMsgStatusForwarded );
<a name="l01541"></a>01541     }
<a name="l01542"></a>01542 
<a name="l01543"></a>01543     <a class="code" href="classKCursorSaver.html" title="sets a cursor and makes sure it&amp;#39;s restored on destruction Create a KCursorSaver...">KCursorSaver</a> busy( KBusyPtr::busy() );
<a name="l01544"></a>01544     KMail::Composer * win = KMail::makeComposer( fwdMsg, <span class="keywordtype">id</span> );
<a name="l01545"></a>01545     win-&gt;setCharset(<span class="stringliteral">""</span>);
<a name="l01546"></a>01546     win-&gt;show();
<a name="l01547"></a>01547 
<a name="l01548"></a>01548   } <span class="keywordflow">else</span> { <span class="comment">// forward a single message at most</span>
<a name="l01549"></a>01549 
<a name="l01550"></a>01550     <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> *msg = msgList.getFirst();
<a name="l01551"></a>01551     <span class="keywordflow">if</span> ( !msg || !msg-&gt;<a class="code" href="classKMMessage.html#91762b3880f42da72185c59c40b28cac" title="Get a QTextCodec suitable for this message part.">codec</a>() )
<a name="l01552"></a>01552       <span class="keywordflow">return</span> Failed;
<a name="l01553"></a>01553 
<a name="l01554"></a>01554     <a class="code" href="classKCursorSaver.html" title="sets a cursor and makes sure it&amp;#39;s restored on destruction Create a KCursorSaver...">KCursorSaver</a> busy( KBusyPtr::busy() );
<a name="l01555"></a>01555     <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> *fwdMsg = msg-&gt;<a class="code" href="classKMMessage.html#86a19707a3ab205ef6272b2acc0181c9" title="Create a new message that is a forward of this message, filling all required header...">createForward</a>( mTemplate );
<a name="l01556"></a>01556 
<a name="l01557"></a>01557     uint <span class="keywordtype">id</span> = msg-&gt;<a class="code" href="classKMMessage.html#082d31ece170fb19cd5402a34a3f6727" title="Returns the value of a header field with the given name.">headerField</a>( <span class="stringliteral">"X-KMail-Identity"</span> ).stripWhiteSpace().toUInt();
<a name="l01558"></a>01558     <span class="keywordflow">if</span> ( <span class="keywordtype">id</span> == 0 )
<a name="l01559"></a>01559       <span class="keywordtype">id</span> = mIdentity;
<a name="l01560"></a>01560     {
<a name="l01561"></a>01561       KMail::Composer * win = KMail::makeComposer( fwdMsg, <span class="keywordtype">id</span> );
<a name="l01562"></a>01562       win-&gt;setCharset( fwdMsg-&gt;<a class="code" href="classKMMessage.html#91762b3880f42da72185c59c40b28cac" title="Get a QTextCodec suitable for this message part.">codec</a>()-&gt;mimeName(), true );
<a name="l01563"></a>01563       win-&gt;show();
<a name="l01564"></a>01564     }
<a name="l01565"></a>01565   }
<a name="l01566"></a>01566   <span class="keywordflow">return</span> OK;
<a name="l01567"></a>01567 }
<a name="l01568"></a>01568 
<a name="l01569"></a>01569 
<a name="l01570"></a>01570 KMPrintCommand::KMPrintCommand( QWidget *parent,
<a name="l01571"></a>01571   <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> *msg, <span class="keywordtype">bool</span> htmlOverride, <span class="keywordtype">bool</span> htmlLoadExtOverride,
<a name="l01572"></a>01572   <span class="keywordtype">bool</span> useFixedFont, <span class="keyword">const</span> QString &amp; encoding )
<a name="l01573"></a>01573   : KMCommand( parent, msg ), mHtmlOverride( htmlOverride ),
<a name="l01574"></a>01574     mHtmlLoadExtOverride( htmlLoadExtOverride ),
<a name="l01575"></a>01575     mUseFixedFont( useFixedFont ), mEncoding( encoding )
<a name="l01576"></a>01576 {
<a name="l01577"></a>01577   mOverrideFont = KGlobalSettings::generalFont();
<a name="l01578"></a>01578 }
<a name="l01579"></a>01579 
<a name="l01580"></a>01580 
<a name="l01581"></a>01581 <span class="keywordtype">void</span> KMPrintCommand::setOverrideFont( <span class="keyword">const</span> QFont&amp; font )
<a name="l01582"></a>01582 {
<a name="l01583"></a>01583   mOverrideFont = font;
<a name="l01584"></a>01584 }
<a name="l01585"></a>01585 
<a name="l01586"></a>01586 KMCommand::Result KMPrintCommand::execute()
<a name="l01587"></a>01587 {
<a name="l01588"></a>01588   <a class="code" href="classKMReaderWin.html" title="This class implements a &amp;quot;reader window&amp;quot;, that is a window used for reading...">KMReaderWin</a> printWin( 0, 0, 0 );
<a name="l01589"></a>01589   printWin.setPrinting( <span class="keyword">true</span> );
<a name="l01590"></a>01590   printWin.readConfig();
<a name="l01591"></a>01591   printWin.setHtmlOverride( mHtmlOverride );
<a name="l01592"></a>01592   printWin.setHtmlLoadExtOverride( mHtmlLoadExtOverride );
<a name="l01593"></a>01593   printWin.setUseFixedFont( mUseFixedFont );
<a name="l01594"></a>01594   printWin.setOverrideEncoding( mEncoding );
<a name="l01595"></a>01595   printWin.setPrintFont( mOverrideFont );
<a name="l01596"></a>01596   printWin.setDecryptMessageOverwrite( <span class="keyword">true</span> );
<a name="l01597"></a>01597   printWin.setMsg( retrievedMessage(), <span class="keyword">true</span> );
<a name="l01598"></a>01598   printWin.printMsg();
<a name="l01599"></a>01599 
<a name="l01600"></a>01600   <span class="keywordflow">return</span> OK;
<a name="l01601"></a>01601 }
<a name="l01602"></a>01602 
<a name="l01603"></a>01603 
<a name="l01604"></a>01604 KMSetStatusCommand::KMSetStatusCommand( KMMsgStatus status,
<a name="l01605"></a>01605   <span class="keyword">const</span> QValueList&lt;Q_UINT32&gt; &amp;serNums, <span class="keywordtype">bool</span> toggle )
<a name="l01606"></a>01606   : mStatus( status ), mSerNums( serNums ), mToggle( toggle )
<a name="l01607"></a>01607 {
<a name="l01608"></a>01608 }
<a name="l01609"></a>01609 
<a name="l01610"></a>01610 KMCommand::Result KMSetStatusCommand::execute()
<a name="l01611"></a>01611 {
<a name="l01612"></a>01612   QValueListIterator&lt;Q_UINT32&gt; it;
<a name="l01613"></a>01613   <span class="keywordtype">int</span> idx = -1;
<a name="l01614"></a>01614   <a class="code" href="classKMFolder.html" title="Mail folder.">KMFolder</a> *folder = 0;
<a name="l01615"></a>01615   <span class="keywordtype">bool</span> parentStatus = <span class="keyword">false</span>;
<a name="l01616"></a>01616 
<a name="l01617"></a>01617   <span class="comment">// Toggle actions on threads toggle the whole thread</span>
<a name="l01618"></a>01618   <span class="comment">// depending on the state of the parent.</span>
<a name="l01619"></a>01619   <span class="keywordflow">if</span> (mToggle) {
<a name="l01620"></a>01620     KMMsgBase *msg;
<a name="l01621"></a>01621     <a class="code" href="classKMMsgDict.html#c39553f1139eff6c27e06082c625d067" title="Access the globally unique MessageDict.">KMMsgDict::instance</a>()-&gt;<a class="code" href="classKMMsgDict.html#c5d3159ddfbc5935322acd5602fb06ef" title="Returns the folder the message represented by the serial number key is in and the...">getLocation</a>( *mSerNums.begin(), &amp;folder, &amp;idx );
<a name="l01622"></a>01622     <span class="keywordflow">if</span> (folder) {
<a name="l01623"></a>01623       msg = folder-&gt;<a class="code" href="classKMFolder.html#4f7a5e120a3cd63293367cde74378a8a" title="Provides access to the basic message fields that are also stored in the index.">getMsgBase</a>(idx);
<a name="l01624"></a>01624       <span class="keywordflow">if</span> (msg &amp;&amp; (msg-&gt;status()&amp;mStatus))
<a name="l01625"></a>01625         parentStatus = <span class="keyword">true</span>;
<a name="l01626"></a>01626       <span class="keywordflow">else</span>
<a name="l01627"></a>01627         parentStatus = <span class="keyword">false</span>;
<a name="l01628"></a>01628     }
<a name="l01629"></a>01629   }
<a name="l01630"></a>01630   QMap&lt; KMFolder*, QValueList&lt;int&gt; &gt; folderMap;
<a name="l01631"></a>01631   <span class="keywordflow">for</span> ( it = mSerNums.begin(); it != mSerNums.end(); ++it ) {
<a name="l01632"></a>01632     <a class="code" href="classKMMsgDict.html#c39553f1139eff6c27e06082c625d067" title="Access the globally unique MessageDict.">KMMsgDict::instance</a>()-&gt;<a class="code" href="classKMMsgDict.html#c5d3159ddfbc5935322acd5602fb06ef" title="Returns the folder the message represented by the serial number key is in and the...">getLocation</a>( *it, &amp;folder, &amp;idx );
<a name="l01633"></a>01633     <span class="keywordflow">if</span> (folder) {
<a name="l01634"></a>01634       <span class="keywordflow">if</span> (mToggle) {
<a name="l01635"></a>01635         KMMsgBase *msg = folder-&gt;<a class="code" href="classKMFolder.html#4f7a5e120a3cd63293367cde74378a8a" title="Provides access to the basic message fields that are also stored in the index.">getMsgBase</a>(idx);
<a name="l01636"></a>01636         <span class="comment">// check if we are already at the target toggle state</span>
<a name="l01637"></a>01637         <span class="keywordflow">if</span> (msg) {
<a name="l01638"></a>01638           <span class="keywordtype">bool</span> myStatus;
<a name="l01639"></a>01639           <span class="keywordflow">if</span> (msg-&gt;status()&amp;mStatus)
<a name="l01640"></a>01640             myStatus = <span class="keyword">true</span>;
<a name="l01641"></a>01641           <span class="keywordflow">else</span>
<a name="l01642"></a>01642             myStatus = <span class="keyword">false</span>;
<a name="l01643"></a>01643           <span class="keywordflow">if</span> (myStatus != parentStatus)
<a name="l01644"></a>01644             <span class="keywordflow">continue</span>;
<a name="l01645"></a>01645         }
<a name="l01646"></a>01646       }
<a name="l01647"></a>01647       <span class="comment">/* Collect the ids for each folder in a separate list and</span>
<a name="l01648"></a>01648 <span class="comment">         send them off in one go at the end. */</span>
<a name="l01649"></a>01649       folderMap[folder].append(idx);
<a name="l01650"></a>01650     }
<a name="l01651"></a>01651   }
<a name="l01652"></a>01652   QMapIterator&lt; KMFolder*, QValueList&lt;int&gt; &gt; it2 = folderMap.begin();
<a name="l01653"></a>01653   <span class="keywordflow">while</span> ( it2 != folderMap.end() ) {
<a name="l01654"></a>01654      <a class="code" href="classKMFolder.html" title="Mail folder.">KMFolder</a> *f = it2.key();
<a name="l01655"></a>01655      f-&gt;<a class="code" href="classKMFolder.html#aa5fc6dd2181b3fc83431d10cc7b5462" title="Set the status of the message at index idx to status.">setStatus</a>( (*it2), mStatus, mToggle );
<a name="l01656"></a>01656      ++it2;
<a name="l01657"></a>01657   }
<a name="l01658"></a>01658   <span class="comment">//kapp-&gt;dcopClient()-&gt;emitDCOPSignal( "unreadCountChanged()", QByteArray() );</span>
<a name="l01659"></a>01659 
<a name="l01660"></a>01660   <span class="keywordflow">return</span> OK;
<a name="l01661"></a>01661 }
<a name="l01662"></a>01662 
<a name="l01663"></a>01663 
<a name="l01664"></a>01664 KMFilterCommand::KMFilterCommand( <span class="keyword">const</span> QCString &amp;field, <span class="keyword">const</span> QString &amp;value )
<a name="l01665"></a>01665   : mField( field ), mValue( value )
<a name="l01666"></a>01666 {
<a name="l01667"></a>01667 }
<a name="l01668"></a>01668 
<a name="l01669"></a>01669 KMCommand::Result KMFilterCommand::execute()
<a name="l01670"></a>01670 {
<a name="l01671"></a>01671   kmkernel-&gt;filterMgr()-&gt;createFilter( mField, mValue );
<a name="l01672"></a>01672 
<a name="l01673"></a>01673   <span class="keywordflow">return</span> OK;
<a name="l01674"></a>01674 }
<a name="l01675"></a>01675 
<a name="l01676"></a>01676 
<a name="l01677"></a>01677 KMFilterActionCommand::KMFilterActionCommand( QWidget *parent,
<a name="l01678"></a>01678                                               <span class="keyword">const</span> QPtrList&lt;KMMsgBase&gt; &amp;msgList,
<a name="l01679"></a>01679                                               KMFilter *filter )
<a name="l01680"></a>01680   : KMCommand( parent, msgList ), mFilter( filter  )
<a name="l01681"></a>01681 {
<a name="l01682"></a>01682   QPtrListIterator&lt;KMMsgBase&gt; it(msgList);
<a name="l01683"></a>01683   <span class="keywordflow">while</span> ( it.current() ) {
<a name="l01684"></a>01684     serNumList.append( (*it)-&gt;getMsgSerNum() );
<a name="l01685"></a>01685     ++it;
<a name="l01686"></a>01686   }
<a name="l01687"></a>01687 }
<a name="l01688"></a>01688 
<a name="l01689"></a>01689 KMCommand::Result KMFilterActionCommand::execute()
<a name="l01690"></a>01690 {
<a name="l01691"></a>01691   <a class="code" href="classKCursorSaver.html" title="sets a cursor and makes sure it&amp;#39;s restored on destruction Create a KCursorSaver...">KCursorSaver</a> busy( KBusyPtr::busy() );
<a name="l01692"></a>01692 
<a name="l01693"></a>01693   <span class="keywordtype">int</span> msgCount = 0;
<a name="l01694"></a>01694   <span class="keywordtype">int</span> msgCountToFilter = serNumList.count();
<a name="l01695"></a>01695   ProgressItem* progressItem =
<a name="l01696"></a>01696     ProgressManager::createProgressItem ( <span class="stringliteral">"filter"</span>+ProgressManager::getUniqueID(),
<a name="l01697"></a>01697                                           i18n( <span class="stringliteral">"Filtering messages"</span> ) );
<a name="l01698"></a>01698   progressItem-&gt;setTotalItems( msgCountToFilter );
<a name="l01699"></a>01699   QValueList&lt;Q_UINT32&gt;::const_iterator it;
<a name="l01700"></a>01700   <span class="keywordflow">for</span> ( it = serNumList.begin(); it != serNumList.end(); it++ ) {
<a name="l01701"></a>01701     Q_UINT32 serNum = *it;
<a name="l01702"></a>01702     <span class="keywordtype">int</span> diff = msgCountToFilter - ++msgCount;
<a name="l01703"></a>01703     <span class="keywordflow">if</span> ( diff &lt; 10 || !( msgCount % 20 ) || msgCount &lt;= 10 ) {
<a name="l01704"></a>01704       progressItem-&gt;updateProgress();
<a name="l01705"></a>01705       QString statusMsg = i18n(<span class="stringliteral">"Filtering message %1 of %2"</span>);
<a name="l01706"></a>01706       statusMsg = statusMsg.arg( msgCount ).arg( msgCountToFilter );
<a name="l01707"></a>01707       KPIM::BroadcastStatus::instance()-&gt;setStatusMsg( statusMsg );
<a name="l01708"></a>01708       KApplication::kApplication()-&gt;eventLoop()-&gt;processEvents( QEventLoop::ExcludeUserInput, 50 );
<a name="l01709"></a>01709     }
<a name="l01710"></a>01710 
<a name="l01711"></a>01711     <span class="keywordtype">int</span> filterResult = kmkernel-&gt;filterMgr()-&gt;process( serNum, mFilter );
<a name="l01712"></a>01712     <span class="keywordflow">if</span> (filterResult == 2) {
<a name="l01713"></a>01713       <span class="comment">// something went horribly wrong (out of space?)</span>
<a name="l01714"></a>01714       perror(<span class="stringliteral">"Critical error"</span>);
<a name="l01715"></a>01715       kmkernel-&gt;emergencyExit( i18n(<span class="stringliteral">"Not enough free disk space?"</span> ));
<a name="l01716"></a>01716     }
<a name="l01717"></a>01717     progressItem-&gt;incCompletedItems();
<a name="l01718"></a>01718   }
<a name="l01719"></a>01719 
<a name="l01720"></a>01720   progressItem-&gt;setComplete();
<a name="l01721"></a>01721   progressItem = 0;
<a name="l01722"></a>01722   <span class="keywordflow">return</span> OK;
<a name="l01723"></a>01723 }
<a name="l01724"></a>01724 
<a name="l01725"></a>01725 
<a name="l01726"></a>01726 KMMetaFilterActionCommand::KMMetaFilterActionCommand( KMFilter *filter,
<a name="l01727"></a>01727                                                       <a class="code" href="classKMHeaders.html" title="The widget that shows the contents of folders.">KMHeaders</a> *headers,
<a name="l01728"></a>01728                                                       KMMainWidget *main )
<a name="l01729"></a>01729     : QObject( main ),
<a name="l01730"></a>01730       mFilter( filter ), mHeaders( headers ), mMainWidget( main )
<a name="l01731"></a>01731 {
<a name="l01732"></a>01732 }
<a name="l01733"></a>01733 
<a name="l01734"></a>01734 <span class="keywordtype">void</span> KMMetaFilterActionCommand::start()
<a name="l01735"></a>01735 {
<a name="l01736"></a>01736   <span class="keywordflow">if</span> (ActionScheduler::isEnabled() ) {
<a name="l01737"></a>01737     <span class="comment">// use action scheduler</span>
<a name="l01738"></a>01738     KMFilterMgr::FilterSet <span class="keyword">set</span> = KMFilterMgr::All;
<a name="l01739"></a>01739     QValueList&lt;KMFilter*&gt; filters;
<a name="l01740"></a>01740     filters.append( mFilter );
<a name="l01741"></a>01741     ActionScheduler *scheduler = <span class="keyword">new</span> ActionScheduler( <span class="keyword">set</span>, filters, mHeaders );
<a name="l01742"></a>01742     scheduler-&gt;setAlwaysMatch( <span class="keyword">true</span> );
<a name="l01743"></a>01743     scheduler-&gt;setAutoDestruct( <span class="keyword">true</span> );
<a name="l01744"></a>01744 
<a name="l01745"></a>01745     <span class="keywordtype">int</span> contentX, contentY;
<a name="l01746"></a>01746     HeaderItem *nextItem = mHeaders-&gt;prepareMove( &amp;contentX, &amp;contentY );
<a name="l01747"></a>01747     QPtrList&lt;KMMsgBase&gt; msgList = *mHeaders-&gt;selectedMsgs(<span class="keyword">true</span>);
<a name="l01748"></a>01748     mHeaders-&gt;finalizeMove( nextItem, contentX, contentY );
<a name="l01749"></a>01749 
<a name="l01750"></a>01750     <span class="keywordflow">for</span> (KMMsgBase *msg = msgList.first(); msg; msg = msgList.next())
<a name="l01751"></a>01751       scheduler-&gt;execFilters( msg );
<a name="l01752"></a>01752   } <span class="keywordflow">else</span> {
<a name="l01753"></a>01753     KMCommand *filterCommand =
<a name="l01754"></a>01754       <span class="keyword">new</span> KMFilterActionCommand( mMainWidget,
<a name="l01755"></a>01755                                  *mHeaders-&gt;selectedMsgs(), mFilter );
<a name="l01756"></a>01756     filterCommand-&gt;start();
<a name="l01757"></a>01757     <span class="keywordtype">int</span> contentX, contentY;
<a name="l01758"></a>01758     HeaderItem *item = mHeaders-&gt;prepareMove( &amp;contentX, &amp;contentY );
<a name="l01759"></a>01759     mHeaders-&gt;finalizeMove( item, contentX, contentY );
<a name="l01760"></a>01760   }
<a name="l01761"></a>01761 }
<a name="l01762"></a>01762 
<a name="l01763"></a>01763 FolderShortcutCommand::FolderShortcutCommand( KMMainWidget *mainwidget,
<a name="l01764"></a>01764                                               <a class="code" href="classKMFolder.html" title="Mail folder.">KMFolder</a> *folder )
<a name="l01765"></a>01765     : mMainWidget( mainwidget ), mFolder( folder ), mAction( 0 )
<a name="l01766"></a>01766 {
<a name="l01767"></a>01767 }
<a name="l01768"></a>01768 
<a name="l01769"></a>01769 
<a name="l01770"></a>01770 FolderShortcutCommand::~FolderShortcutCommand()
<a name="l01771"></a>01771 {
<a name="l01772"></a>01772   <span class="keywordflow">if</span> ( mAction ) mAction-&gt;unplugAll();
<a name="l01773"></a>01773   <span class="keyword">delete</span> mAction;
<a name="l01774"></a>01774 }
<a name="l01775"></a>01775 
<a name="l01776"></a>01776 <span class="keywordtype">void</span> FolderShortcutCommand::start()
<a name="l01777"></a>01777 {
<a name="l01778"></a>01778   mMainWidget-&gt;slotSelectFolder( mFolder );
<a name="l01779"></a>01779 }
<a name="l01780"></a>01780 
<a name="l01781"></a>01781 <span class="keywordtype">void</span> FolderShortcutCommand::setAction( KAction* action )
<a name="l01782"></a>01782 {
<a name="l01783"></a>01783   mAction = action;
<a name="l01784"></a>01784 }
<a name="l01785"></a>01785 
<a name="l01786"></a>01786 KMMailingListFilterCommand::KMMailingListFilterCommand( QWidget *parent,
<a name="l01787"></a>01787                                                         <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> *msg )
<a name="l01788"></a>01788   : KMCommand( parent, msg )
<a name="l01789"></a>01789 {
<a name="l01790"></a>01790 }
<a name="l01791"></a>01791 
<a name="l01792"></a>01792 KMCommand::Result KMMailingListFilterCommand::execute()
<a name="l01793"></a>01793 {
<a name="l01794"></a>01794   QCString name;
<a name="l01795"></a>01795   QString value;
<a name="l01796"></a>01796   <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> *msg = retrievedMessage();
<a name="l01797"></a>01797   <span class="keywordflow">if</span> (!msg)
<a name="l01798"></a>01798     <span class="keywordflow">return</span> Failed;
<a name="l01799"></a>01799 
<a name="l01800"></a>01800   <span class="keywordflow">if</span> ( !MailingList::name( msg, name, value ).isEmpty() ) {
<a name="l01801"></a>01801     kmkernel-&gt;filterMgr()-&gt;createFilter( name, value );
<a name="l01802"></a>01802     <span class="keywordflow">return</span> OK;
<a name="l01803"></a>01803   }
<a name="l01804"></a>01804   <span class="keywordflow">else</span>
<a name="l01805"></a>01805     <span class="keywordflow">return</span> Failed;
<a name="l01806"></a>01806 }
<a name="l01807"></a>01807 
<a name="l01808"></a>01808 
<a name="l01809"></a>01809 <span class="keywordtype">void</span> KMMenuCommand::folderToPopupMenu(<span class="keywordtype">bool</span> move,
<a name="l01810"></a>01810   QObject *receiver, KMMenuToFolder *aMenuToFolder, QPopupMenu *menu )
<a name="l01811"></a>01811 {
<a name="l01812"></a>01812   <span class="keywordflow">while</span> ( menu-&gt;count() )
<a name="l01813"></a>01813   {
<a name="l01814"></a>01814     QPopupMenu *popup = menu-&gt;findItem( menu-&gt;idAt( 0 ) )-&gt;popup();
<a name="l01815"></a>01815     <span class="keywordflow">if</span> (popup)
<a name="l01816"></a>01816       <span class="keyword">delete</span> popup;
<a name="l01817"></a>01817     <span class="keywordflow">else</span>
<a name="l01818"></a>01818       menu-&gt;removeItemAt( 0 );
<a name="l01819"></a>01819   }
<a name="l01820"></a>01820 
<a name="l01821"></a>01821   <span class="keywordflow">if</span> (!kmkernel-&gt;imapFolderMgr()-&gt;dir().first() &amp;&amp;
<a name="l01822"></a>01822       !kmkernel-&gt;dimapFolderMgr()-&gt;dir().first())
<a name="l01823"></a>01823   { <span class="comment">// only local folders</span>
<a name="l01824"></a>01824     makeFolderMenu( &amp;kmkernel-&gt;folderMgr()-&gt;dir(), move,
<a name="l01825"></a>01825                     receiver, aMenuToFolder, menu );
<a name="l01826"></a>01826   } <span class="keywordflow">else</span> {
<a name="l01827"></a>01827     <span class="comment">// operate on top-level items</span>
<a name="l01828"></a>01828     QPopupMenu* subMenu = <span class="keyword">new</span> QPopupMenu(menu);
<a name="l01829"></a>01829     makeFolderMenu( &amp;kmkernel-&gt;folderMgr()-&gt;dir(),
<a name="l01830"></a>01830                     move, receiver, aMenuToFolder, subMenu );
<a name="l01831"></a>01831     menu-&gt;insertItem( i18n( <span class="stringliteral">"Local Folders"</span> ), subMenu );
<a name="l01832"></a>01832     <a class="code" href="classKMFolderDir.html" title="KMail list that manages the contents of one directory that may contain folders and/or...">KMFolderDir</a>* fdir = &amp;kmkernel-&gt;imapFolderMgr()-&gt;dir();
<a name="l01833"></a>01833     <span class="keywordflow">for</span> (KMFolderNode *node = fdir-&gt;first(); node; node = fdir-&gt;next()) {
<a name="l01834"></a>01834       <span class="keywordflow">if</span> (node-&gt;isDir())
<a name="l01835"></a>01835         <span class="keywordflow">continue</span>;
<a name="l01836"></a>01836       subMenu = <span class="keyword">new</span> QPopupMenu(menu);
<a name="l01837"></a>01837       makeFolderMenu( node, move, receiver, aMenuToFolder, subMenu );
<a name="l01838"></a>01838       menu-&gt;insertItem( node-&gt;label(), subMenu );
<a name="l01839"></a>01839     }
<a name="l01840"></a>01840     fdir = &amp;kmkernel-&gt;dimapFolderMgr()-&gt;dir();
<a name="l01841"></a>01841     <span class="keywordflow">for</span> (KMFolderNode *node = fdir-&gt;first(); node; node = fdir-&gt;next()) {
<a name="l01842"></a>01842       <span class="keywordflow">if</span> (node-&gt;isDir())
<a name="l01843"></a>01843         <span class="keywordflow">continue</span>;
<a name="l01844"></a>01844       subMenu = <span class="keyword">new</span> QPopupMenu(menu);
<a name="l01845"></a>01845       makeFolderMenu( node, move, receiver, aMenuToFolder, subMenu );
<a name="l01846"></a>01846       menu-&gt;insertItem( node-&gt;label(), subMenu );
<a name="l01847"></a>01847     }
<a name="l01848"></a>01848   }
<a name="l01849"></a>01849 }
<a name="l01850"></a>01850 
<a name="l01851"></a>01851 <span class="keywordtype">void</span> KMMenuCommand::makeFolderMenu(KMFolderNode* node, <span class="keywordtype">bool</span> move,
<a name="l01852"></a>01852   QObject *receiver, KMMenuToFolder *aMenuToFolder, QPopupMenu *menu )
<a name="l01853"></a>01853 {
<a name="l01854"></a>01854   <span class="comment">// connect the signals</span>
<a name="l01855"></a>01855   <span class="keywordflow">if</span> (move)
<a name="l01856"></a>01856   {
<a name="l01857"></a>01857     disconnect(menu, SIGNAL(activated(<span class="keywordtype">int</span>)), receiver,
<a name="l01858"></a>01858            SLOT(moveSelectedToFolder(<span class="keywordtype">int</span>)));
<a name="l01859"></a>01859     connect(menu, SIGNAL(activated(<span class="keywordtype">int</span>)), receiver,
<a name="l01860"></a>01860              SLOT(moveSelectedToFolder(<span class="keywordtype">int</span>)));
<a name="l01861"></a>01861   } <span class="keywordflow">else</span> {
<a name="l01862"></a>01862     disconnect(menu, SIGNAL(activated(<span class="keywordtype">int</span>)), receiver,
<a name="l01863"></a>01863            SLOT(copySelectedToFolder(<span class="keywordtype">int</span>)));
<a name="l01864"></a>01864     connect(menu, SIGNAL(activated(<span class="keywordtype">int</span>)), receiver,
<a name="l01865"></a>01865              SLOT(copySelectedToFolder(<span class="keywordtype">int</span>)));
<a name="l01866"></a>01866   }
<a name="l01867"></a>01867 
<a name="l01868"></a>01868   <a class="code" href="classKMFolder.html" title="Mail folder.">KMFolder</a> *folder = 0;
<a name="l01869"></a>01869   <a class="code" href="classKMFolderDir.html" title="KMail list that manages the contents of one directory that may contain folders and/or...">KMFolderDir</a> *folderDir = 0;
<a name="l01870"></a>01870   <span class="keywordflow">if</span> (node-&gt;isDir()) {
<a name="l01871"></a>01871     folderDir = <span class="keyword">static_cast&lt;</span><a class="code" href="classKMFolderDir.html" title="KMail list that manages the contents of one directory that may contain folders and/or...">KMFolderDir</a>*<span class="keyword">&gt;</span>(node);
<a name="l01872"></a>01872   } <span class="keywordflow">else</span> {
<a name="l01873"></a>01873     folder = <span class="keyword">static_cast&lt;</span><a class="code" href="classKMFolder.html" title="Mail folder.">KMFolder</a>*<span class="keyword">&gt;</span>(node);
<a name="l01874"></a>01874     folderDir = folder-&gt;<a class="code" href="classKMFolder.html#e64663017e257b091a827139446b5c06" title="Returns the folder directory associated with this node or 0 if no such directory...">child</a>();
<a name="l01875"></a>01875   }
<a name="l01876"></a>01876 
<a name="l01877"></a>01877   <span class="keywordflow">if</span> (folder &amp;&amp; !folder-&gt;<a class="code" href="classKMFolder.html#09686a96c5c426196119823afe49d03b" title="Returns, if the folder can&amp;#39;t contain mails, but only subfolder.">noContent</a>())
<a name="l01878"></a>01878   {
<a name="l01879"></a>01879     <span class="keywordtype">int</span> menuId;
<a name="l01880"></a>01880     <span class="keywordflow">if</span> (move)
<a name="l01881"></a>01881       menuId = menu-&gt;insertItem(i18n(<span class="stringliteral">"Move to This Folder"</span>));
<a name="l01882"></a>01882     <span class="keywordflow">else</span>
<a name="l01883"></a>01883       menuId = menu-&gt;insertItem(i18n(<span class="stringliteral">"Copy to This Folder"</span>));
<a name="l01884"></a>01884     aMenuToFolder-&gt;insert( menuId, folder );
<a name="l01885"></a>01885     menu-&gt;setItemEnabled( menuId, !folder-&gt;<a class="code" href="classKMFolder.html#6fc63ddd905b6d47f348400cb1a61b18" title="Is the folder read-only?">isReadOnly</a>() );
<a name="l01886"></a>01886     menu-&gt;insertSeparator();
<a name="l01887"></a>01887   }
<a name="l01888"></a>01888 
<a name="l01889"></a>01889   <span class="keywordflow">if</span> (!folderDir)
<a name="l01890"></a>01890     <span class="keywordflow">return</span>;
<a name="l01891"></a>01891 
<a name="l01892"></a>01892   <span class="keywordflow">for</span> (KMFolderNode *it = folderDir-&gt;first(); it; it = folderDir-&gt;next() ) {
<a name="l01893"></a>01893     <span class="keywordflow">if</span> (it-&gt;isDir())
<a name="l01894"></a>01894       <span class="keywordflow">continue</span>;
<a name="l01895"></a>01895     <a class="code" href="classKMFolder.html" title="Mail folder.">KMFolder</a> *child = <span class="keyword">static_cast&lt;</span><a class="code" href="classKMFolder.html" title="Mail folder.">KMFolder</a>*<span class="keyword">&gt;</span>(it);
<a name="l01896"></a>01896     QString label = child-&gt;<a class="code" href="classKMFolder.html#34f0beec33715f5a7fa6e1dfa11f6aa0" title="Returns the label of the folder for visualization.">label</a>();
<a name="l01897"></a>01897     label.replace(<span class="stringliteral">"&amp;"</span>,<span class="stringliteral">"&amp;&amp;"</span>);
<a name="l01898"></a>01898     <span class="keywordflow">if</span> (child-&gt;<a class="code" href="classKMFolder.html#e64663017e257b091a827139446b5c06" title="Returns the folder directory associated with this node or 0 if no such directory...">child</a>() &amp;&amp; child-&gt;<a class="code" href="classKMFolder.html#e64663017e257b091a827139446b5c06" title="Returns the folder directory associated with this node or 0 if no such directory...">child</a>()-&gt;first()) {
<a name="l01899"></a>01899       <span class="comment">// descend</span>
<a name="l01900"></a>01900       QPopupMenu *subMenu = <span class="keyword">new</span> QPopupMenu(menu, <span class="stringliteral">"subMenu"</span>);
<a name="l01901"></a>01901       makeFolderMenu( child, move, receiver,
<a name="l01902"></a>01902                       aMenuToFolder, subMenu );
<a name="l01903"></a>01903       menu-&gt;insertItem( label, subMenu );
<a name="l01904"></a>01904     } <span class="keywordflow">else</span> {
<a name="l01905"></a>01905       <span class="comment">// insert an item</span>
<a name="l01906"></a>01906       <span class="keywordtype">int</span> menuId = menu-&gt;insertItem( label );
<a name="l01907"></a>01907       aMenuToFolder-&gt;insert( menuId, child );
<a name="l01908"></a>01908       menu-&gt;setItemEnabled( menuId, !child-&gt;<a class="code" href="classKMFolder.html#6fc63ddd905b6d47f348400cb1a61b18" title="Is the folder read-only?">isReadOnly</a>() );
<a name="l01909"></a>01909     }
<a name="l01910"></a>01910   }
<a name="l01911"></a>01911   <span class="keywordflow">return</span>;
<a name="l01912"></a>01912 }
<a name="l01913"></a>01913 
<a name="l01914"></a>01914 
<a name="l01915"></a>01915 KMCopyCommand::KMCopyCommand( <a class="code" href="classKMFolder.html" title="Mail folder.">KMFolder</a>* destFolder,
<a name="l01916"></a>01916                               <span class="keyword">const</span> QPtrList&lt;KMMsgBase&gt; &amp;msgList )
<a name="l01917"></a>01917 :mDestFolder( destFolder ), mMsgList( msgList )
<a name="l01918"></a>01918 {
<a name="l01919"></a>01919   setDeletesItself( <span class="keyword">true</span> );
<a name="l01920"></a>01920 }
<a name="l01921"></a>01921 
<a name="l01922"></a>01922 KMCopyCommand::KMCopyCommand( <a class="code" href="classKMFolder.html" title="Mail folder.">KMFolder</a>* destFolder, <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> * msg )
<a name="l01923"></a>01923   :mDestFolder( destFolder )
<a name="l01924"></a>01924 {
<a name="l01925"></a>01925   setDeletesItself( <span class="keyword">true</span> );
<a name="l01926"></a>01926   mMsgList.append( &amp;msg-&gt;<a class="code" href="classKMMessage.html#d8a3687b6c8e690a6225b59fdf80eeb8" title="Get KMMsgBase for this object.">toMsgBase</a>() );
<a name="l01927"></a>01927 }
<a name="l01928"></a>01928 
<a name="l01929"></a>01929 KMCommand::Result KMCopyCommand::execute()
<a name="l01930"></a>01930 {
<a name="l01931"></a>01931   KMMsgBase *msgBase;
<a name="l01932"></a>01932   <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> *msg, *newMsg;
<a name="l01933"></a>01933   <span class="keywordtype">int</span> idx = -1;
<a name="l01934"></a>01934   <span class="keywordtype">bool</span> isMessage;
<a name="l01935"></a>01935   QPtrList&lt;KMMessage&gt; list;
<a name="l01936"></a>01936   QPtrList&lt;KMMessage&gt; localList;
<a name="l01937"></a>01937 
<a name="l01938"></a>01938   <span class="keywordflow">if</span> (mDestFolder &amp;&amp; mDestFolder-&gt;open(<span class="stringliteral">"kmcommand"</span>) != 0)
<a name="l01939"></a>01939   {
<a name="l01940"></a>01940     deleteLater();
<a name="l01941"></a>01941     <span class="keywordflow">return</span> Failed;
<a name="l01942"></a>01942   }
<a name="l01943"></a>01943 
<a name="l01944"></a>01944   setEmitsCompletedItself( <span class="keyword">true</span> );
<a name="l01945"></a>01945   <a class="code" href="classKCursorSaver.html" title="sets a cursor and makes sure it&amp;#39;s restored on destruction Create a KCursorSaver...">KCursorSaver</a> busy(KBusyPtr::busy());
<a name="l01946"></a>01946 
<a name="l01947"></a>01947   <span class="keywordflow">for</span> (msgBase = mMsgList.first(); msgBase; msgBase = mMsgList.next() )
<a name="l01948"></a>01948   {
<a name="l01949"></a>01949     <a class="code" href="classKMFolder.html" title="Mail folder.">KMFolder</a> *srcFolder = msgBase-&gt;parent();
<a name="l01950"></a>01950     <span class="keywordflow">if</span> (( isMessage = msgBase-&gt;isMessage() ))
<a name="l01951"></a>01951     {
<a name="l01952"></a>01952       msg = <span class="keyword">static_cast&lt;</span><a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a>*<span class="keyword">&gt;</span>(msgBase);
<a name="l01953"></a>01953     } <span class="keywordflow">else</span> {
<a name="l01954"></a>01954       idx = srcFolder-&gt;<a class="code" href="classKMFolder.html#27adedd629ece306415faf3cf5fbc617" title="Returns the index of the given message or -1 if not found.">find</a>(msgBase);
<a name="l01955"></a>01955       assert(idx != -1);
<a name="l01956"></a>01956       msg = srcFolder-&gt;<a class="code" href="classKMFolder.html#a0fdfeeed6e8e20eff1cd6445309b2f4" title="Read message at given index.">getMsg</a>(idx);
<a name="l01957"></a>01957       <span class="comment">// corrupt IMAP cache, see FolderStorage::getMsg()</span>
<a name="l01958"></a>01958       <span class="keywordflow">if</span> ( msg == 0 ) {
<a name="l01959"></a>01959         KMessageBox::error( parentWidget(), i18n(<span class="stringliteral">"Corrupt IMAP cache detected in folder %1. "</span>
<a name="l01960"></a>01960             <span class="stringliteral">"Copying of messages aborted."</span>).arg( srcFolder-&gt;<a class="code" href="classKMFolder.html#978272752c47b2a2c0ebef7b3203419d" title="URL of the node for visualization purposes.">prettyURL</a>() ) );
<a name="l01961"></a>01961         deleteLater();
<a name="l01962"></a>01962         <span class="keywordflow">return</span> Failed;
<a name="l01963"></a>01963       }
<a name="l01964"></a>01964     }
<a name="l01965"></a>01965 
<a name="l01966"></a>01966     <span class="keywordflow">if</span> (srcFolder &amp;&amp; mDestFolder &amp;&amp;
<a name="l01967"></a>01967         (srcFolder-&gt;<a class="code" href="classKMFolder.html#f95cbfeb07323847c6fe68d43c5a9276" title="Returns the type of this folder.">folderType</a>()== KMFolderTypeImap) &amp;&amp;
<a name="l01968"></a>01968         (mDestFolder-&gt;folderType() == KMFolderTypeImap) &amp;&amp;
<a name="l01969"></a>01969         (static_cast&lt;KMFolderImap*&gt;(srcFolder-&gt;<a class="code" href="classKMFolder.html#4c7476219c137471fb93cb8c88061336">storage</a>())-&gt;account() ==
<a name="l01970"></a>01970          <span class="keyword">static_cast&lt;</span>KMFolderImap*<span class="keyword">&gt;</span>(mDestFolder-&gt;storage())-&gt;account()))
<a name="l01971"></a>01971     {
<a name="l01972"></a>01972       <span class="comment">// imap =&gt; imap with same account</span>
<a name="l01973"></a>01973       list.append(msg);
<a name="l01974"></a>01974     } <span class="keywordflow">else</span> {
<a name="l01975"></a>01975       newMsg = <span class="keyword">new</span> <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a>( <span class="keyword">new</span> DwMessage( *msg-&gt;<a class="code" href="classKMMessage.html#dc5c9ceacb31f0149307e693de6fed65">asDwMessage</a>() ) );
<a name="l01976"></a>01976       newMsg-&gt;<a class="code" href="classKMMessage.html#abd4c5528d72e909766b5aff2bb4ac68" title="Set if the message is a complete message.">setComplete</a>(msg-&gt;<a class="code" href="classKMMessage.html#03cc096943ae864dd06ad23b05122777" title="Return true if the complete message is available without referring to the backing...">isComplete</a>());
<a name="l01977"></a>01977       <span class="comment">// make sure the attachment state is only calculated when it's complete</span>
<a name="l01978"></a>01978       <span class="keywordflow">if</span> (!newMsg-&gt;<a class="code" href="classKMMessage.html#03cc096943ae864dd06ad23b05122777" title="Return true if the complete message is available without referring to the backing...">isComplete</a>())
<a name="l01979"></a>01979         newMsg-&gt;<a class="code" href="classKMMessage.html#2312a56537b9b6ceefa0c2b4b17c387f" title="Set if the message is ready to be shown.">setReadyToShow</a>(<span class="keyword">false</span>);
<a name="l01980"></a>01980       newMsg-&gt;<a class="code" href="classKMMessage.html#508dba38dc91893691edddaab30e274d" title="Set status and mark dirty.">setStatus</a>(msg-&gt;<a class="code" href="classKMMessage.html#c54ef69572e620a3dcc0301aefca913e" title="Status of the message.">status</a>());
<a name="l01981"></a>01981 
<a name="l01982"></a>01982       <span class="keywordflow">if</span> (srcFolder &amp;&amp; !newMsg-&gt;<a class="code" href="classKMMessage.html#03cc096943ae864dd06ad23b05122777" title="Return true if the complete message is available without referring to the backing...">isComplete</a>())
<a name="l01983"></a>01983       {
<a name="l01984"></a>01984         <span class="comment">// imap =&gt; others</span>
<a name="l01985"></a>01985         newMsg-&gt;setParent(msg-&gt;parent());
<a name="l01986"></a>01986         FolderJob *job = srcFolder-&gt;<a class="code" href="classKMFolder.html#b9db21189505d49d37d9f114e216d2f4" title="These methods create respective FolderJob (You should derive FolderJob for each derived...">createJob</a>(newMsg);
<a name="l01987"></a>01987         job-&gt;setCancellable( <span class="keyword">false</span> );
<a name="l01988"></a>01988         mPendingJobs &lt;&lt; job;
<a name="l01989"></a>01989         connect(job, SIGNAL(messageRetrieved(<a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a>*)),
<a name="l01990"></a>01990                 mDestFolder, SLOT(reallyAddCopyOfMsg(<a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a>*)));
<a name="l01991"></a>01991         connect( job, SIGNAL(result(KMail::FolderJob*)),
<a name="l01992"></a>01992                  <span class="keyword">this</span>, SLOT(slotJobFinished(KMail::FolderJob*)) );
<a name="l01993"></a>01993         job-&gt;start();
<a name="l01994"></a>01994       } <span class="keywordflow">else</span> {
<a name="l01995"></a>01995         <span class="comment">// local =&gt; others</span>
<a name="l01996"></a>01996         localList.append(newMsg);
<a name="l01997"></a>01997       }
<a name="l01998"></a>01998     }
<a name="l01999"></a>01999 
<a name="l02000"></a>02000     <span class="keywordflow">if</span> (srcFolder &amp;&amp; !isMessage &amp;&amp; list.isEmpty())
<a name="l02001"></a>02001     {
<a name="l02002"></a>02002       assert(idx != -1);
<a name="l02003"></a>02003       srcFolder-&gt;<a class="code" href="classKMFolder.html#55d936471c71f7d03f6e54d2f83a0b52" title="Replace KMMessage with KMMsgInfo and delete KMMessage.">unGetMsg</a>( idx );
<a name="l02004"></a>02004     }
<a name="l02005"></a>02005 
<a name="l02006"></a>02006   } <span class="comment">// end for</span>
<a name="l02007"></a>02007 
<a name="l02008"></a>02008   <span class="keywordtype">bool</span> deleteNow = <span class="keyword">false</span>;
<a name="l02009"></a>02009   <span class="keywordflow">if</span> (!localList.isEmpty())
<a name="l02010"></a>02010   {
<a name="l02011"></a>02011     QValueList&lt;int&gt; index;
<a name="l02012"></a>02012     mDestFolder-&gt;addMsg( localList, index );
<a name="l02013"></a>02013     <span class="keywordflow">for</span> ( QValueListIterator&lt;int&gt; it = index.begin(); it != index.end(); ++it ) {
<a name="l02014"></a>02014       mDestFolder-&gt;unGetMsg( *it );
<a name="l02015"></a>02015     }
<a name="l02016"></a>02016     <span class="keywordflow">if</span> ( mDestFolder-&gt;folderType() == KMFolderTypeImap ) {
<a name="l02017"></a>02017       <span class="keywordflow">if</span> ( mPendingJobs.isEmpty() ) {
<a name="l02018"></a>02018         <span class="comment">// wait for the end of the copy before closing the folder</span>
<a name="l02019"></a>02019         KMFolderImap *imapDestFolder = <span class="keyword">static_cast&lt;</span>KMFolderImap*<span class="keyword">&gt;</span>(mDestFolder-&gt;storage());
<a name="l02020"></a>02020         connect( imapDestFolder, SIGNAL( folderComplete( KMFolderImap*, <span class="keywordtype">bool</span> ) ),
<a name="l02021"></a>02021             <span class="keyword">this</span>, SLOT( slotFolderComplete( KMFolderImap*, <span class="keywordtype">bool</span> ) ) );
<a name="l02022"></a>02022       }
<a name="l02023"></a>02023     } <span class="keywordflow">else</span> {
<a name="l02024"></a>02024       deleteNow = list.isEmpty() &amp;&amp; mPendingJobs.isEmpty(); <span class="comment">// we're done if there are no other mails we need to fetch</span>
<a name="l02025"></a>02025     }
<a name="l02026"></a>02026   }
<a name="l02027"></a>02027 
<a name="l02028"></a>02028 <span class="comment">//TODO: Get rid of the other cases just use this one for all types of folder</span>
<a name="l02029"></a>02029 <span class="comment">//TODO: requires adding copyMsg and getFolder methods to KMFolder.h</span>
<a name="l02030"></a>02030   <span class="keywordflow">if</span> (!list.isEmpty())
<a name="l02031"></a>02031   {
<a name="l02032"></a>02032     <span class="comment">// copy the message(s); note: the list is empty afterwards!</span>
<a name="l02033"></a>02033     KMFolderImap *imapDestFolder = <span class="keyword">static_cast&lt;</span>KMFolderImap*<span class="keyword">&gt;</span>(mDestFolder-&gt;storage());
<a name="l02034"></a>02034     connect( imapDestFolder, SIGNAL( folderComplete( KMFolderImap*, <span class="keywordtype">bool</span> ) ),
<a name="l02035"></a>02035         <span class="keyword">this</span>, SLOT( slotFolderComplete( KMFolderImap*, <span class="keywordtype">bool</span> ) ) );
<a name="l02036"></a>02036     imapDestFolder-&gt;copyMsg(list);
<a name="l02037"></a>02037     imapDestFolder-&gt;getFolder();
<a name="l02038"></a>02038   }
<a name="l02039"></a>02039 
<a name="l02040"></a>02040   <span class="comment">// only close the folder and delete the job if we're done</span>
<a name="l02041"></a>02041   <span class="comment">// otherwise this is done in slotMsgAdded or slotFolderComplete</span>
<a name="l02042"></a>02042   <span class="keywordflow">if</span> ( deleteNow )
<a name="l02043"></a>02043   {
<a name="l02044"></a>02044     mDestFolder-&gt;close(<span class="stringliteral">"kmcommand"</span>);
<a name="l02045"></a>02045     setResult( OK );
<a name="l02046"></a>02046     emit completed( <span class="keyword">this</span> );
<a name="l02047"></a>02047     deleteLater();
<a name="l02048"></a>02048   }
<a name="l02049"></a>02049 
<a name="l02050"></a>02050   <span class="keywordflow">return</span> OK;
<a name="l02051"></a>02051 }
<a name="l02052"></a>02052 
<a name="l02053"></a>02053 <span class="keywordtype">void</span> KMCopyCommand::slotJobFinished(KMail::FolderJob * job)
<a name="l02054"></a>02054 {
<a name="l02055"></a>02055   mPendingJobs.remove( job );
<a name="l02056"></a>02056   <span class="keywordflow">if</span> ( job-&gt;error() ) {
<a name="l02057"></a>02057     kdDebug(5006) &lt;&lt; k_funcinfo &lt;&lt; <span class="stringliteral">"folder job failed: "</span> &lt;&lt; job-&gt;error() &lt;&lt; endl;
<a name="l02058"></a>02058     <span class="comment">// kill all pending jobs</span>
<a name="l02059"></a>02059     <span class="keywordflow">for</span> ( QValueList&lt;KMail::FolderJob*&gt;::Iterator it = mPendingJobs.begin(); it != mPendingJobs.end(); ++it ) {
<a name="l02060"></a>02060       disconnect( (*it), SIGNAL(result(KMail::FolderJob*)),
<a name="l02061"></a>02061                   <span class="keyword">this</span>, SLOT(slotJobFinished(KMail::FolderJob*)) );
<a name="l02062"></a>02062       (*it)-&gt;kill();
<a name="l02063"></a>02063     }
<a name="l02064"></a>02064     mPendingJobs.clear();
<a name="l02065"></a>02065     setResult( Failed );
<a name="l02066"></a>02066   }
<a name="l02067"></a>02067 
<a name="l02068"></a>02068   <span class="keywordflow">if</span> ( mPendingJobs.isEmpty() )
<a name="l02069"></a>02069   {
<a name="l02070"></a>02070     mDestFolder-&gt;close(<span class="stringliteral">"kmcommand"</span>);
<a name="l02071"></a>02071     emit completed( <span class="keyword">this</span> );
<a name="l02072"></a>02072     deleteLater();
<a name="l02073"></a>02073   }
<a name="l02074"></a>02074 }
<a name="l02075"></a>02075 
<a name="l02076"></a>02076 <span class="keywordtype">void</span> KMCopyCommand::slotFolderComplete( KMFolderImap*, <span class="keywordtype">bool</span> success )
<a name="l02077"></a>02077 {
<a name="l02078"></a>02078   kdDebug(5006) &lt;&lt; k_funcinfo &lt;&lt; success &lt;&lt; endl;
<a name="l02079"></a>02079   <span class="keywordflow">if</span> ( !success )
<a name="l02080"></a>02080     setResult( Failed );
<a name="l02081"></a>02081   mDestFolder-&gt;close( <span class="stringliteral">"kmcommand"</span> );
<a name="l02082"></a>02082   emit completed( <span class="keyword">this</span> );
<a name="l02083"></a>02083   deleteLater();
<a name="l02084"></a>02084 }
<a name="l02085"></a>02085 
<a name="l02086"></a>02086 
<a name="l02087"></a>02087 KMMoveCommand::KMMoveCommand( <a class="code" href="classKMFolder.html" title="Mail folder.">KMFolder</a>* destFolder,
<a name="l02088"></a>02088                               <span class="keyword">const</span> QPtrList&lt;KMMsgBase&gt; &amp;msgList)
<a name="l02089"></a>02089   : mDestFolder( destFolder ), mProgressItem( 0 )
<a name="l02090"></a>02090 {
<a name="l02091"></a>02091   QPtrList&lt;KMMsgBase&gt; tmp = msgList;
<a name="l02092"></a>02092   <span class="keywordflow">for</span> ( KMMsgBase *msgBase = tmp.first(); msgBase; msgBase = tmp.next() )
<a name="l02093"></a>02093     mSerNumList.append( msgBase-&gt;getMsgSerNum() );
<a name="l02094"></a>02094 }
<a name="l02095"></a>02095 
<a name="l02096"></a>02096 KMMoveCommand::KMMoveCommand( <a class="code" href="classKMFolder.html" title="Mail folder.">KMFolder</a>* destFolder,
<a name="l02097"></a>02097                               <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> *msg )
<a name="l02098"></a>02098   : mDestFolder( destFolder ), mProgressItem( 0 )
<a name="l02099"></a>02099 {
<a name="l02100"></a>02100   mSerNumList.append( msg-&gt;getMsgSerNum() );
<a name="l02101"></a>02101 }
<a name="l02102"></a>02102 
<a name="l02103"></a>02103 KMMoveCommand::KMMoveCommand( <a class="code" href="classKMFolder.html" title="Mail folder.">KMFolder</a>* destFolder,
<a name="l02104"></a>02104                               KMMsgBase *msgBase )
<a name="l02105"></a>02105   : mDestFolder( destFolder ), mProgressItem( 0 )
<a name="l02106"></a>02106 {
<a name="l02107"></a>02107   mSerNumList.append( msgBase-&gt;getMsgSerNum() );
<a name="l02108"></a>02108 }
<a name="l02109"></a>02109 
<a name="l02110"></a>02110 KMMoveCommand::KMMoveCommand( Q_UINT32 )
<a name="l02111"></a>02111   : mProgressItem( 0 )
<a name="l02112"></a>02112 {
<a name="l02113"></a>02113 }
<a name="l02114"></a>02114 
<a name="l02115"></a>02115 KMCommand::Result KMMoveCommand::execute()
<a name="l02116"></a>02116 {
<a name="l02117"></a>02117   setEmitsCompletedItself( <span class="keyword">true</span> );
<a name="l02118"></a>02118   setDeletesItself( <span class="keyword">true</span> );
<a name="l02119"></a>02119   <span class="keyword">typedef</span> QMap&lt; KMFolder*, QPtrList&lt;KMMessage&gt;* &gt; FolderToMessageListMap;
<a name="l02120"></a>02120   FolderToMessageListMap folderDeleteList;
<a name="l02121"></a>02121 
<a name="l02122"></a>02122   <span class="keywordflow">if</span> (mDestFolder &amp;&amp; mDestFolder-&gt;open(<span class="stringliteral">"kmcommand"</span>) != 0) {
<a name="l02123"></a>02123     completeMove( Failed );
<a name="l02124"></a>02124     <span class="keywordflow">return</span> Failed;
<a name="l02125"></a>02125   }
<a name="l02126"></a>02126   <a class="code" href="classKCursorSaver.html" title="sets a cursor and makes sure it&amp;#39;s restored on destruction Create a KCursorSaver...">KCursorSaver</a> busy(KBusyPtr::busy());
<a name="l02127"></a>02127 
<a name="l02128"></a>02128   <span class="comment">// TODO set SSL state according to source and destfolder connection?</span>
<a name="l02129"></a>02129   Q_ASSERT( !mProgressItem );
<a name="l02130"></a>02130   mProgressItem =
<a name="l02131"></a>02131      ProgressManager::createProgressItem (
<a name="l02132"></a>02132          <span class="stringliteral">"move"</span>+ProgressManager::getUniqueID(),
<a name="l02133"></a>02133          mDestFolder ? i18n( <span class="stringliteral">"Moving messages"</span> ) : i18n( <span class="stringliteral">"Deleting messages"</span> ) );
<a name="l02134"></a>02134   connect( mProgressItem, SIGNAL( progressItemCanceled( KPIM::ProgressItem* ) ),
<a name="l02135"></a>02135            <span class="keyword">this</span>, SLOT( slotMoveCanceled() ) );
<a name="l02136"></a>02136 
<a name="l02137"></a>02137   <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> *msg;
<a name="l02138"></a>02138   <span class="keywordtype">int</span> rc = 0;
<a name="l02139"></a>02139   <span class="keywordtype">int</span> index;
<a name="l02140"></a>02140   QPtrList&lt;KMMessage&gt; list;
<a name="l02141"></a>02141   <span class="keywordtype">int</span> undoId = -1;
<a name="l02142"></a>02142   mCompleteWithAddedMsg = <span class="keyword">false</span>;
<a name="l02143"></a>02143 
<a name="l02144"></a>02144   <span class="keywordflow">if</span> (mDestFolder) {
<a name="l02145"></a>02145     connect (mDestFolder, SIGNAL(msgAdded(<a class="code" href="classKMFolder.html" title="Mail folder.">KMFolder</a>*, Q_UINT32)),
<a name="l02146"></a>02146              <span class="keyword">this</span>, SLOT(slotMsgAddedToDestFolder(<a class="code" href="classKMFolder.html" title="Mail folder.">KMFolder</a>*, Q_UINT32)));
<a name="l02147"></a>02147     mLostBoys = mSerNumList;
<a name="l02148"></a>02148   }
<a name="l02149"></a>02149   mProgressItem-&gt;setTotalItems( mSerNumList.count() );
<a name="l02150"></a>02150 
<a name="l02151"></a>02151   <span class="keywordflow">for</span> ( QValueList&lt;Q_UINT32&gt;::ConstIterator it = mSerNumList.constBegin(); it != mSerNumList.constEnd(); ++it ) {
<a name="l02152"></a>02152     <a class="code" href="classKMFolder.html" title="Mail folder.">KMFolder</a> *srcFolder;
<a name="l02153"></a>02153     <span class="keywordtype">int</span> idx = -1;
<a name="l02154"></a>02154     <a class="code" href="classKMMsgDict.html#c39553f1139eff6c27e06082c625d067" title="Access the globally unique MessageDict.">KMMsgDict::instance</a>()-&gt;<a class="code" href="classKMMsgDict.html#c5d3159ddfbc5935322acd5602fb06ef" title="Returns the folder the message represented by the serial number key is in and the...">getLocation</a>( *it, &amp;srcFolder, &amp;idx );
<a name="l02155"></a>02155     <span class="keywordflow">if</span> (srcFolder == mDestFolder)
<a name="l02156"></a>02156       <span class="keywordflow">continue</span>;
<a name="l02157"></a>02157     assert(idx != -1);
<a name="l02158"></a>02158     srcFolder-&gt;<a class="code" href="classKMFolder.html#c12a4bb5f265447d87b3e0e9a9482cc6" title="Open folder for access.">open</a>( <span class="stringliteral">"kmmovecommand"</span> );
<a name="l02159"></a>02159     mOpenedFolders.append( srcFolder );
<a name="l02160"></a>02160     msg = srcFolder-&gt;<a class="code" href="classKMFolder.html#a0fdfeeed6e8e20eff1cd6445309b2f4" title="Read message at given index.">getMsg</a>(idx);
<a name="l02161"></a>02161     <span class="keywordflow">if</span> ( !msg ) {
<a name="l02162"></a>02162       kdDebug(5006) &lt;&lt; k_funcinfo &lt;&lt; <span class="stringliteral">"No message found for serial number "</span> &lt;&lt; *it &lt;&lt; endl;
<a name="l02163"></a>02163       <span class="keywordflow">continue</span>;
<a name="l02164"></a>02164     }
<a name="l02165"></a>02165     <span class="keywordtype">bool</span> undo = msg-&gt;enableUndo();
<a name="l02166"></a>02166 
<a name="l02167"></a>02167     <span class="keywordflow">if</span> ( msg &amp;&amp; msg-&gt;<a class="code" href="classKMMessage.html#e1adf17b8b22a8343ed60da3c12ecdb7" title="Return, if the message should not be deleted.">transferInProgress</a>() &amp;&amp;
<a name="l02168"></a>02168          srcFolder-&gt;<a class="code" href="classKMFolder.html#f95cbfeb07323847c6fe68d43c5a9276" title="Returns the type of this folder.">folderType</a>() == KMFolderTypeImap )
<a name="l02169"></a>02169     {
<a name="l02170"></a>02170       <span class="comment">// cancel the download</span>
<a name="l02171"></a>02171       msg-&gt;<a class="code" href="classKMMessage.html#32cc9d6f53648fd997efcc4f9d043197" title="Set that the message shall not be deleted because it is still required.">setTransferInProgress</a>( <span class="keyword">false</span>, <span class="keyword">true</span> );
<a name="l02172"></a>02172       <span class="keyword">static_cast&lt;</span>KMFolderImap*<span class="keyword">&gt;</span>(srcFolder-&gt;<a class="code" href="classKMFolder.html#4c7476219c137471fb93cb8c88061336">storage</a>())-&gt;ignoreJobsForMessage( msg );
<a name="l02173"></a>02173     }
<a name="l02174"></a>02174 
<a name="l02175"></a>02175     <span class="keywordflow">if</span> (mDestFolder) {
<a name="l02176"></a>02176       <span class="keywordflow">if</span> (mDestFolder-&gt;folderType() == KMFolderTypeImap) {
<a name="l02177"></a>02177         <span class="comment">/* If we are moving to an imap folder, connect to it's completed</span>
<a name="l02178"></a>02178 <span class="comment">         * signal so we notice when all the mails should have showed up in it</span>
<a name="l02179"></a>02179 <span class="comment">         * but haven't for some reason. */</span>
<a name="l02180"></a>02180         KMFolderImap *imapFolder = <span class="keyword">static_cast&lt;</span>KMFolderImap*<span class="keyword">&gt;</span> ( mDestFolder-&gt;storage() );
<a name="l02181"></a>02181         disconnect (imapFolder, SIGNAL(folderComplete( KMFolderImap*, <span class="keywordtype">bool</span> )),
<a name="l02182"></a>02182                  <span class="keyword">this</span>, SLOT(slotImapFolderCompleted( KMFolderImap*, <span class="keywordtype">bool</span> )));
<a name="l02183"></a>02183 
<a name="l02184"></a>02184         connect (imapFolder, SIGNAL(folderComplete( KMFolderImap*, <span class="keywordtype">bool</span> )),
<a name="l02185"></a>02185                  <span class="keyword">this</span>, SLOT(slotImapFolderCompleted( KMFolderImap*, <span class="keywordtype">bool</span> )));
<a name="l02186"></a>02186         list.append(msg);
<a name="l02187"></a>02187       } <span class="keywordflow">else</span> {
<a name="l02188"></a>02188         <span class="comment">// We are moving to a local folder.</span>
<a name="l02189"></a>02189         <span class="keywordflow">if</span> ( srcFolder-&gt;<a class="code" href="classKMFolder.html#f95cbfeb07323847c6fe68d43c5a9276" title="Returns the type of this folder.">folderType</a>() == KMFolderTypeImap )
<a name="l02190"></a>02190         {
<a name="l02191"></a>02191           <span class="comment">// do not complete here but wait until all messages are transferred</span>
<a name="l02192"></a>02192           mCompleteWithAddedMsg = <span class="keyword">true</span>;
<a name="l02193"></a>02193         }
<a name="l02194"></a>02194         rc = mDestFolder-&gt;moveMsg(msg, &amp;index);
<a name="l02195"></a>02195         <span class="keywordflow">if</span> (rc == 0 &amp;&amp; index != -1) {
<a name="l02196"></a>02196           KMMsgBase *mb = mDestFolder-&gt;unGetMsg( mDestFolder-&gt;count() - 1 );
<a name="l02197"></a>02197           <span class="keywordflow">if</span> (undo &amp;&amp; mb)
<a name="l02198"></a>02198           {
<a name="l02199"></a>02199             <span class="keywordflow">if</span> ( undoId == -1 )
<a name="l02200"></a>02200               undoId = kmkernel-&gt;undoStack()-&gt;newUndoAction( srcFolder, mDestFolder );
<a name="l02201"></a>02201             kmkernel-&gt;undoStack()-&gt;addMsgToAction( undoId, mb-&gt;getMsgSerNum() );
<a name="l02202"></a>02202           }
<a name="l02203"></a>02203         } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (rc != 0) {
<a name="l02204"></a>02204           <span class="comment">// Something  went wrong. Stop processing here, it is likely that the</span>
<a name="l02205"></a>02205           <span class="comment">// other moves would fail as well.</span>
<a name="l02206"></a>02206           completeMove( Failed );
<a name="l02207"></a>02207           <span class="keywordflow">return</span> Failed;
<a name="l02208"></a>02208         }
<a name="l02209"></a>02209       }
<a name="l02210"></a>02210     } <span class="keywordflow">else</span> {
<a name="l02211"></a>02211       <span class="comment">// really delete messages that are already in the trash folder or if</span>
<a name="l02212"></a>02212       <span class="comment">// we are really, really deleting, not just moving to trash</span>
<a name="l02213"></a>02213       <span class="keywordflow">if</span> (srcFolder-&gt;<a class="code" href="classKMFolder.html#f95cbfeb07323847c6fe68d43c5a9276" title="Returns the type of this folder.">folderType</a>() == KMFolderTypeImap) {
<a name="l02214"></a>02214         <span class="keywordflow">if</span> (!folderDeleteList[srcFolder])
<a name="l02215"></a>02215           folderDeleteList[srcFolder] = <span class="keyword">new</span> QPtrList&lt;KMMessage&gt;;
<a name="l02216"></a>02216         folderDeleteList[srcFolder]-&gt;append( msg );
<a name="l02217"></a>02217       } <span class="keywordflow">else</span> {
<a name="l02218"></a>02218         srcFolder-&gt;removeMsg(idx);
<a name="l02219"></a>02219         <span class="keyword">delete</span> msg;
<a name="l02220"></a>02220       }
<a name="l02221"></a>02221     }
<a name="l02222"></a>02222   }
<a name="l02223"></a>02223   <span class="keywordflow">if</span> (!list.isEmpty() &amp;&amp; mDestFolder) {
<a name="l02224"></a>02224     <span class="comment">// will be completed with folderComplete signal</span>
<a name="l02225"></a>02225     mDestFolder-&gt;moveMsg(list, &amp;index);
<a name="l02226"></a>02226   } <span class="keywordflow">else</span> {
<a name="l02227"></a>02227     FolderToMessageListMap::Iterator it;
<a name="l02228"></a>02228     <span class="keywordflow">for</span> ( it = folderDeleteList.begin(); it != folderDeleteList.end(); ++it ) {
<a name="l02229"></a>02229       it.key()-&gt;removeMsg(*it.data());
<a name="l02230"></a>02230       <span class="keyword">delete</span> it.data();
<a name="l02231"></a>02231     }
<a name="l02232"></a>02232     <span class="keywordflow">if</span> ( !mCompleteWithAddedMsg ) {
<a name="l02233"></a>02233       <span class="comment">// imap folders will be completed in slotMsgAddedToDestFolder</span>
<a name="l02234"></a>02234       completeMove( OK );
<a name="l02235"></a>02235     }
<a name="l02236"></a>02236   }
<a name="l02237"></a>02237 
<a name="l02238"></a>02238   <span class="keywordflow">return</span> OK;
<a name="l02239"></a>02239 }
<a name="l02240"></a>02240 
<a name="l02241"></a>02241 <span class="keywordtype">void</span> KMMoveCommand::slotImapFolderCompleted(KMFolderImap* imapFolder, <span class="keywordtype">bool</span> success)
<a name="l02242"></a>02242 {
<a name="l02243"></a>02243   disconnect (imapFolder, SIGNAL(folderComplete( KMFolderImap*, <span class="keywordtype">bool</span> )),
<a name="l02244"></a>02244       <span class="keyword">this</span>, SLOT(slotImapFolderCompleted( KMFolderImap*, <span class="keywordtype">bool</span> )));
<a name="l02245"></a>02245   <span class="keywordflow">if</span> ( success ) {
<a name="l02246"></a>02246     <span class="comment">// the folder was checked successfully but we were still called, so check</span>
<a name="l02247"></a>02247     <span class="comment">// if we are still waiting for messages to show up. If so, uidValidity</span>
<a name="l02248"></a>02248     <span class="comment">// changed, or something else went wrong. Clean up.</span>
<a name="l02249"></a>02249 
<a name="l02250"></a>02250     <span class="comment">/* Unfortunately older UW imap servers change uid validity for each put job.</span>
<a name="l02251"></a>02251 <span class="comment">     * Yes, it is really that broken. *sigh* So we cannot report error here, I guess. */</span>
<a name="l02252"></a>02252     <span class="keywordflow">if</span> ( !mLostBoys.isEmpty() ) {
<a name="l02253"></a>02253       kdDebug(5006) &lt;&lt;  <span class="stringliteral">"### Not all moved messages reported back that they were "</span> &lt;&lt; endl
<a name="l02254"></a>02254                     &lt;&lt;  <span class="stringliteral">"### added to the target folder. Did uidValidity change? "</span> &lt;&lt; endl;
<a name="l02255"></a>02255     }
<a name="l02256"></a>02256     completeMove( OK );
<a name="l02257"></a>02257   } <span class="keywordflow">else</span> {
<a name="l02258"></a>02258     <span class="comment">// Should we inform the user here or leave that to the caller?</span>
<a name="l02259"></a>02259     completeMove( Failed );
<a name="l02260"></a>02260   }
<a name="l02261"></a>02261 }
<a name="l02262"></a>02262 
<a name="l02263"></a>02263 <span class="keywordtype">void</span> KMMoveCommand::slotMsgAddedToDestFolder(<a class="code" href="classKMFolder.html" title="Mail folder.">KMFolder</a> *folder, Q_UINT32 serNum)
<a name="l02264"></a>02264 {
<a name="l02265"></a>02265   <span class="keywordflow">if</span> ( folder != mDestFolder || mLostBoys.<a class="code" href="classKMFolder.html#27adedd629ece306415faf3cf5fbc617" title="Returns the index of the given message or -1 if not found.">find</a>( serNum ) == mLostBoys.end() ) {
<a name="l02266"></a>02266     <span class="comment">//kdDebug(5006) &lt;&lt; "KMMoveCommand::msgAddedToDestFolder different "</span>
<a name="l02267"></a>02267     <span class="comment">//                 "folder or invalid serial number." &lt;&lt; endl;</span>
<a name="l02268"></a>02268     <span class="keywordflow">return</span>;
<a name="l02269"></a>02269   }
<a name="l02270"></a>02270   mLostBoys.remove(serNum);
<a name="l02271"></a>02271   <span class="keywordflow">if</span> ( mLostBoys.isEmpty() ) {
<a name="l02272"></a>02272     <span class="comment">// we are done. All messages transferred to the host succesfully</span>
<a name="l02273"></a>02273     disconnect (mDestFolder, SIGNAL(msgAdded(<a class="code" href="classKMFolder.html" title="Mail folder.">KMFolder</a>*, Q_UINT32)),
<a name="l02274"></a>02274              <span class="keyword">this</span>, SLOT(slotMsgAddedToDestFolder(<a class="code" href="classKMFolder.html" title="Mail folder.">KMFolder</a>*, Q_UINT32)));
<a name="l02275"></a>02275     <span class="keywordflow">if</span> (mDestFolder &amp;&amp; mDestFolder-&gt;folderType() != KMFolderTypeImap) {
<a name="l02276"></a>02276       mDestFolder-&gt;sync();
<a name="l02277"></a>02277     }
<a name="l02278"></a>02278     <span class="keywordflow">if</span> ( mCompleteWithAddedMsg ) {
<a name="l02279"></a>02279       completeMove( OK );
<a name="l02280"></a>02280     }
<a name="l02281"></a>02281   } <span class="keywordflow">else</span> {
<a name="l02282"></a>02282     <span class="keywordflow">if</span> ( mProgressItem ) {
<a name="l02283"></a>02283       mProgressItem-&gt;incCompletedItems();
<a name="l02284"></a>02284       mProgressItem-&gt;updateProgress();
<a name="l02285"></a>02285     }
<a name="l02286"></a>02286   }
<a name="l02287"></a>02287 }
<a name="l02288"></a>02288 
<a name="l02289"></a>02289 <span class="keywordtype">void</span> KMMoveCommand::completeMove( Result result )
<a name="l02290"></a>02290 {
<a name="l02291"></a>02291   <span class="keywordflow">if</span> ( mDestFolder )
<a name="l02292"></a>02292     mDestFolder-&gt;close(<span class="stringliteral">"kmcommand"</span>);
<a name="l02293"></a>02293   <span class="keywordflow">while</span> ( !mOpenedFolders.empty() ) {
<a name="l02294"></a>02294     <a class="code" href="classKMFolder.html" title="Mail folder.">KMFolder</a> *folder = mOpenedFolders.back();
<a name="l02295"></a>02295     mOpenedFolders.pop_back();
<a name="l02296"></a>02296     folder-&gt;<a class="code" href="classKMFolder.html#8d167662bca3ad6315fa5ad67bb9e4dd" title="Close folder.">close</a>(<span class="stringliteral">"kmcommand"</span>);
<a name="l02297"></a>02297   }
<a name="l02298"></a>02298   <span class="keywordflow">if</span> ( mProgressItem ) {
<a name="l02299"></a>02299     mProgressItem-&gt;setComplete();
<a name="l02300"></a>02300     mProgressItem = 0;
<a name="l02301"></a>02301   }
<a name="l02302"></a>02302   setResult( result );
<a name="l02303"></a>02303   emit completed( <span class="keyword">this</span> );
<a name="l02304"></a>02304   deleteLater();
<a name="l02305"></a>02305 }
<a name="l02306"></a>02306 
<a name="l02307"></a>02307 <span class="keywordtype">void</span> KMMoveCommand::slotMoveCanceled()
<a name="l02308"></a>02308 {
<a name="l02309"></a>02309   completeMove( Canceled );
<a name="l02310"></a>02310 }
<a name="l02311"></a>02311 
<a name="l02312"></a>02312 <span class="comment">// srcFolder doesn't make much sense for searchFolders</span>
<a name="l02313"></a>02313 KMDeleteMsgCommand::KMDeleteMsgCommand( <a class="code" href="classKMFolder.html" title="Mail folder.">KMFolder</a>* srcFolder,
<a name="l02314"></a>02314   <span class="keyword">const</span> QPtrList&lt;KMMsgBase&gt; &amp;msgList )
<a name="l02315"></a>02315 :KMMoveCommand( findTrashFolder( srcFolder ), msgList)
<a name="l02316"></a>02316 {
<a name="l02317"></a>02317   srcFolder-&gt;<a class="code" href="classKMFolder.html#c12a4bb5f265447d87b3e0e9a9482cc6" title="Open folder for access.">open</a>(<span class="stringliteral">"kmcommand"</span>);
<a name="l02318"></a>02318   mOpenedFolders.push_back( srcFolder );
<a name="l02319"></a>02319 }
<a name="l02320"></a>02320 
<a name="l02321"></a>02321 KMDeleteMsgCommand::KMDeleteMsgCommand( <a class="code" href="classKMFolder.html" title="Mail folder.">KMFolder</a>* srcFolder, <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> * msg )
<a name="l02322"></a>02322 :KMMoveCommand( findTrashFolder( srcFolder ), msg)
<a name="l02323"></a>02323 {
<a name="l02324"></a>02324   srcFolder-&gt;<a class="code" href="classKMFolder.html#c12a4bb5f265447d87b3e0e9a9482cc6" title="Open folder for access.">open</a>(<span class="stringliteral">"kmcommand"</span>);
<a name="l02325"></a>02325   mOpenedFolders.push_back( srcFolder );
<a name="l02326"></a>02326 }
<a name="l02327"></a>02327 
<a name="l02328"></a>02328 KMDeleteMsgCommand::KMDeleteMsgCommand( Q_UINT32 sernum )
<a name="l02329"></a>02329 :KMMoveCommand( sernum )
<a name="l02330"></a>02330 {
<a name="l02331"></a>02331   <a class="code" href="classKMFolder.html" title="Mail folder.">KMFolder</a> *srcFolder = 0;
<a name="l02332"></a>02332   <span class="keywordtype">int</span> idx;
<a name="l02333"></a>02333   <a class="code" href="classKMMsgDict.html#c39553f1139eff6c27e06082c625d067" title="Access the globally unique MessageDict.">KMMsgDict::instance</a>()-&gt;<a class="code" href="classKMMsgDict.html#c5d3159ddfbc5935322acd5602fb06ef" title="Returns the folder the message represented by the serial number key is in and the...">getLocation</a>( sernum, &amp;srcFolder, &amp;idx );
<a name="l02334"></a>02334   <span class="keywordflow">if</span> ( srcFolder ) {
<a name="l02335"></a>02335     KMMsgBase *msg = srcFolder-&gt;<a class="code" href="classKMFolder.html#4f7a5e120a3cd63293367cde74378a8a" title="Provides access to the basic message fields that are also stored in the index.">getMsgBase</a>( idx );
<a name="l02336"></a>02336     srcFolder-&gt;<a class="code" href="classKMFolder.html#c12a4bb5f265447d87b3e0e9a9482cc6" title="Open folder for access.">open</a>(<span class="stringliteral">"kmcommand"</span>);
<a name="l02337"></a>02337     mOpenedFolders.push_back( srcFolder );
<a name="l02338"></a>02338     addMsg( msg );
<a name="l02339"></a>02339   }
<a name="l02340"></a>02340   setDestFolder( findTrashFolder( srcFolder ) );
<a name="l02341"></a>02341 }
<a name="l02342"></a>02342 
<a name="l02343"></a>02343 <a class="code" href="classKMFolder.html" title="Mail folder.">KMFolder</a> * KMDeleteMsgCommand::findTrashFolder( <a class="code" href="classKMFolder.html" title="Mail folder.">KMFolder</a> * folder )
<a name="l02344"></a>02344 {
<a name="l02345"></a>02345   <a class="code" href="classKMFolder.html" title="Mail folder.">KMFolder</a>* trash = folder-&gt;<a class="code" href="classKMFolder.html#646e29234f52caebd1d119e4ca959c20" title="If this folder has a special trash folder set, return it.">trashFolder</a>();
<a name="l02346"></a>02346   <span class="keywordflow">if</span>( !trash )
<a name="l02347"></a>02347     trash = kmkernel-&gt;trashFolder();
<a name="l02348"></a>02348   <span class="keywordflow">if</span>( trash != folder )
<a name="l02349"></a>02349     <span class="keywordflow">return</span> trash;
<a name="l02350"></a>02350   <span class="keywordflow">return</span> 0;
<a name="l02351"></a>02351 }
<a name="l02352"></a>02352 
<a name="l02353"></a>02353 
<a name="l02354"></a>02354 KMUrlClickedCommand::KMUrlClickedCommand( <span class="keyword">const</span> KURL &amp;url, uint identity,
<a name="l02355"></a>02355   <a class="code" href="classKMReaderWin.html" title="This class implements a &amp;quot;reader window&amp;quot;, that is a window used for reading...">KMReaderWin</a> *readerWin, <span class="keywordtype">bool</span> htmlPref, KMMainWidget *mainWidget )
<a name="l02356"></a>02356   :mUrl( url ), mIdentity( identity ), mReaderWin( readerWin ),
<a name="l02357"></a>02357    mHtmlPref( htmlPref ), mMainWidget( mainWidget )
<a name="l02358"></a>02358 {
<a name="l02359"></a>02359 }
<a name="l02360"></a>02360 
<a name="l02361"></a>02361 KMCommand::Result KMUrlClickedCommand::execute()
<a name="l02362"></a>02362 {
<a name="l02363"></a>02363   <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a>* msg;
<a name="l02364"></a>02364 
<a name="l02365"></a>02365   <span class="keywordflow">if</span> (mUrl.protocol() == <span class="stringliteral">"mailto"</span>)
<a name="l02366"></a>02366   {
<a name="l02367"></a>02367     msg = <span class="keyword">new</span> <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a>;
<a name="l02368"></a>02368     msg-&gt;<a class="code" href="classKMMessage.html#f3fe6794874214ffa4ad07a3992590e7" title="Initialize header fields.">initHeader</a>(mIdentity);
<a name="l02369"></a>02369     msg-&gt;<a class="code" href="classKMMessage.html#6c6413b3690538964ac810f4c6755a5b" title="Set the message charset.">setCharset</a>(<span class="stringliteral">"utf-8"</span>);
<a name="l02370"></a>02370     msg-&gt;<a class="code" href="classKMMessage.html#5bb40f8b006d66c80cff9a43fa3018d6">setTo</a>( <a class="code" href="classKMMessage.html#e8dca5f50d21a63908d4026e2683ac60" title="Decodes a mailto URL.">KMMessage::decodeMailtoUrl</a>( mUrl.path() ) );
<a name="l02371"></a>02371     QString query=mUrl.query();
<a name="l02372"></a>02372     <span class="keywordflow">while</span> (!query.isEmpty()) {
<a name="l02373"></a>02373       QString queryPart;
<a name="l02374"></a>02374       <span class="keywordtype">int</span> secondQuery = query.find(<span class="charliteral">'?'</span>,1);
<a name="l02375"></a>02375       <span class="keywordflow">if</span> (secondQuery != -1)
<a name="l02376"></a>02376         queryPart = query.left(secondQuery);
<a name="l02377"></a>02377       <span class="keywordflow">else</span>
<a name="l02378"></a>02378         queryPart = query;
<a name="l02379"></a>02379       query = query.mid(queryPart.length());
<a name="l02380"></a>02380 
<a name="l02381"></a>02381       <span class="keywordflow">if</span> (queryPart.left(9) == <span class="stringliteral">"?subject="</span>)
<a name="l02382"></a>02382         msg-&gt;<a class="code" href="classKMMessage.html#dc02d16017d248f9f7c9dc980aee25b4">setSubject</a>( KURL::decode_string(queryPart.mid(9)) );
<a name="l02383"></a>02383       <span class="keywordflow">else</span> <span class="keywordflow">if</span> (queryPart.left(6) == <span class="stringliteral">"?body="</span>)
<a name="l02384"></a>02384         <span class="comment">// It is correct to convert to latin1() as URL should not contain</span>
<a name="l02385"></a>02385         <span class="comment">// anything except ascii.</span>
<a name="l02386"></a>02386         msg-&gt;<a class="code" href="classKMMessage.html#1b9c4db08086c94986f00d0c708a01e7" title="Set the message body.">setBody</a>( KURL::decode_string(queryPart.mid(6)).latin1() );
<a name="l02387"></a>02387       <span class="keywordflow">else</span> <span class="keywordflow">if</span> (queryPart.left(4) == <span class="stringliteral">"?cc="</span>)
<a name="l02388"></a>02388         msg-&gt;<a class="code" href="classKMMessage.html#3bf036f0a5f466a614154a749fb4ac54">setCc</a>( KURL::decode_string(queryPart.mid(4)) );
<a name="l02389"></a>02389     }
<a name="l02390"></a>02390 
<a name="l02391"></a>02391     KMail::Composer * win = KMail::makeComposer( msg, mIdentity );
<a name="l02392"></a>02392     win-&gt;setCharset(<span class="stringliteral">""</span>, <span class="keyword">true</span>);
<a name="l02393"></a>02393     win-&gt;show();
<a name="l02394"></a>02394   }
<a name="l02395"></a>02395   <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( mUrl.protocol() == <span class="stringliteral">"im"</span> )
<a name="l02396"></a>02396   {
<a name="l02397"></a>02397     kmkernel-&gt;imProxy()-&gt;chatWithContact( mUrl.path() );
<a name="l02398"></a>02398   }
<a name="l02399"></a>02399   <span class="keywordflow">else</span> <span class="keywordflow">if</span> ((mUrl.protocol() == <span class="stringliteral">"http"</span>) || (mUrl.protocol() == <span class="stringliteral">"https"</span>) ||
<a name="l02400"></a>02400            (mUrl.protocol() == <span class="stringliteral">"ftp"</span>)  || (mUrl.protocol() == <span class="stringliteral">"file"</span>)  ||
<a name="l02401"></a>02401            (mUrl.protocol() == <span class="stringliteral">"ftps"</span>) || (mUrl.protocol() == <span class="stringliteral">"sftp"</span> ) ||
<a name="l02402"></a>02402            (mUrl.protocol() == <span class="stringliteral">"help"</span>) || (mUrl.protocol() == <span class="stringliteral">"vnc"</span>)   ||
<a name="l02403"></a>02403            (mUrl.protocol() == <span class="stringliteral">"smb"</span>)  || (mUrl.protocol() == <span class="stringliteral">"fish"</span>)  ||
<a name="l02404"></a>02404            (mUrl.protocol() == <span class="stringliteral">"news"</span>))
<a name="l02405"></a>02405   {
<a name="l02406"></a>02406     KPIM::BroadcastStatus::instance()-&gt;setStatusMsg( i18n(<span class="stringliteral">"Opening URL..."</span>));
<a name="l02407"></a>02407     KMimeType::Ptr mime = KMimeType::findByURL( mUrl );
<a name="l02408"></a>02408     <span class="keywordflow">if</span> (mime-&gt;name() == <span class="stringliteral">"application/x-desktop"</span> ||
<a name="l02409"></a>02409         mime-&gt;name() == <span class="stringliteral">"application/x-executable"</span> ||
<a name="l02410"></a>02410         mime-&gt;name() == <span class="stringliteral">"application/x-msdos-program"</span> ||
<a name="l02411"></a>02411         mime-&gt;name() == <span class="stringliteral">"application/x-shellscript"</span> )
<a name="l02412"></a>02412     {
<a name="l02413"></a>02413       <span class="keywordflow">if</span> (KMessageBox::warningYesNo( 0, i18n( <span class="stringliteral">"&lt;qt&gt;Do you really want to execute &lt;b&gt;%1&lt;/b&gt;?&lt;/qt&gt;"</span> )
<a name="l02414"></a>02414         .arg( mUrl.prettyURL() ), QString::null, i18n(<span class="stringliteral">"Execute"</span>), KStdGuiItem::cancel() ) != KMessageBox::Yes)
<a name="l02415"></a>02415         <span class="keywordflow">return</span> Canceled;
<a name="l02416"></a>02416     }
<a name="l02417"></a>02417     (void) <span class="keyword">new</span> KRun( mUrl );
<a name="l02418"></a>02418   }
<a name="l02419"></a>02419   <span class="keywordflow">else</span>
<a name="l02420"></a>02420     <span class="keywordflow">return</span> Failed;
<a name="l02421"></a>02421 
<a name="l02422"></a>02422   <span class="keywordflow">return</span> OK;
<a name="l02423"></a>02423 }
<a name="l02424"></a>02424 
<a name="l02425"></a>02425 KMSaveAttachmentsCommand::KMSaveAttachmentsCommand( QWidget *parent, <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> *msg )
<a name="l02426"></a>02426   : KMCommand( parent, msg ), mImplicitAttachments( true ), mEncoded( false )
<a name="l02427"></a>02427 {
<a name="l02428"></a>02428 }
<a name="l02429"></a>02429 
<a name="l02430"></a>02430 KMSaveAttachmentsCommand::KMSaveAttachmentsCommand( QWidget *parent, <span class="keyword">const</span> QPtrList&lt;KMMsgBase&gt;&amp; msgs )
<a name="l02431"></a>02431   : KMCommand( parent, msgs ), mImplicitAttachments( true ), mEncoded( false )
<a name="l02432"></a>02432 {
<a name="l02433"></a>02433 }
<a name="l02434"></a>02434 
<a name="l02435"></a>02435 KMSaveAttachmentsCommand::KMSaveAttachmentsCommand( QWidget *parent, QPtrList&lt;partNode&gt;&amp; attachments,
<a name="l02436"></a>02436                                                     <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> *msg, <span class="keywordtype">bool</span> encoded )
<a name="l02437"></a>02437   : KMCommand( parent ), mImplicitAttachments( false ), mEncoded( encoded )
<a name="l02438"></a>02438 {
<a name="l02439"></a>02439   <span class="keywordflow">for</span> ( QPtrListIterator&lt;partNode&gt; it( attachments ); it.current(); ++it ) {
<a name="l02440"></a>02440     mAttachmentMap.insert( it.current(), msg );
<a name="l02441"></a>02441   }
<a name="l02442"></a>02442 }
<a name="l02443"></a>02443 
<a name="l02444"></a>02444 KMCommand::Result KMSaveAttachmentsCommand::execute()
<a name="l02445"></a>02445 {
<a name="l02446"></a>02446   setEmitsCompletedItself( <span class="keyword">true</span> );
<a name="l02447"></a>02447   <span class="keywordflow">if</span> ( mImplicitAttachments ) {
<a name="l02448"></a>02448     QPtrList&lt;KMMessage&gt; msgList = retrievedMsgs();
<a name="l02449"></a>02449     <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> *msg;
<a name="l02450"></a>02450     <span class="keywordflow">for</span> ( QPtrListIterator&lt;KMMessage&gt; itr( msgList );
<a name="l02451"></a>02451           ( msg = itr.current() );
<a name="l02452"></a>02452           ++itr ) {
<a name="l02453"></a>02453       partNode *rootNode = partNode::fromMessage( msg );
<a name="l02454"></a>02454       <span class="keywordflow">for</span> ( partNode *child = rootNode; child;
<a name="l02455"></a>02455             child = child-&gt;firstChild() ) {
<a name="l02456"></a>02456         <span class="keywordflow">for</span> ( partNode *node = child; node; node = node-&gt;nextSibling() ) {
<a name="l02457"></a>02457           <span class="keywordflow">if</span> ( node-&gt;type() != DwMime::kTypeMultipart )
<a name="l02458"></a>02458             mAttachmentMap.insert( node, msg );
<a name="l02459"></a>02459         }
<a name="l02460"></a>02460       }
<a name="l02461"></a>02461     }
<a name="l02462"></a>02462   }
<a name="l02463"></a>02463   setDeletesItself( <span class="keyword">true</span> );
<a name="l02464"></a>02464   <span class="comment">// load all parts</span>
<a name="l02465"></a>02465   KMLoadPartsCommand *command = <span class="keyword">new</span> KMLoadPartsCommand( mAttachmentMap );
<a name="l02466"></a>02466   connect( command, SIGNAL( partsRetrieved() ),
<a name="l02467"></a>02467            <span class="keyword">this</span>, SLOT( slotSaveAll() ) );
<a name="l02468"></a>02468   command-&gt;start();
<a name="l02469"></a>02469 
<a name="l02470"></a>02470   <span class="keywordflow">return</span> OK;
<a name="l02471"></a>02471 }
<a name="l02472"></a>02472 
<a name="l02473"></a>02473 <span class="keywordtype">void</span> KMSaveAttachmentsCommand::slotSaveAll()
<a name="l02474"></a>02474 {
<a name="l02475"></a>02475   <span class="comment">// now that all message parts have been retrieved, remove all parts which</span>
<a name="l02476"></a>02476   <span class="comment">// don't represent an attachment if they were not explicitely passed in the</span>
<a name="l02477"></a>02477   <span class="comment">// c'tor</span>
<a name="l02478"></a>02478   <span class="keywordflow">if</span> ( mImplicitAttachments ) {
<a name="l02479"></a>02479     <span class="keywordflow">for</span> ( PartNodeMessageMap::iterator it = mAttachmentMap.begin();
<a name="l02480"></a>02480           it != mAttachmentMap.end(); ) {
<a name="l02481"></a>02481       <span class="comment">// only body parts which have a filename or a name parameter (except for</span>
<a name="l02482"></a>02482       <span class="comment">// the root node for which name is set to the message's subject) are</span>
<a name="l02483"></a>02483       <span class="comment">// considered attachments</span>
<a name="l02484"></a>02484       <span class="keywordflow">if</span> ( it.key()-&gt;msgPart().fileName().stripWhiteSpace().isEmpty() &amp;&amp;
<a name="l02485"></a>02485            ( it.key()-&gt;msgPart().name().stripWhiteSpace().isEmpty() ||
<a name="l02486"></a>02486              !it.key()-&gt;parentNode() ) ) {
<a name="l02487"></a>02487         PartNodeMessageMap::iterator delIt = it;
<a name="l02488"></a>02488         ++it;
<a name="l02489"></a>02489         mAttachmentMap.remove( delIt );
<a name="l02490"></a>02490       }
<a name="l02491"></a>02491       <span class="keywordflow">else</span>
<a name="l02492"></a>02492         ++it;
<a name="l02493"></a>02493     }
<a name="l02494"></a>02494     <span class="keywordflow">if</span> ( mAttachmentMap.isEmpty() ) {
<a name="l02495"></a>02495       KMessageBox::information( 0, i18n(<span class="stringliteral">"Found no attachments to save."</span>) );
<a name="l02496"></a>02496       setResult( OK ); <span class="comment">// The user has already been informed.</span>
<a name="l02497"></a>02497       emit completed( <span class="keyword">this</span> );
<a name="l02498"></a>02498       deleteLater();
<a name="l02499"></a>02499       <span class="keywordflow">return</span>;
<a name="l02500"></a>02500     }
<a name="l02501"></a>02501   }
<a name="l02502"></a>02502 
<a name="l02503"></a>02503   KURL url, dirUrl;
<a name="l02504"></a>02504   <span class="keywordflow">if</span> ( mAttachmentMap.count() &gt; 1 ) {
<a name="l02505"></a>02505     <span class="comment">// get the dir</span>
<a name="l02506"></a>02506     dirUrl = KDirSelectDialog::selectDirectory( QString::null, <span class="keyword">false</span>,
<a name="l02507"></a>02507                                                 parentWidget(),
<a name="l02508"></a>02508                                                 i18n(<span class="stringliteral">"Save Attachments To"</span>) );
<a name="l02509"></a>02509     <span class="keywordflow">if</span> ( !dirUrl.isValid() ) {
<a name="l02510"></a>02510       setResult( Canceled );
<a name="l02511"></a>02511       emit completed( <span class="keyword">this</span> );
<a name="l02512"></a>02512       deleteLater();
<a name="l02513"></a>02513       <span class="keywordflow">return</span>;
<a name="l02514"></a>02514     }
<a name="l02515"></a>02515 
<a name="l02516"></a>02516     <span class="comment">// we may not get a slash-terminated url out of KDirSelectDialog</span>
<a name="l02517"></a>02517     dirUrl.adjustPath( 1 );
<a name="l02518"></a>02518   }
<a name="l02519"></a>02519   <span class="keywordflow">else</span> {
<a name="l02520"></a>02520     <span class="comment">// only one item, get the desired filename</span>
<a name="l02521"></a>02521     partNode *node = mAttachmentMap.begin().key();
<a name="l02522"></a>02522     <span class="comment">// replace all ':' with '_' because ':' isn't allowed on FAT volumes</span>
<a name="l02523"></a>02523     QString s =
<a name="l02524"></a>02524       node-&gt;msgPart().fileName().stripWhiteSpace().replace( <span class="charliteral">':'</span>, <span class="charliteral">'_'</span> );
<a name="l02525"></a>02525     <span class="keywordflow">if</span> ( s.isEmpty() )
<a name="l02526"></a>02526       s = node-&gt;msgPart().name().stripWhiteSpace().replace( <span class="charliteral">':'</span>, <span class="charliteral">'_'</span> );
<a name="l02527"></a>02527     <span class="keywordflow">if</span> ( s.isEmpty() )
<a name="l02528"></a>02528       s = i18n(<span class="stringliteral">"filename for an unnamed attachment"</span>, <span class="stringliteral">"attachment.1"</span>);
<a name="l02529"></a>02529     url = KFileDialog::getSaveURL( s, QString::null, parentWidget(),
<a name="l02530"></a>02530                                    QString::null );
<a name="l02531"></a>02531     <span class="keywordflow">if</span> ( url.isEmpty() ) {
<a name="l02532"></a>02532       setResult( Canceled );
<a name="l02533"></a>02533       emit completed( <span class="keyword">this</span> );
<a name="l02534"></a>02534       deleteLater();
<a name="l02535"></a>02535       <span class="keywordflow">return</span>;
<a name="l02536"></a>02536     }
<a name="l02537"></a>02537   }
<a name="l02538"></a>02538 
<a name="l02539"></a>02539   QMap&lt; QString, int &gt; renameNumbering;
<a name="l02540"></a>02540 
<a name="l02541"></a>02541   Result globalResult = OK;
<a name="l02542"></a>02542   <span class="keywordtype">int</span> unnamedAtmCount = 0;
<a name="l02543"></a>02543   <span class="keywordflow">for</span> ( PartNodeMessageMap::const_iterator it = mAttachmentMap.begin();
<a name="l02544"></a>02544         it != mAttachmentMap.end();
<a name="l02545"></a>02545         ++it ) {
<a name="l02546"></a>02546     KURL curUrl;
<a name="l02547"></a>02547     <span class="keywordflow">if</span> ( !dirUrl.isEmpty() ) {
<a name="l02548"></a>02548       curUrl = dirUrl;
<a name="l02549"></a>02549       QString s =
<a name="l02550"></a>02550         it.key()-&gt;msgPart().fileName().stripWhiteSpace().replace( <span class="charliteral">':'</span>, <span class="charliteral">'_'</span> );
<a name="l02551"></a>02551       <span class="keywordflow">if</span> ( s.isEmpty() )
<a name="l02552"></a>02552         s = it.key()-&gt;msgPart().name().stripWhiteSpace().replace( <span class="charliteral">':'</span>, <span class="charliteral">'_'</span> );
<a name="l02553"></a>02553       <span class="keywordflow">if</span> ( s.isEmpty() ) {
<a name="l02554"></a>02554         ++unnamedAtmCount;
<a name="l02555"></a>02555         s = i18n(<span class="stringliteral">"filename for the %1-th unnamed attachment"</span>,
<a name="l02556"></a>02556                  <span class="stringliteral">"attachment.%1"</span>)
<a name="l02557"></a>02557             .arg( unnamedAtmCount );
<a name="l02558"></a>02558       }
<a name="l02559"></a>02559       curUrl.setFileName( s );
<a name="l02560"></a>02560     } <span class="keywordflow">else</span> {
<a name="l02561"></a>02561       curUrl = url;
<a name="l02562"></a>02562     }
<a name="l02563"></a>02563 
<a name="l02564"></a>02564     <span class="keywordflow">if</span> ( !curUrl.isEmpty() ) {
<a name="l02565"></a>02565 
<a name="l02566"></a>02566      <span class="comment">// Rename the file if we have already saved one with the same name:</span>
<a name="l02567"></a>02567      <span class="comment">// try appending a number before extension (e.g. "pic.jpg" =&gt; "pic_2.jpg")</span>
<a name="l02568"></a>02568      QString origFile = curUrl.fileName();
<a name="l02569"></a>02569      QString file = origFile;
<a name="l02570"></a>02570 
<a name="l02571"></a>02571      <span class="keywordflow">while</span> ( renameNumbering.contains(file) ) {
<a name="l02572"></a>02572        file = origFile;
<a name="l02573"></a>02573        <span class="keywordtype">int</span> num = renameNumbering[file] + 1;
<a name="l02574"></a>02574        <span class="keywordtype">int</span> dotIdx = file.findRev(<span class="charliteral">'.'</span>);
<a name="l02575"></a>02575        file = file.insert( (dotIdx&gt;=0) ? dotIdx : file.length(), QString(<span class="stringliteral">"_"</span>) + QString::number(num) );
<a name="l02576"></a>02576      }
<a name="l02577"></a>02577      curUrl.setFileName(file);
<a name="l02578"></a>02578 
<a name="l02579"></a>02579      <span class="comment">// Increment the counter for both the old and the new filename</span>
<a name="l02580"></a>02580      <span class="keywordflow">if</span> ( !renameNumbering.contains(origFile))
<a name="l02581"></a>02581          renameNumbering[origFile] = 1;
<a name="l02582"></a>02582      <span class="keywordflow">else</span>
<a name="l02583"></a>02583          renameNumbering[origFile]++;
<a name="l02584"></a>02584 
<a name="l02585"></a>02585      <span class="keywordflow">if</span> ( file != origFile ) {
<a name="l02586"></a>02586         <span class="keywordflow">if</span> ( !renameNumbering.contains(file))
<a name="l02587"></a>02587             renameNumbering[file] = 1;
<a name="l02588"></a>02588         <span class="keywordflow">else</span>
<a name="l02589"></a>02589             renameNumbering[file]++;
<a name="l02590"></a>02590      }
<a name="l02591"></a>02591 
<a name="l02592"></a>02592 
<a name="l02593"></a>02593       <span class="keywordflow">if</span> ( KIO::NetAccess::exists( curUrl, <span class="keyword">false</span>, parentWidget() ) ) {
<a name="l02594"></a>02594         <span class="keywordflow">if</span> ( KMessageBox::warningContinueCancel( parentWidget(),
<a name="l02595"></a>02595               i18n( <span class="stringliteral">"A file named %1 already exists. Do you want to overwrite it?"</span> )
<a name="l02596"></a>02596               .arg( curUrl.fileName() ),
<a name="l02597"></a>02597               i18n( <span class="stringliteral">"File Already Exists"</span> ), i18n(<span class="stringliteral">"&amp;Overwrite"</span>) ) == KMessageBox::Cancel) {
<a name="l02598"></a>02598           <span class="keywordflow">continue</span>;
<a name="l02599"></a>02599         }
<a name="l02600"></a>02600       }
<a name="l02601"></a>02601       <span class="comment">// save</span>
<a name="l02602"></a>02602       <span class="keyword">const</span> Result result = saveItem( it.key(), curUrl );
<a name="l02603"></a>02603       <span class="keywordflow">if</span> ( result != OK )
<a name="l02604"></a>02604         globalResult = result;
<a name="l02605"></a>02605     }
<a name="l02606"></a>02606   }
<a name="l02607"></a>02607   setResult( globalResult );
<a name="l02608"></a>02608   emit completed( <span class="keyword">this</span> );
<a name="l02609"></a>02609   deleteLater();
<a name="l02610"></a>02610 }
<a name="l02611"></a>02611 
<a name="l02612"></a>02612 KMCommand::Result KMSaveAttachmentsCommand::saveItem( partNode *node,
<a name="l02613"></a>02613                                                       <span class="keyword">const</span> KURL&amp; url )
<a name="l02614"></a>02614 {
<a name="l02615"></a>02615   <span class="keywordtype">bool</span> bSaveEncrypted = <span class="keyword">false</span>;
<a name="l02616"></a>02616   <span class="keywordtype">bool</span> bEncryptedParts = node-&gt;encryptionState() != KMMsgNotEncrypted;
<a name="l02617"></a>02617   <span class="keywordflow">if</span>( bEncryptedParts )
<a name="l02618"></a>02618     <span class="keywordflow">if</span>( KMessageBox::questionYesNo( parentWidget(),
<a name="l02619"></a>02619           i18n( <span class="stringliteral">"The part %1 of the message is encrypted. Do you want to keep the encryption when saving?"</span> ).
<a name="l02620"></a>02620           arg( url.fileName() ),
<a name="l02621"></a>02621           i18n( <span class="stringliteral">"KMail Question"</span> ), i18n(<span class="stringliteral">"Keep Encryption"</span>), i18n(<span class="stringliteral">"Do Not Keep"</span>) ) ==
<a name="l02622"></a>02622         KMessageBox::Yes )
<a name="l02623"></a>02623       bSaveEncrypted = <span class="keyword">true</span>;
<a name="l02624"></a>02624 
<a name="l02625"></a>02625   <span class="keywordtype">bool</span> bSaveWithSig = <span class="keyword">true</span>;
<a name="l02626"></a>02626   <span class="keywordflow">if</span>( node-&gt;signatureState() != KMMsgNotSigned )
<a name="l02627"></a>02627     <span class="keywordflow">if</span>( KMessageBox::questionYesNo( parentWidget(),
<a name="l02628"></a>02628           i18n( <span class="stringliteral">"The part %1 of the message is signed. Do you want to keep the signature when saving?"</span> ).
<a name="l02629"></a>02629           arg( url.fileName() ),
<a name="l02630"></a>02630           i18n( <span class="stringliteral">"KMail Question"</span> ), i18n(<span class="stringliteral">"Keep Signature"</span>), i18n(<span class="stringliteral">"Do Not Keep"</span>) ) !=
<a name="l02631"></a>02631         KMessageBox::Yes )
<a name="l02632"></a>02632       bSaveWithSig = <span class="keyword">false</span>;
<a name="l02633"></a>02633 
<a name="l02634"></a>02634   QByteArray data;
<a name="l02635"></a>02635   <span class="keywordflow">if</span> ( mEncoded )
<a name="l02636"></a>02636   {
<a name="l02637"></a>02637     <span class="comment">// This does not decode the Message Content-Transfer-Encoding</span>
<a name="l02638"></a>02638     <span class="comment">// but saves the _original_ content of the message part</span>
<a name="l02639"></a>02639     data = <a class="code" href="namespaceKMail_1_1Util.html#62cdb963731a7eeaeca528f2e2651844" title="Construct a QByteArray from a DwString.">KMail::Util::ByteArray</a>( node-&gt;msgPart().dwBody() );
<a name="l02640"></a>02640   }
<a name="l02641"></a>02641   <span class="keywordflow">else</span>
<a name="l02642"></a>02642   {
<a name="l02643"></a>02643     <span class="keywordflow">if</span>( bSaveEncrypted || !bEncryptedParts) {
<a name="l02644"></a>02644       partNode *dataNode = node;
<a name="l02645"></a>02645       QCString rawReplyString;
<a name="l02646"></a>02646       <span class="keywordtype">bool</span> gotRawReplyString = <span class="keyword">false</span>;
<a name="l02647"></a>02647       <span class="keywordflow">if</span>( !bSaveWithSig ) {
<a name="l02648"></a>02648         <span class="keywordflow">if</span>( DwMime::kTypeMultipart == node-&gt;type() &amp;&amp;
<a name="l02649"></a>02649             DwMime::kSubtypeSigned == node-&gt;subType() ){
<a name="l02650"></a>02650           <span class="comment">// carefully look for the part that is *not* the signature part:</span>
<a name="l02651"></a>02651           <span class="keywordflow">if</span>( node-&gt;findType( DwMime::kTypeApplication,
<a name="l02652"></a>02652                 DwMime::kSubtypePgpSignature,
<a name="l02653"></a>02653                 <span class="keyword">true</span>, <span class="keyword">false</span> ) ){
<a name="l02654"></a>02654             dataNode = node-&gt;findTypeNot( DwMime::kTypeApplication,
<a name="l02655"></a>02655                 DwMime::kSubtypePgpSignature,
<a name="l02656"></a>02656                 <span class="keyword">true</span>, <span class="keyword">false</span> );
<a name="l02657"></a>02657           }<span class="keywordflow">else</span> <span class="keywordflow">if</span>( node-&gt;findType( DwMime::kTypeApplication,
<a name="l02658"></a>02658                 DwMime::kSubtypePkcs7Mime,
<a name="l02659"></a>02659                 <span class="keyword">true</span>, <span class="keyword">false</span> ) ){
<a name="l02660"></a>02660             dataNode = node-&gt;findTypeNot( DwMime::kTypeApplication,
<a name="l02661"></a>02661                 DwMime::kSubtypePkcs7Mime,
<a name="l02662"></a>02662                 <span class="keyword">true</span>, <span class="keyword">false</span> );
<a name="l02663"></a>02663           }<span class="keywordflow">else</span>{
<a name="l02664"></a>02664             dataNode = node-&gt;findTypeNot( DwMime::kTypeMultipart,
<a name="l02665"></a>02665                 DwMime::kSubtypeUnknown,
<a name="l02666"></a>02666                 <span class="keyword">true</span>, <span class="keyword">false</span> );
<a name="l02667"></a>02667           }
<a name="l02668"></a>02668     }<span class="keywordflow">else</span>{
<a name="l02669"></a>02669       ObjectTreeParser otp( 0, 0, <span class="keyword">false</span>, <span class="keyword">false</span>, <span class="keyword">false</span> );
<a name="l02670"></a>02670 
<a name="l02671"></a>02671       <span class="comment">// process this node and all it's siblings and descendants</span>
<a name="l02672"></a>02672       dataNode-&gt;setProcessed( <span class="keyword">false</span>, <span class="keyword">true</span> );
<a name="l02673"></a>02673       otp.parseObjectTree( dataNode );
<a name="l02674"></a>02674 
<a name="l02675"></a>02675       rawReplyString = otp.rawReplyString();
<a name="l02676"></a>02676       gotRawReplyString = <span class="keyword">true</span>;
<a name="l02677"></a>02677         }
<a name="l02678"></a>02678       }
<a name="l02679"></a>02679       QByteArray cstr = gotRawReplyString
<a name="l02680"></a>02680                          ? rawReplyString
<a name="l02681"></a>02681                          : dataNode-&gt;msgPart().bodyDecodedBinary();
<a name="l02682"></a>02682       data = cstr;
<a name="l02683"></a>02683       <span class="keywordtype">size_t</span> size = cstr.size();
<a name="l02684"></a>02684       <span class="keywordflow">if</span> ( dataNode-&gt;msgPart().type() == DwMime::kTypeText ) {
<a name="l02685"></a>02685         <span class="comment">// convert CRLF to LF before writing text attachments to disk</span>
<a name="l02686"></a>02686         size = <a class="code" href="namespaceKMail_1_1Util.html#fd680b9adf53e03ccf6c814da9106d0a" title="Convert all sequences of &amp;quot;\r\n&amp;quot; (carriage return followed by a line feed)...">KMail::Util::crlf2lf</a>( cstr.data(), size );
<a name="l02687"></a>02687       }
<a name="l02688"></a>02688       data.resize( size );
<a name="l02689"></a>02689     }
<a name="l02690"></a>02690   }
<a name="l02691"></a>02691   QDataStream ds;
<a name="l02692"></a>02692   QFile file;
<a name="l02693"></a>02693   KTempFile tf;
<a name="l02694"></a>02694   tf.setAutoDelete( <span class="keyword">true</span> );
<a name="l02695"></a>02695   <span class="keywordflow">if</span> ( url.isLocalFile() )
<a name="l02696"></a>02696   {
<a name="l02697"></a>02697     <span class="comment">// save directly</span>
<a name="l02698"></a>02698     file.setName( url.path() );
<a name="l02699"></a>02699     <span class="keywordflow">if</span> ( !file.open( IO_WriteOnly ) )
<a name="l02700"></a>02700     {
<a name="l02701"></a>02701       KMessageBox::error( parentWidget(),
<a name="l02702"></a>02702           i18n( <span class="stringliteral">"%2 is detailed error description"</span>,
<a name="l02703"></a>02703             <span class="stringliteral">"Could not write the file %1:\n%2"</span> )
<a name="l02704"></a>02704           .arg( file.name() )
<a name="l02705"></a>02705           .arg( QString::fromLocal8Bit( strerror( errno ) ) ),
<a name="l02706"></a>02706           i18n( <span class="stringliteral">"KMail Error"</span> ) );
<a name="l02707"></a>02707       <span class="keywordflow">return</span> Failed;
<a name="l02708"></a>02708     }
<a name="l02709"></a>02709 
<a name="l02710"></a>02710     <span class="comment">// #79685 by default use the umask the user defined, but let it be configurable</span>
<a name="l02711"></a>02711     <span class="keywordflow">if</span> ( GlobalSettings::self()-&gt;disregardUmask() )
<a name="l02712"></a>02712       fchmod( file.handle(), S_IRUSR | S_IWUSR );
<a name="l02713"></a>02713 
<a name="l02714"></a>02714     ds.setDevice( &amp;file );
<a name="l02715"></a>02715   } <span class="keywordflow">else</span>
<a name="l02716"></a>02716   {
<a name="l02717"></a>02717     <span class="comment">// tmp file for upload</span>
<a name="l02718"></a>02718     ds.setDevice( tf.file() );
<a name="l02719"></a>02719   }
<a name="l02720"></a>02720 
<a name="l02721"></a>02721   ds.writeRawBytes( data.data(), data.size() );
<a name="l02722"></a>02722   <span class="keywordflow">if</span> ( !url.isLocalFile() )
<a name="l02723"></a>02723   {
<a name="l02724"></a>02724     tf.close();
<a name="l02725"></a>02725     <span class="keywordflow">if</span> ( !KIO::NetAccess::upload( tf.name(), url, parentWidget() ) )
<a name="l02726"></a>02726     {
<a name="l02727"></a>02727       KMessageBox::error( parentWidget(),
<a name="l02728"></a>02728           i18n( <span class="stringliteral">"Could not write the file %1."</span> )
<a name="l02729"></a>02729           .arg( url.path() ),
<a name="l02730"></a>02730           i18n( <span class="stringliteral">"KMail Error"</span> ) );
<a name="l02731"></a>02731       <span class="keywordflow">return</span> Failed;
<a name="l02732"></a>02732     }
<a name="l02733"></a>02733   } <span class="keywordflow">else</span>
<a name="l02734"></a>02734     file.close();
<a name="l02735"></a>02735   <span class="keywordflow">return</span> OK;
<a name="l02736"></a>02736 }
<a name="l02737"></a>02737 
<a name="l02738"></a>02738 KMLoadPartsCommand::KMLoadPartsCommand( QPtrList&lt;partNode&gt;&amp; parts, <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> *msg )
<a name="l02739"></a>02739   : mNeedsRetrieval( 0 )
<a name="l02740"></a>02740 {
<a name="l02741"></a>02741   <span class="keywordflow">for</span> ( QPtrListIterator&lt;partNode&gt; it( parts ); it.current(); ++it ) {
<a name="l02742"></a>02742     mPartMap.insert( it.current(), msg );
<a name="l02743"></a>02743   }
<a name="l02744"></a>02744 }
<a name="l02745"></a>02745 
<a name="l02746"></a>02746 KMLoadPartsCommand::KMLoadPartsCommand( partNode *node, <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> *msg )
<a name="l02747"></a>02747   : mNeedsRetrieval( 0 )
<a name="l02748"></a>02748 {
<a name="l02749"></a>02749   mPartMap.insert( node, msg );
<a name="l02750"></a>02750 }
<a name="l02751"></a>02751 
<a name="l02752"></a>02752 KMLoadPartsCommand::KMLoadPartsCommand( PartNodeMessageMap&amp; partMap )
<a name="l02753"></a>02753   : mNeedsRetrieval( 0 ), mPartMap( partMap )
<a name="l02754"></a>02754 {
<a name="l02755"></a>02755 }
<a name="l02756"></a>02756 
<a name="l02757"></a>02757 <span class="keywordtype">void</span> KMLoadPartsCommand::slotStart()
<a name="l02758"></a>02758 {
<a name="l02759"></a>02759   <span class="keywordflow">for</span> ( PartNodeMessageMap::const_iterator it = mPartMap.begin();
<a name="l02760"></a>02760         it != mPartMap.end();
<a name="l02761"></a>02761         ++it ) {
<a name="l02762"></a>02762     <span class="keywordflow">if</span> ( !it.key()-&gt;msgPart().isComplete() &amp;&amp;
<a name="l02763"></a>02763          !it.key()-&gt;msgPart().partSpecifier().isEmpty() ) {
<a name="l02764"></a>02764       <span class="comment">// incomplete part, so retrieve it first</span>
<a name="l02765"></a>02765       ++mNeedsRetrieval;
<a name="l02766"></a>02766       <a class="code" href="classKMFolder.html" title="Mail folder.">KMFolder</a>* curFolder = it.data()-&gt;parent();
<a name="l02767"></a>02767       <span class="keywordflow">if</span> ( curFolder ) {
<a name="l02768"></a>02768         FolderJob *job =
<a name="l02769"></a>02769           curFolder-&gt;<a class="code" href="classKMFolder.html#b9db21189505d49d37d9f114e216d2f4" title="These methods create respective FolderJob (You should derive FolderJob for each derived...">createJob</a>( it.data(), FolderJob::tGetMessage,
<a name="l02770"></a>02770                                 0, it.key()-&gt;msgPart().partSpecifier() );
<a name="l02771"></a>02771         job-&gt;setCancellable( <span class="keyword">false</span> );
<a name="l02772"></a>02772         connect( job, SIGNAL(messageUpdated(<a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a>*, QString)),
<a name="l02773"></a>02773                  <span class="keyword">this</span>, SLOT(slotPartRetrieved(<a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a>*, QString)) );
<a name="l02774"></a>02774         job-&gt;start();
<a name="l02775"></a>02775       } <span class="keywordflow">else</span>
<a name="l02776"></a>02776         kdWarning(5006) &lt;&lt; <span class="stringliteral">"KMLoadPartsCommand - msg has no parent"</span> &lt;&lt; endl;
<a name="l02777"></a>02777     }
<a name="l02778"></a>02778   }
<a name="l02779"></a>02779   <span class="keywordflow">if</span> ( mNeedsRetrieval == 0 )
<a name="l02780"></a>02780     execute();
<a name="l02781"></a>02781 }
<a name="l02782"></a>02782 
<a name="l02783"></a>02783 <span class="keywordtype">void</span> KMLoadPartsCommand::slotPartRetrieved( <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> *msg,
<a name="l02784"></a>02784                                             QString partSpecifier )
<a name="l02785"></a>02785 {
<a name="l02786"></a>02786   DwBodyPart *part =
<a name="l02787"></a>02787     msg-&gt;<a class="code" href="classKMMessage.html#115edb44d72866530342c81142e419da" title="Return the first DwBodyPart matching a given Content-Type or zero, if no found.">findDwBodyPart</a>( msg-&gt;<a class="code" href="classKMMessage.html#f7412a18d6089e1055bfe50283671714" title="Get the 1st DwBodyPart.">getFirstDwBodyPart</a>(), partSpecifier );
<a name="l02788"></a>02788   <span class="keywordflow">if</span> ( part ) {
<a name="l02789"></a>02789     <span class="comment">// update the DwBodyPart in the partNode</span>
<a name="l02790"></a>02790     <span class="keywordflow">for</span> ( PartNodeMessageMap::const_iterator it = mPartMap.begin();
<a name="l02791"></a>02791           it != mPartMap.end();
<a name="l02792"></a>02792           ++it ) {
<a name="l02793"></a>02793       <span class="keywordflow">if</span> ( it.key()-&gt;dwPart()-&gt;partId() == part-&gt;partId() )
<a name="l02794"></a>02794         it.key()-&gt;setDwPart( part );
<a name="l02795"></a>02795     }
<a name="l02796"></a>02796   } <span class="keywordflow">else</span>
<a name="l02797"></a>02797     kdWarning(5006) &lt;&lt; <span class="stringliteral">"KMLoadPartsCommand::slotPartRetrieved - could not find bodypart!"</span> &lt;&lt; endl;
<a name="l02798"></a>02798   --mNeedsRetrieval;
<a name="l02799"></a>02799   <span class="keywordflow">if</span> ( mNeedsRetrieval == 0 )
<a name="l02800"></a>02800     execute();
<a name="l02801"></a>02801 }
<a name="l02802"></a>02802 
<a name="l02803"></a>02803 KMCommand::Result KMLoadPartsCommand::execute()
<a name="l02804"></a>02804 {
<a name="l02805"></a>02805   emit partsRetrieved();
<a name="l02806"></a>02806   setResult( OK );
<a name="l02807"></a>02807   emit completed( <span class="keyword">this</span> );
<a name="l02808"></a>02808   deleteLater();
<a name="l02809"></a>02809   <span class="keywordflow">return</span> OK;
<a name="l02810"></a>02810 }
<a name="l02811"></a>02811 
<a name="l02812"></a>02812 KMResendMessageCommand::KMResendMessageCommand( QWidget *parent,
<a name="l02813"></a>02813    <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> *msg )
<a name="l02814"></a>02814   :KMCommand( parent, msg )
<a name="l02815"></a>02815 {
<a name="l02816"></a>02816 }
<a name="l02817"></a>02817 
<a name="l02818"></a>02818 KMCommand::Result KMResendMessageCommand::execute()
<a name="l02819"></a>02819 {
<a name="l02820"></a>02820    <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> *msg = retrievedMessage();
<a name="l02821"></a>02821    <span class="keywordflow">if</span> ( !msg || !msg-&gt;<a class="code" href="classKMMessage.html#91762b3880f42da72185c59c40b28cac" title="Get a QTextCodec suitable for this message part.">codec</a>() ) {
<a name="l02822"></a>02822      <span class="keywordflow">return</span> Failed;
<a name="l02823"></a>02823    }
<a name="l02824"></a>02824    <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> *newMsg = <span class="keyword">new</span> <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a>(*msg);
<a name="l02825"></a>02825 
<a name="l02826"></a>02826    QStringList whiteList;
<a name="l02827"></a>02827    whiteList &lt;&lt; <span class="stringliteral">"To"</span> &lt;&lt; <span class="stringliteral">"Cc"</span> &lt;&lt; <span class="stringliteral">"Bcc"</span> &lt;&lt; <span class="stringliteral">"Subject"</span>;
<a name="l02828"></a>02828    newMsg-&gt;<a class="code" href="classKMMessage.html#7a5df78062e4283cebd3eccba0fcb5ad" title="Remove all headers but the content description ones, and those in the white list...">sanitizeHeaders</a>( whiteList );
<a name="l02829"></a>02829 
<a name="l02830"></a>02830    newMsg-&gt;<a class="code" href="classKMMessage.html#6c6413b3690538964ac810f4c6755a5b" title="Set the message charset.">setCharset</a>(msg-&gt;<a class="code" href="classKMMessage.html#91762b3880f42da72185c59c40b28cac" title="Get a QTextCodec suitable for this message part.">codec</a>()-&gt;mimeName());
<a name="l02831"></a>02831    newMsg-&gt;setParent( 0 );
<a name="l02832"></a>02832 
<a name="l02833"></a>02833    <span class="comment">// make sure we have an identity set, default, if necessary</span>
<a name="l02834"></a>02834    newMsg-&gt;<a class="code" href="classKMMessage.html#de227ca74ea9bca2412ddfc63b4025c6" title="Set the header field with the given name to the given value.">setHeaderField</a>(<span class="stringliteral">"X-KMail-Identity"</span>, QString::number( newMsg-&gt;<a class="code" href="classKMMessage.html#c48977675781b8337b2bee6487070ac4">identityUoid</a>() ));
<a name="l02835"></a>02835    newMsg-&gt;<a class="code" href="classKMMessage.html#af14defee2f25d286fb7019688008280" title="Set the from, to, cc, bcc, encrytion etc headers as specified in the given identity...">applyIdentity</a>( newMsg-&gt;<a class="code" href="classKMMessage.html#c48977675781b8337b2bee6487070ac4">identityUoid</a>() );
<a name="l02836"></a>02836 
<a name="l02837"></a>02837    KMail::Composer * win = KMail::makeComposer();
<a name="l02838"></a>02838    win-&gt;setMsg(newMsg, <span class="keyword">false</span>, <span class="keyword">true</span>);
<a name="l02839"></a>02839    win-&gt;show();
<a name="l02840"></a>02840 
<a name="l02841"></a>02841    <span class="keywordflow">return</span> OK;
<a name="l02842"></a>02842 }
<a name="l02843"></a>02843 
<a name="l02844"></a>02844 KMMailingListCommand::KMMailingListCommand( QWidget *parent, <a class="code" href="classKMFolder.html" title="Mail folder.">KMFolder</a> *folder )
<a name="l02845"></a>02845   : KMCommand( parent ), mFolder( folder )
<a name="l02846"></a>02846 {
<a name="l02847"></a>02847 }
<a name="l02848"></a>02848 
<a name="l02849"></a>02849 KMCommand::Result KMMailingListCommand::execute()
<a name="l02850"></a>02850 {
<a name="l02851"></a>02851   KURL::List lst = urls();
<a name="l02852"></a>02852   QString handler = ( mFolder-&gt;mailingList().handler() == MailingList::KMail )
<a name="l02853"></a>02853     ? <span class="stringliteral">"mailto"</span> : <span class="stringliteral">"https"</span>;
<a name="l02854"></a>02854 
<a name="l02855"></a>02855   KMCommand *command = 0;
<a name="l02856"></a>02856   <span class="keywordflow">for</span> ( KURL::List::Iterator itr = lst.begin(); itr != lst.end(); ++itr ) {
<a name="l02857"></a>02857     <span class="keywordflow">if</span> ( handler == (*itr).protocol() ) {
<a name="l02858"></a>02858       command = <span class="keyword">new</span> KMUrlClickedCommand( *itr, mFolder-&gt;identity(), 0, false );
<a name="l02859"></a>02859     }
<a name="l02860"></a>02860   }
<a name="l02861"></a>02861   <span class="keywordflow">if</span> ( !command &amp;&amp; !lst.empty() ) {
<a name="l02862"></a>02862     command =
<a name="l02863"></a>02863       <span class="keyword">new</span> KMUrlClickedCommand( lst.first(), mFolder-&gt;identity(), 0, false );
<a name="l02864"></a>02864   }
<a name="l02865"></a>02865   <span class="keywordflow">if</span> ( command ) {
<a name="l02866"></a>02866     connect( command, SIGNAL( completed( KMCommand * ) ),
<a name="l02867"></a>02867              <span class="keyword">this</span>, SLOT( commandCompleted( KMCommand * ) ) );
<a name="l02868"></a>02868     setDeletesItself( <span class="keyword">true</span> );
<a name="l02869"></a>02869     setEmitsCompletedItself( <span class="keyword">true</span> );
<a name="l02870"></a>02870     command-&gt;start();
<a name="l02871"></a>02871     <span class="keywordflow">return</span> OK;
<a name="l02872"></a>02872   }
<a name="l02873"></a>02873   <span class="keywordflow">return</span> Failed;
<a name="l02874"></a>02874 }
<a name="l02875"></a>02875 
<a name="l02876"></a>02876 <span class="keywordtype">void</span> KMMailingListCommand::commandCompleted( KMCommand *command )
<a name="l02877"></a>02877 {
<a name="l02878"></a>02878   setResult( command-&gt;result() );
<a name="l02879"></a>02879   emit completed( <span class="keyword">this</span> );
<a name="l02880"></a>02880   deleteLater();
<a name="l02881"></a>02881 }
<a name="l02882"></a>02882 
<a name="l02883"></a>02883 KMMailingListPostCommand::KMMailingListPostCommand( QWidget *parent, <a class="code" href="classKMFolder.html" title="Mail folder.">KMFolder</a> *folder )
<a name="l02884"></a>02884   : KMMailingListCommand( parent, folder )
<a name="l02885"></a>02885 {
<a name="l02886"></a>02886 }
<a name="l02887"></a>02887 KURL::List KMMailingListPostCommand::urls()<span class="keyword"> const</span>
<a name="l02888"></a>02888 <span class="keyword"></span>{
<a name="l02889"></a>02889   <span class="keywordflow">return</span> mFolder-&gt;mailingList().postURLS();
<a name="l02890"></a>02890 }
<a name="l02891"></a>02891 
<a name="l02892"></a>02892 KMMailingListSubscribeCommand::KMMailingListSubscribeCommand( QWidget *parent, <a class="code" href="classKMFolder.html" title="Mail folder.">KMFolder</a> *folder )
<a name="l02893"></a>02893   : KMMailingListCommand( parent, folder )
<a name="l02894"></a>02894 {
<a name="l02895"></a>02895 }
<a name="l02896"></a>02896 KURL::List KMMailingListSubscribeCommand::urls()<span class="keyword"> const</span>
<a name="l02897"></a>02897 <span class="keyword"></span>{
<a name="l02898"></a>02898   <span class="keywordflow">return</span> mFolder-&gt;mailingList().subscribeURLS();
<a name="l02899"></a>02899 }
<a name="l02900"></a>02900 
<a name="l02901"></a>02901 KMMailingListUnsubscribeCommand::KMMailingListUnsubscribeCommand( QWidget *parent, <a class="code" href="classKMFolder.html" title="Mail folder.">KMFolder</a> *folder )
<a name="l02902"></a>02902   : KMMailingListCommand( parent, folder )
<a name="l02903"></a>02903 {
<a name="l02904"></a>02904 }
<a name="l02905"></a>02905 KURL::List KMMailingListUnsubscribeCommand::urls()<span class="keyword"> const</span>
<a name="l02906"></a>02906 <span class="keyword"></span>{
<a name="l02907"></a>02907   <span class="keywordflow">return</span> mFolder-&gt;mailingList().unsubscribeURLS();
<a name="l02908"></a>02908 }
<a name="l02909"></a>02909 
<a name="l02910"></a>02910 KMMailingListArchivesCommand::KMMailingListArchivesCommand( QWidget *parent, <a class="code" href="classKMFolder.html" title="Mail folder.">KMFolder</a> *folder )
<a name="l02911"></a>02911   : KMMailingListCommand( parent, folder )
<a name="l02912"></a>02912 {
<a name="l02913"></a>02913 }
<a name="l02914"></a>02914 KURL::List KMMailingListArchivesCommand::urls()<span class="keyword"> const</span>
<a name="l02915"></a>02915 <span class="keyword"></span>{
<a name="l02916"></a>02916   <span class="keywordflow">return</span> mFolder-&gt;mailingList().archiveURLS();
<a name="l02917"></a>02917 }
<a name="l02918"></a>02918 
<a name="l02919"></a>02919 KMMailingListHelpCommand::KMMailingListHelpCommand( QWidget *parent, <a class="code" href="classKMFolder.html" title="Mail folder.">KMFolder</a> *folder )
<a name="l02920"></a>02920   : KMMailingListCommand( parent, folder )
<a name="l02921"></a>02921 {
<a name="l02922"></a>02922 }
<a name="l02923"></a>02923 KURL::List KMMailingListHelpCommand::urls()<span class="keyword"> const</span>
<a name="l02924"></a>02924 <span class="keyword"></span>{
<a name="l02925"></a>02925   <span class="keywordflow">return</span> mFolder-&gt;mailingList().helpURLS();
<a name="l02926"></a>02926 }
<a name="l02927"></a>02927 
<a name="l02928"></a>02928 KMIMChatCommand::KMIMChatCommand( <span class="keyword">const</span> KURL &amp;url, <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> *msg )
<a name="l02929"></a>02929   :mUrl( url ), mMessage( msg )
<a name="l02930"></a>02930 {
<a name="l02931"></a>02931 }
<a name="l02932"></a>02932 
<a name="l02933"></a>02933 KMCommand::Result KMIMChatCommand::execute()
<a name="l02934"></a>02934 {
<a name="l02935"></a>02935   kdDebug( 5006 ) &lt;&lt; k_funcinfo &lt;&lt; <span class="stringliteral">" URL is: "</span> &lt;&lt; mUrl &lt;&lt; endl;
<a name="l02936"></a>02936   QString addr = <a class="code" href="classKMMessage.html#e8dca5f50d21a63908d4026e2683ac60" title="Decodes a mailto URL.">KMMessage::decodeMailtoUrl</a>( mUrl.path() );
<a name="l02937"></a>02937   <span class="comment">// find UID for mail address</span>
<a name="l02938"></a>02938   KABC::AddressBook *addressBook = KABC::StdAddressBook::self( <span class="keyword">true</span> );
<a name="l02939"></a>02939   KABC::AddresseeList addressees = addressBook-&gt;findByEmail( KPIM::getEmailAddress( addr ) ) ;
<a name="l02940"></a>02940 
<a name="l02941"></a>02941   <span class="comment">// start chat</span>
<a name="l02942"></a>02942   <span class="keywordflow">if</span>( addressees.count() == 1 ) {
<a name="l02943"></a>02943     kmkernel-&gt;imProxy()-&gt;chatWithContact( addressees[0].uid() );
<a name="l02944"></a>02944     <span class="keywordflow">return</span> OK;
<a name="l02945"></a>02945   }
<a name="l02946"></a>02946   <span class="keywordflow">else</span>
<a name="l02947"></a>02947   {
<a name="l02948"></a>02948     kdDebug( 5006 ) &lt;&lt; <span class="stringliteral">"Didn't find exactly one addressee, couldn't tell who to chat to for that email address.  Count = "</span> &lt;&lt; addressees.count() &lt;&lt; endl;
<a name="l02949"></a>02949 
<a name="l02950"></a>02950     QString apology;
<a name="l02951"></a>02951     <span class="keywordflow">if</span> ( addressees.isEmpty() )
<a name="l02952"></a>02952       apology = i18n( <span class="stringliteral">"There is no Address Book entry for this email address. Add them to the Address Book and then add instant messaging addresses using your preferred messaging client."</span> );
<a name="l02953"></a>02953     <span class="keywordflow">else</span>
<a name="l02954"></a>02954     {
<a name="l02955"></a>02955       apology = i18n( <span class="stringliteral">"More than one Address Book entry uses this email address:\n %1\n it is not possible to determine who to chat with."</span> );
<a name="l02956"></a>02956       QStringList nameList;
<a name="l02957"></a>02957       KABC::AddresseeList::const_iterator it = addressees.begin();
<a name="l02958"></a>02958       KABC::AddresseeList::const_iterator end = addressees.end();
<a name="l02959"></a>02959       <span class="keywordflow">for</span> ( ; it != end; ++it )
<a name="l02960"></a>02960       {
<a name="l02961"></a>02961           nameList.append( (*it).realName() );
<a name="l02962"></a>02962       }
<a name="l02963"></a>02963       QString names = nameList.join( QString::fromLatin1( <span class="stringliteral">",\n"</span> ) );
<a name="l02964"></a>02964       apology = apology.arg( names );
<a name="l02965"></a>02965     }
<a name="l02966"></a>02966 
<a name="l02967"></a>02967     KMessageBox::sorry( parentWidget(), apology );
<a name="l02968"></a>02968     <span class="keywordflow">return</span> Failed;
<a name="l02969"></a>02969   }
<a name="l02970"></a>02970 }
<a name="l02971"></a>02971 
<a name="l02972"></a>02972 KMHandleAttachmentCommand::KMHandleAttachmentCommand( partNode* node,
<a name="l02973"></a>02973      <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a>* msg, <span class="keywordtype">int</span> atmId, <span class="keyword">const</span> QString&amp; atmName,
<a name="l02974"></a>02974      AttachmentAction action, KService::Ptr offer, QWidget* parent )
<a name="l02975"></a>02975 : KMCommand( parent ), mNode( node ), mMsg( msg ), mAtmId( atmId ), mAtmName( atmName ),
<a name="l02976"></a>02976   mAction( action ), mOffer( offer ), mJob( 0 )
<a name="l02977"></a>02977 {
<a name="l02978"></a>02978 }
<a name="l02979"></a>02979 
<a name="l02980"></a>02980 <span class="keywordtype">void</span> KMHandleAttachmentCommand::slotStart()
<a name="l02981"></a>02981 {
<a name="l02982"></a>02982   <span class="keywordflow">if</span> ( !mNode-&gt;msgPart().isComplete() )
<a name="l02983"></a>02983   {
<a name="l02984"></a>02984     <span class="comment">// load the part</span>
<a name="l02985"></a>02985     kdDebug(5006) &lt;&lt; <span class="stringliteral">"load part"</span> &lt;&lt; endl;
<a name="l02986"></a>02986     KMLoadPartsCommand *command = <span class="keyword">new</span> KMLoadPartsCommand( mNode, mMsg );
<a name="l02987"></a>02987     connect( command, SIGNAL( partsRetrieved() ),
<a name="l02988"></a>02988         <span class="keyword">this</span>, SLOT( slotPartComplete() ) );
<a name="l02989"></a>02989     command-&gt;start();
<a name="l02990"></a>02990   } <span class="keywordflow">else</span>
<a name="l02991"></a>02991   {
<a name="l02992"></a>02992     execute();
<a name="l02993"></a>02993   }
<a name="l02994"></a>02994 }
<a name="l02995"></a>02995 
<a name="l02996"></a>02996 <span class="keywordtype">void</span> KMHandleAttachmentCommand::slotPartComplete()
<a name="l02997"></a>02997 {
<a name="l02998"></a>02998   execute();
<a name="l02999"></a>02999 }
<a name="l03000"></a>03000 
<a name="l03001"></a>03001 KMCommand::Result KMHandleAttachmentCommand::execute()
<a name="l03002"></a>03002 {
<a name="l03003"></a>03003   <span class="keywordflow">switch</span>( mAction )
<a name="l03004"></a>03004   {
<a name="l03005"></a>03005     <span class="keywordflow">case</span> Open:
<a name="l03006"></a>03006       atmOpen();
<a name="l03007"></a>03007       <span class="keywordflow">break</span>;
<a name="l03008"></a>03008     <span class="keywordflow">case</span> OpenWith:
<a name="l03009"></a>03009       atmOpenWith();
<a name="l03010"></a>03010       <span class="keywordflow">break</span>;
<a name="l03011"></a>03011     <span class="keywordflow">case</span> View:
<a name="l03012"></a>03012       atmView();
<a name="l03013"></a>03013       <span class="keywordflow">break</span>;
<a name="l03014"></a>03014     <span class="keywordflow">case</span> Save:
<a name="l03015"></a>03015       atmSave();
<a name="l03016"></a>03016       <span class="keywordflow">break</span>;
<a name="l03017"></a>03017     <span class="keywordflow">case</span> Properties:
<a name="l03018"></a>03018       atmProperties();
<a name="l03019"></a>03019       <span class="keywordflow">break</span>;
<a name="l03020"></a>03020     <span class="keywordflow">case</span> ChiasmusEncrypt:
<a name="l03021"></a>03021       atmEncryptWithChiasmus();
<a name="l03022"></a>03022       <span class="keywordflow">return</span> Undefined;
<a name="l03023"></a>03023       <span class="keywordflow">break</span>;
<a name="l03024"></a>03024     <span class="keywordflow">default</span>:
<a name="l03025"></a>03025       kdDebug(5006) &lt;&lt; <span class="stringliteral">"unknown action "</span> &lt;&lt; mAction &lt;&lt; endl;
<a name="l03026"></a>03026       <span class="keywordflow">break</span>;
<a name="l03027"></a>03027   }
<a name="l03028"></a>03028   setResult( OK );
<a name="l03029"></a>03029   emit completed( <span class="keyword">this</span> );
<a name="l03030"></a>03030   deleteLater();
<a name="l03031"></a>03031   <span class="keywordflow">return</span> OK;
<a name="l03032"></a>03032 }
<a name="l03033"></a>03033 
<a name="l03034"></a>03034 QString KMHandleAttachmentCommand::createAtmFileLink()<span class="keyword"> const</span>
<a name="l03035"></a>03035 <span class="keyword"></span>{
<a name="l03036"></a>03036   QFileInfo atmFileInfo( mAtmName );
<a name="l03037"></a>03037 
<a name="l03038"></a>03038   <span class="keywordflow">if</span> ( atmFileInfo.size() == 0 )
<a name="l03039"></a>03039   {
<a name="l03040"></a>03040     kdDebug(5006) &lt;&lt; k_funcinfo &lt;&lt; <span class="stringliteral">"rewriting attachment"</span> &lt;&lt; endl;
<a name="l03041"></a>03041     <span class="comment">// there is something wrong so write the file again</span>
<a name="l03042"></a>03042     QByteArray data = mNode-&gt;msgPart().bodyDecodedBinary();
<a name="l03043"></a>03043     <span class="keywordtype">size_t</span> size = data.size();
<a name="l03044"></a>03044     <span class="keywordflow">if</span> ( mNode-&gt;msgPart().type() == DwMime::kTypeText &amp;&amp; size) {
<a name="l03045"></a>03045       <span class="comment">// convert CRLF to LF before writing text attachments to disk</span>
<a name="l03046"></a>03046       size = <a class="code" href="namespaceKMail_1_1Util.html#fd680b9adf53e03ccf6c814da9106d0a" title="Convert all sequences of &amp;quot;\r\n&amp;quot; (carriage return followed by a line feed)...">KMail::Util::crlf2lf</a>( data.data(), size );
<a name="l03047"></a>03047     }
<a name="l03048"></a>03048     KPIM::kBytesToFile( data.data(), size, mAtmName, <span class="keyword">false</span>, <span class="keyword">false</span>, false );
<a name="l03049"></a>03049   }
<a name="l03050"></a>03050 
<a name="l03051"></a>03051   KTempFile *linkFile = <span class="keyword">new</span> KTempFile( locateLocal(<span class="stringliteral">"tmp"</span>, atmFileInfo.fileName() +<span class="stringliteral">"_["</span>),
<a name="l03052"></a>03052                           <span class="stringliteral">"]."</span>+ atmFileInfo.extension() );
<a name="l03053"></a>03053 
<a name="l03054"></a>03054   linkFile-&gt;setAutoDelete(<span class="keyword">true</span>);
<a name="l03055"></a>03055   QString linkName = linkFile-&gt;name();
<a name="l03056"></a>03056   <span class="keyword">delete</span> linkFile;
<a name="l03057"></a>03057 
<a name="l03058"></a>03058   <span class="keywordflow">if</span> ( ::link(QFile::encodeName( mAtmName ), QFile::encodeName( linkName )) == 0 ) {
<a name="l03059"></a>03059     <span class="keywordflow">return</span> linkName; <span class="comment">// success</span>
<a name="l03060"></a>03060   }
<a name="l03061"></a>03061   <span class="keywordflow">return</span> QString::null;
<a name="l03062"></a>03062 }
<a name="l03063"></a>03063 
<a name="l03064"></a>03064 KService::Ptr KMHandleAttachmentCommand::getServiceOffer()
<a name="l03065"></a>03065 {
<a name="l03066"></a>03066   KMMessagePart&amp; msgPart = mNode-&gt;msgPart();
<a name="l03067"></a>03067   <span class="keyword">const</span> QString contentTypeStr =
<a name="l03068"></a>03068     ( msgPart.typeStr() + <span class="charliteral">'/'</span> + msgPart.subtypeStr() ).lower();
<a name="l03069"></a>03069 
<a name="l03070"></a>03070   <span class="keywordflow">if</span> ( contentTypeStr == <span class="stringliteral">"text/x-vcard"</span> ) {
<a name="l03071"></a>03071     atmView();
<a name="l03072"></a>03072     <span class="keywordflow">return</span> 0;
<a name="l03073"></a>03073   }
<a name="l03074"></a>03074   <span class="comment">// determine the MIME type of the attachment</span>
<a name="l03075"></a>03075   KMimeType::Ptr mimetype;
<a name="l03076"></a>03076   <span class="comment">// prefer the value of the Content-Type header</span>
<a name="l03077"></a>03077   mimetype = KMimeType::mimeType( contentTypeStr );
<a name="l03078"></a>03078   <span class="keywordflow">if</span> ( mimetype-&gt;name() == <span class="stringliteral">"application/octet-stream"</span> ) {
<a name="l03079"></a>03079     <span class="comment">// consider the filename if Content-Type is application/octet-stream</span>
<a name="l03080"></a>03080     mimetype = KMimeType::findByPath( mAtmName, 0, <span class="keyword">true</span> <span class="comment">/* no disk access */</span> );
<a name="l03081"></a>03081   }
<a name="l03082"></a>03082   <span class="keywordflow">if</span> ( ( mimetype-&gt;name() == <span class="stringliteral">"application/octet-stream"</span> )
<a name="l03083"></a>03083        &amp;&amp; msgPart.isComplete() ) {
<a name="l03084"></a>03084     <span class="comment">// consider the attachment's contents if neither the Content-Type header</span>
<a name="l03085"></a>03085     <span class="comment">// nor the filename give us a clue</span>
<a name="l03086"></a>03086     mimetype = KMimeType::findByFileContent( mAtmName );
<a name="l03087"></a>03087   }
<a name="l03088"></a>03088   <span class="keywordflow">return</span> KServiceTypeProfile::preferredService( mimetype-&gt;name(), <span class="stringliteral">"Application"</span> );
<a name="l03089"></a>03089 }
<a name="l03090"></a>03090 
<a name="l03091"></a>03091 <span class="keywordtype">void</span> KMHandleAttachmentCommand::atmOpen()
<a name="l03092"></a>03092 {
<a name="l03093"></a>03093   <span class="keywordflow">if</span> ( !mOffer )
<a name="l03094"></a>03094     mOffer = getServiceOffer();
<a name="l03095"></a>03095   <span class="keywordflow">if</span> ( !mOffer ) {
<a name="l03096"></a>03096     kdDebug(5006) &lt;&lt; k_funcinfo &lt;&lt; <span class="stringliteral">"got no offer"</span> &lt;&lt; endl;
<a name="l03097"></a>03097     <span class="keywordflow">return</span>;
<a name="l03098"></a>03098   }
<a name="l03099"></a>03099 
<a name="l03100"></a>03100   KURL::List lst;
<a name="l03101"></a>03101   KURL url;
<a name="l03102"></a>03102   <span class="keywordtype">bool</span> autoDelete = <span class="keyword">true</span>;
<a name="l03103"></a>03103   QString fname = createAtmFileLink();
<a name="l03104"></a>03104 
<a name="l03105"></a>03105   <span class="keywordflow">if</span> ( fname.isNull() ) {
<a name="l03106"></a>03106     autoDelete = <span class="keyword">false</span>;
<a name="l03107"></a>03107     fname = mAtmName;
<a name="l03108"></a>03108   }
<a name="l03109"></a>03109 
<a name="l03110"></a>03110   url.setPath( fname );
<a name="l03111"></a>03111   lst.append( url );
<a name="l03112"></a>03112   <span class="keywordflow">if</span> ( (KRun::run( *mOffer, lst, autoDelete ) &lt;= 0) &amp;&amp; autoDelete ) {
<a name="l03113"></a>03113       QFile::remove(url.path());
<a name="l03114"></a>03114   }
<a name="l03115"></a>03115 }
<a name="l03116"></a>03116 
<a name="l03117"></a>03117 <span class="keywordtype">void</span> KMHandleAttachmentCommand::atmOpenWith()
<a name="l03118"></a>03118 {
<a name="l03119"></a>03119   KURL::List lst;
<a name="l03120"></a>03120   KURL url;
<a name="l03121"></a>03121   <span class="keywordtype">bool</span> autoDelete = <span class="keyword">true</span>;
<a name="l03122"></a>03122   QString fname = createAtmFileLink();
<a name="l03123"></a>03123 
<a name="l03124"></a>03124   <span class="keywordflow">if</span> ( fname.isNull() ) {
<a name="l03125"></a>03125     autoDelete = <span class="keyword">false</span>;
<a name="l03126"></a>03126     fname = mAtmName;
<a name="l03127"></a>03127   }
<a name="l03128"></a>03128 
<a name="l03129"></a>03129   url.setPath( fname );
<a name="l03130"></a>03130   lst.append( url );
<a name="l03131"></a>03131   <span class="keywordflow">if</span> ( (! KRun::displayOpenWithDialog(lst, autoDelete)) &amp;&amp; autoDelete ) {
<a name="l03132"></a>03132     QFile::remove( url.path() );
<a name="l03133"></a>03133   }
<a name="l03134"></a>03134 }
<a name="l03135"></a>03135 
<a name="l03136"></a>03136 <span class="keywordtype">void</span> KMHandleAttachmentCommand::atmView()
<a name="l03137"></a>03137 {
<a name="l03138"></a>03138   <span class="comment">// we do not handle this ourself</span>
<a name="l03139"></a>03139   emit showAttachment( mAtmId, mAtmName );
<a name="l03140"></a>03140 }
<a name="l03141"></a>03141 
<a name="l03142"></a>03142 <span class="keywordtype">void</span> KMHandleAttachmentCommand::atmSave()
<a name="l03143"></a>03143 {
<a name="l03144"></a>03144   QPtrList&lt;partNode&gt; parts;
<a name="l03145"></a>03145   parts.append( mNode );
<a name="l03146"></a>03146   <span class="comment">// save, do not leave encoded</span>
<a name="l03147"></a>03147   KMSaveAttachmentsCommand *command =
<a name="l03148"></a>03148     <span class="keyword">new</span> KMSaveAttachmentsCommand( 0, parts, mMsg, <span class="keyword">false</span> );
<a name="l03149"></a>03149   command-&gt;start();
<a name="l03150"></a>03150 }
<a name="l03151"></a>03151 
<a name="l03152"></a>03152 <span class="keywordtype">void</span> KMHandleAttachmentCommand::atmProperties()
<a name="l03153"></a>03153 {
<a name="l03154"></a>03154   <a class="code" href="classKMMsgPartDialogCompat.html" title="The attachment dialog with convenience backward compatible methods.">KMMsgPartDialogCompat</a> dlg( parentWidget() , 0, <span class="keyword">true</span> );
<a name="l03155"></a>03155   KMMessagePart&amp; msgPart = mNode-&gt;msgPart();
<a name="l03156"></a>03156   dlg.setMsgPart( &amp;msgPart );
<a name="l03157"></a>03157   dlg.exec();
<a name="l03158"></a>03158 }
<a name="l03159"></a>03159 
<a name="l03160"></a>03160 <span class="keywordtype">void</span> KMHandleAttachmentCommand::atmEncryptWithChiasmus()
<a name="l03161"></a>03161 {
<a name="l03162"></a>03162   <span class="keyword">const</span> partNode * node = mNode;
<a name="l03163"></a>03163   Q_ASSERT( node );
<a name="l03164"></a>03164   <span class="keywordflow">if</span> ( !node )
<a name="l03165"></a>03165     <span class="keywordflow">return</span>;
<a name="l03166"></a>03166 
<a name="l03167"></a>03167   <span class="comment">// FIXME: better detection of mimetype??</span>
<a name="l03168"></a>03168   <span class="keywordflow">if</span> ( !mAtmName.endsWith( <span class="stringliteral">".xia"</span>, <span class="keyword">false</span> ) )
<a name="l03169"></a>03169     <span class="keywordflow">return</span>;
<a name="l03170"></a>03170 
<a name="l03171"></a>03171   <span class="keyword">const</span> Kleo::CryptoBackend::Protocol * chiasmus =
<a name="l03172"></a>03172     Kleo::CryptoBackendFactory::instance()-&gt;protocol( <span class="stringliteral">"Chiasmus"</span> );
<a name="l03173"></a>03173   Q_ASSERT( chiasmus );
<a name="l03174"></a>03174   <span class="keywordflow">if</span> ( !chiasmus )
<a name="l03175"></a>03175     <span class="keywordflow">return</span>;
<a name="l03176"></a>03176 
<a name="l03177"></a>03177   <span class="keyword">const</span> STD_NAMESPACE_PREFIX auto_ptr&lt;Kleo::SpecialJob&gt; listjob( chiasmus-&gt;specialJob( <span class="stringliteral">"x-obtain-keys"</span>, QMap&lt;QString,QVariant&gt;() ) );
<a name="l03178"></a>03178   <span class="keywordflow">if</span> ( !listjob.get() ) {
<a name="l03179"></a>03179     <span class="keyword">const</span> QString msg = i18n( <span class="stringliteral">"Chiasmus backend does not offer the "</span>
<a name="l03180"></a>03180                               <span class="stringliteral">"\"x-obtain-keys\" function. Please report this bug."</span> );
<a name="l03181"></a>03181     KMessageBox::error( parentWidget(), msg, i18n( <span class="stringliteral">"Chiasmus Backend Error"</span> ) );
<a name="l03182"></a>03182     <span class="keywordflow">return</span>;
<a name="l03183"></a>03183   }
<a name="l03184"></a>03184 
<a name="l03185"></a>03185   <span class="keywordflow">if</span> ( listjob-&gt;exec() ) {
<a name="l03186"></a>03186     listjob-&gt;showErrorDialog( parentWidget(), i18n( <span class="stringliteral">"Chiasmus Backend Error"</span> ) );
<a name="l03187"></a>03187     <span class="keywordflow">return</span>;
<a name="l03188"></a>03188   }
<a name="l03189"></a>03189 
<a name="l03190"></a>03190   <span class="keyword">const</span> QVariant result = listjob-&gt;property( <span class="stringliteral">"result"</span> );
<a name="l03191"></a>03191   <span class="keywordflow">if</span> ( result.type() != QVariant::StringList ) {
<a name="l03192"></a>03192     <span class="keyword">const</span> QString msg = i18n( <span class="stringliteral">"Unexpected return value from Chiasmus backend: "</span>
<a name="l03193"></a>03193                               <span class="stringliteral">"The \"x-obtain-keys\" function did not return a "</span>
<a name="l03194"></a>03194                               <span class="stringliteral">"string list. Please report this bug."</span> );
<a name="l03195"></a>03195     KMessageBox::error( parentWidget(), msg, i18n( <span class="stringliteral">"Chiasmus Backend Error"</span> ) );
<a name="l03196"></a>03196     <span class="keywordflow">return</span>;
<a name="l03197"></a>03197   }
<a name="l03198"></a>03198 
<a name="l03199"></a>03199   <span class="keyword">const</span> QStringList keys = result.toStringList();
<a name="l03200"></a>03200   <span class="keywordflow">if</span> ( keys.empty() ) {
<a name="l03201"></a>03201     <span class="keyword">const</span> QString msg = i18n( <span class="stringliteral">"No keys have been found. Please check that a "</span>
<a name="l03202"></a>03202                               <span class="stringliteral">"valid key path has been set in the Chiasmus "</span>
<a name="l03203"></a>03203                               <span class="stringliteral">"configuration."</span> );
<a name="l03204"></a>03204     KMessageBox::error( parentWidget(), msg, i18n( <span class="stringliteral">"Chiasmus Backend Error"</span> ) );
<a name="l03205"></a>03205     <span class="keywordflow">return</span>;
<a name="l03206"></a>03206   }
<a name="l03207"></a>03207 
<a name="l03208"></a>03208   ChiasmusKeySelector selectorDlg( parentWidget(), i18n( <span class="stringliteral">"Chiasmus Decryption Key Selection"</span> ),
<a name="l03209"></a>03209                                    keys, GlobalSettings::chiasmusDecryptionKey(),
<a name="l03210"></a>03210                                    GlobalSettings::chiasmusDecryptionOptions() );
<a name="l03211"></a>03211   <span class="keywordflow">if</span> ( selectorDlg.exec() != QDialog::Accepted )
<a name="l03212"></a>03212     <span class="keywordflow">return</span>;
<a name="l03213"></a>03213 
<a name="l03214"></a>03214   GlobalSettings::setChiasmusDecryptionOptions( selectorDlg.options() );
<a name="l03215"></a>03215   GlobalSettings::setChiasmusDecryptionKey( selectorDlg.key() );
<a name="l03216"></a>03216   assert( !GlobalSettings::chiasmusDecryptionKey().isEmpty() );
<a name="l03217"></a>03217 
<a name="l03218"></a>03218   Kleo::SpecialJob * job = chiasmus-&gt;specialJob( <span class="stringliteral">"x-decrypt"</span>, QMap&lt;QString,QVariant&gt;() );
<a name="l03219"></a>03219   <span class="keywordflow">if</span> ( !job ) {
<a name="l03220"></a>03220     <span class="keyword">const</span> QString msg = i18n( <span class="stringliteral">"Chiasmus backend does not offer the "</span>
<a name="l03221"></a>03221                               <span class="stringliteral">"\"x-decrypt\" function. Please report this bug."</span> );
<a name="l03222"></a>03222     KMessageBox::error( parentWidget(), msg, i18n( <span class="stringliteral">"Chiasmus Backend Error"</span> ) );
<a name="l03223"></a>03223     <span class="keywordflow">return</span>;
<a name="l03224"></a>03224   }
<a name="l03225"></a>03225 
<a name="l03226"></a>03226   <span class="keyword">const</span> QByteArray input = node-&gt;msgPart().bodyDecodedBinary();
<a name="l03227"></a>03227 
<a name="l03228"></a>03228   <span class="keywordflow">if</span> ( !job-&gt;setProperty( <span class="stringliteral">"key"</span>, GlobalSettings::chiasmusDecryptionKey() ) ||
<a name="l03229"></a>03229        !job-&gt;setProperty( <span class="stringliteral">"options"</span>, GlobalSettings::chiasmusDecryptionOptions() ) ||
<a name="l03230"></a>03230        !job-&gt;setProperty( <span class="stringliteral">"input"</span>, input ) ) {
<a name="l03231"></a>03231     <span class="keyword">const</span> QString msg = i18n( <span class="stringliteral">"The \"x-decrypt\" function does not accept "</span>
<a name="l03232"></a>03232                               <span class="stringliteral">"the expected parameters. Please report this bug."</span> );
<a name="l03233"></a>03233     KMessageBox::error( parentWidget(), msg, i18n( <span class="stringliteral">"Chiasmus Backend Error"</span> ) );
<a name="l03234"></a>03234     <span class="keywordflow">return</span>;
<a name="l03235"></a>03235   }
<a name="l03236"></a>03236 
<a name="l03237"></a>03237   setDeletesItself( <span class="keyword">true</span> ); <span class="comment">// the job below is async, we have to cleanup ourselves</span>
<a name="l03238"></a>03238   <span class="keywordflow">if</span> ( job-&gt;start() ) {
<a name="l03239"></a>03239     job-&gt;showErrorDialog( parentWidget(), i18n( <span class="stringliteral">"Chiasmus Decryption Error"</span> ) );
<a name="l03240"></a>03240     <span class="keywordflow">return</span>;
<a name="l03241"></a>03241   }
<a name="l03242"></a>03242 
<a name="l03243"></a>03243   mJob = job;
<a name="l03244"></a>03244   connect( job, SIGNAL(result(<span class="keyword">const</span> GpgME::Error&amp;,<span class="keyword">const</span> QVariant&amp;)),
<a name="l03245"></a>03245            <span class="keyword">this</span>, SLOT(slotAtmDecryptWithChiasmusResult(<span class="keyword">const</span> GpgME::Error&amp;,<span class="keyword">const</span> QVariant&amp;)) );
<a name="l03246"></a>03246 }
<a name="l03247"></a>03247 
<a name="l03248"></a>03248 <span class="keyword">static</span> <span class="keyword">const</span> QString chomp( <span class="keyword">const</span> QString &amp; base, <span class="keyword">const</span> QString &amp; suffix, <span class="keywordtype">bool</span> cs ) {
<a name="l03249"></a>03249   <span class="keywordflow">return</span> base.endsWith( suffix, cs ) ? base.left( base.length() - suffix.length() ) : base ;
<a name="l03250"></a>03250 }
<a name="l03251"></a>03251 
<a name="l03252"></a>03252 <span class="keywordtype">void</span> KMHandleAttachmentCommand::slotAtmDecryptWithChiasmusResult( <span class="keyword">const</span> GpgME::Error &amp; err, <span class="keyword">const</span> QVariant &amp; result )
<a name="l03253"></a>03253 {
<a name="l03254"></a>03254   LaterDeleterWithCommandCompletion d( <span class="keyword">this</span> );
<a name="l03255"></a>03255   <span class="keywordflow">if</span> ( !mJob )
<a name="l03256"></a>03256     <span class="keywordflow">return</span>;
<a name="l03257"></a>03257   Q_ASSERT( mJob == sender() );
<a name="l03258"></a>03258   <span class="keywordflow">if</span> ( mJob != sender() )
<a name="l03259"></a>03259     <span class="keywordflow">return</span>;
<a name="l03260"></a>03260   Kleo::Job * job = mJob;
<a name="l03261"></a>03261   mJob = 0;
<a name="l03262"></a>03262   <span class="keywordflow">if</span> ( err.isCanceled() )
<a name="l03263"></a>03263     <span class="keywordflow">return</span>;
<a name="l03264"></a>03264   <span class="keywordflow">if</span> ( err ) {
<a name="l03265"></a>03265     job-&gt;showErrorDialog( parentWidget(), i18n( <span class="stringliteral">"Chiasmus Decryption Error"</span> ) );
<a name="l03266"></a>03266     <span class="keywordflow">return</span>;
<a name="l03267"></a>03267   }
<a name="l03268"></a>03268 
<a name="l03269"></a>03269   <span class="keywordflow">if</span> ( result.type() != QVariant::ByteArray ) {
<a name="l03270"></a>03270     <span class="keyword">const</span> QString msg = i18n( <span class="stringliteral">"Unexpected return value from Chiasmus backend: "</span>
<a name="l03271"></a>03271                               <span class="stringliteral">"The \"x-decrypt\" function did not return a "</span>
<a name="l03272"></a>03272                               <span class="stringliteral">"byte array. Please report this bug."</span> );
<a name="l03273"></a>03273     KMessageBox::error( parentWidget(), msg, i18n( <span class="stringliteral">"Chiasmus Backend Error"</span> ) );
<a name="l03274"></a>03274     <span class="keywordflow">return</span>;
<a name="l03275"></a>03275   }
<a name="l03276"></a>03276 
<a name="l03277"></a>03277   <span class="keyword">const</span> KURL url = KFileDialog::getSaveURL( chomp( mAtmName, <span class="stringliteral">".xia"</span>, <span class="keyword">false</span> ), QString::null, parentWidget() );
<a name="l03278"></a>03278   <span class="keywordflow">if</span> ( url.isEmpty() )
<a name="l03279"></a>03279     <span class="keywordflow">return</span>;
<a name="l03280"></a>03280 
<a name="l03281"></a>03281   <span class="keywordtype">bool</span> overwrite = KMail::Util::checkOverwrite( url, parentWidget() );
<a name="l03282"></a>03282   <span class="keywordflow">if</span> ( !overwrite )
<a name="l03283"></a>03283     <span class="keywordflow">return</span>;
<a name="l03284"></a>03284 
<a name="l03285"></a>03285   d.setDisabled( <span class="keyword">true</span> ); <span class="comment">// we got this far, don't delete yet</span>
<a name="l03286"></a>03286   KIO::Job * uploadJob = KIO::storedPut( result.toByteArray(), url, -1, overwrite, <span class="keyword">false</span> <span class="comment">/*resume*/</span> );
<a name="l03287"></a>03287   uploadJob-&gt;setWindow( parentWidget() );
<a name="l03288"></a>03288   connect( uploadJob, SIGNAL(result(KIO::Job*)),
<a name="l03289"></a>03289            <span class="keyword">this</span>, SLOT(slotAtmDecryptWithChiasmusUploadResult(KIO::Job*)) );
<a name="l03290"></a>03290 }
<a name="l03291"></a>03291 
<a name="l03292"></a>03292 <span class="keywordtype">void</span> KMHandleAttachmentCommand::slotAtmDecryptWithChiasmusUploadResult( KIO::Job * job )
<a name="l03293"></a>03293 {
<a name="l03294"></a>03294   <span class="keywordflow">if</span> ( job-&gt;error() )
<a name="l03295"></a>03295     job-&gt;showErrorDialog();
<a name="l03296"></a>03296   LaterDeleterWithCommandCompletion d( <span class="keyword">this</span> );
<a name="l03297"></a>03297   d.setResult( OK );
<a name="l03298"></a>03298 }
<a name="l03299"></a>03299 
<a name="l03300"></a>03300 
<a name="l03301"></a>03301 AttachmentModifyCommand::AttachmentModifyCommand(partNode * node, <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> * msg, QWidget * parent) :
<a name="l03302"></a>03302     KMCommand( parent, msg ),
<a name="l03303"></a>03303     mPartIndex( node-&gt;nodeId() ),
<a name="l03304"></a>03304     mSernum( 0 )
<a name="l03305"></a>03305 {
<a name="l03306"></a>03306 }
<a name="l03307"></a>03307 
<a name="l03308"></a>03308 AttachmentModifyCommand::~ AttachmentModifyCommand()
<a name="l03309"></a>03309 {
<a name="l03310"></a>03310 }
<a name="l03311"></a>03311 
<a name="l03312"></a>03312 KMCommand::Result AttachmentModifyCommand::execute()
<a name="l03313"></a>03313 {
<a name="l03314"></a>03314   <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> *msg = retrievedMessage();
<a name="l03315"></a>03315   <span class="keywordflow">if</span> ( !msg )
<a name="l03316"></a>03316     <span class="keywordflow">return</span> Failed;
<a name="l03317"></a>03317   mSernum = msg-&gt;getMsgSerNum();
<a name="l03318"></a>03318 
<a name="l03319"></a>03319   mFolder = msg-&gt;parent();
<a name="l03320"></a>03320   <span class="keywordflow">if</span> ( !mFolder || !mFolder-&gt;storage() )
<a name="l03321"></a>03321     <span class="keywordflow">return</span> Failed;
<a name="l03322"></a>03322 
<a name="l03323"></a>03323   Result res = doAttachmentModify();
<a name="l03324"></a>03324   <span class="keywordflow">if</span> ( res != OK )
<a name="l03325"></a>03325     <span class="keywordflow">return</span> res;
<a name="l03326"></a>03326 
<a name="l03327"></a>03327   setEmitsCompletedItself( <span class="keyword">true</span> );
<a name="l03328"></a>03328   setDeletesItself( <span class="keyword">true</span> );
<a name="l03329"></a>03329   <span class="keywordflow">return</span> OK;
<a name="l03330"></a>03330 }
<a name="l03331"></a>03331 
<a name="l03332"></a>03332 <span class="keywordtype">void</span> AttachmentModifyCommand::storeChangedMessage(<a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> * msg)
<a name="l03333"></a>03333 {
<a name="l03334"></a>03334   <span class="keywordflow">if</span> ( !mFolder || !mFolder-&gt;storage() ) {
<a name="l03335"></a>03335     kdWarning(5006) &lt;&lt; k_funcinfo &lt;&lt; <span class="stringliteral">"We lost the folder!"</span> &lt;&lt; endl;
<a name="l03336"></a>03336     setResult( Failed );
<a name="l03337"></a>03337     emit completed( <span class="keyword">this</span> );
<a name="l03338"></a>03338     deleteLater();
<a name="l03339"></a>03339   }
<a name="l03340"></a>03340   <span class="keywordtype">int</span> res = mFolder-&gt;addMsg( msg ) != 0;
<a name="l03341"></a>03341   <span class="keywordflow">if</span> ( mFolder-&gt;folderType() == KMFolderTypeImap ) {
<a name="l03342"></a>03342     KMFolderImap *f = <span class="keyword">static_cast&lt;</span>KMFolderImap*<span class="keyword">&gt;</span>( mFolder-&gt;storage() );
<a name="l03343"></a>03343     connect( f, SIGNAL(folderComplete(KMFolderImap*,<span class="keywordtype">bool</span>)),
<a name="l03344"></a>03344              SLOT(messageStoreResult(KMFolderImap*,<span class="keywordtype">bool</span>)) );
<a name="l03345"></a>03345   } <span class="keywordflow">else</span> {
<a name="l03346"></a>03346     messageStoreResult( 0, res == 0 );
<a name="l03347"></a>03347   }
<a name="l03348"></a>03348 }
<a name="l03349"></a>03349 
<a name="l03350"></a>03350 <span class="keywordtype">void</span> AttachmentModifyCommand::messageStoreResult(KMFolderImap* folder, <span class="keywordtype">bool</span> success )
<a name="l03351"></a>03351 {
<a name="l03352"></a>03352   Q_UNUSED( folder );
<a name="l03353"></a>03353   <span class="keywordflow">if</span> ( success ) {
<a name="l03354"></a>03354     KMCommand *delCmd = <span class="keyword">new</span> KMDeleteMsgCommand( mSernum );
<a name="l03355"></a>03355     connect( delCmd, SIGNAL(completed(KMCommand*)), SLOT(messageDeleteResult(KMCommand*)) );
<a name="l03356"></a>03356     delCmd-&gt;start();
<a name="l03357"></a>03357     <span class="keywordflow">return</span>;
<a name="l03358"></a>03358   }
<a name="l03359"></a>03359   kdWarning(5006) &lt;&lt; k_funcinfo &lt;&lt; <span class="stringliteral">"Adding modified message failed."</span> &lt;&lt; endl;
<a name="l03360"></a>03360   setResult( Failed );
<a name="l03361"></a>03361   emit completed( <span class="keyword">this</span> );
<a name="l03362"></a>03362   deleteLater();
<a name="l03363"></a>03363 }
<a name="l03364"></a>03364 
<a name="l03365"></a>03365 <span class="keywordtype">void</span> AttachmentModifyCommand::messageDeleteResult(KMCommand * cmd)
<a name="l03366"></a>03366 {
<a name="l03367"></a>03367   setResult( cmd-&gt;result() );
<a name="l03368"></a>03368   emit completed( <span class="keyword">this</span> );
<a name="l03369"></a>03369   deleteLater();
<a name="l03370"></a>03370 }
<a name="l03371"></a>03371 
<a name="l03372"></a>03372 
<a name="l03373"></a>03373 KMDeleteAttachmentCommand::KMDeleteAttachmentCommand(partNode * node, <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> * msg, QWidget * parent) :
<a name="l03374"></a>03374     <a class="code" href="classAttachmentModifyCommand.html" title="Base class for commands modifying attachements of existing messages.">AttachmentModifyCommand</a>( node, msg, parent )
<a name="l03375"></a>03375 {
<a name="l03376"></a>03376   kdDebug(5006) &lt;&lt; k_funcinfo &lt;&lt; endl;
<a name="l03377"></a>03377 }
<a name="l03378"></a>03378 
<a name="l03379"></a>03379 KMDeleteAttachmentCommand::~KMDeleteAttachmentCommand()
<a name="l03380"></a>03380 {
<a name="l03381"></a>03381   kdDebug(5006) &lt;&lt; k_funcinfo &lt;&lt; endl;
<a name="l03382"></a>03382 }
<a name="l03383"></a>03383 
<a name="l03384"></a>03384 KMCommand::Result KMDeleteAttachmentCommand::doAttachmentModify()
<a name="l03385"></a>03385 {
<a name="l03386"></a>03386   <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> *msg = retrievedMessage();
<a name="l03387"></a>03387   KMMessagePart part;
<a name="l03388"></a>03388   <span class="comment">// -2 because partNode counts root and body of the message as well</span>
<a name="l03389"></a>03389   DwBodyPart *dwpart = msg-&gt;<a class="code" href="classKMMessage.html#d29d08c00132080dd384caa3861a872f" title="Get the DwBodyPart at position in aIdx.">dwBodyPart</a>( mPartIndex - 2 );
<a name="l03390"></a>03390   <span class="keywordflow">if</span> ( !dwpart )
<a name="l03391"></a>03391     <span class="keywordflow">return</span> Failed;
<a name="l03392"></a>03392   <a class="code" href="classKMMessage.html#2b942616accf9ac39e19351ce2bba17d" title="Fill the KMMessagePart structure for a given DwBodyPart.">KMMessage::bodyPart</a>( dwpart, &amp;part, <span class="keyword">true</span> );
<a name="l03393"></a>03393   <span class="keywordflow">if</span> ( !part.isComplete() )
<a name="l03394"></a>03394      <span class="keywordflow">return</span> Failed;
<a name="l03395"></a>03395   msg-&gt;<a class="code" href="classKMMessage.html#1858f691f77ad3420ae34e575b9ef2e5" title="Removes the given body part.">removeBodyPart</a>( dwpart );
<a name="l03396"></a>03396 
<a name="l03397"></a>03397   <span class="comment">// add dummy part to show that a attachment has been deleted</span>
<a name="l03398"></a>03398   KMMessagePart dummyPart;
<a name="l03399"></a>03399   dummyPart.duplicate( part );
<a name="l03400"></a>03400   QString comment = i18n(<span class="stringliteral">"This attachment has been deleted."</span>);
<a name="l03401"></a>03401   <span class="keywordflow">if</span> ( !part.fileName().isEmpty() )
<a name="l03402"></a>03402     comment = i18n( <span class="stringliteral">"The attachment '%1' has been deleted."</span> ).arg( part.fileName() );
<a name="l03403"></a>03403   dummyPart.setContentDescription( comment );
<a name="l03404"></a>03404   dummyPart.setBodyEncodedBinary( QByteArray() );
<a name="l03405"></a>03405   QCString cd = dummyPart.contentDisposition();
<a name="l03406"></a>03406   <span class="keywordflow">if</span> ( cd.find( <span class="stringliteral">"inline"</span>, 0, <span class="keyword">false</span> ) == 0 ) {
<a name="l03407"></a>03407     cd.replace( 0, 10, <span class="stringliteral">"attachment"</span> );
<a name="l03408"></a>03408     dummyPart.setContentDisposition( cd );
<a name="l03409"></a>03409   } <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( cd.isEmpty() ) {
<a name="l03410"></a>03410     dummyPart.setContentDisposition( <span class="stringliteral">"attachment"</span> );
<a name="l03411"></a>03411   }
<a name="l03412"></a>03412   msg-&gt;<a class="code" href="classKMMessage.html#98f53dd0092cd4b6a8a07efef0526217" title="Append a body part to the message.">addBodyPart</a>( &amp;dummyPart );
<a name="l03413"></a>03413 
<a name="l03414"></a>03414   <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> *newMsg = <span class="keyword">new</span> <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a>();
<a name="l03415"></a>03415   newMsg-&gt;<a class="code" href="classKMMessage.html#765ec32909b2bfde6a205c1b76431381" title="Parse the string and create this message from it.">fromDwString</a>( msg-&gt;<a class="code" href="classKMMessage.html#49c5b4223492f2d81dcc97bb9462f728" title="Return the entire message contents in the DwString.">asDwString</a>() );
<a name="l03416"></a>03416   newMsg-&gt;<a class="code" href="classKMMessage.html#508dba38dc91893691edddaab30e274d" title="Set status and mark dirty.">setStatus</a>( msg-&gt;<a class="code" href="classKMMessage.html#c54ef69572e620a3dcc0301aefca913e" title="Status of the message.">status</a>() );
<a name="l03417"></a>03417 
<a name="l03418"></a>03418   storeChangedMessage( newMsg );
<a name="l03419"></a>03419   <span class="keywordflow">return</span> OK;
<a name="l03420"></a>03420 }
<a name="l03421"></a>03421 
<a name="l03422"></a>03422 
<a name="l03423"></a>03423 KMEditAttachmentCommand::KMEditAttachmentCommand(partNode * node, <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> * msg, QWidget * parent) :
<a name="l03424"></a>03424     <a class="code" href="classAttachmentModifyCommand.html" title="Base class for commands modifying attachements of existing messages.">AttachmentModifyCommand</a>( node, msg, parent )
<a name="l03425"></a>03425 {
<a name="l03426"></a>03426   kdDebug(5006) &lt;&lt; k_funcinfo &lt;&lt; endl;
<a name="l03427"></a>03427   mTempFile.setAutoDelete( <span class="keyword">true</span> );
<a name="l03428"></a>03428 }
<a name="l03429"></a>03429 
<a name="l03430"></a>03430 KMEditAttachmentCommand::~ KMEditAttachmentCommand()
<a name="l03431"></a>03431 {
<a name="l03432"></a>03432 }
<a name="l03433"></a>03433 
<a name="l03434"></a>03434 KMCommand::Result KMEditAttachmentCommand::doAttachmentModify()
<a name="l03435"></a>03435 {
<a name="l03436"></a>03436   <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> *msg = retrievedMessage();
<a name="l03437"></a>03437   KMMessagePart part;
<a name="l03438"></a>03438   <span class="comment">// -2 because partNode counts root and body of the message as well</span>
<a name="l03439"></a>03439   DwBodyPart *dwpart = msg-&gt;<a class="code" href="classKMMessage.html#d29d08c00132080dd384caa3861a872f" title="Get the DwBodyPart at position in aIdx.">dwBodyPart</a>( mPartIndex - 2 );
<a name="l03440"></a>03440   <span class="keywordflow">if</span> ( !dwpart )
<a name="l03441"></a>03441     <span class="keywordflow">return</span> Failed;
<a name="l03442"></a>03442   <a class="code" href="classKMMessage.html#2b942616accf9ac39e19351ce2bba17d" title="Fill the KMMessagePart structure for a given DwBodyPart.">KMMessage::bodyPart</a>( dwpart, &amp;part, <span class="keyword">true</span> );
<a name="l03443"></a>03443   <span class="keywordflow">if</span> ( !part.isComplete() )
<a name="l03444"></a>03444      <span class="keywordflow">return</span> Failed;
<a name="l03445"></a>03445 
<a name="l03446"></a>03446   mTempFile.file()-&gt;writeBlock( part.bodyDecodedBinary() );
<a name="l03447"></a>03447   mTempFile.file()-&gt;flush();
<a name="l03448"></a>03448 
<a name="l03449"></a>03449   <a class="code" href="classKMail_1_1EditorWatcher.html" title="Starts an editor for the given URL and emits an signal when editing has been finished...">KMail::EditorWatcher</a> *watcher = <span class="keyword">new</span> <a class="code" href="classKMail_1_1EditorWatcher.html" title="Starts an editor for the given URL and emits an signal when editing has been finished...">KMail::EditorWatcher</a>( KURL(mTempFile.file()-&gt;name()), part.typeStr() + <span class="stringliteral">"/"</span> + part.subtypeStr(), <span class="keyword">false</span>, this );
<a name="l03450"></a>03450   connect( watcher, SIGNAL(editDone(<a class="code" href="classKMail_1_1EditorWatcher.html" title="Starts an editor for the given URL and emits an signal when editing has been finished...">KMail::EditorWatcher</a>*)), SLOT(editDone(<a class="code" href="classKMail_1_1EditorWatcher.html" title="Starts an editor for the given URL and emits an signal when editing has been finished...">KMail::EditorWatcher</a>*)) );
<a name="l03451"></a>03451   <span class="keywordflow">if</span> ( !watcher-&gt;<a class="code" href="classKMail_1_1EditorWatcher.html#ffed2d5fc76aead29f193f38cd4954f2">start</a>() )
<a name="l03452"></a>03452     <span class="keywordflow">return</span> Failed;
<a name="l03453"></a>03453   setEmitsCompletedItself( <span class="keyword">true</span> );
<a name="l03454"></a>03454   setDeletesItself( <span class="keyword">true</span> );
<a name="l03455"></a>03455   <span class="keywordflow">return</span> OK;
<a name="l03456"></a>03456 }
<a name="l03457"></a>03457 
<a name="l03458"></a>03458 <span class="keywordtype">void</span> KMEditAttachmentCommand::editDone(<a class="code" href="classKMail_1_1EditorWatcher.html" title="Starts an editor for the given URL and emits an signal when editing has been finished...">KMail::EditorWatcher</a> * watcher)
<a name="l03459"></a>03459 {
<a name="l03460"></a>03460   kdDebug(5006) &lt;&lt; k_funcinfo &lt;&lt; endl;
<a name="l03461"></a>03461   <span class="comment">// anything changed?</span>
<a name="l03462"></a>03462   <span class="keywordflow">if</span> ( !watcher-&gt;<a class="code" href="classKMail_1_1EditorWatcher.html#d76ce47a11792f0dd976d79c6b1f4962">fileChanged</a>() ) {
<a name="l03463"></a>03463     kdDebug(5006) &lt;&lt; k_funcinfo &lt;&lt; <span class="stringliteral">"File has not been changed"</span> &lt;&lt; endl;
<a name="l03464"></a>03464     setResult( Canceled );
<a name="l03465"></a>03465     emit completed( <span class="keyword">this</span> );
<a name="l03466"></a>03466     deleteLater();
<a name="l03467"></a>03467   }
<a name="l03468"></a>03468 
<a name="l03469"></a>03469   mTempFile.file()-&gt;reset();
<a name="l03470"></a>03470   QByteArray data = mTempFile.file()-&gt;readAll();
<a name="l03471"></a>03471 
<a name="l03472"></a>03472   <span class="comment">// build the new message</span>
<a name="l03473"></a>03473   <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> *msg = retrievedMessage();
<a name="l03474"></a>03474   KMMessagePart part;
<a name="l03475"></a>03475   <span class="comment">// -2 because partNode counts root and body of the message as well</span>
<a name="l03476"></a>03476   DwBodyPart *dwpart = msg-&gt;<a class="code" href="classKMMessage.html#d29d08c00132080dd384caa3861a872f" title="Get the DwBodyPart at position in aIdx.">dwBodyPart</a>( mPartIndex - 2 );
<a name="l03477"></a>03477   <a class="code" href="classKMMessage.html#2b942616accf9ac39e19351ce2bba17d" title="Fill the KMMessagePart structure for a given DwBodyPart.">KMMessage::bodyPart</a>( dwpart, &amp;part, <span class="keyword">true</span> );
<a name="l03478"></a>03478   msg-&gt;<a class="code" href="classKMMessage.html#1858f691f77ad3420ae34e575b9ef2e5" title="Removes the given body part.">removeBodyPart</a>( dwpart );
<a name="l03479"></a>03479 
<a name="l03480"></a>03480   KMMessagePart att;
<a name="l03481"></a>03481   att.duplicate( part );
<a name="l03482"></a>03482   att.setBodyEncodedBinary( data );
<a name="l03483"></a>03483   msg-&gt;<a class="code" href="classKMMessage.html#98f53dd0092cd4b6a8a07efef0526217" title="Append a body part to the message.">addBodyPart</a>( &amp;att );
<a name="l03484"></a>03484 
<a name="l03485"></a>03485   <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> *newMsg = <span class="keyword">new</span> <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a>();
<a name="l03486"></a>03486   newMsg-&gt;<a class="code" href="classKMMessage.html#765ec32909b2bfde6a205c1b76431381" title="Parse the string and create this message from it.">fromDwString</a>( msg-&gt;<a class="code" href="classKMMessage.html#49c5b4223492f2d81dcc97bb9462f728" title="Return the entire message contents in the DwString.">asDwString</a>() );
<a name="l03487"></a>03487   newMsg-&gt;<a class="code" href="classKMMessage.html#508dba38dc91893691edddaab30e274d" title="Set status and mark dirty.">setStatus</a>( msg-&gt;<a class="code" href="classKMMessage.html#c54ef69572e620a3dcc0301aefca913e" title="Status of the message.">status</a>() );
<a name="l03488"></a>03488 
<a name="l03489"></a>03489   storeChangedMessage( newMsg );
<a name="l03490"></a>03490 }
<a name="l03491"></a>03491 
<a name="l03492"></a>03492 
<a name="l03493"></a>03493 CreateTodoCommand::CreateTodoCommand(QWidget * parent, <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> * msg)
<a name="l03494"></a>03494   : KMCommand( parent, msg )
<a name="l03495"></a>03495 {
<a name="l03496"></a>03496 }
<a name="l03497"></a>03497 
<a name="l03498"></a>03498 KMCommand::Result CreateTodoCommand::execute()
<a name="l03499"></a>03499 {
<a name="l03500"></a>03500   <a class="code" href="classKMMessage.html" title="This is a Mime Message.">KMMessage</a> *msg = retrievedMessage();
<a name="l03501"></a>03501   <span class="keywordflow">if</span> ( !msg || !msg-&gt;<a class="code" href="classKMMessage.html#91762b3880f42da72185c59c40b28cac" title="Get a QTextCodec suitable for this message part.">codec</a>() ) {
<a name="l03502"></a>03502     <span class="keywordflow">return</span> Failed;
<a name="l03503"></a>03503   }
<a name="l03504"></a>03504 
<a name="l03505"></a>03505   KMail::KorgHelper::ensureRunning();
<a name="l03506"></a>03506 
<a name="l03507"></a>03507   QString txt = i18n(<span class="stringliteral">"From: %1\nTo: %2\nSubject: %3"</span>).arg( msg-&gt;<a class="code" href="classKMMessage.html#8c90e62a192cb4a42b53458d82697cbe" title="Get or set the &amp;#39;From&amp;#39; header field.">from</a>() )
<a name="l03508"></a>03508                 .arg( msg-&gt;<a class="code" href="classKMMessage.html#87af921446ba2e30316d6207d9394a2b" title="Get or set the &amp;#39;To&amp;#39; header field.">to</a>() ).arg( msg-&gt;<a class="code" href="classKMMessage.html#8f39a479d6704ce51bcdb1de1fc28bda" title="Get or set the &amp;#39;Subject&amp;#39; header field.">subject</a>() );
<a name="l03509"></a>03509 
<a name="l03510"></a>03510   KTempFile tf;
<a name="l03511"></a>03511   tf.setAutoDelete( <span class="keyword">true</span> );
<a name="l03512"></a>03512   QString uri = <span class="stringliteral">"kmail:"</span> + QString::number( msg-&gt;getMsgSerNum() ) + <span class="stringliteral">"/"</span> + msg-&gt;<a class="code" href="classKMMessage.html#ec7262aeb49504396dfaa65fa4be94a1" title="Get or set the &amp;#39;Message-Id&amp;#39; header field.">msgId</a>();
<a name="l03513"></a>03513   tf.file()-&gt;writeBlock( msg-&gt;<a class="code" href="classKMMessage.html#49c5b4223492f2d81dcc97bb9462f728" title="Return the entire message contents in the DwString.">asDwString</a>().c_str(), msg-&gt;<a class="code" href="classKMMessage.html#49c5b4223492f2d81dcc97bb9462f728" title="Return the entire message contents in the DwString.">asDwString</a>().length() );
<a name="l03514"></a>03514   tf.close();
<a name="l03515"></a>03515 
<a name="l03516"></a>03516   KCalendarIface_stub *iface = <span class="keyword">new</span> KCalendarIface_stub( kapp-&gt;dcopClient(), <span class="stringliteral">"korganizer"</span>, <span class="stringliteral">"CalendarIface"</span> );
<a name="l03517"></a>03517   iface-&gt;openTodoEditor( i18n(<span class="stringliteral">"Mail: %1"</span>).arg( msg-&gt;<a class="code" href="classKMMessage.html#8f39a479d6704ce51bcdb1de1fc28bda" title="Get or set the &amp;#39;Subject&amp;#39; header field.">subject</a>() ), txt,
<a name="l03518"></a>03518                          uri, tf.name(), QStringList(), <span class="stringliteral">"message/rfc822"</span> );
<a name="l03519"></a>03519   <span class="keyword">delete</span> iface;
<a name="l03520"></a>03520 
<a name="l03521"></a>03521   <span class="keywordflow">return</span> OK;
<a name="l03522"></a>03522 }
<a name="l03523"></a>03523 
<a name="l03524"></a>03524 <span class="preprocessor">#include "kmcommands.moc"</span>
</pre></div></div>
    </div></div>


      </td>
  </tr>
  <tr>
    <td valign="top" id="leftmenu" width="25%">
      <a name="navigation"></a>
      <div class="menu_box"><h2>kmail</h2>
<div class="nav_list">
<ul><li><a href="index.html">Main Page</a></li><li><a href="namespaces.html">Namespace List</a></li><li><a href="hierarchy.html">Class Hierarchy</a></li><li><a href="classes.html">Alphabetical List</a></li><li><a href="annotated.html">Class List</a></li><li><a href="files.html">File List</a></li><li><a href="namespacemembers.html">Namespace Members</a></li><li><a href="functions.html">Class Members</a></li><li><a href="pages.html">Related Pages</a></li></ul>
<!--
<h2>Class Picker</h2>
<div style="text-align: center;">
<form name="guideform">
<select name="guidelinks" style="width:100%;" onChange="window.location=document.guideform.guidelinks.options[document.guideform.guidelinks.selectedIndex].value">
<option value="annotated.html">-- Choose --</option>
  <option value="classAccountUpdater.html">accountupdater</option>,  <option value="classAttachmentModifyCommand.html">attachmentmodifycommand</option>,  <option value="classFolderStorage.html">folderstorage</option>,  <option value="classKCursorSaver.html">kcursorsaver</option>,  <option value="classKleo_1_1KeyResolver.html">kleo::keyresolver</option>,  <option value="classKListViewIndexedSearchLine.html">klistviewindexedsearchline</option>,  <option value="classKMAcctFolder.html">kmacctfolder</option>,  <option value="classKMAcctSelDlg.html">kmacctseldlg</option>,  <option value="classKMail_1_1AccountComboBox.html">kmail::accountcombobox</option>,  <option value="classKMail_1_1AccountManager.html">kmail::accountmanager</option>,  <option value="classKMail_1_1ACLEntryDialog.html">kmail::aclentrydialog</option>,  <option value="classKMail_1_1ACLJobs_1_1DeleteACLJob.html">kmail::acljobs::deleteacljob</option>,  <option value="classKMail_1_1ACLJobs_1_1GetACLJob.html">kmail::acljobs::getacljob</option>,  <option value="classKMail_1_1ACLJobs_1_1GetUserRightsJob.html">kmail::acljobs::getuserrightsjob</option>,  <option value="classKMail_1_1ACLJobs_1_1MultiSetACLJob.html">kmail::acljobs::multisetacljob</option>,  <option value="classKMail_1_1AnnotationJobs_1_1GetAnnotationJob.html">kmail::annotationjobs::getannotationjob</option>,  <option value="classKMail_1_1AnnotationJobs_1_1MultiGetAnnotationJob.html">kmail::annotationjobs::multigetannotationjob</option>,  <option value="classKMail_1_1AnnotationJobs_1_1MultiSetAnnotationJob.html">kmail::annotationjobs::multisetannotationjob</option>,  <option value="classKMail_1_1AnnotationJobs_1_1MultiUrlGetAnnotationJob.html">kmail::annotationjobs::multiurlgetannotationjob</option>,  <option value="classKMail_1_1AntiSpamConfig.html">kmail::antispamconfig</option>,  <option value="classKMail_1_1AntiSpamWizard.html">kmail::antispamwizard</option>,  <option value="classKMail_1_1AntiSpamWizard_1_1ConfigReader.html">kmail::antispamwizard::configreader</option>,  <option value="classKMail_1_1AntiSpamWizard_1_1SpamToolConfig.html">kmail::antispamwizard::spamtoolconfig</option>,  <option value="classKMail_1_1Callback.html">kmail::callback</option>,  <option value="classKMail_1_1CopyFolderJob.html">kmail::copyfolderjob</option>,  <option value="classKMail_1_1DictionaryComboBox.html">kmail::dictionarycombobox</option>,  <option value="classKMail_1_1EditorWatcher.html">kmail::editorwatcher</option>,  <option value="classKMail_1_1FilterImporterExporter.html">kmail::filterimporterexporter</option>,  <option value="classKMail_1_1FilterLog.html">kmail::filterlog</option>,  <option value="classKMail_1_1FilterLogDialog.html">kmail::filterlogdialog</option>,  <option value="classKMail_1_1FolderDiaACLTab.html">kmail::folderdiaacltab</option>,  <option value="classKMail_1_1FolderDiaGeneralTab.html">kmail::folderdiageneraltab</option>,  <option value="classKMail_1_1FolderDiaQuotaTab.html">kmail::folderdiaquotatab</option>,  <option value="classKMail_1_1FolderDiaTab.html">kmail::folderdiatab</option>,  <option value="classKMail_1_1FolderDiaTemplatesTab.html">kmail::folderdiatemplatestab</option>,  <option value="classKMail_1_1FolderRequester.html">kmail::folderrequester</option>,  <option value="classKMail_1_1HeaderItem.html">kmail::headeritem</option>,  <option value="classKMail_1_1HeaderStyle.html">kmail::headerstyle</option>,  <option value="classKMail_1_1HtmlStatusBar.html">kmail::htmlstatusbar</option>,  <option value="classKMail_1_1HtmlWriter.html">kmail::htmlwriter</option>,  <option value="classKMail_1_1IdentityDrag.html">kmail::identitydrag</option>,  <option value="classKMail_1_1IdentityListView.html">kmail::identitylistview</option>,  <option value="classKMail_1_1IdentityListViewItem.html">kmail::identitylistviewitem</option>,  <option value="classKMail_1_1Interface_1_1BodyPart.html">kmail::interface::bodypart</option>,  <option value="classKMail_1_1Interface_1_1BodyPartFormatterPlugin.html">kmail::interface::bodypartformatterplugin</option>,  <option value="classKMail_1_1Interface_1_1BodyPartMemento.html">kmail::interface::bodypartmemento</option>,  <option value="classKMail_1_1Interface_1_1BodyPartURLHandler.html">kmail::interface::bodyparturlhandler</option>,  <option value="classKMail_1_1Interface_1_1Observable.html">kmail::interface::observable</option>,  <option value="classKMail_1_1Interface_1_1Observer.html">kmail::interface::observer</option>,  <option value="classKMail_1_1JobScheduler.html">kmail::jobscheduler</option>,  <option value="classKMail_1_1ListJob.html">kmail::listjob</option>,  <option value="classKMail_1_1MaildirCompactionJob.html">kmail::maildircompactionjob</option>,  <option value="classKMail_1_1MailingList.html">kmail::mailinglist</option>,  <option value="classKMail_1_1MboxCompactionJob.html">kmail::mboxcompactionjob</option>,  <option value="classKMail_1_1MessageActions.html">kmail::messageactions</option>,  <option value="classKMail_1_1MessageCopyHelper.html">kmail::messagecopyhelper</option>,  <option value="classKMail_1_1PartNodeBodyPart.html">kmail::partnodebodypart</option>,  <option value="classKMail_1_1PopAccount.html">kmail::popaccount</option>,  <option value="classKMail_1_1QuotaJobs_1_1GetQuotarootJob.html">kmail::quotajobs::getquotarootjob</option>,  <option value="classKMail_1_1QuotaJobs_1_1GetStorageQuotaJob.html">kmail::quotajobs::getstoragequotajob</option>,  <option value="classKMail_1_1RedirectDialog.html">kmail::redirectdialog</option>,  <option value="classKMail_1_1RenameJob.html">kmail::renamejob</option>,  <option value="classKMail_1_1RuleWidgetHandler.html">kmail::rulewidgethandler</option>,  <option value="classKMail_1_1RuleWidgetHandlerManager.html">kmail::rulewidgethandlermanager</option>,  <option value="classKMail_1_1ScheduledCompactionTask.html">kmail::scheduledcompactiontask</option>,  <option value="classKMail_1_1ScheduledExpireTask.html">kmail::scheduledexpiretask</option>,  <option value="classKMail_1_1ScheduledJob.html">kmail::scheduledjob</option>,  <option value="classKMail_1_1ScheduledTask.html">kmail::scheduledtask</option>,  <option value="classKMail_1_1SearchJob.html">kmail::searchjob</option>,  <option value="classKMail_1_1SearchWindow.html">kmail::searchwindow</option>,  <option value="classKMail_1_1SecondaryWindow.html">kmail::secondarywindow</option>,  <option value="classKMail_1_1SieveDebugDialog.html">kmail::sievedebugdialog</option>,  <option value="classKMail_1_1SortCacheItem.html">kmail::sortcacheitem</option>,  <option value="classKMail_1_1SpamHeaderAnalyzer.html">kmail::spamheaderanalyzer</option>,  <option value="classKMail_1_1SpamScore.html">kmail::spamscore</option>,  <option value="classKMail_1_1TeeHtmlWriter.html">kmail::teehtmlwriter</option>,  <option value="classKMail_1_1TransportManager.html">kmail::transportmanager</option>,  <option value="classKMail_1_1UndoInfo.html">kmail::undoinfo</option>,  <option value="classKMail_1_1URLHandler.html">kmail::urlhandler</option>,  <option value="classKMail_1_1URLHandlerManager.html">kmail::urlhandlermanager</option>,  <option value="classKMail_1_1Util_1_1LaterDeleter.html">kmail::util::laterdeleter</option>,  <option value="classKMailICalIfaceImpl.html">kmailicalifaceimpl</option>,  <option value="classKMailIface.html">kmailiface</option>,  <option value="classKMDict.html">kmdict</option>,  <option value="classKMDictItem.html">kmdictitem</option>,  <option value="classKMFilterAction.html">kmfilteraction</option>,  <option value="classKMFilterActionDict.html">kmfilteractiondict</option>,  <option value="classKMFilterActionWidget.html">kmfilteractionwidget</option>,  <option value="classKMFilterActionWithAddress.html">kmfilteractionwithaddress</option>,  <option value="classKMFilterActionWithFolder.html">kmfilteractionwithfolder</option>,  <option value="classKMFilterActionWithNone.html">kmfilteractionwithnone</option>,  <option value="classKMFilterActionWithString.html">kmfilteractionwithstring</option>,  <option value="classKMFilterActionWithStringList.html">kmfilteractionwithstringlist</option>,  <option value="classKMFilterActionWithUOID.html">kmfilteractionwithuoid</option>,  <option value="classKMFilterActionWithUrl.html">kmfilteractionwithurl</option>,  <option value="classKMFilterDlg.html">kmfilterdlg</option>,  <option value="classKMFilterListBox.html">kmfilterlistbox</option>,  <option value="classKMFolder.html">kmfolder</option>,  <option value="classKMFolderDialog.html">kmfolderdialog</option>,  <option value="classKMFolderDir.html">kmfolderdir</option>,  <option value="classKMFolderIndex.html">kmfolderindex</option>,  <option value="classKMFolderOpener.html">kmfolderopener</option>,  <option value="classKMHeaders.html">kmheaders</option>,  <option value="classKMKernel.html">kmkernel</option>,  <option value="classKMMenuCommand.html">kmmenucommand</option>,  <option value="classKMMessage.html">kmmessage</option>,  <option value="classKMMsgDict.html">kmmsgdict</option>,  <option value="classKMMsgList.html">kmmsglist</option>,  <option value="classKMMsgPartDialog.html">kmmsgpartdialog</option>,  <option value="classKMMsgPartDialogCompat.html">kmmsgpartdialogcompat</option>,  <option value="classKMPopHeadersView.html">kmpopheadersview</option>,  <option value="classKMReaderWin.html">kmreaderwin</option>,  <option value="classKMSearchPattern.html">kmsearchpattern</option>,  <option value="classKMSearchPatternEdit.html">kmsearchpatternedit</option>,  <option value="classKMSearchRule.html">kmsearchrule</option>,  <option value="classKMSearchRuleNumerical.html">kmsearchrulenumerical</option>,  <option value="classKMSearchRuleStatus.html">kmsearchrulestatus</option>,  <option value="classKMSearchRuleString.html">kmsearchrulestring</option>,  <option value="classKMSearchRuleWidget.html">kmsearchrulewidget</option>,  <option value="classKMSystemTray.html">kmsystemtray</option>,  <option value="classMailComposerIface.html">mailcomposeriface</option>,  <option value="classScalix_1_1FolderAttributeParser.html">scalix::folderattributeparser</option>,  <option value="classSnippetConfig.html">snippetconfig</option>,  <option value="classSnippetGroup.html">snippetgroup</option>,  <option value="classSnippetItem.html">snippetitem</option>,  <option value="classSnippetSettings.html">snippetsettings</option>,  <option value="classSnippetWidget.html">snippetwidget</option>,
</select>
</form>
</div>
-->
</div></div>
<div class="menu_box"><h2>API Dox</h2>
<div class="nav_list">
<ul>
<li><a href="../../akregator/html/index.html">akregator</a></li><li>&nbsp;&nbsp;<a href="../../akregator/src/html/index.html">src</a></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<a href="../../akregator/src/librss/html/index.html">librss</a></li><li><a href="../../certmanager/html/index.html">certmanager</a></li><li>&nbsp;&nbsp;<a href="../../certmanager/lib/html/index.html">lib</a></li><li><a href="../../kaddressbook/html/index.html">kaddressbook</a></li><li><a href="../../kalarm/html/index.html">kalarm</a></li><li>&nbsp;&nbsp;<a href="../../kalarm/lib/html/index.html">lib</a></li><li><a href="../../kandy/html/index.html">kandy</a></li><li><a href="../../karm/html/index.html">karm</a></li><li><a href="../../kdgantt/html/index.html">kdgantt</a></li><li><a href="../../kgantt/html/index.html">kgantt</a></li><li><a href="../../kioslaves/html/index.html">kioslaves</a></li><li>&nbsp;&nbsp;<a href="../../kioslaves/imap4/html/index.html">imap4</a></li><li>&nbsp;&nbsp;<a href="../../kioslaves/mbox/html/index.html">mbox</a></li><li><a href="../../kitchensync/html/index.html">kitchensync</a></li><li><a href="../../kmail/html/index.html">kmail</a></li><li><a href="../../knotes/html/index.html">knotes</a></li><li><a href="../../konsolekalendar/html/index.html">konsolekalendar</a></li><li><a href="../../kontact/html/index.html">kontact</a></li><li><a href="../../korganizer/html/index.html">korganizer</a></li><li><a href="../../kpilot/html/index.html">kpilot</a></li><li>&nbsp;&nbsp;<a href="../../kpilot/kpilot/html/index.html">kpilot</a></li><li>&nbsp;&nbsp;<a href="../../kpilot/lib/html/index.html">lib</a></li><li><a href="../../libemailfunctions/html/index.html">libemailfunctions</a></li><li><a href="../../libkcal/html/index.html">libkcal</a></li><li><a href="../../libkdepim/html/index.html">libkdepim</a></li><li><a href="../../libkholidays/html/index.html">libkholidays</a></li><li><a href="../../libkmime/html/index.html">libkmime</a></li><li><a href="../../libkpgp/html/index.html">libkpgp</a></li><li><a href="../../libkpimidentities/html/index.html">libkpimidentities</a></li>
</ul></div></div>


        </td>
</tr>
</table>

<span class="doNotDisplay">
  <a href="http://www.kde.org/" accesskey="8">KDE Home</a> |
  <a href="http://accessibility.kde.org/" accesskey="9">KDE Accessibility Home</a> |
  <a href="http://www.kde.org/media/accesskeys.php" accesskey="0">Description of Access Keys</a>
</span>


<div style="height: 8px"></div>

<div id="footer">
  <div id="footer_left">
    Maintained by <a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;groo&#116;&#64;kde&#46;or&#x67;">Adriaan de Groot</a>
and
<a href="&#109;a&#105;&#108;&#116;&#111;&#58;w&#105;nter&#64;kde&#46;or&#x67">Allen Winter</a>.
<br/>
    KDE and K Desktop Environment are trademarks of <a href="http://www.kde.org/areas/kde-ev/" title="Homepage of the KDE non-profit Organization">KDE e.V.</a> |
    <a href="http://www.kde.org/contact/impressum.php">Legal</a>
  </div>
  <div id="footer_right"><img src="/media/images/footer_right.png" style="margin: 0px" alt="" /></div>
</div>

<!--
WARNING: DO NOT SEND MAIL TO THE FOLLOWING EMAIL ADDRESS! YOU WILL
BE BLOCKED INSTANTLY AND PERMANENTLY!
<a href="mailto:aaaatrap-425acc3b5374943f@kde.org">Block me</a>
WARNING END
-->

</body>
</html>