kmail

kmmessage.cpp
1// kmmessage.cpp
2
3// if you do not want GUI elements in here then set ALLOW_GUI to 0.
4#include <config.h>
5// needed temporarily until KMime is replacing the partNode helper class:
6#include "partNode.h"
7
8
9#define ALLOW_GUI 1
10#include "kmkernel.h"
11#include "kmmessage.h"
12#include "mailinglist-magic.h"
13#include "messageproperty.h"
14using KMail::MessageProperty;
15#include "objecttreeparser.h"
16using KMail::ObjectTreeParser;
17#include "kmfolderindex.h"
18#include "undostack.h"
19#include "kmversion.h"
20#include "headerstrategy.h"
21#include "globalsettings.h"
22using KMail::HeaderStrategy;
23#include "kmaddrbook.h"
24#include "kcursorsaver.h"
25#include "templateparser.h"
26
27#include <libkpimidentities/identity.h>
28#include <libkpimidentities/identitymanager.h>
29#include <libemailfunctions/email.h>
30
31#include <kpgpblock.h>
32#include <kaddrbook.h>
33
34#include <tdeapplication.h>
35#include <tdeglobal.h>
36#include <tdeglobalsettings.h>
37#include <kdebug.h>
38#include <tdeconfig.h>
39#include <tdehtml_part.h>
40#include <kuser.h>
41#include <kidna.h>
42
43#include <tqcursor.h>
44#include <tqtextcodec.h>
45#include <tqmessagebox.h>
46#include <kmime_util.h>
47#include <kmime_charfreq.h>
48
49#include <kmime_header_parsing.h>
50using KMime::HeaderParsing::parseAddressList;
51using namespace KMime::Types;
52
53#include <mimelib/body.h>
54#include <mimelib/field.h>
55#include <mimelib/mimepp.h>
56#include <mimelib/string.h>
57#include <assert.h>
58#include <sys/time.h>
59#include <time.h>
60#include <tdelocale.h>
61#include <stdlib.h>
62#include <unistd.h>
63#include "util.h"
64
65#if ALLOW_GUI
66#include <tdemessagebox.h>
67#endif
68
69using namespace KMime;
70
71static DwString emptyString("");
72
73// Values that are set from the config file with KMMessage::readConfig()
74static TQString sReplyLanguage, sReplyStr, sReplyAllStr, sIndentPrefixStr;
75static bool sSmartQuote,
76 sWordWrap;
77static int sWrapCol;
78static TQStringList sPrefCharsets;
79
80TQString KMMessage::sForwardStr;
81const HeaderStrategy * KMMessage::sHeaderStrategy = HeaderStrategy::rich();
82//helper
83static void applyHeadersToMessagePart( DwHeaders& headers, KMMessagePart* aPart );
84
85TQValueList<KMMessage*> KMMessage::sPendingDeletes;
86
87//-----------------------------------------------------------------------------
88KMMessage::KMMessage(DwMessage* aMsg)
89 : KMMsgBase()
90{
91 init( aMsg );
92 // aMsg might need assembly
93 mNeedsAssembly = true;
94}
95
96//-----------------------------------------------------------------------------
97KMMessage::KMMessage(KMFolder* parent): KMMsgBase(parent)
98{
99 init();
100}
101
102
103//-----------------------------------------------------------------------------
104KMMessage::KMMessage(KMMsgInfo& msgInfo): KMMsgBase()
105{
106 init();
107 // now overwrite a few from the msgInfo
108 mMsgSize = msgInfo.msgSize();
109 mFolderOffset = msgInfo.folderOffset();
110 mStatus = msgInfo.status();
111 mEncryptionState = msgInfo.encryptionState();
112 mSignatureState = msgInfo.signatureState();
113 mMDNSentState = msgInfo.mdnSentState();
114 mDate = msgInfo.date();
115 mFileName = msgInfo.fileName();
116 KMMsgBase::assign(&msgInfo);
117}
118
119
120//-----------------------------------------------------------------------------
122 KMMsgBase( other ),
123 ISubject(),
124 mMsg(nullptr)
125{
126 init(); // to be safe
127 assign( other );
128}
129
130void KMMessage::init( DwMessage* aMsg )
131{
132 mNeedsAssembly = false;
133 if ( aMsg ) {
134 mMsg = aMsg;
135 } else {
136 mMsg = new DwMessage;
137 }
138 mOverrideCodec = nullptr;
139 mDecodeHTML = false;
140 mComplete = true;
141 mReadyToShow = true;
142 mMsgSize = 0;
143 mMsgLength = 0;
144 mFolderOffset = 0;
145 mStatus = KMMsgStatusNew;
146 mEncryptionState = KMMsgEncryptionStateUnknown;
147 mSignatureState = KMMsgSignatureStateUnknown;
148 mMDNSentState = KMMsgMDNStateUnknown;
149 mDate = 0;
150 mUnencryptedMsg = nullptr;
151 mLastUpdated = nullptr;
152 mCursorPos = 0;
153 mMsgInfo = nullptr;
154 mIsParsed = false;
155}
156
157void KMMessage::assign( const KMMessage& other )
158{
159 MessageProperty::forget( this );
160 delete mMsg;
161 delete mUnencryptedMsg;
162
163 mNeedsAssembly = true;//other.mNeedsAssembly;
164 if( other.mMsg )
165 mMsg = new DwMessage( *(other.mMsg) );
166 else
167 mMsg = nullptr;
168 mOverrideCodec = other.mOverrideCodec;
169 mDecodeHTML = other.mDecodeHTML;
170 mMsgSize = other.mMsgSize;
171 mMsgLength = other.mMsgLength;
172 mFolderOffset = other.mFolderOffset;
173 mStatus = other.mStatus;
174 mEncryptionState = other.mEncryptionState;
175 mSignatureState = other.mSignatureState;
176 mMDNSentState = other.mMDNSentState;
177 mIsParsed = other.mIsParsed;
178 mDate = other.mDate;
179 if( other.hasUnencryptedMsg() )
180 mUnencryptedMsg = new KMMessage( *other.unencryptedMsg() );
181 else
182 mUnencryptedMsg = nullptr;
183 setDrafts( other.drafts() );
184 setTemplates( other.templates() );
185 //mFileName = ""; // we might not want to copy the other messages filename (?)
186 //KMMsgBase::assign( &other );
187}
188
189//-----------------------------------------------------------------------------
191{
192 delete mMsgInfo;
193 delete mMsg;
194 kmkernel->undoStack()->msgDestroyed( this );
195}
196
197
198//-----------------------------------------------------------------------------
199void KMMessage::setReferences(const TQCString& aStr)
200{
201 if (aStr.isNull()) return;
202 mMsg->Headers().References().FromString(aStr);
203 mNeedsAssembly = true;
204}
205
206
207//-----------------------------------------------------------------------------
208TQCString KMMessage::id() const
209{
210 DwHeaders& header = mMsg->Headers();
211 if (header.HasMessageId())
212 return KMail::Util::CString( header.MessageId().AsString() );
213 else
214 return "";
215}
216
217
218//-----------------------------------------------------------------------------
219//WARNING: This method updates the memory resident cache of serial numbers
220//WARNING: held in MessageProperty, but it does not update the persistent
221//WARNING: store of serial numbers on the file system that is managed by
222//WARNING: KMMsgDict
223void KMMessage::setMsgSerNum(unsigned long newMsgSerNum)
224{
225 MessageProperty::setSerialCache( this, newMsgSerNum );
226}
227
228
229//-----------------------------------------------------------------------------
231{
232 return true;
233}
234
235//-----------------------------------------------------------------------------
237{
238 return MessageProperty::transferInProgress( getMsgSerNum() );
239}
240
241
242//-----------------------------------------------------------------------------
243void KMMessage::setTransferInProgress(bool value, bool force)
244{
245 MessageProperty::setTransferInProgress( getMsgSerNum(), value, force );
246 if ( !transferInProgress() && sPendingDeletes.contains( this ) ) {
247 sPendingDeletes.remove( this );
248 if ( parent() ) {
249 int idx = parent()->find( this );
250 if ( idx > 0 ) {
251 parent()->removeMsg( idx );
252 }
253 }
254 }
255}
256
257
258
260 return headerField( "Priority" ).contains( "urgent", false )
261 || headerField( "X-Priority" ).startsWith( "2" );
262}
263
264//-----------------------------------------------------------------------------
266{
267 delete mUnencryptedMsg;
268 mUnencryptedMsg = unencrypted;
269}
270
271//-----------------------------------------------------------------------------
272//FIXME: move to libemailfunctions
273KPIM::EmailParseResult KMMessage::isValidEmailAddressList( const TQString& aStr,
274 TQString& brokenAddress )
275{
276 if ( aStr.isEmpty() ) {
277 return KPIM::AddressEmpty;
278 }
279
280 TQStringList list = KPIM::splitEmailAddrList( aStr );
281 for( TQStringList::const_iterator it = list.begin(); it != list.end(); ++it ) {
282 KPIM::EmailParseResult errorCode = KPIM::isValidEmailAddress( *it );
283 if ( errorCode != KPIM::AddressOk ) {
284 brokenAddress = ( *it );
285 return errorCode;
286 }
287 }
288 return KPIM::AddressOk;
289}
290
291//-----------------------------------------------------------------------------
292const DwString& KMMessage::asDwString() const
293{
294 if (mNeedsAssembly)
295 {
296 mNeedsAssembly = false;
297 mMsg->Assemble();
298 }
299 return mMsg->AsString();
300}
301
302//-----------------------------------------------------------------------------
303const DwMessage* KMMessage::asDwMessage()
304{
305 if (mNeedsAssembly)
306 {
307 mNeedsAssembly = false;
308 mMsg->Assemble();
309 }
310 return mMsg;
311}
312
313//-----------------------------------------------------------------------------
314TQCString KMMessage::asString() const {
316}
317
318
320{
321 KMMessage msg( new DwMessage( *this->mMsg ) );
323 msg.removeHeaderField("Bcc");
324 return KMail::Util::ByteArray( msg.asDwString() ); // and another copy again!
325}
326
328{
329 KMMessage msg( new DwMessage( *this->mMsg ) );
331 msg.removeHeaderField("Bcc");
332 return msg.headerAsString().latin1();
333}
334
336 removeHeaderField("Status");
337 removeHeaderField("X-Status");
338 removeHeaderField("X-KMail-EncryptionState");
339 removeHeaderField("X-KMail-SignatureState");
340 removeHeaderField("X-KMail-MDN-Sent");
341 removeHeaderField("X-KMail-Transport");
342 removeHeaderField("X-KMail-Identity");
343 removeHeaderField("X-KMail-Fcc");
344 removeHeaderField("X-KMail-Redirect-From");
345 removeHeaderField("X-KMail-Link-Message");
346 removeHeaderField("X-KMail-Link-Type");
347 removeHeaderField( "X-KMail-Markup" );
348}
349
350//-----------------------------------------------------------------------------
352{
353 char str[2] = { 0, 0 };
354
355 setHeaderField("Status", status() & KMMsgStatusNew ? "R" : "RO");
356 setHeaderField("X-Status", statusToStr(status()));
357
358 str[0] = (char)encryptionState();
359 setHeaderField("X-KMail-EncryptionState", str);
360
361 str[0] = (char)signatureState();
362 //kdDebug(5006) << "Setting SignatureState header field to " << str[0] << endl;
363 setHeaderField("X-KMail-SignatureState", str);
364
365 str[0] = static_cast<char>( mdnSentState() );
366 setHeaderField("X-KMail-MDN-Sent", str);
367
368 // We better do the assembling ourselves now to prevent the
369 // mimelib from changing the message *body*. (khz, 10.8.2002)
370 mNeedsAssembly = false;
371 mMsg->Headers().Assemble();
372 mMsg->Assemble( mMsg->Headers(),
373 mMsg->Body() );
374}
375
376
377//----------------------------------------------------------------------------
379{
380 DwHeaders& header = mMsg->Headers();
381 header.Assemble();
382 if ( header.AsString().empty() )
383 return TQString();
384 return TQString::fromLatin1( header.AsString().c_str() );
385}
386
387
388//-----------------------------------------------------------------------------
390{
391 return mMsg->Headers().ContentType();
392}
393
394void KMMessage::fromByteArray( const TQByteArray & ba, bool setStatus ) {
395 return fromDwString( DwString( ba.data(), ba.size() ), setStatus );
396}
397
398void KMMessage::fromString( const TQCString & str, bool aSeStatus ) {
399 return fromDwString( KMail::Util::dwString( str ), aSeStatus );
400}
401
402void KMMessage::fromDwString(const DwString& str, bool aSeStatus)
403{
404 delete mMsg;
405 mMsg = new DwMessage;
406 mMsg->FromString( str );
407 mMsg->Parse();
408
409 if (aSeStatus) {
410 setStatus(headerField("Status").latin1(), headerField("X-Status").latin1());
411 setEncryptionStateChar( headerField("X-KMail-EncryptionState").at(0) );
412 setSignatureStateChar( headerField("X-KMail-SignatureState").at(0) );
413 setMDNSentState( static_cast<KMMsgMDNSentState>( headerField("X-KMail-MDN-Sent").at(0).latin1() ) );
414 }
415 if ( invitationState() == KMMsgInvitationUnknown && readyToShow() )
416 updateInvitationState();
417 if ( attachmentState() == KMMsgAttachmentUnknown && readyToShow() )
418 updateAttachmentState();
419
420 mNeedsAssembly = false;
421 mDate = date();
422}
423
424
425//-----------------------------------------------------------------------------
426TQString KMMessage::formatString(const TQString& aStr) const
427{
428 TQString result, str;
429 TQChar ch;
430 uint j;
431
432 if (aStr.isEmpty())
433 return aStr;
434
435 unsigned int strLength(aStr.length());
436 for (uint i=0; i<strLength;) {
437 ch = aStr[i++];
438 if (ch == '%') {
439 ch = aStr[i++];
440 switch ((char)ch) {
441 case 'D':
442 /* I'm not too sure about this change. Is it not possible
443 to have a long form of the date used? I don't
444 like this change to a short XX/XX/YY date format.
445 At least not for the default. -sanders */
446 result += KMime::DateFormatter::formatDate( KMime::DateFormatter::Localized,
447 date(), sReplyLanguage, false );
448 break;
449 case 'e':
450 result += from();
451 break;
452 case 'F':
453 result += fromStrip();
454 break;
455 case 'f':
456 {
457 str = fromStrip();
458
459 for (j=0; str[j]>' '; j++)
460 ;
461 unsigned int strLength(str.length());
462 for (; j < strLength && str[j] <= ' '; j++)
463 ;
464 result += str[0];
465 if (str[j]>' ')
466 result += str[j];
467 else
468 if (str[1]>' ')
469 result += str[1];
470 }
471 break;
472 case 'T':
473 result += toStrip();
474 break;
475 case 't':
476 result += to();
477 break;
478 case 'C':
479 result += ccStrip();
480 break;
481 case 'c':
482 result += cc();
483 break;
484 case 'S':
485 result += subject();
486 break;
487 case '_':
488 result += ' ';
489 break;
490 case 'L':
491 result += "\n";
492 break;
493 case '%':
494 result += '%';
495 break;
496 default:
497 result += '%';
498 result += ch;
499 break;
500 }
501 } else
502 result += ch;
503 }
504 return result;
505}
506
507static void removeTrailingSpace( TQString &line )
508{
509 int i = line.length()-1;
510 while( (i >= 0) && ((line[i] == ' ') || (line[i] == '\t')))
511 i--;
512 line.truncate( i+1);
513}
514
515static TQString splitLine( TQString &line)
516{
517 removeTrailingSpace( line );
518 int i = 0;
519 int j = -1;
520 int l = line.length();
521
522 // TODO: Replace tabs with spaces first.
523
524 while(i < l)
525 {
526 TQChar c = line[i];
527 if ((c == '>') || (c == ':') || (c == '|'))
528 j = i+1;
529 else if ((c != ' ') && (c != '\t'))
530 break;
531 i++;
532 }
533
534 if ( j <= 0 )
535 {
536 return "";
537 }
538 if ( i == l )
539 {
540 TQString result = line.left(j);
541 line = TQString();
542 return result;
543 }
544
545 TQString result = line.left(j);
546 line = line.mid(j);
547 return result;
548}
549
550static TQString flowText(TQString &text, const TQString& indent, int maxLength)
551{
552 maxLength--;
553 if (text.isEmpty())
554 {
555 return indent+"<NULL>\n";
556 }
557 TQString result;
558 while (1)
559 {
560 int i;
561 if ((int) text.length() > maxLength)
562 {
563 i = maxLength;
564 while( (i >= 0) && (text[i] != ' '))
565 i--;
566 if (i <= 0)
567 {
568 // Couldn't break before maxLength.
569 i = maxLength;
570// while( (i < (int) text.length()) && (text[i] != ' '))
571// i++;
572 }
573 }
574 else
575 {
576 i = text.length();
577 }
578
579 TQString line = text.left(i);
580 if (i < (int) text.length())
581 text = text.mid(i);
582 else
583 text = TQString();
584
585 result += indent + line + '\n';
586
587 if (text.isEmpty())
588 return result;
589 }
590}
591
592static bool flushPart(TQString &msg, TQStringList &part,
593 const TQString &indent, int maxLength)
594{
595 maxLength -= indent.length();
596 if (maxLength < 20) maxLength = 20;
597
598 // Remove empty lines at end of quote
599 while ((part.begin() != part.end()) && part.last().isEmpty())
600 {
601 part.remove(part.fromLast());
602 }
603
604 TQString text;
605 for(TQStringList::Iterator it2 = part.begin();
606 it2 != part.end();
607 it2++)
608 {
609 TQString line = (*it2);
610
611 if (line.isEmpty())
612 {
613 if (!text.isEmpty())
614 msg += flowText(text, indent, maxLength);
615 msg += indent + '\n';
616 }
617 else
618 {
619 if (text.isEmpty())
620 text = line;
621 else
622 text += ' '+line.stripWhiteSpace();
623
624 if (((int) text.length() < maxLength) || ((int) line.length() < (maxLength-10)))
625 msg += flowText(text, indent, maxLength);
626 }
627 }
628 if (!text.isEmpty())
629 msg += flowText(text, indent, maxLength);
630
631 bool appendEmptyLine = true;
632 if (!part.count())
633 appendEmptyLine = false;
634
635 part.clear();
636 return appendEmptyLine;
637}
638
639static TQString stripSignature( const TQString & msg, bool clearSigned ) {
640 if ( clearSigned )
641 return msg.left( msg.findRev( TQRegExp( "\n--\\s?\n" ) ) );
642 else
643 return msg.left( msg.findRev( "\n-- \n" ) );
644}
645
646TQString KMMessage::smartQuote( const TQString & msg, int maxLineLength )
647{
648 TQStringList part;
649 TQString oldIndent;
650 bool firstPart = true;
651
652
653 const TQStringList lines = TQStringList::split('\n', msg, true);
654
655 TQString result;
656 for(TQStringList::const_iterator it = lines.begin();
657 it != lines.end();
658 ++it)
659 {
660 TQString line = *it;
661
662 const TQString indent = splitLine( line );
663
664 if ( line.isEmpty())
665 {
666 if (!firstPart)
667 part.append(TQString());
668 continue;
669 };
670
671 if (firstPart)
672 {
673 oldIndent = indent;
674 firstPart = false;
675 }
676
677 if (oldIndent != indent)
678 {
679 TQString fromLine;
680 // Search if the last non-blank line could be "From" line
681 if (part.count() && (oldIndent.length() < indent.length()))
682 {
683 TQStringList::Iterator it2 = part.fromLast();
684 while( (it2 != part.end()) && (*it2).isEmpty())
685 --it2;
686
687 if ((it2 != part.end()) && ((*it2).endsWith(":")))
688 {
689 fromLine = oldIndent + (*it2) + '\n';
690 part.remove(it2);
691 }
692 }
693 if (flushPart( result, part, oldIndent, maxLineLength))
694 {
695 if (oldIndent.length() > indent.length())
696 result += indent + '\n';
697 else
698 result += oldIndent + '\n';
699 }
700 if (!fromLine.isEmpty())
701 {
702 result += fromLine;
703 }
704 oldIndent = indent;
705 }
706 part.append(line);
707 }
708 flushPart( result, part, oldIndent, maxLineLength);
709 return result;
710}
711
712
713//-----------------------------------------------------------------------------
715 TQCString& parsedString,
716 const TQTextCodec*& codec,
717 bool& isHTML ) const
718{
719 if ( !root ) return;
720
721 isHTML = false;
722 partNode * curNode = root->findType( DwMime::kTypeText,
723 DwMime::kSubtypeUnknown,
724 true,
725 false );
726 kdDebug(5006) << endl
727 << endl
728 << "======= KMMessage::parseTextStringFromDwPart() - "
729 << ( curNode ? "text part found!" : "sorry, no text node!" ) << endl;
730 if( curNode ) {
731 isHTML = DwMime::kSubtypeHtml == curNode->subType();
732 // now parse the TEXT message part we want to quote
733 ObjectTreeParser otp( nullptr, nullptr, true, false, true );
734 otp.parseObjectTree( curNode );
735 parsedString = otp.rawReplyString();
736 codec = curNode->msgPart().codec();
737 }
738}
739
740//-----------------------------------------------------------------------------
741
742TQString KMMessage::asPlainTextFromObjectTree( partNode *root, bool aStripSignature,
743 bool allowDecryption ) const
744{
745 Q_ASSERT( root );
746 Q_ASSERT( root->processed() );
747
748 TQCString parsedString;
749 bool isHTML = false;
750 const TQTextCodec * codec = nullptr;
751
752 if ( !root ) return TQString();
753 parseTextStringFromDwPart( root, parsedString, codec, isHTML );
754
755 if ( mOverrideCodec || !codec )
756 codec = this->codec();
757
758 if ( parsedString.isEmpty() )
759 return TQString();
760
761 bool clearSigned = false;
762 TQString result;
763
764 // decrypt
765 if ( allowDecryption ) {
766 TQPtrList<Kpgp::Block> pgpBlocks;
767 TQStrList nonPgpBlocks;
768 if ( Kpgp::Module::prepareMessageForDecryption( parsedString,
769 pgpBlocks,
770 nonPgpBlocks ) ) {
771 // Only decrypt/strip off the signature if there is only one OpenPGP
772 // block in the message
773 if ( pgpBlocks.count() == 1 ) {
774 Kpgp::Block * block = pgpBlocks.first();
775 if ( block->type() == Kpgp::PgpMessageBlock ||
776 block->type() == Kpgp::ClearsignedBlock ) {
777 if ( block->type() == Kpgp::PgpMessageBlock ) {
778 // try to decrypt this OpenPGP block
779 block->decrypt();
780 } else {
781 // strip off the signature
782 block->verify();
783 clearSigned = true;
784 }
785
786 result = codec->toUnicode( nonPgpBlocks.first() )
787 + codec->toUnicode( block->text() )
788 + codec->toUnicode( nonPgpBlocks.last() );
789 }
790 }
791 }
792 }
793
794 if ( result.isEmpty() ) {
795 result = codec->toUnicode( parsedString );
796 if ( result.isEmpty() )
797 return result;
798 }
799
800 // html -> plaintext conversion, if necessary:
801 if ( isHTML && mDecodeHTML ) {
802 TDEHTMLPart htmlPart;
803 htmlPart.setOnlyLocalReferences( true );
804 htmlPart.setMetaRefreshEnabled( false );
805 htmlPart.setPluginsEnabled( false );
806 htmlPart.setJScriptEnabled( false );
807 htmlPart.setJavaEnabled( false );
808 htmlPart.begin();
809 htmlPart.write( result );
810 htmlPart.end();
811 htmlPart.selectAll();
812 result = htmlPart.selectedText();
813 }
814
815 // strip the signature (footer):
816 if ( aStripSignature )
817 return stripSignature( result, clearSigned );
818 else
819 return result;
820}
821
822//-----------------------------------------------------------------------------
823
824TQString KMMessage::asPlainText( bool aStripSignature, bool allowDecryption ) const
825{
826 partNode *root = partNode::fromMessage( this );
827 if ( !root )
828 return TQString();
829
830 ObjectTreeParser otp;
831 otp.parseObjectTree( root );
832 TQString result = asPlainTextFromObjectTree( root, aStripSignature, allowDecryption );
833 delete root;
834 return result;
835}
836
837TQString KMMessage::asQuotedString( const TQString& aHeaderStr,
838 const TQString& aIndentStr,
839 const TQString& selection /* = TQString() */,
840 bool aStripSignature /* = true */,
841 bool allowDecryption /* = true */) const
842{
843 TQString content = selection.isEmpty() ?
844 asPlainText( aStripSignature, allowDecryption ) : selection ;
845
846 // Remove blank lines at the beginning:
847 const int firstNonWS = content.find( TQRegExp( "\\S" ) );
848 const int lineStart = content.findRev( '\n', firstNonWS );
849 if ( lineStart >= 0 )
850 content.remove( 0, static_cast<unsigned int>( lineStart ) );
851
852 const TQString indentStr = formatString( aIndentStr );
853
854 content.replace( '\n', '\n' + indentStr );
855 content.prepend( indentStr );
856 content += '\n';
857
858 const TQString headerStr = formatString( aHeaderStr );
859 if ( sSmartQuote && sWordWrap )
860 return headerStr + smartQuote( content, sWrapCol );
861 return headerStr + content;
862}
863
864//-----------------------------------------------------------------------------
865KMMessage* KMMessage::createReply( KMail::ReplyStrategy replyStrategy,
866 TQString selection /* = TQString() */,
867 bool noQuote /* = false */,
868 bool allowDecryption /* = true */,
869 const TQString &tmpl /* = TQString() */,
870 const TQString &originatingAccount /* = TQString() */ )
871{
872 KMMessage* msg = new KMMessage;
873 TQString mailingListStr, replyToStr, toStr;
874 TQStringList mailingListAddresses;
875 TQCString refStr, headerName;
876 bool replyAll = true;
877
878 msg->initFromMessage(this);
879
880 MailingList::name(this, headerName, mailingListStr);
881 replyToStr = replyTo();
882
883 msg->setCharset("utf-8");
884
885 // determine the mailing list posting address
886 if ( parent() && parent()->isMailingListEnabled() &&
887 !parent()->mailingListPostAddress().isEmpty() ) {
888 mailingListAddresses << parent()->mailingListPostAddress();
889 }
890 if ( headerField("List-Post").find( "mailto:", 0, false ) != -1 ) {
891 TQString listPost = headerField("List-Post");
892 TQRegExp rx( "<mailto:([^@>]+)@([^>]+)>", false );
893 if ( rx.search( listPost, 0 ) != -1 ) // matched
894 mailingListAddresses << rx.cap(1) + '@' + rx.cap(2);
895 }
896
897 // use the "On ... Joe User wrote:" header by default
898 switch( replyStrategy ) {
899 case KMail::ReplySmart : {
900 if ( !headerField( "Mail-Followup-To" ).isEmpty() ) {
901 toStr = headerField( "Mail-Followup-To" );
902 }
903 else if ( !replyToStr.isEmpty() ) {
904 // assume a Reply-To header mangling mailing list
905 toStr = replyToStr;
906 }
907 else if ( !mailingListAddresses.isEmpty() ) {
908 toStr = mailingListAddresses[0];
909 }
910 else {
911 // doesn't seem to be a mailing list, reply to From: address
912 toStr = from();
913 //replyStr = sReplyStr; // reply to author, so use "On ... you wrote:"
914 replyAll = false;
915 }
916 // strip all my addresses from the list of recipients
917 TQStringList recipients = KPIM::splitEmailAddrList( toStr );
918 toStr = stripMyAddressesFromAddressList( recipients ).join(", ");
919 // ... unless the list contains only my addresses (reply to self)
920 if ( toStr.isEmpty() && !recipients.isEmpty() )
921 toStr = recipients[0];
922
923 break;
924 }
925 case KMail::ReplyList : {
926 if ( !headerField( "Mail-Followup-To" ).isEmpty() ) {
927 toStr = headerField( "Mail-Followup-To" );
928 }
929 else if ( !mailingListAddresses.isEmpty() ) {
930 toStr = mailingListAddresses[0];
931 }
932 else if ( !replyToStr.isEmpty() ) {
933 // assume a Reply-To header mangling mailing list
934 toStr = replyToStr;
935 }
936 // strip all my addresses from the list of recipients
937 TQStringList recipients = KPIM::splitEmailAddrList( toStr );
938 toStr = stripMyAddressesFromAddressList( recipients ).join(", ");
939
940 break;
941 }
942 case KMail::ReplyAll : {
943 TQStringList recipients;
944 TQStringList ccRecipients;
945
946 // add addresses from the Reply-To header to the list of recipients
947 if( !replyToStr.isEmpty() ) {
948 recipients += KPIM::splitEmailAddrList( replyToStr );
949 // strip all possible mailing list addresses from the list of Reply-To
950 // addresses
951 for ( TQStringList::const_iterator it = mailingListAddresses.begin();
952 it != mailingListAddresses.end();
953 ++it ) {
954 recipients = stripAddressFromAddressList( *it, recipients );
955 }
956 }
957
958 if ( !mailingListAddresses.isEmpty() ) {
959 // this is a mailing list message
960 if ( recipients.isEmpty() && !from().isEmpty() ) {
961 // The sender didn't set a Reply-to address, so we add the From
962 // address to the list of CC recipients.
963 ccRecipients += from();
964 kdDebug(5006) << "Added " << from() << " to the list of CC recipients"
965 << endl;
966 }
967 // if it is a mailing list, add the posting address
968 recipients.prepend( mailingListAddresses[0] );
969 }
970 else {
971 // this is a normal message
972 if ( recipients.isEmpty() && !from().isEmpty() ) {
973 // in case of replying to a normal message only then add the From
974 // address to the list of recipients if there was no Reply-to address
975 recipients += from();
976 kdDebug(5006) << "Added " << from() << " to the list of recipients"
977 << endl;
978 }
979 }
980
981 // strip all my addresses from the list of recipients
982 toStr = stripMyAddressesFromAddressList( recipients ).join(", ");
983
984 // merge To header and CC header into a list of CC recipients
985 if( !cc().isEmpty() || !to().isEmpty() ) {
986 TQStringList list;
987 if (!to().isEmpty())
988 list += KPIM::splitEmailAddrList(to());
989 if (!cc().isEmpty())
990 list += KPIM::splitEmailAddrList(cc());
991 for( TQStringList::Iterator it = list.begin(); it != list.end(); ++it ) {
992 if( !addressIsInAddressList( *it, recipients )
993 && !addressIsInAddressList( *it, ccRecipients ) ) {
994 ccRecipients += *it;
995 kdDebug(5006) << "Added " << *it << " to the list of CC recipients"
996 << endl;
997 }
998 }
999 }
1000
1001 if ( !ccRecipients.isEmpty() ) {
1002 // strip all my addresses from the list of CC recipients
1003 ccRecipients = stripMyAddressesFromAddressList( ccRecipients );
1004
1005 // in case of a reply to self toStr might be empty. if that's the case
1006 // then propagate a cc recipient to To: (if there is any).
1007 if ( toStr.isEmpty() && !ccRecipients.isEmpty() ) {
1008 toStr = ccRecipients[0];
1009 ccRecipients.pop_front();
1010 }
1011
1012 msg->setCc( ccRecipients.join(", ") );
1013 }
1014
1015 if ( toStr.isEmpty() && !recipients.isEmpty() ) {
1016 // reply to self without other recipients
1017 toStr = recipients[0];
1018 }
1019 break;
1020 }
1021 case KMail::ReplyAuthor : {
1022 if ( !replyToStr.isEmpty() ) {
1023 TQStringList recipients = KPIM::splitEmailAddrList( replyToStr );
1024 // strip the mailing list post address from the list of Reply-To
1025 // addresses since we want to reply in private
1026 for ( TQStringList::const_iterator it = mailingListAddresses.begin();
1027 it != mailingListAddresses.end();
1028 ++it ) {
1029 recipients = stripAddressFromAddressList( *it, recipients );
1030 }
1031 if ( !recipients.isEmpty() ) {
1032 toStr = recipients.join(", ");
1033 }
1034 else {
1035 // there was only the mailing list post address in the Reply-To header,
1036 // so use the From address instead
1037 toStr = from();
1038 }
1039 }
1040 else if ( !from().isEmpty() ) {
1041 toStr = from();
1042 }
1043 replyAll = false;
1044 break;
1045 }
1046 case KMail::ReplyNone : {
1047 // the addressees will be set by the caller
1048 }
1049 }
1050
1051 if (!originatingAccount.isEmpty()) {
1052 msg->setOriginatingAccountName(originatingAccount);
1053 }
1054
1055 msg->setTo(toStr);
1056
1057 refStr = getRefStr();
1058 if (!refStr.isEmpty())
1059 msg->setReferences(refStr);
1060 //In-Reply-To = original msg-id
1061 msg->setReplyToId(msgId());
1062
1063// if (!noQuote) {
1064// if( selectionIsBody ){
1065// TQCString cStr = selection.latin1();
1066// msg->setBody( cStr );
1067// }else{
1068// msg->setBody(asQuotedString(replyStr + "\n", sIndentPrefixStr, selection,
1069// sSmartQuote, allowDecryption).utf8());
1070// }
1071// }
1072
1073 msg->setSubject( replySubject() );
1074 msg->setHeaderField( "X-KMail-QuotePrefix",
1075 formatString( GlobalSettings::self()->quoteString() ) );
1076 if( !noQuote ) {
1077 TemplateParser parser( msg, ( replyAll ? TemplateParser::ReplyAll : TemplateParser::Reply ) );
1078 parser.setAllowDecryption( allowDecryption );
1079 if ( GlobalSettings::quoteSelectionOnly() ) {
1080 parser.setSelection( selection );
1081 }
1082 if ( !tmpl.isEmpty() ) {
1083 parser.process( tmpl, this );
1084 } else {
1085 parser.process( this );
1086 }
1087 }
1088 // setStatus(KMMsgStatusReplied);
1089 msg->link(this, KMMsgStatusReplied);
1090
1091 if ( parent() && parent()->putRepliesInSameFolder() )
1092 msg->setFcc( parent()->idString() );
1093
1094 // replies to an encrypted message should be encrypted as well
1095 if ( encryptionState() == KMMsgPartiallyEncrypted ||
1096 encryptionState() == KMMsgFullyEncrypted ) {
1097 msg->setEncryptionState( KMMsgFullyEncrypted );
1098 }
1099
1100 return msg;
1101}
1102
1103
1104//-----------------------------------------------------------------------------
1105TQCString KMMessage::getRefStr() const
1106{
1107 TQCString firstRef, lastRef, refStr, retRefStr;
1108 int i, j;
1109
1110 refStr = headerField("References").stripWhiteSpace().latin1();
1111
1112 if (refStr.isEmpty())
1113 return headerField("Message-Id").latin1();
1114
1115 i = refStr.find('<');
1116 j = refStr.find('>');
1117 firstRef = refStr.mid(i, j-i+1);
1118 if (!firstRef.isEmpty())
1119 retRefStr = firstRef + ' ';
1120
1121 i = refStr.findRev('<');
1122 j = refStr.findRev('>');
1123
1124 lastRef = refStr.mid(i, j-i+1);
1125 if (!lastRef.isEmpty() && lastRef != firstRef)
1126 retRefStr += lastRef + ' ';
1127
1128 retRefStr += headerField("Message-Id").latin1();
1129 return retRefStr;
1130}
1131
1132
1133KMMessage* KMMessage::createRedirect( const TQString &toStr )
1134{
1135 // copy the message 1:1
1136 KMMessage* msg = new KMMessage( new DwMessage( *this->mMsg ) );
1137 KMMessagePart msgPart;
1138
1139 uint id = 0;
1140 TQString strId = msg->headerField( "X-KMail-Identity" ).stripWhiteSpace();
1141 if ( !strId.isEmpty())
1142 id = strId.toUInt();
1143 const KPIM::Identity & ident =
1144 kmkernel->identityManager()->identityForUoidOrDefault( id );
1145
1146 // X-KMail-Redirect-From: content
1147 TQString strByWayOf = TQString("%1 (by way of %2 <%3>)")
1148 .arg( from() )
1149 .arg( ident.fullName() )
1150 .arg( ident.primaryEmailAddress() );
1151
1152 // Resent-From: content
1153 TQString strFrom = TQString("%1 <%2>")
1154 .arg( ident.fullName() )
1155 .arg( ident.primaryEmailAddress() );
1156
1157 // format the current date to be used in Resent-Date:
1158 TQString origDate = msg->headerField( "Date" );
1159 msg->setDateToday();
1160 TQString newDate = msg->headerField( "Date" );
1161 // make sure the Date: header is valid
1162 if ( origDate.isEmpty() )
1163 msg->removeHeaderField( "Date" );
1164 else
1165 msg->setHeaderField( "Date", origDate );
1166
1167 // prepend Resent-*: headers (c.f. RFC2822 3.6.6)
1168 msg->setHeaderField( "Resent-Message-ID", generateMessageId( msg->sender() ),
1169 Structured, true);
1170 msg->setHeaderField( "Resent-Date", newDate, Structured, true );
1171 msg->setHeaderField( "Resent-To", toStr, Address, true );
1172 msg->setHeaderField( "Resent-From", strFrom, Address, true );
1173
1174 msg->setHeaderField( "X-KMail-Redirect-From", strByWayOf );
1175 msg->setHeaderField( "X-KMail-Recipients", toStr, Address );
1176
1177 msg->link(this, KMMsgStatusForwarded);
1178
1179 return msg;
1180}
1181
1182
1183//-----------------------------------------------------------------------------
1185{
1186 TQString s;
1187 TQCString str;
1188
1189 if (sHeaderStrategy == HeaderStrategy::all()) {
1190 s = "\n\n---------- " + sForwardStr + " ----------\n\n";
1191 s += headerAsString();
1192 str = asQuotedString(s, "", TQString(), false, false).utf8();
1193 str += "\n-------------------------------------------------------\n";
1194 } else {
1195 s = "\n\n---------- " + sForwardStr + " ----------\n\n";
1196 s += "Subject: " + subject() + "\n";
1197 s += "Date: "
1198 + KMime::DateFormatter::formatDate( KMime::DateFormatter::Localized,
1199 date(), sReplyLanguage, false )
1200 + "\n";
1201 s += "From: " + from() + "\n";
1202 s += "To: " + to() + "\n";
1203 if (!cc().isEmpty()) s += "Cc: " + cc() + "\n";
1204 s += "\n";
1205 str = asQuotedString(s, "", TQString(), false, false).utf8();
1206 str += "\n-------------------------------------------------------\n";
1207 }
1208
1209 return str;
1210}
1211
1212void KMMessage::sanitizeHeaders( const TQStringList& whiteList )
1213{
1214 // Strip out all headers apart from the content description and other
1215 // whitelisted ones, because we don't want to inherit them.
1216 DwHeaders& header = mMsg->Headers();
1217 DwField* field = header.FirstField();
1218 DwField* nextField;
1219 while (field)
1220 {
1221 nextField = field->Next();
1222 if ( field->FieldNameStr().find( "ontent" ) == DwString::npos
1223 && !whiteList.contains( TQString::fromLatin1( field->FieldNameStr().c_str() ) ) )
1224 header.RemoveField(field);
1225 field = nextField;
1226 }
1227 mMsg->Assemble();
1228}
1229
1230//-----------------------------------------------------------------------------
1231KMMessage* KMMessage::createForward( const TQString &tmpl /* = TQString() */ )
1232{
1233 KMMessage* msg = new KMMessage();
1234
1235 // If this is a multipart mail or if the main part is only the text part,
1236 // Make an identical copy of the mail, minus headers, so attachments are
1237 // preserved
1238 if ( type() == DwMime::kTypeMultipart ||
1239 ( type() == DwMime::kTypeText && subtype() == DwMime::kSubtypePlain ) ) {
1240 // ## slow, we could probably use: delete msg->mMsg; msg->mMsg = new DwMessage( this->mMsg );
1241 msg->fromDwString( this->asDwString() );
1242 // remember the type and subtype, initFromMessage sets the contents type to
1243 // text/plain, via initHeader, for unclear reasons
1244 DwMediaType oldContentType = msg->mMsg->Headers().ContentType();
1245
1246 msg->sanitizeHeaders();
1247
1248 // strip blacklisted parts
1249 TQStringList blacklist = GlobalSettings::self()->mimetypesToStripWhenInlineForwarding();
1250 for ( TQStringList::Iterator it = blacklist.begin(); it != blacklist.end(); ++it ) {
1251 TQString entry = (*it);
1252 int sep = entry.find( '/' );
1253 TQCString type = entry.left( sep ).latin1();
1254 TQCString subtype = entry.mid( sep+1 ).latin1();
1255 kdDebug( 5006 ) << "Looking for blacklisted type: " << type << "/" << subtype << endl;
1256 while ( DwBodyPart * part = msg->findDwBodyPart( type, subtype ) ) {
1257 msg->mMsg->Body().RemoveBodyPart( part );
1258 }
1259 }
1260 msg->mMsg->Assemble();
1261 msg->initFromMessage( this );
1262
1263 //restore type
1264 msg->mMsg->Headers().ContentType().FromString( oldContentType.AsString() );
1265 msg->mMsg->Headers().ContentType().Parse();
1266 msg->mMsg->Assemble();
1267 }
1268 else if( type() == DwMime::kTypeText && subtype() == DwMime::kSubtypeHtml ) {
1269 // This is non-multipart html mail. Let`s make it text/plain and allow
1270 // template parser do the hard job.
1271 msg->initFromMessage( this );
1272 msg->setType( DwMime::kTypeText );
1273 msg->setSubtype( DwMime::kSubtypeHtml );
1274 msg->mNeedsAssembly = true;
1275 msg->cleanupHeader();
1276 }
1277 else {
1278 // This is a non-multipart, non-text mail (e.g. text/calendar). Construct
1279 // a multipart/mixed mail and add the original body as an attachment.
1280 msg->initFromMessage( this );
1281 msg->removeHeaderField("Content-Type");
1282 msg->removeHeaderField("Content-Transfer-Encoding");
1283 // Modify the ContentType directly (replaces setAutomaticFields(true))
1284 DwHeaders & header = msg->mMsg->Headers();
1285 header.MimeVersion().FromString("1.0");
1286 DwMediaType & contentType = msg->dwContentType();
1287 contentType.SetType( DwMime::kTypeMultipart );
1288 contentType.SetSubtype( DwMime::kSubtypeMixed );
1289 contentType.CreateBoundary(0);
1290 contentType.Assemble();
1291
1292 // empty text part
1293 KMMessagePart msgPart;
1294 bodyPart( 0, &msgPart );
1295 msg->addBodyPart(&msgPart);
1296 // the old contents of the mail
1297 KMMessagePart secondPart;
1298 secondPart.setType( type() );
1299 secondPart.setSubtype( subtype() );
1300 secondPart.setBody( mMsg->Body().AsString() );
1301 // use the headers of the original mail
1302 applyHeadersToMessagePart( mMsg->Headers(), &secondPart );
1303 msg->addBodyPart(&secondPart);
1304 msg->mNeedsAssembly = true;
1305 msg->cleanupHeader();
1306 }
1307 // TQString st = TQString::fromUtf8(createForwardBody());
1308
1309 msg->setSubject( forwardSubject() );
1310
1311 TemplateParser parser( msg, TemplateParser::Forward );
1312 if ( !tmpl.isEmpty() ) {
1313 parser.process( tmpl, this );
1314 } else {
1315 parser.process( this );
1316 }
1317
1318 // TQCString encoding = autoDetectCharset(charset(), sPrefCharsets, msg->body());
1319 // if (encoding.isEmpty()) encoding = "utf-8";
1320 // msg->setCharset(encoding);
1321
1322 // force utf-8
1323 // msg->setCharset( "utf-8" );
1324
1325 msg->link(this, KMMsgStatusForwarded);
1326 return msg;
1327}
1328
1329static const struct {
1330 const char * dontAskAgainID;
1331 bool canDeny;
1332 const char * text;
1333} mdnMessageBoxes[] = {
1334 { "mdnNormalAsk", true,
1335 I18N_NOOP("This message contains a request to return a notification "
1336 "about your reception of the message.\n"
1337 "You can either ignore the request or let KMail send a "
1338 "\"denied\" or normal response.") },
1339 { "mdnUnknownOption", false,
1340 I18N_NOOP("This message contains a request to send a notification "
1341 "about your reception of the message.\n"
1342 "It contains a processing instruction that is marked as "
1343 "\"required\", but which is unknown to KMail.\n"
1344 "You can either ignore the request or let KMail send a "
1345 "\"failed\" response.") },
1346 { "mdnMultipleAddressesInReceiptTo", true,
1347 I18N_NOOP("This message contains a request to send a notification "
1348 "about your reception of the message,\n"
1349 "but it is requested to send the notification to more "
1350 "than one address.\n"
1351 "You can either ignore the request or let KMail send a "
1352 "\"denied\" or normal response.") },
1353 { "mdnReturnPathEmpty", true,
1354 I18N_NOOP("This message contains a request to send a notification "
1355 "about your reception of the message,\n"
1356 "but there is no return-path set.\n"
1357 "You can either ignore the request or let KMail send a "
1358 "\"denied\" or normal response.") },
1359 { "mdnReturnPathNotInReceiptTo", true,
1360 I18N_NOOP("This message contains a request to send a notification "
1361 "about your reception of the message,\n"
1362 "but the return-path address differs from the address "
1363 "the notification was requested to be sent to.\n"
1364 "You can either ignore the request or let KMail send a "
1365 "\"denied\" or normal response.") },
1366};
1367
1368static const int numMdnMessageBoxes
1369 = sizeof mdnMessageBoxes / sizeof *mdnMessageBoxes;
1370
1371
1372static int requestAdviceOnMDN( const char * what ) {
1373 for ( int i = 0 ; i < numMdnMessageBoxes ; ++i ) {
1374 if ( !qstrcmp( what, mdnMessageBoxes[i].dontAskAgainID ) ) {
1375 if ( mdnMessageBoxes[i].canDeny ) {
1376 const KCursorSaver saver( TQCursor::ArrowCursor );
1377 int answer = TQMessageBox::information( nullptr,
1378 i18n("Message Disposition Notification Request"),
1379 i18n( mdnMessageBoxes[i].text ),
1380 i18n("&Ignore"), i18n("Send \"&denied\""), i18n("&Send") );
1381 return answer ? answer + 1 : 0 ; // map to "mode" in createMDN
1382 } else {
1383 const KCursorSaver saver( TQCursor::ArrowCursor );
1384 int answer = TQMessageBox::information( nullptr,
1385 i18n("Message Disposition Notification Request"),
1386 i18n( mdnMessageBoxes[i].text ),
1387 i18n("&Ignore"), i18n("&Send") );
1388 return answer ? answer + 2 : 0 ; // map to "mode" in createMDN
1389 }
1390 }
1391 }
1392 kdWarning(5006) << "didn't find data for message box \""
1393 << what << "\"" << endl;
1394 return 0;
1395}
1396
1398 MDN::DispositionType d,
1399 bool allowGUI,
1400 TQValueList<MDN::DispositionModifier> m )
1401{
1402 // RFC 2298: At most one MDN may be issued on behalf of each
1403 // particular recipient by their user agent. That is, once an MDN
1404 // has been issued on behalf of a recipient, no further MDNs may be
1405 // issued on behalf of that recipient, even if another disposition
1406 // is performed on the message.
1407//#define MDN_DEBUG 1
1408#ifndef MDN_DEBUG
1409 if ( mdnSentState() != KMMsgMDNStateUnknown &&
1410 mdnSentState() != KMMsgMDNNone )
1411 return nullptr;
1412#else
1413 char st[2]; st[0] = (char)mdnSentState(); st[1] = 0;
1414 kdDebug(5006) << "mdnSentState() == '" << st << "'" << endl;
1415#endif
1416
1417 // RFC 2298: An MDN MUST NOT be generated in response to an MDN.
1418 if ( findDwBodyPart( DwMime::kTypeMessage,
1419 DwMime::kSubtypeDispositionNotification ) ) {
1420 setMDNSentState( KMMsgMDNIgnore );
1421 return nullptr;
1422 }
1423
1424 // extract where to send to:
1425 TQString receiptTo = headerField("Disposition-Notification-To");
1426 if ( receiptTo.stripWhiteSpace().isEmpty() ) return nullptr;
1427 receiptTo.remove( '\n' );
1428
1429
1430 MDN::SendingMode s = MDN::SentAutomatically; // set to manual if asked user
1431 TQString special; // fill in case of error, warning or failure
1432 TDEConfigGroup mdnConfig( KMKernel::config(), "MDN" );
1433
1434 // default:
1435 int mode = mdnConfig.readNumEntry( "default-policy", 0 );
1436 if ( !mode || mode < 0 || mode > 3 ) {
1437 // early out for ignore:
1438 setMDNSentState( KMMsgMDNIgnore );
1439 return nullptr;
1440 }
1441
1442 // RFC 2298: An importance of "required" indicates that
1443 // interpretation of the parameter is necessary for proper
1444 // generation of an MDN in response to this request. If a UA does
1445 // not understand the meaning of the parameter, it MUST NOT generate
1446 // an MDN with any disposition type other than "failed" in response
1447 // to the request.
1448 TQString notificationOptions = headerField("Disposition-Notification-Options");
1449 if ( notificationOptions.contains( "required", false ) ) {
1450 // ### hacky; should parse...
1451 // There is a required option that we don't understand. We need to
1452 // ask the user what we should do:
1453 if ( !allowGUI ) return nullptr; // don't setMDNSentState here!
1454 mode = requestAdviceOnMDN( "mdnUnknownOption" );
1455 s = MDN::SentManually;
1456
1457 special = i18n("Header \"Disposition-Notification-Options\" contained "
1458 "required, but unknown parameter");
1459 d = MDN::Failed;
1460 m.clear(); // clear modifiers
1461 }
1462
1463 // RFC 2298: [ Confirmation from the user SHOULD be obtained (or no
1464 // MDN sent) ] if there is more than one distinct address in the
1465 // Disposition-Notification-To header.
1466 kdDebug(5006) << "KPIM::splitEmailAddrList(receiptTo): "
1467 << KPIM::splitEmailAddrList(receiptTo).join("\n") << endl;
1468 if ( KPIM::splitEmailAddrList(receiptTo).count() > 1 ) {
1469 if ( !allowGUI ) return nullptr; // don't setMDNSentState here!
1470 mode = requestAdviceOnMDN( "mdnMultipleAddressesInReceiptTo" );
1471 s = MDN::SentManually;
1472 }
1473
1474 // RFC 2298: MDNs SHOULD NOT be sent automatically if the address in
1475 // the Disposition-Notification-To header differs from the address
1476 // in the Return-Path header. [...] Confirmation from the user
1477 // SHOULD be obtained (or no MDN sent) if there is no Return-Path
1478 // header in the message [...]
1479 AddrSpecList returnPathList = extractAddrSpecs("Return-Path");
1480 TQString returnPath = returnPathList.isEmpty() ? TQString()
1481 : returnPathList.front().localPart + '@' + returnPathList.front().domain ;
1482 kdDebug(5006) << "clean return path: " << returnPath << endl;
1483 if ( returnPath.isEmpty() || !receiptTo.contains( returnPath, false ) ) {
1484 if ( !allowGUI ) return nullptr; // don't setMDNSentState here!
1485 mode = requestAdviceOnMDN( returnPath.isEmpty() ?
1486 "mdnReturnPathEmpty" :
1487 "mdnReturnPathNotInReceiptTo" );
1488 s = MDN::SentManually;
1489 }
1490
1491 if ( a != KMime::MDN::AutomaticAction ) {
1492 //TODO: only ingore user settings for AutomaticAction if requested
1493 if ( mode == 1 ) { // ask
1494 if ( !allowGUI ) return nullptr; // don't setMDNSentState here!
1495 mode = requestAdviceOnMDN( "mdnNormalAsk" );
1496 s = MDN::SentManually; // asked user
1497 }
1498
1499 switch ( mode ) {
1500 case 0: // ignore:
1501 setMDNSentState( KMMsgMDNIgnore );
1502 return nullptr;
1503 default:
1504 case 1:
1505 kdFatal(5006) << "KMMessage::createMDN(): The \"ask\" mode should "
1506 << "never appear here!" << endl;
1507 break;
1508 case 2: // deny
1509 d = MDN::Denied;
1510 m.clear();
1511 break;
1512 case 3:
1513 break;
1514 }
1515 }
1516
1517
1518 // extract where to send from:
1519 TQString finalRecipient = kmkernel->identityManager()
1520 ->identityForUoidOrDefault( identityUoid() ).fullEmailAddr();
1521
1522 //
1523 // Generate message:
1524 //
1525
1526 KMMessage * receipt = new KMMessage();
1527 receipt->initFromMessage( this );
1528 receipt->removeHeaderField("Content-Type");
1529 receipt->removeHeaderField("Content-Transfer-Encoding");
1530 // Modify the ContentType directly (replaces setAutomaticFields(true))
1531 DwHeaders & header = receipt->mMsg->Headers();
1532 header.MimeVersion().FromString("1.0");
1533 DwMediaType & contentType = receipt->dwContentType();
1534 contentType.SetType( DwMime::kTypeMultipart );
1535 contentType.SetSubtype( DwMime::kSubtypeReport );
1536 contentType.CreateBoundary(0);
1537 receipt->mNeedsAssembly = true;
1538 receipt->setContentTypeParam( "report-type", "disposition-notification" );
1539
1540 TQString description = replaceHeadersInString( MDN::descriptionFor( d, m ) );
1541
1542 // text/plain part:
1543 KMMessagePart firstMsgPart;
1544 firstMsgPart.setTypeStr( "text" );
1545 firstMsgPart.setSubtypeStr( "plain" );
1546 firstMsgPart.setBodyFromUnicode( description );
1547 receipt->addBodyPart( &firstMsgPart );
1548
1549 // message/disposition-notification part:
1550 KMMessagePart secondMsgPart;
1551 secondMsgPart.setType( DwMime::kTypeMessage );
1552 secondMsgPart.setSubtype( DwMime::kSubtypeDispositionNotification );
1553 //secondMsgPart.setCharset( "us-ascii" );
1554 //secondMsgPart.setCteStr( "7bit" );
1555 secondMsgPart.setBodyEncoded( MDN::dispositionNotificationBodyContent(
1556 finalRecipient,
1557 rawHeaderField("Original-Recipient"),
1558 id(), /* Message-ID */
1559 d, a, s, m, special ) );
1560 receipt->addBodyPart( &secondMsgPart );
1561
1562 // message/rfc822 or text/rfc822-headers body part:
1563 int num = mdnConfig.readNumEntry( "quote-message", 0 );
1564 if ( num < 0 || num > 2 ) num = 0;
1565 MDN::ReturnContent returnContent = static_cast<MDN::ReturnContent>( num );
1566
1567 KMMessagePart thirdMsgPart;
1568 switch ( returnContent ) {
1569 case MDN::All:
1570 thirdMsgPart.setTypeStr( "message" );
1571 thirdMsgPart.setSubtypeStr( "rfc822" );
1572 thirdMsgPart.setBody( asSendableString() );
1573 receipt->addBodyPart( &thirdMsgPart );
1574 break;
1575 case MDN::HeadersOnly:
1576 thirdMsgPart.setTypeStr( "text" );
1577 thirdMsgPart.setSubtypeStr( "rfc822-headers" );
1578 thirdMsgPart.setBody( headerAsSendableString() );
1579 receipt->addBodyPart( &thirdMsgPart );
1580 break;
1581 case MDN::Nothing:
1582 default:
1583 break;
1584 };
1585
1586 receipt->setTo( receiptTo );
1587 receipt->setSubject( "Message Disposition Notification" );
1588 receipt->setReplyToId( msgId() );
1589 receipt->setReferences( getRefStr() );
1590
1591 receipt->cleanupHeader();
1592
1593 kdDebug(5006) << "final message:" << endl
1594 << receipt->asString() << endl;
1595
1596 //
1597 // Set "MDN sent" status:
1598 //
1599 KMMsgMDNSentState state = KMMsgMDNStateUnknown;
1600 switch ( d ) {
1601 case MDN::Displayed: state = KMMsgMDNDisplayed; break;
1602 case MDN::Deleted: state = KMMsgMDNDeleted; break;
1603 case MDN::Dispatched: state = KMMsgMDNDispatched; break;
1604 case MDN::Processed: state = KMMsgMDNProcessed; break;
1605 case MDN::Denied: state = KMMsgMDNDenied; break;
1606 case MDN::Failed: state = KMMsgMDNFailed; break;
1607 };
1608 setMDNSentState( state );
1609
1610 return receipt;
1611}
1612
1613TQString KMMessage::replaceHeadersInString( const TQString & s ) const {
1614 TQString result = s;
1615 TQRegExp rx( "\\$\\{([a-z0-9-]+)\\}", false );
1616 Q_ASSERT( rx.isValid() );
1617
1618 TQRegExp rxDate( "\\$\\{date\\}" );
1619 Q_ASSERT( rxDate.isValid() );
1620
1621 TQString sDate = KMime::DateFormatter::formatDate(
1622 KMime::DateFormatter::Localized, date() );
1623
1624 int idx = 0;
1625 if( ( idx = rxDate.search( result, idx ) ) != -1 ) {
1626 result.replace( idx, rxDate.matchedLength(), sDate );
1627 }
1628
1629 idx = 0;
1630 while ( ( idx = rx.search( result, idx ) ) != -1 ) {
1631 TQString replacement = headerField( TQString(rx.cap(1)).latin1() );
1632 result.replace( idx, rx.matchedLength(), replacement );
1633 idx += replacement.length();
1634 }
1635 return result;
1636}
1637
1639{
1640 TQString str, receiptTo;
1641 KMMessage *receipt;
1642
1643 receiptTo = headerField("Disposition-Notification-To");
1644 if ( receiptTo.stripWhiteSpace().isEmpty() ) return nullptr;
1645 receiptTo.remove( '\n' );
1646
1647 receipt = new KMMessage;
1648 receipt->initFromMessage(this);
1649 receipt->setTo(receiptTo);
1650 receipt->setSubject(i18n("Receipt: ") + subject());
1651
1652 str = "Your message was successfully delivered.";
1653 str += "\n\n---------- Message header follows ----------\n";
1654 str += headerAsString();
1655 str += "--------------------------------------------\n";
1656 // Conversion to latin1 is correct here as Mail headers should contain
1657 // ascii only
1658 receipt->setBody(str.latin1());
1659 receipt->setAutomaticFields();
1660
1661 return receipt;
1662}
1663
1664
1666{
1667 const KPIM::Identity & ident =
1668 kmkernel->identityManager()->identityForUoidOrDefault( id );
1669
1670 if(ident.fullEmailAddr().isEmpty())
1671 setFrom("");
1672 else
1673 setFrom(ident.fullEmailAddr());
1674
1675 if(ident.replyToAddr().isEmpty())
1676 setReplyTo("");
1677 else
1678 setReplyTo(ident.replyToAddr());
1679
1680 if(ident.bcc().isEmpty())
1681 setBcc("");
1682 else
1683 setBcc(ident.bcc());
1684
1685 if (ident.organization().isEmpty())
1686 removeHeaderField("Organization");
1687 else
1688 setHeaderField("Organization", ident.organization());
1689
1690 if (ident.isDefault())
1691 removeHeaderField("X-KMail-Identity");
1692 else
1693 setHeaderField("X-KMail-Identity", TQString::number( ident.uoid() ));
1694
1695 if ( ident.transport().isEmpty() )
1696 removeHeaderField( "X-KMail-Transport" );
1697 else
1698 setHeaderField( "X-KMail-Transport", ident.transport() );
1699
1700 if ( ident.fcc().isEmpty() )
1701 setFcc( TQString() );
1702 else
1703 setFcc( ident.fcc() );
1704
1705 if ( ident.drafts().isEmpty() )
1706 setDrafts( TQString() );
1707 else
1708 setDrafts( ident.drafts() );
1709
1710 if ( ident.templates().isEmpty() )
1711 setTemplates( TQString() );
1712 else
1713 setTemplates( ident.templates() );
1714
1715}
1716
1717//-----------------------------------------------------------------------------
1719{
1720 applyIdentity( id );
1721 setTo("");
1722 setSubject("");
1723 setDateToday();
1724
1725 setHeaderField("User-Agent", "KMail/" KMAIL_VERSION );
1726 // This will allow to change Content-Type:
1727 setHeaderField("Content-Type","text/plain");
1728}
1729
1731 TQString idString = headerField("X-KMail-Identity").stripWhiteSpace();
1732 bool ok = false;
1733 int id = idString.toUInt( &ok );
1734
1735 if ( !ok || id == 0 )
1736 id = kmkernel->identityManager()->identityForAddress( to() + ", " + cc() ).uoid();
1737 if ( id == 0 && parent() )
1738 id = parent()->identity();
1739
1740 return id;
1741}
1742
1743
1744//-----------------------------------------------------------------------------
1745void KMMessage::initFromMessage(const KMMessage *msg, bool idHeaders)
1746{
1747 uint id = msg->identityUoid();
1748
1749 if ( idHeaders ) initHeader(id);
1750 else setHeaderField("X-KMail-Identity", TQString::number(id));
1751 if (!msg->headerField("X-KMail-Transport").isEmpty())
1752 setHeaderField("X-KMail-Transport", msg->headerField("X-KMail-Transport"));
1753}
1754
1755
1756//-----------------------------------------------------------------------------
1758{
1759 DwHeaders& header = mMsg->Headers();
1760 DwField* field = header.FirstField();
1761 DwField* nextField;
1762
1763 if (mNeedsAssembly) mMsg->Assemble();
1764 mNeedsAssembly = false;
1765
1766 while (field)
1767 {
1768 nextField = field->Next();
1769 if (field->FieldBody()->AsString().empty())
1770 {
1771 header.RemoveField(field);
1772 mNeedsAssembly = true;
1773 }
1774 field = nextField;
1775 }
1776}
1777
1778
1779//-----------------------------------------------------------------------------
1781{
1782 DwHeaders& header = mMsg->Headers();
1783 header.MimeVersion().FromString("1.0");
1784
1785 if (aIsMulti || numBodyParts() > 1)
1786 {
1787 // Set the type to 'Multipart' and the subtype to 'Mixed'
1788 DwMediaType& contentType = dwContentType();
1789 contentType.SetType( DwMime::kTypeMultipart);
1790 contentType.SetSubtype(DwMime::kSubtypeMixed );
1791
1792 // Create a random printable string and set it as the boundary parameter
1793 contentType.CreateBoundary(0);
1794 }
1795 mNeedsAssembly = true;
1796}
1797
1798
1799//-----------------------------------------------------------------------------
1800TQString KMMessage::dateStr() const
1801{
1802 TDEConfigGroup general( KMKernel::config(), "General" );
1803 DwHeaders& header = mMsg->Headers();
1804 time_t unixTime;
1805
1806 if (!header.HasDate()) return "";
1807 unixTime = header.Date().AsUnixTime();
1808
1809 //kdDebug(5006)<<"#### Date = "<<header.Date().AsString().c_str() << endl;
1810
1811 return KMime::DateFormatter::formatDate(
1812 static_cast<KMime::DateFormatter::FormatType>(general.readNumEntry( "dateFormat", KMime::DateFormatter::Fancy )),
1813 unixTime, general.readEntry( "customDateFormat" ));
1814}
1815
1816
1817//-----------------------------------------------------------------------------
1819{
1820 DwHeaders& header = mMsg->Headers();
1821 time_t unixTime;
1822
1823 if (!header.HasDate()) return "";
1824 unixTime = header.Date().AsUnixTime();
1825
1826 TQCString result = ctime(&unixTime);
1827 int len = result.length();
1828 if (result[len-1]=='\n')
1829 result.truncate(len-1);
1830
1831 return result;
1832}
1833
1834
1835//-----------------------------------------------------------------------------
1836TQString KMMessage::dateIsoStr() const
1837{
1838 DwHeaders& header = mMsg->Headers();
1839 time_t unixTime;
1840
1841 if (!header.HasDate()) return "";
1842 unixTime = header.Date().AsUnixTime();
1843
1844 char cstr[64];
1845 strftime(cstr, 63, "%Y-%m-%d %H:%M:%S", localtime(&unixTime));
1846 return TQString(cstr);
1847}
1848
1849
1850//-----------------------------------------------------------------------------
1851time_t KMMessage::date() const
1852{
1853 time_t res = ( time_t )-1;
1854 DwHeaders& header = mMsg->Headers();
1855 if (header.HasDate())
1856 res = header.Date().AsUnixTime();
1857 return res;
1858}
1859
1860
1861//-----------------------------------------------------------------------------
1863{
1864 struct timeval tval;
1865 gettimeofday(&tval, nullptr);
1866 setDate((time_t)tval.tv_sec);
1867}
1868
1869
1870//-----------------------------------------------------------------------------
1871void KMMessage::setDate(time_t aDate)
1872{
1873 mDate = aDate;
1874 mMsg->Headers().Date().FromCalendarTime(aDate);
1875 mMsg->Headers().Date().Assemble();
1876 mNeedsAssembly = true;
1877 mDirty = true;
1878}
1879
1880
1881//-----------------------------------------------------------------------------
1882void KMMessage::setDate(const TQCString& aStr)
1883{
1884 DwHeaders& header = mMsg->Headers();
1885
1886 header.Date().FromString(aStr);
1887 header.Date().Parse();
1888 mNeedsAssembly = true;
1889 mDirty = true;
1890
1891 if (header.HasDate())
1892 mDate = header.Date().AsUnixTime();
1893}
1894
1895
1896//-----------------------------------------------------------------------------
1897TQString KMMessage::to() const
1898{
1899 // handle To same as Cc below, bug 80747
1900 TQValueList<TQCString> rawHeaders = rawHeaderFields( "To" );
1901 TQStringList headers;
1902 for ( TQValueList<TQCString>::Iterator it = rawHeaders.begin(); it != rawHeaders.end(); ++it ) {
1903 headers << *it;
1904 }
1905 return KPIM::normalizeAddressesAndDecodeIDNs( headers.join( ", " ) );
1906}
1907
1908
1909//-----------------------------------------------------------------------------
1910void KMMessage::setTo(const TQString& aStr)
1911{
1912 setHeaderField( "To", aStr, Address );
1913}
1914
1915//-----------------------------------------------------------------------------
1916TQString KMMessage::toStrip() const
1917{
1918 return stripEmailAddr( to() );
1919}
1920
1921//-----------------------------------------------------------------------------
1922TQString KMMessage::replyTo() const
1923{
1924 return KPIM::normalizeAddressesAndDecodeIDNs( rawHeaderField("Reply-To") );
1925}
1926
1927
1928//-----------------------------------------------------------------------------
1929void KMMessage::setReplyTo(const TQString& aStr)
1930{
1931 setHeaderField( "Reply-To", aStr, Address );
1932}
1933
1934
1935//-----------------------------------------------------------------------------
1936void KMMessage::setReplyTo(KMMessage* aMsg)
1937{
1938 setHeaderField( "Reply-To", aMsg->from(), Address );
1939}
1940
1941
1942//-----------------------------------------------------------------------------
1943TQString KMMessage::cc() const
1944{
1945 // get the combined contents of all Cc headers (as workaround for invalid
1946 // messages with multiple Cc headers)
1947 TQValueList<TQCString> rawHeaders = rawHeaderFields( "Cc" );
1948 TQStringList headers;
1949 for ( TQValueList<TQCString>::Iterator it = rawHeaders.begin(); it != rawHeaders.end(); ++it ) {
1950 headers << *it;
1951 }
1952 return KPIM::normalizeAddressesAndDecodeIDNs( headers.join( ", " ) );
1953}
1954
1955
1956//-----------------------------------------------------------------------------
1957void KMMessage::setCc(const TQString& aStr)
1958{
1959 setHeaderField( "Cc", aStr, Address );
1960}
1961
1962
1963//-----------------------------------------------------------------------------
1964TQString KMMessage::ccStrip() const
1965{
1966 return stripEmailAddr( cc() );
1967}
1968
1969
1970//-----------------------------------------------------------------------------
1971TQString KMMessage::bcc() const
1972{
1973 return KPIM::normalizeAddressesAndDecodeIDNs( rawHeaderField("Bcc") );
1974}
1975
1976
1977//-----------------------------------------------------------------------------
1978void KMMessage::setBcc(const TQString& aStr)
1979{
1980 setHeaderField( "Bcc", aStr, Address );
1981}
1982
1983//-----------------------------------------------------------------------------
1984TQString KMMessage::fcc() const
1985{
1986 return headerField( "X-KMail-Fcc" );
1987}
1988
1989
1990//-----------------------------------------------------------------------------
1991void KMMessage::setFcc( const TQString &aStr )
1992{
1993 setHeaderField( "X-KMail-Fcc", aStr );
1994}
1995
1996//-----------------------------------------------------------------------------
1997void KMMessage::setDrafts( const TQString &aStr )
1998{
1999 mDrafts = aStr;
2000}
2001
2002//-----------------------------------------------------------------------------
2003void KMMessage::setTemplates( const TQString &aStr )
2004{
2005 mTemplates = aStr;
2006}
2007
2008//-----------------------------------------------------------------------------
2009TQString KMMessage::who() const
2010{
2011 if (mParent)
2012 return KPIM::normalizeAddressesAndDecodeIDNs( rawHeaderField(mParent->whoField().utf8()) );
2013 return from();
2014}
2015
2016
2017//-----------------------------------------------------------------------------
2018TQString KMMessage::from() const
2019{
2020 return KPIM::normalizeAddressesAndDecodeIDNs( rawHeaderField("From") );
2021}
2022
2023
2024//-----------------------------------------------------------------------------
2025void KMMessage::setFrom(const TQString& bStr)
2026{
2027 TQString aStr = bStr;
2028 if (aStr.isNull())
2029 aStr = "";
2030 setHeaderField( "From", aStr, Address );
2031 mDirty = true;
2032}
2033
2034
2035//-----------------------------------------------------------------------------
2036TQString KMMessage::fromStrip() const
2037{
2038 return stripEmailAddr( from() );
2039}
2040
2041//-----------------------------------------------------------------------------
2042TQString KMMessage::sender() const {
2043 AddrSpecList asl = extractAddrSpecs( "Sender" );
2044 if ( asl.empty() )
2045 asl = extractAddrSpecs( "From" );
2046 if ( asl.empty() )
2047 return TQString();
2048 return asl.front().asString();
2049}
2050
2051//-----------------------------------------------------------------------------
2052TQString KMMessage::subject() const
2053{
2054 return headerField("Subject");
2055}
2056
2057
2058//-----------------------------------------------------------------------------
2059void KMMessage::setSubject(const TQString& aStr)
2060{
2061 setHeaderField("Subject",aStr);
2062 mDirty = true;
2063}
2064
2065
2066//-----------------------------------------------------------------------------
2067TQString KMMessage::xmark() const
2068{
2069 return headerField("X-KMail-Mark");
2070}
2071
2072
2073//-----------------------------------------------------------------------------
2074void KMMessage::setXMark(const TQString& aStr)
2075{
2076 setHeaderField("X-KMail-Mark", aStr);
2077 mDirty = true;
2078}
2079
2080
2081//-----------------------------------------------------------------------------
2082TQString KMMessage::replyToId() const
2083{
2084 int leftAngle, rightAngle;
2085 TQString replyTo, references;
2086
2087 replyTo = headerField("In-Reply-To");
2088 // search the end of the (first) message id in the In-Reply-To header
2089 rightAngle = replyTo.find( '>' );
2090 if (rightAngle != -1)
2091 replyTo.truncate( rightAngle + 1 );
2092 // now search the start of the message id
2093 leftAngle = replyTo.findRev( '<' );
2094 if (leftAngle != -1)
2095 replyTo = replyTo.mid( leftAngle );
2096
2097 // if we have found a good message id we can return immediately
2098 // We ignore mangled In-Reply-To headers which are created by a
2099 // misconfigured Mutt. They look like this <"from foo"@bar.baz>, i.e.
2100 // they contain double quotes and spaces. We only check for '"'.
2101 if (!replyTo.isEmpty() && (replyTo[0] == '<') &&
2102 ( -1 == replyTo.find( '"' ) ) )
2103 return replyTo;
2104
2105 references = headerField("References");
2106 leftAngle = references.findRev( '<' );
2107 if (leftAngle != -1)
2108 references = references.mid( leftAngle );
2109 rightAngle = references.find( '>' );
2110 if (rightAngle != -1)
2111 references.truncate( rightAngle + 1 );
2112
2113 // if we found a good message id in the References header return it
2114 if (!references.isEmpty() && references[0] == '<')
2115 return references;
2116 // else return the broken message id we found in the In-Reply-To header
2117 else
2118 return replyTo;
2119}
2120
2121
2122//-----------------------------------------------------------------------------
2123TQString KMMessage::replyToIdMD5() const {
2124 return base64EncodedMD5( replyToId() );
2125}
2126
2127//-----------------------------------------------------------------------------
2129{
2130 int leftAngle, rightAngle;
2131 TQString references = headerField( "References" );
2132
2133 // keep the last two entries for threading
2134 leftAngle = references.findRev( '<' );
2135 leftAngle = references.findRev( '<', leftAngle - 1 );
2136 if( leftAngle != -1 )
2137 references = references.mid( leftAngle );
2138 rightAngle = references.findRev( '>' );
2139 if( rightAngle != -1 )
2140 references.truncate( rightAngle + 1 );
2141
2142 if( !references.isEmpty() && references[0] == '<' )
2143 return references;
2144 else
2145 return TQString();
2146}
2147
2148//-----------------------------------------------------------------------------
2150{
2151 TQString result = references();
2152 // references contains two items, use the first one
2153 // (the second to last reference)
2154 const int rightAngle = result.find( '>' );
2155 if( rightAngle != -1 )
2156 result.truncate( rightAngle + 1 );
2157
2158 return base64EncodedMD5( result );
2159}
2160
2161//-----------------------------------------------------------------------------
2163 return base64EncodedMD5( stripOffPrefixes( subject() ), true /*utf8*/ );
2164}
2165
2166//-----------------------------------------------------------------------------
2167TQString KMMessage::subjectMD5() const {
2168 return base64EncodedMD5( subject(), true /*utf8*/ );
2169}
2170
2171//-----------------------------------------------------------------------------
2173 return subjectMD5() != strippedSubjectMD5();
2174}
2175
2176//-----------------------------------------------------------------------------
2177void KMMessage::setReplyToId(const TQString& aStr)
2178{
2179 setHeaderField("In-Reply-To", aStr);
2180 mDirty = true;
2181}
2182
2183
2184//-----------------------------------------------------------------------------
2185TQString KMMessage::msgId() const
2186{
2187 TQString msgId = headerField("Message-Id");
2188
2189 // search the end of the message id
2190 const int rightAngle = msgId.find( '>' );
2191 if (rightAngle != -1)
2192 msgId.truncate( rightAngle + 1 );
2193 // now search the start of the message id
2194 const int leftAngle = msgId.findRev( '<' );
2195 if (leftAngle != -1)
2196 msgId = msgId.mid( leftAngle );
2197 return msgId;
2198}
2199
2200
2201//-----------------------------------------------------------------------------
2202TQString KMMessage::msgIdMD5() const {
2203 return base64EncodedMD5( msgId() );
2204}
2205
2206
2207//-----------------------------------------------------------------------------
2208void KMMessage::setMsgId(const TQString& aStr)
2209{
2210 setHeaderField("Message-Id", aStr);
2211 mDirty = true;
2212}
2213
2214//-----------------------------------------------------------------------------
2216 return headerField( "X-Length" ).toULong();
2217}
2218
2219
2220//-----------------------------------------------------------------------------
2221void KMMessage::setMsgSizeServer(size_t size)
2222{
2223 setHeaderField("X-Length", TQCString().setNum(size));
2224 mDirty = true;
2225}
2226
2227//-----------------------------------------------------------------------------
2228ulong KMMessage::UID() const {
2229 return headerField( "X-UID" ).toULong();
2230}
2231
2232
2233//-----------------------------------------------------------------------------
2234void KMMessage::setUID(ulong uid)
2235{
2236 setHeaderField("X-UID", TQCString().setNum(uid));
2237 mDirty = true;
2238}
2239
2240//-----------------------------------------------------------------------------
2241AddressList KMMessage::splitAddrField( const TQCString & str )
2242{
2243 AddressList result;
2244 const char * scursor = str.begin();
2245 if ( !scursor )
2246 return AddressList();
2247 const char * const send = str.begin() + str.length();
2248 if ( !parseAddressList( scursor, send, result ) )
2249 kdDebug(5006) << "Error in address splitting: parseAddressList returned false!"
2250 << endl;
2251 return result;
2252}
2253
2254AddressList KMMessage::headerAddrField( const TQCString & aName ) const {
2255 return KMMessage::splitAddrField( rawHeaderField( aName ) );
2256}
2257
2258AddrSpecList KMMessage::extractAddrSpecs( const TQCString & header ) const {
2259 AddressList al = headerAddrField( header );
2260 AddrSpecList result;
2261 for ( AddressList::const_iterator ait = al.begin() ; ait != al.end() ; ++ait )
2262 for ( MailboxList::const_iterator mit = (*ait).mailboxList.begin() ; mit != (*ait).mailboxList.end() ; ++mit )
2263 result.push_back( (*mit).addrSpec );
2264 return result;
2265}
2266
2267TQCString KMMessage::rawHeaderField( const TQCString & name ) const {
2268 if ( name.isEmpty() ) return TQCString();
2269
2270 DwHeaders & header = mMsg->Headers();
2271 DwField * field = header.FindField( name );
2272
2273 if ( !field ) return TQCString();
2274
2275 return header.FieldBody( name.data() ).AsString().c_str();
2276}
2277
2278TQValueList<TQCString> KMMessage::rawHeaderFields( const TQCString& field ) const
2279{
2280 if ( field.isEmpty() || !mMsg->Headers().FindField( field ) )
2281 return TQValueList<TQCString>();
2282
2283 std::vector<DwFieldBody*> v = mMsg->Headers().AllFieldBodies( field.data() );
2284 TQValueList<TQCString> headerFields;
2285 for ( uint i = 0; i < v.size(); ++i ) {
2286 headerFields.append( v[i]->AsString().c_str() );
2287 }
2288
2289 return headerFields;
2290}
2291
2292TQString KMMessage::headerField(const TQCString& aName) const
2293{
2294 if ( aName.isEmpty() )
2295 return TQString();
2296
2297 if ( !mMsg->Headers().FindField( aName ) )
2298 return TQString();
2299
2300 return decodeRFC2047String( mMsg->Headers().FieldBody( aName.data() ).AsString().c_str(),
2301 charset() );
2302
2303}
2304
2305TQStringList KMMessage::headerFields( const TQCString& field ) const
2306{
2307 if ( field.isEmpty() || !mMsg->Headers().FindField( field ) )
2308 return TQStringList();
2309
2310 std::vector<DwFieldBody*> v = mMsg->Headers().AllFieldBodies( field.data() );
2311 TQStringList headerFields;
2312 for ( uint i = 0; i < v.size(); ++i ) {
2313 headerFields.append( decodeRFC2047String( v[i]->AsString().c_str(), charset() ) );
2314 }
2315
2316 return headerFields;
2317}
2318
2319//-----------------------------------------------------------------------------
2320void KMMessage::removeHeaderField(const TQCString& aName)
2321{
2322 DwHeaders & header = mMsg->Headers();
2323 DwField * field = header.FindField(aName);
2324 if (!field) return;
2325
2326 header.RemoveField(field);
2327 mNeedsAssembly = true;
2328}
2329
2330//-----------------------------------------------------------------------------
2331void KMMessage::removeHeaderFields(const TQCString& aName)
2332{
2333 DwHeaders & header = mMsg->Headers();
2334 while ( DwField * field = header.FindField(aName) ) {
2335 header.RemoveField(field);
2336 mNeedsAssembly = true;
2337 }
2338}
2339
2340
2341//-----------------------------------------------------------------------------
2342void KMMessage::setHeaderField( const TQCString& aName, const TQString& bValue,
2343 HeaderFieldType type, bool prepend )
2344{
2345#if 0
2346 if ( type != Unstructured )
2347 kdDebug(5006) << "KMMessage::setHeaderField( \"" << aName << "\", \""
2348 << bValue << "\", " << type << " )" << endl;
2349#endif
2350 if (aName.isEmpty()) return;
2351
2352 DwHeaders& header = mMsg->Headers();
2353
2354 DwString str;
2355 DwField* field;
2356 TQCString aValue;
2357 if (!bValue.isEmpty())
2358 {
2359 TQString value = bValue;
2360 if ( type == Address )
2361 value = KPIM::normalizeAddressesAndEncodeIDNs( value );
2362#if 0
2363 if ( type != Unstructured )
2364 kdDebug(5006) << "value: \"" << value << "\"" << endl;
2365#endif
2366 TQCString encoding = autoDetectCharset( charset(), sPrefCharsets, value );
2367 if (encoding.isEmpty())
2368 encoding = "utf-8";
2369 aValue = encodeRFC2047String( value, encoding );
2370#if 0
2371 if ( type != Unstructured )
2372 kdDebug(5006) << "aValue: \"" << aValue << "\"" << endl;
2373#endif
2374 }
2375 str = aName.data();
2376 if (str[str.length()-1] != ':') str += ": ";
2377 else str += ' ';
2378 if ( !aValue.isEmpty() )
2379 str += aValue.data();
2380 if (str[str.length()-1] != '\n') str += '\n';
2381
2382 field = new DwField(str, mMsg);
2383 field->Parse();
2384
2385 if ( prepend )
2386 header.AddFieldAt( 1, field );
2387 else
2388 header.AddOrReplaceField( field );
2389 mNeedsAssembly = true;
2390}
2391
2392
2393//-----------------------------------------------------------------------------
2394TQCString KMMessage::typeStr() const
2395{
2396 DwHeaders& header = mMsg->Headers();
2397 if (header.HasContentType()) return header.ContentType().TypeStr().c_str();
2398 else return "";
2399}
2400
2401
2402//-----------------------------------------------------------------------------
2403int KMMessage::type() const
2404{
2405 DwHeaders& header = mMsg->Headers();
2406 if (header.HasContentType()) return header.ContentType().Type();
2407 else return DwMime::kTypeNull;
2408}
2409
2410
2411//-----------------------------------------------------------------------------
2412void KMMessage::setTypeStr(const TQCString& aStr)
2413{
2414 dwContentType().SetTypeStr(DwString(aStr));
2415 dwContentType().Parse();
2416 mNeedsAssembly = true;
2417}
2418
2419
2420//-----------------------------------------------------------------------------
2421void KMMessage::setType(int aType)
2422{
2423 dwContentType().SetType(aType);
2424 dwContentType().Assemble();
2425 mNeedsAssembly = true;
2426}
2427
2428
2429
2430//-----------------------------------------------------------------------------
2431TQCString KMMessage::subtypeStr() const
2432{
2433 DwHeaders& header = mMsg->Headers();
2434 if (header.HasContentType()) return header.ContentType().SubtypeStr().c_str();
2435 else return "";
2436}
2437
2438
2439//-----------------------------------------------------------------------------
2440int KMMessage::subtype() const
2441{
2442 DwHeaders& header = mMsg->Headers();
2443 if (header.HasContentType()) return header.ContentType().Subtype();
2444 else return DwMime::kSubtypeNull;
2445}
2446
2447
2448//-----------------------------------------------------------------------------
2449void KMMessage::setSubtypeStr(const TQCString& aStr)
2450{
2451 dwContentType().SetSubtypeStr(DwString(aStr));
2452 dwContentType().Parse();
2453 mNeedsAssembly = true;
2454}
2455
2456
2457//-----------------------------------------------------------------------------
2458void KMMessage::setSubtype(int aSubtype)
2459{
2460 dwContentType().SetSubtype(aSubtype);
2461 dwContentType().Assemble();
2462 mNeedsAssembly = true;
2463}
2464
2465
2466//-----------------------------------------------------------------------------
2467void KMMessage::setDwMediaTypeParam( DwMediaType &mType,
2468 const TQCString& attr,
2469 const TQCString& val )
2470{
2471 mType.Parse();
2472 DwParameter *param = mType.FirstParameter();
2473 while(param) {
2474 if (!kasciistricmp(param->Attribute().c_str(), attr))
2475 break;
2476 else
2477 param = param->Next();
2478 }
2479 if (!param){
2480 param = new DwParameter;
2481 param->SetAttribute(DwString( attr ));
2482 mType.AddParameter( param );
2483 }
2484 else
2485 mType.SetModified();
2486 param->SetValue(DwString( val ));
2487 mType.Assemble();
2488}
2489
2490
2491//-----------------------------------------------------------------------------
2492void KMMessage::setContentTypeParam(const TQCString& attr, const TQCString& val)
2493{
2494 if (mNeedsAssembly) mMsg->Assemble();
2495 mNeedsAssembly = false;
2496 setDwMediaTypeParam( dwContentType(), attr, val );
2497 mNeedsAssembly = true;
2498}
2499
2500
2501//-----------------------------------------------------------------------------
2503{
2504 DwHeaders& header = mMsg->Headers();
2505 if (header.HasContentTransferEncoding())
2506 return header.ContentTransferEncoding().AsString().c_str();
2507 else return "";
2508}
2509
2510
2511//-----------------------------------------------------------------------------
2512int KMMessage::contentTransferEncoding( DwEntity *entity ) const
2513{
2514 if ( !entity )
2515 entity = mMsg;
2516
2517 DwHeaders& header = entity->Headers();
2518 if ( header.HasContentTransferEncoding() )
2519 return header.ContentTransferEncoding().AsEnum();
2520 else return DwMime::kCteNull;
2521}
2522
2523
2524//-----------------------------------------------------------------------------
2525void KMMessage::setContentTransferEncodingStr( const TQCString& cteString,
2526 DwEntity *entity )
2527{
2528 if ( !entity )
2529 entity = mMsg;
2530
2531 entity->Headers().ContentTransferEncoding().FromString( cteString );
2532 entity->Headers().ContentTransferEncoding().Parse();
2533 mNeedsAssembly = true;
2534}
2535
2536
2537//-----------------------------------------------------------------------------
2538void KMMessage::setContentTransferEncoding( int cte, DwEntity *entity )
2539{
2540 if ( !entity )
2541 entity = mMsg;
2542
2543 entity->Headers().ContentTransferEncoding().FromEnum( cte );
2544 mNeedsAssembly = true;
2545}
2546
2547
2548//-----------------------------------------------------------------------------
2549DwHeaders& KMMessage::headers() const
2550{
2551 return mMsg->Headers();
2552}
2553
2554
2555//-----------------------------------------------------------------------------
2557{
2558 mNeedsAssembly = true;
2559}
2560
2561//-----------------------------------------------------------------------------
2563{
2564 Q_ASSERT( mMsg );
2565
2566 if ( mNeedsAssembly ) {
2567 mMsg->Assemble();
2568 mNeedsAssembly = false;
2569 }
2570}
2571
2572//-----------------------------------------------------------------------------
2573TQCString KMMessage::body() const
2574{
2575 const DwString& body = mMsg->Body().AsString();
2576 TQCString str = KMail::Util::CString( body );
2577 // Calls length() -> slow
2578 //kdWarning( str.length() != body.length(), 5006 )
2579 // << "KMMessage::body(): body is binary but used as text!" << endl;
2580 return str;
2581}
2582
2583
2584//-----------------------------------------------------------------------------
2585TQByteArray KMMessage::bodyDecodedBinary() const
2586{
2587 DwString dwstr;
2588 const DwString& dwsrc = mMsg->Body().AsString();
2589
2590 switch (cte())
2591 {
2592 case DwMime::kCteBase64:
2593 DwDecodeBase64(dwsrc, dwstr);
2594 break;
2595 case DwMime::kCteQuotedPrintable:
2596 DwDecodeQuotedPrintable(dwsrc, dwstr);
2597 break;
2598 default:
2599 dwstr = dwsrc;
2600 break;
2601 }
2602
2603 int len = dwstr.size();
2604 TQByteArray ba(len);
2605 memcpy(ba.data(),dwstr.data(),len);
2606 return ba;
2607}
2608
2609
2610//-----------------------------------------------------------------------------
2611TQCString KMMessage::bodyDecoded() const
2612{
2613 DwString dwstr;
2614 DwString dwsrc = mMsg->Body().AsString();
2615
2616 switch (cte())
2617 {
2618 case DwMime::kCteBase64:
2619 DwDecodeBase64(dwsrc, dwstr);
2620 break;
2621 case DwMime::kCteQuotedPrintable:
2622 DwDecodeQuotedPrintable(dwsrc, dwstr);
2623 break;
2624 default:
2625 dwstr = dwsrc;
2626 break;
2627 }
2628
2629 return KMail::Util::CString( dwstr );
2630
2631 // Calling TQCString::length() is slow
2632 //TQCString result = KMail::Util::CString( dwstr );
2633 //kdWarning(result.length() != len, 5006)
2634 // << "KMMessage::bodyDecoded(): body is binary but used as text!" << endl;
2635 //return result;
2636}
2637
2638
2639//-----------------------------------------------------------------------------
2640TQValueList<int> KMMessage::determineAllowedCtes( const CharFreq& cf,
2641 bool allow8Bit,
2642 bool willBeSigned )
2643{
2644 TQValueList<int> allowedCtes;
2645
2646 switch ( cf.type() ) {
2647 case CharFreq::SevenBitText:
2648 allowedCtes << DwMime::kCte7bit;
2649 case CharFreq::EightBitText:
2650 if ( allow8Bit )
2651 allowedCtes << DwMime::kCte8bit;
2652 case CharFreq::SevenBitData:
2653 if ( cf.printableRatio() > 5.0/6.0 ) {
2654 // let n the length of data and p the number of printable chars.
2655 // Then base64 \approx 4n/3; qp \approx p + 3(n-p)
2656 // => qp < base64 iff p > 5n/6.
2657 allowedCtes << DwMime::kCteQp;
2658 allowedCtes << DwMime::kCteBase64;
2659 } else {
2660 allowedCtes << DwMime::kCteBase64;
2661 allowedCtes << DwMime::kCteQp;
2662 }
2663 break;
2664 case CharFreq::EightBitData:
2665 allowedCtes << DwMime::kCteBase64;
2666 break;
2667 case CharFreq::None:
2668 default:
2669 // just nothing (avoid compiler warning)
2670 ;
2671 }
2672
2673 // In the following cases only QP and Base64 are allowed:
2674 // - the buffer will be OpenPGP/MIME signed and it contains trailing
2675 // whitespace (cf. RFC 3156)
2676 // - a line starts with "From "
2677 if ( ( willBeSigned && cf.hasTrailingWhitespace() ) ||
2678 cf.hasLeadingFrom() ) {
2679 allowedCtes.remove( DwMime::kCte8bit );
2680 allowedCtes.remove( DwMime::kCte7bit );
2681 }
2682
2683 return allowedCtes;
2684}
2685
2686
2687//-----------------------------------------------------------------------------
2688void KMMessage::setBodyAndGuessCte( const TQByteArray& aBuf,
2689 TQValueList<int> & allowedCte,
2690 bool allow8Bit,
2691 bool willBeSigned,
2692 DwEntity *entity )
2693{
2694 if ( !entity )
2695 entity = mMsg;
2696
2697 CharFreq cf( aBuf ); // it's safe to pass null arrays
2698 allowedCte = determineAllowedCtes( cf, allow8Bit, willBeSigned );
2699 setCte( allowedCte[0], entity ); // choose best fitting
2700 setBodyEncodedBinary( aBuf, entity );
2701}
2702
2703
2704//-----------------------------------------------------------------------------
2705void KMMessage::setBodyAndGuessCte( const TQCString& aBuf,
2706 TQValueList<int> & allowedCte,
2707 bool allow8Bit,
2708 bool willBeSigned,
2709 DwEntity *entity )
2710{
2711 if ( !entity )
2712 entity = mMsg;
2713
2714 CharFreq cf( aBuf.data(), aBuf.size()-1 ); // it's safe to pass null strings
2715 allowedCte = determineAllowedCtes( cf, allow8Bit, willBeSigned );
2716 setCte( allowedCte[0], entity ); // choose best fitting
2717 setBodyEncoded( aBuf, entity );
2718}
2719
2720
2721//-----------------------------------------------------------------------------
2722void KMMessage::setBodyEncoded(const TQCString& aStr, DwEntity *entity )
2723{
2724 if ( !entity )
2725 entity = mMsg;
2726
2727 DwString dwSrc(aStr.data(), aStr.size()-1 /* not the trailing NUL */);
2728 DwString dwResult;
2729
2730 switch (cte( entity ))
2731 {
2732 case DwMime::kCteBase64:
2733 DwEncodeBase64(dwSrc, dwResult);
2734 break;
2735 case DwMime::kCteQuotedPrintable:
2736 DwEncodeQuotedPrintable(dwSrc, dwResult);
2737 break;
2738 default:
2739 dwResult = dwSrc;
2740 break;
2741 }
2742
2743 entity->Body().FromString(dwResult);
2744 mNeedsAssembly = true;
2745}
2746
2747//-----------------------------------------------------------------------------
2748void KMMessage::setBodyEncodedBinary( const TQByteArray& aStr, DwEntity *entity )
2749{
2750 if ( !entity )
2751 entity = mMsg;
2752
2753 DwString dwSrc(aStr.data(), aStr.size());
2754 DwString dwResult;
2755
2756 switch ( cte( entity ) )
2757 {
2758 case DwMime::kCteBase64:
2759 DwEncodeBase64( dwSrc, dwResult );
2760 break;
2761 case DwMime::kCteQuotedPrintable:
2762 DwEncodeQuotedPrintable( dwSrc, dwResult );
2763 break;
2764 default:
2765 dwResult = dwSrc;
2766 break;
2767 }
2768
2769 entity->Body().FromString( dwResult );
2770 entity->Body().Parse();
2771
2772 mNeedsAssembly = true;
2773}
2774
2775
2776//-----------------------------------------------------------------------------
2777void KMMessage::setBody(const TQCString& aStr)
2778{
2779 mMsg->Body().FromString(KMail::Util::dwString(aStr));
2780 mNeedsAssembly = true;
2781}
2782void KMMessage::setBody(const DwString& aStr)
2783{
2784 mMsg->Body().FromString(aStr);
2785 mNeedsAssembly = true;
2786}
2787void KMMessage::setBody(const char* aStr)
2788{
2789 mMsg->Body().FromString(aStr);
2790 mNeedsAssembly = true;
2791}
2792
2793//-----------------------------------------------------------------------------
2794void KMMessage::setMultiPartBody( const TQCString & aStr ) {
2795 setBody( aStr );
2796 mMsg->Body().Parse();
2797 mNeedsAssembly = true;
2798}
2799
2800
2801// Patched by Daniel Moisset <dmoisset@grulic.org.ar>
2802// modified numbodyparts, bodypart to take nested body parts as
2803// a linear sequence.
2804// third revision, Sep 26 2000
2805
2806// this is support structure for traversing tree without recursion
2807
2808//-----------------------------------------------------------------------------
2810{
2811 int count = 0;
2812 DwBodyPart* part = getFirstDwBodyPart();
2813 TQPtrList< DwBodyPart > parts;
2814
2815 while (part)
2816 {
2817 //dive into multipart messages
2818 while ( part
2819 && part->hasHeaders()
2820 && part->Headers().HasContentType()
2821 && part->Body().FirstBodyPart()
2822 && (DwMime::kTypeMultipart == part->Headers().ContentType().Type()) )
2823 {
2824 parts.append( part );
2825 part = part->Body().FirstBodyPart();
2826 }
2827 // this is where currPart->msgPart contains a leaf message part
2828 count++;
2829 // go up in the tree until reaching a node with next
2830 // (or the last top-level node)
2831 while (part && !(part->Next()) && !(parts.isEmpty()))
2832 {
2833 part = parts.getLast();
2834 parts.removeLast();
2835 }
2836
2837 if (part && part->Body().Message() &&
2838 part->Body().Message()->Body().FirstBodyPart())
2839 {
2840 part = part->Body().Message()->Body().FirstBodyPart();
2841 } else if (part) {
2842 part = part->Next();
2843 }
2844 }
2845
2846 return count;
2847}
2848
2849
2850//-----------------------------------------------------------------------------
2852{
2853 return mMsg->Body().FirstBodyPart();
2854}
2855
2856
2857//-----------------------------------------------------------------------------
2858int KMMessage::partNumber( DwBodyPart * aDwBodyPart ) const
2859{
2860 DwBodyPart *curpart;
2861 TQPtrList< DwBodyPart > parts;
2862 int curIdx = 0;
2863 int idx = 0;
2864 // Get the DwBodyPart for this index
2865
2866 curpart = getFirstDwBodyPart();
2867
2868 while (curpart && !idx) {
2869 //dive into multipart messages
2870 while( curpart
2871 && curpart->hasHeaders()
2872 && curpart->Headers().HasContentType()
2873 && curpart->Body().FirstBodyPart()
2874 && (DwMime::kTypeMultipart == curpart->Headers().ContentType().Type()) )
2875 {
2876 parts.append( curpart );
2877 curpart = curpart->Body().FirstBodyPart();
2878 }
2879 // this is where currPart->msgPart contains a leaf message part
2880 if (curpart == aDwBodyPart)
2881 idx = curIdx;
2882 curIdx++;
2883 // go up in the tree until reaching a node with next
2884 // (or the last top-level node)
2885 while (curpart && !(curpart->Next()) && !(parts.isEmpty()))
2886 {
2887 curpart = parts.getLast();
2888 parts.removeLast();
2889 } ;
2890 if (curpart)
2891 curpart = curpart->Next();
2892 }
2893 return idx;
2894}
2895
2896
2897//-----------------------------------------------------------------------------
2898DwBodyPart * KMMessage::dwBodyPart( int aIdx ) const
2899{
2900 DwBodyPart *part, *curpart;
2901 TQPtrList< DwBodyPart > parts;
2902 int curIdx = 0;
2903 // Get the DwBodyPart for this index
2904
2905 curpart = getFirstDwBodyPart();
2906 part = nullptr;
2907
2908 while (curpart && !part) {
2909 //dive into multipart messages
2910 while( curpart
2911 && curpart->hasHeaders()
2912 && curpart->Headers().HasContentType()
2913 && curpart->Body().FirstBodyPart()
2914 && (DwMime::kTypeMultipart == curpart->Headers().ContentType().Type()) )
2915 {
2916 parts.append( curpart );
2917 curpart = curpart->Body().FirstBodyPart();
2918 }
2919 // this is where currPart->msgPart contains a leaf message part
2920 if (curIdx==aIdx)
2921 part = curpart;
2922 curIdx++;
2923 // go up in the tree until reaching a node with next
2924 // (or the last top-level node)
2925 while (curpart && !(curpart->Next()) && !(parts.isEmpty()))
2926 {
2927 curpart = parts.getLast();
2928 parts.removeLast();
2929 }
2930 if (curpart)
2931 curpart = curpart->Next();
2932 }
2933 return part;
2934}
2935
2936
2937//-----------------------------------------------------------------------------
2938DwBodyPart * KMMessage::findDwBodyPart( int type, int subtype ) const
2939{
2940 DwBodyPart *part, *curpart;
2941 TQPtrList< DwBodyPart > parts;
2942 // Get the DwBodyPart for this index
2943
2944 curpart = getFirstDwBodyPart();
2945 part = nullptr;
2946
2947 while (curpart && !part) {
2948 //dive into multipart messages
2949 while(curpart
2950 && curpart->hasHeaders()
2951 && curpart->Headers().HasContentType()
2952 && curpart->Body().FirstBodyPart()
2953 && (DwMime::kTypeMultipart == curpart->Headers().ContentType().Type()) ) {
2954 parts.append( curpart );
2955 curpart = curpart->Body().FirstBodyPart();
2956 }
2957 // this is where curPart->msgPart contains a leaf message part
2958
2959 // pending(khz): Find out WHY this look does not travel down *into* an
2960 // embedded "Message/RfF822" message containing a "Multipart/Mixed"
2961 if ( curpart && curpart->hasHeaders() && curpart->Headers().HasContentType() ) {
2962 kdDebug(5006) << curpart->Headers().ContentType().TypeStr().c_str()
2963 << " " << curpart->Headers().ContentType().SubtypeStr().c_str() << endl;
2964 }
2965
2966 if (curpart &&
2967 curpart->hasHeaders() &&
2968 curpart->Headers().HasContentType() &&
2969 curpart->Headers().ContentType().Type() == type &&
2970 curpart->Headers().ContentType().Subtype() == subtype) {
2971 part = curpart;
2972 } else {
2973 // go up in the tree until reaching a node with next
2974 // (or the last top-level node)
2975 while (curpart && !(curpart->Next()) && !(parts.isEmpty())) {
2976 curpart = parts.getLast();
2977 parts.removeLast();
2978 } ;
2979 if (curpart)
2980 curpart = curpart->Next();
2981 }
2982 }
2983 return part;
2984}
2985
2986//-----------------------------------------------------------------------------
2987DwBodyPart * KMMessage::findDwBodyPart( const TQCString& type, const TQCString& subtype ) const
2988{
2989 DwBodyPart *part, *curpart;
2990 TQPtrList< DwBodyPart > parts;
2991 // Get the DwBodyPart for this index
2992
2993 curpart = getFirstDwBodyPart();
2994 part = nullptr;
2995
2996 while (curpart && !part) {
2997 //dive into multipart messages
2998 while(curpart
2999 && curpart->hasHeaders()
3000 && curpart->Headers().HasContentType()
3001 && curpart->Body().FirstBodyPart()
3002 && (DwMime::kTypeMultipart == curpart->Headers().ContentType().Type()) ) {
3003 parts.append( curpart );
3004 curpart = curpart->Body().FirstBodyPart();
3005 }
3006 // this is where curPart->msgPart contains a leaf message part
3007
3008 // pending(khz): Find out WHY this look does not travel down *into* an
3009 // embedded "Message/RfF822" message containing a "Multipart/Mixed"
3010 if (curpart && curpart->hasHeaders() && curpart->Headers().HasContentType() ) {
3011 kdDebug(5006) << curpart->Headers().ContentType().TypeStr().c_str()
3012 << " " << curpart->Headers().ContentType().SubtypeStr().c_str() << endl;
3013 }
3014
3015 if (curpart &&
3016 curpart->hasHeaders() &&
3017 curpart->Headers().HasContentType() &&
3018 curpart->Headers().ContentType().TypeStr().c_str() == type &&
3019 curpart->Headers().ContentType().SubtypeStr().c_str() == subtype) {
3020 part = curpart;
3021 } else {
3022 // go up in the tree until reaching a node with next
3023 // (or the last top-level node)
3024 while (curpart && !(curpart->Next()) && !(parts.isEmpty())) {
3025 curpart = parts.getLast();
3026 parts.removeLast();
3027 } ;
3028 if (curpart)
3029 curpart = curpart->Next();
3030 }
3031 }
3032 return part;
3033}
3034
3035
3036void applyHeadersToMessagePart( DwHeaders& headers, KMMessagePart* aPart )
3037{
3038 // TODO: Instead of manually implementing RFC2231 header encoding (i.e.
3039 // possibly multiple values given as paramname*0=..; parmaname*1=..;...
3040 // or par as paramname*0*=..; parmaname*1*=..;..., which should be
3041 // concatenated), use a generic method to decode the header, using RFC
3042 // 2047 or 2231, or whatever future RFC might be appropriate!
3043 // Right now, some fields are decoded, while others are not. E.g.
3044 // Content-Disposition is not decoded here, rather only on demand in
3045 // KMMsgPart::fileName; Name however is decoded here and stored as a
3046 // decoded String in KMMsgPart...
3047 // Content-type
3048 TQCString additionalCTypeParams;
3049 if (headers.HasContentType())
3050 {
3051 DwMediaType& ct = headers.ContentType();
3052 aPart->setOriginalContentTypeStr( ct.AsString().c_str() );
3053 aPart->setTypeStr(ct.TypeStr().c_str());
3054 aPart->setSubtypeStr(ct.SubtypeStr().c_str());
3055 DwParameter *param = ct.FirstParameter();
3056 while(param)
3057 {
3058 if (!tqstricmp(param->Attribute().c_str(), "charset")) {
3059 if (aPart->type() == DwMime::kTypeText) {
3060 aPart->setCharset(TQCString(param->Value().c_str()).lower());
3061 }
3062 }
3063 else if (!tqstrnicmp(param->Attribute().c_str(), "name*", 5))
3064 aPart->setName(KMMsgBase::decodeRFC2231String(KMMsgBase::extractRFC2231HeaderField( param->Value().c_str(), "name" )));
3065 else {
3066 additionalCTypeParams += ';';
3067 additionalCTypeParams += param->AsString().c_str();
3068 }
3069 param=param->Next();
3070 }
3071 }
3072 else
3073 {
3074 aPart->setTypeStr("text"); // Set to defaults
3075 aPart->setSubtypeStr("plain");
3076 }
3077 aPart->setAdditionalCTypeParamStr( additionalCTypeParams );
3078 // Modification by Markus
3079 if (aPart->name().isEmpty())
3080 {
3081 if (headers.HasContentType() && !headers.ContentType().Name().empty()) {
3082 aPart->setName(KMMsgBase::decodeRFC2047String(headers.
3083 ContentType().Name().c_str()) );
3084 } else if (headers.HasSubject() && !headers.Subject().AsString().empty()) {
3085 aPart->setName( KMMsgBase::decodeRFC2047String(headers.
3086 Subject().AsString().c_str()) );
3087 }
3088 }
3089
3090 // Content-transfer-encoding
3091 if (headers.HasContentTransferEncoding())
3092 aPart->setCteStr(headers.ContentTransferEncoding().AsString().c_str());
3093 else
3094 aPart->setCteStr("7bit");
3095
3096 // Content-description
3097 if (headers.HasContentDescription())
3098 aPart->setContentDescription( KMMsgBase::decodeRFC2047String(
3099 headers.ContentDescription().AsString().c_str() ) );
3100 else
3101 aPart->setContentDescription("");
3102
3103 // Content-disposition
3104 if (headers.HasContentDisposition())
3105 aPart->setContentDisposition(headers.ContentDisposition().AsString().c_str());
3106 else
3107 aPart->setContentDisposition("");
3108}
3109
3110//-----------------------------------------------------------------------------
3111void KMMessage::bodyPart(DwBodyPart* aDwBodyPart, KMMessagePart* aPart,
3112 bool withBody)
3113{
3114 if ( !aPart )
3115 return;
3116
3117 aPart->clear();
3118
3119 if( aDwBodyPart && aDwBodyPart->hasHeaders() ) {
3120 // This must not be an empty string, because we'll get a
3121 // spurious empty Subject: line in some of the parts.
3122 //aPart->setName(" ");
3123 // partSpecifier
3124 TQString partId( aDwBodyPart->partId() );
3125 aPart->setPartSpecifier( partId );
3126
3127 DwHeaders& headers = aDwBodyPart->Headers();
3128 applyHeadersToMessagePart( headers, aPart );
3129
3130 // Body
3131 if (withBody)
3132 aPart->setBody( aDwBodyPart->Body().AsString() );
3133 else
3134 aPart->setBody( TQCString("") );
3135
3136 // Content-id
3137 if ( headers.HasContentId() ) {
3138 const TQCString contentId = headers.ContentId().AsString().c_str();
3139 // ignore leading '<' and trailing '>'
3140 aPart->setContentId( contentId.mid( 1, contentId.length() - 2 ) );
3141 }
3142 }
3143 // If no valid body part was given,
3144 // set all MultipartBodyPart attributes to empty values.
3145 else
3146 {
3147 aPart->setTypeStr("");
3148 aPart->setSubtypeStr("");
3149 aPart->setCteStr("");
3150 // This must not be an empty string, because we'll get a
3151 // spurious empty Subject: line in some of the parts.
3152 //aPart->setName(" ");
3153 aPart->setContentDescription("");
3154 aPart->setContentDisposition("");
3155 aPart->setBody(TQCString(""));
3156 aPart->setContentId("");
3157 }
3158}
3159
3160
3161//-----------------------------------------------------------------------------
3162void KMMessage::bodyPart(int aIdx, KMMessagePart* aPart) const
3163{
3164 if ( !aPart )
3165 return;
3166
3167 // If the DwBodyPart was found get the header fields and body
3168 if ( DwBodyPart *part = dwBodyPart( aIdx ) ) {
3169 KMMessage::bodyPart(part, aPart);
3170 if( aPart->name().isEmpty() )
3171 aPart->setName( i18n("Attachment: %1").arg( aIdx ) );
3172 }
3173}
3174
3175
3176//-----------------------------------------------------------------------------
3178{
3179 mMsg->Body().DeleteBodyParts();
3180}
3181
3182//-----------------------------------------------------------------------------
3183
3184bool KMMessage::deleteBodyPart( int partIndex )
3185{
3186 KMMessagePart part;
3187 DwBodyPart *dwpart = findPart( partIndex );
3188 if ( !dwpart )
3189 return false;
3190 KMMessage::bodyPart( dwpart, &part, true );
3191 if ( !part.isComplete() )
3192 return false;
3193
3194 DwBody *parentNode = dynamic_cast<DwBody*>( dwpart->Parent() );
3195 if ( !parentNode )
3196 return false;
3197 parentNode->RemoveBodyPart( dwpart );
3198
3199 // add dummy part to show that a attachment has been deleted
3200 KMMessagePart dummyPart;
3201 dummyPart.duplicate( part );
3202 TQString comment = i18n("This attachment has been deleted.");
3203 if ( !part.fileName().isEmpty() )
3204 comment = i18n( "The attachment '%1' has been deleted." ).arg( part.fileName() );
3205 dummyPart.setContentDescription( comment );
3206 dummyPart.setBodyEncodedBinary( TQByteArray() );
3207 TQCString cd = dummyPart.contentDisposition();
3208 if ( cd.find( "inline", 0, false ) == 0 ) {
3209 cd.replace( 0, 10, "attachment" );
3210 dummyPart.setContentDisposition( cd );
3211 } else if ( cd.isEmpty() ) {
3212 dummyPart.setContentDisposition( "attachment" );
3213 }
3214 DwBodyPart* newDwPart = createDWBodyPart( &dummyPart );
3215 parentNode->AddBodyPart( newDwPart );
3216 getTopLevelPart()->Assemble();
3217 return true;
3218}
3219
3220//-----------------------------------------------------------------------------
3221DwBodyPart* KMMessage::createDWBodyPart(const KMMessagePart* aPart)
3222{
3223 DwBodyPart* part = DwBodyPart::NewBodyPart(emptyString, nullptr);
3224
3225 if ( !aPart )
3226 return part;
3227
3228 TQCString charset = aPart->charset();
3229 TQCString type = aPart->typeStr();
3230 TQCString subtype = aPart->subtypeStr();
3231 TQCString cte = aPart->cteStr();
3232 TQCString contDesc = aPart->contentDescriptionEncoded();
3233 TQCString contDisp = aPart->contentDisposition();
3234 TQCString name = KMMsgBase::encodeRFC2231StringAutoDetectCharset( aPart->name(), charset );
3235 bool RFC2231encoded = aPart->name() != TQString(name);
3236 TQCString paramAttr = aPart->parameterAttribute();
3237
3238 DwHeaders& headers = part->Headers();
3239
3240 DwMediaType& ct = headers.ContentType();
3241 if (!type.isEmpty() && !subtype.isEmpty())
3242 {
3243 ct.SetTypeStr(type.data());
3244 ct.SetSubtypeStr(subtype.data());
3245 if (!charset.isEmpty()){
3246 DwParameter *param;
3247 param=new DwParameter;
3248 param->SetAttribute("charset");
3249 param->SetValue(charset.data());
3250 ct.AddParameter(param);
3251 }
3252 }
3253
3254 TQCString additionalParam = aPart->additionalCTypeParamStr();
3255 if( !additionalParam.isEmpty() )
3256 {
3257 TQCString parAV;
3258 DwString parA, parV;
3259 int iL, i1, i2, iM;
3260 iL = additionalParam.length();
3261 i1 = 0;
3262 i2 = additionalParam.find(';', i1, false);
3263 while ( i1 < iL )
3264 {
3265 if( -1 == i2 )
3266 i2 = iL;
3267 if( i1+1 < i2 ) {
3268 parAV = additionalParam.mid( i1, (i2-i1) );
3269 iM = parAV.find('=');
3270 if( -1 < iM )
3271 {
3272 parA = parAV.left( iM ).data();
3273 parV = parAV.right( parAV.length() - iM - 1 ).data();
3274 if( ('"' == parV.at(0)) && ('"' == parV.at(parV.length()-1)) )
3275 {
3276 parV.erase( 0, 1);
3277 parV.erase( parV.length()-1 );
3278 }
3279 }
3280 else
3281 {
3282 parA = parAV.data();
3283 parV = "";
3284 }
3285 DwParameter *param;
3286 param = new DwParameter;
3287 param->SetAttribute( parA );
3288 param->SetValue( parV );
3289 ct.AddParameter( param );
3290 }
3291 i1 = i2+1;
3292 i2 = additionalParam.find(';', i1, false);
3293 }
3294 }
3295
3296 if ( !name.isEmpty() ) {
3297 if (RFC2231encoded)
3298 {
3299 DwParameter *nameParam;
3300 nameParam = new DwParameter;
3301 nameParam->SetAttribute("name*");
3302 nameParam->SetValue(name.data(),true);
3303 ct.AddParameter(nameParam);
3304 } else {
3305 ct.SetName(name.data());
3306 }
3307 }
3308
3309 if (!paramAttr.isEmpty())
3310 {
3311 TQCString paramValue;
3312 paramValue = KMMsgBase::encodeRFC2231StringAutoDetectCharset( aPart->parameterValue(), charset );
3313 DwParameter *param = new DwParameter;
3314 if (aPart->parameterValue() != TQString(paramValue))
3315 {
3316 param->SetAttribute((paramAttr + '*').data());
3317 param->SetValue(paramValue.data(),true);
3318 } else {
3319 param->SetAttribute(paramAttr.data());
3320 param->SetValue(paramValue.data());
3321 }
3322 ct.AddParameter(param);
3323 }
3324
3325 if (!cte.isEmpty())
3326 headers.Cte().FromString(cte);
3327
3328 if (!contDesc.isEmpty())
3329 headers.ContentDescription().FromString(contDesc);
3330
3331 if (!contDisp.isEmpty())
3332 headers.ContentDisposition().FromString(contDisp);
3333
3334 const DwString bodyStr = aPart->dwBody();
3335 if (!bodyStr.empty())
3336 part->Body().FromString(bodyStr);
3337 else
3338 part->Body().FromString("");
3339
3340 if (!aPart->partSpecifier().isNull())
3341 part->SetPartId( aPart->partSpecifier().latin1() );
3342
3343 if (aPart->decodedSize() > 0)
3344 part->SetBodySize( aPart->decodedSize() );
3345
3346 return part;
3347}
3348
3349
3350//-----------------------------------------------------------------------------
3351void KMMessage::addDwBodyPart(DwBodyPart * aDwPart)
3352{
3353 mMsg->Body().AddBodyPart( aDwPart );
3354 mNeedsAssembly = true;
3355}
3356
3357
3358//-----------------------------------------------------------------------------
3359void KMMessage::addBodyPart(const KMMessagePart* aPart)
3360{
3361 DwBodyPart* part = createDWBodyPart( aPart );
3362 addDwBodyPart( part );
3363}
3364
3365
3366//-----------------------------------------------------------------------------
3367TQString KMMessage::generateMessageId( const TQString& addr )
3368{
3369 TQDateTime datetime = TQDateTime::currentDateTime();
3370 TQString msgIdStr;
3371
3372 msgIdStr = '<' + datetime.toString( "yyyyMMddhhmm.sszzz" );
3373
3374 TQString msgIdSuffix;
3375 TDEConfigGroup general( KMKernel::config(), "General" );
3376
3377 if( general.readBoolEntry( "useCustomMessageIdSuffix", false ) )
3378 msgIdSuffix = general.readEntry( "myMessageIdSuffix" );
3379
3380 if( !msgIdSuffix.isEmpty() )
3381 msgIdStr += '@' + msgIdSuffix;
3382 else
3383 msgIdStr += '.' + KPIM::encodeIDN( addr );
3384
3385 msgIdStr += '>';
3386
3387 return msgIdStr;
3388}
3389
3390
3391//-----------------------------------------------------------------------------
3392TQCString KMMessage::html2source( const TQCString & src )
3393{
3394 TQCString result( 1 + 6*(src.size()-1) ); // maximal possible length
3395
3396 TQCString::ConstIterator s = src.begin();
3397 TQCString::Iterator d = result.begin();
3398 while ( *s ) {
3399 switch ( *s ) {
3400 case '<': {
3401 *d++ = '&';
3402 *d++ = 'l';
3403 *d++ = 't';
3404 *d++ = ';';
3405 ++s;
3406 }
3407 break;
3408 case '\r': {
3409 ++s;
3410 }
3411 break;
3412 case '\n': {
3413 *d++ = '<';
3414 *d++ = 'b';
3415 *d++ = 'r';
3416 *d++ = '>';
3417 ++s;
3418 }
3419 break;
3420 case '>': {
3421 *d++ = '&';
3422 *d++ = 'g';
3423 *d++ = 't';
3424 *d++ = ';';
3425 ++s;
3426 }
3427 break;
3428 case '&': {
3429 *d++ = '&';
3430 *d++ = 'a';
3431 *d++ = 'm';
3432 *d++ = 'p';
3433 *d++ = ';';
3434 ++s;
3435 }
3436 break;
3437 case '"': {
3438 *d++ = '&';
3439 *d++ = 'q';
3440 *d++ = 'u';
3441 *d++ = 'o';
3442 *d++ = 't';
3443 *d++ = ';';
3444 ++s;
3445 }
3446 break;
3447 case '\'': {
3448 *d++ = '&';
3449 *d++ = 'a';
3450 *d++ = 'p';
3451 *d++ = 's';
3452 *d++ = ';';
3453 ++s;
3454 }
3455 break;
3456 default:
3457 *d++ = *s++;
3458 }
3459 }
3460 result.truncate( d - result.begin() ); // adds trailing NUL
3461 return result;
3462}
3463
3464//-----------------------------------------------------------------------------
3465TQString KMMessage::encodeMailtoUrl( const TQString& str )
3466{
3467 TQString result;
3468 result = TQString::fromLatin1( KMMsgBase::encodeRFC2047String( str,
3469 "utf-8" ) );
3470 result = KURL::encode_string( result );
3471 return result;
3472}
3473
3474
3475//-----------------------------------------------------------------------------
3476TQString KMMessage::decodeMailtoUrl( const TQString& url )
3477{
3478 TQString result;
3479 result = KURL::decode_string( url );
3480 result = KMMsgBase::decodeRFC2047String( result.latin1() );
3481 return result;
3482}
3483
3484
3485//-----------------------------------------------------------------------------
3486TQCString KMMessage::stripEmailAddr( const TQCString& aStr )
3487{
3488 //kdDebug(5006) << "KMMessage::stripEmailAddr( " << aStr << " )" << endl;
3489
3490 if ( aStr.isEmpty() )
3491 return TQCString();
3492
3493 TQCString result;
3494
3495 // The following is a primitive parser for a mailbox-list (cf. RFC 2822).
3496 // The purpose is to extract a displayable string from the mailboxes.
3497 // Comments in the addr-spec are not handled. No error checking is done.
3498
3499 TQCString name;
3500 TQCString comment;
3501 TQCString angleAddress;
3502 enum { TopLevel, InComment, InAngleAddress } context = TopLevel;
3503 bool inQuotedString = false;
3504 int commentLevel = 0;
3505
3506 for ( const char* p = aStr.data(); *p; ++p ) {
3507 switch ( context ) {
3508 case TopLevel : {
3509 switch ( *p ) {
3510 case '"' : inQuotedString = !inQuotedString;
3511 break;
3512 case '(' : if ( !inQuotedString ) {
3513 context = InComment;
3514 commentLevel = 1;
3515 }
3516 else
3517 name += *p;
3518 break;
3519 case '<' : if ( !inQuotedString ) {
3520 context = InAngleAddress;
3521 }
3522 else
3523 name += *p;
3524 break;
3525 case '\\' : // quoted character
3526 ++p; // skip the '\'
3527 if ( *p )
3528 name += *p;
3529 break;
3530 case ',' : if ( !inQuotedString ) {
3531 // next email address
3532 if ( !result.isEmpty() )
3533 result += ", ";
3534 name = name.stripWhiteSpace();
3535 comment = comment.stripWhiteSpace();
3536 angleAddress = angleAddress.stripWhiteSpace();
3537 /*
3538 kdDebug(5006) << "Name : \"" << name
3539 << "\"" << endl;
3540 kdDebug(5006) << "Comment : \"" << comment
3541 << "\"" << endl;
3542 kdDebug(5006) << "Address : \"" << angleAddress
3543 << "\"" << endl;
3544 */
3545 if ( angleAddress.isEmpty() && !comment.isEmpty() ) {
3546 // handle Outlook-style addresses like
3547 // john.doe@invalid (John Doe)
3548 result += comment;
3549 }
3550 else if ( !name.isEmpty() ) {
3551 result += name;
3552 }
3553 else if ( !comment.isEmpty() ) {
3554 result += comment;
3555 }
3556 else if ( !angleAddress.isEmpty() ) {
3557 result += angleAddress;
3558 }
3559 name = TQCString();
3560 comment = TQCString();
3561 angleAddress = TQCString();
3562 }
3563 else
3564 name += *p;
3565 break;
3566 default : name += *p;
3567 }
3568 break;
3569 }
3570 case InComment : {
3571 switch ( *p ) {
3572 case '(' : ++commentLevel;
3573 comment += *p;
3574 break;
3575 case ')' : --commentLevel;
3576 if ( commentLevel == 0 ) {
3577 context = TopLevel;
3578 comment += ' '; // separate the text of several comments
3579 }
3580 else
3581 comment += *p;
3582 break;
3583 case '\\' : // quoted character
3584 ++p; // skip the '\'
3585 if ( *p )
3586 comment += *p;
3587 break;
3588 default : comment += *p;
3589 }
3590 break;
3591 }
3592 case InAngleAddress : {
3593 switch ( *p ) {
3594 case '"' : inQuotedString = !inQuotedString;
3595 angleAddress += *p;
3596 break;
3597 case '>' : if ( !inQuotedString ) {
3598 context = TopLevel;
3599 }
3600 else
3601 angleAddress += *p;
3602 break;
3603 case '\\' : // quoted character
3604 ++p; // skip the '\'
3605 if ( *p )
3606 angleAddress += *p;
3607 break;
3608 default : angleAddress += *p;
3609 }
3610 break;
3611 }
3612 } // switch ( context )
3613 }
3614 if ( !result.isEmpty() )
3615 result += ", ";
3616 name = name.stripWhiteSpace();
3617 comment = comment.stripWhiteSpace();
3618 angleAddress = angleAddress.stripWhiteSpace();
3619 /*
3620 kdDebug(5006) << "Name : \"" << name << "\"" << endl;
3621 kdDebug(5006) << "Comment : \"" << comment << "\"" << endl;
3622 kdDebug(5006) << "Address : \"" << angleAddress << "\"" << endl;
3623 */
3624 if ( angleAddress.isEmpty() && !comment.isEmpty() ) {
3625 // handle Outlook-style addresses like
3626 // john.doe@invalid (John Doe)
3627 result += comment;
3628 }
3629 else if ( !name.isEmpty() ) {
3630 result += name;
3631 }
3632 else if ( !comment.isEmpty() ) {
3633 result += comment;
3634 }
3635 else if ( !angleAddress.isEmpty() ) {
3636 result += angleAddress;
3637 }
3638
3639 //kdDebug(5006) << "KMMessage::stripEmailAddr(...) returns \"" << result
3640 // << "\"" << endl;
3641 return result;
3642}
3643
3644//-----------------------------------------------------------------------------
3645TQString KMMessage::stripEmailAddr( const TQString& aStr )
3646{
3647 //kdDebug(5006) << "KMMessage::stripEmailAddr( " << aStr << " )" << endl;
3648
3649 if ( aStr.isEmpty() )
3650 return TQString();
3651
3652 TQString result;
3653
3654 // The following is a primitive parser for a mailbox-list (cf. RFC 2822).
3655 // The purpose is to extract a displayable string from the mailboxes.
3656 // Comments in the addr-spec are not handled. No error checking is done.
3657
3658 TQString name;
3659 TQString comment;
3660 TQString angleAddress;
3661 enum { TopLevel, InComment, InAngleAddress } context = TopLevel;
3662 bool inQuotedString = false;
3663 int commentLevel = 0;
3664
3665 TQChar ch;
3666 unsigned int strLength(aStr.length());
3667 for ( uint index = 0; index < strLength; ++index ) {
3668 ch = aStr[index];
3669 switch ( context ) {
3670 case TopLevel : {
3671 switch ( ch.latin1() ) {
3672 case '"' : inQuotedString = !inQuotedString;
3673 break;
3674 case '(' : if ( !inQuotedString ) {
3675 context = InComment;
3676 commentLevel = 1;
3677 }
3678 else
3679 name += ch;
3680 break;
3681 case '<' : if ( !inQuotedString ) {
3682 context = InAngleAddress;
3683 }
3684 else
3685 name += ch;
3686 break;
3687 case '\\' : // quoted character
3688 ++index; // skip the '\'
3689 if ( index < aStr.length() )
3690 name += aStr[index];
3691 break;
3692 case ',' : if ( !inQuotedString ) {
3693 // next email address
3694 if ( !result.isEmpty() )
3695 result += ", ";
3696 name = name.stripWhiteSpace();
3697 comment = comment.stripWhiteSpace();
3698 angleAddress = angleAddress.stripWhiteSpace();
3699 /*
3700 kdDebug(5006) << "Name : \"" << name
3701 << "\"" << endl;
3702 kdDebug(5006) << "Comment : \"" << comment
3703 << "\"" << endl;
3704 kdDebug(5006) << "Address : \"" << angleAddress
3705 << "\"" << endl;
3706 */
3707 if ( angleAddress.isEmpty() && !comment.isEmpty() ) {
3708 // handle Outlook-style addresses like
3709 // john.doe@invalid (John Doe)
3710 result += comment;
3711 }
3712 else if ( !name.isEmpty() ) {
3713 result += name;
3714 }
3715 else if ( !comment.isEmpty() ) {
3716 result += comment;
3717 }
3718 else if ( !angleAddress.isEmpty() ) {
3719 result += angleAddress;
3720 }
3721 name = TQString();
3722 comment = TQString();
3723 angleAddress = TQString();
3724 }
3725 else
3726 name += ch;
3727 break;
3728 default : name += ch;
3729 }
3730 break;
3731 }
3732 case InComment : {
3733 switch ( ch.latin1() ) {
3734 case '(' : ++commentLevel;
3735 comment += ch;
3736 break;
3737 case ')' : --commentLevel;
3738 if ( commentLevel == 0 ) {
3739 context = TopLevel;
3740 comment += ' '; // separate the text of several comments
3741 }
3742 else
3743 comment += ch;
3744 break;
3745 case '\\' : // quoted character
3746 ++index; // skip the '\'
3747 if ( index < aStr.length() )
3748 comment += aStr[index];
3749 break;
3750 default : comment += ch;
3751 }
3752 break;
3753 }
3754 case InAngleAddress : {
3755 switch ( ch.latin1() ) {
3756 case '"' : inQuotedString = !inQuotedString;
3757 angleAddress += ch;
3758 break;
3759 case '>' : if ( !inQuotedString ) {
3760 context = TopLevel;
3761 }
3762 else
3763 angleAddress += ch;
3764 break;
3765 case '\\' : // quoted character
3766 ++index; // skip the '\'
3767 if ( index < aStr.length() )
3768 angleAddress += aStr[index];
3769 break;
3770 default : angleAddress += ch;
3771 }
3772 break;
3773 }
3774 } // switch ( context )
3775 }
3776 if ( !result.isEmpty() )
3777 result += ", ";
3778 name = name.stripWhiteSpace();
3779 comment = comment.stripWhiteSpace();
3780 angleAddress = angleAddress.stripWhiteSpace();
3781 /*
3782 kdDebug(5006) << "Name : \"" << name << "\"" << endl;
3783 kdDebug(5006) << "Comment : \"" << comment << "\"" << endl;
3784 kdDebug(5006) << "Address : \"" << angleAddress << "\"" << endl;
3785 */
3786 if ( angleAddress.isEmpty() && !comment.isEmpty() ) {
3787 // handle Outlook-style addresses like
3788 // john.doe@invalid (John Doe)
3789 result += comment;
3790 }
3791 else if ( !name.isEmpty() ) {
3792 result += name;
3793 }
3794 else if ( !comment.isEmpty() ) {
3795 result += comment;
3796 }
3797 else if ( !angleAddress.isEmpty() ) {
3798 result += angleAddress;
3799 }
3800
3801 //kdDebug(5006) << "KMMessage::stripEmailAddr(...) returns \"" << result
3802 // << "\"" << endl;
3803 return result;
3804}
3805
3806//-----------------------------------------------------------------------------
3807TQString KMMessage::quoteHtmlChars( const TQString& str, bool removeLineBreaks )
3808{
3809 TQString result;
3810
3811 unsigned int strLength(str.length());
3812 result.reserve( 6*strLength ); // maximal possible length
3813 for( unsigned int i = 0; i < strLength; ++i )
3814 switch ( str[i].latin1() ) {
3815 case '<':
3816 result += "&lt;";
3817 break;
3818 case '>':
3819 result += "&gt;";
3820 break;
3821 case '&':
3822 result += "&amp;";
3823 break;
3824 case '"':
3825 result += "&quot;";
3826 break;
3827 case '\n':
3828 if ( !removeLineBreaks )
3829 result += "<br>";
3830 break;
3831 case '\r':
3832 // ignore CR
3833 break;
3834 default:
3835 result += str[i];
3836 }
3837
3838 result.squeeze();
3839 return result;
3840}
3841
3842//-----------------------------------------------------------------------------
3843TQString KMMessage::emailAddrAsAnchor(const TQString& aEmail, bool stripped, const TQString& cssStyle, bool aLink)
3844{
3845 if( aEmail.isEmpty() )
3846 return aEmail;
3847
3848 TQStringList addressList = KPIM::splitEmailAddrList( aEmail );
3849 TQString result;
3850
3851 for( TQStringList::ConstIterator it = addressList.begin();
3852 ( it != addressList.end() );
3853 ++it ) {
3854 if( !(*it).isEmpty() ) {
3855
3856 // Extract the name, mail and some pretty versions out of the mail address
3857 TQString name, mail;
3858 KPIM::getNameAndMail( *it, name, mail );
3859 TQString pretty;
3860 TQString prettyStripped;
3861 if ( name.stripWhiteSpace().isEmpty() ) {
3862 pretty = mail;
3863 prettyStripped = mail;
3864 } else {
3865 pretty = KPIM::quoteNameIfNecessary( name ) + " <" + mail + ">";
3866 prettyStripped = name;
3867 }
3868
3869 if(aLink) {
3870 result += "<a href=\"mailto:"
3871 + KMMessage::encodeMailtoUrl( pretty )
3872 + "\" "+cssStyle+">";
3873 }
3874
3875 if ( stripped ) {
3876 result += KMMessage::quoteHtmlChars( prettyStripped, true );
3877 }
3878 else {
3879 result += KMMessage::quoteHtmlChars( pretty, true );
3880 }
3881
3882 if(aLink)
3883 result += "</a>, ";
3884 }
3885 }
3886 // cut of the trailing ", "
3887 if(aLink)
3888 result.truncate( result.length() - 2 );
3889
3890 //kdDebug(5006) << "KMMessage::emailAddrAsAnchor('" << aEmail
3891 // << "') returns:\n-->" << result << "<--" << endl;
3892 return result;
3893}
3894
3895//-----------------------------------------------------------------------------
3896//static
3897TQStringList KMMessage::stripAddressFromAddressList( const TQString& address,
3898 const TQStringList& list )
3899{
3900 TQStringList addresses( list );
3901 TQString addrSpec( KPIM::getEmailAddress( address ) );
3902 for ( TQStringList::Iterator it = addresses.begin();
3903 it != addresses.end(); ) {
3904 if ( kasciistricmp( addrSpec.utf8().data(),
3905 KPIM::getEmailAddress( *it ).utf8().data() ) == 0 ) {
3906 kdDebug(5006) << "Removing " << *it << " from the address list"
3907 << endl;
3908 it = addresses.remove( it );
3909 }
3910 else
3911 ++it;
3912 }
3913 return addresses;
3914}
3915
3916
3917//-----------------------------------------------------------------------------
3918//static
3919TQStringList KMMessage::stripMyAddressesFromAddressList( const TQStringList& list )
3920{
3921 TQStringList addresses = list;
3922 for( TQStringList::Iterator it = addresses.begin();
3923 it != addresses.end(); ) {
3924 kdDebug(5006) << "Check whether " << *it << " is one of my addresses"
3925 << endl;
3926 if( kmkernel->identityManager()->thatIsMe( KPIM::getEmailAddress( *it ) ) ) {
3927 kdDebug(5006) << "Removing " << *it << " from the address list"
3928 << endl;
3929 it = addresses.remove( it );
3930 }
3931 else
3932 ++it;
3933 }
3934 return addresses;
3935}
3936
3937
3938//-----------------------------------------------------------------------------
3939//static
3940bool KMMessage::addressIsInAddressList( const TQString& address,
3941 const TQStringList& addresses )
3942{
3943 TQString addrSpec = KPIM::getEmailAddress( address );
3944 for( TQStringList::ConstIterator it = addresses.begin();
3945 it != addresses.end(); ++it ) {
3946 if ( kasciistricmp( addrSpec.utf8().data(),
3947 KPIM::getEmailAddress( *it ).utf8().data() ) == 0 )
3948 return true;
3949 }
3950 return false;
3951}
3952
3953
3954//-----------------------------------------------------------------------------
3955//static
3956TQString KMMessage::expandAliases( const TQString& recipients )
3957{
3958 if ( recipients.isEmpty() )
3959 return TQString();
3960
3961 TQStringList recipientList = KPIM::splitEmailAddrList( recipients );
3962
3963 TQString expandedRecipients;
3964 for ( TQStringList::Iterator it = recipientList.begin();
3965 it != recipientList.end(); ++it ) {
3966 if ( !expandedRecipients.isEmpty() )
3967 expandedRecipients += ", ";
3968 TQString receiver = (*it).stripWhiteSpace();
3969
3970 // try to expand distribution list
3971 TQString expandedList = KAddrBookExternal::expandDistributionList( receiver );
3972 if ( !expandedList.isEmpty() ) {
3973 expandedRecipients += expandedList;
3974 continue;
3975 }
3976
3977 // try to expand nick name
3978 TQString expandedNickName = KabcBridge::expandNickName( receiver );
3979 if ( !expandedNickName.isEmpty() ) {
3980 expandedRecipients += expandedNickName;
3981 continue;
3982 }
3983
3984 // check whether the address is missing the domain part
3985 // FIXME: looking for '@' might be wrong
3986 if ( receiver.find('@') == -1 ) {
3987 TDEConfigGroup general( KMKernel::config(), "General" );
3988 TQString defaultdomain = general.readEntry( "Default domain" );
3989 if( !defaultdomain.isEmpty() ) {
3990 expandedRecipients += receiver + "@" + defaultdomain;
3991 }
3992 else {
3993 expandedRecipients += guessEmailAddressFromLoginName( receiver );
3994 }
3995 }
3996 else
3997 expandedRecipients += receiver;
3998 }
3999
4000 return expandedRecipients;
4001}
4002
4003
4004//-----------------------------------------------------------------------------
4005//static
4006TQString KMMessage::guessEmailAddressFromLoginName( const TQString& loginName )
4007{
4008 if ( loginName.isEmpty() )
4009 return TQString();
4010
4011 char hostnameC[256];
4012 // null terminate this C string
4013 hostnameC[255] = '\0';
4014 // set the string to 0 length if gethostname fails
4015 if ( gethostname( hostnameC, 255 ) )
4016 hostnameC[0] = '\0';
4017 TQString address = loginName;
4018 address += '@';
4019 address += TQString::fromLocal8Bit( hostnameC );
4020
4021 // try to determine the real name
4022 const KUser user( loginName );
4023 if ( user.isValid() ) {
4024 TQString fullName = user.fullName();
4025 if ( fullName.find( TQRegExp( "[^ 0-9A-Za-z\\x0080-\\xFFFF]" ) ) != -1 )
4026 address = '"' + fullName.replace( '\\', "\\" ).replace( '"', "\\" )
4027 + "\" <" + address + '>';
4028 else
4029 address = fullName + " <" + address + '>';
4030 }
4031
4032 return address;
4033}
4034
4035//-----------------------------------------------------------------------------
4037{
4038 KMMsgBase::readConfig();
4039
4040 TDEConfig *config=KMKernel::config();
4041 TDEConfigGroupSaver saver(config, "General");
4042
4043 config->setGroup("General");
4044
4045 int languageNr = config->readNumEntry("reply-current-language",0);
4046
4047 { // area for config group "KMMessage #n"
4048 TDEConfigGroupSaver saver(config, TQString("KMMessage #%1").arg(languageNr));
4049 sReplyLanguage = config->readEntry("language",TDEGlobal::locale()->language());
4050 sReplyStr = config->readEntry("phrase-reply",
4051 i18n("On %D, you wrote:"));
4052 sReplyAllStr = config->readEntry("phrase-reply-all",
4053 i18n("On %D, %F wrote:"));
4054 sForwardStr = config->readEntry("phrase-forward",
4055 i18n("Forwarded Message"));
4056 sIndentPrefixStr = config->readEntry("indent-prefix",">%_");
4057 }
4058
4059 { // area for config group "Composer"
4060 TDEConfigGroupSaver saver(config, "Composer");
4061 sSmartQuote = GlobalSettings::self()->smartQuote();
4062 sWordWrap = GlobalSettings::self()->wordWrap();
4063 sWrapCol = GlobalSettings::self()->lineWrapWidth();
4064 if ((sWrapCol == 0) || (sWrapCol > 78))
4065 sWrapCol = 78;
4066 if (sWrapCol < 30)
4067 sWrapCol = 30;
4068
4069 sPrefCharsets = config->readListEntry("pref-charsets");
4070 }
4071
4072 { // area for config group "Reader"
4073 TDEConfigGroupSaver saver(config, "Reader");
4074 sHeaderStrategy = HeaderStrategy::create( config->readEntry( "header-set-displayed", "rich" ) );
4075 }
4076}
4077
4079{
4080 TQCString retval;
4081
4082 if (!sPrefCharsets.isEmpty())
4083 retval = sPrefCharsets[0].latin1();
4084
4085 if (retval.isEmpty() || (retval == "locale")) {
4086 retval = TQCString(kmkernel->networkCodec()->mimeName());
4087 kasciitolower( retval.data() );
4088 }
4089
4090 if (retval == "jisx0208.1983-0") retval = "iso-2022-jp";
4091 else if (retval == "ksc5601.1987-0") retval = "euc-kr";
4092 return retval;
4093}
4094
4095const TQStringList &KMMessage::preferredCharsets()
4096{
4097 return sPrefCharsets;
4098}
4099
4100//-----------------------------------------------------------------------------
4101TQCString KMMessage::charset() const
4102{
4103 if ( mMsg->Headers().HasContentType() ) {
4104 DwMediaType &mType=mMsg->Headers().ContentType();
4105 mType.Parse();
4106 DwParameter *param=mType.FirstParameter();
4107 while(param){
4108 if (!kasciistricmp(param->Attribute().c_str(), "charset"))
4109 return param->Value().c_str();
4110 else param=param->Next();
4111 }
4112 }
4113 return ""; // us-ascii, but we don't have to specify it
4114}
4115
4116//-----------------------------------------------------------------------------
4117void KMMessage::setCharset( const TQCString &charset, DwEntity *entity )
4118{
4119 kdWarning( type() != DwMime::kTypeText )
4120 << "KMMessage::setCharset(): trying to set a charset for a non-textual mimetype." << endl
4121 << "Fix this caller:" << endl
4122 << "====================================================================" << endl
4123 << kdBacktrace( 5 ) << endl
4124 << "====================================================================" << endl;
4125
4126 if ( !entity )
4127 entity = mMsg;
4128
4129 DwMediaType &mType = entity->Headers().ContentType();
4130 mType.Parse();
4131 DwParameter *param = mType.FirstParameter();
4132 while( param ) {
4133
4134 // FIXME use the mimelib functions here for comparison.
4135 if ( !kasciistricmp( param->Attribute().c_str(), "charset" ) )
4136 break;
4137
4138 param = param->Next();
4139 }
4140 if ( !param ) {
4141 param = new DwParameter;
4142 param->SetAttribute( "charset" );
4143 mType.AddParameter( param );
4144 }
4145 else
4146 mType.SetModified();
4147
4148 TQCString lowerCharset = charset;
4149 kasciitolower( lowerCharset.data() );
4150 param->SetValue( DwString( lowerCharset ) );
4151 mType.Assemble();
4152}
4153
4154
4155//-----------------------------------------------------------------------------
4156void KMMessage::setStatus(const KMMsgStatus aStatus, int idx)
4157{
4158 if (mStatus == aStatus)
4159 return;
4160 KMMsgBase::setStatus(aStatus, idx);
4161}
4162
4163void KMMessage::setEncryptionState(const KMMsgEncryptionState s, int idx)
4164{
4165 if( mEncryptionState == s )
4166 return;
4167 mEncryptionState = s;
4168 mDirty = true;
4169 KMMsgBase::setEncryptionState(s, idx);
4170}
4171
4172void KMMessage::setSignatureState(KMMsgSignatureState s, int idx)
4173{
4174 if( mSignatureState == s )
4175 return;
4176 mSignatureState = s;
4177 mDirty = true;
4178 KMMsgBase::setSignatureState(s, idx);
4179}
4180
4181void KMMessage::setMDNSentState( KMMsgMDNSentState status, int idx )
4182{
4183 if ( mMDNSentState == status )
4184 return;
4185 if ( status == 0 )
4186 status = KMMsgMDNStateUnknown;
4187 mMDNSentState = status;
4188 mDirty = true;
4189 KMMsgBase::setMDNSentState( status, idx );
4190}
4191
4192//-----------------------------------------------------------------------------
4193void KMMessage::link( const KMMessage *aMsg, KMMsgStatus aStatus )
4194{
4195 Q_ASSERT( aStatus == KMMsgStatusReplied
4196 || aStatus == KMMsgStatusForwarded
4197 || aStatus == KMMsgStatusDeleted );
4198
4199 TQString message = headerField( "X-KMail-Link-Message" );
4200 if ( !message.isEmpty() )
4201 message += ',';
4202 TQString type = headerField( "X-KMail-Link-Type" );
4203 if ( !type.isEmpty() )
4204 type += ',';
4205
4206 message += TQString::number( aMsg->getMsgSerNum() );
4207 if ( aStatus == KMMsgStatusReplied )
4208 type += "reply";
4209 else if ( aStatus == KMMsgStatusForwarded )
4210 type += "forward";
4211 else if ( aStatus == KMMsgStatusDeleted )
4212 type += "deleted";
4213
4214 setHeaderField( "X-KMail-Link-Message", message );
4215 setHeaderField( "X-KMail-Link-Type", type );
4216}
4217
4218//-----------------------------------------------------------------------------
4219void KMMessage::getLink(int n, ulong *retMsgSerNum, KMMsgStatus *reStatus) const
4220{
4221 *retMsgSerNum = 0;
4222 *reStatus = KMMsgStatusUnknown;
4223
4224 TQString message = headerField("X-KMail-Link-Message");
4225 TQString type = headerField("X-KMail-Link-Type");
4226 message = message.section(',', n, n);
4227 type = type.section(',', n, n);
4228
4229 if ( !message.isEmpty() && !type.isEmpty() ) {
4230 *retMsgSerNum = message.toULong();
4231 if ( type == "reply" )
4232 *reStatus = KMMsgStatusReplied;
4233 else if ( type == "forward" )
4234 *reStatus = KMMsgStatusForwarded;
4235 else if ( type == "deleted" )
4236 *reStatus = KMMsgStatusDeleted;
4237 }
4238}
4239
4240//-----------------------------------------------------------------------------
4241DwBodyPart* KMMessage::findDwBodyPart( DwBodyPart* part, const TQString & partSpecifier )
4242{
4243 if ( !part ) return nullptr;
4244 DwBodyPart* current;
4245
4246 if ( part->partId() == partSpecifier )
4247 return part;
4248
4249 // multipart
4250 if ( part->hasHeaders() &&
4251 part->Headers().HasContentType() &&
4252 part->Body().FirstBodyPart() &&
4253 (DwMime::kTypeMultipart == part->Headers().ContentType().Type() ) &&
4254 (current = findDwBodyPart( part->Body().FirstBodyPart(), partSpecifier )) )
4255 {
4256 return current;
4257 }
4258
4259 // encapsulated message
4260 if ( part->Body().Message() &&
4261 part->Body().Message()->Body().FirstBodyPart() &&
4262 (current = findDwBodyPart( part->Body().Message()->Body().FirstBodyPart(),
4263 partSpecifier )) )
4264 {
4265 return current;
4266 }
4267
4268 // next part
4269 return findDwBodyPart( part->Next(), partSpecifier );
4270}
4271
4272//-----------------------------------------------------------------------------
4273void KMMessage::updateBodyPart(const TQString partSpecifier, const TQByteArray & data)
4274{
4275 if ( !data.data() || !data.size() )
4276 return;
4277
4278 DwString content( data.data(), data.size() );
4279 if ( numBodyParts() > 0 &&
4280 partSpecifier != "0" &&
4281 partSpecifier != "TEXT" )
4282 {
4283 TQString specifier = partSpecifier;
4284 if ( partSpecifier.endsWith(".HEADER") ||
4285 partSpecifier.endsWith(".MIME") ) {
4286 // get the parent bodypart
4287 specifier = partSpecifier.section( '.', 0, -2 );
4288 }
4289
4290 // search for the bodypart
4291 mLastUpdated = findDwBodyPart( getFirstDwBodyPart(), specifier );
4292 kdDebug(5006) << "KMMessage::updateBodyPart " << specifier << endl;
4293 if (!mLastUpdated)
4294 {
4295 kdWarning(5006) << "KMMessage::updateBodyPart - can not find part "
4296 << specifier << endl;
4297 return;
4298 }
4299 if ( partSpecifier.endsWith(".MIME") )
4300 {
4301 // update headers
4302 // get rid of EOL
4303 content.resize( TQMAX( content.length(), 2 ) - 2 );
4304 // we have to delete the fields first as they might have been created by
4305 // an earlier call to DwHeaders::FieldBody
4306 mLastUpdated->Headers().DeleteAllFields();
4307 mLastUpdated->Headers().FromString( content );
4308 mLastUpdated->Headers().Parse();
4309 } else if ( partSpecifier.endsWith(".HEADER") )
4310 {
4311 // update header of embedded message
4312 mLastUpdated->Body().Message()->Headers().FromString( content );
4313 mLastUpdated->Body().Message()->Headers().Parse();
4314 } else {
4315 // update body
4316 mLastUpdated->Body().FromString( content );
4317 TQString parentSpec = partSpecifier.section( '.', 0, -2 );
4318 if ( !parentSpec.isEmpty() )
4319 {
4320 DwBodyPart* parent = findDwBodyPart( getFirstDwBodyPart(), parentSpec );
4321 if ( parent && parent->hasHeaders() && parent->Headers().HasContentType() )
4322 {
4323 const DwMediaType& contentType = parent->Headers().ContentType();
4324 if ( contentType.Type() == DwMime::kTypeMessage &&
4325 contentType.Subtype() == DwMime::kSubtypeRfc822 )
4326 {
4327 // an embedded message that is not multipart
4328 // update this directly
4329 parent->Body().Message()->Body().FromString( content );
4330 }
4331 }
4332 }
4333 }
4334
4335 } else
4336 {
4337 // update text-only messages
4338 if ( partSpecifier == "TEXT" )
4339 deleteBodyParts(); // delete empty parts first
4340 mMsg->Body().FromString( content );
4341 mMsg->Body().Parse();
4342 }
4343 mNeedsAssembly = true;
4344 if (! partSpecifier.endsWith(".HEADER") )
4345 {
4346 // notify observers
4347 notify();
4348 }
4349}
4350
4351void KMMessage::updateInvitationState()
4352{
4353 if ( mMsg && mMsg->hasHeaders() && mMsg->Headers().HasContentType() ) {
4354 TQString cntType = mMsg->Headers().ContentType().TypeStr().c_str();
4355 cntType += '/';
4356 cntType += mMsg->Headers().ContentType().SubtypeStr().c_str();
4357 if ( cntType.lower() == "text/calendar" ) {
4358 setStatus( KMMsgStatusHasInvitation );
4359 return;
4360 }
4361 }
4362 setStatus( KMMsgStatusHasNoInvitation );
4363 return;
4364}
4365
4366//-----------------------------------------------------------------------------
4367void KMMessage::updateAttachmentState( DwBodyPart* part )
4368{
4369 if ( !part )
4370 part = getFirstDwBodyPart();
4371
4372 if ( !part )
4373 {
4374 // kdDebug(5006) << "updateAttachmentState - no part!" << endl;
4375 setStatus( KMMsgStatusHasNoAttach );
4376 return;
4377 }
4378
4379 bool filenameEmpty = true;
4380 if ( part->hasHeaders() ) {
4381 if ( part->Headers().HasContentDisposition() ) {
4382 DwDispositionType cd = part->Headers().ContentDisposition();
4383 filenameEmpty = cd.Filename().empty();
4384 if ( filenameEmpty ) {
4385 // let's try if it is rfc 2231 encoded which mimelib can't handle
4386 filenameEmpty = KMMsgBase::decodeRFC2231String( KMMsgBase::extractRFC2231HeaderField( cd.AsString().c_str(), "filename" ) ).isEmpty();
4387 }
4388 }
4389
4390 // Filename still empty? Check if the content-type has a "name" parameter and try to use that as
4391 // the attachment name
4392 if ( filenameEmpty && part->Headers().HasContentType() ) {
4393 DwMediaType contentType = part->Headers().ContentType();
4394 filenameEmpty = contentType.Name().empty();
4395 if ( filenameEmpty ) {
4396 // let's try if it is rfc 2231 encoded which mimelib can't handle
4397 filenameEmpty = KMMsgBase::decodeRFC2231String( KMMsgBase::extractRFC2231HeaderField(
4398 contentType.AsString().c_str(), "name" ) ).isEmpty();
4399 }
4400 }
4401 }
4402
4403 if ( part->hasHeaders() &&
4404 ( ( part->Headers().HasContentDisposition() &&
4405 !part->Headers().ContentDisposition().Filename().empty() ) ||
4406 ( part->Headers().HasContentType() &&
4407 !filenameEmpty ) ) )
4408 {
4409 // now blacklist certain ContentTypes
4410 if ( !part->Headers().HasContentType() ||
4411 ( part->Headers().HasContentType() &&
4412 part->Headers().ContentType().Subtype() != DwMime::kSubtypePgpSignature &&
4413 part->Headers().ContentType().Subtype() != DwMime::kSubtypePkcs7Signature ) )
4414 {
4415 setStatus( KMMsgStatusHasAttach );
4416 }
4417 return;
4418 }
4419
4420 // multipart
4421 if ( part->hasHeaders() &&
4422 part->Headers().HasContentType() &&
4423 part->Body().FirstBodyPart() &&
4424 (DwMime::kTypeMultipart == part->Headers().ContentType().Type() ) )
4425 {
4426 updateAttachmentState( part->Body().FirstBodyPart() );
4427 }
4428
4429 // encapsulated message
4430 if ( part->Body().Message() &&
4431 part->Body().Message()->Body().FirstBodyPart() )
4432 {
4433 updateAttachmentState( part->Body().Message()->Body().FirstBodyPart() );
4434 }
4435
4436 // next part
4437 if ( part->Next() )
4438 updateAttachmentState( part->Next() );
4439 else if ( attachmentState() == KMMsgAttachmentUnknown )
4440 setStatus( KMMsgStatusHasNoAttach );
4441}
4442
4443void KMMessage::setBodyFromUnicode( const TQString &str, DwEntity *entity )
4444{
4445 TQCString encoding = KMMsgBase::autoDetectCharset( charset(), KMMessage::preferredCharsets(), str );
4446 if ( encoding.isEmpty() )
4447 encoding = "utf-8";
4448 const TQTextCodec * codec = KMMsgBase::codecForName( encoding );
4449 assert( codec );
4450 TQValueList<int> dummy;
4451 setCharset( encoding, entity );
4452 setBodyAndGuessCte( codec->fromUnicode( str ), dummy, false /* no 8bit */,
4453 false, entity );
4454}
4455
4456const TQTextCodec * KMMessage::codec() const {
4457 const TQTextCodec * c = mOverrideCodec;
4458 if ( !c )
4459 // no override-codec set for this message, try the CT charset parameter:
4460 c = KMMsgBase::codecForName( charset() );
4461 if ( !c ) {
4462 // Ok, no override and nothing in the message, let's use the fallback
4463 // the user configured
4464 c = KMMsgBase::codecForName( GlobalSettings::self()->fallbackCharacterEncoding().latin1() );
4465 }
4466 if ( !c )
4467 // no charset means us-ascii (RFC 2045), so using local encoding should
4468 // be okay
4469 c = kmkernel->networkCodec();
4470 assert( c );
4471 return c;
4472}
4473
4474TQString KMMessage::bodyToUnicode(const TQTextCodec* codec) const {
4475 if ( !codec )
4476 // No codec was given, so try the charset in the mail
4477 codec = this->codec();
4478 assert( codec );
4479
4480 return codec->toUnicode( bodyDecoded() );
4481}
4482
4483//-----------------------------------------------------------------------------
4485{
4486 TQCString str( KPIM::getFirstEmailAddress( rawHeaderField("From") ) );
4487 if ( str.isEmpty() )
4488 str = "unknown@unknown.invalid";
4489 TQCString dateStr( dateShortStr() );
4490 if ( dateStr.isEmpty() ) {
4491 time_t t = ::time( nullptr );
4492 dateStr = ctime( &t );
4493 const int len = dateStr.length();
4494 if ( dateStr[len-1] == '\n' )
4495 dateStr.truncate( len - 1 );
4496 }
4497 return "From " + str + " " + dateStr + "\n";
4498}
4499
4501{
4502 sPendingDeletes << this;
4503}
4504
4505DwBodyPart* KMMessage::findPart( int index )
4506{
4507 int accu = 0;
4508 return findPartInternal( getTopLevelPart(), index, accu );
4509}
4510
4511DwBodyPart* KMMessage::findPartInternal(DwEntity * root, int index, int & accu)
4512{
4513 accu++;
4514 if ( index < accu ) // should not happen
4515 return nullptr;
4516 DwBodyPart *current = dynamic_cast<DwBodyPart*>( root );
4517 if ( index == accu )
4518 return current;
4519 DwBodyPart *rv = nullptr;
4520 if ( root->Body().FirstBodyPart() )
4521 rv = findPartInternal( root->Body().FirstBodyPart(), index, accu );
4522 if ( !rv && current && current->Next() )
4523 rv = findPartInternal( current->Next(), index, accu );
4524 if ( !rv && root->Body().Message() )
4525 rv = findPartInternal( root->Body().Message(), index, accu );
4526 return rv;
4527}
4528
sets a cursor and makes sure it's restored on destruction Create a KCursorSaver object when you want ...
Definition: kcursorsaver.h:14
Mail folder.
Definition: kmfolder.h:69
This is a Mime Message.
Definition: kmmessage.h:68
uint identityUoid() const
Definition: kmmessage.cpp:1730
int partNumber(DwBodyPart *aDwBodyPart) const
Get the number of the given DwBodyPart.
Definition: kmmessage.cpp:2858
void link(const KMMessage *aMsg, KMMsgStatus aStatus)
Links this message to aMsg, setting link type to aStatus.
Definition: kmmessage.cpp:4193
void updateBodyPart(const TQString partSpecifier, const TQByteArray &data)
Sets the body of the specified part.
Definition: kmmessage.cpp:4273
static KPIM::EmailParseResult isValidEmailAddressList(const TQString &aStr, TQString &brokenAddress)
Validate a list of email addresses, and also allow aliases and distribution lists to be expanded befo...
Definition: kmmessage.cpp:273
TQString who() const
Get or set the 'Who' header field.
Definition: kmmessage.cpp:2009
void setBody(const TQCString &aStr)
Set the message body.
Definition: kmmessage.cpp:2777
static TQString generateMessageId(const TQString &addr)
Generates the Message-Id.
Definition: kmmessage.cpp:3367
void setBodyFromUnicode(const TQString &str, DwEntity *entity=nullptr)
Sets this body's content to str.
Definition: kmmessage.cpp:4443
DwBodyPart * getFirstDwBodyPart() const
Get the 1st DwBodyPart.
Definition: kmmessage.cpp:2851
TQCString bodyDecoded() const
Returns a decoded version of the body from the current content transfer encoding.
Definition: kmmessage.cpp:2611
TQString formatString(const TQString &) const
Convert wildcards into normal string.
Definition: kmmessage.cpp:426
TQCString typeStr() const
Get or set the 'Content-Type' header field The member functions that involve enumerated types (ints) ...
Definition: kmmessage.cpp:2394
static TQString quoteHtmlChars(const TQString &str, bool removeLineBreaks=false)
Quotes the following characters which have a special meaning in HTML: '<' '>' '&' '"'....
Definition: kmmessage.cpp:3807
TQCString getRefStr() const
Creates reference string for reply to messages.
Definition: kmmessage.cpp:1105
KMMessage(KMFolder *parent=nullptr)
Straight forward initialization.
Definition: kmmessage.cpp:97
TQString templates() const
Get or set the 'Templates' folder.
Definition: kmmessage.h:337
static void bodyPart(DwBodyPart *aDwBodyPart, KMMessagePart *aPart, bool withBody=true)
Fill the KMMessagePart structure for a given DwBodyPart.
Definition: kmmessage.cpp:3111
void setDateToday()
Set the 'Date' header field to the current date.
Definition: kmmessage.cpp:1862
bool isUrgent() const
Definition: kmmessage.cpp:259
void removeHeaderFields(const TQCString &name)
Remove all header fields with given name.
Definition: kmmessage.cpp:2331
void parseTextStringFromDwPart(partNode *root, TQCString &parsedString, const TQTextCodec *&codec, bool &isHTML) const
Returns a decoded body part string to be further processed by function asQuotedString().
Definition: kmmessage.cpp:714
static KMime::Types::AddressList splitAddrField(const TQCString &str)
Splits the given address list into separate addresses.
Definition: kmmessage.cpp:2241
size_t msgSizeServer() const
Get/set size on server.
Definition: kmmessage.cpp:2215
void setTransferInProgress(bool value, bool force=false)
Set that the message shall not be deleted because it is still required.
Definition: kmmessage.cpp:243
TQCString body() const
Get the message body.
Definition: kmmessage.cpp:2573
TQString msgId() const
Get or set the 'Message-Id' header field.
Definition: kmmessage.cpp:2185
TQString from() const
Get or set the 'From' header field.
Definition: kmmessage.cpp:2018
TQCString charset() const
Get the message charset.
Definition: kmmessage.cpp:4101
static TQValueList< int > determineAllowedCtes(const KMime::CharFreq &cf, bool allow8Bit, bool willBeSigned)
Returns a list of content-transfer-encodings that can be used with the given result of the character ...
Definition: kmmessage.cpp:2640
void setAutomaticFields(bool isMultipart=false)
Set fields that are either automatically set (Message-id) or that do not change from one message to a...
Definition: kmmessage.cpp:1780
TQString asQuotedString(const TQString &headerStr, const TQString &indentStr, const TQString &selection=TQString(), bool aStripSignature=true, bool allowDecryption=true) const
Returns message body with quoting header and indented by the given indentation string.
Definition: kmmessage.cpp:837
bool readyToShow() const
Return if the message is ready to be shown.
Definition: kmmessage.h:872
TQString sender() const
Definition: kmmessage.cpp:2042
void setBodyEncoded(const TQCString &aStr, DwEntity *entity=nullptr)
Set the message body, encoding it according to the current content transfer encoding.
Definition: kmmessage.cpp:2722
TQString xmark() const
Get or set the 'X-Mark' header field.
Definition: kmmessage.cpp:2067
static TQCString html2source(const TQCString &src)
Convert '<' into "<" resp.
Definition: kmmessage.cpp:3392
TQString bcc() const
Get or set the 'Bcc' header field.
Definition: kmmessage.cpp:1971
static void readConfig()
Reads config settings from group "KMMessage" and sets all internal variables (e.g.
Definition: kmmessage.cpp:4036
KMMsgInfo * msgInfo()
Get the KMMsgInfo object that was set with setMsgInfo().
Definition: kmmessage.h:930
void setNeedsAssembly()
tell the message that internal data were changed (must be called after directly modifying message str...
Definition: kmmessage.cpp:2556
void setStatus(const KMMsgStatus status, int idx=-1)
Set status and mark dirty.
Definition: kmmessage.cpp:4156
static TQStringList stripMyAddressesFromAddressList(const TQStringList &list)
Strips all the user's addresses from an address list.
Definition: kmmessage.cpp:3919
void setUnencryptedMsg(KMMessage *unencrypted)
Specifies an unencrypted copy of this message to be stored in a separate member variable to allow sav...
Definition: kmmessage.cpp:265
static bool addressIsInAddressList(const TQString &address, const TQStringList &addresses)
Returns true if the given address is contained in the given address list.
Definition: kmmessage.cpp:3940
DwMediaType & dwContentType()
Return reference to Content-Type header for direct manipulation.
Definition: kmmessage.cpp:389
bool deleteBodyPart(int partIndex)
Delete a body part with the specified part index.
Definition: kmmessage.cpp:3184
TQString replyToAuxIdMD5() const
Get the second to last id from the References header field.
Definition: kmmessage.cpp:2149
TQString to() const
Get or set the 'To' header field.
Definition: kmmessage.cpp:1897
TQString subject() const
Get or set the 'Subject' header field.
Definition: kmmessage.cpp:2052
KMMessage * createForward(const TQString &tmpl=TQString())
Create a new message that is a forward of this message, filling all required header fields with the p...
Definition: kmmessage.cpp:1231
void setStatusFields()
Set "Status" and "X-Status" fields of the message from the internal message status.
Definition: kmmessage.cpp:351
void removeHeaderField(const TQCString &name)
Remove header field with given name.
Definition: kmmessage.cpp:2320
void setBodyAndGuessCte(const TQByteArray &aBuf, TQValueList< int > &allowedCte, bool allow8Bit=false, bool willBeSigned=false, DwEntity *entity=nullptr)
Sets body, encoded in the best fitting content-transfer-encoding, which is determined by character fr...
Definition: kmmessage.cpp:2688
KMMsgEncryptionState encryptionState() const
Encryption status of the message.
Definition: kmmessage.h:844
static TQStringList stripAddressFromAddressList(const TQString &address, const TQStringList &addresses)
Strips an address from an address list.
Definition: kmmessage.cpp:3897
TQCString headerAsSendableString() const
Return the message header with the headers that should not be sent stripped off.
Definition: kmmessage.cpp:327
TQCString subtypeStr() const
Subtype.
Definition: kmmessage.cpp:2431
static TQString smartQuote(const TQString &msg, int maxLineLength)
Given argument msg add quoting characters and relayout for max width maxLength.
Definition: kmmessage.cpp:646
void addDwBodyPart(DwBodyPart *aDwPart)
Append a DwBodyPart to the message.
Definition: kmmessage.cpp:3351
static const TQStringList & preferredCharsets()
Get a list of preferred message charsets.
Definition: kmmessage.cpp:4095
void fromDwString(const DwString &str, bool setStatus=false)
Parse the string and create this message from it.
Definition: kmmessage.cpp:402
TQValueList< TQCString > rawHeaderFields(const TQCString &field) const
Returns a list of the raw values of all header fields with the given name.
Definition: kmmessage.cpp:2278
KMMessage * createReply(KMail::ReplyStrategy replyStrategy=KMail::ReplySmart, TQString selection=TQString(), bool noQuote=false, bool allowDecryption=true, const TQString &tmpl=TQString(), const TQString &originatingAccount=TQString())
Create a new message that is a reply to this message, filling all required header fields with the pro...
Definition: kmmessage.cpp:865
static TQString expandAliases(const TQString &recipients)
Expands aliases (distribution lists and nick names) and appends a domain part to all email addresses ...
Definition: kmmessage.cpp:3956
virtual ~KMMessage()
Destructor.
Definition: kmmessage.cpp:190
TQStringList headerFields(const TQCString &name) const
Returns a list of the values of all header fields with the given name.
Definition: kmmessage.cpp:2305
TQString asPlainTextFromObjectTree(partNode *root, bool stripSignature, bool allowDecryption) const
Same as asPlainText(), only that this method expects an already parsed object tree as paramter.
Definition: kmmessage.cpp:742
static void setDwMediaTypeParam(DwMediaType &mType, const TQCString &attr, const TQCString &val)
add or change a parameter of a DwMediaType field
Definition: kmmessage.cpp:2467
TQCString asString() const
Return the entire message contents as a string.
Definition: kmmessage.cpp:314
static TQString encodeMailtoUrl(const TQString &str)
Encodes an email address as mailto URL.
Definition: kmmessage.cpp:3465
TQString bodyToUnicode(const TQTextCodec *codec=nullptr) const
Returns the body part decoded to unicode.
Definition: kmmessage.cpp:4474
KMime::Types::AddressList headerAddrField(const TQCString &name) const
Returns header address list as string list.
Definition: kmmessage.cpp:2254
TQByteArray asSendableString() const
Return the message contents with the headers that should not be sent stripped off.
Definition: kmmessage.cpp:319
static TQCString stripEmailAddr(const TQCString &emailAddr)
This function generates a displayable string from a list of email addresses.
Definition: kmmessage.cpp:3486
KMMessage * createRedirect(const TQString &toStr)
Create a new message that is a redirect to this message, filling all required header fields with the ...
Definition: kmmessage.cpp:1133
static TQString emailAddrAsAnchor(const TQString &emailAddr, bool stripped=true, const TQString &cssStyle=TQString(), bool link=true)
Converts the email address(es) to (a) nice HTML mailto: anchor(s).
Definition: kmmessage.cpp:3843
void setSignatureState(const KMMsgSignatureState, int idx=-1)
Set signature status of the message.
Definition: kmmessage.cpp:4172
TQString asPlainText(bool stripSignature, bool allowDecryption) const
Return the textual content of the message as plain text, converting HTML to plain text if necessary.
Definition: kmmessage.cpp:824
KMMessage * createMDN(KMime::MDN::ActionMode a, KMime::MDN::DispositionType d, bool allowGUI=false, TQValueList< KMime::MDN::DispositionModifier > m=TQValueList< KMime::MDN::DispositionModifier >())
Create a new message that is a MDN for this message, filling all required fields with proper values.
Definition: kmmessage.cpp:1397
void addBodyPart(const KMMessagePart *aPart)
Append a body part to the message.
Definition: kmmessage.cpp:3359
TQString references() const
Get or set the references for this message.
Definition: kmmessage.cpp:2128
void setCharset(const TQCString &charset, DwEntity *entity=nullptr)
Sets the charset of the message or a subpart of the message.
Definition: kmmessage.cpp:4117
void removePrivateHeaderFields()
Remove all private header fields: Status: and X-KMail-
Definition: kmmessage.cpp:335
const DwString & asDwString() const
Return the entire message contents in the DwString.
Definition: kmmessage.cpp:292
bool transferInProgress() const
Return, if the message should not be deleted.
Definition: kmmessage.cpp:236
void setMsgSerNum(unsigned long newMsgSerNum=0)
Sets the message serial number.
Definition: kmmessage.cpp:223
void sanitizeHeaders(const TQStringList &whiteList=TQStringList())
Remove all headers but the content description ones, and those in the white list.
Definition: kmmessage.cpp:1212
static TQString decodeMailtoUrl(const TQString &url)
Decodes a mailto URL.
Definition: kmmessage.cpp:3476
TQString cc() const
Get or set the 'Cc' header field.
Definition: kmmessage.cpp:1943
const TQTextCodec * codec() const
Get a TQTextCodec suitable for this message part.
Definition: kmmessage.cpp:4456
bool isMessage() const
Returns true if object is a real message (not KMMsgInfo or KMMsgBase)
Definition: kmmessage.cpp:230
KMMsgStatus status() const
Status of the message.
Definition: kmmessage.h:830
TQString headerField(const TQCString &name) const
Returns the value of a header field with the given name.
Definition: kmmessage.cpp:2292
void applyIdentity(uint id)
Set the from, to, cc, bcc, encrytion etc headers as specified in the given identity.
Definition: kmmessage.cpp:1665
void deleteWhenUnused()
Delete this message as soon as it no longer in use.
Definition: kmmessage.cpp:4500
TQString strippedSubjectMD5() const
Get a hash of the subject with all prefixes such as Re: removed.
Definition: kmmessage.cpp:2162
static TQCString defaultCharset()
Get the default message charset.
Definition: kmmessage.cpp:4078
TQCString mboxMessageSeparator()
Returns an mbox message separator line for this message, i.e.
Definition: kmmessage.cpp:4484
TQString replaceHeadersInString(const TQString &s) const
Replaces every occurrence of "${foo}" in s with headerField("foo")
Definition: kmmessage.cpp:1613
TQCString id() const
Returns the message ID, useful for followups.
Definition: kmmessage.cpp:208
void initFromMessage(const KMMessage *msg, bool idHeaders=true)
Initialize headers fields according to the identity and the transport header of the given original me...
Definition: kmmessage.cpp:1745
TQCString createForwardBody()
Create the forwarded body for the message.
Definition: kmmessage.cpp:1184
void cleanupHeader()
Removes empty fields from the header, e.g.
Definition: kmmessage.cpp:1757
int numBodyParts() const
Number of body parts the message has.
Definition: kmmessage.cpp:2809
KMMessage * unencryptedMsg() const
Returns an unencrypted copy of this message or 0 if none exists.
Definition: kmmessage.h:137
static TQString guessEmailAddressFromLoginName(const TQString &userName)
Uses the hostname as domain part and tries to determine the real name from the entries in the passwor...
Definition: kmmessage.cpp:4006
TQString replyToId() const
Get or set the 'In-Reply-To' header field.
Definition: kmmessage.cpp:2082
TQCString rawHeaderField(const TQCString &name) const
Returns the raw value of a header field with the given name.
Definition: kmmessage.cpp:2267
void setContentTypeParam(const TQCString &attr, const TQCString &val)
add or change a parameter of the Content-Type field
Definition: kmmessage.cpp:2492
TQString drafts() const
Get or set the 'Drafts' folder.
Definition: kmmessage.h:333
DwBodyPart * dwBodyPart(int aIdx) const
Get the DwBodyPart at position in aIdx.
Definition: kmmessage.cpp:2898
void setMultiPartBody(const TQCString &aStr)
Hack to enable structured body parts to be set as flat text...
Definition: kmmessage.cpp:2794
TQCString contentTransferEncodingStr() const
Get or set the 'Content-Transfer-Encoding' header field The member functions that involve enumerated ...
Definition: kmmessage.cpp:2502
bool hasUnencryptedMsg() const
Returns true if the message contains an unencrypted copy of itself.
Definition: kmmessage.h:134
TQString replyTo() const
Get or set the 'ReplyTo' header field.
Definition: kmmessage.cpp:1922
KMMessage * createDeliveryReceipt() const
Create a new message that is a delivery receipt of this message, filling required header fileds with ...
Definition: kmmessage.cpp:1638
void setEncryptionState(const KMMsgEncryptionState, int idx=-1)
Set encryption status of the message.
Definition: kmmessage.cpp:4163
TQString fcc() const
Get or set the 'Fcc' header field.
Definition: kmmessage.cpp:1984
void getLink(int n, ulong *retMsgSerNum, KMMsgStatus *reStatus) const
Returns the information for the Nth link into retMsg and reStatus.
Definition: kmmessage.cpp:4219
TQCString dateShortStr() const
Returns the message date in asctime format or an empty string if the message lacks a Date header.
Definition: kmmessage.cpp:1818
DwHeaders & headers() const
get the DwHeaders (make sure to call setNeedsAssembly() function after directly modyfying internal da...
Definition: kmmessage.cpp:2549
TQString subjectMD5() const
Get a hash of the subject.
Definition: kmmessage.cpp:2167
TQString headerAsString() const
Return header as string.
Definition: kmmessage.cpp:378
void initHeader(uint identity=0)
Initialize header fields.
Definition: kmmessage.cpp:1718
bool subjectIsPrefixed() const
Is the subject prefixed by Re: or similar?
Definition: kmmessage.cpp:2172
void setHeaderField(const TQCString &name, const TQString &value, HeaderFieldType type=Unstructured, bool prepend=false)
Set the header field with the given name to the given value.
Definition: kmmessage.cpp:2342
void assembleIfNeeded()
Assemble the internal message.
Definition: kmmessage.cpp:2562
ulong UID() const
Get/set UID.
Definition: kmmessage.cpp:2228
DwBodyPart * findDwBodyPart(int type, int subtype) const
Return the first DwBodyPart matching a given Content-Type or zero, if no found.
Definition: kmmessage.cpp:2938
void deleteBodyParts()
Delete all body parts.
Definition: kmmessage.cpp:3177
TQString dateStr() const
Get or set the 'Date' header field.
Definition: kmmessage.cpp:1800
KMMsgSignatureState signatureState() const
Signature status of the message.
Definition: kmmessage.h:847
DwBodyPart * createDWBodyPart(const KMMessagePart *aPart)
Compose a DwBodyPart (needed for adding a part to the message).
Definition: kmmessage.cpp:3221
The TemplateParser transforms a message with a given template.
void setAllowDecryption(const bool allowDecryption)
Sets whether the template parser is allowed to decrypt the original message when needing its message ...
void setSelection(const TQString &selection)
Sets the selection.
TQByteArray ByteArray(const DwString &str)
Construct a TQByteArray from a DwString.
Definition: util.cpp:122
TQCString CString(const DwString &str)
Construct a TQCString from a DwString.
Definition: util.cpp:113
DwString dwString(const TQCString &str)
Construct a DwString from a TQCString.
Definition: util.cpp:130