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