10 #include "kmreaderwin.h"
12 #include "globalsettings.h"
13 #include "kmversion.h"
14 #include "kmmainwidget.h"
15 #include "kmreadermainwin.h"
16 #include <libtdepim/tdefileio.h>
17 #include "kmfolderindex.h"
18 #include "kmcommands.h"
19 #include "kmmsgpartdlg.h"
20 #include "mailsourceviewer.h"
21 using KMail::MailSourceViewer;
23 #include "kmmsgdict.h"
24 #include "messagesender.h"
25 #include "kcursorsaver.h"
27 #include "vcardviewer.h"
28 using KMail::VCardViewer;
29 #include "objecttreeparser.h"
30 using KMail::ObjectTreeParser;
31 #include "partmetadata.h"
32 using KMail::PartMetaData;
33 #include "attachmentstrategy.h"
34 using KMail::AttachmentStrategy;
35 #include "headerstrategy.h"
36 using KMail::HeaderStrategy;
37 #include "headerstyle.h"
39 #include "tdehtmlparthtmlwriter.h"
41 using KMail::KHtmlPartHtmlWriter;
42 #include "htmlstatusbar.h"
44 #include "folderjob.h"
45 using KMail::FolderJob;
46 #include "csshelper.h"
47 using KMail::CSSHelper;
49 using KMail::ISubject;
50 #include "urlhandlermanager.h"
52 #include "interfaces/observable.h"
54 #include "kmheaders.h"
56 #include "broadcaststatus.h"
58 #include <kmime_mdn.h>
59 using namespace KMime;
60 #ifdef KMAIL_READER_HTML_DEBUG
61 #include "filehtmlwriter.h"
62 using KMail::FileHtmlWriter;
63 #include "teehtmlwriter.h"
67 #include <kasciistringtools.h>
68 #include <kstringhandler.h>
70 #include <mimelib/mimepp.h>
71 #include <mimelib/body.h>
72 #include <mimelib/utility.h>
74 #include <kleo/specialjob.h>
75 #include <kleo/cryptobackend.h>
76 #include <kleo/cryptobackendfactory.h>
79 #include <tdeabc/addressee.h>
80 #include <tdeabc/vcardconverter.h>
83 #include <tdehtml_part.h>
84 #include <tdehtmlview.h>
85 #include <dom/html_element.h>
86 #include <dom/html_block.h>
87 #include <dom/html_document.h>
88 #include <dom/dom_string.h>
89 #include <dom/dom_exception.h>
91 #include <tdeapplication.h>
93 #include <kuserprofile.h>
94 #include <kcharsets.h>
95 #include <tdepopupmenu.h>
96 #include <kstandarddirs.h>
99 #include <tdefiledialog.h>
100 #include <tdelocale.h>
101 #include <tdemessagebox.h>
102 #include <tdeglobalsettings.h>
104 #include <tdetempfile.h>
105 #include <kprocess.h>
107 #include <tdeaction.h>
108 #include <kiconloader.h>
109 #include <kmdcodec.h>
110 #include <kasciistricmp.h>
111 #include <kurldrag.h>
113 #include <tqclipboard.h>
115 #include <tqtextcodec.h>
116 #include <tqpaintdevicemetrics.h>
117 #include <tqlayout.h>
119 #include <tqsplitter.h>
128 #include <sys/stat.h>
138 class NewByteArray :
public TQByteArray
141 NewByteArray &appendNULL();
142 NewByteArray &operator+=(
const char * );
143 NewByteArray &operator+=(
const TQByteArray & );
144 NewByteArray &operator+=(
const TQCString & );
145 TQByteArray& qByteArray();
148 NewByteArray& NewByteArray::appendNULL()
150 TQByteArray::detach();
152 if ( !TQByteArray::resize( len1 + 1 ) )
154 *(data() + len1) =
'\0';
157 NewByteArray& NewByteArray::operator+=(
const char * newData )
161 TQByteArray::detach();
163 uint len2 = tqstrlen( newData );
164 if ( !TQByteArray::resize( len1 + len2 ) )
166 memcpy( data() + len1, newData, len2 );
169 NewByteArray& NewByteArray::operator+=(
const TQByteArray & newData )
171 if ( newData.isNull() )
173 TQByteArray::detach();
175 uint len2 = newData.size();
176 if ( !TQByteArray::resize( len1 + len2 ) )
178 memcpy( data() + len1, newData.data(), len2 );
181 NewByteArray& NewByteArray::operator+=(
const TQCString & newData )
183 if ( newData.isEmpty() )
185 TQByteArray::detach();
187 uint len2 = newData.length();
188 if ( !TQByteArray::resize( len1 + len2 ) )
190 memcpy( data() + len1, newData.data(), len2 );
193 TQByteArray& NewByteArray::qByteArray()
195 return *((TQByteArray*)
this);
202 void KMReaderWin::objectTreeToDecryptedMsg( partNode* node,
203 NewByteArray& resultingData,
205 bool weAreReplacingTheRootNode,
208 kdDebug(5006) << TQString(
"-------------------------------------------------" ) << endl;
209 kdDebug(5006) << TQString(
"KMReaderWin::objectTreeToDecryptedMsg( %1 ) START").arg( recCount ) << endl;
212 kdDebug(5006) << node->typeString() <<
'/' << node->subTypeString() << endl;
214 partNode* curNode = node;
215 partNode* dataNode = curNode;
216 partNode * child = node->firstChild();
217 const bool bIsMultipart = node->type() == DwMime::kTypeMultipart ;
218 bool bKeepPartAsIs =
false;
220 switch( curNode->type() ){
221 case DwMime::kTypeMultipart: {
222 switch( curNode->subType() ){
223 case DwMime::kSubtypeSigned: {
224 bKeepPartAsIs =
true;
227 case DwMime::kSubtypeEncrypted: {
235 case DwMime::kTypeMessage: {
236 switch( curNode->subType() ){
237 case DwMime::kSubtypeRfc822: {
245 case DwMime::kTypeApplication: {
246 switch( curNode->subType() ){
247 case DwMime::kSubtypeOctetStream: {
252 case DwMime::kSubtypePkcs7Signature: {
255 bKeepPartAsIs =
true;
258 case DwMime::kSubtypePkcs7Mime: {
261 if ( child && curNode->encryptionState() != KMMsgNotEncrypted )
271 DwHeaders& rootHeaders( theMessage.
headers() );
272 DwBodyPart * part = dataNode->dwPart() ? dataNode->dwPart() : 0;
274 (part && part->hasHeaders())
276 : ( (weAreReplacingTheRootNode || !dataNode->parentNode())
279 if( dataNode == curNode ) {
280 kdDebug(5006) <<
"dataNode == curNode: Save curNode without replacing it." << endl;
286 if( dataNode->parentNode() && !weAreReplacingTheRootNode ) {
287 kdDebug(5006) <<
"dataNode is NOT replacing the root node: Store the headers." << endl;
288 resultingData += headers->AsString().c_str();
289 }
else if( weAreReplacingTheRootNode && part && part->hasHeaders() ){
290 kdDebug(5006) <<
"dataNode replace the root node: Do NOT store the headers but change" << endl;
291 kdDebug(5006) <<
" the Message's headers accordingly." << endl;
292 kdDebug(5006) <<
" old Content-Type = " << rootHeaders.ContentType().AsString().c_str() << endl;
293 kdDebug(5006) <<
" new Content-Type = " << headers->ContentType( ).AsString().c_str() << endl;
294 rootHeaders.ContentType() = headers->ContentType();
295 theMessage.setContentTransferEncodingStr(
296 headers->HasContentTransferEncoding()
297 ? headers->ContentTransferEncoding().AsString().c_str()
299 rootHeaders.ContentDescription() = headers->ContentDescription();
300 rootHeaders.ContentDisposition() = headers->ContentDisposition();
305 if ( bKeepPartAsIs ) {
306 resultingData += dataNode->encodedBody();
310 if( headers && bIsMultipart && dataNode->firstChild() ) {
311 kdDebug(5006) <<
"is valid Multipart, processing children:" << endl;
312 TQCString boundary = headers->ContentType().Boundary().c_str();
313 curNode = dataNode->firstChild();
316 kdDebug(5006) <<
"--boundary" << endl;
317 if( resultingData.size() &&
318 (
'\n' != resultingData.at( resultingData.size()-1 ) ) )
319 resultingData += TQCString(
"\n" );
320 resultingData += TQCString(
"\n" );
321 resultingData +=
"--";
322 resultingData += boundary;
323 resultingData +=
"\n";
327 objectTreeToDecryptedMsg( curNode,
332 curNode = curNode->nextSibling();
334 kdDebug(5006) <<
"--boundary--" << endl;
335 resultingData +=
"\n--";
336 resultingData += boundary;
337 resultingData +=
"--\n\n";
338 kdDebug(5006) <<
"Multipart processing children - DONE" << endl;
341 kdDebug(5006) <<
"is Simple part or invalid Multipart, storing body data .. DONE" << endl;
342 resultingData += part->Body().AsString().c_str();
346 kdDebug(5006) <<
"dataNode != curNode: Replace curNode by dataNode." << endl;
347 bool rootNodeReplaceFlag = weAreReplacingTheRootNode || !curNode->parentNode();
348 if( rootNodeReplaceFlag ) {
349 kdDebug(5006) <<
" Root node will be replaced." << endl;
351 kdDebug(5006) <<
" Root node will NOT be replaced." << endl;
355 objectTreeToDecryptedMsg( dataNode,
362 kdDebug(5006) << TQString(
"\nKMReaderWin::objectTreeToDecryptedMsg( %1 ) END").arg( recCount ) << endl;
386 void KMReaderWin::createWidgets() {
387 TQVBoxLayout * vlay =
new TQVBoxLayout(
this );
388 mSplitter =
new TQSplitter( Qt::Vertical,
this,
"mSplitter" );
389 vlay->addWidget( mSplitter );
390 mMimePartTree =
new KMMimePartTree(
this, mSplitter,
"mMimePartTree" );
391 mBox =
new TQHBox( mSplitter,
"mBox" );
392 setStyleDependantFrameWidth();
393 mBox->setFrameStyle( mMimePartTree->frameStyle() );
395 mViewer =
new TDEHTMLPart( mBox,
"mViewer" );
396 mSplitter->setOpaqueResize( TDEGlobalSettings::opaqueResize() );
397 mSplitter->setResizeMode( mMimePartTree, TQSplitter::KeepSize );
400 const int KMReaderWin::delay = 150;
403 KMReaderWin::KMReaderWin(TQWidget *aParent,
404 TQWidget *mainWindow,
405 TDEActionCollection* actionCollection,
408 : TQWidget(aParent, aName, aFlags | TQt::WDestructiveClose),
409 mSerNumOfOriginalMessage( 0 ),
411 mAttachmentStrategy( 0 ),
412 mHeaderStrategy( 0 ),
414 mUpdateReaderWinTimer( 0,
"mUpdateReaderWinTimer" ),
415 mResizeTimer( 0,
"mResizeTimer" ),
416 mDelayedMarkTimer( 0,
"mDelayedMarkTimer" ),
417 mHeaderRefreshTimer( 0,
"mHeaderRefreshTimer" ),
418 mOldGlobalOverrideEncoding(
"---" ),
421 mMainWindow( mainWindow ),
422 mActionCollection( actionCollection ),
423 mMailToComposeAction( 0 ),
424 mMailToReplyAction( 0 ),
425 mMailToForwardAction( 0 ),
426 mAddAddrBookAction( 0 ),
427 mOpenAddrBookAction( 0 ),
431 mUrlSaveAsAction( 0 ),
432 mAddBookmarksAction( 0 ),
433 mStartIMChatAction( 0 ),
434 mSelectAllAction( 0 ),
435 mHeaderOnlyAttachmentsAction( 0 ),
436 mSelectEncodingAction( 0 ),
437 mToggleFixFontAction( 0 ),
438 mCanStartDrag( false ),
440 mSavedRelativePosition( 0 ),
441 mDecrytMessageOverwrite( false ),
442 mShowSignatureDetails( false ),
443 mShowAttachmentQuicklist( true ),
444 mShowRawToltecMail( false )
446 mExternalWindow = (aParent == mainWindow );
447 mSplitterSizes << 180 << 100;
449 mMimeTreeAtBottom =
true;
452 mWaitingForSerNum = 0;
456 mShowColorbar =
false;
460 createActions( actionCollection );
464 mHtmlOverride =
false;
465 mHtmlLoadExtOverride =
false;
467 mLevelQuote = GlobalSettings::self()->collapseQuoteLevelSpin() - 1;
469 connect( &mUpdateReaderWinTimer, TQT_SIGNAL(timeout()),
470 TQT_TQOBJECT(
this), TQT_SLOT(updateReaderWin()) );
471 connect( &mResizeTimer, TQT_SIGNAL(timeout()),
472 TQT_TQOBJECT(
this), TQT_SLOT(slotDelayedResize()) );
473 connect( &mDelayedMarkTimer, TQT_SIGNAL(timeout()),
474 TQT_TQOBJECT(
this), TQT_SLOT(slotTouchMessage()) );
475 connect( &mHeaderRefreshTimer, TQT_SIGNAL(timeout()),
476 TQT_TQOBJECT(
this), TQT_SLOT(updateHeader()) );
480 void KMReaderWin::createActions( TDEActionCollection * ac ) {
484 TDERadioAction *raction = 0;
487 TDEActionMenu *headerMenu =
488 new TDEActionMenu( i18n(
"View->",
"&Headers"), ac,
"view_headers" );
489 headerMenu->setToolTip( i18n(
"Choose display style of message headers") );
491 connect( headerMenu, TQT_SIGNAL(activated()),
492 TQT_TQOBJECT(
this), TQT_SLOT(slotCycleHeaderStyles()) );
494 raction =
new TDERadioAction( i18n(
"View->headers->",
"&Enterprise Headers"), 0,
495 TQT_TQOBJECT(
this), TQT_SLOT(slotEnterpriseHeaders()),
496 ac,
"view_headers_enterprise" );
497 raction->setToolTip( i18n(
"Show the list of headers in Enterprise style") );
498 raction->setExclusiveGroup(
"view_headers_group" );
499 headerMenu->insert(raction);
501 raction =
new TDERadioAction( i18n(
"View->headers->",
"&Fancy Headers"), 0,
502 TQT_TQOBJECT(
this), TQT_SLOT(slotFancyHeaders()),
503 ac,
"view_headers_fancy" );
504 raction->setToolTip( i18n(
"Show the list of headers in a fancy format") );
505 raction->setExclusiveGroup(
"view_headers_group" );
506 headerMenu->insert( raction );
508 raction =
new TDERadioAction( i18n(
"View->headers->",
"&Brief Headers"), 0,
509 TQT_TQOBJECT(
this), TQT_SLOT(slotBriefHeaders()),
510 ac,
"view_headers_brief" );
511 raction->setToolTip( i18n(
"Show brief list of message headers") );
512 raction->setExclusiveGroup(
"view_headers_group" );
513 headerMenu->insert( raction );
515 raction =
new TDERadioAction( i18n(
"View->headers->",
"&Standard Headers"), 0,
516 TQT_TQOBJECT(
this), TQT_SLOT(slotStandardHeaders()),
517 ac,
"view_headers_standard" );
518 raction->setToolTip( i18n(
"Show standard list of message headers") );
519 raction->setExclusiveGroup(
"view_headers_group" );
520 headerMenu->insert( raction );
522 raction =
new TDERadioAction( i18n(
"View->headers->",
"&Long Headers"), 0,
523 TQT_TQOBJECT(
this), TQT_SLOT(slotLongHeaders()),
524 ac,
"view_headers_long" );
525 raction->setToolTip( i18n(
"Show long list of message headers") );
526 raction->setExclusiveGroup(
"view_headers_group" );
527 headerMenu->insert( raction );
529 raction =
new TDERadioAction( i18n(
"View->headers->",
"&All Headers"), 0,
530 TQT_TQOBJECT(
this), TQT_SLOT(slotAllHeaders()),
531 ac,
"view_headers_all" );
532 raction->setToolTip( i18n(
"Show all message headers") );
533 raction->setExclusiveGroup(
"view_headers_group" );
534 headerMenu->insert( raction );
537 TDEActionMenu *attachmentMenu =
538 new TDEActionMenu( i18n(
"View->",
"&Attachments"), ac,
"view_attachments" );
539 attachmentMenu->setToolTip( i18n(
"Choose display style of attachments") );
540 connect( attachmentMenu, TQT_SIGNAL(activated()),
541 TQT_TQOBJECT(
this), TQT_SLOT(slotCycleAttachmentStrategy()) );
543 raction =
new TDERadioAction( i18n(
"View->attachments->",
"&As Icons"), 0,
544 TQT_TQOBJECT(
this), TQT_SLOT(slotIconicAttachments()),
545 ac,
"view_attachments_as_icons" );
546 raction->setToolTip( i18n(
"Show all attachments as icons. Click to see them.") );
547 raction->setExclusiveGroup(
"view_attachments_group" );
548 attachmentMenu->insert( raction );
550 raction =
new TDERadioAction( i18n(
"View->attachments->",
"&Smart"), 0,
551 TQT_TQOBJECT(
this), TQT_SLOT(slotSmartAttachments()),
552 ac,
"view_attachments_smart" );
553 raction->setToolTip( i18n(
"Show attachments as suggested by sender.") );
554 raction->setExclusiveGroup(
"view_attachments_group" );
555 attachmentMenu->insert( raction );
557 raction =
new TDERadioAction( i18n(
"View->attachments->",
"&Inline"), 0,
558 TQT_TQOBJECT(
this), TQT_SLOT(slotInlineAttachments()),
559 ac,
"view_attachments_inline" );
560 raction->setToolTip( i18n(
"Show all attachments inline (if possible)") );
561 raction->setExclusiveGroup(
"view_attachments_group" );
562 attachmentMenu->insert( raction );
564 raction =
new TDERadioAction( i18n(
"View->attachments->",
"&Hide"), 0,
565 TQT_TQOBJECT(
this), TQT_SLOT(slotHideAttachments()),
566 ac,
"view_attachments_hide" );
567 raction->setToolTip( i18n(
"Do not show attachments in the message viewer") );
568 raction->setExclusiveGroup(
"view_attachments_group" );
569 attachmentMenu->insert( raction );
571 mHeaderOnlyAttachmentsAction =
new TDERadioAction( i18n(
"View->attachments->",
"In Header &Only" ), 0,
572 TQT_TQOBJECT(
this), TQT_SLOT( slotHeaderOnlyAttachments() ),
573 ac,
"view_attachments_headeronly" );
574 mHeaderOnlyAttachmentsAction->setToolTip( i18n(
"Show Attachments only in the header of the mail" ) );
575 mHeaderOnlyAttachmentsAction->setExclusiveGroup(
"view_attachments_group" );
576 attachmentMenu->insert( mHeaderOnlyAttachmentsAction );
579 mSelectEncodingAction =
new TDESelectAction( i18n(
"&Set Encoding" ),
"charset", 0,
580 TQT_TQOBJECT(
this), TQT_SLOT( slotSetEncoding() ),
582 TQStringList encodings = KMMsgBase::supportedEncodings(
false );
583 encodings.prepend( i18n(
"Auto" ) );
584 mSelectEncodingAction->setItems( encodings );
585 mSelectEncodingAction->setCurrentItem( 0 );
587 mMailToComposeAction =
new TDEAction( i18n(
"New Message To..."),
"mail-message-new",
588 0, TQT_TQOBJECT(
this), TQT_SLOT(slotMailtoCompose()), ac,
590 mMailToReplyAction =
new TDEAction( i18n(
"Reply To..."),
"mail-reply-sender",
593 mMailToForwardAction =
new TDEAction( i18n(
"Forward To..."),
"mail-forward",
594 0, TQT_TQOBJECT(
this), TQT_SLOT(slotMailtoForward()), ac,
596 mAddAddrBookAction =
new TDEAction( i18n(
"Add to Address Book"),
597 0, TQT_TQOBJECT(
this), TQT_SLOT(slotMailtoAddAddrBook()),
598 ac,
"add_addr_book" );
599 mOpenAddrBookAction =
new TDEAction( i18n(
"Open in Address Book"),
600 0, TQT_TQOBJECT(
this), TQT_SLOT(slotMailtoOpenAddrBook()),
601 ac,
"openin_addr_book" );
602 mCopyAction = KStdAction::copy( TQT_TQOBJECT(
this), TQT_SLOT(
slotCopySelectedText()), ac,
"kmail_copy");
603 mSelectAllAction =
new TDEAction( i18n(
"Select All Text"), CTRL+SHIFT+Key_A, TQT_TQOBJECT(
this),
604 TQT_SLOT(
selectAll()), ac,
"mark_all_text" );
605 mCopyURLAction =
new TDEAction( i18n(
"Copy Link Address"), 0, TQT_TQOBJECT(
this),
607 mUrlOpenAction =
new TDEAction( i18n(
"Open URL"), 0, TQT_TQOBJECT(
this),
609 mAddBookmarksAction =
new TDEAction( i18n(
"Bookmark This Link"),
611 0, TQT_TQOBJECT(
this), TQT_SLOT(slotAddBookmarks()),
612 ac,
"add_bookmarks" );
613 mUrlSaveAsAction =
new TDEAction( i18n(
"Save Link As..."), 0, TQT_TQOBJECT(
this),
616 mToggleFixFontAction =
new TDEToggleAction( i18n(
"Use Fi&xed Font"),
618 ac,
"toggle_fixedfont" );
620 mStartIMChatAction =
new TDEAction( i18n(
"Chat &With..."), 0, TQT_TQOBJECT(
this),
621 TQT_SLOT(
slotIMChat()), ac,
"start_im_chat" );
625 TDERadioAction *KMReaderWin::actionForHeaderStyle(
const HeaderStyle * style,
const HeaderStrategy * strategy ) {
626 if ( !mActionCollection )
628 const char * actionName = 0;
629 if ( style == HeaderStyle::enterprise() )
630 actionName =
"view_headers_enterprise";
631 if ( style == HeaderStyle::fancy() )
632 actionName =
"view_headers_fancy";
633 else if ( style == HeaderStyle::brief() )
634 actionName =
"view_headers_brief";
635 else if ( style == HeaderStyle::plain() ) {
636 if ( strategy == HeaderStrategy::standard() )
637 actionName =
"view_headers_standard";
638 else if ( strategy == HeaderStrategy::rich() )
639 actionName =
"view_headers_long";
640 else if ( strategy == HeaderStrategy::all() )
641 actionName =
"view_headers_all";
644 return static_cast<TDERadioAction*
>(mActionCollection->action(actionName));
649 TDERadioAction *KMReaderWin::actionForAttachmentStrategy(
const AttachmentStrategy * as ) {
650 if ( !mActionCollection )
652 const char * actionName = 0;
653 if ( as == AttachmentStrategy::iconic() )
654 actionName =
"view_attachments_as_icons";
655 else if ( as == AttachmentStrategy::smart() )
656 actionName =
"view_attachments_smart";
657 else if ( as == AttachmentStrategy::inlined() )
658 actionName =
"view_attachments_inline";
659 else if ( as == AttachmentStrategy::hidden() )
660 actionName =
"view_attachments_hide";
661 else if ( as == AttachmentStrategy::headerOnly() )
662 actionName =
"view_attachments_headeronly";
665 return static_cast<TDERadioAction*
>(mActionCollection->action(actionName));
670 void KMReaderWin::slotEnterpriseHeaders() {
672 HeaderStrategy::rich() );
673 if( !mExternalWindow )
677 void KMReaderWin::slotFancyHeaders() {
679 HeaderStrategy::rich() );
680 if( !mExternalWindow )
684 void KMReaderWin::slotBriefHeaders() {
686 HeaderStrategy::brief() );
687 if( !mExternalWindow )
691 void KMReaderWin::slotStandardHeaders() {
693 HeaderStrategy::standard());
697 void KMReaderWin::slotLongHeaders() {
699 HeaderStrategy::rich() );
700 if( !mExternalWindow )
704 void KMReaderWin::slotAllHeaders() {
706 HeaderStrategy::all() );
707 if( !mExternalWindow )
711 void KMReaderWin::slotLevelQuote(
int l )
718 void KMReaderWin::slotCycleHeaderStyles() {
722 const char * actionName = 0;
723 if ( style == HeaderStyle::enterprise() ) {
725 actionName =
"view_headers_fancy";
727 if ( style == HeaderStyle::fancy() ) {
729 actionName =
"view_headers_brief";
730 }
else if ( style == HeaderStyle::brief() ) {
731 slotStandardHeaders();
732 actionName =
"view_headers_standard";
733 }
else if ( style == HeaderStyle::plain() ) {
734 if ( strategy == HeaderStrategy::standard() ) {
736 actionName =
"view_headers_long";
737 }
else if ( strategy == HeaderStrategy::rich() ) {
739 actionName =
"view_headers_all";
740 }
else if ( strategy == HeaderStrategy::all() ) {
741 slotEnterpriseHeaders();
742 actionName =
"view_headers_enterprise";
747 static_cast<TDERadioAction*
>( mActionCollection->action( actionName ) )->setChecked(
true );
751 void KMReaderWin::slotIconicAttachments() {
752 setAttachmentStrategy( AttachmentStrategy::iconic() );
755 void KMReaderWin::slotSmartAttachments() {
756 setAttachmentStrategy( AttachmentStrategy::smart() );
759 void KMReaderWin::slotInlineAttachments() {
760 setAttachmentStrategy( AttachmentStrategy::inlined() );
763 void KMReaderWin::slotHideAttachments() {
764 setAttachmentStrategy( AttachmentStrategy::hidden() );
767 void KMReaderWin::slotHeaderOnlyAttachments() {
768 setAttachmentStrategy( AttachmentStrategy::headerOnly() );
771 void KMReaderWin::slotCycleAttachmentStrategy() {
775 action->setChecked(
true );
780 KMReaderWin::~KMReaderWin()
785 clearBodyPartMementos();
786 delete mHtmlWriter; mHtmlWriter = 0;
788 if (mAutoDelete)
delete message();
789 delete mRootNode; mRootNode = 0;
795 void KMReaderWin::slotMessageArrived(
KMMessage *msg )
797 if (msg && ((KMMsgBase*)msg)->isMessage()) {
798 if ( msg->getMsgSerNum() == mWaitingForSerNum ) {
824 kdDebug(5006) <<
"KMReaderWin::update - no updated part" << endl;
827 partNode* node = mRootNode->findNodeForDwPart( msg->
lastUpdatedPart() );
829 kdDebug(5006) <<
"KMReaderWin::update - can't find node for part" << endl;
836 ::chmod( TQFile::encodeName( mAtmCurrentName ), S_IRWXU );
837 TQByteArray data = node->msgPart().bodyDecodedBinary();
838 size_t size = data.size();
839 if ( node->msgPart().type() == DwMime::kTypeText && size) {
842 KPIM::kBytesToFile( data.data(), size, mAtmCurrentName,
false,
false,
false );
843 ::chmod( TQFile::encodeName( mAtmCurrentName ), S_IRUSR );
851 for (TQStringList::Iterator it = mTempFiles.begin(); it != mTempFiles.end();
857 for (TQStringList::Iterator it = mTempDirs.begin(); it != mTempDirs.end();
860 TQDir(*it).rmdir(*it);
869 if (e->type() == TQEvent::ApplicationPaletteChange)
872 mCSSHelper =
new KMail::CSSHelper( TQPaintDeviceMetrics( mViewer->view() ) );
878 return TQWidget::event(e);
885 const TDEConfigGroup mdnGroup( KMKernel::config(),
"MDN" );
886 TDEConfigGroup reader( KMKernel::config(),
"Reader" );
889 mCSSHelper =
new KMail::CSSHelper( TQPaintDeviceMetrics( mViewer->view() ) );
891 mNoMDNsWhenEncrypted = mdnGroup.readBoolEntry(
"not-send-when-encrypted",
true );
893 mUseFixedFont = reader.readBoolEntry(
"useFixedFont",
false );
894 if ( mToggleFixFontAction )
895 mToggleFixFontAction->setChecked( mUseFixedFont );
897 mHtmlMail = reader.readBoolEntry(
"htmlMail",
false );
898 mHtmlLoadExternal = reader.readBoolEntry(
"htmlLoadExternal",
false );
901 HeaderStrategy::create( reader.readEntry(
"header-set-displayed",
"rich" ) ) );
902 TDERadioAction *raction = actionForHeaderStyle( headerStyle(),
headerStrategy() );
904 raction->setChecked(
true );
906 setAttachmentStrategy( AttachmentStrategy::create( reader.readEntry(
"attachment-strategy",
"smart" ) ) );
909 raction->setChecked(
true );
913 mShowColorbar = reader.readBoolEntry(
"showColorbar", Kpgp::Module::getKpgp()->usePGP() );
917 reader.writeEntry(
"showColorbar", mShowColorbar );
919 mMimeTreeAtBottom = reader.readEntry(
"MimeTreeLocation",
"bottom" ) !=
"top";
920 const TQString s = reader.readEntry(
"MimeTreeMode",
"smart" );
923 else if ( s ==
"always" )
928 const int mimeH = reader.readNumEntry(
"MimePaneHeight", 100 );
929 const int messageH = reader.readNumEntry(
"MessagePaneHeight", 180 );
930 mSplitterSizes.clear();
931 if ( mMimeTreeAtBottom )
932 mSplitterSizes << messageH << mimeH;
934 mSplitterSizes << mimeH << messageH;
938 readGlobalOverrideCodec();
946 void KMReaderWin::adjustLayout() {
947 if ( mMimeTreeAtBottom )
948 mSplitter->moveToLast( mMimePartTree );
950 mSplitter->moveToFirst( mMimePartTree );
951 mSplitter->setSizes( mSplitterSizes );
953 if ( mMimeTreeMode == 2 && mMsgDisplay )
954 mMimePartTree->show();
956 mMimePartTree->hide();
958 if ( mShowColorbar && mMsgDisplay )
965 void KMReaderWin::saveSplitterSizes( TDEConfigBase & c )
const {
966 if ( !mSplitter || !mMimePartTree )
968 if ( mMimePartTree->isHidden() )
971 c.writeEntry(
"MimePaneHeight", mSplitter->sizes()[ mMimeTreeAtBottom ? 1 : 0 ] );
972 c.writeEntry(
"MessagePaneHeight", mSplitter->sizes()[ mMimeTreeAtBottom ? 0 : 1 ] );
977 TDEConfigGroup reader( KMKernel::config(),
"Reader" );
979 reader.writeEntry(
"useFixedFont", mUseFixedFont );
981 reader.writeEntry(
"header-style", headerStyle()->name() );
983 reader.writeEntry(
"header-set-displayed",
headerStrategy()->name() );
987 saveSplitterSizes( reader );
990 kmkernel->slotRequestConfigSync();
996 mViewer->widget()->setFocusPolicy(TQ_WheelFocus);
998 mViewer->setPluginsEnabled(
false);
999 mViewer->setJScriptEnabled(
false);
1000 mViewer->setJavaEnabled(
false);
1001 mViewer->setMetaRefreshEnabled(
false);
1002 mViewer->setURLCursor(KCursor::handCursor());
1004 mViewer->view()->setLineWidth(0);
1006 mViewer->view()->viewport()->installEventFilter(
this );
1009 #ifdef KMAIL_READER_HTML_DEBUG
1010 mHtmlWriter =
new TeeHtmlWriter(
new FileHtmlWriter( TQString() ),
1011 new KHtmlPartHtmlWriter( mViewer, 0 ) );
1013 mHtmlWriter =
new KHtmlPartHtmlWriter( mViewer, 0 );
1016 connect(mViewer->browserExtension(),
1017 TQT_SIGNAL(openURLRequest(
const KURL &,
const KParts::URLArgs &)),
this,
1019 connect(mViewer->browserExtension(),
1020 TQT_SIGNAL(createNewWindow(
const KURL &,
const KParts::URLArgs &)),
this,
1022 connect(mViewer,TQT_SIGNAL(
popupMenu(
const TQString &,
const TQPoint &)),
1023 TQT_SLOT(
slotUrlPopup(
const TQString &,
const TQPoint &)));
1024 connect( kmkernel->imProxy(), TQT_SIGNAL( sigContactPresenceChanged(
const TQString & ) ),
1025 TQT_TQOBJECT(
this), TQT_SLOT( contactStatusChanged(
const TQString & ) ) );
1026 connect( kmkernel->imProxy(), TQT_SIGNAL( sigPresenceInfoExpired() ),
1030 void KMReaderWin::contactStatusChanged(
const TQString &uid)
1034 DOM::NodeList presenceNodes = mViewer->htmlDocument()
1035 .getElementsByName( DOM::DOMString( TQString::fromLatin1(
"presence-") + uid ) );
1036 for (
unsigned int i = 0; i < presenceNodes.length(); ++i ) {
1037 DOM::Node n = presenceNodes.item( i );
1038 kdDebug( 5006 ) <<
"name is " << n.nodeName().string() << endl;
1039 kdDebug( 5006 ) <<
"value of content was " << n.firstChild().nodeValue().string() << endl;
1040 TQString newPresence = kmkernel->imProxy()->presenceString( uid );
1041 if ( newPresence.isNull() )
1042 newPresence = TQString::fromLatin1(
"ENOIMRUNNING" );
1043 n.firstChild().setNodeValue( newPresence );
1049 void KMReaderWin::setAttachmentStrategy(
const AttachmentStrategy * strategy ) {
1050 mAttachmentStrategy = strategy ? strategy : AttachmentStrategy::smart();
1055 const HeaderStrategy * strategy ) {
1056 mHeaderStyle = style ? style : HeaderStyle::fancy();
1057 mHeaderStrategy = strategy ? strategy : HeaderStrategy::rich();
1058 if ( mHeaderOnlyAttachmentsAction ) {
1059 const bool styleHasAttachmentQuickList = mHeaderStyle == HeaderStyle::fancy() ||
1060 mHeaderStyle == HeaderStyle::enterprise();
1061 mHeaderOnlyAttachmentsAction->setEnabled( styleHasAttachmentQuickList );
1062 if ( !styleHasAttachmentQuickList && mAttachmentStrategy == AttachmentStrategy::headerOnly() ) {
1065 setAttachmentStrategy( AttachmentStrategy::smart() );
1074 if ( encoding == mOverrideEncoding )
1077 mOverrideEncoding = encoding;
1078 if ( mSelectEncodingAction ) {
1079 if ( encoding.isEmpty() ) {
1080 mSelectEncodingAction->setCurrentItem( 0 );
1083 TQStringList encodings = mSelectEncodingAction->items();
1085 for ( TQStringList::const_iterator it = encodings.begin(), end = encodings.end(); it != end; ++it, ++i ) {
1086 if ( TDEGlobal::charsets()->encodingForName( *it ) == encoding ) {
1087 mSelectEncodingAction->setCurrentItem( i );
1091 if ( i == encodings.size() ) {
1093 kdWarning(5006) <<
"Unknown override character encoding \"" << encoding
1094 <<
"\". Using Auto instead." << endl;
1095 mSelectEncodingAction->setCurrentItem( 0 );
1096 mOverrideEncoding = TQString();
1104 void KMReaderWin::setPrintFont(
const TQFont& font )
1107 mCSSHelper->setPrintFont( font );
1113 if ( mOverrideEncoding.isEmpty() || mOverrideEncoding ==
"Auto" )
1116 return KMMsgBase::codecForName( mOverrideEncoding.latin1() );
1120 void KMReaderWin::slotSetEncoding()
1122 if ( mSelectEncodingAction->currentItem() == 0 )
1123 mOverrideEncoding = TQString();
1125 mOverrideEncoding = TDEGlobal::charsets()->encodingForName( mSelectEncodingAction->currentText() );
1130 void KMReaderWin::readGlobalOverrideCodec()
1133 if ( GlobalSettings::self()->overrideCharacterEncoding() == mOldGlobalOverrideEncoding )
1137 mOldGlobalOverrideEncoding = GlobalSettings::self()->overrideCharacterEncoding();
1143 mSerNumOfOriginalMessage = serNumOfOriginalMessage;
1144 mNodeIdOffset = nodeIdOffset;
1151 kdDebug(5006) <<
"(" << aMsg->getMsgSerNum() <<
", last " << mLastSerNum <<
") " << aMsg->
subject() <<
" "
1152 << aMsg->fromStrip() <<
", readyToShow " << (aMsg->
readyToShow()) << endl;
1156 if ( aMsg && aMsg->getMsgSerNum() != mLastSerNum && !updateOnly ){
1157 mLevelQuote = GlobalSettings::self()->collapseQuoteLevelSpin()-1;
1158 mShowRawToltecMail = !GlobalSettings::self()->showToltecReplacementText();
1159 clearBodyPartMementos();
1164 bool complete =
true;
1167 (aMsg->getMsgSerNum() != mLastSerNum) &&
1172 if (!force && aMsg && mLastSerNum != 0 && aMsg->getMsgSerNum() == mLastSerNum)
1179 aMsg->attach(
this );
1182 mDelayedMarkTimer.stop();
1186 mWaitingForSerNum = 0;
1189 mLastSerNum = aMsg->getMsgSerNum();
1206 mViewer->setDNDEnabled(
false );
1208 mViewer->setDNDEnabled(
true );
1218 mUpdateReaderWinTimer.stop();
1221 else if (mUpdateReaderWinTimer.isActive())
1222 mUpdateReaderWinTimer.changeInterval( delay );
1224 mUpdateReaderWinTimer.start( 0,
true );
1227 if ( aMsg && (aMsg->isUnread() || aMsg->isNew()) && GlobalSettings::self()->delayedMarkAsRead() ) {
1228 if ( GlobalSettings::self()->delayedMarkTime() != 0 )
1229 mDelayedMarkTimer.start( GlobalSettings::self()->delayedMarkTime() * 1000,
true );
1234 mHeaderRefreshTimer.start( 1000,
false );
1240 mUpdateReaderWinTimer.stop();
1242 mDelayedMarkTimer.stop();
1244 mWaitingForSerNum = 0;
1249 static const char *
const kmailChanges[] = {
1252 static const int numKMailChanges =
1253 sizeof kmailChanges /
sizeof *kmailChanges;
1259 static const char *
const kmailNewFeatures[] = {
1260 I18N_NOOP(
"Full namespace support for IMAP"),
1261 I18N_NOOP(
"Offline mode"),
1262 I18N_NOOP(
"Sieve script management and editing"),
1263 I18N_NOOP(
"Account specific filtering"),
1264 I18N_NOOP(
"Filtering of incoming mail for online IMAP accounts"),
1265 I18N_NOOP(
"Online IMAP folders can be used when filtering into folders"),
1266 I18N_NOOP(
"Automatically delete older mails on POP servers")
1268 static const int numKMailNewFeatures =
1269 sizeof kmailNewFeatures /
sizeof *kmailNewFeatures;
1277 for (
int i = 0 ; i < numKMailChanges ; ++i )
1278 str += kmailChanges[i];
1279 for (
int i = 0 ; i < numKMailNewFeatures ; ++i )
1280 str += kmailNewFeatures[i];
1282 return md5.base64Digest();
1288 mMsgDisplay =
false;
1291 TQString location = locate(
"data",
"kmail/about/main.html");
1292 TQString content = KPIM::kFileToString(location);
1293 content = content.arg( locate(
"data",
"libtdepim/about/kde_infopage.css" ) );
1294 if ( kapp->reverseLayout() )
1295 content = content.arg(
"@import \"%1\";" ).arg( locate(
"data",
"libtdepim/about/kde_infopage_rtl.css" ) );
1297 content = content.arg(
"" );
1299 mViewer->begin(KURL( location ));
1301 TQString fontSize = TQString::number(
pointsToPixel( mCSSHelper->bodyFont().pointSize() ) );
1302 TQString appTitle = i18n(
"KMail");
1303 TQString catchPhrase =
"";
1304 TQString quickDescription = i18n(
"The email client for the Trinity Desktop Environment.");
1305 mViewer->write(content.arg(fontSize).arg(appTitle).arg(catchPhrase).arg(quickDescription).arg(info));
1312 i18n(
"<h2 style='margin-top: 0px;'>Retrieving Folder Contents</h2><p>Please wait . . .</p> " );
1320 i18n(
"<h2 style='margin-top: 0px;'>Offline</h2><p>KMail is currently in offline mode. "
1321 "Click <a href=\"kmail:goOnline\">here</a> to go online . . .</p> " );
1331 i18n(
"%1: KMail version; %2: help:// URL; %3: homepage URL; "
1332 "%4: prior KMail version; %5: prior TDE version; "
1333 "%6: generated list of new features; "
1334 "%7: First-time user text (only shown on first start); "
1335 "%8: generated list of important changes; "
1336 "--- end of comment ---",
1337 "<h2 style='margin-top: 0px;'>Welcome to KMail %1</h2><p>KMail is the email client for the Trinity "
1338 "Desktop Environment. It is designed to be fully compatible with "
1339 "Internet mailing standards including MIME, SMTP, POP3 and IMAP."
1341 "<ul><li>KMail has many powerful features which are described in the "
1342 "<a href=\"%2\">documentation</a></li>\n"
1343 "<li>The <a href=\"%3\">KMail (TDE) homepage</A> offers information about "
1344 "new versions of KMail</li></ul>\n"
1346 "<p>Some of the new features in this release of KMail include "
1347 "(compared to KMail %4, which is part of TDE %5):</p>\n"
1350 "<p>We hope that you will enjoy KMail.</p>\n"
1351 "<p>Thank you,</p>\n"
1352 "<p style='margin-bottom: 0px'> The KMail Team</p>")
1354 .arg(
"help:/kmail/index.html")
1355 .arg(
"http://www.trinitydesktop.org")
1356 .arg(
"1.8").arg(
"3.4");
1358 TQString featureItems;
1359 for (
int i = 0 ; i < numKMailNewFeatures ; i++ )
1360 featureItems += i18n(
"<li>%1</li>\n").arg( i18n( kmailNewFeatures[i] ) );
1362 info = info.arg( featureItems );
1364 if( kmkernel->firstStart() ) {
1365 info = info.arg( i18n(
"<p>Please take a moment to fill in the KMail "
1366 "configuration panel at Settings->Configure "
1368 "You need to create at least a default identity and "
1369 "an incoming as well as outgoing mail account."
1372 info = info.arg( TQString() );
1375 if ( ( numKMailChanges > 1 ) || ( numKMailChanges == 1 && strlen(kmailChanges[0]) > 0 ) ) {
1376 TQString changesText =
1377 i18n(
"<p><span style='font-size:125%; font-weight:bold;'>"
1378 "Important changes</span> (compared to KMail %1):</p>\n")
1380 changesText +=
"<ul>\n";
1381 for (
int i = 0 ; i < numKMailChanges ; i++ )
1382 changesText += i18n(
"<li>%1</li>\n").arg( i18n( kmailChanges[i] ) );
1383 changesText +=
"</ul>\n";
1384 info = info.arg( changesText );
1387 info = info.arg(
"");
1402 if (!mMsgDisplay)
return;
1411 if ( mShowColorbar )
1420 mMimePartTree->hide();
1421 mMimePartTree->clear();
1422 htmlWriter()->begin( mCSSHelper->cssDefinitions( isFixedFont() ) );
1423 htmlWriter()->write( mCSSHelper->htmlHead( isFixedFont() ) +
"</body></html>" );
1427 if (mSavedRelativePosition)
1429 TQScrollView * scrollview =
static_cast<TQScrollView *
>(mViewer->widget());
1430 scrollview->setContentsPos( 0,
1431 tqRound( scrollview->contentsHeight() * mSavedRelativePosition ) );
1432 mSavedRelativePosition = 0;
1439 const TQPaintDeviceMetrics pdm(mViewer->view());
1441 return (pointSize * pdm.logicalDpiY() + 36) / 72;
1446 if ( mMimeTreeMode == 2 ||
1447 ( mMimeTreeMode == 1 && !isPlainTextTopLevel ) )
1448 mMimePartTree->show();
1451 TDEConfigGroup reader( KMKernel::config(),
"Reader" );
1452 saveSplitterSizes( reader );
1453 mMimePartTree->hide();
1460 mMimePartTree->clear();
1462 ( msg->type() == DwMime::kTypeText
1463 && msg->subtype() == DwMime::kSubtypePlain ) );
1470 htmlWriter()->begin( mCSSHelper->cssDefinitions( isFixedFont() ) );
1471 htmlWriter()->queue( mCSSHelper->htmlHead( isFixedFont() ) );
1482 if( mColorBar->isNeutral() )
1488 TQTimer::singleShot( 1, TQT_TQOBJECT(
this), TQT_SLOT(injectAttachments()) );
1491 static bool message_was_saved_decrypted_before(
const KMMessage * msg ) {
1495 return msg->
msgId().stripWhiteSpace().startsWith(
"<DecryptedMsg." );
1501 KMMessagePart msgPart;
1502 TQCString subtype, contDisp;
1507 aMsg->setIsBeingParsed(
true );
1509 if ( mRootNode && !mRootNode->processed() )
1511 kdWarning() <<
"The root node is not yet processed! Danger!\n";
1515 mRootNode = partNode::fromMessage( aMsg,
this );
1516 const TQCString mainCntTypeStr = mRootNode->typeString() +
'/' + mRootNode->subTypeString();
1518 TQString cntDesc = aMsg->
subject();
1519 if( cntDesc.isEmpty() )
1520 cntDesc = i18n(
"( body part )");
1521 TDEIO::filesize_t cntSize = aMsg->
msgSize();
1529 mRootNode->fillMimePartTree( 0,
1536 partNode* vCardNode = mRootNode->findType( DwMime::kTypeText, DwMime::kSubtypeXVCard );
1537 bool hasVCard =
false;
1541 TDEABC::VCardConverter t;
1542 #if defined(KABC_VCARD_ENCODING_FIX)
1543 const TQByteArray vcard = vCardNode->msgPart().bodyDecodedBinary();
1544 if ( !t.parseVCardsRaw( vcard.data() ).empty() ) {
1546 const TQString vcard = vCardNode->msgPart().bodyToUnicode(
overrideCodec() );
1547 if ( !t.parseVCards( vcard ).empty() ) {
1554 if ( !mRootNode || !mRootNode->isToltecMessage() || mShowRawToltecMail ) {
1559 ObjectTreeParser otp(
this );
1560 otp.setAllowAsync(
true );
1561 otp.setShowRawToltecMail( mShowRawToltecMail );
1562 otp.parseObjectTree( mRootNode );
1566 KMMsgEncryptionState encryptionState = mRootNode->overallEncryptionState();
1567 KMMsgSignatureState signatureState = mRootNode->overallSignatureState();
1576 if ( signatureState != KMMsgNotSigned ||
1581 bool emitReplaceMsgByUnencryptedVersion =
false;
1582 const TDEConfigGroup reader( KMKernel::config(),
"Reader" );
1583 if ( reader.readBoolEntry(
"store-displayed-messages-unencrypted",
false ) ) {
1598 kdDebug(5006) <<
"\n\n\nKMReaderWin::parseMsg() - special post-encryption handling:\n1." << endl;
1599 kdDebug(5006) <<
"(aMsg == msg) = " << (aMsg ==
message()) << endl;
1600 kdDebug(5006) <<
"aMsg->parent() && aMsg->parent() != kmkernel->outboxFolder() = " << (aMsg->parent() && aMsg->parent() != kmkernel->outboxFolder()) << endl;
1601 kdDebug(5006) <<
"message_was_saved_decrypted_before( aMsg ) = " << message_was_saved_decrypted_before( aMsg ) << endl;
1602 kdDebug(5006) <<
"this->decryptMessage() = " <<
decryptMessage() << endl;
1603 kdDebug(5006) <<
"otp.hasPendingAsyncJobs() = " << otp.hasPendingAsyncJobs() << endl;
1604 kdDebug(5006) <<
" (KMMsgFullyEncrypted == encryptionState) = " << (KMMsgFullyEncrypted == encryptionState) << endl;
1605 kdDebug(5006) <<
"|| (KMMsgPartiallyEncrypted == encryptionState) = " << (KMMsgPartiallyEncrypted == encryptionState) << endl;
1610 && ( aMsg->parent() && aMsg->parent() != kmkernel->outboxFolder() )
1612 && !message_was_saved_decrypted_before( aMsg )
1616 && !otp.hasPendingAsyncJobs()
1618 && ( (KMMsgFullyEncrypted == encryptionState)
1619 || (KMMsgPartiallyEncrypted == encryptionState) ) ) {
1621 kdDebug(5006) <<
"KMReaderWin - calling objectTreeToDecryptedMsg()" << endl;
1623 NewByteArray decryptedData;
1625 objectTreeToDecryptedMsg( mRootNode, decryptedData, *aMsg );
1627 decryptedData.appendNULL();
1628 TQCString resultString( decryptedData.data() );
1629 kdDebug(5006) <<
"KMReaderWin - resulting data:" << resultString << endl;
1631 if( !resultString.isEmpty() ) {
1632 kdDebug(5006) <<
"KMReaderWin - composing unencrypted message" << endl;
1634 aMsg->
setBody( resultString );
1636 unencryptedMessage->setParent( 0 );
1645 kdDebug(5006) <<
"KMReaderWin - attach unencrypted message to aMsg" << endl;
1647 emitReplaceMsgByUnencryptedVersion =
true;
1653 const int rootNodeCntType = mRootNode ? mRootNode->type() : DwMime::kTypeText;
1654 const int rootNodeCntSubtype = mRootNode ? mRootNode->subType() : DwMime::kSubtypePlain;
1659 if( emitReplaceMsgByUnencryptedVersion ) {
1660 kdDebug(5006) <<
"KMReaderWin - invoce saving in decrypted form:" << endl;
1663 kdDebug(5006) <<
"KMReaderWin - finished parsing and displaying of message." << endl;
1665 rootNodeCntSubtype == DwMime::kSubtypePlain );
1668 aMsg->setIsBeingParsed(
false );
1673 void KMReaderWin::updateHeader()
1685 if (currentMessage &&
1686 mHeaderStyle == HeaderStyle::fancy() &&
1687 currentMessage->parent())
1691 DOM::NodeList divs(mViewer->document().documentElement().getElementsByTagName(
"div"));
1692 DOM::NodeList headerDivs(
static_cast<DOM::HTMLDivElement
>(divs.item(0)).getElementsByTagName(
"div"));
1693 for (i=0; i<((int)headerDivs.length()); i++) {
1694 if (
static_cast<DOM::HTMLDivElement
>(headerDivs.item(i)).
id().string() ==
"sendersCurrentTime") {
1700 if (divNumber >= 0) {
1701 DOM::HTMLDivElement elem =
static_cast<DOM::HTMLDivElement
>(headerDivs.item(i));
1705 TQString latestHeader = headerStyle()->format( currentMessage,
headerStrategy(),
"", mPrinting,
false );
1706 int startPos = latestHeader.find(
"<div id=\"sendersCurrentTime\" style=\"");
1707 if (startPos >= 0) {
1708 latestHeader = latestHeader.mid(startPos);
1709 int endPos = latestHeader.find(
"</div>");
1711 endPos = endPos + 6;
1712 latestHeader.truncate(endPos);
1714 TQString divText = latestHeader;
1715 TQString divStyle = latestHeader;
1717 divText = divText.mid(divText.find(
">")+1);
1718 divText.truncate(divText.find(
"</div>"));
1720 divStyle = divStyle.mid(TQString(
"<div id=\"sendersCurrentTime\" style=\"").length());
1721 divStyle.truncate(divStyle.find(
"\""));
1723 elem.setInnerHTML(divText);
1724 elem.setAttribute(
"style", divStyle);
1725 elem.applyChanges();
1735 kdFatal( !headerStyle(), 5006 )
1736 <<
"trying to writeMsgHeader() without a header style set!" << endl;
1738 <<
"trying to writeMsgHeader() without a header strategy set!" << endl;
1741 href = vCardNode->asHREF(
"body" );
1743 return headerStyle()->format( aMsg,
headerStrategy(), href, mPrinting, topLevel );
1752 TQString fileName = aMsgPart->fileName();
1753 if( fileName.isEmpty() )
1754 fileName = aMsgPart->name();
1757 TQString fname =
createTempDir( TQString::number( aPartNum ) );
1758 if ( fname.isEmpty() )
1762 int slashPos = fileName.findRev(
'/' );
1763 if( -1 != slashPos )
1764 fileName = fileName.mid( slashPos + 1 );
1765 if( fileName.isEmpty() )
1766 fileName =
"unnamed";
1767 fname +=
"/" + fileName;
1769 TQByteArray data = aMsgPart->bodyDecodedBinary();
1770 size_t size = data.size();
1771 if ( aMsgPart->type() == DwMime::kTypeText && size) {
1775 if( !KPIM::kBytesToFile( data.data(), size, fname,
false,
false,
false ) )
1778 mTempFiles.append( fname );
1781 ::chmod( TQFile::encodeName( fname ), S_IRUSR );
1788 KTempFile *tempFile =
new KTempFile( TQString(),
"." + param );
1789 tempFile->setAutoDelete(
true );
1790 TQString fname = tempFile->name();
1793 if( ::access( TQFile::encodeName( fname ), W_OK ) != 0 )
1795 if( ::mkdir( TQFile::encodeName( fname ), 0 ) != 0
1796 || ::chmod( TQFile::encodeName( fname ), S_IRWXU ) != 0 )
1799 assert( !fname.isNull() );
1801 mTempDirs.append( fname );
1808 #if defined(KABC_VCARD_ENCODING_FIX)
1809 const TQByteArray vCard = msgPart->bodyDecodedBinary();
1811 const TQString vCard = msgPart->bodyToUnicode(
overrideCodec() );
1813 VCardViewer *vcv =
new VCardViewer(
this, vCard,
"vCardDialog" );
1821 mViewer->view()->print();
1828 if (aUrl.isEmpty())
return -1;
1829 if (!aUrl.isLocalFile())
return -1;
1831 TQString path = aUrl.path();
1832 uint right = path.findRev(
'/');
1833 uint left = path.findRev(
'.', right);
1836 int res = path.mid(left + 1, right - left - 1).toInt(&ok);
1837 return (ok) ? res : -1;
1842 void KMReaderWin::resizeEvent(TQResizeEvent *)
1844 if( !mResizeTimer.isActive() )
1850 mResizeTimer.start( 100,
true );
1856 void KMReaderWin::slotDelayedResize()
1858 mSplitter->setGeometry(0, 0, width(), height());
1863 void KMReaderWin::slotTouchMessage()
1872 serNums.append(
message()->getMsgSerNum() );
1873 KMCommand *command =
new KMSeStatusCommand( KMMsgStatusRead, serNums );
1877 if ( mNoMDNsWhenEncrypted &&
1878 message()->encryptionState() != KMMsgNotEncrypted &&
1879 message()->encryptionState() != KMMsgEncryptionStateUnknown )
1891 if ( !kmkernel->msgSender()->send( receipt ) )
1892 KMessageBox::error(
this, i18n(
"Could not send MDN.") );
1899 TQWidget::closeEvent(e);
1904 bool foundSMIMEData(
const TQString aUrl,
1905 TQString& displayName,
1909 static TQString showCertMan(
"showCertificate#");
1913 int i1 = aUrl.find( showCertMan );
1915 i1 += showCertMan.length();
1916 int i2 = aUrl.find(
" ### ", i1);
1919 displayName = aUrl.mid( i1, i2-i1 );
1921 i2 = aUrl.find(
" ### ", i1);
1924 libName = aUrl.mid( i1, i2-i1 );
1927 keyId = aUrl.mid( i2 );
1943 return !keyId.isEmpty();
1950 const KURL url(aUrl);
1952 if ( url.protocol() ==
"kmail" || url.protocol() ==
"x-kmail" || url.protocol() ==
"attachment"
1953 || (url.protocol().isEmpty() && url.path().isEmpty()) ) {
1954 mViewer->setDNDEnabled(
false );
1956 mViewer->setDNDEnabled(
true );
1959 if ( aUrl.stripWhiteSpace().isEmpty() ) {
1960 KPIM::BroadcastStatus::instance()->reset();
1961 mHoveredUrl = KURL();
1962 mLastClickImagePath = TQString();
1968 const TQString msg = URLHandlerManager::instance()->statusBarMessage( url,
this );
1970 kdWarning( msg.isEmpty(), 5006 ) <<
"KMReaderWin::slotUrlOn(): Unhandled URL hover!" << endl;
1971 KPIM::BroadcastStatus::instance()->setTransienStatusMsg( msg );
1980 if ( URLHandlerManager::instance()->handleClick( aUrl,
this ) )
1983 kdWarning( 5006 ) <<
"KMReaderWin::slotOpenUrl(): Unhandled URL click!" << endl;
1990 const KURL url( aUrl );
1993 if ( url.protocol() ==
"mailto" ) {
1994 mCopyURLAction->setText( i18n(
"Copy Email Address" ) );
1996 mCopyURLAction->setText( i18n(
"Copy Link Address" ) );
1999 if ( URLHandlerManager::instance()->handleContextMenuRequest( url, aPos,
this ) )
2003 kdWarning( 5006 ) <<
"KMReaderWin::slotUrlPopup(): Unhandled URL right-click!" << endl;
2004 emitPopupMenu( url, aPos );
2010 static bool hasParentDivWithId(
const DOM::Node &start,
const TQString &
id )
2012 if ( start.isNull() )
2015 if ( start.nodeName().string() ==
"div" ) {
2016 for (
unsigned int i = 0; i < start.attributes().length(); i++ ) {
2017 if ( start.attributes().item( i ).nodeName().string() ==
"id" &&
2018 start.attributes().item( i ).nodeValue().string() ==
id )
2023 if ( !start.parentNode().isNull() )
2024 return hasParentDivWithId( start.parentNode(),
id );
2029 void KMReaderWin::showAttachmentPopup(
int id,
const TQString & name,
const TQPoint & p )
2032 mAtmCurrentName = name;
2033 TDEPopupMenu *menu =
new TDEPopupMenu();
2034 menu->insertItem(SmallIcon(
"document-open"),i18n(
"to open",
"Open"), 1);
2035 menu->insertItem(i18n(
"Open With..."), 2);
2036 menu->insertItem(i18n(
"to view something",
"View"), 3);
2037 menu->insertItem(SmallIcon(
"document-save-as"),i18n(
"Save As..."), 4);
2038 menu->insertItem(SmallIcon(
"edit-copy"), i18n(
"Copy"), 9 );
2039 const bool canChange =
message()->parent() ? !
message()->parent()->isReadOnly() :
false;
2040 if ( GlobalSettings::self()->allowAttachmentEditing() && canChange )
2041 menu->insertItem(SmallIcon(
"edit"), i18n(
"Edit Attachment"), 8 );
2042 if ( GlobalSettings::self()->allowAttachmentDeletion() && canChange )
2043 menu->insertItem(SmallIcon(
"edit-delete"), i18n(
"Delete Attachment"), 7 );
2044 if ( name.endsWith(
".xia",
false ) &&
2045 Kleo::CryptoBackendFactory::instance()->protocol(
"Chiasmus" ) )
2046 menu->insertItem( i18n(
"Decrypt With Chiasmus..." ), 6 );
2047 menu->insertItem(i18n(
"Properties"), 5);
2049 const bool attachmentInHeader = hasParentDivWithId( mViewer->nodeUnderMouse(),
"attachmentInjectionPoint" );
2050 const bool hasScrollbar = mViewer->view()->verticalScrollBar()->isVisible();
2051 if ( attachmentInHeader && hasScrollbar ) {
2052 menu->insertItem( i18n(
"Scroll To"), 10 );
2055 connect(menu, TQT_SIGNAL(activated(
int)), TQT_TQOBJECT(
this), TQT_SLOT(slotHandleAttachment(
int)));
2067 if( style().isA(
"KeramikStyle") )
2068 frameWidth = style().pixelMetric( TQStyle::PM_DefaultFrameWidth ) - 1;
2070 frameWidth = style().pixelMetric( TQStyle::PM_DefaultFrameWidth );
2071 if ( frameWidth < 0 )
2073 if ( frameWidth != mBox->lineWidth() )
2074 mBox->setLineWidth( frameWidth );
2081 TQWidget::styleChange( oldStyle );
2085 void KMReaderWin::slotHandleAttachment(
int choice )
2088 partNode* node = mRootNode ? mRootNode->findId( mAtmCurrent ) : 0;
2089 if ( mAtmCurrentName.isEmpty() && node )
2090 mAtmCurrentName = tempFileUrlFromPartNode( node ).path();
2092 KMHandleAttachmentCommand* command =
new KMHandleAttachmentCommand(
2093 node,
message(), mAtmCurrent, mAtmCurrentName,
2094 KMHandleAttachmentCommand::AttachmentAction( choice ), 0,
this );
2095 connect( command, TQT_SIGNAL( showAttachment(
int,
const TQString& ) ),
2096 TQT_TQOBJECT(
this), TQT_SLOT(
slotAtmView(
int,
const TQString& ) ) );
2098 }
else if ( choice == 7 ) {
2099 slotDeleteAttachment( node );
2100 }
else if ( choice == 8 ) {
2101 slotEditAttachment( node );
2102 }
else if ( choice == 9 ) {
2103 if ( !node )
return;
2105 KURL url = tempFileUrlFromPartNode( node );
2106 if (!url.isValid() )
return;
2108 KURLDrag* drag =
new KURLDrag( urls,
this );
2109 TQApplication::clipboard()->setData( drag, TQClipboard::Clipboard );
2110 }
else if ( choice == 10 ) {
2118 mViewer->findText();
2124 mViewer->findTextNext();
2130 mUseFixedFont = !mUseFixedFont;
2139 kapp->clipboard()->setText( mViewer->selectedText() );
2146 assert(aMsgPart!=0);
2148 msg->fromString(aMsgPart->bodyDecoded());
2152 msg->setParent(
message()->parent() );
2153 msg->setUID(
message()->UID());
2155 KMReaderMainWin *win =
new KMReaderMainWin();
2164 htmlWriter()->begin( mCSSHelper->cssDefinitions( isFixedFont() ) );
2165 htmlWriter()->write( mCSSHelper->htmlHead( isFixedFont() ) );
2168 ObjectTreeParser otp(
this, 0,
true );
2169 otp.parseObjectTree( node );
2178 const TQString& aFileName,
const TQString& pname )
2181 if (kasciistricmp(aMsgPart->typeStr(),
"message")==0) {
2184 assert(aMsgPart!=0);
2185 msg->fromString(aMsgPart->bodyDecoded());
2186 mMainWindow->setCaption(msg->
subject());
2188 setAutoDelete(
true);
2189 }
else if (kasciistricmp(aMsgPart->typeStr(),
"text")==0) {
2190 if (kasciistricmp(aMsgPart->subtypeStr(),
"x-vcard") == 0) {
2194 htmlWriter()->begin( mCSSHelper->cssDefinitions( isFixedFont() ) );
2195 htmlWriter()->queue( mCSSHelper->htmlHead( isFixedFont() ) );
2197 if (aHTML && (kasciistricmp(aMsgPart->subtypeStr(),
"html")==0)) {
2202 const TQCString str = aMsgPart->bodyDecoded();
2203 ObjectTreeParser otp(
this );
2204 otp.writeBodyStr( str,
2210 mMainWindow->setCaption(i18n(
"View Attachment: %1").arg(pname));
2211 }
else if (kasciistricmp(aMsgPart->typeStr(),
"image")==0 ||
2212 (kasciistricmp(aMsgPart->typeStr(),
"application")==0 &&
2213 kasciistricmp(aMsgPart->subtypeStr(),
"postscript")==0))
2215 if (aFileName.isEmpty())
return;
2217 TQImageIO *iio =
new TQImageIO();
2218 iio->setFileName(aFileName);
2220 TQImage img = iio->image();
2221 TQRect desk = TDEGlobalSettings::desktopGeometry(mMainWindow);
2224 if( img.width() < 50 )
2226 else if( img.width()+20 < desk.width() )
2227 width = img.width()+20;
2229 width = desk.width();
2230 if( img.height() < 50 )
2232 else if( img.height()+20 < desk.height() )
2233 height = img.height()+20;
2235 height = desk.height();
2236 mMainWindow->resize( width, height );
2239 htmlWriter()->begin( mCSSHelper->cssDefinitions( isFixedFont() ) );
2240 htmlWriter()->write( mCSSHelper->htmlHead( isFixedFont() ) );
2242 KURL::encode_string( aFileName ) +
2243 "\" border=\"0\">\n"
2244 "</body></html>\n" );
2246 setCaption( i18n(
"View Attachment: %1").arg( pname ) );
2250 htmlWriter()->begin( mCSSHelper->cssDefinitions( isFixedFont() ) );
2251 htmlWriter()->queue( mCSSHelper->htmlHead( isFixedFont() ) );
2254 TQString str = aMsgPart->bodyDecoded();
2257 if( str.length() < (
unsigned) aMsgPart->decodedSize() ) {
2258 str.prepend( i18n(
"[KMail: Attachment contains binary data. Trying to show first character.]",
2259 "[KMail: Attachment contains binary data. Trying to show first %n characters.]",
2260 str.length()) + TQChar(
'\n') );
2262 htmlWriter()->queue( TQStyleSheet::escape( str ) );
2266 mMainWindow->setCaption(i18n(
"View Attachment: %1").arg(pname));
2275 partNode* node = mRootNode ? mRootNode->findId(
id ) : 0;
2278 mAtmCurrentName = name;
2279 if ( mAtmCurrentName.isEmpty() )
2280 mAtmCurrentName = tempFileUrlFromPartNode( node ).path();
2282 KMMessagePart& msgPart = node->msgPart();
2283 TQString pname = msgPart.fileName();
2284 if (pname.isEmpty()) pname=msgPart.name();
2285 if (pname.isEmpty()) pname=msgPart.contentDescription();
2286 if (pname.isEmpty()) pname=
"unnamed";
2288 if (kasciistricmp(msgPart.typeStr(),
"message")==0) {
2290 }
else if ((kasciistricmp(msgPart.typeStr(),
"text")==0) &&
2291 (kasciistricmp(msgPart.subtypeStr(),
"x-vcard")==0)) {
2294 KMReaderMainWin *win =
new KMReaderMainWin(&msgPart,
htmlMail(),
2302 void KMReaderWin::openAttachment(
int id,
const TQString & name )
2304 mAtmCurrentName = name;
2307 TQString str, pname, cmd, fileName;
2309 partNode* node = mRootNode ? mRootNode->findId(
id ) : 0;
2311 kdWarning(5006) <<
"KMReaderWin::openAttachment - could not find node " <<
id << endl;
2314 if ( mAtmCurrentName.isEmpty() )
2315 mAtmCurrentName = tempFileUrlFromPartNode( node ).path();
2317 KMMessagePart& msgPart = node->msgPart();
2318 if (kasciistricmp(msgPart.typeStr(),
"message")==0)
2324 TQCString contentTypeStr( msgPart.typeStr() +
'/' + msgPart.subtypeStr() );
2325 KPIM::kAsciiToLower( contentTypeStr.data() );
2327 if ( qstrcmp( contentTypeStr,
"text/x-vcard" ) == 0 ) {
2333 KMimeType::Ptr mimetype;
2335 mimetype = KMimeType::mimeType( TQString::fromLatin1( contentTypeStr ) );
2336 if ( mimetype->name() ==
"application/octet-stream" ) {
2338 mimetype = KMimeType::findByPath( name, 0,
true );
2340 if ( ( mimetype->name() ==
"application/octet-stream" )
2341 && msgPart.isComplete() ) {
2344 mimetype = KMimeType::findByFileContent( name );
2347 KService::Ptr offer =
2348 KServiceTypeProfile::preferredService( mimetype->name(),
"Application" );
2351 TQString filenameText = msgPart.fileName();
2352 if ( filenameText.isEmpty() )
2353 filenameText = msgPart.name();
2355 open_text = i18n(
"&Open with '%1'").arg( offer->name() );
2357 open_text = i18n(
"&Open With...");
2359 const TQString text = i18n(
"Open attachment '%1'?\n"
2360 "Note that opening an attachment may compromise "
2361 "your system's security.")
2362 .arg( filenameText );
2363 const int choice = KMessageBox::questionYesNoCancel(
this, text,
2364 i18n(
"Open Attachment?"), KStdGuiItem::saveAs(), open_text,
2365 TQString::fromLatin1(
"askSave") + mimetype->name() );
2367 if( choice == KMessageBox::Yes ) {
2369 KMHandleAttachmentCommand* command =
new KMHandleAttachmentCommand( node,
2370 message(), mAtmCurrent, mAtmCurrentName, KMHandleAttachmentCommand::Save,
2372 connect( command, TQT_SIGNAL( showAttachment(
int,
const TQString& ) ),
2373 TQT_TQOBJECT(
this), TQT_SLOT(
slotAtmView(
int,
const TQString& ) ) );
2376 else if( choice == KMessageBox::No ) {
2377 KMHandleAttachmentCommand::AttachmentAction action = ( offer ?
2378 KMHandleAttachmentCommand::Open : KMHandleAttachmentCommand::OpenWith );
2380 KMHandleAttachmentCommand* command =
new KMHandleAttachmentCommand( node,
2381 message(), mAtmCurrent, mAtmCurrentName, action, offer,
this );
2382 connect( command, TQT_SIGNAL( showAttachment(
int,
const TQString& ) ),
2383 TQT_TQOBJECT(
this), TQT_SLOT(
slotAtmView(
int,
const TQString& ) ) );
2386 kdDebug(5006) <<
"Canceled opening attachment" << endl;
2393 static_cast<TQScrollView *
>(mViewer->widget())->scrollBy(0, -10);
2398 void KMReaderWin::slotScrollDown()
2400 static_cast<TQScrollView *
>(mViewer->widget())->scrollBy(0, 10);
2403 bool KMReaderWin::atBottom()
const
2405 const TQScrollView *view =
static_cast<const TQScrollView *
>(mViewer->widget());
2406 return view->contentsY() + view->visibleHeight() >= view->contentsHeight();
2410 void KMReaderWin::slotJumpDown()
2412 TQScrollView *view =
static_cast<TQScrollView *
>(mViewer->widget());
2413 int offs = (view->clipper()->height() < 30) ? view->clipper()->height() : 30;
2414 view->scrollBy( 0, view->clipper()->height() - offs );
2418 void KMReaderWin::slotScrollPrior()
2420 static_cast<TQScrollView *
>(mViewer->widget())->scrollBy(0, -(
int)(height()*0.8));
2425 void KMReaderWin::slotScrollNext()
2427 static_cast<TQScrollView *
>(mViewer->widget())->scrollBy(0, (
int)(height()*0.8));
2431 void KMReaderWin::slotDocumentChanged()
2438 void KMReaderWin::slotTextSelected(
bool)
2440 TQString temp = mViewer->selectedText();
2441 kapp->clipboard()->setText(temp);
2447 mViewer->selectAll();
2453 TQString temp = mViewer->selectedText();
2459 void KMReaderWin::slotDocumentDone()
2466 void KMReaderWin::setHtmlOverride(
bool override)
2468 mHtmlOverride =
override;
2475 void KMReaderWin::setHtmlLoadExtOverride(
bool override)
2477 mHtmlLoadExtOverride =
override;
2486 return ((mHtmlMail && !mHtmlOverride) || (!mHtmlMail && mHtmlOverride));
2493 return ((mHtmlLoadExternal && !mHtmlLoadExtOverride) ||
2494 (!mHtmlLoadExternal && mHtmlLoadExtOverride));
2501 const TQScrollView * scrollview =
static_cast<TQScrollView *
>( mViewer->widget() );
2502 mSavedRelativePosition =
2503 static_cast<float>( scrollview->contentsY() ) / scrollview->contentsHeight();
2512 setMsg( msg, force,
true );
2520 KMFolder*& folder = aFolder ? *aFolder : tmpFolder;
2531 kdWarning(5006) <<
"Attempt to reference invalid serial number " << mLastSerNum <<
"\n" << endl;
2540 void KMReaderWin::slotUrlClicked()
2542 KMMainWidget *mainWidget =
dynamic_cast<KMMainWidget*
>(mMainWindow);
2545 identity =
message()->parent()->identity();
2548 KMCommand *command =
new KMUrlClickedCommand( mClickedUrl, identity,
this,
2549 false, mainWidget );
2554 void KMReaderWin::slotMailtoCompose()
2556 KMCommand *command =
new KMMailtoComposeCommand( mClickedUrl,
message() );
2561 void KMReaderWin::slotMailtoForward()
2563 KMCommand *command =
new KMMailtoForwardCommand( mMainWindow, mClickedUrl,
2569 void KMReaderWin::slotMailtoAddAddrBook()
2571 KMCommand *command =
new KMMailtoAddAddrBookCommand( mClickedUrl,
2577 void KMReaderWin::slotMailtoOpenAddrBook()
2579 KMCommand *command =
new KMMailtoOpenAddrBookCommand( mClickedUrl,
2589 KMCommand *command =
2590 new KMUrlCopyCommand( mClickedUrl,
2591 dynamic_cast<KMMainWidget*
>( mMainWindow ) );
2598 if ( !url.isEmpty() )
2600 KMCommand *command =
new KMUrlOpenCommand( mClickedUrl,
this );
2605 void KMReaderWin::slotAddBookmarks()
2607 KMCommand *command =
new KMAddBookmarksCommand( mClickedUrl,
this );
2614 KMCommand *command =
new KMUrlSaveCommand( mClickedUrl, mMainWindow );
2621 KMCommand *command =
new KMMailtoReplyCommand( mMainWindow, mClickedUrl,
2628 return mRootNode ? mRootNode->findId(
msgPartFromUrl( url ) ) : 0 ;
2631 partNode * KMReaderWin::partNodeForId(
int id ) {
2632 return mRootNode ? mRootNode->findId(
id ) : 0 ;
2636 KURL KMReaderWin::tempFileUrlFromPartNode(
const partNode * node )
2638 if (!node)
return KURL();
2639 TQStringList::const_iterator it = mTempFiles.begin();
2640 TQStringList::const_iterator end = mTempFiles.end();
2642 while ( it != end ) {
2643 TQString path = *it;
2645 uint right = path.findRev(
'/');
2646 uint left = path.findRev(
'.', right);
2649 int res = path.mid(left + 1, right - left - 1).toInt(&ok);
2650 if ( res == node->nodeId() )
2651 return KURL( path );
2657 void KMReaderWin::slotSaveAttachments()
2660 KMSaveAttachmentsCommand *saveCommand =
new KMSaveAttachmentsCommand( mMainWindow,
2662 saveCommand->start();
2666 void KMReaderWin::saveAttachment(
const KURL &tempFileName )
2669 mAtmCurrentName = mClickedUrl.path();
2670 slotHandleAttachment( KMHandleAttachmentCommand::Save );
2674 void KMReaderWin::slotSaveMsg()
2676 KMSaveMsgCommand *saveCommand =
new KMSaveMsgCommand( mMainWindow,
message() );
2678 if (saveCommand->url().isEmpty())
2681 saveCommand->start();
2686 KMCommand *command =
new KMIMChatCommand( mClickedUrl,
message() );
2691 static TQString linkForNode(
const DOM::Node &node )
2694 if ( node.isNull() )
2697 const DOM::NamedNodeMap attributes = node.attributes();
2698 if ( !attributes.isNull() ) {
2699 const DOM::Node href = attributes.getNamedItem( DOM::DOMString(
"href" ) );
2700 if ( !href.isNull() ) {
2701 return href.nodeValue().string();
2704 if ( !node.parentNode().isNull() ) {
2705 return linkForNode( node.parentNode() );
2709 }
catch ( DOM::DOMException &e ) {
2710 kdWarning(5006) <<
"Got an exception when trying to determine link under cursor!" << endl;
2718 if ( e->type() == TQEvent::MouseButtonPress ) {
2719 TQMouseEvent* me = TQT_TQMOUSEEVENT(e);
2720 if ( me->button() == Qt::LeftButton && ( me->state() & ShiftButton ) ) {
2722 URLHandlerManager::instance()->handleShiftClick( mHoveredUrl,
this );
2726 if ( me->button() == Qt::LeftButton ) {
2729 const DOM::Node nodeUnderMouse = mViewer->nodeUnderMouse();
2730 if ( !nodeUnderMouse.isNull() ) {
2731 const DOM::NamedNodeMap attributes = nodeUnderMouse.attributes();
2732 if ( !attributes.isNull() ) {
2733 const DOM::Node src = attributes.getNamedItem( DOM::DOMString(
"src" ) );
2734 if ( !src.isNull() ) {
2735 imagePath = src.nodeValue().string();
2740 mCanStartDrag = URLHandlerManager::instance()->willHandleDrag( mHoveredUrl, imagePath,
this );
2741 mLastClickPosition = me->pos();
2742 mLastClickImagePath = imagePath;
2746 if ( e->type() == TQEvent::MouseButtonRelease ) {
2747 mCanStartDrag =
false;
2750 if ( e->type() == TQEvent::MouseMove ) {
2751 TQMouseEvent* me = TQT_TQMOUSEEVENT( e );
2755 slotUrlOn( linkForNode( mViewer->nodeUnderMouse() ) );
2757 if ( ( mLastClickPosition - me->pos() ).manhattanLength() > TDEGlobalSettings::dndEventDelay() ) {
2758 if ( mCanStartDrag && ( !( mHoveredUrl.isEmpty() && mLastClickImagePath.isEmpty() ) ) ) {
2759 if ( URLHandlerManager::instance()->handleDrag( mHoveredUrl, mLastClickImagePath,
this ) ) {
2760 mCanStartDrag =
false;
2766 TQMouseEvent mouseEvent( TQEvent::MouseButtonRelease, me->pos(), Qt::NoButton, Qt::NoButton );
2767 TQT_TQOBJECT( mViewer->view() )->eventFilter( mViewer->view()->viewport(),
2781 Q_ASSERT( msg && nodeId );
2783 if ( mSerNumOfOriginalMessage != 0 ) {
2787 if ( folder && index != -1 )
2788 *msg = folder->
getMsg( index );
2791 kdWarning( 5006 ) <<
"Unable to find the original message, aborting attachment deletion!" << endl;
2795 *nodeId = node->nodeId() + mNodeIdOffset;
2798 *nodeId = node->nodeId();
2803 void KMReaderWin::slotDeleteAttachment(partNode * node)
2805 if ( KMessageBox::warningContinueCancel(
this,
2806 i18n(
"Deleting an attachment might invalidate any digital signature on this message."),
2807 i18n(
"Delete Attachment"), KStdGuiItem::del(),
"DeleteAttachmentSignatureWarning" )
2808 != KMessageBox::Continue ) {
2815 if ( msg && nodeId != -1 ) {
2816 KMDeleteAttachmentCommand* command =
new KMDeleteAttachmentCommand( nodeId, msg,
this );
2818 connect( command, TQT_SIGNAL( completed( KMCommand * ) ),
2820 connect( command, TQT_SIGNAL( completed( KMCommand * ) ),
2829 connect( headers, TQT_SIGNAL( msgAddedToListView( TQListViewItem* ) ),
2830 TQT_TQOBJECT(
this), TQT_SLOT( msgAdded( TQListViewItem* ) ) );
2834 if ( mSerNumOfOriginalMessage != 0 &&
message() ) {
2840 void KMReaderWin::msgAdded( TQListViewItem *item )
2847 headers->setCurrentItem( item );
2848 headers->clearSelection();
2855 disconnect( headers, TQT_SIGNAL( msgAddedToListView( TQListViewItem* ) ),
2856 TQT_TQOBJECT(
this), TQT_SLOT( msgAdded( TQListViewItem* ) ) );
2859 void KMReaderWin::slotEditAttachment(partNode * node)
2861 if ( KMessageBox::warningContinueCancel(
this,
2862 i18n(
"Modifying an attachment might invalidate any digital signature on this message."),
2863 i18n(
"Edit Attachment"), KGuiItem( i18n(
"Edit"),
"edit" ),
"EditAttachmentSignatureWarning" )
2864 != KMessageBox::Continue ) {
2871 if ( msg && nodeId != -1 ) {
2872 KMEditAttachmentCommand* command =
new KMEditAttachmentCommand( nodeId, msg,
this );
2879 KMail::CSSHelper* KMReaderWin::cssHelper()
2886 if ( !GlobalSettings::self()->alwaysDecrypt() )
2887 return mDecrytMessageOverwrite;
2893 DOM::Document doc = mViewer->htmlDocument();
2896 mViewer->gotoAnchor( TQString::fromLatin1(
"att%1" ).arg( node->nodeId() ) );
2899 const partNode *root = node->topLevelParent();
2900 for (
int i = 0; i <= root->totalChildCount() + 1; i++ ) {
2901 DOM::Element attachmentDiv = doc.getElementById( TQString(
"attachmentDiv%1" ).arg( i + 1 ) );
2902 if ( !attachmentDiv.isNull() )
2903 attachmentDiv.removeAttribute(
"style" );
2907 if ( node->isDisplayedHidden() )
2913 DOM::Element attachmentDiv = doc.getElementById( TQString(
"attachmentDiv%1" ).arg( node->nodeId() ) );
2914 if ( attachmentDiv.isNull() ) {
2915 kdWarning( 5006 ) <<
"Could not find attachment div for attachment " << node->nodeId() << endl;
2919 attachmentDiv.setAttribute(
"style", TQString(
"border:2px solid %1" )
2920 .arg( cssHelper()->pgpWarnColor().name() ) );
2924 doc.updateRendering();
2927 void KMReaderWin::injectAttachments()
2931 DOM::Document doc = mViewer->htmlDocument();
2932 DOM::Element injectionPoint = doc.getElementById(
"attachmentInjectionPoint" );
2933 if ( injectionPoint.isNull() )
2936 TQString imgpath( locate(
"data",
"kmail/pics/") );
2937 TQString visibility;
2940 if( !showAttachmentQuicklist() ) {
2941 urlHandle.append(
"kmail:showAttachmentQuicklist" );
2942 imgSrc.append(
"attachmentQuicklistClosed.png" );
2944 urlHandle.append(
"kmail:hideAttachmentQuicklist" );
2945 imgSrc.append(
"attachmentQuicklistOpened.png" );
2948 TQString html = renderAttachments( mRootNode, TQApplication::palette().active().background() );
2949 if ( html.isEmpty() )
2953 if ( headerStyle() == HeaderStyle::fancy() ) {
2954 link +=
"<div style=\"text-align: left;\"><a href=\"" + urlHandle +
"\"><img src=\"" +
2955 imgpath + imgSrc +
"\"/></a></div>";
2956 html.prepend( link );
2957 html.prepend( TQString::fromLatin1(
"<div style=\"float:left;\">%1 </div>" ).
2958 arg( i18n(
"Attachments:" ) ) );
2960 link +=
"<div style=\"text-align: right;\"><a href=\"" + urlHandle +
"\"><img src=\"" +
2961 imgpath + imgSrc +
"\"/></a></div>";
2962 html.prepend( link );
2965 assert( injectionPoint.tagName() ==
"div" );
2966 static_cast<DOM::HTMLElement
>( injectionPoint ).setInnerHTML( html );
2969 static TQColor nextColor(
const TQColor & c )
2972 c.hsv( &h, &s, &v );
2973 return TQColor( (h + 50) % 360, TQMAX(s, 64), v, TQColor::Hsv );
2976 TQString KMReaderWin::renderAttachments(partNode * node,
const TQColor &bgColor )
2982 if ( node->firstChild() ) {
2983 TQString subHtml = renderAttachments( node->firstChild(), nextColor( bgColor ) );
2984 if ( !subHtml.isEmpty() ) {
2986 TQString visibility;
2987 if ( !showAttachmentQuicklist() ) {
2988 visibility.append(
"display:none;" );
2992 if ( node != mRootNode || headerStyle() != HeaderStyle::enterprise() )
2993 margin =
"padding:2px; margin:2px; ";
2994 TQString align =
"left";
2995 if ( headerStyle() == HeaderStyle::enterprise() )
2997 if ( node->msgPart().typeStr().lower() ==
"message" || node == mRootNode )
2998 html += TQString::fromLatin1(
"<div style=\"background:%1; %2"
2999 "vertical-align:middle; float:%3; %4\">").arg( bgColor.name() ).arg( margin )
3000 .arg( align ).arg( visibility );
3002 if ( node->msgPart().typeStr().lower() ==
"message" || node == mRootNode )
3006 partNode::AttachmentDisplayInfo info = node->attachmentDisplayInfo();
3007 if ( info.displayInHeader ) {
3008 html +=
"<div style=\"float:left;\">";
3009 html += TQString::fromLatin1(
"<span style=\"white-space:nowrap; border-width: 0px; border-left-width: 5px; border-color: %1; 2px; border-left-style: solid;\">" ).arg( bgColor.name() );
3011 TQString href = node->asHREF(
"header" );
3012 html += TQString::fromLatin1(
"<a href=\"" ) + href +
3013 TQString::fromLatin1(
"\">" );
3014 html +=
"<img style=\"vertical-align:middle;\" src=\"" + info.icon +
"\"/> ";
3015 if ( headerStyle() == HeaderStyle::enterprise() ) {
3016 TQFont bodyFont = mCSSHelper->bodyFont( isFixedFont() );
3017 TQFontMetrics fm( bodyFont );
3018 html += KStringHandler::rPixelSqueeze( info.label, fm, 140 );
3019 }
else if ( headerStyle() == HeaderStyle::fancy() ) {
3020 TQFont bodyFont = mCSSHelper->bodyFont( isFixedFont() );
3021 TQFontMetrics fm( bodyFont );
3022 html += KStringHandler::rPixelSqueeze( info.label, fm, 640 );
3026 html +=
"</a></span></div> ";
3030 html += renderAttachments( node->nextSibling(), nextColor ( bgColor ) );
3036 void KMReaderWin::setBodyPartMemento(
const partNode * node,
const TQCString & which,
BodyPartMemento * memento )
3038 const TQCString index = node->path() +
':' + which.lower();
3040 const std::map<TQCString,BodyPartMemento*>::iterator it = mBodyPartMementoMap.lower_bound( index );
3041 if ( it != mBodyPartMementoMap.end() && it->first == index ) {
3043 if ( memento && memento == it->second )
3049 it->second = memento;
3052 mBodyPartMementoMap.erase( it );
3057 mBodyPartMementoMap.insert( it, std::make_pair( index, memento ) );
3065 BodyPartMemento * KMReaderWin::bodyPartMemento(
const partNode * node,
const TQCString & which )
const
3067 const TQCString index = node->path() +
':' + which.lower();
3068 const std::map<TQCString,BodyPartMemento*>::const_iterator it = mBodyPartMementoMap.find( index );
3069 if ( it == mBodyPartMementoMap.end() ) {
3083 void KMReaderWin::clearBodyPartMementos()
3085 for ( std::map<TQCString,BodyPartMemento*>::const_iterator it = mBodyPartMementoMap.begin(), end = mBodyPartMementoMap.end() ; it != end ; ++it )
3090 detach_and_delete( it->second,
this );
3092 mBodyPartMementoMap.clear();
3095 #include "kmreaderwin.moc"