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