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