11 #include "kmreaderwin.h"
13 #include "globalsettings.h"
14 #include "kmversion.h"
15 #include "kmmainwidget.h"
16 #include "kmreadermainwin.h"
17 #include <libtdepim/tdefileio.h>
18 #include "kmfolderindex.h"
19 #include "kmcommands.h"
20 #include "kmmsgpartdlg.h"
21 #include "mailsourceviewer.h"
22 using KMail::MailSourceViewer;
24 #include "kmmsgdict.h"
25 #include "messagesender.h"
26 #include "kcursorsaver.h"
28 #include "vcardviewer.h"
29 using KMail::VCardViewer;
30 #include "objecttreeparser.h"
31 using KMail::ObjectTreeParser;
32 #include "partmetadata.h"
33 using KMail::PartMetaData;
34 #include "attachmentstrategy.h"
35 using KMail::AttachmentStrategy;
36 #include "headerstrategy.h"
37 using KMail::HeaderStrategy;
38 #include "headerstyle.h"
40 #include "tdehtmlparthtmlwriter.h"
42 using KMail::KHtmlPartHtmlWriter;
43 #include "htmlstatusbar.h"
45 #include "folderjob.h"
46 using KMail::FolderJob;
47 #include "csshelper.h"
48 using KMail::CSSHelper;
50 using KMail::ISubject;
51 #include "urlhandlermanager.h"
53 #include "interfaces/observable.h"
55 #include "kmheaders.h"
57 #include "broadcaststatus.h"
59 #include <kmime_mdn.h>
60 using namespace KMime;
61 #ifdef KMAIL_READER_HTML_DEBUG
62 #include "filehtmlwriter.h"
63 using KMail::FileHtmlWriter;
64 #include "teehtmlwriter.h"
68 #include <kasciistringtools.h>
69 #include <kstringhandler.h>
71 #include <mimelib/mimepp.h>
72 #include <mimelib/body.h>
73 #include <mimelib/utility.h>
75 #include <kleo/specialjob.h>
76 #include <kleo/cryptobackend.h>
77 #include <kleo/cryptobackendfactory.h>
80 #include <tdeabc/addressee.h>
81 #include <tdeabc/vcardconverter.h>
84 #include <tdehtml_part.h>
85 #include <tdehtmlview.h>
86 #include <dom/html_element.h>
87 #include <dom/html_block.h>
88 #include <dom/html_document.h>
89 #include <dom/dom_string.h>
90 #include <dom/dom_exception.h>
92 #include <tdeapplication.h>
94 #include <kuserprofile.h>
95 #include <kcharsets.h>
96 #include <tdepopupmenu.h>
97 #include <kstandarddirs.h>
100 #include <tdefiledialog.h>
101 #include <tdelocale.h>
102 #include <tdemessagebox.h>
103 #include <tdeglobalsettings.h>
105 #include <tdetempfile.h>
106 #include <kprocess.h>
108 #include <tdeaction.h>
109 #include <kiconloader.h>
110 #include <kmdcodec.h>
111 #include <kasciistricmp.h>
112 #include <kurldrag.h>
114 #include <tqclipboard.h>
116 #include <tqtextcodec.h>
117 #include <tqpaintdevicemetrics.h>
118 #include <tqlayout.h>
120 #include <tqsplitter.h>
129 #include <sys/stat.h>
139 class NewByteArray :
public TQByteArray
142 NewByteArray &appendNULL();
143 NewByteArray &operator+=(
const char * );
144 NewByteArray &operator+=(
const TQByteArray & );
145 NewByteArray &operator+=(
const TQCString & );
146 TQByteArray& qByteArray();
149 NewByteArray& NewByteArray::appendNULL()
151 TQByteArray::detach();
153 if ( !TQByteArray::resize( len1 + 1 ) )
155 *(data() + len1) =
'\0';
158 NewByteArray& NewByteArray::operator+=(
const char * newData )
162 TQByteArray::detach();
164 uint len2 = tqstrlen( newData );
165 if ( !TQByteArray::resize( len1 + len2 ) )
167 memcpy( data() + len1, newData, len2 );
170 NewByteArray& NewByteArray::operator+=(
const TQByteArray & newData )
172 if ( newData.isNull() )
174 TQByteArray::detach();
176 uint len2 = newData.size();
177 if ( !TQByteArray::resize( len1 + len2 ) )
179 memcpy( data() + len1, newData.data(), len2 );
182 NewByteArray& NewByteArray::operator+=(
const TQCString & newData )
184 if ( newData.isEmpty() )
186 TQByteArray::detach();
188 uint len2 = newData.length();
189 if ( !TQByteArray::resize( len1 + len2 ) )
191 memcpy( data() + len1, newData.data(), len2 );
194 TQByteArray& NewByteArray::qByteArray()
196 return *((TQByteArray*)
this);
203 void KMReaderWin::objectTreeToDecryptedMsg( partNode* node,
204 NewByteArray& resultingData,
206 bool weAreReplacingTheRootNode,
209 kdDebug(5006) << TQString(
"-------------------------------------------------" ) << endl;
210 kdDebug(5006) << TQString(
"KMReaderWin::objectTreeToDecryptedMsg( %1 ) START").arg( recCount ) << endl;
213 kdDebug(5006) << node->typeString() <<
'/' << node->subTypeString() << endl;
215 partNode* curNode = node;
216 partNode* dataNode = curNode;
217 partNode * child = node->firstChild();
218 const bool bIsMultipart = node->type() == DwMime::kTypeMultipart ;
219 bool bKeepPartAsIs =
false;
221 switch( curNode->type() ){
222 case DwMime::kTypeMultipart: {
223 switch( curNode->subType() ){
224 case DwMime::kSubtypeSigned: {
225 bKeepPartAsIs =
true;
228 case DwMime::kSubtypeEncrypted: {
236 case DwMime::kTypeMessage: {
237 switch( curNode->subType() ){
238 case DwMime::kSubtypeRfc822: {
246 case DwMime::kTypeApplication: {
247 switch( curNode->subType() ){
248 case DwMime::kSubtypeOctetStream: {
253 case DwMime::kSubtypePkcs7Signature: {
256 bKeepPartAsIs =
true;
259 case DwMime::kSubtypePkcs7Mime: {
262 if ( child && curNode->encryptionState() != KMMsgNotEncrypted )
272 DwHeaders& rootHeaders( theMessage.
headers() );
273 DwBodyPart * part = dataNode->dwPart() ? dataNode->dwPart() : 0;
275 (part && part->hasHeaders())
277 : ( (weAreReplacingTheRootNode || !dataNode->parentNode())
280 if( dataNode == curNode ) {
281 kdDebug(5006) <<
"dataNode == curNode: Save curNode without replacing it." << endl;
287 if( dataNode->parentNode() && !weAreReplacingTheRootNode ) {
288 kdDebug(5006) <<
"dataNode is NOT replacing the root node: Store the headers." << endl;
289 resultingData += headers->AsString().c_str();
290 }
else if( weAreReplacingTheRootNode && part && part->hasHeaders() ){
291 kdDebug(5006) <<
"dataNode replace the root node: Do NOT store the headers but change" << endl;
292 kdDebug(5006) <<
" the Message's headers accordingly." << endl;
293 kdDebug(5006) <<
" old Content-Type = " << rootHeaders.ContentType().AsString().c_str() << endl;
294 kdDebug(5006) <<
" new Content-Type = " << headers->ContentType( ).AsString().c_str() << endl;
295 rootHeaders.ContentType() = headers->ContentType();
296 theMessage.setContentTransferEncodingStr(
297 headers->HasContentTransferEncoding()
298 ? headers->ContentTransferEncoding().AsString().c_str()
300 rootHeaders.ContentDescription() = headers->ContentDescription();
301 rootHeaders.ContentDisposition() = headers->ContentDisposition();
306 if ( bKeepPartAsIs ) {
307 resultingData += dataNode->encodedBody();
311 if( headers && bIsMultipart && dataNode->firstChild() ) {
312 kdDebug(5006) <<
"is valid Multipart, processing children:" << endl;
313 TQCString boundary = headers->ContentType().Boundary().c_str();
314 curNode = dataNode->firstChild();
317 kdDebug(5006) <<
"--boundary" << endl;
318 if( resultingData.size() &&
319 (
'\n' != resultingData.at( resultingData.size()-1 ) ) )
320 resultingData += TQCString(
"\n" );
321 resultingData += TQCString(
"\n" );
322 resultingData +=
"--";
323 resultingData += boundary;
324 resultingData +=
"\n";
328 objectTreeToDecryptedMsg( curNode,
333 curNode = curNode->nextSibling();
335 kdDebug(5006) <<
"--boundary--" << endl;
336 resultingData +=
"\n--";
337 resultingData += boundary;
338 resultingData +=
"--\n\n";
339 kdDebug(5006) <<
"Multipart processing children - DONE" << endl;
342 kdDebug(5006) <<
"is Simple part or invalid Multipart, storing body data .. DONE" << endl;
343 resultingData += part->Body().AsString().c_str();
347 kdDebug(5006) <<
"dataNode != curNode: Replace curNode by dataNode." << endl;
348 bool rootNodeReplaceFlag = weAreReplacingTheRootNode || !curNode->parentNode();
349 if( rootNodeReplaceFlag ) {
350 kdDebug(5006) <<
" Root node will be replaced." << endl;
352 kdDebug(5006) <<
" Root node will NOT be replaced." << endl;
356 objectTreeToDecryptedMsg( dataNode,
363 kdDebug(5006) << TQString(
"\nKMReaderWin::objectTreeToDecryptedMsg( %1 ) END").arg( recCount ) << endl;
387 void KMReaderWin::createWidgets() {
388 TQVBoxLayout * vlay =
new TQVBoxLayout(
this );
389 mSplitter =
new TQSplitter( Qt::Vertical,
this,
"mSplitter" );
390 vlay->addWidget( mSplitter );
391 mMimePartTree =
new KMMimePartTree(
this, mSplitter,
"mMimePartTree" );
392 mBox =
new TQHBox( mSplitter,
"mBox" );
393 setStyleDependantFrameWidth();
394 mBox->setFrameStyle( mMimePartTree->frameStyle() );
396 mViewer =
new TDEHTMLPart( mBox,
"mViewer" );
397 mSplitter->setOpaqueResize( TDEGlobalSettings::opaqueResize() );
398 mSplitter->setResizeMode( mMimePartTree, TQSplitter::KeepSize );
401 const int KMReaderWin::delay = 150;
404 KMReaderWin::KMReaderWin(TQWidget *aParent,
405 TQWidget *mainWindow,
406 TDEActionCollection* actionCollection,
409 : TQWidget(aParent, aName, aFlags | TQt::WDestructiveClose),
410 mSerNumOfOriginalMessage( 0 ),
412 mAttachmentStrategy( 0 ),
413 mHeaderStrategy( 0 ),
415 mUpdateReaderWinTimer( 0,
"mUpdateReaderWinTimer" ),
416 mResizeTimer( 0,
"mResizeTimer" ),
417 mDelayedMarkTimer( 0,
"mDelayedMarkTimer" ),
418 mHeaderRefreshTimer( 0,
"mHeaderRefreshTimer" ),
419 mOldGlobalOverrideEncoding(
"---" ),
422 mMainWindow( mainWindow ),
423 mActionCollection( actionCollection ),
424 mMailToComposeAction( 0 ),
425 mMailToReplyAction( 0 ),
426 mMailToForwardAction( 0 ),
427 mAddAddrBookAction( 0 ),
428 mOpenAddrBookAction( 0 ),
432 mUrlSaveAsAction( 0 ),
433 mAddBookmarksAction( 0 ),
434 mStartIMChatAction( 0 ),
435 mSelectAllAction( 0 ),
436 mHeaderOnlyAttachmentsAction( 0 ),
437 mSelectEncodingAction( 0 ),
438 mToggleFixFontAction( 0 ),
439 mToggleMimePartTreeAction( 0 ),
440 mCanStartDrag( false ),
442 mSavedRelativePosition( 0 ),
443 mDecrytMessageOverwrite( false ),
444 mShowSignatureDetails( false ),
445 mShowAttachmentQuicklist( true ),
446 mShowRawToltecMail( false )
448 mExternalWindow = (aParent == mainWindow );
449 mSplitterSizes << 180 << 100;
451 mMimeTreeModeOverride = -1;
452 mMimeTreeAtBottom =
true;
455 mWaitingForSerNum = 0;
459 mShowColorbar =
false;
463 createActions( actionCollection );
467 mHtmlOverride =
false;
468 mHtmlLoadExtOverride =
false;
470 mLevelQuote = GlobalSettings::self()->collapseQuoteLevelSpin() - 1;
472 connect( &mUpdateReaderWinTimer, TQT_SIGNAL(timeout()),
473 TQT_TQOBJECT(
this), TQT_SLOT(updateReaderWin()) );
474 connect( &mResizeTimer, TQT_SIGNAL(timeout()),
475 TQT_TQOBJECT(
this), TQT_SLOT(slotDelayedResize()) );
476 connect( &mDelayedMarkTimer, TQT_SIGNAL(timeout()),
477 TQT_TQOBJECT(
this), TQT_SLOT(slotTouchMessage()) );
478 connect( &mHeaderRefreshTimer, TQT_SIGNAL(timeout()),
479 TQT_TQOBJECT(
this), TQT_SLOT(updateHeader()) );
483 void KMReaderWin::createActions( TDEActionCollection * ac ) {
487 TDERadioAction *raction = 0;
490 TDEActionMenu *headerMenu =
491 new TDEActionMenu( i18n(
"View->",
"&Headers"), ac,
"view_headers" );
492 headerMenu->setToolTip( i18n(
"Choose display style of message headers") );
494 connect( headerMenu, TQT_SIGNAL(activated()),
495 TQT_TQOBJECT(
this), TQT_SLOT(slotCycleHeaderStyles()) );
497 raction =
new TDERadioAction( i18n(
"View->headers->",
"&Enterprise Headers"), 0,
498 TQT_TQOBJECT(
this), TQT_SLOT(slotEnterpriseHeaders()),
499 ac,
"view_headers_enterprise" );
500 raction->setToolTip( i18n(
"Show the list of headers in Enterprise style") );
501 raction->setExclusiveGroup(
"view_headers_group" );
502 headerMenu->insert(raction);
504 raction =
new TDERadioAction( i18n(
"View->headers->",
"&Fancy Headers"), 0,
505 TQT_TQOBJECT(
this), TQT_SLOT(slotFancyHeaders()),
506 ac,
"view_headers_fancy" );
507 raction->setToolTip( i18n(
"Show the list of headers in a fancy format") );
508 raction->setExclusiveGroup(
"view_headers_group" );
509 headerMenu->insert( raction );
511 raction =
new TDERadioAction( i18n(
"View->headers->",
"&Brief Headers"), 0,
512 TQT_TQOBJECT(
this), TQT_SLOT(slotBriefHeaders()),
513 ac,
"view_headers_brief" );
514 raction->setToolTip( i18n(
"Show brief list of message headers") );
515 raction->setExclusiveGroup(
"view_headers_group" );
516 headerMenu->insert( raction );
518 raction =
new TDERadioAction( i18n(
"View->headers->",
"&Standard Headers"), 0,
519 TQT_TQOBJECT(
this), TQT_SLOT(slotStandardHeaders()),
520 ac,
"view_headers_standard" );
521 raction->setToolTip( i18n(
"Show standard list of message headers") );
522 raction->setExclusiveGroup(
"view_headers_group" );
523 headerMenu->insert( raction );
525 raction =
new TDERadioAction( i18n(
"View->headers->",
"&Long Headers"), 0,
526 TQT_TQOBJECT(
this), TQT_SLOT(slotLongHeaders()),
527 ac,
"view_headers_long" );
528 raction->setToolTip( i18n(
"Show long list of message headers") );
529 raction->setExclusiveGroup(
"view_headers_group" );
530 headerMenu->insert( raction );
532 raction =
new TDERadioAction( i18n(
"View->headers->",
"&All Headers"), 0,
533 TQT_TQOBJECT(
this), TQT_SLOT(slotAllHeaders()),
534 ac,
"view_headers_all" );
535 raction->setToolTip( i18n(
"Show all message headers") );
536 raction->setExclusiveGroup(
"view_headers_group" );
537 headerMenu->insert( raction );
540 TDEActionMenu *attachmentMenu =
541 new TDEActionMenu( i18n(
"View->",
"&Attachments"), ac,
"view_attachments" );
542 attachmentMenu->setToolTip( i18n(
"Choose display style of attachments") );
543 connect( attachmentMenu, TQT_SIGNAL(activated()),
544 TQT_TQOBJECT(
this), TQT_SLOT(slotCycleAttachmentStrategy()) );
546 raction =
new TDERadioAction( i18n(
"View->attachments->",
"&As Icons"), 0,
547 TQT_TQOBJECT(
this), TQT_SLOT(slotIconicAttachments()),
548 ac,
"view_attachments_as_icons" );
549 raction->setToolTip( i18n(
"Show all attachments as icons. Click to see them.") );
550 raction->setExclusiveGroup(
"view_attachments_group" );
551 attachmentMenu->insert( raction );
553 raction =
new TDERadioAction( i18n(
"View->attachments->",
"&Smart"), 0,
554 TQT_TQOBJECT(
this), TQT_SLOT(slotSmartAttachments()),
555 ac,
"view_attachments_smart" );
556 raction->setToolTip( i18n(
"Show attachments as suggested by sender.") );
557 raction->setExclusiveGroup(
"view_attachments_group" );
558 attachmentMenu->insert( raction );
560 raction =
new TDERadioAction( i18n(
"View->attachments->",
"&Inline"), 0,
561 TQT_TQOBJECT(
this), TQT_SLOT(slotInlineAttachments()),
562 ac,
"view_attachments_inline" );
563 raction->setToolTip( i18n(
"Show all attachments inline (if possible)") );
564 raction->setExclusiveGroup(
"view_attachments_group" );
565 attachmentMenu->insert( raction );
567 raction =
new TDERadioAction( i18n(
"View->attachments->",
"&Hide"), 0,
568 TQT_TQOBJECT(
this), TQT_SLOT(slotHideAttachments()),
569 ac,
"view_attachments_hide" );
570 raction->setToolTip( i18n(
"Do not show attachments in the message viewer") );
571 raction->setExclusiveGroup(
"view_attachments_group" );
572 attachmentMenu->insert( raction );
574 mHeaderOnlyAttachmentsAction =
new TDERadioAction( i18n(
"View->attachments->",
"In Header &Only" ), 0,
575 TQT_TQOBJECT(
this), TQT_SLOT( slotHeaderOnlyAttachments() ),
576 ac,
"view_attachments_headeronly" );
577 mHeaderOnlyAttachmentsAction->setToolTip( i18n(
"Show Attachments only in the header of the mail" ) );
578 mHeaderOnlyAttachmentsAction->setExclusiveGroup(
"view_attachments_group" );
579 attachmentMenu->insert( mHeaderOnlyAttachmentsAction );
582 mSelectEncodingAction =
new TDESelectAction( i18n(
"&Set Encoding" ),
"charset", 0,
583 TQT_TQOBJECT(
this), TQT_SLOT( slotSetEncoding() ),
585 TQStringList encodings = KMMsgBase::supportedEncodings(
false );
586 encodings.prepend( i18n(
"Auto" ) );
587 mSelectEncodingAction->setItems( encodings );
588 mSelectEncodingAction->setCurrentItem( 0 );
590 mMailToComposeAction =
new TDEAction( i18n(
"New Message To..."),
"mail-message-new",
591 0, TQT_TQOBJECT(
this), TQT_SLOT(slotMailtoCompose()), ac,
593 mMailToReplyAction =
new TDEAction( i18n(
"Reply To..."),
"mail-reply-sender",
596 mMailToForwardAction =
new TDEAction( i18n(
"Forward To..."),
"mail-forward",
597 0, TQT_TQOBJECT(
this), TQT_SLOT(slotMailtoForward()), ac,
599 mAddAddrBookAction =
new TDEAction( i18n(
"Add to Address Book"),
600 0, TQT_TQOBJECT(
this), TQT_SLOT(slotMailtoAddAddrBook()),
601 ac,
"add_addr_book" );
602 mOpenAddrBookAction =
new TDEAction( i18n(
"Open in Address Book"),
603 0, TQT_TQOBJECT(
this), TQT_SLOT(slotMailtoOpenAddrBook()),
604 ac,
"openin_addr_book" );
605 mCopyAction = KStdAction::copy( TQT_TQOBJECT(
this), TQT_SLOT(
slotCopySelectedText()), ac,
"kmail_copy");
606 mSelectAllAction =
new TDEAction( i18n(
"Select All Text"), CTRL+SHIFT+Key_A, TQT_TQOBJECT(
this),
607 TQT_SLOT(
selectAll()), ac,
"mark_all_text" );
608 mCopyURLAction =
new TDEAction( i18n(
"Copy Link Address"), 0, TQT_TQOBJECT(
this),
610 mUrlOpenAction =
new TDEAction( i18n(
"Open URL"), 0, TQT_TQOBJECT(
this),
612 mAddBookmarksAction =
new TDEAction( i18n(
"Bookmark This Link"),
614 0, TQT_TQOBJECT(
this), TQT_SLOT(slotAddBookmarks()),
615 ac,
"add_bookmarks" );
616 mUrlSaveAsAction =
new TDEAction( i18n(
"Save Link As..."), 0, TQT_TQOBJECT(
this),
619 mToggleFixFontAction =
new TDEToggleAction( i18n(
"Use Fi&xed Font"),
621 ac,
"toggle_fixedfont" );
623 mToggleMimePartTreeAction =
new TDEToggleAction( i18n(
"Show Message Structure"),
624 0, ac,
"toggle_mimeparttree" );
625 connect(mToggleMimePartTreeAction, TQT_SIGNAL(toggled(
bool)),
628 mStartIMChatAction =
new TDEAction( i18n(
"Chat &With..."), 0, TQT_TQOBJECT(
this),
629 TQT_SLOT(
slotIMChat()), ac,
"start_im_chat" );
633 TDERadioAction *KMReaderWin::actionForHeaderStyle(
const HeaderStyle * style,
const HeaderStrategy * strategy ) {
634 if ( !mActionCollection )
636 const char * actionName = 0;
637 if ( style == HeaderStyle::enterprise() )
638 actionName =
"view_headers_enterprise";
639 if ( style == HeaderStyle::fancy() )
640 actionName =
"view_headers_fancy";
641 else if ( style == HeaderStyle::brief() )
642 actionName =
"view_headers_brief";
643 else if ( style == HeaderStyle::plain() ) {
644 if ( strategy == HeaderStrategy::standard() )
645 actionName =
"view_headers_standard";
646 else if ( strategy == HeaderStrategy::rich() )
647 actionName =
"view_headers_long";
648 else if ( strategy == HeaderStrategy::all() )
649 actionName =
"view_headers_all";
652 return static_cast<TDERadioAction*
>(mActionCollection->action(actionName));
657 TDERadioAction *KMReaderWin::actionForAttachmentStrategy(
const AttachmentStrategy * as ) {
658 if ( !mActionCollection )
660 const char * actionName = 0;
661 if ( as == AttachmentStrategy::iconic() )
662 actionName =
"view_attachments_as_icons";
663 else if ( as == AttachmentStrategy::smart() )
664 actionName =
"view_attachments_smart";
665 else if ( as == AttachmentStrategy::inlined() )
666 actionName =
"view_attachments_inline";
667 else if ( as == AttachmentStrategy::hidden() )
668 actionName =
"view_attachments_hide";
669 else if ( as == AttachmentStrategy::headerOnly() )
670 actionName =
"view_attachments_headeronly";
673 return static_cast<TDERadioAction*
>(mActionCollection->action(actionName));
678 void KMReaderWin::slotEnterpriseHeaders() {
680 HeaderStrategy::rich() );
681 if( !mExternalWindow )
685 void KMReaderWin::slotFancyHeaders() {
687 HeaderStrategy::rich() );
688 if( !mExternalWindow )
692 void KMReaderWin::slotBriefHeaders() {
694 HeaderStrategy::brief() );
695 if( !mExternalWindow )
699 void KMReaderWin::slotStandardHeaders() {
701 HeaderStrategy::standard());
705 void KMReaderWin::slotLongHeaders() {
707 HeaderStrategy::rich() );
708 if( !mExternalWindow )
712 void KMReaderWin::slotAllHeaders() {
714 HeaderStrategy::all() );
715 if( !mExternalWindow )
719 void KMReaderWin::slotLevelQuote(
int l )
726 void KMReaderWin::slotCycleHeaderStyles() {
730 const char * actionName = 0;
731 if ( style == HeaderStyle::enterprise() ) {
733 actionName =
"view_headers_fancy";
735 if ( style == HeaderStyle::fancy() ) {
737 actionName =
"view_headers_brief";
738 }
else if ( style == HeaderStyle::brief() ) {
739 slotStandardHeaders();
740 actionName =
"view_headers_standard";
741 }
else if ( style == HeaderStyle::plain() ) {
742 if ( strategy == HeaderStrategy::standard() ) {
744 actionName =
"view_headers_long";
745 }
else if ( strategy == HeaderStrategy::rich() ) {
747 actionName =
"view_headers_all";
748 }
else if ( strategy == HeaderStrategy::all() ) {
749 slotEnterpriseHeaders();
750 actionName =
"view_headers_enterprise";
755 static_cast<TDERadioAction*
>( mActionCollection->action( actionName ) )->setChecked(
true );
759 void KMReaderWin::slotIconicAttachments() {
760 setAttachmentStrategy( AttachmentStrategy::iconic() );
763 void KMReaderWin::slotSmartAttachments() {
764 setAttachmentStrategy( AttachmentStrategy::smart() );
767 void KMReaderWin::slotInlineAttachments() {
768 setAttachmentStrategy( AttachmentStrategy::inlined() );
771 void KMReaderWin::slotHideAttachments() {
772 setAttachmentStrategy( AttachmentStrategy::hidden() );
775 void KMReaderWin::slotHeaderOnlyAttachments() {
776 setAttachmentStrategy( AttachmentStrategy::headerOnly() );
779 void KMReaderWin::slotCycleAttachmentStrategy() {
783 action->setChecked(
true );
788 KMReaderWin::~KMReaderWin()
793 clearBodyPartMementos();
794 delete mHtmlWriter; mHtmlWriter = 0;
796 if (mAutoDelete)
delete message();
797 delete mRootNode; mRootNode = 0;
803 void KMReaderWin::slotMessageArrived(
KMMessage *msg )
805 if (msg && ((KMMsgBase*)msg)->isMessage()) {
806 if ( msg->getMsgSerNum() == mWaitingForSerNum ) {
832 kdDebug(5006) <<
"KMReaderWin::update - no updated part" << endl;
835 partNode* node = mRootNode->findNodeForDwPart( msg->
lastUpdatedPart() );
837 kdDebug(5006) <<
"KMReaderWin::update - can't find node for part" << endl;
844 ::chmod( TQFile::encodeName( mAtmCurrentName ), S_IRWXU );
845 TQByteArray data = node->msgPart().bodyDecodedBinary();
846 size_t size = data.size();
847 if ( node->msgPart().type() == DwMime::kTypeText && size) {
850 KPIM::kBytesToFile( data.data(), size, mAtmCurrentName,
false,
false, false );
851 ::chmod( TQFile::encodeName( mAtmCurrentName ), S_IRUSR );
859 for (TQStringList::Iterator it = mTempFiles.begin(); it != mTempFiles.end();
865 for (TQStringList::Iterator it = mTempDirs.begin(); it != mTempDirs.end();
868 TQDir(*it).rmdir(*it);
877 if (e->type() == TQEvent::ApplicationPaletteChange)
880 mCSSHelper =
new KMail::CSSHelper( TQPaintDeviceMetrics( mViewer->view() ) );
893 const TDEConfigGroup mdnGroup( KMKernel::config(),
"MDN" );
894 TDEConfigGroup reader( KMKernel::config(),
"Reader" );
897 mCSSHelper =
new KMail::CSSHelper( TQPaintDeviceMetrics( mViewer->view() ) );
899 mNoMDNsWhenEncrypted = mdnGroup.readBoolEntry(
"not-send-when-encrypted",
true );
901 mUseFixedFont = reader.readBoolEntry(
"useFixedFont",
false );
902 if ( mToggleFixFontAction )
903 mToggleFixFontAction->setChecked( mUseFixedFont );
905 mHtmlMail = reader.readBoolEntry(
"htmlMail",
false );
906 mHtmlLoadExternal = reader.readBoolEntry(
"htmlLoadExternal",
false );
909 HeaderStrategy::create( reader.readEntry(
"header-set-displayed",
"rich" ) ) );
910 TDERadioAction *raction = actionForHeaderStyle( headerStyle(),
headerStrategy() );
912 raction->setChecked(
true );
914 setAttachmentStrategy( AttachmentStrategy::create( reader.readEntry(
"attachment-strategy",
"smart" ) ) );
917 raction->setChecked(
true );
921 mShowColorbar = reader.readBoolEntry(
"showColorbar", Kpgp::Module::getKpgp()->usePGP() );
925 reader.writeEntry(
"showColorbar", mShowColorbar );
927 mMimeTreeAtBottom = reader.readEntry(
"MimeTreeLocation",
"bottom" ) !=
"top";
928 const TQString s = reader.readEntry(
"MimeTreeMode",
"smart" );
931 else if ( s ==
"always" )
936 const int mimeH = reader.readNumEntry(
"MimePaneHeight", 100 );
937 const int messageH = reader.readNumEntry(
"MessagePaneHeight", 180 );
938 mSplitterSizes.clear();
939 if ( mMimeTreeAtBottom )
940 mSplitterSizes << messageH << mimeH;
942 mSplitterSizes << mimeH << messageH;
946 readGlobalOverrideCodec();
954 void KMReaderWin::adjustLayout() {
955 if ( mMimeTreeAtBottom )
956 mSplitter->moveToLast( mMimePartTree );
958 mSplitter->moveToFirst( mMimePartTree );
959 mSplitter->setSizes( mSplitterSizes );
961 if ( mMimeTreeMode == 2 && mMsgDisplay )
962 mMimePartTree->show();
964 mMimePartTree->hide();
966 if ( mShowColorbar && mMsgDisplay )
973 void KMReaderWin::saveSplitterSizes( TDEConfigBase & c )
const {
974 if ( !mSplitter || !mMimePartTree )
976 if ( mMimePartTree->isHidden() )
979 c.writeEntry(
"MimePaneHeight", mSplitter->sizes()[ mMimeTreeAtBottom ? 1 : 0 ] );
980 c.writeEntry(
"MessagePaneHeight", mSplitter->sizes()[ mMimeTreeAtBottom ? 0 : 1 ] );
985 TDEConfigGroup reader( KMKernel::config(),
"Reader" );
987 reader.writeEntry(
"useFixedFont", mUseFixedFont );
989 reader.writeEntry(
"header-style", headerStyle()->name() );
991 reader.writeEntry(
"header-set-displayed",
headerStrategy()->name() );
995 saveSplitterSizes( reader );
998 kmkernel->slotRequestConfigSync();
1004 mViewer->widget()->setFocusPolicy(TQ_WheelFocus);
1006 mViewer->setPluginsEnabled(
false);
1007 mViewer->setJScriptEnabled(
false);
1008 mViewer->setJavaEnabled(
false);
1009 mViewer->setMetaRefreshEnabled(
false);
1010 mViewer->setURLCursor(KCursor::handCursor());
1012 mViewer->view()->setLineWidth(0);
1014 mViewer->view()->viewport()->installEventFilter(
this );
1017 #ifdef KMAIL_READER_HTML_DEBUG
1018 mHtmlWriter =
new TeeHtmlWriter(
new FileHtmlWriter( TQString() ),
1019 new KHtmlPartHtmlWriter( mViewer, 0 ) );
1021 mHtmlWriter =
new KHtmlPartHtmlWriter( mViewer, 0 );
1024 connect(mViewer->browserExtension(),
1025 TQT_SIGNAL(openURLRequest(
const KURL &,
const KParts::URLArgs &)),
this,
1027 connect(mViewer->browserExtension(),
1028 TQT_SIGNAL(createNewWindow(
const KURL &,
const KParts::URLArgs &)),
this,
1030 connect(mViewer,TQT_SIGNAL(
popupMenu(
const TQString &,
const TQPoint &)),
1031 TQT_SLOT(
slotUrlPopup(
const TQString &,
const TQPoint &)));
1032 connect( kmkernel->imProxy(), TQT_SIGNAL( sigContactPresenceChanged(
const TQString & ) ),
1033 TQT_TQOBJECT(
this), TQT_SLOT( contactStatusChanged(
const TQString & ) ) );
1034 connect( kmkernel->imProxy(), TQT_SIGNAL( sigPresenceInfoExpired() ),
1038 void KMReaderWin::contactStatusChanged(
const TQString &uid)
1042 DOM::NodeList presenceNodes = mViewer->htmlDocument()
1043 .getElementsByName( DOM::DOMString( TQString::fromLatin1(
"presence-") + uid ) );
1044 for (
unsigned int i = 0; i < presenceNodes.length(); ++i ) {
1045 DOM::Node n = presenceNodes.item( i );
1046 kdDebug( 5006 ) <<
"name is " << n.nodeName().string() << endl;
1047 kdDebug( 5006 ) <<
"value of content was " << n.firstChild().nodeValue().string() << endl;
1048 TQString newPresence = kmkernel->imProxy()->presenceString( uid );
1049 if ( newPresence.isNull() )
1050 newPresence = TQString::fromLatin1(
"ENOIMRUNNING" );
1051 n.firstChild().setNodeValue( newPresence );
1057 void KMReaderWin::setAttachmentStrategy(
const AttachmentStrategy * strategy ) {
1058 mAttachmentStrategy = strategy ? strategy : AttachmentStrategy::smart();
1063 const HeaderStrategy * strategy ) {
1064 mHeaderStyle = style ? style : HeaderStyle::fancy();
1065 mHeaderStrategy = strategy ? strategy : HeaderStrategy::rich();
1066 if ( mHeaderOnlyAttachmentsAction ) {
1067 const bool styleHasAttachmentQuickList = mHeaderStyle == HeaderStyle::fancy() ||
1068 mHeaderStyle == HeaderStyle::enterprise();
1069 mHeaderOnlyAttachmentsAction->setEnabled( styleHasAttachmentQuickList );
1070 if ( !styleHasAttachmentQuickList && mAttachmentStrategy == AttachmentStrategy::headerOnly() ) {
1073 setAttachmentStrategy( AttachmentStrategy::smart() );
1082 if ( encoding == mOverrideEncoding )
1085 mOverrideEncoding = encoding;
1086 if ( mSelectEncodingAction ) {
1087 if ( encoding.isEmpty() ) {
1088 mSelectEncodingAction->setCurrentItem( 0 );
1091 TQStringList encodings = mSelectEncodingAction->items();
1093 for ( TQStringList::const_iterator it = encodings.begin(), end = encodings.end(); it != end; ++it, ++i ) {
1094 if ( TDEGlobal::charsets()->encodingForName( *it ) == encoding ) {
1095 mSelectEncodingAction->setCurrentItem( i );
1099 if ( i == encodings.size() ) {
1101 kdWarning(5006) <<
"Unknown override character encoding \"" << encoding
1102 <<
"\". Using Auto instead." << endl;
1103 mSelectEncodingAction->setCurrentItem( 0 );
1104 mOverrideEncoding = TQString();
1112 void KMReaderWin::setPrintFont(
const TQFont& font )
1115 mCSSHelper->setPrintFont( font );
1121 if ( mOverrideEncoding.isEmpty() || mOverrideEncoding ==
"Auto" )
1124 return KMMsgBase::codecForName( mOverrideEncoding.latin1() );
1128 void KMReaderWin::slotSetEncoding()
1130 if ( mSelectEncodingAction->currentItem() == 0 )
1131 mOverrideEncoding = TQString();
1133 mOverrideEncoding = TDEGlobal::charsets()->encodingForName( mSelectEncodingAction->currentText() );
1138 void KMReaderWin::readGlobalOverrideCodec()
1141 if ( GlobalSettings::self()->overrideCharacterEncoding() == mOldGlobalOverrideEncoding )
1145 mOldGlobalOverrideEncoding = GlobalSettings::self()->overrideCharacterEncoding();
1151 mSerNumOfOriginalMessage = serNumOfOriginalMessage;
1152 mNodeIdOffset = nodeIdOffset;
1159 kdDebug(5006) <<
"(" << aMsg->getMsgSerNum() <<
", last " << mLastSerNum <<
") " << aMsg->
subject() <<
" "
1160 << aMsg->fromStrip() <<
", readyToShow " << (aMsg->
readyToShow()) << endl;
1164 if ( aMsg && aMsg->getMsgSerNum() != mLastSerNum && !updateOnly ){
1165 mLevelQuote = GlobalSettings::self()->collapseQuoteLevelSpin()-1;
1166 mShowRawToltecMail = !GlobalSettings::self()->showToltecReplacementText();
1167 clearBodyPartMementos();
1172 bool complete =
true;
1175 (aMsg->getMsgSerNum() != mLastSerNum) &&
1180 if (!force && aMsg && mLastSerNum != 0 && aMsg->getMsgSerNum() == mLastSerNum)
1187 aMsg->attach(
this );
1190 mDelayedMarkTimer.stop();
1194 mWaitingForSerNum = 0;
1197 mLastSerNum = aMsg->getMsgSerNum();
1214 mViewer->setDNDEnabled(
false );
1216 mViewer->setDNDEnabled(
true );
1226 mUpdateReaderWinTimer.stop();
1229 else if (mUpdateReaderWinTimer.isActive())
1230 mUpdateReaderWinTimer.changeInterval( delay );
1232 mUpdateReaderWinTimer.start( 0,
true );
1235 if ( aMsg && (aMsg->isUnread() || aMsg->isNew()) && GlobalSettings::self()->delayedMarkAsRead() ) {
1236 if ( GlobalSettings::self()->delayedMarkTime() != 0 )
1237 mDelayedMarkTimer.start( GlobalSettings::self()->delayedMarkTime() * 1000, true );
1242 mHeaderRefreshTimer.start( 1000,
false );
1248 mUpdateReaderWinTimer.stop();
1250 mDelayedMarkTimer.stop();
1252 mWaitingForSerNum = 0;
1257 static const char *
const kmailChanges[] = {
1260 static const int numKMailChanges =
1261 sizeof kmailChanges /
sizeof *kmailChanges;
1267 static const char *
const kmailNewFeatures[] = {
1268 I18N_NOOP(
"Full namespace support for IMAP"),
1269 I18N_NOOP(
"Offline mode"),
1270 I18N_NOOP(
"Sieve script management and editing"),
1271 I18N_NOOP(
"Account specific filtering"),
1272 I18N_NOOP(
"Filtering of incoming mail for online IMAP accounts"),
1273 I18N_NOOP(
"Online IMAP folders can be used when filtering into folders"),
1274 I18N_NOOP(
"Automatically delete older mails on POP servers")
1276 static const int numKMailNewFeatures =
1277 sizeof kmailNewFeatures /
sizeof *kmailNewFeatures;
1285 for (
int i = 0 ; i < numKMailChanges ; ++i )
1286 str += kmailChanges[i];
1287 for (
int i = 0 ; i < numKMailNewFeatures ; ++i )
1288 str += kmailNewFeatures[i];
1290 return md5.base64Digest();
1296 mMsgDisplay =
false;
1299 TQString location = locate(
"data",
"kmail/about/main.html");
1300 TQString content = KPIM::kFileToString(location);
1301 content = content.arg( locate(
"data",
"libtdepim/about/kde_infopage.css" ) );
1302 if ( kapp->reverseLayout() )
1303 content = content.arg(
"@import \"%1\";" ).arg( locate(
"data",
"libtdepim/about/kde_infopage_rtl.css" ) );
1305 content = content.arg(
"" );
1307 mViewer->begin(KURL( location ));
1309 TQString fontSize = TQString::number(
pointsToPixel( mCSSHelper->bodyFont().pointSize() ) );
1310 TQString appTitle = i18n(
"KMail");
1311 TQString catchPhrase =
"";
1312 TQString quickDescription = i18n(
"The email client for the Trinity Desktop Environment.");
1313 mViewer->write(content.arg(fontSize).arg(appTitle).arg(catchPhrase).arg(quickDescription).arg(info));
1320 i18n(
"<h2 style='margin-top: 0px;'>Retrieving Folder Contents</h2><p>Please wait . . .</p> " );
1328 i18n(
"<h2 style='margin-top: 0px;'>Offline</h2><p>KMail is currently in offline mode. "
1329 "Click <a href=\"kmail:goOnline\">here</a> to go online . . .</p> " );
1339 i18n(
"%1: KMail version; %2: help:// URL; %3: homepage URL; "
1340 "%4: prior KMail version; %5: prior TDE version; "
1341 "%6: generated list of new features; "
1342 "%7: First-time user text (only shown on first start); "
1343 "%8: generated list of important changes; "
1344 "--- end of comment ---",
1345 "<h2 style='margin-top: 0px;'>Welcome to KMail %1</h2><p>KMail is the email client for the Trinity "
1346 "Desktop Environment. It is designed to be fully compatible with "
1347 "Internet mailing standards including MIME, SMTP, POP3 and IMAP."
1349 "<ul><li>KMail has many powerful features which are described in the "
1350 "<a href=\"%2\">documentation</a></li>\n"
1351 "<li>The <a href=\"%3\">KMail (TDE) homepage</A> offers information about "
1352 "new versions of KMail</li></ul>\n"
1354 "<p>Some of the new features in this release of KMail include "
1355 "(compared to KMail %4, which is part of TDE %5):</p>\n"
1358 "<p>We hope that you will enjoy KMail.</p>\n"
1359 "<p>Thank you,</p>\n"
1360 "<p style='margin-bottom: 0px'> The KMail Team</p>")
1362 .arg(
"help:/kmail/index.html")
1363 .arg(
"http://www.trinitydesktop.org")
1364 .arg(
"1.8").arg(
"3.4");
1366 TQString featureItems;
1367 for (
int i = 0 ; i < numKMailNewFeatures ; i++ )
1368 featureItems += i18n(
"<li>%1</li>\n").arg( i18n( kmailNewFeatures[i] ) );
1370 info = info.arg( featureItems );
1372 if( kmkernel->firstStart() ) {
1373 info = info.arg( i18n(
"<p>Please take a moment to fill in the KMail "
1374 "configuration panel at Settings->Configure "
1376 "You need to create at least a default identity and "
1377 "an incoming as well as outgoing mail account."
1380 info = info.arg( TQString() );
1383 if ( ( numKMailChanges > 1 ) || ( numKMailChanges == 1 && strlen(kmailChanges[0]) > 0 ) ) {
1384 TQString changesText =
1385 i18n(
"<p><span style='font-size:125%; font-weight:bold;'>"
1386 "Important changes</span> (compared to KMail %1):</p>\n")
1388 changesText +=
"<ul>\n";
1389 for (
int i = 0 ; i < numKMailChanges ; i++ )
1390 changesText += i18n(
"<li>%1</li>\n").arg( i18n( kmailChanges[i] ) );
1391 changesText +=
"</ul>\n";
1392 info = info.arg( changesText );
1395 info = info.arg(
"");
1410 if (!mMsgDisplay)
return;
1419 if ( mShowColorbar )
1428 mMimePartTree->hide();
1429 mMimePartTree->clear();
1430 htmlWriter()->begin( mCSSHelper->cssDefinitions( isFixedFont() ) );
1431 htmlWriter()->write( mCSSHelper->htmlHead( isFixedFont() ) +
"</body></html>" );
1435 if (mSavedRelativePosition)
1437 TQScrollView * scrollview =
static_cast<TQScrollView *
>(mViewer->widget());
1438 scrollview->setContentsPos( 0,
1439 tqRound( scrollview->contentsHeight() * mSavedRelativePosition ) );
1440 mSavedRelativePosition = 0;
1447 const TQPaintDeviceMetrics pdm(mViewer->view());
1449 return (pointSize * pdm.logicalDpiY() + 36) / 72;
1454 if ( mMimeTreeModeOverride == 2 ||
1455 ( mMimeTreeModeOverride != 0 && (mMimeTreeMode == 2 ||
1456 ( mMimeTreeMode == 1 && !isPlainTextTopLevel ) ) ) ) {
1457 mMimePartTree->show();
1461 TDEConfigGroup reader( KMKernel::config(),
"Reader" );
1462 saveSplitterSizes( reader );
1463 mMimePartTree->hide();
1466 if ( mToggleMimePartTreeAction && mToggleMimePartTreeAction->isChecked() != mMimePartTree->isVisible() ) {
1467 mToggleMimePartTreeAction->setChecked( mMimePartTree->isVisible() );
1474 mMimePartTree->clear();
1475 mMimeTreeModeOverride = -1;
1477 ( msg->type() == DwMime::kTypeText
1478 && msg->subtype() == DwMime::kSubtypePlain ) );
1485 htmlWriter()->begin( mCSSHelper->cssDefinitions( isFixedFont() ) );
1486 htmlWriter()->queue( mCSSHelper->htmlHead( isFixedFont() ) );
1497 if( mColorBar->isNeutral() )
1503 TQTimer::singleShot( 1, TQT_TQOBJECT(
this), TQT_SLOT(injectAttachments()) );
1506 static bool message_was_saved_decrypted_before(
const KMMessage * msg ) {
1510 return msg->
msgId().stripWhiteSpace().startsWith(
"<DecryptedMsg." );
1516 KMMessagePart msgPart;
1517 TQCString subtype, contDisp;
1522 aMsg->setIsBeingParsed(
true );
1524 if ( mRootNode && !mRootNode->processed() )
1526 kdWarning() <<
"The root node is not yet processed! Danger!\n";
1530 mRootNode = partNode::fromMessage( aMsg,
this );
1531 const TQCString mainCntTypeStr = mRootNode->typeString() +
'/' + mRootNode->subTypeString();
1533 TQString cntDesc = aMsg->
subject();
1534 if( cntDesc.isEmpty() )
1535 cntDesc = i18n(
"( body part )");
1536 TDEIO::filesize_t cntSize = aMsg->
msgSize();
1544 mRootNode->fillMimePartTree( 0,
1551 partNode* vCardNode = mRootNode->findType( DwMime::kTypeText, DwMime::kSubtypeXVCard );
1552 bool hasVCard =
false;
1556 TDEABC::VCardConverter t;
1557 #if defined(KABC_VCARD_ENCODING_FIX)
1558 const TQByteArray vcard = vCardNode->msgPart().bodyDecodedBinary();
1559 if ( !t.parseVCardsRaw( vcard.data() ).empty() ) {
1561 const TQString vcard = vCardNode->msgPart().bodyToUnicode(
overrideCodec() );
1562 if ( !t.parseVCards( vcard ).empty() ) {
1569 if ( !mRootNode || !mRootNode->isToltecMessage() || mShowRawToltecMail ) {
1574 ObjectTreeParser otp(
this );
1575 otp.setAllowAsync(
true );
1576 otp.setShowRawToltecMail( mShowRawToltecMail );
1577 otp.parseObjectTree( mRootNode );
1581 KMMsgEncryptionState encryptionState = mRootNode->overallEncryptionState();
1582 KMMsgSignatureState signatureState = mRootNode->overallSignatureState();
1591 if ( signatureState != KMMsgNotSigned ||
1596 bool emitReplaceMsgByUnencryptedVersion =
false;
1597 const TDEConfigGroup reader( KMKernel::config(),
"Reader" );
1598 if ( reader.readBoolEntry(
"store-displayed-messages-unencrypted",
false ) ) {
1613 kdDebug(5006) <<
"\n\n\nKMReaderWin::parseMsg() - special post-encryption handling:\n1." << endl;
1614 kdDebug(5006) <<
"(aMsg == msg) = " << (aMsg ==
message()) << endl;
1615 kdDebug(5006) <<
"aMsg->parent() && aMsg->parent() != kmkernel->outboxFolder() = " << (aMsg->parent() && aMsg->parent() != kmkernel->outboxFolder()) << endl;
1616 kdDebug(5006) <<
"message_was_saved_decrypted_before( aMsg ) = " << message_was_saved_decrypted_before( aMsg ) << endl;
1617 kdDebug(5006) <<
"this->decryptMessage() = " <<
decryptMessage() << endl;
1618 kdDebug(5006) <<
"otp.hasPendingAsyncJobs() = " << otp.hasPendingAsyncJobs() << endl;
1619 kdDebug(5006) <<
" (KMMsgFullyEncrypted == encryptionState) = " << (KMMsgFullyEncrypted == encryptionState) << endl;
1620 kdDebug(5006) <<
"|| (KMMsgPartiallyEncrypted == encryptionState) = " << (KMMsgPartiallyEncrypted == encryptionState) << endl;
1625 && ( aMsg->parent() && aMsg->parent() != kmkernel->outboxFolder() )
1627 && !message_was_saved_decrypted_before( aMsg )
1631 && !otp.hasPendingAsyncJobs()
1633 && ( (KMMsgFullyEncrypted == encryptionState)
1634 || (KMMsgPartiallyEncrypted == encryptionState) ) ) {
1636 kdDebug(5006) <<
"KMReaderWin - calling objectTreeToDecryptedMsg()" << endl;
1638 NewByteArray decryptedData;
1640 objectTreeToDecryptedMsg( mRootNode, decryptedData, *aMsg );
1642 decryptedData.appendNULL();
1643 TQCString resultString( decryptedData.data() );
1644 kdDebug(5006) <<
"KMReaderWin - resulting data:" << resultString << endl;
1646 if( !resultString.isEmpty() ) {
1647 kdDebug(5006) <<
"KMReaderWin - composing unencrypted message" << endl;
1649 aMsg->
setBody( resultString );
1651 unencryptedMessage->setParent( 0 );
1660 kdDebug(5006) <<
"KMReaderWin - attach unencrypted message to aMsg" << endl;
1662 emitReplaceMsgByUnencryptedVersion =
true;
1668 const int rootNodeCntType = mRootNode ? mRootNode->type() : DwMime::kTypeText;
1669 const int rootNodeCntSubtype = mRootNode ? mRootNode->subType() : DwMime::kSubtypePlain;
1674 if( emitReplaceMsgByUnencryptedVersion ) {
1675 kdDebug(5006) <<
"KMReaderWin - invoce saving in decrypted form:" << endl;
1678 kdDebug(5006) <<
"KMReaderWin - finished parsing and displaying of message." << endl;
1680 rootNodeCntSubtype == DwMime::kSubtypePlain );
1683 aMsg->setIsBeingParsed(
false );
1688 void KMReaderWin::updateHeader()
1700 if (currentMessage &&
1701 mHeaderStyle == HeaderStyle::fancy() &&
1702 currentMessage->parent())
1706 DOM::NodeList divs(mViewer->document().documentElement().getElementsByTagName(
"div"));
1707 DOM::NodeList headerDivs(static_cast<DOM::HTMLDivElement>(divs.item(0)).getElementsByTagName(
"div"));
1708 for (i=0; i<((int)headerDivs.length()); i++) {
1709 if (static_cast<DOM::HTMLDivElement>(headerDivs.item(i)).
id().string() ==
"sendersCurrentTime") {
1715 if (divNumber >= 0) {
1716 DOM::HTMLDivElement elem =
static_cast<DOM::HTMLDivElement
>(headerDivs.item(i));
1720 TQString latestHeader = headerStyle()->format( currentMessage,
headerStrategy(),
"", mPrinting,
false );
1721 int startPos = latestHeader.find(
"<div id=\"sendersCurrentTime\" style=\"");
1722 if (startPos >= 0) {
1723 latestHeader = latestHeader.mid(startPos);
1724 int endPos = latestHeader.find(
"</div>");
1726 endPos = endPos + 6;
1727 latestHeader.truncate(endPos);
1729 TQString divText = latestHeader;
1730 TQString divStyle = latestHeader;
1732 divText = divText.mid(divText.find(
">")+1);
1733 divText.truncate(divText.find(
"</div>"));
1735 divStyle = divStyle.mid(TQString(
"<div id=\"sendersCurrentTime\" style=\"").length());
1736 divStyle.truncate(divStyle.find(
"\""));
1738 elem.setInnerHTML(divText);
1739 elem.setAttribute(
"style", divStyle);
1740 elem.applyChanges();
1750 kdFatal( !headerStyle(), 5006 )
1751 <<
"trying to writeMsgHeader() without a header style set!" << endl;
1753 <<
"trying to writeMsgHeader() without a header strategy set!" << endl;
1756 href = vCardNode->asHREF(
"body" );
1758 return headerStyle()->format( aMsg,
headerStrategy(), href, mPrinting, topLevel );
1767 TQString fileName = aMsgPart->fileName();
1768 if( fileName.isEmpty() )
1769 fileName = aMsgPart->name();
1772 TQString fname =
createTempDir( TQString::number( aPartNum ) );
1773 if ( fname.isEmpty() )
1777 int slashPos = fileName.findRev(
'/' );
1778 if( -1 != slashPos )
1779 fileName = fileName.mid( slashPos + 1 );
1780 if( fileName.isEmpty() )
1781 fileName =
"unnamed";
1782 fname +=
"/" + fileName;
1784 TQByteArray data = aMsgPart->bodyDecodedBinary();
1785 size_t size = data.size();
1786 if ( aMsgPart->type() == DwMime::kTypeText && size) {
1790 if( !KPIM::kBytesToFile( data.data(), size, fname,
false,
false, false ) )
1793 mTempFiles.append( fname );
1796 ::chmod( TQFile::encodeName( fname ), S_IRUSR );
1803 KTempFile *tempFile =
new KTempFile( TQString(),
"." + param );
1804 tempFile->setAutoDelete(
true );
1805 TQString fname = tempFile->name();
1808 if( ::access( TQFile::encodeName( fname ), W_OK ) != 0 )
1810 if( ::mkdir( TQFile::encodeName( fname ), 0 ) != 0
1811 || ::chmod( TQFile::encodeName( fname ), S_IRWXU ) != 0 )
1814 assert( !fname.isNull() );
1816 mTempDirs.append( fname );
1823 #if defined(KABC_VCARD_ENCODING_FIX)
1824 const TQByteArray vCard = msgPart->bodyDecodedBinary();
1826 const TQString vCard = msgPart->bodyToUnicode(
overrideCodec() );
1828 VCardViewer *vcv =
new VCardViewer(
this, vCard,
"vCardDialog" );
1836 mViewer->view()->print();
1843 if (aUrl.isEmpty())
return -1;
1844 if (!aUrl.isLocalFile())
return -1;
1846 TQString path = aUrl.path();
1847 uint right = path.findRev(
'/');
1848 uint left = path.findRev(
'.', right);
1851 int res = path.mid(left + 1, right - left - 1).toInt(&ok);
1852 return (ok) ? res : -1;
1857 void KMReaderWin::resizeEvent(TQResizeEvent *)
1859 if( !mResizeTimer.isActive() )
1865 mResizeTimer.start( 100,
true );
1871 void KMReaderWin::slotDelayedResize()
1873 mSplitter->setGeometry(0, 0, width(), height());
1878 void KMReaderWin::slotTouchMessage()
1887 serNums.append(
message()->getMsgSerNum() );
1888 KMCommand *command =
new KMSeStatusCommand( KMMsgStatusRead, serNums );
1892 if ( mNoMDNsWhenEncrypted &&
1893 message()->encryptionState() != KMMsgNotEncrypted &&
1894 message()->encryptionState() != KMMsgEncryptionStateUnknown )
1906 if ( !kmkernel->msgSender()->send( receipt ) )
1907 KMessageBox::error(
this, i18n(
"Could not send MDN.") );
1919 bool foundSMIMEData(
const TQString aUrl,
1920 TQString& displayName,
1924 static TQString showCertMan(
"showCertificate#");
1928 int i1 = aUrl.find( showCertMan );
1930 i1 += showCertMan.length();
1931 int i2 = aUrl.find(
" ### ", i1);
1934 displayName = aUrl.mid( i1, i2-i1 );
1936 i2 = aUrl.find(
" ### ", i1);
1939 libName = aUrl.mid( i1, i2-i1 );
1942 keyId = aUrl.mid( i2 );
1958 return !keyId.isEmpty();
1965 const KURL url(aUrl);
1967 if ( url.protocol() ==
"kmail" || url.protocol() ==
"x-kmail" || url.protocol() ==
"attachment"
1968 || (url.protocol().isEmpty() && url.path().isEmpty()) ) {
1969 mViewer->setDNDEnabled(
false );
1971 mViewer->setDNDEnabled(
true );
1974 if ( aUrl.stripWhiteSpace().isEmpty() ) {
1975 KPIM::BroadcastStatus::instance()->reset();
1976 mHoveredUrl = KURL();
1977 mLastClickImagePath = TQString();
1983 const TQString msg = URLHandlerManager::instance()->statusBarMessage( url,
this );
1985 kdWarning( msg.isEmpty(), 5006 ) <<
"KMReaderWin::slotUrlOn(): Unhandled URL hover!" << endl;
1986 KPIM::BroadcastStatus::instance()->setTransienStatusMsg( msg );
1995 if ( URLHandlerManager::instance()->handleClick( aUrl,
this ) )
1998 kdWarning( 5006 ) <<
"KMReaderWin::slotOpenUrl(): Unhandled URL click!" << endl;
2005 const KURL url( aUrl );
2008 if ( url.protocol() ==
"mailto" ) {
2009 mCopyURLAction->setText( i18n(
"Copy Email Address" ) );
2011 mCopyURLAction->setText( i18n(
"Copy Link Address" ) );
2014 if ( URLHandlerManager::instance()->handleContextMenuRequest( url, aPos,
this ) )
2018 kdWarning( 5006 ) <<
"KMReaderWin::slotUrlPopup(): Unhandled URL right-click!" << endl;
2019 emitPopupMenu( url, aPos );
2025 static bool hasParentDivWithId(
const DOM::Node &start,
const TQString &
id )
2027 if ( start.isNull() )
2030 if ( start.nodeName().string() ==
"div" ) {
2031 for (
unsigned int i = 0; i < start.attributes().length(); i++ ) {
2032 if ( start.attributes().item( i ).nodeName().string() ==
"id" &&
2033 start.attributes().item( i ).nodeValue().string() == id )
2038 if ( !start.parentNode().isNull() )
2039 return hasParentDivWithId( start.parentNode(), id );
2044 void KMReaderWin::showAttachmentPopup(
int id,
const TQString & name,
const TQPoint & p )
2047 mAtmCurrentName = name;
2048 TDEPopupMenu *menu =
new TDEPopupMenu();
2049 menu->insertItem(SmallIcon(
"document-open"),i18n(
"to open",
"Open"), 1);
2050 menu->insertItem(i18n(
"Open With..."), 2);
2051 menu->insertItem(i18n(
"to view something",
"View"), 3);
2052 menu->insertItem(SmallIcon(
"document-save-as"),i18n(
"Save As..."), 4);
2053 menu->insertItem(SmallIcon(
"edit-copy"), i18n(
"Copy"), 9 );
2054 const bool canChange =
message()->parent() ? !
message()->parent()->isReadOnly() :
false;
2055 if ( GlobalSettings::self()->allowAttachmentEditing() && canChange )
2056 menu->insertItem(SmallIcon(
"edit"), i18n(
"Edit Attachment"), 8 );
2057 if ( GlobalSettings::self()->allowAttachmentDeletion() && canChange )
2058 menu->insertItem(SmallIcon(
"edit-delete"), i18n(
"Delete Attachment"), 7 );
2059 if ( name.endsWith(
".xia",
false ) &&
2060 Kleo::CryptoBackendFactory::instance()->protocol(
"Chiasmus" ) )
2061 menu->insertItem( i18n(
"Decrypt With Chiasmus..." ), 6 );
2062 menu->insertItem(i18n(
"Properties"), 5);
2064 const bool attachmentInHeader = hasParentDivWithId( mViewer->nodeUnderMouse(),
"attachmentInjectionPoint" );
2065 const bool hasScrollbar = mViewer->view()->verticalScrollBar()->isVisible();
2066 if ( attachmentInHeader && hasScrollbar ) {
2067 menu->insertItem( i18n(
"Scroll To"), 10 );
2070 connect(menu, TQT_SIGNAL(activated(
int)), TQT_TQOBJECT(
this), TQT_SLOT(slotHandleAttachment(
int)));
2082 if( style().isA(
"KeramikStyle") )
2083 frameWidth = style().pixelMetric( TQStyle::PM_DefaultFrameWidth ) - 1;
2085 frameWidth = style().pixelMetric( TQStyle::PM_DefaultFrameWidth );
2086 if ( frameWidth < 0 )
2088 if ( frameWidth != mBox->lineWidth() )
2089 mBox->setLineWidth( frameWidth );
2100 void KMReaderWin::slotHandleAttachment(
int choice )
2103 partNode* node = mRootNode ? mRootNode->findId( mAtmCurrent ) : 0;
2104 if ( mAtmCurrentName.isEmpty() && node )
2105 mAtmCurrentName = tempFileUrlFromPartNode( node ).path();
2107 KMHandleAttachmentCommand* command =
new KMHandleAttachmentCommand(
2108 node,
message(), mAtmCurrent, mAtmCurrentName,
2109 KMHandleAttachmentCommand::AttachmentAction( choice ), 0,
this );
2110 connect( command, TQT_SIGNAL( showAttachment(
int,
const TQString& ) ),
2111 TQT_TQOBJECT(
this), TQT_SLOT(
slotAtmView(
int,
const TQString& ) ) );
2113 }
else if ( choice == 7 ) {
2114 slotDeleteAttachment( node );
2115 }
else if ( choice == 8 ) {
2116 slotEditAttachment( node );
2117 }
else if ( choice == 9 ) {
2118 if ( !node )
return;
2120 KURL url = tempFileUrlFromPartNode( node );
2121 if (!url.isValid() )
return;
2123 KURLDrag* drag =
new KURLDrag( urls,
this );
2124 TQApplication::clipboard()->setData( drag, TQClipboard::Clipboard );
2125 }
else if ( choice == 10 ) {
2133 mViewer->findText();
2139 mViewer->findTextNext();
2145 mUseFixedFont = !mUseFixedFont;
2154 if ( mToggleMimePartTreeAction->isChecked() ) {
2155 mMimeTreeModeOverride = 2;
2157 mMimeTreeModeOverride = 0;
2165 kapp->clipboard()->setText( mViewer->selectedText() );
2172 assert(aMsgPart!=0);
2174 msg->fromString(aMsgPart->bodyDecoded());
2178 msg->setParent(
message()->parent() );
2179 msg->setUID(
message()->UID());
2181 KMReaderMainWin *win =
new KMReaderMainWin();
2190 htmlWriter()->begin( mCSSHelper->cssDefinitions( isFixedFont() ) );
2191 htmlWriter()->write( mCSSHelper->htmlHead( isFixedFont() ) );
2194 ObjectTreeParser otp(
this, 0,
true );
2195 otp.parseObjectTree( node );
2204 const TQString& aFileName,
const TQString& pname )
2207 if (kasciistricmp(aMsgPart->typeStr(),
"message")==0) {
2210 assert(aMsgPart!=0);
2211 msg->fromString(aMsgPart->bodyDecoded());
2212 mMainWindow->setCaption(msg->
subject());
2214 setAutoDelete(
true);
2215 }
else if (kasciistricmp(aMsgPart->typeStr(),
"text")==0) {
2216 if (kasciistricmp(aMsgPart->subtypeStr(),
"x-vcard") == 0) {
2220 htmlWriter()->begin( mCSSHelper->cssDefinitions( isFixedFont() ) );
2221 htmlWriter()->queue( mCSSHelper->htmlHead( isFixedFont() ) );
2223 if (aHTML && (kasciistricmp(aMsgPart->subtypeStr(),
"html")==0)) {
2228 const TQCString str = aMsgPart->bodyDecoded();
2229 ObjectTreeParser otp(
this );
2230 otp.writeBodyStr( str,
2236 mMainWindow->setCaption(i18n(
"View Attachment: %1").arg(pname));
2237 }
else if (kasciistricmp(aMsgPart->typeStr(),
"image")==0 ||
2238 (kasciistricmp(aMsgPart->typeStr(),
"application")==0 &&
2239 kasciistricmp(aMsgPart->subtypeStr(),
"postscript")==0))
2241 if (aFileName.isEmpty())
return;
2243 TQImageIO *iio =
new TQImageIO();
2244 iio->setFileName(aFileName);
2246 TQImage img = iio->image();
2247 TQRect desk = TDEGlobalSettings::desktopGeometry(mMainWindow);
2250 if( img.width() < 50 )
2252 else if( img.width()+20 < desk.width() )
2253 width = img.width()+20;
2255 width = desk.width();
2256 if( img.height() < 50 )
2258 else if( img.height()+20 < desk.height() )
2259 height = img.height()+20;
2261 height = desk.height();
2262 mMainWindow->resize( width, height );
2265 htmlWriter()->begin( mCSSHelper->cssDefinitions( isFixedFont() ) );
2266 htmlWriter()->write( mCSSHelper->htmlHead( isFixedFont() ) );
2268 KURL::encode_string( aFileName ) +
2269 "\" border=\"0\">\n"
2270 "</body></html>\n" );
2272 setCaption( i18n(
"View Attachment: %1").arg( pname ) );
2276 htmlWriter()->begin( mCSSHelper->cssDefinitions( isFixedFont() ) );
2277 htmlWriter()->queue( mCSSHelper->htmlHead( isFixedFont() ) );
2280 TQString str = aMsgPart->bodyDecoded();
2283 if( str.length() < (unsigned) aMsgPart->decodedSize() ) {
2284 str.prepend( i18n(
"[KMail: Attachment contains binary data. Trying to show first character.]",
2285 "[KMail: Attachment contains binary data. Trying to show first %n characters.]",
2286 str.length()) + TQChar(
'\n') );
2288 htmlWriter()->queue( TQStyleSheet::escape( str ) );
2292 mMainWindow->setCaption(i18n(
"View Attachment: %1").arg(pname));
2301 partNode* node = mRootNode ? mRootNode->findId(
id ) : 0;
2304 mAtmCurrentName = name;
2305 if ( mAtmCurrentName.isEmpty() )
2306 mAtmCurrentName = tempFileUrlFromPartNode( node ).path();
2308 KMMessagePart& msgPart = node->msgPart();
2309 TQString pname = msgPart.fileName();
2310 if (pname.isEmpty()) pname=msgPart.name();
2311 if (pname.isEmpty()) pname=msgPart.contentDescription();
2312 if (pname.isEmpty()) pname=
"unnamed";
2314 if (kasciistricmp(msgPart.typeStr(),
"message")==0) {
2316 }
else if ((kasciistricmp(msgPart.typeStr(),
"text")==0) &&
2317 (kasciistricmp(msgPart.subtypeStr(),
"x-vcard")==0)) {
2320 KMReaderMainWin *win =
new KMReaderMainWin(&msgPart,
htmlMail(),
2328 void KMReaderWin::openAttachment(
int id,
const TQString & name )
2330 mAtmCurrentName = name;
2333 TQString str, pname, cmd, fileName;
2335 partNode* node = mRootNode ? mRootNode->findId(
id ) : 0;
2337 kdWarning(5006) <<
"KMReaderWin::openAttachment - could not find node " <<
id << endl;
2340 if ( mAtmCurrentName.isEmpty() )
2341 mAtmCurrentName = tempFileUrlFromPartNode( node ).path();
2343 KMMessagePart& msgPart = node->msgPart();
2344 if (kasciistricmp(msgPart.typeStr(),
"message")==0)
2350 TQCString contentTypeStr( msgPart.typeStr() +
'/' + msgPart.subtypeStr() );
2351 KPIM::kAsciiToLower( contentTypeStr.data() );
2353 if ( qstrcmp( contentTypeStr,
"text/x-vcard" ) == 0 ) {
2359 KMimeType::Ptr mimetype;
2361 mimetype = KMimeType::mimeType( TQString::fromLatin1( contentTypeStr ) );
2362 if ( mimetype->name() ==
"application/octet-stream" ) {
2364 mimetype = KMimeType::findByPath( name, 0,
true );
2366 if ( ( mimetype->name() ==
"application/octet-stream" )
2367 && msgPart.isComplete() ) {
2370 mimetype = KMimeType::findByFileContent( name );
2373 KService::Ptr offer =
2374 KServiceTypeProfile::preferredService( mimetype->name(),
"Application" );
2377 TQString filenameText = msgPart.fileName();
2378 if ( filenameText.isEmpty() )
2379 filenameText = msgPart.name();
2381 open_text = i18n(
"&Open with '%1'").arg( offer->name() );
2383 open_text = i18n(
"&Open With...");
2385 const TQString text = i18n(
"Open attachment '%1'?\n"
2386 "Note that opening an attachment may compromise "
2387 "your system's security.")
2388 .arg( filenameText );
2389 const int choice = KMessageBox::questionYesNoCancel(
this, text,
2390 i18n(
"Open Attachment?"), KStdGuiItem::saveAs(), open_text,
2391 TQString::fromLatin1(
"askSave") + mimetype->name() );
2393 if( choice == KMessageBox::Yes ) {
2395 KMHandleAttachmentCommand* command =
new KMHandleAttachmentCommand( node,
2396 message(), mAtmCurrent, mAtmCurrentName, KMHandleAttachmentCommand::Save,
2398 connect( command, TQT_SIGNAL( showAttachment(
int,
const TQString& ) ),
2399 TQT_TQOBJECT(
this), TQT_SLOT(
slotAtmView(
int,
const TQString& ) ) );
2402 else if( choice == KMessageBox::No ) {
2403 KMHandleAttachmentCommand::AttachmentAction action = ( offer ?
2404 KMHandleAttachmentCommand::Open : KMHandleAttachmentCommand::OpenWith );
2406 KMHandleAttachmentCommand* command =
new KMHandleAttachmentCommand( node,
2407 message(), mAtmCurrent, mAtmCurrentName, action, offer,
this );
2408 connect( command, TQT_SIGNAL( showAttachment(
int,
const TQString& ) ),
2409 TQT_TQOBJECT(
this), TQT_SLOT(
slotAtmView(
int,
const TQString& ) ) );
2412 kdDebug(5006) <<
"Canceled opening attachment" << endl;
2419 static_cast<TQScrollView *
>(mViewer->widget())->scrollBy(0, -10);
2424 void KMReaderWin::slotScrollDown()
2426 static_cast<TQScrollView *
>(mViewer->widget())->scrollBy(0, 10);
2429 bool KMReaderWin::atBottom()
const
2431 const TQScrollView *view =
static_cast<const TQScrollView *
>(mViewer->widget());
2432 return view->contentsY() + view->visibleHeight() >= view->contentsHeight();
2436 void KMReaderWin::slotJumpDown()
2438 TQScrollView *view =
static_cast<TQScrollView *
>(mViewer->widget());
2439 int offs = (view->clipper()->height() < 30) ? view->clipper()->height() : 30;
2440 view->scrollBy( 0, view->clipper()->height() - offs );
2444 void KMReaderWin::slotScrollPrior()
2446 static_cast<TQScrollView *
>(mViewer->widget())->scrollBy(0, -(
int)(height()*0.8));
2451 void KMReaderWin::slotScrollNext()
2453 static_cast<TQScrollView *
>(mViewer->widget())->scrollBy(0, (
int)(height()*0.8));
2457 void KMReaderWin::slotDocumentChanged()
2464 void KMReaderWin::slotTextSelected(
bool)
2466 TQString temp = mViewer->selectedText();
2467 kapp->clipboard()->setText(temp);
2473 mViewer->selectAll();
2479 TQString temp = mViewer->selectedText();
2485 void KMReaderWin::slotDocumentDone()
2492 void KMReaderWin::setHtmlOverride(
bool override)
2494 mHtmlOverride =
override;
2501 void KMReaderWin::setHtmlLoadExtOverride(
bool override)
2503 mHtmlLoadExtOverride =
override;
2512 return ((mHtmlMail && !mHtmlOverride) || (!mHtmlMail && mHtmlOverride));
2519 return ((mHtmlLoadExternal && !mHtmlLoadExtOverride) ||
2520 (!mHtmlLoadExternal && mHtmlLoadExtOverride));
2527 const TQScrollView * scrollview =
static_cast<TQScrollView *
>( mViewer->widget() );
2528 mSavedRelativePosition =
2529 static_cast<float>( scrollview->contentsY() ) / scrollview->contentsHeight();
2538 setMsg( msg, force,
true );
2546 KMFolder*& folder = aFolder ? *aFolder : tmpFolder;
2555 message = folder->
getMsg( index );
2557 kdWarning(5006) <<
"Attempt to reference invalid serial number " << mLastSerNum <<
"\n" << endl;
2566 void KMReaderWin::slotUrlClicked()
2568 KMMainWidget *mainWidget =
dynamic_cast<KMMainWidget*
>(mMainWindow);
2571 identity =
message()->parent()->identity();
2574 KMCommand *command =
new KMUrlClickedCommand( mClickedUrl, identity,
this,
2575 false, mainWidget );
2580 void KMReaderWin::slotMailtoCompose()
2582 KMCommand *command =
new KMMailtoComposeCommand( mClickedUrl,
message() );
2587 void KMReaderWin::slotMailtoForward()
2589 KMCommand *command =
new KMMailtoForwardCommand( mMainWindow, mClickedUrl,
2595 void KMReaderWin::slotMailtoAddAddrBook()
2597 KMCommand *command =
new KMMailtoAddAddrBookCommand( mClickedUrl,
2603 void KMReaderWin::slotMailtoOpenAddrBook()
2605 KMCommand *command =
new KMMailtoOpenAddrBookCommand( mClickedUrl,
2615 KMCommand *command =
2616 new KMUrlCopyCommand( mClickedUrl,
2617 dynamic_cast<KMMainWidget*>( mMainWindow ) );
2624 if ( !url.isEmpty() )
2626 KMCommand *command =
new KMUrlOpenCommand( mClickedUrl,
this );
2631 void KMReaderWin::slotAddBookmarks()
2633 KMCommand *command =
new KMAddBookmarksCommand( mClickedUrl,
this );
2640 KMCommand *command =
new KMUrlSaveCommand( mClickedUrl, mMainWindow );
2647 KMCommand *command =
new KMMailtoReplyCommand( mMainWindow, mClickedUrl,
2654 return mRootNode ? mRootNode->findId(
msgPartFromUrl( url ) ) : 0 ;
2657 partNode * KMReaderWin::partNodeForId(
int id ) {
2658 return mRootNode ? mRootNode->findId(
id ) : 0 ;
2662 KURL KMReaderWin::tempFileUrlFromPartNode(
const partNode * node )
2664 if (!node)
return KURL();
2665 TQStringList::const_iterator it = mTempFiles.begin();
2666 TQStringList::const_iterator end = mTempFiles.end();
2668 while ( it != end ) {
2669 TQString path = *it;
2671 uint right = path.findRev(
'/');
2672 uint left = path.findRev(
'.', right);
2675 int res = path.mid(left + 1, right - left - 1).toInt(&ok);
2676 if ( res == node->nodeId() )
2677 return KURL( path );
2683 void KMReaderWin::slotSaveAttachments()
2686 KMSaveAttachmentsCommand *saveCommand =
new KMSaveAttachmentsCommand( mMainWindow,
2688 saveCommand->start();
2692 void KMReaderWin::saveAttachment(
const KURL &tempFileName )
2695 mAtmCurrentName = mClickedUrl.path();
2696 slotHandleAttachment( KMHandleAttachmentCommand::Save );
2700 void KMReaderWin::slotSaveMsg()
2702 KMSaveMsgCommand *saveCommand =
new KMSaveMsgCommand( mMainWindow,
message() );
2704 if (saveCommand->url().isEmpty())
2707 saveCommand->start();
2712 KMCommand *command =
new KMIMChatCommand( mClickedUrl,
message() );
2717 static TQString linkForNode(
const DOM::Node &node )
2720 if ( node.isNull() )
2723 const DOM::NamedNodeMap attributes = node.attributes();
2724 if ( !attributes.isNull() ) {
2725 const DOM::Node href = attributes.getNamedItem( DOM::DOMString(
"href" ) );
2726 if ( !href.isNull() ) {
2727 return href.nodeValue().string();
2730 if ( !node.parentNode().isNull() ) {
2731 return linkForNode( node.parentNode() );
2735 }
catch ( DOM::DOMException &e ) {
2736 kdWarning(5006) <<
"Got an exception when trying to determine link under cursor!" << endl;
2744 if ( e->type() == TQEvent::MouseButtonPress ) {
2745 TQMouseEvent* me = TQT_TQMOUSEEVENT(e);
2746 if ( me->button() == Qt::LeftButton && ( me->state() & ShiftButton ) ) {
2748 URLHandlerManager::instance()->handleShiftClick( mHoveredUrl,
this );
2752 if ( me->button() == Qt::LeftButton ) {
2755 const DOM::Node nodeUnderMouse = mViewer->nodeUnderMouse();
2756 if ( !nodeUnderMouse.isNull() ) {
2757 const DOM::NamedNodeMap attributes = nodeUnderMouse.attributes();
2758 if ( !attributes.isNull() ) {
2759 const DOM::Node src = attributes.getNamedItem( DOM::DOMString(
"src" ) );
2760 if ( !src.isNull() ) {
2761 imagePath = src.nodeValue().string();
2766 mCanStartDrag = URLHandlerManager::instance()->willHandleDrag( mHoveredUrl, imagePath,
this );
2767 mLastClickPosition = me->pos();
2768 mLastClickImagePath = imagePath;
2772 if ( e->type() == TQEvent::MouseButtonRelease ) {
2773 mCanStartDrag =
false;
2776 if ( e->type() == TQEvent::MouseMove ) {
2777 TQMouseEvent* me = TQT_TQMOUSEEVENT( e );
2781 slotUrlOn( linkForNode( mViewer->nodeUnderMouse() ) );
2783 if ( ( mLastClickPosition - me->pos() ).manhattanLength() > TDEGlobalSettings::dndEventDelay() ) {
2784 if ( mCanStartDrag && ( !( mHoveredUrl.isEmpty() && mLastClickImagePath.isEmpty() ) ) ) {
2785 if ( URLHandlerManager::instance()->handleDrag( mHoveredUrl, mLastClickImagePath,
this ) ) {
2786 mCanStartDrag =
false;
2792 TQMouseEvent mouseEvent( TQEvent::MouseButtonRelease, me->pos(), Qt::NoButton, Qt::NoButton );
2793 TQT_TQOBJECT( mViewer->view() )->
eventFilter( mViewer->view()->viewport(),
2807 Q_ASSERT( msg && nodeId );
2809 if ( mSerNumOfOriginalMessage != 0 ) {
2813 if ( folder && index != -1 )
2814 *msg = folder->
getMsg( index );
2817 kdWarning( 5006 ) <<
"Unable to find the original message, aborting attachment deletion!" << endl;
2821 *nodeId = node->nodeId() + mNodeIdOffset;
2824 *nodeId = node->nodeId();
2829 void KMReaderWin::slotDeleteAttachment(partNode * node)
2831 if ( KMessageBox::warningContinueCancel(
this,
2832 i18n(
"Deleting an attachment might invalidate any digital signature on this message."),
2833 i18n(
"Delete Attachment"), KStdGuiItem::del(),
"DeleteAttachmentSignatureWarning" )
2834 != KMessageBox::Continue ) {
2841 if ( msg && nodeId != -1 ) {
2842 KMDeleteAttachmentCommand* command =
new KMDeleteAttachmentCommand( nodeId, msg,
this );
2844 connect( command, TQT_SIGNAL( completed( KMCommand * ) ),
2846 connect( command, TQT_SIGNAL( completed( KMCommand * ) ),
2855 connect( headers, TQT_SIGNAL( msgAddedToListView( TQListViewItem* ) ),
2856 TQT_TQOBJECT(
this), TQT_SLOT( msgAdded( TQListViewItem* ) ) );
2860 if ( mSerNumOfOriginalMessage != 0 &&
message() ) {
2866 void KMReaderWin::msgAdded( TQListViewItem *item )
2873 headers->setCurrentItem( item );
2874 headers->clearSelection();
2881 disconnect( headers, TQT_SIGNAL( msgAddedToListView( TQListViewItem* ) ),
2882 TQT_TQOBJECT(
this), TQT_SLOT( msgAdded( TQListViewItem* ) ) );
2885 void KMReaderWin::slotEditAttachment(partNode * node)
2887 if ( KMessageBox::warningContinueCancel(
this,
2888 i18n(
"Modifying an attachment might invalidate any digital signature on this message."),
2889 i18n(
"Edit Attachment"), KGuiItem( i18n(
"Edit"),
"edit" ),
"EditAttachmentSignatureWarning" )
2890 != KMessageBox::Continue ) {
2897 if ( msg && nodeId != -1 ) {
2898 KMEditAttachmentCommand* command =
new KMEditAttachmentCommand( nodeId, msg,
this );
2905 KMail::CSSHelper* KMReaderWin::cssHelper()
2912 if ( !GlobalSettings::self()->alwaysDecrypt() )
2913 return mDecrytMessageOverwrite;
2919 DOM::Document doc = mViewer->htmlDocument();
2922 mViewer->gotoAnchor( TQString::fromLatin1(
"att%1" ).arg( node->nodeId() ) );
2925 const partNode *root = node->topLevelParent();
2926 for (
int i = 0; i <= root->totalChildCount() + 1; i++ ) {
2927 DOM::Element attachmentDiv = doc.getElementById( TQString(
"attachmentDiv%1" ).arg( i + 1 ) );
2928 if ( !attachmentDiv.isNull() )
2929 attachmentDiv.removeAttribute(
"style" );
2933 if ( node->isDisplayedHidden() )
2939 DOM::Element attachmentDiv = doc.getElementById( TQString(
"attachmentDiv%1" ).arg( node->nodeId() ) );
2940 if ( attachmentDiv.isNull() ) {
2941 kdWarning( 5006 ) <<
"Could not find attachment div for attachment " << node->nodeId() << endl;
2945 attachmentDiv.setAttribute(
"style", TQString(
"border:2px solid %1" )
2946 .arg( cssHelper()->pgpWarnColor().name() ) );
2950 doc.updateRendering();
2953 void KMReaderWin::injectAttachments()
2957 DOM::Document doc = mViewer->htmlDocument();
2958 DOM::Element injectionPoint = doc.getElementById(
"attachmentInjectionPoint" );
2959 if ( injectionPoint.isNull() )
2962 TQString imgpath( locate(
"data",
"kmail/pics/") );
2963 TQString visibility;
2966 if( !showAttachmentQuicklist() ) {
2967 urlHandle.append(
"kmail:showAttachmentQuicklist" );
2968 imgSrc.append(
"attachmentQuicklistClosed.png" );
2970 urlHandle.append(
"kmail:hideAttachmentQuicklist" );
2971 imgSrc.append(
"attachmentQuicklistOpened.png" );
2974 TQString html = renderAttachments( mRootNode, TQApplication::palette().active().background() );
2975 if ( html.isEmpty() )
2979 if ( headerStyle() == HeaderStyle::fancy() ) {
2980 link +=
"<div style=\"text-align: left;\"><a href=\"" + urlHandle +
"\"><img src=\"" +
2981 imgpath + imgSrc +
"\"/></a></div>";
2982 html.prepend( link );
2983 html.prepend( TQString::fromLatin1(
"<div style=\"float:left;\">%1 </div>" ).
2984 arg( i18n(
"Attachments:" ) ) );
2986 link +=
"<div style=\"text-align: right;\"><a href=\"" + urlHandle +
"\"><img src=\"" +
2987 imgpath + imgSrc +
"\"/></a></div>";
2988 html.prepend( link );
2991 assert( injectionPoint.tagName() ==
"div" );
2992 static_cast<DOM::HTMLElement
>( injectionPoint ).setInnerHTML( html );
2995 static TQColor nextColor(
const TQColor & c )
2998 c.hsv( &h, &s, &v );
2999 return TQColor( (h + 50) % 360, TQMAX(s, 64), v, TQColor::Hsv );
3002 TQString KMReaderWin::renderAttachments(partNode * node,
const TQColor &bgColor )
3008 if ( node->firstChild() ) {
3009 TQString subHtml = renderAttachments( node->firstChild(), nextColor( bgColor ) );
3010 if ( !subHtml.isEmpty() ) {
3012 TQString visibility;
3013 if ( !showAttachmentQuicklist() ) {
3014 visibility.append(
"display:none;" );
3018 if ( node != mRootNode || headerStyle() != HeaderStyle::enterprise() )
3019 margin =
"padding:2px; margin:2px; ";
3020 TQString align =
"left";
3021 if ( headerStyle() == HeaderStyle::enterprise() )
3023 if ( node->msgPart().typeStr().lower() ==
"message" || node == mRootNode )
3024 html += TQString::fromLatin1(
"<div style=\"background:%1; %2"
3025 "vertical-align:middle; float:%3; %4\">").arg( bgColor.name() ).arg( margin )
3026 .arg( align ).arg( visibility );
3028 if ( node->msgPart().typeStr().lower() ==
"message" || node == mRootNode )
3032 partNode::AttachmentDisplayInfo info = node->attachmentDisplayInfo();
3033 if ( info.displayInHeader ) {
3034 html +=
"<div style=\"float:left;\">";
3035 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() );
3037 TQString href = node->asHREF(
"header" );
3038 html += TQString::fromLatin1(
"<a href=\"" ) + href +
3039 TQString::fromLatin1(
"\">" );
3040 html +=
"<img style=\"vertical-align:middle;\" src=\"" + info.icon +
"\"/> ";
3041 if ( headerStyle() == HeaderStyle::enterprise() ) {
3042 TQFont bodyFont = mCSSHelper->bodyFont( isFixedFont() );
3043 TQFontMetrics fm( bodyFont );
3044 html += KStringHandler::rPixelSqueeze( info.label, fm, 140 );
3045 }
else if ( headerStyle() == HeaderStyle::fancy() ) {
3046 TQFont bodyFont = mCSSHelper->bodyFont( isFixedFont() );
3047 TQFontMetrics fm( bodyFont );
3048 html += KStringHandler::rPixelSqueeze( info.label, fm, 640 );
3052 html +=
"</a></span></div> ";
3056 html += renderAttachments( node->nextSibling(), nextColor ( bgColor ) );
3060 using namespace KMail::Interface;
3062 void KMReaderWin::setBodyPartMemento(
const partNode * node,
const TQCString & which,
BodyPartMemento * memento )
3064 const TQCString index = node->path() +
':' + which.lower();
3066 const std::map<TQCString,BodyPartMemento*>::iterator it = mBodyPartMementoMap.lower_bound( index );
3067 if ( it != mBodyPartMementoMap.end() && it->first == index ) {
3069 if ( memento && memento == it->second )
3075 it->second = memento;
3078 mBodyPartMementoMap.erase( it );
3083 mBodyPartMementoMap.insert( it, std::make_pair( index, memento ) );
3091 BodyPartMemento * KMReaderWin::bodyPartMemento(
const partNode * node,
const TQCString & which )
const
3093 const TQCString index = node->path() +
':' + which.lower();
3094 const std::map<TQCString,BodyPartMemento*>::const_iterator it = mBodyPartMementoMap.find( index );
3095 if ( it == mBodyPartMementoMap.end() ) {
3109 void KMReaderWin::clearBodyPartMementos()
3111 for ( std::map<TQCString,BodyPartMemento*>::const_iterator it = mBodyPartMementoMap.begin(), end = mBodyPartMementoMap.end() ; it != end ; ++it )
3116 detach_and_delete( it->second,
this );
3118 mBodyPartMementoMap.clear();
3121 #include "kmreaderwin.moc"