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