00001
00002
00003
00004
00005
00006
00007
00008
00009 #include <config.h>
00010
00011 #include "kmreaderwin.h"
00012
00013 #include "globalsettings.h"
00014 #include "kmversion.h"
00015 #include "kmmainwidget.h"
00016 #include "kmreadermainwin.h"
00017 #include <libkdepim/kfileio.h>
00018 #include "kmfolderindex.h"
00019 #include "kmcommands.h"
00020 #include "kmmsgpartdlg.h"
00021 #include "mailsourceviewer.h"
00022 using KMail::MailSourceViewer;
00023 #include "partNode.h"
00024 #include "kmmsgdict.h"
00025 #include "messagesender.h"
00026 #include "kcursorsaver.h"
00027 #include "kmfolder.h"
00028 #include "vcardviewer.h"
00029 using KMail::VCardViewer;
00030 #include "objecttreeparser.h"
00031 using KMail::ObjectTreeParser;
00032 #include "partmetadata.h"
00033 using KMail::PartMetaData;
00034 #include "attachmentstrategy.h"
00035 using KMail::AttachmentStrategy;
00036 #include "headerstrategy.h"
00037 using KMail::HeaderStrategy;
00038 #include "headerstyle.h"
00039 using KMail::HeaderStyle;
00040 #include "khtmlparthtmlwriter.h"
00041 using KMail::HtmlWriter;
00042 using KMail::KHtmlPartHtmlWriter;
00043 #include "htmlstatusbar.h"
00044 using KMail::HtmlStatusBar;
00045 #include "folderjob.h"
00046 using KMail::FolderJob;
00047 #include "csshelper.h"
00048 using KMail::CSSHelper;
00049 #include "isubject.h"
00050 using KMail::ISubject;
00051 #include "urlhandlermanager.h"
00052 using KMail::URLHandlerManager;
00053 #include "interfaces/observable.h"
00054 #include "util.h"
00055 #include "kmheaders.h"
00056
00057 #include "broadcaststatus.h"
00058
00059 #include <kmime_mdn.h>
00060 using namespace KMime;
00061 #ifdef KMAIL_READER_HTML_DEBUG
00062 #include "filehtmlwriter.h"
00063 using KMail::FileHtmlWriter;
00064 #include "teehtmlwriter.h"
00065 using KMail::TeeHtmlWriter;
00066 #endif
00067
00068 #include <kasciistringtools.h>
00069 #include <kstringhandler.h>
00070
00071 #include <mimelib/mimepp.h>
00072 #include <mimelib/body.h>
00073 #include <mimelib/utility.h>
00074
00075 #include <kleo/specialjob.h>
00076 #include <kleo/cryptobackend.h>
00077 #include <kleo/cryptobackendfactory.h>
00078
00079
00080 #include <kabc/addressee.h>
00081 #include <kabc/vcardconverter.h>
00082
00083
00084 #include <khtml_part.h>
00085 #include <khtmlview.h>
00086 #include <dom/html_element.h>
00087 #include <dom/html_block.h>
00088 #include <dom/html_document.h>
00089 #include <dom/dom_string.h>
00090 #include <dom/dom_exception.h>
00091
00092 #include <kapplication.h>
00093
00094 #include <kuserprofile.h>
00095 #include <kcharsets.h>
00096 #include <kpopupmenu.h>
00097 #include <kstandarddirs.h>
00098 #include <kcursor.h>
00099 #include <kdebug.h>
00100 #include <kfiledialog.h>
00101 #include <klocale.h>
00102 #include <kmessagebox.h>
00103 #include <kglobalsettings.h>
00104 #include <krun.h>
00105 #include <ktempfile.h>
00106 #include <kprocess.h>
00107 #include <kdialog.h>
00108 #include <kaction.h>
00109 #include <kiconloader.h>
00110 #include <kmdcodec.h>
00111 #include <kasciistricmp.h>
00112 #include <kurldrag.h>
00113
00114 #include <qclipboard.h>
00115 #include <qhbox.h>
00116 #include <qtextcodec.h>
00117 #include <qpaintdevicemetrics.h>
00118 #include <qlayout.h>
00119 #include <qlabel.h>
00120 #include <qsplitter.h>
00121 #include <qstyle.h>
00122
00123
00124 #undef Never
00125 #undef Always
00126
00127 #include <unistd.h>
00128 #include <stdlib.h>
00129 #include <sys/stat.h>
00130 #include <errno.h>
00131 #include <stdio.h>
00132 #include <ctype.h>
00133 #include <string.h>
00134
00135 #ifdef HAVE_PATHS_H
00136 #include <paths.h>
00137 #endif
00138
00139 class NewByteArray : public QByteArray
00140 {
00141 public:
00142 NewByteArray &appendNULL();
00143 NewByteArray &operator+=( const char * );
00144 NewByteArray &operator+=( const QByteArray & );
00145 NewByteArray &operator+=( const QCString & );
00146 QByteArray& qByteArray();
00147 };
00148
00149 NewByteArray& NewByteArray::appendNULL()
00150 {
00151 QByteArray::detach();
00152 uint len1 = size();
00153 if ( !QByteArray::resize( len1 + 1 ) )
00154 return *this;
00155 *(data() + len1) = '\0';
00156 return *this;
00157 }
00158 NewByteArray& NewByteArray::operator+=( const char * newData )
00159 {
00160 if ( !newData )
00161 return *this;
00162 QByteArray::detach();
00163 uint len1 = size();
00164 uint len2 = qstrlen( newData );
00165 if ( !QByteArray::resize( len1 + len2 ) )
00166 return *this;
00167 memcpy( data() + len1, newData, len2 );
00168 return *this;
00169 }
00170 NewByteArray& NewByteArray::operator+=( const QByteArray & newData )
00171 {
00172 if ( newData.isNull() )
00173 return *this;
00174 QByteArray::detach();
00175 uint len1 = size();
00176 uint len2 = newData.size();
00177 if ( !QByteArray::resize( len1 + len2 ) )
00178 return *this;
00179 memcpy( data() + len1, newData.data(), len2 );
00180 return *this;
00181 }
00182 NewByteArray& NewByteArray::operator+=( const QCString & newData )
00183 {
00184 if ( newData.isEmpty() )
00185 return *this;
00186 QByteArray::detach();
00187 uint len1 = size();
00188 uint len2 = newData.length();
00189 if ( !QByteArray::resize( len1 + len2 ) )
00190 return *this;
00191 memcpy( data() + len1, newData.data(), len2 );
00192 return *this;
00193 }
00194 QByteArray& NewByteArray::qByteArray()
00195 {
00196 return *((QByteArray*)this);
00197 }
00198
00199
00200
00201
00202
00203 bool KMReaderWin::objectTreeToDecryptedMsg( partNode* node,
00204 NewByteArray& resultingData,
00205 DwMessage *currentDwMessage,
00206 bool weAreReplacingAMessageNode,
00207 int recCount )
00208 {
00209 bool somethingWasChanged = false;
00210 kdDebug(5006) << QString("-------------------------------------------------" ) << endl;
00211 kdDebug(5006) << QString("KMReaderWin::objectTreeToDecryptedMsg( %1 ) START").arg( recCount ) << endl;
00212 if( node ) {
00213
00214 kdDebug(5006) << node->typeString() << '/' << node->subTypeString() << endl;
00215
00216 partNode* curNode = node;
00217 partNode* dataNode = curNode;
00218 partNode * child = node->firstChild();
00219 const bool bIsMultipart = node->type() == DwMime::kTypeMultipart;
00220 const bool isEncapsulatedMessage = node->type() == DwMime::kTypeMessage && node->parentNode();
00221 const bool isFirstChildOfMessage = !node->parentNode() || node->parentNode()->type() == DwMime::kTypeMessage;
00222 bool bKeepPartAsIs = false;
00223
00224 switch( curNode->type() ){
00225 case DwMime::kTypeMultipart: {
00226 switch( curNode->subType() ){
00227 case DwMime::kSubtypeSigned: {
00228 bKeepPartAsIs = true;
00229 }
00230 break;
00231 case DwMime::kSubtypeEncrypted: {
00232 if ( child )
00233 dataNode = child;
00234 }
00235 break;
00236 }
00237 }
00238 break;
00239 case DwMime::kTypeApplication: {
00240 switch( curNode->subType() ){
00241 case DwMime::kSubtypeOctetStream: {
00242 if ( child )
00243 dataNode = child;
00244 }
00245 break;
00246 case DwMime::kSubtypePkcs7Signature: {
00247
00248
00249 bKeepPartAsIs = true;
00250 }
00251 break;
00252 case DwMime::kSubtypePkcs7Mime: {
00253
00254
00255 if ( child && curNode->encryptionState() != KMMsgNotEncrypted )
00256 dataNode = child;
00257 }
00258 break;
00259 }
00260 }
00261 break;
00262 }
00263
00264
00265 DwHeaders& messageHeaders( currentDwMessage->Headers() );
00266 DwBodyPart * part = dataNode->dwPart();
00267 DwHeaders * headers(
00268 (part && part->hasHeaders())
00269 ? &part->Headers()
00270 : ( (weAreReplacingAMessageNode || isFirstChildOfMessage)
00271 ? &messageHeaders
00272 : 0 ) );
00273 if( dataNode == curNode ) {
00274 kdDebug(5006) << "dataNode == curNode: Save curNode without replacing it." << endl;
00275
00276
00277
00278
00279 if( headers ) {
00280 if( dataNode->parentNode() && !weAreReplacingAMessageNode ) {
00281 kdDebug(5006) << "dataNode is NOT replacing a message node: Store the headers." << endl;
00282 resultingData += headers->AsString().c_str();
00283 resultingData += QCString( "\n" );
00284 } else if( weAreReplacingAMessageNode && part && part->hasHeaders() ){
00285 kdDebug(5006) << "dataNode replace a message node: Do NOT store the headers but change" << endl;
00286 kdDebug(5006) << " the Message's headers accordingly." << endl;
00287 kdDebug(5006) << " old Content-Type = " << messageHeaders.ContentType().AsString().c_str() << endl;
00288 kdDebug(5006) << " new Content-Type = " << headers->ContentType().AsString().c_str() << endl;
00289 messageHeaders.ContentType() = headers->ContentType();
00290 messageHeaders.FindField( "Content-Type" )->SetModified();
00291 if ( headers->HasContentTransferEncoding() ) {
00292 messageHeaders.ContentTransferEncoding() = headers->ContentTransferEncoding();
00293 messageHeaders.FindField( "Content-Transfer-Encoding" )->SetModified();
00294 } else if ( messageHeaders.HasContentTransferEncoding() ) {
00295 messageHeaders.RemoveField( messageHeaders.FindField( "Content-Transfer-Encoding" ) );
00296 }
00297 messageHeaders.ContentDescription() = headers->ContentDescription();
00298 messageHeaders.FindField( "Content-Description" )->SetModified();
00299 messageHeaders.ContentDisposition() = headers->ContentDisposition();
00300 messageHeaders.FindField( "Content-Disposition" )->SetModified();
00301 messageHeaders.SetModified();
00302 messageHeaders.Assemble();
00303 somethingWasChanged = true;
00304 }
00305 }
00306
00307 if ( bKeepPartAsIs ) {
00308 kdDebug(5006) << "keeping body as is." << endl;
00309 resultingData += dataNode->encodedBody();
00310 } else {
00311
00312
00313 if ( isEncapsulatedMessage && part && part->Body().Message() ) {
00314 kdDebug(5006) << "is a valid Message, processing it." << endl;
00315 DwMessage * const message = part->Body().Message();
00316
00317
00318
00319 NewByteArray messageContents;
00320 const bool changed = objectTreeToDecryptedMsg( curNode->firstChild(), messageContents,
00321 message, false, recCount + 1 );
00322 if ( !somethingWasChanged ) {
00323 somethingWasChanged = changed;
00324 }
00325
00326 resultingData += message->Headers().AsString().c_str();
00327 resultingData += QCString( "\n" );
00328 resultingData += messageContents;
00329 }
00330 else if( headers && bIsMultipart && dataNode->firstChild() ) {
00331 kdDebug(5006) << "is valid Multipart, processing children:" << endl;
00332 QCString boundary = headers->ContentType().Boundary().c_str();
00333 curNode = dataNode->firstChild();
00334
00335 while( curNode ) {
00336 kdDebug(5006) << "--boundary" << endl;
00337 if( resultingData.size() &&
00338 ( '\n' != resultingData.at( resultingData.size()-1 ) ) )
00339 resultingData += QCString( "\n" );
00340 resultingData += QCString( "\n" );
00341 resultingData += "--";
00342 resultingData += boundary;
00343 resultingData += "\n";
00344
00345
00346
00347 const bool changed = objectTreeToDecryptedMsg( curNode, resultingData, currentDwMessage,
00348 false, recCount + 1 );
00349 if ( !somethingWasChanged ) {
00350 somethingWasChanged = changed;
00351 }
00352 curNode = curNode->nextSibling();
00353 }
00354 kdDebug(5006) << "--boundary--" << endl;
00355 resultingData += "\n--";
00356 resultingData += boundary;
00357 resultingData += "--\n\n";
00358 kdDebug(5006) << "Multipart processing children - DONE" << endl;
00359 } else if( part ){
00360
00361 kdDebug(5006) << "is Simple part or invalid Multipart, storing body data .. DONE" << endl;
00362 resultingData += part->Body().AsString().c_str();
00363 }
00364 }
00365 } else {
00366 kdDebug(5006) << "dataNode != curNode: Replace curNode by dataNode." << endl;
00367 bool messageNodeReplaceFlag = weAreReplacingAMessageNode || isFirstChildOfMessage;
00368 if( messageNodeReplaceFlag ) {
00369 kdDebug(5006) << " A message node will be replaced." << endl;
00370 } else {
00371 kdDebug(5006) << " A message will NOT be replaced." << endl;
00372 }
00373
00374
00375 somethingWasChanged = objectTreeToDecryptedMsg( dataNode, resultingData, currentDwMessage,
00376 messageNodeReplaceFlag, recCount + 1 );
00377 Q_ASSERT( somethingWasChanged );
00378 }
00379 }
00380 kdDebug(5006) << QString("\nKMReaderWin::objectTreeToDecryptedMsg( %1 ) END").arg( recCount ) << endl;
00381 return somethingWasChanged;
00382 }
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405 void KMReaderWin::createWidgets() {
00406 QVBoxLayout * vlay = new QVBoxLayout( this );
00407 mSplitter = new QSplitter( Qt::Vertical, this, "mSplitter" );
00408 vlay->addWidget( mSplitter );
00409 mMimePartTree = new KMMimePartTree( this, mSplitter, "mMimePartTree" );
00410 mBox = new QHBox( mSplitter, "mBox" );
00411 setStyleDependantFrameWidth();
00412 mBox->setFrameStyle( mMimePartTree->frameStyle() );
00413 mColorBar = new HtmlStatusBar( mBox, "mColorBar" );
00414 mViewer = new KHTMLPart( mBox, "mViewer" );
00415 mSplitter->setOpaqueResize( KGlobalSettings::opaqueResize() );
00416 mSplitter->setResizeMode( mMimePartTree, QSplitter::KeepSize );
00417 }
00418
00419 const int KMReaderWin::delay = 150;
00420
00421
00422 KMReaderWin::KMReaderWin(QWidget *aParent,
00423 QWidget *mainWindow,
00424 KActionCollection* actionCollection,
00425 const char *aName,
00426 int aFlags )
00427 : QWidget(aParent, aName, aFlags | Qt::WDestructiveClose),
00428 mSerNumOfOriginalMessage( 0 ),
00429 mNodeIdOffset( -1 ),
00430 mAttachmentStrategy( 0 ),
00431 mHeaderStrategy( 0 ),
00432 mHeaderStyle( 0 ),
00433 mUpdateReaderWinTimer( 0, "mUpdateReaderWinTimer" ),
00434 mResizeTimer( 0, "mResizeTimer" ),
00435 mDelayedMarkTimer( 0, "mDelayedMarkTimer" ),
00436 mOldGlobalOverrideEncoding( "---" ),
00437 mCSSHelper( 0 ),
00438 mRootNode( 0 ),
00439 mMainWindow( mainWindow ),
00440 mActionCollection( actionCollection ),
00441 mMailToComposeAction( 0 ),
00442 mMailToReplyAction( 0 ),
00443 mMailToForwardAction( 0 ),
00444 mAddAddrBookAction( 0 ),
00445 mOpenAddrBookAction( 0 ),
00446 mCopyAction( 0 ),
00447 mCopyURLAction( 0 ),
00448 mUrlOpenAction( 0 ),
00449 mUrlSaveAsAction( 0 ),
00450 mAddBookmarksAction( 0 ),
00451 mStartIMChatAction( 0 ),
00452 mSelectAllAction( 0 ),
00453 mHeaderOnlyAttachmentsAction( 0 ),
00454 mSelectEncodingAction( 0 ),
00455 mToggleFixFontAction( 0 ),
00456 mCanStartDrag( false ),
00457 mHtmlWriter( 0 ),
00458 mSavedRelativePosition( 0 ),
00459 mDecrytMessageOverwrite( false ),
00460 mShowSignatureDetails( false ),
00461 mShowAttachmentQuicklist( true ),
00462 mShowRawToltecMail( false )
00463 {
00464 mExternalWindow = (aParent == mainWindow );
00465 mSplitterSizes << 180 << 100;
00466 mMimeTreeMode = 1;
00467 mMimeTreeAtBottom = true;
00468 mAutoDelete = false;
00469 mLastSerNum = 0;
00470 mWaitingForSerNum = 0;
00471 mMessage = 0;
00472 mMsgDisplay = true;
00473 mPrinting = false;
00474 mShowColorbar = false;
00475 mAtmUpdate = false;
00476
00477 createWidgets();
00478 createActions( actionCollection );
00479 initHtmlWidget();
00480 readConfig();
00481
00482 mHtmlOverride = false;
00483 mHtmlLoadExtOverride = false;
00484
00485 mLevelQuote = GlobalSettings::self()->collapseQuoteLevelSpin() - 1;
00486
00487 connect( &mUpdateReaderWinTimer, SIGNAL(timeout()),
00488 this, SLOT(updateReaderWin()) );
00489 connect( &mResizeTimer, SIGNAL(timeout()),
00490 this, SLOT(slotDelayedResize()) );
00491 connect( &mDelayedMarkTimer, SIGNAL(timeout()),
00492 this, SLOT(slotTouchMessage()) );
00493
00494 }
00495
00496 void KMReaderWin::createActions( KActionCollection * ac ) {
00497 if ( !ac )
00498 return;
00499
00500 KRadioAction *raction = 0;
00501
00502
00503 KActionMenu *headerMenu =
00504 new KActionMenu( i18n("View->", "&Headers"), ac, "view_headers" );
00505 headerMenu->setToolTip( i18n("Choose display style of message headers") );
00506
00507 connect( headerMenu, SIGNAL(activated()),
00508 this, SLOT(slotCycleHeaderStyles()) );
00509
00510 raction = new KRadioAction( i18n("View->headers->", "&Enterprise Headers"), 0,
00511 this, SLOT(slotEnterpriseHeaders()),
00512 ac, "view_headers_enterprise" );
00513 raction->setToolTip( i18n("Show the list of headers in Enterprise style") );
00514 raction->setExclusiveGroup( "view_headers_group" );
00515 headerMenu->insert(raction);
00516
00517 raction = new KRadioAction( i18n("View->headers->", "&Fancy Headers"), 0,
00518 this, SLOT(slotFancyHeaders()),
00519 ac, "view_headers_fancy" );
00520 raction->setToolTip( i18n("Show the list of headers in a fancy format") );
00521 raction->setExclusiveGroup( "view_headers_group" );
00522 headerMenu->insert( raction );
00523
00524 raction = new KRadioAction( i18n("View->headers->", "&Brief Headers"), 0,
00525 this, SLOT(slotBriefHeaders()),
00526 ac, "view_headers_brief" );
00527 raction->setToolTip( i18n("Show brief list of message headers") );
00528 raction->setExclusiveGroup( "view_headers_group" );
00529 headerMenu->insert( raction );
00530
00531 raction = new KRadioAction( i18n("View->headers->", "&Standard Headers"), 0,
00532 this, SLOT(slotStandardHeaders()),
00533 ac, "view_headers_standard" );
00534 raction->setToolTip( i18n("Show standard list of message headers") );
00535 raction->setExclusiveGroup( "view_headers_group" );
00536 headerMenu->insert( raction );
00537
00538 raction = new KRadioAction( i18n("View->headers->", "&Long Headers"), 0,
00539 this, SLOT(slotLongHeaders()),
00540 ac, "view_headers_long" );
00541 raction->setToolTip( i18n("Show long list of message headers") );
00542 raction->setExclusiveGroup( "view_headers_group" );
00543 headerMenu->insert( raction );
00544
00545 raction = new KRadioAction( i18n("View->headers->", "&All Headers"), 0,
00546 this, SLOT(slotAllHeaders()),
00547 ac, "view_headers_all" );
00548 raction->setToolTip( i18n("Show all message headers") );
00549 raction->setExclusiveGroup( "view_headers_group" );
00550 headerMenu->insert( raction );
00551
00552
00553 KActionMenu *attachmentMenu =
00554 new KActionMenu( i18n("View->", "&Attachments"), ac, "view_attachments" );
00555 attachmentMenu->setToolTip( i18n("Choose display style of attachments") );
00556 connect( attachmentMenu, SIGNAL(activated()),
00557 this, SLOT(slotCycleAttachmentStrategy()) );
00558
00559 raction = new KRadioAction( i18n("View->attachments->", "&As Icons"), 0,
00560 this, SLOT(slotIconicAttachments()),
00561 ac, "view_attachments_as_icons" );
00562 raction->setToolTip( i18n("Show all attachments as icons. Click to see them.") );
00563 raction->setExclusiveGroup( "view_attachments_group" );
00564 attachmentMenu->insert( raction );
00565
00566 raction = new KRadioAction( i18n("View->attachments->", "&Smart"), 0,
00567 this, SLOT(slotSmartAttachments()),
00568 ac, "view_attachments_smart" );
00569 raction->setToolTip( i18n("Show attachments as suggested by sender.") );
00570 raction->setExclusiveGroup( "view_attachments_group" );
00571 attachmentMenu->insert( raction );
00572
00573 raction = new KRadioAction( i18n("View->attachments->", "&Inline"), 0,
00574 this, SLOT(slotInlineAttachments()),
00575 ac, "view_attachments_inline" );
00576 raction->setToolTip( i18n("Show all attachments inline (if possible)") );
00577 raction->setExclusiveGroup( "view_attachments_group" );
00578 attachmentMenu->insert( raction );
00579
00580 raction = new KRadioAction( i18n("View->attachments->", "&Hide"), 0,
00581 this, SLOT(slotHideAttachments()),
00582 ac, "view_attachments_hide" );
00583 raction->setToolTip( i18n("Do not show attachments in the message viewer") );
00584 raction->setExclusiveGroup( "view_attachments_group" );
00585 attachmentMenu->insert( raction );
00586
00587 mHeaderOnlyAttachmentsAction = new KRadioAction( i18n( "View->attachments->", "In Header &Only" ), 0,
00588 this, SLOT( slotHeaderOnlyAttachments() ),
00589 ac, "view_attachments_headeronly" );
00590 mHeaderOnlyAttachmentsAction->setToolTip( i18n( "Show Attachments only in the header of the mail" ) );
00591 mHeaderOnlyAttachmentsAction->setExclusiveGroup( "view_attachments_group" );
00592 attachmentMenu->insert( mHeaderOnlyAttachmentsAction );
00593
00594
00595 mSelectEncodingAction = new KSelectAction( i18n( "&Set Encoding" ), "charset", 0,
00596 this, SLOT( slotSetEncoding() ),
00597 ac, "encoding" );
00598 QStringList encodings = KMMsgBase::supportedEncodings( false );
00599 encodings.prepend( i18n( "Auto" ) );
00600 mSelectEncodingAction->setItems( encodings );
00601 mSelectEncodingAction->setCurrentItem( 0 );
00602
00603 mMailToComposeAction = new KAction( i18n("New Message To..."), "mail_new",
00604 0, this, SLOT(slotMailtoCompose()), ac,
00605 "mailto_compose" );
00606 mMailToReplyAction = new KAction( i18n("Reply To..."), "mail_reply",
00607 0, this, SLOT(slotMailtoReply()), ac,
00608 "mailto_reply" );
00609 mMailToForwardAction = new KAction( i18n("Forward To..."), "mail_forward",
00610 0, this, SLOT(slotMailtoForward()), ac,
00611 "mailto_forward" );
00612 mAddAddrBookAction = new KAction( i18n("Add to Address Book"),
00613 0, this, SLOT(slotMailtoAddAddrBook()),
00614 ac, "add_addr_book" );
00615 mOpenAddrBookAction = new KAction( i18n("Open in Address Book"),
00616 0, this, SLOT(slotMailtoOpenAddrBook()),
00617 ac, "openin_addr_book" );
00618 mCopyAction = KStdAction::copy( this, SLOT(slotCopySelectedText()), ac, "kmail_copy");
00619 mSelectAllAction = new KAction( i18n("Select All Text"), CTRL+SHIFT+Key_A, this,
00620 SLOT(selectAll()), ac, "mark_all_text" );
00621 mCopyURLAction = new KAction( i18n("Copy Link Address"), 0, this,
00622 SLOT(slotUrlCopy()), ac, "copy_url" );
00623 mUrlOpenAction = new KAction( i18n("Open URL"), 0, this,
00624 SLOT(slotUrlOpen()), ac, "open_url" );
00625 mAddBookmarksAction = new KAction( i18n("Bookmark This Link"),
00626 "bookmark_add",
00627 0, this, SLOT(slotAddBookmarks()),
00628 ac, "add_bookmarks" );
00629 mUrlSaveAsAction = new KAction( i18n("Save Link As..."), 0, this,
00630 SLOT(slotUrlSave()), ac, "saveas_url" );
00631
00632 mToggleFixFontAction = new KToggleAction( i18n("Use Fi&xed Font"),
00633 Key_X, this, SLOT(slotToggleFixedFont()),
00634 ac, "toggle_fixedfont" );
00635
00636 mStartIMChatAction = new KAction( i18n("Chat &With..."), 0, this,
00637 SLOT(slotIMChat()), ac, "start_im_chat" );
00638 }
00639
00640
00641 KRadioAction *KMReaderWin::actionForHeaderStyle( const HeaderStyle * style, const HeaderStrategy * strategy ) {
00642 if ( !mActionCollection )
00643 return 0;
00644 const char * actionName = 0;
00645 if ( style == HeaderStyle::enterprise() )
00646 actionName = "view_headers_enterprise";
00647 if ( style == HeaderStyle::fancy() )
00648 actionName = "view_headers_fancy";
00649 else if ( style == HeaderStyle::brief() )
00650 actionName = "view_headers_brief";
00651 else if ( style == HeaderStyle::plain() ) {
00652 if ( strategy == HeaderStrategy::standard() )
00653 actionName = "view_headers_standard";
00654 else if ( strategy == HeaderStrategy::rich() )
00655 actionName = "view_headers_long";
00656 else if ( strategy == HeaderStrategy::all() )
00657 actionName = "view_headers_all";
00658 }
00659 if ( actionName )
00660 return static_cast<KRadioAction*>(mActionCollection->action(actionName));
00661 else
00662 return 0;
00663 }
00664
00665 KRadioAction *KMReaderWin::actionForAttachmentStrategy( const AttachmentStrategy * as ) {
00666 if ( !mActionCollection )
00667 return 0;
00668 const char * actionName = 0;
00669 if ( as == AttachmentStrategy::iconic() )
00670 actionName = "view_attachments_as_icons";
00671 else if ( as == AttachmentStrategy::smart() )
00672 actionName = "view_attachments_smart";
00673 else if ( as == AttachmentStrategy::inlined() )
00674 actionName = "view_attachments_inline";
00675 else if ( as == AttachmentStrategy::hidden() )
00676 actionName = "view_attachments_hide";
00677 else if ( as == AttachmentStrategy::headerOnly() )
00678 actionName = "view_attachments_headeronly";
00679
00680 if ( actionName )
00681 return static_cast<KRadioAction*>(mActionCollection->action(actionName));
00682 else
00683 return 0;
00684 }
00685
00686 void KMReaderWin::slotEnterpriseHeaders() {
00687 setHeaderStyleAndStrategy( HeaderStyle::enterprise(),
00688 HeaderStrategy::rich() );
00689 if( !mExternalWindow )
00690 writeConfig();
00691 }
00692
00693 void KMReaderWin::slotFancyHeaders() {
00694 setHeaderStyleAndStrategy( HeaderStyle::fancy(),
00695 HeaderStrategy::rich() );
00696 if( !mExternalWindow )
00697 writeConfig();
00698 }
00699
00700 void KMReaderWin::slotBriefHeaders() {
00701 setHeaderStyleAndStrategy( HeaderStyle::brief(),
00702 HeaderStrategy::brief() );
00703 if( !mExternalWindow )
00704 writeConfig();
00705 }
00706
00707 void KMReaderWin::slotStandardHeaders() {
00708 setHeaderStyleAndStrategy( HeaderStyle::plain(),
00709 HeaderStrategy::standard());
00710 writeConfig();
00711 }
00712
00713 void KMReaderWin::slotLongHeaders() {
00714 setHeaderStyleAndStrategy( HeaderStyle::plain(),
00715 HeaderStrategy::rich() );
00716 if( !mExternalWindow )
00717 writeConfig();
00718 }
00719
00720 void KMReaderWin::slotAllHeaders() {
00721 setHeaderStyleAndStrategy( HeaderStyle::plain(),
00722 HeaderStrategy::all() );
00723 if( !mExternalWindow )
00724 writeConfig();
00725 }
00726
00727 void KMReaderWin::slotLevelQuote( int l )
00728 {
00729 mLevelQuote = l;
00730 saveRelativePosition();
00731 update(true);
00732 }
00733
00734 void KMReaderWin::slotCycleHeaderStyles() {
00735 const HeaderStrategy * strategy = headerStrategy();
00736 const HeaderStyle * style = headerStyle();
00737
00738 const char * actionName = 0;
00739 if ( style == HeaderStyle::enterprise() ) {
00740 slotFancyHeaders();
00741 actionName = "view_headers_fancy";
00742 }
00743 if ( style == HeaderStyle::fancy() ) {
00744 slotBriefHeaders();
00745 actionName = "view_headers_brief";
00746 } else if ( style == HeaderStyle::brief() ) {
00747 slotStandardHeaders();
00748 actionName = "view_headers_standard";
00749 } else if ( style == HeaderStyle::plain() ) {
00750 if ( strategy == HeaderStrategy::standard() ) {
00751 slotLongHeaders();
00752 actionName = "view_headers_long";
00753 } else if ( strategy == HeaderStrategy::rich() ) {
00754 slotAllHeaders();
00755 actionName = "view_headers_all";
00756 } else if ( strategy == HeaderStrategy::all() ) {
00757 slotEnterpriseHeaders();
00758 actionName = "view_headers_enterprise";
00759 }
00760 }
00761
00762 if ( actionName )
00763 static_cast<KRadioAction*>( mActionCollection->action( actionName ) )->setChecked( true );
00764 }
00765
00766
00767 void KMReaderWin::slotIconicAttachments() {
00768 setAttachmentStrategy( AttachmentStrategy::iconic() );
00769 }
00770
00771 void KMReaderWin::slotSmartAttachments() {
00772 setAttachmentStrategy( AttachmentStrategy::smart() );
00773 }
00774
00775 void KMReaderWin::slotInlineAttachments() {
00776 setAttachmentStrategy( AttachmentStrategy::inlined() );
00777 }
00778
00779 void KMReaderWin::slotHideAttachments() {
00780 setAttachmentStrategy( AttachmentStrategy::hidden() );
00781 }
00782
00783 void KMReaderWin::slotHeaderOnlyAttachments() {
00784 setAttachmentStrategy( AttachmentStrategy::headerOnly() );
00785 }
00786
00787 void KMReaderWin::slotCycleAttachmentStrategy() {
00788 setAttachmentStrategy( attachmentStrategy()->next() );
00789 KRadioAction * action = actionForAttachmentStrategy( attachmentStrategy() );
00790 assert( action );
00791 action->setChecked( true );
00792 }
00793
00794
00795
00796 KMReaderWin::~KMReaderWin()
00797 {
00798 clearBodyPartMementos();
00799 delete mHtmlWriter; mHtmlWriter = 0;
00800 delete mCSSHelper;
00801 if (mAutoDelete) delete message();
00802 delete mRootNode; mRootNode = 0;
00803 removeTempFiles();
00804 }
00805
00806
00807
00808 void KMReaderWin::slotMessageArrived( KMMessage *msg )
00809 {
00810 if (msg && ((KMMsgBase*)msg)->isMessage()) {
00811 if ( msg->getMsgSerNum() == mWaitingForSerNum ) {
00812 setMsg( msg, true );
00813 } else {
00814
00815 }
00816 }
00817 }
00818
00819
00820 void KMReaderWin::update( KMail::Interface::Observable * observable )
00821 {
00822 if ( !mAtmUpdate ) {
00823
00824
00825 updateReaderWin();
00826 return;
00827 }
00828
00829 if ( !mRootNode )
00830 return;
00831
00832 KMMessage* msg = static_cast<KMMessage*>( observable );
00833 assert( msg != 0 );
00834
00835
00836 if ( !msg->lastUpdatedPart() ) {
00837 kdDebug(5006) << "KMReaderWin::update - no updated part" << endl;
00838 return;
00839 }
00840 partNode* node = mRootNode->findNodeForDwPart( msg->lastUpdatedPart() );
00841 if ( !node ) {
00842 kdDebug(5006) << "KMReaderWin::update - can't find node for part" << endl;
00843 return;
00844 }
00845 node->setDwPart( msg->lastUpdatedPart() );
00846
00847
00848
00849 ::chmod( QFile::encodeName( mAtmCurrentName ), S_IRWXU );
00850 QByteArray data = node->msgPart().bodyDecodedBinary();
00851 size_t size = data.size();
00852 if ( node->msgPart().type() == DwMime::kTypeText && size) {
00853 size = KMail::Util::crlf2lf( data.data(), size );
00854 }
00855 KPIM::kBytesToFile( data.data(), size, mAtmCurrentName, false, false, false );
00856 ::chmod( QFile::encodeName( mAtmCurrentName ), S_IRUSR );
00857
00858 mAtmUpdate = false;
00859 }
00860
00861
00862 void KMReaderWin::removeTempFiles()
00863 {
00864 for (QStringList::Iterator it = mTempFiles.begin(); it != mTempFiles.end();
00865 it++)
00866 {
00867 QFile::remove(*it);
00868 }
00869 mTempFiles.clear();
00870 for (QStringList::Iterator it = mTempDirs.begin(); it != mTempDirs.end();
00871 it++)
00872 {
00873 QDir(*it).rmdir(*it);
00874 }
00875 mTempDirs.clear();
00876 }
00877
00878
00879
00880 bool KMReaderWin::event(QEvent *e)
00881 {
00882 if (e->type() == QEvent::ApplicationPaletteChange)
00883 {
00884 delete mCSSHelper;
00885 mCSSHelper = new KMail::CSSHelper( QPaintDeviceMetrics( mViewer->view() ) );
00886 if (message())
00887 message()->readConfig();
00888 update( true );
00889 return true;
00890 }
00891 return QWidget::event(e);
00892 }
00893
00894
00895
00896 void KMReaderWin::readConfig(void)
00897 {
00898 const KConfigGroup mdnGroup( KMKernel::config(), "MDN" );
00899 KConfigGroup reader( KMKernel::config(), "Reader" );
00900
00901 delete mCSSHelper;
00902 mCSSHelper = new KMail::CSSHelper( QPaintDeviceMetrics( mViewer->view() ) );
00903
00904 mNoMDNsWhenEncrypted = mdnGroup.readBoolEntry( "not-send-when-encrypted", true );
00905
00906 mUseFixedFont = reader.readBoolEntry( "useFixedFont", false );
00907 if ( mToggleFixFontAction )
00908 mToggleFixFontAction->setChecked( mUseFixedFont );
00909
00910 mHtmlMail = reader.readBoolEntry( "htmlMail", false );
00911 mHtmlLoadExternal = reader.readBoolEntry( "htmlLoadExternal", false );
00912
00913 setHeaderStyleAndStrategy( HeaderStyle::create( reader.readEntry( "header-style", "fancy" ) ),
00914 HeaderStrategy::create( reader.readEntry( "header-set-displayed", "rich" ) ) );
00915 KRadioAction *raction = actionForHeaderStyle( headerStyle(), headerStrategy() );
00916 if ( raction )
00917 raction->setChecked( true );
00918
00919 setAttachmentStrategy( AttachmentStrategy::create( reader.readEntry( "attachment-strategy", "smart" ) ) );
00920 raction = actionForAttachmentStrategy( attachmentStrategy() );
00921 if ( raction )
00922 raction->setChecked( true );
00923
00924
00925
00926 mShowColorbar = reader.readBoolEntry( "showColorbar", Kpgp::Module::getKpgp()->usePGP() );
00927
00928
00929
00930 reader.writeEntry( "showColorbar", mShowColorbar );
00931
00932 mMimeTreeAtBottom = reader.readEntry( "MimeTreeLocation", "bottom" ) != "top";
00933 const QString s = reader.readEntry( "MimeTreeMode", "smart" );
00934 if ( s == "never" )
00935 mMimeTreeMode = 0;
00936 else if ( s == "always" )
00937 mMimeTreeMode = 2;
00938 else
00939 mMimeTreeMode = 1;
00940
00941 const int mimeH = reader.readNumEntry( "MimePaneHeight", 100 );
00942 const int messageH = reader.readNumEntry( "MessagePaneHeight", 180 );
00943 mSplitterSizes.clear();
00944 if ( mMimeTreeAtBottom )
00945 mSplitterSizes << messageH << mimeH;
00946 else
00947 mSplitterSizes << mimeH << messageH;
00948
00949 adjustLayout();
00950
00951 readGlobalOverrideCodec();
00952
00953 if (message())
00954 update();
00955 KMMessage::readConfig();
00956 }
00957
00958
00959 void KMReaderWin::adjustLayout() {
00960 if ( mMimeTreeAtBottom )
00961 mSplitter->moveToLast( mMimePartTree );
00962 else
00963 mSplitter->moveToFirst( mMimePartTree );
00964 mSplitter->setSizes( mSplitterSizes );
00965
00966 if ( mMimeTreeMode == 2 && mMsgDisplay )
00967 mMimePartTree->show();
00968 else
00969 mMimePartTree->hide();
00970
00971 if ( mShowColorbar && mMsgDisplay )
00972 mColorBar->show();
00973 else
00974 mColorBar->hide();
00975 }
00976
00977
00978 void KMReaderWin::saveSplitterSizes( KConfigBase & c ) const {
00979 if ( !mSplitter || !mMimePartTree )
00980 return;
00981 if ( mMimePartTree->isHidden() )
00982 return;
00983
00984 c.writeEntry( "MimePaneHeight", mSplitter->sizes()[ mMimeTreeAtBottom ? 1 : 0 ] );
00985 c.writeEntry( "MessagePaneHeight", mSplitter->sizes()[ mMimeTreeAtBottom ? 0 : 1 ] );
00986 }
00987
00988
00989 void KMReaderWin::writeConfig( bool sync ) const {
00990 KConfigGroup reader( KMKernel::config(), "Reader" );
00991
00992 reader.writeEntry( "useFixedFont", mUseFixedFont );
00993 if ( headerStyle() )
00994 reader.writeEntry( "header-style", headerStyle()->name() );
00995 if ( headerStrategy() )
00996 reader.writeEntry( "header-set-displayed", headerStrategy()->name() );
00997 if ( attachmentStrategy() )
00998 reader.writeEntry( "attachment-strategy", attachmentStrategy()->name() );
00999
01000 saveSplitterSizes( reader );
01001
01002 if ( sync )
01003 kmkernel->slotRequestConfigSync();
01004 }
01005
01006
01007 void KMReaderWin::initHtmlWidget(void)
01008 {
01009 mViewer->widget()->setFocusPolicy(WheelFocus);
01010
01011 mViewer->setPluginsEnabled(false);
01012 mViewer->setJScriptEnabled(false);
01013 mViewer->setJavaEnabled(false);
01014 mViewer->setMetaRefreshEnabled(false);
01015 mViewer->setURLCursor(KCursor::handCursor());
01016
01017 mViewer->view()->setLineWidth(0);
01018
01019 mViewer->view()->viewport()->installEventFilter( this );
01020
01021 if ( !htmlWriter() )
01022 #ifdef KMAIL_READER_HTML_DEBUG
01023 mHtmlWriter = new TeeHtmlWriter( new FileHtmlWriter( QString::null ),
01024 new KHtmlPartHtmlWriter( mViewer, 0 ) );
01025 #else
01026 mHtmlWriter = new KHtmlPartHtmlWriter( mViewer, 0 );
01027 #endif
01028
01029 connect(mViewer->browserExtension(),
01030 SIGNAL(openURLRequest(const KURL &, const KParts::URLArgs &)),this,
01031 SLOT(slotUrlOpen(const KURL &)));
01032 connect(mViewer->browserExtension(),
01033 SIGNAL(createNewWindow(const KURL &, const KParts::URLArgs &)),this,
01034 SLOT(slotUrlOpen(const KURL &)));
01035 connect(mViewer,SIGNAL(popupMenu(const QString &, const QPoint &)),
01036 SLOT(slotUrlPopup(const QString &, const QPoint &)));
01037 connect( kmkernel->imProxy(), SIGNAL( sigContactPresenceChanged( const QString & ) ),
01038 this, SLOT( contactStatusChanged( const QString & ) ) );
01039 connect( kmkernel->imProxy(), SIGNAL( sigPresenceInfoExpired() ),
01040 this, SLOT( updateReaderWin() ) );
01041 }
01042
01043 void KMReaderWin::contactStatusChanged( const QString &uid)
01044 {
01045
01046
01047 DOM::NodeList presenceNodes = mViewer->htmlDocument()
01048 .getElementsByName( DOM::DOMString( QString::fromLatin1("presence-") + uid ) );
01049 for ( unsigned int i = 0; i < presenceNodes.length(); ++i ) {
01050 DOM::Node n = presenceNodes.item( i );
01051 kdDebug( 5006 ) << "name is " << n.nodeName().string() << endl;
01052 kdDebug( 5006 ) << "value of content was " << n.firstChild().nodeValue().string() << endl;
01053 QString newPresence = kmkernel->imProxy()->presenceString( uid );
01054 if ( newPresence.isNull() )
01055 newPresence = QString::fromLatin1( "ENOIMRUNNING" );
01056 n.firstChild().setNodeValue( newPresence );
01057
01058 }
01059
01060 }
01061
01062 void KMReaderWin::setAttachmentStrategy( const AttachmentStrategy * strategy ) {
01063 mAttachmentStrategy = strategy ? strategy : AttachmentStrategy::smart();
01064 update( true );
01065 }
01066
01067 void KMReaderWin::setHeaderStyleAndStrategy( const HeaderStyle * style,
01068 const HeaderStrategy * strategy ) {
01069 mHeaderStyle = style ? style : HeaderStyle::fancy();
01070 mHeaderStrategy = strategy ? strategy : HeaderStrategy::rich();
01071 if ( mHeaderOnlyAttachmentsAction ) {
01072 const bool styleHasAttachmentQuickList = mHeaderStyle == HeaderStyle::fancy() ||
01073 mHeaderStyle == HeaderStyle::enterprise();
01074 mHeaderOnlyAttachmentsAction->setEnabled( styleHasAttachmentQuickList );
01075 if ( !styleHasAttachmentQuickList && mAttachmentStrategy == AttachmentStrategy::headerOnly() ) {
01076
01077
01078 setAttachmentStrategy( AttachmentStrategy::smart() );
01079 }
01080 }
01081 update( true );
01082 }
01083
01084
01085 void KMReaderWin::setOverrideEncoding( const QString & encoding )
01086 {
01087 if ( encoding == mOverrideEncoding )
01088 return;
01089
01090 mOverrideEncoding = encoding;
01091 if ( mSelectEncodingAction ) {
01092 if ( encoding.isEmpty() ) {
01093 mSelectEncodingAction->setCurrentItem( 0 );
01094 }
01095 else {
01096 QStringList encodings = mSelectEncodingAction->items();
01097 uint i = 0;
01098 for ( QStringList::const_iterator it = encodings.begin(), end = encodings.end(); it != end; ++it, ++i ) {
01099 if ( KGlobal::charsets()->encodingForName( *it ) == encoding ) {
01100 mSelectEncodingAction->setCurrentItem( i );
01101 break;
01102 }
01103 }
01104 if ( i == encodings.size() ) {
01105
01106 kdWarning(5006) << "Unknown override character encoding \"" << encoding
01107 << "\". Using Auto instead." << endl;
01108 mSelectEncodingAction->setCurrentItem( 0 );
01109 mOverrideEncoding = QString::null;
01110 }
01111 }
01112 }
01113 update( true );
01114 }
01115
01116
01117 void KMReaderWin::setPrintFont( const QFont& font )
01118 {
01119
01120 mCSSHelper->setPrintFont( font );
01121 }
01122
01123
01124 const QTextCodec * KMReaderWin::overrideCodec() const
01125 {
01126 if ( mOverrideEncoding.isEmpty() || mOverrideEncoding == "Auto" )
01127 return 0;
01128 else
01129 return KMMsgBase::codecForName( mOverrideEncoding.latin1() );
01130 }
01131
01132
01133 void KMReaderWin::slotSetEncoding()
01134 {
01135 if ( mSelectEncodingAction->currentItem() == 0 )
01136 mOverrideEncoding = QString();
01137 else
01138 mOverrideEncoding = KGlobal::charsets()->encodingForName( mSelectEncodingAction->currentText() );
01139 update( true );
01140 }
01141
01142
01143 void KMReaderWin::readGlobalOverrideCodec()
01144 {
01145
01146 if ( GlobalSettings::self()->overrideCharacterEncoding() == mOldGlobalOverrideEncoding )
01147 return;
01148
01149 setOverrideEncoding( GlobalSettings::self()->overrideCharacterEncoding() );
01150 mOldGlobalOverrideEncoding = GlobalSettings::self()->overrideCharacterEncoding();
01151 }
01152
01153
01154 void KMReaderWin::setOriginalMsg( unsigned long serNumOfOriginalMessage, int nodeIdOffset )
01155 {
01156 mSerNumOfOriginalMessage = serNumOfOriginalMessage;
01157 mNodeIdOffset = nodeIdOffset;
01158 }
01159
01160
01161 void KMReaderWin::setMsg( KMMessage* aMsg, bool force, bool updateOnly )
01162 {
01163 if ( aMsg ) {
01164 kdDebug(5006) << "(" << aMsg->getMsgSerNum() << ", last " << mLastSerNum << ") " << aMsg->subject() << " "
01165 << aMsg->fromStrip() << ", readyToShow " << (aMsg->readyToShow()) << endl;
01166 }
01167
01168
01169 if ( aMsg && aMsg->getMsgSerNum() != mLastSerNum && !updateOnly ){
01170 mLevelQuote = GlobalSettings::self()->collapseQuoteLevelSpin()-1;
01171 mShowRawToltecMail = !GlobalSettings::self()->showToltecReplacementText();
01172 clearBodyPartMementos();
01173 }
01174 if ( mPrinting )
01175 mLevelQuote = -1;
01176
01177 bool complete = true;
01178 if ( aMsg &&
01179 !aMsg->readyToShow() &&
01180 (aMsg->getMsgSerNum() != mLastSerNum) &&
01181 !aMsg->isComplete() )
01182 complete = false;
01183
01184
01185 if (!force && aMsg && mLastSerNum != 0 && aMsg->getMsgSerNum() == mLastSerNum)
01186 return;
01187
01188
01189 if (aMsg && message())
01190 message()->detach( this );
01191 if (aMsg)
01192 aMsg->attach( this );
01193 mAtmUpdate = false;
01194
01195
01196
01197 mDelayedMarkTimer.stop();
01198
01199 mMessage = 0;
01200 if ( !aMsg ) {
01201 mWaitingForSerNum = 0;
01202 mLastSerNum = 0;
01203 } else {
01204 mLastSerNum = aMsg->getMsgSerNum();
01205
01206
01207
01208
01209
01210 if (message() != aMsg) {
01211 mMessage = aMsg;
01212 mLastSerNum = 0;
01213 }
01214 }
01215
01216 if (aMsg) {
01217 aMsg->setOverrideCodec( overrideCodec() );
01218 aMsg->setDecodeHTML( htmlMail() );
01219
01220 if ( !aMsg->isComplete() )
01221 mViewer->setDNDEnabled( false );
01222 else
01223 mViewer->setDNDEnabled( true );
01224 }
01225
01226 const KMMessage * const oldMessage = message();
01227
01228
01229
01230 if ( complete )
01231 {
01232
01233 if (force) {
01234
01235 mUpdateReaderWinTimer.stop();
01236 updateReaderWin();
01237 }
01238 else if (mUpdateReaderWinTimer.isActive())
01239 mUpdateReaderWinTimer.changeInterval( delay );
01240 else
01241 mUpdateReaderWinTimer.start( 0, true );
01242 }
01243
01244 const bool messageChangedDuringUpdate = message() != oldMessage;
01245
01246
01247
01248
01249 if ( !messageChangedDuringUpdate ) {
01250 if ( aMsg && (aMsg->isUnread() || aMsg->isNew()) && GlobalSettings::self()->delayedMarkAsRead() ) {
01251 if ( GlobalSettings::self()->delayedMarkTime() != 0 )
01252 mDelayedMarkTimer.start( GlobalSettings::self()->delayedMarkTime() * 1000, true );
01253 else
01254 slotTouchMessage();
01255 }
01256 }
01257 }
01258
01259
01260 void KMReaderWin::clearCache()
01261 {
01262 mUpdateReaderWinTimer.stop();
01263 clear();
01264 mDelayedMarkTimer.stop();
01265 mLastSerNum = 0;
01266 mWaitingForSerNum = 0;
01267 mMessage = 0;
01268 }
01269
01270
01271 static const char * const kmailChanges[] = {
01272 ""
01273 };
01274 static const int numKMailChanges =
01275 sizeof kmailChanges / sizeof *kmailChanges;
01276
01277
01278
01279
01280
01281 static const char * const kmailNewFeatures[] = {
01282 I18N_NOOP("Full namespace support for IMAP"),
01283 I18N_NOOP("Offline mode"),
01284 I18N_NOOP("Sieve script management and editing"),
01285 I18N_NOOP("Account specific filtering"),
01286 I18N_NOOP("Filtering of incoming mail for online IMAP accounts"),
01287 I18N_NOOP("Online IMAP folders can be used when filtering into folders"),
01288 I18N_NOOP("Automatically delete older mails on POP servers")
01289 };
01290 static const int numKMailNewFeatures =
01291 sizeof kmailNewFeatures / sizeof *kmailNewFeatures;
01292
01293
01294
01295
01296 QString KMReaderWin::newFeaturesMD5()
01297 {
01298 QCString str;
01299 for ( int i = 0 ; i < numKMailChanges ; ++i )
01300 str += kmailChanges[i];
01301 for ( int i = 0 ; i < numKMailNewFeatures ; ++i )
01302 str += kmailNewFeatures[i];
01303 KMD5 md5( str );
01304 return md5.base64Digest();
01305 }
01306
01307
01308 void KMReaderWin::displaySplashPage( const QString &info )
01309 {
01310 mMsgDisplay = false;
01311 adjustLayout();
01312
01313 QString location = locate("data", "kmail/about/main.html");
01314 QString content = KPIM::kFileToString(location);
01315 content = content.arg( locate( "data", "libkdepim/about/kde_infopage.css" ) );
01316 if ( kapp->reverseLayout() )
01317 content = content.arg( "@import \"%1\";" ).arg( locate( "data", "libkdepim/about/kde_infopage_rtl.css" ) );
01318 else
01319 content = content.arg( "" );
01320
01321 mViewer->begin(KURL( location ));
01322
01323 QString fontSize = QString::number( pointsToPixel( mCSSHelper->bodyFont().pointSize() ) );
01324 QString appTitle = i18n("KMail");
01325 QString catchPhrase = "";
01326 QString quickDescription = i18n("The email client for the K Desktop Environment.");
01327 mViewer->write(content.arg(fontSize).arg(appTitle).arg(catchPhrase).arg(quickDescription).arg(info));
01328 mViewer->end();
01329 }
01330
01331 void KMReaderWin::displayBusyPage()
01332 {
01333 QString info =
01334 i18n( "<h2 style='margin-top: 0px;'>Retrieving Folder Contents</h2><p>Please wait . . .</p> " );
01335
01336 displaySplashPage( info );
01337 }
01338
01339 void KMReaderWin::displayOfflinePage()
01340 {
01341 QString info =
01342 i18n( "<h2 style='margin-top: 0px;'>Offline</h2><p>KMail is currently in offline mode. "
01343 "Click <a href=\"kmail:goOnline\">here</a> to go online . . .</p> " );
01344
01345 displaySplashPage( info );
01346 }
01347
01348
01349
01350 void KMReaderWin::displayAboutPage()
01351 {
01352 QString info =
01353 i18n("%1: KMail version; %2: help:// URL; %3: homepage URL; "
01354 "%4: prior KMail version; %5: prior KDE version; "
01355 "%6: generated list of new features; "
01356 "%7: First-time user text (only shown on first start); "
01357 "%8: generated list of important changes; "
01358 "--- end of comment ---",
01359 "<h2 style='margin-top: 0px;'>Welcome to KMail %1</h2><p>KMail is the email client for the K "
01360 "Desktop Environment. It is designed to be fully compatible with "
01361 "Internet mailing standards including MIME, SMTP, POP3 and IMAP."
01362 "</p>\n"
01363 "<ul><li>KMail has many powerful features which are described in the "
01364 "<a href=\"%2\">documentation</a></li>\n"
01365 "<li>The <a href=\"%3\">KMail homepage</A> offers information about "
01366 "new versions of KMail</li></ul>\n"
01367 "%8\n"
01368 "<p>Some of the new features in this release of KMail include "
01369 "(compared to KMail %4, which is part of KDE %5):</p>\n"
01370 "<ul>\n%6</ul>\n"
01371 "%7\n"
01372 "<p>We hope that you will enjoy KMail.</p>\n"
01373 "<p>Thank you,</p>\n"
01374 "<p style='margin-bottom: 0px'> The KMail Team</p>")
01375 .arg(KMAIL_VERSION)
01376 .arg("help:/kmail/index.html")
01377 .arg("http://kontact.kde.org/kmail/")
01378 .arg("1.8").arg("3.4");
01379
01380 QString featureItems;
01381 for ( int i = 0 ; i < numKMailNewFeatures ; i++ )
01382 featureItems += i18n("<li>%1</li>\n").arg( i18n( kmailNewFeatures[i] ) );
01383
01384 info = info.arg( featureItems );
01385
01386 if( kmkernel->firstStart() ) {
01387 info = info.arg( i18n("<p>Please take a moment to fill in the KMail "
01388 "configuration panel at Settings->Configure "
01389 "KMail.\n"
01390 "You need to create at least a default identity and "
01391 "an incoming as well as outgoing mail account."
01392 "</p>\n") );
01393 } else {
01394 info = info.arg( QString::null );
01395 }
01396
01397 if ( ( numKMailChanges > 1 ) || ( numKMailChanges == 1 && strlen(kmailChanges[0]) > 0 ) ) {
01398 QString changesText =
01399 i18n("<p><span style='font-size:125%; font-weight:bold;'>"
01400 "Important changes</span> (compared to KMail %1):</p>\n")
01401 .arg("1.8");
01402 changesText += "<ul>\n";
01403 for ( int i = 0 ; i < numKMailChanges ; i++ )
01404 changesText += i18n("<li>%1</li>\n").arg( i18n( kmailChanges[i] ) );
01405 changesText += "</ul>\n";
01406 info = info.arg( changesText );
01407 }
01408 else
01409 info = info.arg("");
01410
01411 displaySplashPage( info );
01412 }
01413
01414 void KMReaderWin::enableMsgDisplay() {
01415 mMsgDisplay = true;
01416 adjustLayout();
01417 }
01418
01419
01420
01421
01422 void KMReaderWin::updateReaderWin()
01423 {
01424 if (!mMsgDisplay) return;
01425
01426 mViewer->setOnlyLocalReferences(!htmlLoadExternal());
01427
01428 htmlWriter()->reset();
01429
01430 KMFolder* folder = 0;
01431 if (message(&folder))
01432 {
01433 if ( mShowColorbar )
01434 mColorBar->show();
01435 else
01436 mColorBar->hide();
01437 displayMessage();
01438 }
01439 else
01440 {
01441 mColorBar->hide();
01442 mMimePartTree->hide();
01443 mMimePartTree->clear();
01444 htmlWriter()->begin( mCSSHelper->cssDefinitions( isFixedFont() ) );
01445 htmlWriter()->write( mCSSHelper->htmlHead( isFixedFont() ) + "</body></html>" );
01446 htmlWriter()->end();
01447 }
01448
01449 if (mSavedRelativePosition)
01450 {
01451 QScrollView * scrollview = static_cast<QScrollView *>(mViewer->widget());
01452 scrollview->setContentsPos( 0,
01453 qRound( scrollview->contentsHeight() * mSavedRelativePosition ) );
01454 mSavedRelativePosition = 0;
01455 }
01456 }
01457
01458
01459 int KMReaderWin::pointsToPixel(int pointSize) const
01460 {
01461 const QPaintDeviceMetrics pdm(mViewer->view());
01462
01463 return (pointSize * pdm.logicalDpiY() + 36) / 72;
01464 }
01465
01466
01467 void KMReaderWin::showHideMimeTree( bool isPlainTextTopLevel ) {
01468 if ( mMimeTreeMode == 2 ||
01469 ( mMimeTreeMode == 1 && !isPlainTextTopLevel ) )
01470 mMimePartTree->show();
01471 else {
01472
01473 KConfigGroup reader( KMKernel::config(), "Reader" );
01474 saveSplitterSizes( reader );
01475 mMimePartTree->hide();
01476 }
01477 }
01478
01479 void KMReaderWin::displayMessage() {
01480 KMMessage * msg = message();
01481
01482 mMimePartTree->clear();
01483 showHideMimeTree( !msg ||
01484 ( msg->type() == DwMime::kTypeText
01485 && msg->subtype() == DwMime::kSubtypePlain ) );
01486
01487 if ( !msg )
01488 return;
01489
01490 msg->setOverrideCodec( overrideCodec() );
01491
01492 htmlWriter()->begin( mCSSHelper->cssDefinitions( isFixedFont() ) );
01493 htmlWriter()->queue( mCSSHelper->htmlHead( isFixedFont() ) );
01494
01495 if (!parent())
01496 setCaption(msg->subject());
01497
01498 removeTempFiles();
01499
01500 mColorBar->setNeutralMode();
01501
01502 parseMsg(msg);
01503
01504 if( mColorBar->isNeutral() )
01505 mColorBar->setNormalMode();
01506
01507 htmlWriter()->queue("</body></html>");
01508 htmlWriter()->flush();
01509
01510 QTimer::singleShot( 1, this, SLOT(injectAttachments()) );
01511 }
01512
01513 static bool message_was_saved_decrypted_before( const KMMessage * msg ) {
01514 if ( !msg )
01515 return false;
01516
01517 return msg->msgId().stripWhiteSpace().startsWith( "<DecryptedMsg." );
01518 }
01519
01520
01521 bool KMReaderWin::saveDecryptedMessage( KMMessage* aMsg, ObjectTreeParser *otp,
01522 KMMsgEncryptionState encryptionState )
01523 {
01524 bool messageWasReplaced = false;
01525 const KConfigGroup reader( KMKernel::config(), "Reader" );
01526 if ( reader.readBoolEntry( "store-displayed-messages-unencrypted", false ) ) {
01527
01528
01529
01530
01531
01532
01533
01534
01535
01536
01537
01538
01539
01540
01541 kdDebug(5006) << "\n\n\nKMReaderWin::parseMsg() - special post-encryption handling:\n1." << endl;
01542 kdDebug(5006) << "(aMsg == msg) = " << (aMsg == message()) << endl;
01543 kdDebug(5006) << "aMsg->parent() && aMsg->parent() != kmkernel->outboxFolder() = " << (aMsg->parent() && aMsg->parent() != kmkernel->outboxFolder()) << endl;
01544 kdDebug(5006) << "message_was_saved_decrypted_before( aMsg ) = " << message_was_saved_decrypted_before( aMsg ) << endl;
01545 kdDebug(5006) << "this->decryptMessage() = " << decryptMessage() << endl;
01546 kdDebug(5006) << "otp.hasPendingAsyncJobs() = " << otp->hasPendingAsyncJobs() << endl;
01547 kdDebug(5006) << " (KMMsgFullyEncrypted == encryptionState) = " << (KMMsgFullyEncrypted == encryptionState) << endl;
01548 kdDebug(5006) << "|| (KMMsgPartiallyEncrypted == encryptionState) = " << (KMMsgPartiallyEncrypted == encryptionState) << endl;
01549
01550
01551 if( (aMsg == message())
01552
01553 && ( aMsg->parent() && aMsg->parent() != kmkernel->outboxFolder() )
01554
01555 && !message_was_saved_decrypted_before( aMsg )
01556
01557 && decryptMessage()
01558
01559 && !otp->hasPendingAsyncJobs()
01560
01561 && ( (KMMsgFullyEncrypted == encryptionState)
01562 || (KMMsgPartiallyEncrypted == encryptionState) ) ) {
01563
01564 kdDebug(5006) << "KMReaderWin - calling objectTreeToDecryptedMsg()" << endl;
01565
01566 NewByteArray decryptedData;
01567
01568 const bool messageWasChanged =
01569 objectTreeToDecryptedMsg( mRootNode, decryptedData, aMsg->getTopLevelPart() );
01570
01571 decryptedData.appendNULL();
01572 QCString resultString( decryptedData.data() );
01573
01574
01575 if( !resultString.isEmpty() && messageWasChanged ) {
01576 kdDebug(5006) << "KMReaderWin - composing unencrypted message" << endl;
01577
01578 aMsg->setBody( resultString );
01579 KMMessage* unencryptedMessage = new KMMessage( *aMsg );
01580 unencryptedMessage->setParent( 0 );
01581
01582
01583
01584
01585
01586
01587
01588
01589 kdDebug(5006) << "KMReaderWin - attach unencrypted message to aMsg" << endl;
01590 aMsg->setUnencryptedMsg( unencryptedMessage );
01591 messageWasReplaced = true;
01592 }
01593 }
01594 }
01595 return messageWasReplaced;
01596 }
01597
01598
01599 void KMReaderWin::parseMsg(KMMessage* aMsg)
01600 {
01601 KMMessagePart msgPart;
01602 QCString subtype, contDisp;
01603 QByteArray str;
01604
01605 assert(aMsg!=0);
01606
01607 aMsg->setIsBeingParsed( true );
01608
01609 if ( mRootNode && !mRootNode->processed() )
01610 {
01611 kdWarning() << "The root node is not yet processed! Danger!\n";
01612 return;
01613 } else
01614 delete mRootNode;
01615 mRootNode = partNode::fromMessage( aMsg, this );
01616 const QCString mainCntTypeStr = mRootNode->typeString() + '/' + mRootNode->subTypeString();
01617
01618 QString cntDesc = aMsg->subject();
01619 if( cntDesc.isEmpty() )
01620 cntDesc = i18n("( body part )");
01621 KIO::filesize_t cntSize = aMsg->msgSize();
01622 QString cntEnc;
01623 if( aMsg->contentTransferEncodingStr().isEmpty() )
01624 cntEnc = "7bit";
01625 else
01626 cntEnc = aMsg->contentTransferEncodingStr();
01627
01628
01629 mRootNode->fillMimePartTree( 0,
01630 mMimePartTree,
01631 cntDesc,
01632 mainCntTypeStr,
01633 cntEnc,
01634 cntSize );
01635
01636 partNode* vCardNode = mRootNode->findType( DwMime::kTypeText, DwMime::kSubtypeXVCard );
01637 bool hasVCard = false;
01638 if( vCardNode ) {
01639
01640
01641 KABC::VCardConverter t;
01642 #if defined(KABC_VCARD_ENCODING_FIX)
01643 const QByteArray vcard = vCardNode->msgPart().bodyDecodedBinary();
01644 if ( !t.parseVCardsRaw( vcard.data() ).empty() ) {
01645 #else
01646 const QString vcard = vCardNode->msgPart().bodyToUnicode( overrideCodec() );
01647 if ( !t.parseVCards( vcard ).empty() ) {
01648 #endif
01649 hasVCard = true;
01650 writeMessagePartToTempFile( &vCardNode->msgPart(), vCardNode->nodeId() );
01651 }
01652 }
01653
01654 if ( !mRootNode || !mRootNode->isToltecMessage() || mShowRawToltecMail ) {
01655 htmlWriter()->queue( writeMsgHeader(aMsg, hasVCard ? vCardNode : 0, true ) );
01656 }
01657
01658
01659 ObjectTreeParser otp( this );
01660 otp.setAllowAsync( true );
01661 otp.setShowRawToltecMail( mShowRawToltecMail );
01662 otp.parseObjectTree( mRootNode );
01663
01664
01665
01666 KMMsgEncryptionState encryptionState = mRootNode->overallEncryptionState();
01667 KMMsgSignatureState signatureState = mRootNode->overallSignatureState();
01668
01669 if (aMsg != message()) {
01670 displayMessage();
01671 return;
01672 }
01673 aMsg->setEncryptionState( encryptionState );
01674
01675
01676 if ( signatureState != KMMsgNotSigned ||
01677 aMsg->signatureState() == KMMsgSignatureStateUnknown ) {
01678 aMsg->setSignatureState( signatureState );
01679 }
01680
01681
01682 const bool messageWasReplaced = saveDecryptedMessage( aMsg, &otp, encryptionState );
01683
01684 if( messageWasReplaced ) {
01685 kdDebug(5006) << "KMReaderWin - invoke saving in decrypted form:" << endl;
01686 emit replaceMsgByUnencryptedVersion();
01687 } else {
01688 kdDebug(5006) << "KMReaderWin - finished parsing and displaying of message." << endl;
01689
01690
01691 setIdOfLastViewedMessage( aMsg->msgId() );
01692
01693
01694 const int rootNodeCntType = mRootNode ? mRootNode->type() : DwMime::kTypeText;
01695 const int rootNodeCntSubtype = mRootNode ? mRootNode->subType() : DwMime::kSubtypePlain;
01696 showHideMimeTree( rootNodeCntType == DwMime::kTypeText &&
01697 rootNodeCntSubtype == DwMime::kSubtypePlain );
01698 aMsg->setIsBeingParsed( false );
01699 }
01700 }
01701
01702
01703
01704 QString KMReaderWin::writeMsgHeader( KMMessage* aMsg, partNode *vCardNode, bool topLevel )
01705 {
01706 kdFatal( !headerStyle(), 5006 )
01707 << "trying to writeMsgHeader() without a header style set!" << endl;
01708 kdFatal( !headerStrategy(), 5006 )
01709 << "trying to writeMsgHeader() without a header strategy set!" << endl;
01710 QString href;
01711 if ( vCardNode )
01712 href = vCardNode->asHREF( "body" );
01713
01714 return headerStyle()->format( aMsg, headerStrategy(), href, mPrinting, topLevel );
01715 }
01716
01717
01718
01719
01720 QString KMReaderWin::writeMessagePartToTempFile( KMMessagePart* aMsgPart,
01721 int aPartNum )
01722 {
01723 QString fileName = aMsgPart->fileName();
01724 if( fileName.isEmpty() )
01725 fileName = aMsgPart->name();
01726
01727
01728 QString fname = createTempDir( QString::number( aPartNum ) );
01729 if ( fname.isEmpty() )
01730 return QString();
01731
01732
01733 int slashPos = fileName.findRev( '/' );
01734 if( -1 != slashPos )
01735 fileName = fileName.mid( slashPos + 1 );
01736 if( fileName.isEmpty() )
01737 fileName = "unnamed";
01738 fname += "/" + fileName;
01739
01740 QByteArray data = aMsgPart->bodyDecodedBinary();
01741 size_t size = data.size();
01742 if ( aMsgPart->type() == DwMime::kTypeText && size) {
01743
01744 size = KMail::Util::crlf2lf( data.data(), size );
01745 }
01746 if( !KPIM::kBytesToFile( data.data(), size, fname, false, false, false ) )
01747 return QString::null;
01748
01749 mTempFiles.append( fname );
01750
01751
01752 ::chmod( QFile::encodeName( fname ), S_IRUSR );
01753
01754 return fname;
01755 }
01756
01757 QString KMReaderWin::createTempDir( const QString ¶m )
01758 {
01759 KTempFile *tempFile = new KTempFile( QString::null, "." + param );
01760 tempFile->setAutoDelete( true );
01761 QString fname = tempFile->name();
01762 delete tempFile;
01763
01764 if( ::access( QFile::encodeName( fname ), W_OK ) != 0 )
01765
01766 if( ::mkdir( QFile::encodeName( fname ), 0 ) != 0
01767 || ::chmod( QFile::encodeName( fname ), S_IRWXU ) != 0 )
01768 return QString::null;
01769
01770 assert( !fname.isNull() );
01771
01772 mTempDirs.append( fname );
01773 return fname;
01774 }
01775
01776
01777 void KMReaderWin::showVCard( KMMessagePart *msgPart )
01778 {
01779 #if defined(KABC_VCARD_ENCODING_FIX)
01780 const QByteArray vCard = msgPart->bodyDecodedBinary();
01781 #else
01782 const QString vCard = msgPart->bodyToUnicode( overrideCodec() );
01783 #endif
01784 VCardViewer *vcv = new VCardViewer( this, vCard, "vCardDialog" );
01785 vcv->show();
01786 }
01787
01788
01789 void KMReaderWin::printMsg()
01790 {
01791 if (!message()) return;
01792 mViewer->view()->print();
01793 }
01794
01795
01796
01797 int KMReaderWin::msgPartFromUrl(const KURL &aUrl)
01798 {
01799 if (aUrl.isEmpty()) return -1;
01800 if (!aUrl.isLocalFile()) return -1;
01801
01802 QString path = aUrl.path();
01803 uint right = path.findRev('/');
01804 uint left = path.findRev('.', right);
01805
01806 bool ok;
01807 int res = path.mid(left + 1, right - left - 1).toInt(&ok);
01808 return (ok) ? res : -1;
01809 }
01810
01811
01812
01813 void KMReaderWin::resizeEvent(QResizeEvent *)
01814 {
01815 if( !mResizeTimer.isActive() )
01816 {
01817
01818
01819
01820
01821 mResizeTimer.start( 100, true );
01822 }
01823 }
01824
01825
01826
01827 void KMReaderWin::slotDelayedResize()
01828 {
01829 mSplitter->setGeometry(0, 0, width(), height());
01830 }
01831
01832
01833
01834 void KMReaderWin::slotTouchMessage()
01835 {
01836 if ( !message() )
01837 return;
01838
01839 if ( !message()->isNew() && !message()->isUnread() )
01840 return;
01841
01842 SerNumList serNums;
01843 serNums.append( message()->getMsgSerNum() );
01844 KMCommand *command = new KMSetStatusCommand( KMMsgStatusRead, serNums );
01845 command->start();
01846
01847
01848 if ( mNoMDNsWhenEncrypted &&
01849 message()->encryptionState() != KMMsgNotEncrypted &&
01850 message()->encryptionState() != KMMsgEncryptionStateUnknown )
01851 return;
01852
01853 KMFolder *folder = message()->parent();
01854 if (folder &&
01855 (folder->isOutbox() || folder->isSent() || folder->isTrash() ||
01856 folder->isDrafts() || folder->isTemplates() ) )
01857 return;
01858
01859 if ( KMMessage * receipt = message()->createMDN( MDN::ManualAction,
01860 MDN::Displayed,
01861 true ) )
01862 if ( !kmkernel->msgSender()->send( receipt ) )
01863 KMessageBox::error( this, i18n("Could not send MDN.") );
01864 }
01865
01866
01867
01868 void KMReaderWin::closeEvent(QCloseEvent *e)
01869 {
01870 QWidget::closeEvent(e);
01871 writeConfig();
01872 }
01873
01874
01875 bool foundSMIMEData( const QString aUrl,
01876 QString& displayName,
01877 QString& libName,
01878 QString& keyId )
01879 {
01880 static QString showCertMan("showCertificate#");
01881 displayName = "";
01882 libName = "";
01883 keyId = "";
01884 int i1 = aUrl.find( showCertMan );
01885 if( -1 < i1 ) {
01886 i1 += showCertMan.length();
01887 int i2 = aUrl.find(" ### ", i1);
01888 if( i1 < i2 )
01889 {
01890 displayName = aUrl.mid( i1, i2-i1 );
01891 i1 = i2+5;
01892 i2 = aUrl.find(" ### ", i1);
01893 if( i1 < i2 )
01894 {
01895 libName = aUrl.mid( i1, i2-i1 );
01896 i2 += 5;
01897
01898 keyId = aUrl.mid( i2 );
01899
01900
01901
01902
01903
01904
01905
01906
01907
01908
01909
01910
01911 }
01912 }
01913 }
01914 return !keyId.isEmpty();
01915 }
01916
01917
01918
01919 void KMReaderWin::slotUrlOn(const QString &aUrl)
01920 {
01921 const KURL url(aUrl);
01922
01923 if ( url.protocol() == "kmail" || url.protocol() == "x-kmail" || url.protocol() == "attachment"
01924 || (url.protocol().isEmpty() && url.path().isEmpty()) ) {
01925 mViewer->setDNDEnabled( false );
01926 } else {
01927 mViewer->setDNDEnabled( true );
01928 }
01929
01930 if ( aUrl.stripWhiteSpace().isEmpty() ) {
01931 KPIM::BroadcastStatus::instance()->reset();
01932 mHoveredUrl = KURL();
01933 mLastClickImagePath = QString();
01934 return;
01935 }
01936
01937 mHoveredUrl = url;
01938
01939 const QString msg = URLHandlerManager::instance()->statusBarMessage( url, this );
01940
01941 kdWarning( msg.isEmpty(), 5006 ) << "KMReaderWin::slotUrlOn(): Unhandled URL hover!" << endl;
01942 KPIM::BroadcastStatus::instance()->setTransientStatusMsg( msg );
01943 }
01944
01945
01946
01947 void KMReaderWin::slotUrlOpen(const KURL &aUrl, const KParts::URLArgs &)
01948 {
01949 mClickedUrl = aUrl;
01950
01951 if ( URLHandlerManager::instance()->handleClick( aUrl, this ) )
01952 return;
01953
01954 kdWarning( 5006 ) << "KMReaderWin::slotOpenUrl(): Unhandled URL click!" << endl;
01955 emit urlClicked( aUrl, Qt::LeftButton );
01956 }
01957
01958
01959 void KMReaderWin::slotUrlPopup(const QString &aUrl, const QPoint& aPos)
01960 {
01961 const KURL url( aUrl );
01962 mClickedUrl = url;
01963
01964 if ( url.protocol() == "mailto" ) {
01965 mCopyURLAction->setText( i18n( "Copy Email Address" ) );
01966 } else {
01967 mCopyURLAction->setText( i18n( "Copy Link Address" ) );
01968 }
01969
01970 if ( URLHandlerManager::instance()->handleContextMenuRequest( url, aPos, this ) )
01971 return;
01972
01973 if ( message() ) {
01974 kdWarning( 5006 ) << "KMReaderWin::slotUrlPopup(): Unhandled URL right-click!" << endl;
01975 emitPopupMenu( url, aPos );
01976 }
01977 }
01978
01979
01980
01981 static bool hasParentDivWithId( const DOM::Node &start, const QString &id )
01982 {
01983 if ( start.isNull() )
01984 return false;
01985
01986 if ( start.nodeName().string() == "div" ) {
01987 for ( unsigned int i = 0; i < start.attributes().length(); i++ ) {
01988 if ( start.attributes().item( i ).nodeName().string() == "id" &&
01989 start.attributes().item( i ).nodeValue().string() == id )
01990 return true;
01991 }
01992 }
01993
01994 if ( !start.parentNode().isNull() )
01995 return hasParentDivWithId( start.parentNode(), id );
01996 else return false;
01997 }
01998
01999
02000 void KMReaderWin::showAttachmentPopup( int id, const QString & name, const QPoint & p )
02001 {
02002 mAtmCurrent = id;
02003 mAtmCurrentName = name;
02004 KPopupMenu *menu = new KPopupMenu();
02005 menu->insertItem(SmallIcon("fileopen"),i18n("to open", "Open"), 1);
02006 menu->insertItem(i18n("Open With..."), 2);
02007 menu->insertItem(i18n("to view something", "View"), 3);
02008 menu->insertItem(SmallIcon("filesaveas"),i18n("Save As..."), 4);
02009 menu->insertItem(SmallIcon("editcopy"), i18n("Copy"), 9 );
02010 const bool canChange = message()->parent() ? !message()->parent()->isReadOnly() : false;
02011 if ( GlobalSettings::self()->allowAttachmentEditing() && canChange )
02012 menu->insertItem(SmallIcon("edit"), i18n("Edit Attachment"), 8 );
02013 if ( GlobalSettings::self()->allowAttachmentDeletion() && canChange )
02014 menu->insertItem(SmallIcon("editdelete"), i18n("Delete Attachment"), 7 );
02015 if ( name.endsWith( ".xia", false ) &&
02016 Kleo::CryptoBackendFactory::instance()->protocol( "Chiasmus" ) )
02017 menu->insertItem( i18n( "Decrypt With Chiasmus..." ), 6 );
02018 menu->insertItem(i18n("Properties"), 5);
02019
02020 const bool attachmentInHeader = hasParentDivWithId( mViewer->nodeUnderMouse(), "attachmentInjectionPoint" );
02021 const bool hasScrollbar = mViewer->view()->verticalScrollBar()->isVisible();
02022 if ( attachmentInHeader && hasScrollbar ) {
02023 menu->insertItem( i18n("Scroll To"), 10 );
02024 }
02025
02026 connect(menu, SIGNAL(activated(int)), this, SLOT(slotHandleAttachment(int)));
02027 menu->exec( p ,0 );
02028 delete menu;
02029 }
02030
02031
02032 void KMReaderWin::setStyleDependantFrameWidth()
02033 {
02034 if ( !mBox )
02035 return;
02036
02037 int frameWidth;
02038 if( style().isA("KeramikStyle") )
02039 frameWidth = style().pixelMetric( QStyle::PM_DefaultFrameWidth ) - 1;
02040 else
02041 frameWidth = style().pixelMetric( QStyle::PM_DefaultFrameWidth );
02042 if ( frameWidth < 0 )
02043 frameWidth = 0;
02044 if ( frameWidth != mBox->lineWidth() )
02045 mBox->setLineWidth( frameWidth );
02046 }
02047
02048
02049 void KMReaderWin::styleChange( QStyle& oldStyle )
02050 {
02051 setStyleDependantFrameWidth();
02052 QWidget::styleChange( oldStyle );
02053 }
02054
02055
02056 void KMReaderWin::slotHandleAttachment( int choice )
02057 {
02058 mAtmUpdate = true;
02059 partNode* node = mRootNode ? mRootNode->findId( mAtmCurrent ) : 0;
02060 if ( mAtmCurrentName.isEmpty() && node )
02061 mAtmCurrentName = tempFileUrlFromPartNode( node ).path();
02062 if ( choice < 7 ) {
02063 KMHandleAttachmentCommand* command = new KMHandleAttachmentCommand(
02064 node, message(), mAtmCurrent, mAtmCurrentName,
02065 KMHandleAttachmentCommand::AttachmentAction( choice ), 0, this );
02066 connect( command, SIGNAL( showAttachment( int, const QString& ) ),
02067 this, SLOT( slotAtmView( int, const QString& ) ) );
02068 command->start();
02069 } else if ( choice == 7 ) {
02070 slotDeleteAttachment( node );
02071 } else if ( choice == 8 ) {
02072 slotEditAttachment( node );
02073 } else if ( choice == 9 ) {
02074 if ( !node ) return;
02075 KURL::List urls;
02076 KURL url = tempFileUrlFromPartNode( node );
02077 if (!url.isValid() ) return;
02078 urls.append( url );
02079 KURLDrag* drag = new KURLDrag( urls, this );
02080 QApplication::clipboard()->setData( drag, QClipboard::Clipboard );
02081 } else if ( choice == 10 ) {
02082 scrollToAttachment( node );
02083 }
02084 }
02085
02086
02087 void KMReaderWin::slotFind()
02088 {
02089 mViewer->findText();
02090 }
02091
02092
02093 void KMReaderWin::slotFindNext()
02094 {
02095 mViewer->findTextNext();
02096 }
02097
02098
02099 void KMReaderWin::slotToggleFixedFont()
02100 {
02101 mUseFixedFont = !mUseFixedFont;
02102 saveRelativePosition();
02103 update(true);
02104 }
02105
02106
02107
02108 void KMReaderWin::slotCopySelectedText()
02109 {
02110 kapp->clipboard()->setText( mViewer->selectedText() );
02111 }
02112
02113
02114
02115 void KMReaderWin::atmViewMsg( KMMessagePart* aMsgPart, int nodeId )
02116 {
02117 assert(aMsgPart!=0);
02118 KMMessage* msg = new KMMessage;
02119 msg->fromString(aMsgPart->bodyDecoded());
02120 assert(msg != 0);
02121 msg->setMsgSerNum( 0 );
02122
02123 msg->setParent( message()->parent() );
02124 msg->setUID(message()->UID());
02125 msg->setReadyToShow(true);
02126 KMReaderMainWin *win = new KMReaderMainWin();
02127 win->showMsg( overrideEncoding(), msg, message()->getMsgSerNum(), nodeId );
02128 win->show();
02129 }
02130
02131
02132 void KMReaderWin::setMsgPart( partNode * node ) {
02133 htmlWriter()->reset();
02134 mColorBar->hide();
02135 htmlWriter()->begin( mCSSHelper->cssDefinitions( isFixedFont() ) );
02136 htmlWriter()->write( mCSSHelper->htmlHead( isFixedFont() ) );
02137
02138 if ( node ) {
02139 ObjectTreeParser otp( this, 0, true );
02140 otp.parseObjectTree( node );
02141 }
02142
02143 htmlWriter()->queue( "</body></html>" );
02144 htmlWriter()->flush();
02145 }
02146
02147
02148 void KMReaderWin::setMsgPart( KMMessagePart* aMsgPart, bool aHTML,
02149 const QString& aFileName, const QString& pname )
02150 {
02151 KCursorSaver busy(KBusyPtr::busy());
02152 if (kasciistricmp(aMsgPart->typeStr(), "message")==0) {
02153
02154 KMMessage* msg = new KMMessage;
02155 assert(aMsgPart!=0);
02156 msg->fromString(aMsgPart->bodyDecoded());
02157 mMainWindow->setCaption(msg->subject());
02158 setMsg(msg, true);
02159 setAutoDelete(true);
02160 } else if (kasciistricmp(aMsgPart->typeStr(), "text")==0) {
02161 if (kasciistricmp(aMsgPart->subtypeStr(), "x-vcard") == 0) {
02162 showVCard( aMsgPart );
02163 return;
02164 }
02165 htmlWriter()->begin( mCSSHelper->cssDefinitions( isFixedFont() ) );
02166 htmlWriter()->queue( mCSSHelper->htmlHead( isFixedFont() ) );
02167
02168 if (aHTML && (kasciistricmp(aMsgPart->subtypeStr(), "html")==0)) {
02169
02170 htmlWriter()->queue( aMsgPart->bodyToUnicode( overrideCodec() ) );
02171 mColorBar->setHtmlMode();
02172 } else {
02173 const QCString str = aMsgPart->bodyDecoded();
02174 ObjectTreeParser otp( this );
02175 otp.writeBodyStr( str,
02176 overrideCodec() ? overrideCodec() : aMsgPart->codec(),
02177 message() ? message()->from() : QString::null );
02178 }
02179 htmlWriter()->queue("</body></html>");
02180 htmlWriter()->flush();
02181 mMainWindow->setCaption(i18n("View Attachment: %1").arg(pname));
02182 } else if (kasciistricmp(aMsgPart->typeStr(), "image")==0 ||
02183 (kasciistricmp(aMsgPart->typeStr(), "application")==0 &&
02184 kasciistricmp(aMsgPart->subtypeStr(), "postscript")==0))
02185 {
02186 if (aFileName.isEmpty()) return;
02187
02188 QImageIO *iio = new QImageIO();
02189 iio->setFileName(aFileName);
02190 if( iio->read() ) {
02191 QImage img = iio->image();
02192 QRect desk = KGlobalSettings::desktopGeometry(mMainWindow);
02193
02194 int width, height;
02195 if( img.width() < 50 )
02196 width = 70;
02197 else if( img.width()+20 < desk.width() )
02198 width = img.width()+20;
02199 else
02200 width = desk.width();
02201 if( img.height() < 50 )
02202 height = 70;
02203 else if( img.height()+20 < desk.height() )
02204 height = img.height()+20;
02205 else
02206 height = desk.height();
02207 mMainWindow->resize( width, height );
02208 }
02209
02210 htmlWriter()->begin( mCSSHelper->cssDefinitions( isFixedFont() ) );
02211 htmlWriter()->write( mCSSHelper->htmlHead( isFixedFont() ) );
02212 htmlWriter()->write( "<img src=\"file:" +
02213 KURL::encode_string( aFileName ) +
02214 "\" border=\"0\">\n"
02215 "</body></html>\n" );
02216 htmlWriter()->end();
02217 setCaption( i18n("View Attachment: %1").arg( pname ) );
02218 show();
02219 delete iio;
02220 } else {
02221 htmlWriter()->begin( mCSSHelper->cssDefinitions( isFixedFont() ) );
02222 htmlWriter()->queue( mCSSHelper->htmlHead( isFixedFont() ) );
02223 htmlWriter()->queue( "<pre>" );
02224
02225 QString str = aMsgPart->bodyDecoded();
02226
02227
02228 if( str.length() < (unsigned) aMsgPart->decodedSize() ) {
02229 str.prepend( i18n("[KMail: Attachment contains binary data. Trying to show first character.]",
02230 "[KMail: Attachment contains binary data. Trying to show first %n characters.]",
02231 str.length()) + QChar('\n') );
02232 }
02233 htmlWriter()->queue( QStyleSheet::escape( str ) );
02234 htmlWriter()->queue( "</pre>" );
02235 htmlWriter()->queue("</body></html>");
02236 htmlWriter()->flush();
02237 mMainWindow->setCaption(i18n("View Attachment: %1").arg(pname));
02238 }
02239
02240 }
02241
02242
02243
02244 void KMReaderWin::slotAtmView( int id, const QString& name )
02245 {
02246 partNode* node = mRootNode ? mRootNode->findId( id ) : 0;
02247 if( node ) {
02248 mAtmCurrent = id;
02249 mAtmCurrentName = name;
02250 if ( mAtmCurrentName.isEmpty() )
02251 mAtmCurrentName = tempFileUrlFromPartNode( node ).path();
02252
02253 KMMessagePart& msgPart = node->msgPart();
02254 QString pname = msgPart.fileName();
02255 if (pname.isEmpty()) pname=msgPart.name();
02256 if (pname.isEmpty()) pname=msgPart.contentDescription();
02257 if (pname.isEmpty()) pname="unnamed";
02258
02259 if (kasciistricmp(msgPart.typeStr(), "message")==0) {
02260 atmViewMsg( &msgPart,id );
02261 } else if ((kasciistricmp(msgPart.typeStr(), "text")==0) &&
02262 (kasciistricmp(msgPart.subtypeStr(), "x-vcard")==0)) {
02263 setMsgPart( &msgPart, htmlMail(), name, pname );
02264 } else {
02265 KMReaderMainWin *win = new KMReaderMainWin(&msgPart, htmlMail(),
02266 name, pname, overrideEncoding() );
02267 win->show();
02268 }
02269 }
02270 }
02271
02272
02273 void KMReaderWin::openAttachment( int id, const QString & name )
02274 {
02275 mAtmCurrentName = name;
02276 mAtmCurrent = id;
02277
02278 QString str, pname, cmd, fileName;
02279
02280 partNode* node = mRootNode ? mRootNode->findId( id ) : 0;
02281 if( !node ) {
02282 kdWarning(5006) << "KMReaderWin::openAttachment - could not find node " << id << endl;
02283 return;
02284 }
02285 if ( mAtmCurrentName.isEmpty() )
02286 mAtmCurrentName = tempFileUrlFromPartNode( node ).path();
02287
02288 KMMessagePart& msgPart = node->msgPart();
02289 if (kasciistricmp(msgPart.typeStr(), "message")==0)
02290 {
02291 atmViewMsg( &msgPart, id );
02292 return;
02293 }
02294
02295 QCString contentTypeStr( msgPart.typeStr() + '/' + msgPart.subtypeStr() );
02296 KPIM::kAsciiToLower( contentTypeStr.data() );
02297
02298 if ( qstrcmp( contentTypeStr, "text/x-vcard" ) == 0 ) {
02299 showVCard( &msgPart );
02300 return;
02301 }
02302
02303
02304 KMimeType::Ptr mimetype;
02305
02306 mimetype = KMimeType::mimeType( QString::fromLatin1( contentTypeStr ) );
02307 if ( mimetype->name() == "application/octet-stream" ) {
02308
02309 mimetype = KMimeType::findByPath( name, 0, true );
02310 }
02311 if ( ( mimetype->name() == "application/octet-stream" )
02312 && msgPart.isComplete() ) {
02313
02314
02315 mimetype = KMimeType::findByFileContent( name );
02316 }
02317
02318 KService::Ptr offer =
02319 KServiceTypeProfile::preferredService( mimetype->name(), "Application" );
02320
02321 QString open_text;
02322 QString filenameText = msgPart.fileName();
02323 if ( filenameText.isEmpty() )
02324 filenameText = msgPart.name();
02325 if ( offer ) {
02326 open_text = i18n("&Open with '%1'").arg( offer->name() );
02327 } else {
02328 open_text = i18n("&Open With...");
02329 }
02330 const QString text = i18n("Open attachment '%1'?\n"
02331 "Note that opening an attachment may compromise "
02332 "your system's security.")
02333 .arg( filenameText );
02334 const int choice = KMessageBox::questionYesNoCancel( this, text,
02335 i18n("Open Attachment?"), KStdGuiItem::saveAs(), open_text,
02336 QString::fromLatin1("askSave") + mimetype->name() );
02337
02338 if( choice == KMessageBox::Yes ) {
02339 mAtmUpdate = true;
02340 KMHandleAttachmentCommand* command = new KMHandleAttachmentCommand( node,
02341 message(), mAtmCurrent, mAtmCurrentName, KMHandleAttachmentCommand::Save,
02342 offer, this );
02343 connect( command, SIGNAL( showAttachment( int, const QString& ) ),
02344 this, SLOT( slotAtmView( int, const QString& ) ) );
02345 command->start();
02346 }
02347 else if( choice == KMessageBox::No ) {
02348 KMHandleAttachmentCommand::AttachmentAction action = ( offer ?
02349 KMHandleAttachmentCommand::Open : KMHandleAttachmentCommand::OpenWith );
02350 mAtmUpdate = true;
02351 KMHandleAttachmentCommand* command = new KMHandleAttachmentCommand( node,
02352 message(), mAtmCurrent, mAtmCurrentName, action, offer, this );
02353 connect( command, SIGNAL( showAttachment( int, const QString& ) ),
02354 this, SLOT( slotAtmView( int, const QString& ) ) );
02355 command->start();
02356 } else {
02357 kdDebug(5006) << "Canceled opening attachment" << endl;
02358 }
02359 }
02360
02361
02362 void KMReaderWin::slotScrollUp()
02363 {
02364 static_cast<QScrollView *>(mViewer->widget())->scrollBy(0, -10);
02365 }
02366
02367
02368
02369 void KMReaderWin::slotScrollDown()
02370 {
02371 static_cast<QScrollView *>(mViewer->widget())->scrollBy(0, 10);
02372 }
02373
02374 bool KMReaderWin::atBottom() const
02375 {
02376 const QScrollView *view = static_cast<const QScrollView *>(mViewer->widget());
02377 return view->contentsY() + view->visibleHeight() >= view->contentsHeight();
02378 }
02379
02380
02381 void KMReaderWin::slotJumpDown()
02382 {
02383 QScrollView *view = static_cast<QScrollView *>(mViewer->widget());
02384 int offs = (view->clipper()->height() < 30) ? view->clipper()->height() : 30;
02385 view->scrollBy( 0, view->clipper()->height() - offs );
02386 }
02387
02388
02389 void KMReaderWin::slotScrollPrior()
02390 {
02391 static_cast<QScrollView *>(mViewer->widget())->scrollBy(0, -(int)(height()*0.8));
02392 }
02393
02394
02395
02396 void KMReaderWin::slotScrollNext()
02397 {
02398 static_cast<QScrollView *>(mViewer->widget())->scrollBy(0, (int)(height()*0.8));
02399 }
02400
02401
02402 void KMReaderWin::slotDocumentChanged()
02403 {
02404
02405 }
02406
02407
02408
02409 void KMReaderWin::slotTextSelected(bool)
02410 {
02411 QString temp = mViewer->selectedText();
02412 kapp->clipboard()->setText(temp);
02413 }
02414
02415
02416 void KMReaderWin::selectAll()
02417 {
02418 mViewer->selectAll();
02419 }
02420
02421
02422 QString KMReaderWin::copyText()
02423 {
02424 QString temp = mViewer->selectedText();
02425 return temp;
02426 }
02427
02428
02429
02430 void KMReaderWin::slotDocumentDone()
02431 {
02432
02433 }
02434
02435
02436
02437 void KMReaderWin::setHtmlOverride(bool override)
02438 {
02439 mHtmlOverride = override;
02440 if (message())
02441 message()->setDecodeHTML(htmlMail());
02442 }
02443
02444
02445
02446 void KMReaderWin::setHtmlLoadExtOverride(bool override)
02447 {
02448 mHtmlLoadExtOverride = override;
02449
02450
02451 }
02452
02453
02454
02455 bool KMReaderWin::htmlMail()
02456 {
02457 return ((mHtmlMail && !mHtmlOverride) || (!mHtmlMail && mHtmlOverride));
02458 }
02459
02460
02461
02462 bool KMReaderWin::htmlLoadExternal()
02463 {
02464 return ((mHtmlLoadExternal && !mHtmlLoadExtOverride) ||
02465 (!mHtmlLoadExternal && mHtmlLoadExtOverride));
02466 }
02467
02468
02469
02470 void KMReaderWin::saveRelativePosition()
02471 {
02472 const QScrollView * scrollview = static_cast<QScrollView *>( mViewer->widget() );
02473 mSavedRelativePosition =
02474 static_cast<float>( scrollview->contentsY() ) / scrollview->contentsHeight();
02475 }
02476
02477
02478
02479 void KMReaderWin::update( bool force )
02480 {
02481 KMMessage* msg = message();
02482 if ( msg )
02483 setMsg( msg, force, true );
02484 }
02485
02486
02487
02488 KMMessage* KMReaderWin::message( KMFolder** aFolder ) const
02489 {
02490 KMFolder* tmpFolder;
02491 KMFolder*& folder = aFolder ? *aFolder : tmpFolder;
02492 folder = 0;
02493 if (mMessage)
02494 return mMessage;
02495 if (mLastSerNum) {
02496 KMMessage *message = 0;
02497 int index;
02498 KMMsgDict::instance()->getLocation( mLastSerNum, &folder, &index );
02499 if (folder )
02500 message = folder->getMsg( index );
02501 if (!message)
02502 kdWarning(5006) << "Attempt to reference invalid serial number " << mLastSerNum << "\n" << endl;
02503 return message;
02504 }
02505 return 0;
02506 }
02507
02508
02509
02510
02511 void KMReaderWin::slotUrlClicked()
02512 {
02513 KMMainWidget *mainWidget = dynamic_cast<KMMainWidget*>(mMainWindow);
02514 uint identity = 0;
02515 if ( message() && message()->parent() ) {
02516 identity = message()->parent()->identity();
02517 }
02518
02519 KMCommand *command = new KMUrlClickedCommand( mClickedUrl, identity, this,
02520 false, mainWidget );
02521 command->start();
02522 }
02523
02524
02525 void KMReaderWin::slotMailtoCompose()
02526 {
02527 KMCommand *command = new KMMailtoComposeCommand( mClickedUrl, message() );
02528 command->start();
02529 }
02530
02531
02532 void KMReaderWin::slotMailtoForward()
02533 {
02534 KMCommand *command = new KMMailtoForwardCommand( mMainWindow, mClickedUrl,
02535 message() );
02536 command->start();
02537 }
02538
02539
02540 void KMReaderWin::slotMailtoAddAddrBook()
02541 {
02542 KMCommand *command = new KMMailtoAddAddrBookCommand( mClickedUrl,
02543 mMainWindow);
02544 command->start();
02545 }
02546
02547
02548 void KMReaderWin::slotMailtoOpenAddrBook()
02549 {
02550 KMCommand *command = new KMMailtoOpenAddrBookCommand( mClickedUrl,
02551 mMainWindow );
02552 command->start();
02553 }
02554
02555
02556 void KMReaderWin::slotUrlCopy()
02557 {
02558
02559
02560 KMCommand *command =
02561 new KMUrlCopyCommand( mClickedUrl,
02562 dynamic_cast<KMMainWidget*>( mMainWindow ) );
02563 command->start();
02564 }
02565
02566
02567 void KMReaderWin::slotUrlOpen( const KURL &url )
02568 {
02569 if ( !url.isEmpty() )
02570 mClickedUrl = url;
02571 KMCommand *command = new KMUrlOpenCommand( mClickedUrl, this );
02572 command->start();
02573 }
02574
02575
02576 void KMReaderWin::slotAddBookmarks()
02577 {
02578 KMCommand *command = new KMAddBookmarksCommand( mClickedUrl, this );
02579 command->start();
02580 }
02581
02582
02583 void KMReaderWin::slotUrlSave()
02584 {
02585 KMCommand *command = new KMUrlSaveCommand( mClickedUrl, mMainWindow );
02586 command->start();
02587 }
02588
02589
02590 void KMReaderWin::slotMailtoReply()
02591 {
02592 KMCommand *command = new KMMailtoReplyCommand( mMainWindow, mClickedUrl,
02593 message(), copyText() );
02594 command->start();
02595 }
02596
02597
02598 partNode * KMReaderWin::partNodeFromUrl( const KURL & url ) {
02599 return mRootNode ? mRootNode->findId( msgPartFromUrl( url ) ) : 0 ;
02600 }
02601
02602 partNode * KMReaderWin::partNodeForId( int id ) {
02603 return mRootNode ? mRootNode->findId( id ) : 0 ;
02604 }
02605
02606
02607 KURL KMReaderWin::tempFileUrlFromPartNode( const partNode * node )
02608 {
02609 if (!node) return KURL();
02610 QStringList::const_iterator it = mTempFiles.begin();
02611 QStringList::const_iterator end = mTempFiles.end();
02612
02613 while ( it != end ) {
02614 QString path = *it;
02615 it++;
02616 uint right = path.findRev('/');
02617 uint left = path.findRev('.', right);
02618
02619 bool ok;
02620 int res = path.mid(left + 1, right - left - 1).toInt(&ok);
02621 if ( res == node->nodeId() )
02622 return KURL( path );
02623 }
02624 return KURL();
02625 }
02626
02627
02628 void KMReaderWin::slotSaveAttachments()
02629 {
02630 mAtmUpdate = true;
02631 KMSaveAttachmentsCommand *saveCommand = new KMSaveAttachmentsCommand( mMainWindow,
02632 message() );
02633 saveCommand->start();
02634 }
02635
02636
02637 void KMReaderWin::saveAttachment( const KURL &tempFileName )
02638 {
02639 mAtmCurrent = msgPartFromUrl( tempFileName );
02640 mAtmCurrentName = mClickedUrl.path();
02641 slotHandleAttachment( KMHandleAttachmentCommand::Save );
02642 }
02643
02644
02645 void KMReaderWin::slotSaveMsg()
02646 {
02647 KMSaveMsgCommand *saveCommand = new KMSaveMsgCommand( mMainWindow, message() );
02648
02649 if (saveCommand->url().isEmpty())
02650 delete saveCommand;
02651 else
02652 saveCommand->start();
02653 }
02654
02655 void KMReaderWin::slotIMChat()
02656 {
02657 KMCommand *command = new KMIMChatCommand( mClickedUrl, message() );
02658 command->start();
02659 }
02660
02661
02662 static QString linkForNode( const DOM::Node &node )
02663 {
02664 try {
02665 if ( node.isNull() )
02666 return QString();
02667
02668 const DOM::NamedNodeMap attributes = node.attributes();
02669 if ( !attributes.isNull() ) {
02670 const DOM::Node href = attributes.getNamedItem( DOM::DOMString( "href" ) );
02671 if ( !href.isNull() ) {
02672 return href.nodeValue().string();
02673 }
02674 }
02675 if ( !node.parentNode().isNull() ) {
02676 return linkForNode( node.parentNode() );
02677 } else {
02678 return QString();
02679 }
02680 } catch ( DOM::DOMException &e ) {
02681 kdWarning(5006) << "Got an exception when trying to determine link under cursor!" << endl;
02682 return QString();
02683 }
02684 }
02685
02686
02687 bool KMReaderWin::eventFilter( QObject *, QEvent *e )
02688 {
02689 if ( e->type() == QEvent::MouseButtonPress ) {
02690 QMouseEvent* me = static_cast<QMouseEvent*>(e);
02691 if ( me->button() == LeftButton && ( me->state() & ShiftButton ) ) {
02692
02693 URLHandlerManager::instance()->handleShiftClick( mHoveredUrl, this );
02694 return true;
02695 }
02696
02697 if ( me->button() == LeftButton ) {
02698
02699 QString imagePath;
02700 const DOM::Node nodeUnderMouse = mViewer->nodeUnderMouse();
02701 if ( !nodeUnderMouse.isNull() ) {
02702 const DOM::NamedNodeMap attributes = nodeUnderMouse.attributes();
02703 if ( !attributes.isNull() ) {
02704 const DOM::Node src = attributes.getNamedItem( DOM::DOMString( "src" ) );
02705 if ( !src.isNull() ) {
02706 imagePath = src.nodeValue().string();
02707 }
02708 }
02709 }
02710
02711 mCanStartDrag = URLHandlerManager::instance()->willHandleDrag( mHoveredUrl, imagePath, this );
02712 mLastClickPosition = me->pos();
02713 mLastClickImagePath = imagePath;
02714 }
02715 }
02716
02717 if ( e->type() == QEvent::MouseButtonRelease ) {
02718 mCanStartDrag = false;
02719 }
02720
02721 if ( e->type() == QEvent::MouseMove ) {
02722 QMouseEvent* me = static_cast<QMouseEvent*>( e );
02723
02724
02725
02726 slotUrlOn( linkForNode( mViewer->nodeUnderMouse() ) );
02727
02728 if ( ( mLastClickPosition - me->pos() ).manhattanLength() > KGlobalSettings::dndEventDelay() ) {
02729 if ( mCanStartDrag && ( !( mHoveredUrl.isEmpty() && mLastClickImagePath.isEmpty() ) ) ) {
02730 if ( URLHandlerManager::instance()->handleDrag( mHoveredUrl, mLastClickImagePath, this ) ) {
02731 mCanStartDrag = false;
02732 slotUrlOn( QString() );
02733
02734
02735
02736
02737 QMouseEvent mouseEvent( QEvent::MouseButtonRelease, me->pos(), Qt::NoButton, Qt::NoButton );
02738 static_cast<QObject*>( mViewer->view() )->eventFilter( mViewer->view()->viewport(),
02739 &mouseEvent );
02740 return true;
02741 }
02742 }
02743 }
02744 }
02745
02746
02747 return false;
02748 }
02749
02750 void KMReaderWin::fillCommandInfo( partNode *node, KMMessage **msg, int *nodeId )
02751 {
02752 Q_ASSERT( msg && nodeId );
02753
02754 if ( mSerNumOfOriginalMessage != 0 ) {
02755 KMFolder *folder = 0;
02756 int index = -1;
02757 KMMsgDict::instance()->getLocation( mSerNumOfOriginalMessage, &folder, &index );
02758 if ( folder && index != -1 )
02759 *msg = folder->getMsg( index );
02760
02761 if ( !( *msg ) ) {
02762 kdWarning( 5006 ) << "Unable to find the original message, aborting attachment deletion!" << endl;
02763 return;
02764 }
02765
02766 *nodeId = node->nodeId() + mNodeIdOffset;
02767 }
02768 else {
02769 *nodeId = node->nodeId();
02770 *msg = message();
02771 }
02772 }
02773
02774 void KMReaderWin::slotDeleteAttachment(partNode * node)
02775 {
02776 if ( KMessageBox::warningContinueCancel( this,
02777 i18n("Deleting an attachment might invalidate any digital signature on this message."),
02778 i18n("Delete Attachment"), KStdGuiItem::del(), "DeleteAttachmentSignatureWarning" )
02779 != KMessageBox::Continue ) {
02780 return;
02781 }
02782
02783 int nodeId = -1;
02784 KMMessage *msg = 0;
02785 fillCommandInfo( node, &msg, &nodeId );
02786 if ( msg && nodeId != -1 ) {
02787 KMDeleteAttachmentCommand* command = new KMDeleteAttachmentCommand( nodeId, msg, this );
02788 command->start();
02789 connect( command, SIGNAL( completed( KMCommand * ) ),
02790 this, SLOT( updateReaderWin() ) );
02791 connect( command, SIGNAL( completed( KMCommand * ) ),
02792 this, SLOT( disconnectMsgAdded() ) );
02793
02794
02795
02796
02797
02798
02799 const KMHeaders * const headers = KMKernel::self()->getKMMainWidget()->headers();
02800 connect( headers, SIGNAL( msgAddedToListView( QListViewItem* ) ),
02801 this, SLOT( msgAdded( QListViewItem* ) ) );
02802 }
02803
02804
02805 if ( mSerNumOfOriginalMessage != 0 && message() ) {
02806 message()->deleteBodyPart( node->nodeId() );
02807 update( true );
02808 }
02809 }
02810
02811 void KMReaderWin::msgAdded( QListViewItem *item )
02812 {
02813
02814
02815
02816 disconnectMsgAdded();
02817 KMHeaders * const headers = KMKernel::self()->getKMMainWidget()->headers();
02818 headers->setCurrentItem( item );
02819 headers->clearSelection();
02820 headers->setSelected( item, true );
02821 }
02822
02823 void KMReaderWin::disconnectMsgAdded()
02824 {
02825 const KMHeaders *const headers = KMKernel::self()->getKMMainWidget()->headers();
02826 disconnect( headers, SIGNAL( msgAddedToListView( QListViewItem* ) ),
02827 this, SLOT( msgAdded( QListViewItem* ) ) );
02828 }
02829
02830 void KMReaderWin::slotEditAttachment(partNode * node)
02831 {
02832 if ( KMessageBox::warningContinueCancel( this,
02833 i18n("Modifying an attachment might invalidate any digital signature on this message."),
02834 i18n("Edit Attachment"), KGuiItem( i18n("Edit"), "edit" ), "EditAttachmentSignatureWarning" )
02835 != KMessageBox::Continue ) {
02836 return;
02837 }
02838
02839 int nodeId = -1;
02840 KMMessage *msg = 0;
02841 fillCommandInfo( node, &msg, &nodeId );
02842 if ( msg && nodeId != -1 ) {
02843 KMEditAttachmentCommand* command = new KMEditAttachmentCommand( nodeId, msg, this );
02844 command->start();
02845 }
02846
02847
02848 }
02849
02850 KMail::CSSHelper* KMReaderWin::cssHelper()
02851 {
02852 return mCSSHelper;
02853 }
02854
02855 bool KMReaderWin::decryptMessage() const
02856 {
02857 if ( !GlobalSettings::self()->alwaysDecrypt() )
02858 return mDecrytMessageOverwrite;
02859 return true;
02860 }
02861
02862 void KMReaderWin::scrollToAttachment( const partNode *node )
02863 {
02864 DOM::Document doc = mViewer->htmlDocument();
02865
02866
02867 mViewer->gotoAnchor( QString::fromLatin1( "att%1" ).arg( node->nodeId() ) );
02868
02869
02870 const partNode *root = node->topLevelParent();
02871 for ( int i = 0; i <= root->totalChildCount() + 1; i++ ) {
02872 DOM::Element attachmentDiv = doc.getElementById( QString( "attachmentDiv%1" ).arg( i + 1 ) );
02873 if ( !attachmentDiv.isNull() )
02874 attachmentDiv.removeAttribute( "style" );
02875 }
02876
02877
02878 if ( node->isDisplayedHidden() )
02879 return;
02880
02881
02882
02883
02884 DOM::Element attachmentDiv = doc.getElementById( QString( "attachmentDiv%1" ).arg( node->nodeId() ) );
02885 if ( attachmentDiv.isNull() ) {
02886 kdWarning( 5006 ) << "Could not find attachment div for attachment " << node->nodeId() << endl;
02887 return;
02888 }
02889
02890 attachmentDiv.setAttribute( "style", QString( "border:2px solid %1" )
02891 .arg( cssHelper()->pgpWarnColor().name() ) );
02892
02893
02894
02895 doc.updateRendering();
02896 }
02897
02898 void KMReaderWin::injectAttachments()
02899 {
02900
02901
02902 DOM::Document doc = mViewer->htmlDocument();
02903 DOM::Element injectionPoint = doc.getElementById( "attachmentInjectionPoint" );
02904 if ( injectionPoint.isNull() )
02905 return;
02906
02907 QString imgpath( locate("data","kmail/pics/") );
02908 QString visibility;
02909 QString urlHandle;
02910 QString imgSrc;
02911 if( !showAttachmentQuicklist() ) {
02912 urlHandle.append( "kmail:showAttachmentQuicklist" );
02913 imgSrc.append( "attachmentQuicklistClosed.png" );
02914 } else {
02915 urlHandle.append( "kmail:hideAttachmentQuicklist" );
02916 imgSrc.append( "attachmentQuicklistOpened.png" );
02917 }
02918
02919 QString html = renderAttachments( mRootNode, QApplication::palette().active().background() );
02920 if ( html.isEmpty() )
02921 return;
02922
02923 QString link("");
02924 if ( headerStyle() == HeaderStyle::fancy() ) {
02925 link += "<div style=\"text-align: left;\"><a href=\"" + urlHandle + "\"><img src=\"" +
02926 imgpath + imgSrc + "\"/></a></div>";
02927 html.prepend( link );
02928 html.prepend( QString::fromLatin1( "<div style=\"float:left;\">%1 </div>" ).
02929 arg( i18n( "Attachments:" ) ) );
02930 } else {
02931 link += "<div style=\"text-align: right;\"><a href=\"" + urlHandle + "\"><img src=\"" +
02932 imgpath + imgSrc + "\"/></a></div>";
02933 html.prepend( link );
02934 }
02935
02936 assert( injectionPoint.tagName() == "div" );
02937 static_cast<DOM::HTMLElement>( injectionPoint ).setInnerHTML( html );
02938 }
02939
02940 static QColor nextColor( const QColor & c )
02941 {
02942 int h, s, v;
02943 c.hsv( &h, &s, &v );
02944 return QColor( (h + 50) % 360, QMAX(s, 64), v, QColor::Hsv );
02945 }
02946
02947 QString KMReaderWin::renderAttachments(partNode * node, const QColor &bgColor )
02948 {
02949 if ( !node )
02950 return QString();
02951
02952 QString html;
02953 if ( node->firstChild() ) {
02954 QString subHtml = renderAttachments( node->firstChild(), nextColor( bgColor ) );
02955 if ( !subHtml.isEmpty() ) {
02956
02957 QString visibility;
02958 if ( !showAttachmentQuicklist() ) {
02959 visibility.append( "display:none;" );
02960 }
02961
02962 QString margin;
02963 if ( node != mRootNode || headerStyle() != HeaderStyle::enterprise() )
02964 margin = "padding:2px; margin:2px; ";
02965 QString align = "left";
02966 if ( headerStyle() == HeaderStyle::enterprise() )
02967 align = "right";
02968 if ( node->msgPart().typeStr().lower() == "message" || node == mRootNode )
02969 html += QString::fromLatin1("<div style=\"background:%1; %2"
02970 "vertical-align:middle; float:%3; %4\">").arg( bgColor.name() ).arg( margin )
02971 .arg( align ).arg( visibility );
02972 html += subHtml;
02973 if ( node->msgPart().typeStr().lower() == "message" || node == mRootNode )
02974 html += "</div>";
02975 }
02976 } else {
02977 partNode::AttachmentDisplayInfo info = node->attachmentDisplayInfo();
02978 if ( info.displayInHeader ) {
02979 html += "<div style=\"float:left;\">";
02980 html += QString::fromLatin1( "<span style=\"white-space:nowrap; border-width: 0px; border-left-width: 5px; border-color: %1; 2px; border-left-style: solid;\">" ).arg( bgColor.name() );
02981 QString fileName = writeMessagePartToTempFile( &node->msgPart(), node->nodeId() );
02982 QString href = node->asHREF( "header" );
02983 html += QString::fromLatin1( "<a href=\"" ) + href +
02984 QString::fromLatin1( "\">" );
02985 html += "<img style=\"vertical-align:middle;\" src=\"" + info.icon + "\"/> ";
02986 if ( headerStyle() == HeaderStyle::enterprise() ) {
02987 QFont bodyFont = mCSSHelper->bodyFont( isFixedFont() );
02988 QFontMetrics fm( bodyFont );
02989 html += KStringHandler::rPixelSqueeze( info.label, fm, 140 );
02990 } else if ( headerStyle() == HeaderStyle::fancy() ) {
02991 QFont bodyFont = mCSSHelper->bodyFont( isFixedFont() );
02992 QFontMetrics fm( bodyFont );
02993 html += KStringHandler::rPixelSqueeze( info.label, fm, 640 );
02994 } else {
02995 html += info.label;
02996 }
02997 html += "</a></span></div> ";
02998 }
02999 }
03000
03001 html += renderAttachments( node->nextSibling(), nextColor ( bgColor ) );
03002 return html;
03003 }
03004
03005 using namespace KMail::Interface;
03006
03007 void KMReaderWin::setBodyPartMemento( const partNode * node, const QCString & which, BodyPartMemento * memento )
03008 {
03009 const QCString index = node->path() + ':' + which.lower();
03010
03011 const std::map<QCString,BodyPartMemento*>::iterator it = mBodyPartMementoMap.lower_bound( index );
03012 if ( it != mBodyPartMementoMap.end() && it->first == index ) {
03013
03014 if ( memento && memento == it->second )
03015 return;
03016
03017 delete it->second;
03018
03019 if ( memento ) {
03020 it->second = memento;
03021 }
03022 else {
03023 mBodyPartMementoMap.erase( it );
03024 }
03025
03026 } else {
03027 if ( memento ) {
03028 mBodyPartMementoMap.insert( it, std::make_pair( index, memento ) );
03029 }
03030 }
03031
03032 if ( Observable * o = memento ? memento->asObservable() : 0 )
03033 o->attach( this );
03034 }
03035
03036 BodyPartMemento * KMReaderWin::bodyPartMemento( const partNode * node, const QCString & which ) const
03037 {
03038 const QCString index = node->path() + ':' + which.lower();
03039 const std::map<QCString,BodyPartMemento*>::const_iterator it = mBodyPartMementoMap.find( index );
03040 if ( it == mBodyPartMementoMap.end() ) {
03041 return 0;
03042 }
03043 else {
03044 return it->second;
03045 }
03046 }
03047
03048 static void detach_and_delete( BodyPartMemento * memento, KMReaderWin * obs ) {
03049 if ( Observable * const o = memento ? memento->asObservable() : 0 )
03050 o->detach( obs );
03051 delete memento;
03052 }
03053
03054 void KMReaderWin::clearBodyPartMementos()
03055 {
03056 for ( std::map<QCString,BodyPartMemento*>::const_iterator it = mBodyPartMementoMap.begin(), end = mBodyPartMementoMap.end() ; it != end ; ++it )
03057
03058
03059
03060
03061 detach_and_delete( it->second, this );
03062
03063 mBodyPartMementoMap.clear();
03064 }
03065
03066 #include "kmreaderwin.moc"
03067
03068