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 aMsg->setEncryptionState( encryptionState );
01541
01542
01543 if ( signatureState != KMMsgNotSigned ||
01544 aMsg->signatureState() == KMMsgSignatureStateUnknown ) {
01545 aMsg->setSignatureState( signatureState );
01546 }
01547
01548 bool emitReplaceMsgByUnencryptedVersion = false;
01549 const KConfigGroup reader( KMKernel::config(), "Reader" );
01550 if ( reader.readBoolEntry( "store-displayed-messages-unencrypted", false ) ) {
01551
01552
01553
01554
01555
01556
01557
01558
01559
01560
01561
01562
01563
01564
01565 kdDebug(5006) << "\n\n\nKMReaderWin::parseMsg() - special post-encryption handling:\n1." << endl;
01566 kdDebug(5006) << "(aMsg == msg) = " << (aMsg == message()) << endl;
01567 kdDebug(5006) << "aMsg->parent() && aMsg->parent() != kmkernel->outboxFolder() = " << (aMsg->parent() && aMsg->parent() != kmkernel->outboxFolder()) << endl;
01568 kdDebug(5006) << "message_was_saved_decrypted_before( aMsg ) = " << message_was_saved_decrypted_before( aMsg ) << endl;
01569 kdDebug(5006) << "this->decryptMessage() = " << decryptMessage() << endl;
01570 kdDebug(5006) << "otp.hasPendingAsyncJobs() = " << otp.hasPendingAsyncJobs() << endl;
01571 kdDebug(5006) << " (KMMsgFullyEncrypted == encryptionState) = " << (KMMsgFullyEncrypted == encryptionState) << endl;
01572 kdDebug(5006) << "|| (KMMsgPartiallyEncrypted == encryptionState) = " << (KMMsgPartiallyEncrypted == encryptionState) << endl;
01573
01574
01575 if( (aMsg == message())
01576
01577 && ( aMsg->parent() && aMsg->parent() != kmkernel->outboxFolder() )
01578
01579 && !message_was_saved_decrypted_before( aMsg )
01580
01581 && decryptMessage()
01582
01583 && !otp.hasPendingAsyncJobs()
01584
01585 && ( (KMMsgFullyEncrypted == encryptionState)
01586 || (KMMsgPartiallyEncrypted == encryptionState) ) ) {
01587
01588 kdDebug(5006) << "KMReaderWin - calling objectTreeToDecryptedMsg()" << endl;
01589
01590 NewByteArray decryptedData;
01591
01592 objectTreeToDecryptedMsg( mRootNode, decryptedData, *aMsg );
01593
01594 decryptedData.appendNULL();
01595 QCString resultString( decryptedData.data() );
01596 kdDebug(5006) << "KMReaderWin - resulting data:" << resultString << endl;
01597
01598 if( !resultString.isEmpty() ) {
01599 kdDebug(5006) << "KMReaderWin - composing unencrypted message" << endl;
01600
01601 aMsg->setBody( resultString );
01602 KMMessage* unencryptedMessage = new KMMessage( *aMsg );
01603 unencryptedMessage->setParent( 0 );
01604
01605
01606
01607
01608
01609
01610
01611
01612 kdDebug(5006) << "KMReaderWin - attach unencrypted message to aMsg" << endl;
01613 aMsg->setUnencryptedMsg( unencryptedMessage );
01614 emitReplaceMsgByUnencryptedVersion = true;
01615 }
01616 }
01617 }
01618
01619
01620 const int rootNodeCntType = mRootNode ? mRootNode->type() : DwMime::kTypeText;
01621 const int rootNodeCntSubtype = mRootNode ? mRootNode->subType() : DwMime::kSubtypePlain;
01622
01623
01624 setIdOfLastViewedMessage( aMsg->msgId() );
01625
01626 if( emitReplaceMsgByUnencryptedVersion ) {
01627 kdDebug(5006) << "KMReaderWin - invoce saving in decrypted form:" << endl;
01628 emit replaceMsgByUnencryptedVersion();
01629 } else {
01630 kdDebug(5006) << "KMReaderWin - finished parsing and displaying of message." << endl;
01631 showHideMimeTree( rootNodeCntType == DwMime::kTypeText &&
01632 rootNodeCntSubtype == DwMime::kSubtypePlain );
01633 }
01634
01635 aMsg->setIsBeingParsed( false );
01636 }
01637
01638
01639
01640 QString KMReaderWin::writeMsgHeader( KMMessage* aMsg, partNode *vCardNode, bool topLevel )
01641 {
01642 kdFatal( !headerStyle(), 5006 )
01643 << "trying to writeMsgHeader() without a header style set!" << endl;
01644 kdFatal( !headerStrategy(), 5006 )
01645 << "trying to writeMsgHeader() without a header strategy set!" << endl;
01646 QString href;
01647 if ( vCardNode )
01648 href = vCardNode->asHREF( "body" );
01649
01650 return headerStyle()->format( aMsg, headerStrategy(), href, mPrinting, topLevel );
01651 }
01652
01653
01654
01655
01656 QString KMReaderWin::writeMessagePartToTempFile( KMMessagePart* aMsgPart,
01657 int aPartNum )
01658 {
01659 QString fileName = aMsgPart->fileName();
01660 if( fileName.isEmpty() )
01661 fileName = aMsgPart->name();
01662
01663
01664 QString fname = createTempDir( QString::number( aPartNum ) );
01665 if ( fname.isEmpty() )
01666 return QString();
01667
01668
01669 int slashPos = fileName.findRev( '/' );
01670 if( -1 != slashPos )
01671 fileName = fileName.mid( slashPos + 1 );
01672 if( fileName.isEmpty() )
01673 fileName = "unnamed";
01674 fname += "/" + fileName;
01675
01676 QByteArray data = aMsgPart->bodyDecodedBinary();
01677 size_t size = data.size();
01678 if ( aMsgPart->type() == DwMime::kTypeText && size) {
01679
01680 size = KMail::Util::crlf2lf( data.data(), size );
01681 }
01682 if( !KPIM::kBytesToFile( data.data(), size, fname, false, false, false ) )
01683 return QString::null;
01684
01685 mTempFiles.append( fname );
01686
01687
01688 ::chmod( QFile::encodeName( fname ), S_IRUSR );
01689
01690 return fname;
01691 }
01692
01693 QString KMReaderWin::createTempDir( const QString ¶m )
01694 {
01695 KTempFile *tempFile = new KTempFile( QString::null, "." + param );
01696 tempFile->setAutoDelete( true );
01697 QString fname = tempFile->name();
01698 delete tempFile;
01699
01700 if( ::access( QFile::encodeName( fname ), W_OK ) != 0 )
01701
01702 if( ::mkdir( QFile::encodeName( fname ), 0 ) != 0
01703 || ::chmod( QFile::encodeName( fname ), S_IRWXU ) != 0 )
01704 return QString::null;
01705
01706 assert( !fname.isNull() );
01707
01708 mTempDirs.append( fname );
01709 return fname;
01710 }
01711
01712
01713 void KMReaderWin::showVCard( KMMessagePart * msgPart ) {
01714 const QString vCard = msgPart->bodyToUnicode( overrideCodec() );
01715
01716 VCardViewer *vcv = new VCardViewer(this, vCard, "vCardDialog");
01717 vcv->show();
01718 }
01719
01720
01721 void KMReaderWin::printMsg()
01722 {
01723 if (!message()) return;
01724 mViewer->view()->print();
01725 }
01726
01727
01728
01729 int KMReaderWin::msgPartFromUrl(const KURL &aUrl)
01730 {
01731 if (aUrl.isEmpty()) return -1;
01732 if (!aUrl.isLocalFile()) return -1;
01733
01734 QString path = aUrl.path();
01735 uint right = path.findRev('/');
01736 uint left = path.findRev('.', right);
01737
01738 bool ok;
01739 int res = path.mid(left + 1, right - left - 1).toInt(&ok);
01740 return (ok) ? res : -1;
01741 }
01742
01743
01744
01745 void KMReaderWin::resizeEvent(QResizeEvent *)
01746 {
01747 if( !mResizeTimer.isActive() )
01748 {
01749
01750
01751
01752
01753 mResizeTimer.start( 100, true );
01754 }
01755 }
01756
01757
01758
01759 void KMReaderWin::slotDelayedResize()
01760 {
01761 mSplitter->setGeometry(0, 0, width(), height());
01762 }
01763
01764
01765
01766 void KMReaderWin::slotTouchMessage()
01767 {
01768 if ( !message() )
01769 return;
01770
01771 if ( !message()->isNew() && !message()->isUnread() )
01772 return;
01773
01774 SerNumList serNums;
01775 serNums.append( message()->getMsgSerNum() );
01776 KMCommand *command = new KMSetStatusCommand( KMMsgStatusRead, serNums );
01777 command->start();
01778
01779
01780 if ( mNoMDNsWhenEncrypted &&
01781 message()->encryptionState() != KMMsgNotEncrypted &&
01782 message()->encryptionState() != KMMsgEncryptionStateUnknown )
01783 return;
01784
01785 KMFolder *folder = message()->parent();
01786 if (folder &&
01787 (folder->isOutbox() || folder->isSent() || folder->isTrash() ||
01788 folder->isDrafts() || folder->isTemplates() ) )
01789 return;
01790
01791 if ( KMMessage * receipt = message()->createMDN( MDN::ManualAction,
01792 MDN::Displayed,
01793 true ) )
01794 if ( !kmkernel->msgSender()->send( receipt ) )
01795 KMessageBox::error( this, i18n("Could not send MDN.") );
01796 }
01797
01798
01799
01800 void KMReaderWin::closeEvent(QCloseEvent *e)
01801 {
01802 QWidget::closeEvent(e);
01803 writeConfig();
01804 }
01805
01806
01807 bool foundSMIMEData( const QString aUrl,
01808 QString& displayName,
01809 QString& libName,
01810 QString& keyId )
01811 {
01812 static QString showCertMan("showCertificate#");
01813 displayName = "";
01814 libName = "";
01815 keyId = "";
01816 int i1 = aUrl.find( showCertMan );
01817 if( -1 < i1 ) {
01818 i1 += showCertMan.length();
01819 int i2 = aUrl.find(" ### ", i1);
01820 if( i1 < i2 )
01821 {
01822 displayName = aUrl.mid( i1, i2-i1 );
01823 i1 = i2+5;
01824 i2 = aUrl.find(" ### ", i1);
01825 if( i1 < i2 )
01826 {
01827 libName = aUrl.mid( i1, i2-i1 );
01828 i2 += 5;
01829
01830 keyId = aUrl.mid( i2 );
01831
01832
01833
01834
01835
01836
01837
01838
01839
01840
01841
01842
01843 }
01844 }
01845 }
01846 return !keyId.isEmpty();
01847 }
01848
01849
01850
01851 void KMReaderWin::slotUrlOn(const QString &aUrl)
01852 {
01853 const KURL url(aUrl);
01854
01855 if ( url.protocol() == "kmail" || url.protocol() == "x-kmail" || url.protocol() == "attachment"
01856 || (url.protocol().isEmpty() && url.path().isEmpty()) ) {
01857 mViewer->setDNDEnabled( false );
01858 } else {
01859 mViewer->setDNDEnabled( true );
01860 }
01861
01862 if ( aUrl.stripWhiteSpace().isEmpty() ) {
01863 KPIM::BroadcastStatus::instance()->reset();
01864 mHoveredUrl = KURL();
01865 return;
01866 }
01867
01868 mHoveredUrl = url;
01869
01870 const QString msg = URLHandlerManager::instance()->statusBarMessage( url, this );
01871
01872 kdWarning( msg.isEmpty(), 5006 ) << "KMReaderWin::slotUrlOn(): Unhandled URL hover!" << endl;
01873 KPIM::BroadcastStatus::instance()->setTransientStatusMsg( msg );
01874 }
01875
01876
01877
01878 void KMReaderWin::slotUrlOpen(const KURL &aUrl, const KParts::URLArgs &)
01879 {
01880 mClickedUrl = aUrl;
01881
01882 if ( URLHandlerManager::instance()->handleClick( aUrl, this ) )
01883 return;
01884
01885 kdWarning( 5006 ) << "KMReaderWin::slotOpenUrl(): Unhandled URL click!" << endl;
01886 emit urlClicked( aUrl, Qt::LeftButton );
01887 }
01888
01889
01890 void KMReaderWin::slotUrlPopup(const QString &aUrl, const QPoint& aPos)
01891 {
01892 const KURL url( aUrl );
01893 mClickedUrl = url;
01894
01895 if ( URLHandlerManager::instance()->handleContextMenuRequest( url, aPos, this ) )
01896 return;
01897
01898 if ( message() ) {
01899 kdWarning( 5006 ) << "KMReaderWin::slotUrlPopup(): Unhandled URL right-click!" << endl;
01900 emit popupMenu( *message(), url, aPos );
01901 }
01902 }
01903
01904
01905
01906 static bool hasParentDivWithId( const DOM::Node &start, const QString &id )
01907 {
01908 if ( start.isNull() )
01909 return false;
01910
01911 if ( start.nodeName().string() == "div" ) {
01912 for ( unsigned int i = 0; i < start.attributes().length(); i++ ) {
01913 if ( start.attributes().item( i ).nodeName().string() == "id" &&
01914 start.attributes().item( i ).nodeValue().string() == id )
01915 return true;
01916 }
01917 }
01918
01919 if ( !start.parentNode().isNull() )
01920 return hasParentDivWithId( start.parentNode(), id );
01921 else return false;
01922 }
01923
01924
01925 void KMReaderWin::showAttachmentPopup( int id, const QString & name, const QPoint & p )
01926 {
01927 mAtmCurrent = id;
01928 mAtmCurrentName = name;
01929 KPopupMenu *menu = new KPopupMenu();
01930 menu->insertItem(SmallIcon("fileopen"),i18n("to open", "Open"), 1);
01931 menu->insertItem(i18n("Open With..."), 2);
01932 menu->insertItem(i18n("to view something", "View"), 3);
01933 menu->insertItem(SmallIcon("filesaveas"),i18n("Save As..."), 4);
01934 menu->insertItem(SmallIcon("editcopy"), i18n("Copy"), 9 );
01935 const bool canChange = message()->parent() ? !message()->parent()->isReadOnly() : false;
01936 if ( GlobalSettings::self()->allowAttachmentEditing() && canChange )
01937 menu->insertItem(SmallIcon("edit"), i18n("Edit Attachment"), 8 );
01938 if ( GlobalSettings::self()->allowAttachmentDeletion() && canChange )
01939 menu->insertItem(SmallIcon("editdelete"), i18n("Delete Attachment"), 7 );
01940 if ( name.endsWith( ".xia", false ) &&
01941 Kleo::CryptoBackendFactory::instance()->protocol( "Chiasmus" ) )
01942 menu->insertItem( i18n( "Decrypt With Chiasmus..." ), 6 );
01943 menu->insertItem(i18n("Properties"), 5);
01944
01945 const bool attachmentInHeader = hasParentDivWithId( mViewer->nodeUnderMouse(), "attachmentInjectionPoint" );
01946 const bool hasScrollbar = mViewer->view()->verticalScrollBar()->isVisible();
01947 if ( attachmentInHeader && hasScrollbar ) {
01948 menu->insertItem( i18n("Scroll To"), 10 );
01949 }
01950
01951 connect(menu, SIGNAL(activated(int)), this, SLOT(slotHandleAttachment(int)));
01952 menu->exec( p ,0 );
01953 delete menu;
01954 }
01955
01956
01957 void KMReaderWin::setStyleDependantFrameWidth()
01958 {
01959 if ( !mBox )
01960 return;
01961
01962 int frameWidth;
01963 if( style().isA("KeramikStyle") )
01964 frameWidth = style().pixelMetric( QStyle::PM_DefaultFrameWidth ) - 1;
01965 else
01966 frameWidth = style().pixelMetric( QStyle::PM_DefaultFrameWidth );
01967 if ( frameWidth < 0 )
01968 frameWidth = 0;
01969 if ( frameWidth != mBox->lineWidth() )
01970 mBox->setLineWidth( frameWidth );
01971 }
01972
01973
01974 void KMReaderWin::styleChange( QStyle& oldStyle )
01975 {
01976 setStyleDependantFrameWidth();
01977 QWidget::styleChange( oldStyle );
01978 }
01979
01980
01981 void KMReaderWin::slotHandleAttachment( int choice )
01982 {
01983 mAtmUpdate = true;
01984 partNode* node = mRootNode ? mRootNode->findId( mAtmCurrent ) : 0;
01985 if ( mAtmCurrentName.isEmpty() && node )
01986 mAtmCurrentName = tempFileUrlFromPartNode( node ).path();
01987 if ( choice < 7 ) {
01988 KMHandleAttachmentCommand* command = new KMHandleAttachmentCommand(
01989 node, message(), mAtmCurrent, mAtmCurrentName,
01990 KMHandleAttachmentCommand::AttachmentAction( choice ), 0, this );
01991 connect( command, SIGNAL( showAttachment( int, const QString& ) ),
01992 this, SLOT( slotAtmView( int, const QString& ) ) );
01993 command->start();
01994 } else if ( choice == 7 ) {
01995 slotDeleteAttachment( node );
01996 } else if ( choice == 8 ) {
01997 slotEditAttachment( node );
01998 } else if ( choice == 9 ) {
01999 if ( !node ) return;
02000 KURL::List urls;
02001 KURL url = tempFileUrlFromPartNode( node );
02002 if (!url.isValid() ) return;
02003 urls.append( url );
02004 KURLDrag* drag = new KURLDrag( urls, this );
02005 QApplication::clipboard()->setData( drag, QClipboard::Clipboard );
02006 } else if ( choice == 10 ) {
02007 scrollToAttachment( node );
02008 }
02009 }
02010
02011
02012 void KMReaderWin::slotFind()
02013 {
02014 mViewer->findText();
02015 }
02016
02017
02018 void KMReaderWin::slotFindNext()
02019 {
02020 mViewer->findTextNext();
02021 }
02022
02023
02024 void KMReaderWin::slotToggleFixedFont()
02025 {
02026 mUseFixedFont = !mUseFixedFont;
02027 saveRelativePosition();
02028 update(true);
02029 }
02030
02031
02032
02033 void KMReaderWin::slotCopySelectedText()
02034 {
02035 kapp->clipboard()->setText( mViewer->selectedText() );
02036 }
02037
02038
02039
02040 void KMReaderWin::atmViewMsg( KMMessagePart* aMsgPart, int nodeId )
02041 {
02042 assert(aMsgPart!=0);
02043 KMMessage* msg = new KMMessage;
02044 msg->fromString(aMsgPart->bodyDecoded());
02045 assert(msg != 0);
02046 msg->setMsgSerNum( 0 );
02047
02048 msg->setParent( message()->parent() );
02049 msg->setUID(message()->UID());
02050 msg->setReadyToShow(true);
02051 KMReaderMainWin *win = new KMReaderMainWin();
02052 win->showMsg( overrideEncoding(), msg, message()->getMsgSerNum(), nodeId );
02053 win->show();
02054 }
02055
02056
02057 void KMReaderWin::setMsgPart( partNode * node ) {
02058 htmlWriter()->reset();
02059 mColorBar->hide();
02060 htmlWriter()->begin( mCSSHelper->cssDefinitions( isFixedFont() ) );
02061 htmlWriter()->write( mCSSHelper->htmlHead( isFixedFont() ) );
02062
02063 if ( node ) {
02064 ObjectTreeParser otp( this, 0, true );
02065 otp.parseObjectTree( node );
02066 }
02067
02068 htmlWriter()->queue( "</body></html>" );
02069 htmlWriter()->flush();
02070 }
02071
02072
02073 void KMReaderWin::setMsgPart( KMMessagePart* aMsgPart, bool aHTML,
02074 const QString& aFileName, const QString& pname )
02075 {
02076 KCursorSaver busy(KBusyPtr::busy());
02077 if (kasciistricmp(aMsgPart->typeStr(), "message")==0) {
02078
02079 KMMessage* msg = new KMMessage;
02080 assert(aMsgPart!=0);
02081 msg->fromString(aMsgPart->bodyDecoded());
02082 mMainWindow->setCaption(msg->subject());
02083 setMsg(msg, true);
02084 setAutoDelete(true);
02085 } else if (kasciistricmp(aMsgPart->typeStr(), "text")==0) {
02086 if (kasciistricmp(aMsgPart->subtypeStr(), "x-vcard") == 0) {
02087 showVCard( aMsgPart );
02088 return;
02089 }
02090 htmlWriter()->begin( mCSSHelper->cssDefinitions( isFixedFont() ) );
02091 htmlWriter()->queue( mCSSHelper->htmlHead( isFixedFont() ) );
02092
02093 if (aHTML && (kasciistricmp(aMsgPart->subtypeStr(), "html")==0)) {
02094
02095 htmlWriter()->queue( aMsgPart->bodyToUnicode( overrideCodec() ) );
02096 mColorBar->setHtmlMode();
02097 } else {
02098 const QCString str = aMsgPart->bodyDecoded();
02099 ObjectTreeParser otp( this );
02100 otp.writeBodyStr( str,
02101 overrideCodec() ? overrideCodec() : aMsgPart->codec(),
02102 message() ? message()->from() : QString::null );
02103 }
02104 htmlWriter()->queue("</body></html>");
02105 htmlWriter()->flush();
02106 mMainWindow->setCaption(i18n("View Attachment: %1").arg(pname));
02107 } else if (kasciistricmp(aMsgPart->typeStr(), "image")==0 ||
02108 (kasciistricmp(aMsgPart->typeStr(), "application")==0 &&
02109 kasciistricmp(aMsgPart->subtypeStr(), "postscript")==0))
02110 {
02111 if (aFileName.isEmpty()) return;
02112
02113 QImageIO *iio = new QImageIO();
02114 iio->setFileName(aFileName);
02115 if( iio->read() ) {
02116 QImage img = iio->image();
02117 QRect desk = KGlobalSettings::desktopGeometry(mMainWindow);
02118
02119 int width, height;
02120 if( img.width() < 50 )
02121 width = 70;
02122 else if( img.width()+20 < desk.width() )
02123 width = img.width()+20;
02124 else
02125 width = desk.width();
02126 if( img.height() < 50 )
02127 height = 70;
02128 else if( img.height()+20 < desk.height() )
02129 height = img.height()+20;
02130 else
02131 height = desk.height();
02132 mMainWindow->resize( width, height );
02133 }
02134
02135 htmlWriter()->begin( mCSSHelper->cssDefinitions( isFixedFont() ) );
02136 htmlWriter()->write( mCSSHelper->htmlHead( isFixedFont() ) );
02137 htmlWriter()->write( "<img src=\"file:" +
02138 KURL::encode_string( aFileName ) +
02139 "\" border=\"0\">\n"
02140 "</body></html>\n" );
02141 htmlWriter()->end();
02142 setCaption( i18n("View Attachment: %1").arg( pname ) );
02143 show();
02144 delete iio;
02145 } else {
02146 htmlWriter()->begin( mCSSHelper->cssDefinitions( isFixedFont() ) );
02147 htmlWriter()->queue( mCSSHelper->htmlHead( isFixedFont() ) );
02148 htmlWriter()->queue( "<pre>" );
02149
02150 QString str = aMsgPart->bodyDecoded();
02151
02152
02153 if( str.length() < (unsigned) aMsgPart->decodedSize() ) {
02154 str.prepend( i18n("[KMail: Attachment contains binary data. Trying to show first character.]",
02155 "[KMail: Attachment contains binary data. Trying to show first %n characters.]",
02156 str.length()) + QChar('\n') );
02157 }
02158 htmlWriter()->queue( QStyleSheet::escape( str ) );
02159 htmlWriter()->queue( "</pre>" );
02160 htmlWriter()->queue("</body></html>");
02161 htmlWriter()->flush();
02162 mMainWindow->setCaption(i18n("View Attachment: %1").arg(pname));
02163 }
02164
02165 }
02166
02167
02168
02169 void KMReaderWin::slotAtmView( int id, const QString& name )
02170 {
02171 partNode* node = mRootNode ? mRootNode->findId( id ) : 0;
02172 if( node ) {
02173 mAtmCurrent = id;
02174 mAtmCurrentName = name;
02175 if ( mAtmCurrentName.isEmpty() )
02176 mAtmCurrentName = tempFileUrlFromPartNode( node ).path();
02177
02178 KMMessagePart& msgPart = node->msgPart();
02179 QString pname = msgPart.fileName();
02180 if (pname.isEmpty()) pname=msgPart.name();
02181 if (pname.isEmpty()) pname=msgPart.contentDescription();
02182 if (pname.isEmpty()) pname="unnamed";
02183
02184 if (kasciistricmp(msgPart.typeStr(), "message")==0) {
02185 atmViewMsg( &msgPart,id );
02186 } else if ((kasciistricmp(msgPart.typeStr(), "text")==0) &&
02187 (kasciistricmp(msgPart.subtypeStr(), "x-vcard")==0)) {
02188 setMsgPart( &msgPart, htmlMail(), name, pname );
02189 } else {
02190 KMReaderMainWin *win = new KMReaderMainWin(&msgPart, htmlMail(),
02191 name, pname, overrideEncoding() );
02192 win->show();
02193 }
02194 }
02195 }
02196
02197
02198 void KMReaderWin::openAttachment( int id, const QString & name )
02199 {
02200 mAtmCurrentName = name;
02201 mAtmCurrent = id;
02202
02203 QString str, pname, cmd, fileName;
02204
02205 partNode* node = mRootNode ? mRootNode->findId( id ) : 0;
02206 if( !node ) {
02207 kdWarning(5006) << "KMReaderWin::openAttachment - could not find node " << id << endl;
02208 return;
02209 }
02210 if ( mAtmCurrentName.isEmpty() )
02211 mAtmCurrentName = tempFileUrlFromPartNode( node ).path();
02212
02213 KMMessagePart& msgPart = node->msgPart();
02214 if (kasciistricmp(msgPart.typeStr(), "message")==0)
02215 {
02216 atmViewMsg( &msgPart, id );
02217 return;
02218 }
02219
02220 QCString contentTypeStr( msgPart.typeStr() + '/' + msgPart.subtypeStr() );
02221 KPIM::kAsciiToLower( contentTypeStr.data() );
02222
02223 if ( qstrcmp( contentTypeStr, "text/x-vcard" ) == 0 ) {
02224 showVCard( &msgPart );
02225 return;
02226 }
02227
02228
02229 KMimeType::Ptr mimetype;
02230
02231 mimetype = KMimeType::mimeType( QString::fromLatin1( contentTypeStr ) );
02232 if ( mimetype->name() == "application/octet-stream" ) {
02233
02234 mimetype = KMimeType::findByPath( name, 0, true );
02235 }
02236 if ( ( mimetype->name() == "application/octet-stream" )
02237 && msgPart.isComplete() ) {
02238
02239
02240 mimetype = KMimeType::findByFileContent( name );
02241 }
02242
02243 KService::Ptr offer =
02244 KServiceTypeProfile::preferredService( mimetype->name(), "Application" );
02245
02246 QString open_text;
02247 QString filenameText = msgPart.fileName();
02248 if ( filenameText.isEmpty() )
02249 filenameText = msgPart.name();
02250 if ( offer ) {
02251 open_text = i18n("&Open with '%1'").arg( offer->name() );
02252 } else {
02253 open_text = i18n("&Open With...");
02254 }
02255 const QString text = i18n("Open attachment '%1'?\n"
02256 "Note that opening an attachment may compromise "
02257 "your system's security.")
02258 .arg( filenameText );
02259 const int choice = KMessageBox::questionYesNoCancel( this, text,
02260 i18n("Open Attachment?"), KStdGuiItem::saveAs(), open_text,
02261 QString::fromLatin1("askSave") + mimetype->name() );
02262
02263 if( choice == KMessageBox::Yes ) {
02264 mAtmUpdate = true;
02265 KMHandleAttachmentCommand* command = new KMHandleAttachmentCommand( node,
02266 message(), mAtmCurrent, mAtmCurrentName, KMHandleAttachmentCommand::Save,
02267 offer, this );
02268 connect( command, SIGNAL( showAttachment( int, const QString& ) ),
02269 this, SLOT( slotAtmView( int, const QString& ) ) );
02270 command->start();
02271 }
02272 else if( choice == KMessageBox::No ) {
02273 KMHandleAttachmentCommand::AttachmentAction action = ( offer ?
02274 KMHandleAttachmentCommand::Open : KMHandleAttachmentCommand::OpenWith );
02275 mAtmUpdate = true;
02276 KMHandleAttachmentCommand* command = new KMHandleAttachmentCommand( node,
02277 message(), mAtmCurrent, mAtmCurrentName, action, offer, this );
02278 connect( command, SIGNAL( showAttachment( int, const QString& ) ),
02279 this, SLOT( slotAtmView( int, const QString& ) ) );
02280 command->start();
02281 } else {
02282 kdDebug(5006) << "Canceled opening attachment" << endl;
02283 }
02284 }
02285
02286
02287 void KMReaderWin::slotScrollUp()
02288 {
02289 static_cast<QScrollView *>(mViewer->widget())->scrollBy(0, -10);
02290 }
02291
02292
02293
02294 void KMReaderWin::slotScrollDown()
02295 {
02296 static_cast<QScrollView *>(mViewer->widget())->scrollBy(0, 10);
02297 }
02298
02299 bool KMReaderWin::atBottom() const
02300 {
02301 const QScrollView *view = static_cast<const QScrollView *>(mViewer->widget());
02302 return view->contentsY() + view->visibleHeight() >= view->contentsHeight();
02303 }
02304
02305
02306 void KMReaderWin::slotJumpDown()
02307 {
02308 QScrollView *view = static_cast<QScrollView *>(mViewer->widget());
02309 int offs = (view->clipper()->height() < 30) ? view->clipper()->height() : 30;
02310 view->scrollBy( 0, view->clipper()->height() - offs );
02311 }
02312
02313
02314 void KMReaderWin::slotScrollPrior()
02315 {
02316 static_cast<QScrollView *>(mViewer->widget())->scrollBy(0, -(int)(height()*0.8));
02317 }
02318
02319
02320
02321 void KMReaderWin::slotScrollNext()
02322 {
02323 static_cast<QScrollView *>(mViewer->widget())->scrollBy(0, (int)(height()*0.8));
02324 }
02325
02326
02327 void KMReaderWin::slotDocumentChanged()
02328 {
02329
02330 }
02331
02332
02333
02334 void KMReaderWin::slotTextSelected(bool)
02335 {
02336 QString temp = mViewer->selectedText();
02337 kapp->clipboard()->setText(temp);
02338 }
02339
02340
02341 void KMReaderWin::selectAll()
02342 {
02343 mViewer->selectAll();
02344 }
02345
02346
02347 QString KMReaderWin::copyText()
02348 {
02349 QString temp = mViewer->selectedText();
02350 return temp;
02351 }
02352
02353
02354
02355 void KMReaderWin::slotDocumentDone()
02356 {
02357
02358 }
02359
02360
02361
02362 void KMReaderWin::setHtmlOverride(bool override)
02363 {
02364 mHtmlOverride = override;
02365 if (message())
02366 message()->setDecodeHTML(htmlMail());
02367 }
02368
02369
02370
02371 void KMReaderWin::setHtmlLoadExtOverride(bool override)
02372 {
02373 mHtmlLoadExtOverride = override;
02374
02375
02376 }
02377
02378
02379
02380 bool KMReaderWin::htmlMail()
02381 {
02382 return ((mHtmlMail && !mHtmlOverride) || (!mHtmlMail && mHtmlOverride));
02383 }
02384
02385
02386
02387 bool KMReaderWin::htmlLoadExternal()
02388 {
02389 return ((mHtmlLoadExternal && !mHtmlLoadExtOverride) ||
02390 (!mHtmlLoadExternal && mHtmlLoadExtOverride));
02391 }
02392
02393
02394
02395 void KMReaderWin::saveRelativePosition()
02396 {
02397 const QScrollView * scrollview = static_cast<QScrollView *>( mViewer->widget() );
02398 mSavedRelativePosition =
02399 static_cast<float>( scrollview->contentsY() ) / scrollview->contentsHeight();
02400 }
02401
02402
02403
02404 void KMReaderWin::update( bool force )
02405 {
02406 KMMessage* msg = message();
02407 if ( msg )
02408 setMsg( msg, force );
02409 }
02410
02411
02412
02413 KMMessage* KMReaderWin::message( KMFolder** aFolder ) const
02414 {
02415 KMFolder* tmpFolder;
02416 KMFolder*& folder = aFolder ? *aFolder : tmpFolder;
02417 folder = 0;
02418 if (mMessage)
02419 return mMessage;
02420 if (mLastSerNum) {
02421 KMMessage *message = 0;
02422 int index;
02423 KMMsgDict::instance()->getLocation( mLastSerNum, &folder, &index );
02424 if (folder )
02425 message = folder->getMsg( index );
02426 if (!message)
02427 kdWarning(5006) << "Attempt to reference invalid serial number " << mLastSerNum << "\n" << endl;
02428 return message;
02429 }
02430 return 0;
02431 }
02432
02433
02434
02435
02436 void KMReaderWin::slotUrlClicked()
02437 {
02438 KMMainWidget *mainWidget = dynamic_cast<KMMainWidget*>(mMainWindow);
02439 uint identity = 0;
02440 if ( message() && message()->parent() ) {
02441 identity = message()->parent()->identity();
02442 }
02443
02444 KMCommand *command = new KMUrlClickedCommand( mClickedUrl, identity, this,
02445 false, mainWidget );
02446 command->start();
02447 }
02448
02449
02450 void KMReaderWin::slotMailtoCompose()
02451 {
02452 KMCommand *command = new KMMailtoComposeCommand( mClickedUrl, message() );
02453 command->start();
02454 }
02455
02456
02457 void KMReaderWin::slotMailtoForward()
02458 {
02459 KMCommand *command = new KMMailtoForwardCommand( mMainWindow, mClickedUrl,
02460 message() );
02461 command->start();
02462 }
02463
02464
02465 void KMReaderWin::slotMailtoAddAddrBook()
02466 {
02467 KMCommand *command = new KMMailtoAddAddrBookCommand( mClickedUrl,
02468 mMainWindow);
02469 command->start();
02470 }
02471
02472
02473 void KMReaderWin::slotMailtoOpenAddrBook()
02474 {
02475 KMCommand *command = new KMMailtoOpenAddrBookCommand( mClickedUrl,
02476 mMainWindow );
02477 command->start();
02478 }
02479
02480
02481 void KMReaderWin::slotUrlCopy()
02482 {
02483
02484
02485 KMCommand *command =
02486 new KMUrlCopyCommand( mClickedUrl,
02487 dynamic_cast<KMMainWidget*>( mMainWindow ) );
02488 command->start();
02489 }
02490
02491
02492 void KMReaderWin::slotUrlOpen( const KURL &url )
02493 {
02494 if ( !url.isEmpty() )
02495 mClickedUrl = url;
02496 KMCommand *command = new KMUrlOpenCommand( mClickedUrl, this );
02497 command->start();
02498 }
02499
02500
02501 void KMReaderWin::slotAddBookmarks()
02502 {
02503 KMCommand *command = new KMAddBookmarksCommand( mClickedUrl, this );
02504 command->start();
02505 }
02506
02507
02508 void KMReaderWin::slotUrlSave()
02509 {
02510 KMCommand *command = new KMUrlSaveCommand( mClickedUrl, mMainWindow );
02511 command->start();
02512 }
02513
02514
02515 void KMReaderWin::slotMailtoReply()
02516 {
02517 KMCommand *command = new KMMailtoReplyCommand( mMainWindow, mClickedUrl,
02518 message(), copyText() );
02519 command->start();
02520 }
02521
02522
02523 partNode * KMReaderWin::partNodeFromUrl( const KURL & url ) {
02524 return mRootNode ? mRootNode->findId( msgPartFromUrl( url ) ) : 0 ;
02525 }
02526
02527 partNode * KMReaderWin::partNodeForId( int id ) {
02528 return mRootNode ? mRootNode->findId( id ) : 0 ;
02529 }
02530
02531
02532 KURL KMReaderWin::tempFileUrlFromPartNode( const partNode * node )
02533 {
02534 if (!node) return KURL();
02535 QStringList::const_iterator it = mTempFiles.begin();
02536 QStringList::const_iterator end = mTempFiles.end();
02537
02538 while ( it != end ) {
02539 QString path = *it;
02540 it++;
02541 uint right = path.findRev('/');
02542 uint left = path.findRev('.', right);
02543
02544 bool ok;
02545 int res = path.mid(left + 1, right - left - 1).toInt(&ok);
02546 if ( res == node->nodeId() )
02547 return KURL( path );
02548 }
02549 return KURL();
02550 }
02551
02552
02553 void KMReaderWin::slotSaveAttachments()
02554 {
02555 mAtmUpdate = true;
02556 KMSaveAttachmentsCommand *saveCommand = new KMSaveAttachmentsCommand( mMainWindow,
02557 message() );
02558 saveCommand->start();
02559 }
02560
02561
02562 void KMReaderWin::saveAttachment( const KURL &tempFileName )
02563 {
02564 mAtmCurrent = msgPartFromUrl( tempFileName );
02565 mAtmCurrentName = mClickedUrl.path();
02566 slotHandleAttachment( KMHandleAttachmentCommand::Save );
02567 }
02568
02569
02570 void KMReaderWin::slotSaveMsg()
02571 {
02572 KMSaveMsgCommand *saveCommand = new KMSaveMsgCommand( mMainWindow, message() );
02573
02574 if (saveCommand->url().isEmpty())
02575 delete saveCommand;
02576 else
02577 saveCommand->start();
02578 }
02579
02580 void KMReaderWin::slotIMChat()
02581 {
02582 KMCommand *command = new KMIMChatCommand( mClickedUrl, message() );
02583 command->start();
02584 }
02585
02586
02587 bool KMReaderWin::eventFilter( QObject *, QEvent *e )
02588 {
02589 if ( e->type() == QEvent::MouseButtonPress ) {
02590 QMouseEvent* me = static_cast<QMouseEvent*>(e);
02591 if ( me->button() == LeftButton && ( me->state() & ShiftButton ) ) {
02592
02593 URLHandlerManager::instance()->handleShiftClick( mHoveredUrl, this );
02594 return true;
02595 }
02596
02597 if ( me->button() == LeftButton ) {
02598 mCanStartDrag = URLHandlerManager::instance()->willHandleDrag( mHoveredUrl, this );
02599 mLastClickPosition = me->pos();
02600 }
02601 }
02602
02603 if ( e->type() == QEvent::MouseButtonRelease ) {
02604 mCanStartDrag = false;
02605 }
02606
02607 if ( e->type() == QEvent::MouseMove ) {
02608 QMouseEvent* me = static_cast<QMouseEvent*>( e );
02609
02610 if ( ( mLastClickPosition - me->pos() ).manhattanLength() > KGlobalSettings::dndEventDelay() ) {
02611 if ( mCanStartDrag && !mHoveredUrl.isEmpty() && mHoveredUrl.protocol() == "attachment" ) {
02612 mCanStartDrag = false;
02613 URLHandlerManager::instance()->handleDrag( mHoveredUrl, this );
02614 slotUrlOn( QString() );
02615 return true;
02616 }
02617 }
02618 }
02619
02620
02621 return false;
02622 }
02623
02624 void KMReaderWin::fillCommandInfo( partNode *node, KMMessage **msg, int *nodeId )
02625 {
02626 Q_ASSERT( msg && nodeId );
02627
02628 if ( mSerNumOfOriginalMessage != 0 ) {
02629 KMFolder *folder = 0;
02630 int index = -1;
02631 KMMsgDict::instance()->getLocation( mSerNumOfOriginalMessage, &folder, &index );
02632 if ( folder && index != -1 )
02633 *msg = folder->getMsg( index );
02634
02635 if ( !( *msg ) ) {
02636 kdWarning( 5006 ) << "Unable to find the original message, aborting attachment deletion!" << endl;
02637 return;
02638 }
02639
02640 *nodeId = node->nodeId() + mNodeIdOffset;
02641 }
02642 else {
02643 *nodeId = node->nodeId();
02644 *msg = message();
02645 }
02646 }
02647
02648 void KMReaderWin::slotDeleteAttachment(partNode * node)
02649 {
02650 if ( KMessageBox::warningContinueCancel( this,
02651 i18n("Deleting an attachment might invalidate any digital signature on this message."),
02652 i18n("Delete Attachment"), KStdGuiItem::del(), "DeleteAttachmentSignatureWarning" )
02653 != KMessageBox::Continue ) {
02654 return;
02655 }
02656
02657 int nodeId = -1;
02658 KMMessage *msg = 0;
02659 fillCommandInfo( node, &msg, &nodeId );
02660 if ( msg && nodeId != -1 ) {
02661 KMDeleteAttachmentCommand* command = new KMDeleteAttachmentCommand( nodeId, msg, this );
02662 command->start();
02663 connect( command, SIGNAL( completed( KMCommand * ) ),
02664 this, SLOT( updateReaderWin() ) );
02665 connect( command, SIGNAL( completed( KMCommand * ) ),
02666 this, SLOT( disconnectMsgAdded() ) );
02667
02668
02669
02670
02671
02672
02673 const KMHeaders * const headers = KMKernel::self()->getKMMainWidget()->headers();
02674 connect( headers, SIGNAL( msgAddedToListView( QListViewItem* ) ),
02675 this, SLOT( msgAdded( QListViewItem* ) ) );
02676 }
02677
02678
02679 if ( mSerNumOfOriginalMessage != 0 && message() ) {
02680 message()->deleteBodyPart( node->nodeId() );
02681 update( true );
02682 }
02683 }
02684
02685 void KMReaderWin::msgAdded( QListViewItem *item )
02686 {
02687
02688
02689
02690 disconnectMsgAdded();
02691 KMHeaders * const headers = KMKernel::self()->getKMMainWidget()->headers();
02692 headers->setCurrentItem( item );
02693 headers->clearSelection();
02694 headers->setSelected( item, true );
02695 }
02696
02697 void KMReaderWin::disconnectMsgAdded()
02698 {
02699 const KMHeaders *const headers = KMKernel::self()->getKMMainWidget()->headers();
02700 disconnect( headers, SIGNAL( msgAddedToListView( QListViewItem* ) ),
02701 this, SLOT( msgAdded( QListViewItem* ) ) );
02702 }
02703
02704 void KMReaderWin::slotEditAttachment(partNode * node)
02705 {
02706 if ( KMessageBox::warningContinueCancel( this,
02707 i18n("Modifying an attachment might invalidate any digital signature on this message."),
02708 i18n("Edit Attachment"), KGuiItem( i18n("Edit"), "edit" ), "EditAttachmentSignatureWarning" )
02709 != KMessageBox::Continue ) {
02710 return;
02711 }
02712
02713 int nodeId = -1;
02714 KMMessage *msg = 0;
02715 fillCommandInfo( node, &msg, &nodeId );
02716 if ( msg && nodeId != -1 ) {
02717 KMEditAttachmentCommand* command = new KMEditAttachmentCommand( nodeId, msg, this );
02718 command->start();
02719 }
02720
02721
02722 }
02723
02724 KMail::CSSHelper* KMReaderWin::cssHelper()
02725 {
02726 return mCSSHelper;
02727 }
02728
02729 bool KMReaderWin::decryptMessage() const
02730 {
02731 if ( !GlobalSettings::self()->alwaysDecrypt() )
02732 return mDecrytMessageOverwrite;
02733 return true;
02734 }
02735
02736 void KMReaderWin::scrollToAttachment( const partNode *node )
02737 {
02738 DOM::Document doc = mViewer->htmlDocument();
02739
02740
02741 mViewer->gotoAnchor( QString::fromLatin1( "att%1" ).arg( node->nodeId() ) );
02742
02743
02744 const partNode *root = node->topLevelParent();
02745 for ( int i = 0; i <= root->totalChildCount() + 1; i++ ) {
02746 DOM::Element attachmentDiv = doc.getElementById( QString( "attachmentDiv%1" ).arg( i + 1 ) );
02747 if ( !attachmentDiv.isNull() )
02748 attachmentDiv.removeAttribute( "style" );
02749 }
02750
02751
02752
02753
02754 DOM::Element attachmentDiv = doc.getElementById( QString( "attachmentDiv%1" ).arg( node->nodeId() ) );
02755 if ( attachmentDiv.isNull() ) {
02756 kdWarning( 5006 ) << "Could not find attachment div for attachment " << node->nodeId() << endl;
02757 return;
02758 }
02759 attachmentDiv.setAttribute( "style", QString( "border:2px solid %1" )
02760 .arg( cssHelper()->pgpWarnColor().name() ) );
02761
02762
02763
02764 doc.updateRendering();
02765 }
02766
02767 void KMReaderWin::injectAttachments()
02768 {
02769
02770
02771 DOM::Document doc = mViewer->htmlDocument();
02772 DOM::Element injectionPoint = doc.getElementById( "attachmentInjectionPoint" );
02773 if ( injectionPoint.isNull() )
02774 return;
02775
02776 QString imgpath( locate("data","kmail/pics/") );
02777 QString visibility;
02778 QString urlHandle;
02779 QString imgSrc;
02780 if( !showAttachmentQuicklist() )
02781 {
02782 urlHandle.append( "kmail:showAttachmentQuicklist" );
02783 imgSrc.append( "attachmentQuicklistClosed.png" );
02784 } else {
02785 urlHandle.append( "kmail:hideAttachmentQuicklist" );
02786 imgSrc.append( "attachmentQuicklistOpened.png" );
02787 }
02788
02789 QString html = renderAttachments( mRootNode, QApplication::palette().active().background() );
02790 if ( html.isEmpty() )
02791 return;
02792
02793 QString link("");
02794 if ( headerStyle() == HeaderStyle::fancy() ) {
02795 link += "<div style=\"text-align: left;\"><a href=\""+urlHandle+"\"><img src=\""+imgpath+imgSrc+"\"/></a></div>";
02796 html.prepend( link );
02797 html.prepend( QString::fromLatin1("<div style=\"float:left;\">%1 </div>" ).arg(i18n("Attachments:")) );
02798 } else {
02799 link += "<div style=\"text-align: right;\"><a href=\""+urlHandle+"\"><img src=\""+imgpath+imgSrc+"\"/></a></div>";
02800 html.prepend( link );
02801 }
02802
02803 assert( injectionPoint.tagName() == "div" );
02804 static_cast<DOM::HTMLElement>( injectionPoint ).setInnerHTML( html );
02805 }
02806
02807 static QColor nextColor( const QColor & c )
02808 {
02809 int h, s, v;
02810 c.hsv( &h, &s, &v );
02811 return QColor( (h + 50) % 360, QMAX(s, 64), v, QColor::Hsv );
02812 }
02813
02814 QString KMReaderWin::renderAttachments(partNode * node, const QColor &bgColor )
02815 {
02816 if ( !node )
02817 return QString();
02818
02819 QString html;
02820 if ( node->firstChild() ) {
02821 QString subHtml = renderAttachments( node->firstChild(), nextColor( bgColor ) );
02822 if ( !subHtml.isEmpty() ) {
02823
02824 QString visibility;
02825 if ( !showAttachmentQuicklist() ) {
02826 visibility.append( "display:none;" );
02827 }
02828
02829 QString margin;
02830 if ( node != mRootNode || headerStyle() != HeaderStyle::enterprise() )
02831 margin = "padding:2px; margin:2px; ";
02832 QString align = "left";
02833 if ( headerStyle() == HeaderStyle::enterprise() )
02834 align = "right";
02835 if ( node->msgPart().typeStr().lower() == "message" || node == mRootNode )
02836 html += QString::fromLatin1("<div style=\"background:%1; %2"
02837 "vertical-align:middle; float:%3; %4\">").arg( bgColor.name() ).arg( margin )
02838 .arg( align ).arg( visibility );
02839 html += subHtml;
02840 if ( node->msgPart().typeStr().lower() == "message" || node == mRootNode )
02841 html += "</div>";
02842 }
02843 } else {
02844 QString label, icon;
02845 icon = node->msgPart().iconName( KIcon::Small );
02846 label = node->msgPart().contentDescription();
02847 if( label.isEmpty() )
02848 label = node->msgPart().name().stripWhiteSpace();
02849 if( label.isEmpty() )
02850 label = node->msgPart().fileName();
02851 bool typeBlacklisted = node->msgPart().typeStr().lower() == "multipart";
02852 if ( !typeBlacklisted && node->msgPart().typeStr().lower() == "application" ) {
02853 typeBlacklisted = node->msgPart().subtypeStr() == "pgp-encrypted"
02854 || node->msgPart().subtypeStr().lower() == "pgp-signature"
02855 || node->msgPart().subtypeStr().lower() == "pkcs7-mime"
02856 || node->msgPart().subtypeStr().lower() == "pkcs7-signature";
02857 }
02858 typeBlacklisted = typeBlacklisted || node == mRootNode;
02859 bool firstTextChildOfEncapsulatedMsg = node->msgPart().typeStr().lower() == "text" &&
02860 node->msgPart().subtypeStr().lower() == "plain" &&
02861 node->parentNode() &&
02862 node->parentNode()->msgPart().typeStr().lower() == "message";
02863 typeBlacklisted = typeBlacklisted || firstTextChildOfEncapsulatedMsg;
02864 if ( !label.isEmpty() && !icon.isEmpty() && !typeBlacklisted ) {
02865 html += "<div style=\"float:left;\">";
02866 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() );
02867 QString fileName = writeMessagePartToTempFile( &node->msgPart(), node->nodeId() );
02868 QString href = node->asHREF( "header" );
02869 html += QString::fromLatin1( "<a href=\"" ) + href +
02870 QString::fromLatin1( "\">" );
02871 html += "<img style=\"vertical-align:middle;\" src=\"" + icon + "\"/> ";
02872 if ( headerStyle() == HeaderStyle::enterprise() ) {
02873 QFont bodyFont = mCSSHelper->bodyFont( isFixedFont() );
02874 QFontMetrics fm( bodyFont );
02875 html += KStringHandler::rPixelSqueeze( label, fm, 140 );
02876 } else if ( headerStyle() == HeaderStyle::fancy() ) {
02877 QFont bodyFont = mCSSHelper->bodyFont( isFixedFont() );
02878 QFontMetrics fm( bodyFont );
02879 html += KStringHandler::rPixelSqueeze( label, fm, 1000 );
02880 } else {
02881 html += label;
02882 }
02883 html += "</a></span></div> ";
02884 }
02885 }
02886
02887 html += renderAttachments( node->nextSibling(), nextColor ( bgColor ) );
02888 return html;
02889 }
02890
02891 using namespace KMail::Interface;
02892
02893 void KMReaderWin::setBodyPartMemento( const partNode * node, const QCString & which, BodyPartMemento * memento )
02894 {
02895 const QCString index = node->path() + ':' + which.lower();
02896
02897 const std::map<QCString,BodyPartMemento*>::iterator it = mBodyPartMementoMap.lower_bound( index );
02898 if ( it != mBodyPartMementoMap.end() && it->first == index ) {
02899
02900 if ( memento && memento == it->second )
02901 return;
02902
02903 delete it->second;
02904
02905 if ( memento )
02906 it->second = memento;
02907 else
02908 mBodyPartMementoMap.erase( it );
02909
02910 } else {
02911 if ( memento )
02912 mBodyPartMementoMap.insert( it, std::make_pair( index, memento ) );
02913 }
02914
02915 if ( Observable * o = memento ? memento->asObservable() : 0 )
02916 o->attach( this );
02917 }
02918
02919 BodyPartMemento * KMReaderWin::bodyPartMemento( const partNode * node, const QCString & which ) const
02920 {
02921 const QCString index = node->path() + ':' + which.lower();
02922 const std::map<QCString,BodyPartMemento*>::const_iterator it = mBodyPartMementoMap.find( index );
02923 if ( it == mBodyPartMementoMap.end() )
02924 return 0;
02925 else
02926 return it->second;
02927 }
02928
02929 void KMReaderWin::clearBodyPartMementos()
02930 {
02931 for ( std::map<QCString,BodyPartMemento*>::const_iterator it = mBodyPartMementoMap.begin(), end = mBodyPartMementoMap.end() ; it != end ; ++it )
02932 delete it->second;
02933 mBodyPartMementoMap.clear();
02934 }
02935
02936 #include "kmreaderwin.moc"
02937
02938