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