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