11 #include <sys/types.h>
13 #include <mimelib/string.h>
14 #include "kmmsgbase.h"
17 #include <kmime_mdn.h>
19 #include<libemailfunctions/email.h>
35 class KMForwardDigestCommand;
42 typedef TQValueList<Address> AddressList;
43 typedef TQValueList<AddrSpec> AddrSpecList;
59 enum ReplyStrategy { ReplySmart = 0,
67 class KMMessage:
public KMMsgBase,
public KMail::ISubject
69 friend class ::KMForwardDigestCommand;
73 using KMMsgBase::parent;
74 using KMMsgBase::setParent;
75 using KMMsgBase::enableUndo;
76 using KMMsgBase::setEnableUndo;
77 using KMMsgBase::isRead;
78 using KMMsgBase::isUnread;
79 using KMMsgBase::isNew;
80 using KMMsgBase::isOld;
81 using KMMsgBase::isWatched;
82 using KMMsgBase::isIgnored;
83 using KMMsgBase::setEncryptionStateChar;
84 using KMMsgBase::setSignatureStateChar;
102 const KMMessage& operator=( const KMMessage& other ) {
115 const KMMsgBase & toMsgBase()
const {
return *
this; }
118 bool isMessage()
const;
123 bool isUrgent()
const;
131 void setUnencryptedMsg(
KMMessage* unencrypted );
152 void del() { setStatus(KMMsgStatusDeleted); }
155 void undel() { setStatus(KMMsgStatusOld); }
158 void touch() { setStatus(KMMsgStatusOld); }
163 KMMessage* createReply( KMail::ReplyStrategy replyStrategy = KMail::ReplySmart,
164 TQString selection=TQString(),
bool noQuote =
false,
165 bool allowDecryption =
true,
166 const TQString &tmpl = TQString(),
167 const TQString &originatingAccount = TQString() );
176 KMMessage* createRedirect(
const TQString &toStr );
179 TQCString createForwardBody();
184 KMMessage* createForward(
const TQString &tmpl = TQString() );
189 KMMessage* createDeliveryReceipt()
const;
204 KMMessage* createMDN( KMime::MDN::ActionMode a,
205 KMime::MDN::DispositionType d,
207 TQValueList<KMime::MDN::DispositionModifier> m=TQValueList<KMime::MDN::DispositionModifier>() );
210 void sanitizeHeaders(
const TQStringList& whiteList = TQStringList() );
213 void fromDwString(
const DwString& str,
bool setStatus=
false);
214 void fromString(
const TQCString& str,
bool setStatus=
false);
215 void fromByteArray(
const TQByteArray & ba,
bool setStatus=
false);
221 const DwString& asDwString()
const;
222 const DwMessage *asDwMessage();
231 TQCString asString()
const;
237 TQByteArray asSendableString()
const;
243 TQCString headerAsSendableString()
const;
248 void removePrivateHeaderFields();
251 DwMediaType& dwContentType();
254 TQString headerAsString()
const;
260 void parseTextStringFromDwPart( partNode * root,
261 TQCString& parsedString,
262 const TQTextCodec*& codec,
263 bool& isHTML )
const;
268 void initHeader(uint identity=0);
272 void initFromMessage(
const KMMessage *msg,
bool idHeaders =
true);
279 uint identityUoid()
const;
283 void applyIdentity( uint
id );
287 void cleanupHeader();
294 void setAutomaticFields(
bool isMultipart=
false);
297 TQString dateStr()
const;
300 TQCString dateShortStr()
const;
301 TQString dateIsoStr()
const;
303 void setDate(
const TQCString& str);
304 void setDate(time_t aUnixTime);
311 void setTo(
const TQString& aStr);
312 TQString toStrip()
const;
315 TQString replyTo()
const;
316 void setReplyTo(
const TQString &aStr );
321 void setCc(
const TQString &aStr );
322 TQString ccStrip()
const;
325 TQString bcc()
const;
326 void setBcc(
const TQString &aStr );
329 TQString fcc()
const;
330 void setFcc(
const TQString &aStr );
333 TQString
drafts()
const {
return mDrafts; }
334 void setDrafts(
const TQString &aStr );
338 void setTemplates(
const TQString &aStr );
341 TQString from()
const;
342 void setFrom(
const TQString& aStr);
343 TQString fromStrip()
const;
347 TQString sender()
const;
352 TQString who()
const;
355 TQString subject()
const;
356 void setSubject(
const TQString& aStr);
362 TQString xmark()
const;
363 void setXMark(
const TQString& aStr);
366 TQString replyToId()
const;
367 void setReplyToId(
const TQString& aStr);
368 TQString replyToIdMD5()
const;
384 TQString replyToAuxIdMD5()
const;
390 TQString strippedSubjectMD5()
const;
402 static KPIM::EmailParseResult isValidEmailAddressList(
const TQString& aStr,
403 TQString& brokenAddress );
409 TQString subjectMD5()
const;
412 bool subjectIsPrefixed()
const;
415 TQString msgId()
const;
416 void setMsgId(
const TQString& aStr);
417 TQString msgIdMD5()
const;
420 TQString references()
const;
421 void setReferences(
const TQCString& aStr);
424 TQCString id()
const;
430 void setMsgSerNum(
unsigned long newMsgSerNum = 0);
436 TQString headerField(
const TQCString& name)
const;
438 enum HeaderFieldType { Unstructured, Structured, Address };
444 void setHeaderField(
const TQCString& name,
const TQString& value,
445 HeaderFieldType type = Unstructured,
446 bool prepend =
false );
449 TQStringList headerFields(
const TQCString& name )
const;
455 TQCString rawHeaderField(
const TQCString & name )
const;
460 TQValueList<TQCString> rawHeaderFields(
const TQCString & field )
const;
463 static KMime::Types::AddressList splitAddrField(
const TQCString & str );
468 KMime::Types::AddressList headerAddrField(
const TQCString& name)
const;
469 KMime::Types::AddrSpecList extractAddrSpecs(
const TQCString & headerNames )
const;
472 void removeHeaderField(
const TQCString& name);
475 void removeHeaderFields(
const TQCString& name);
480 TQCString typeStr()
const;
482 void setTypeStr(
const TQCString& aStr);
483 void setType(
int aType);
485 TQCString subtypeStr()
const;
487 void setSubtypeStr(
const TQCString& aStr);
488 void setSubtype(
int aSubtype);
490 static void setDwMediaTypeParam( DwMediaType &mType,
491 const TQCString& attr,
492 const TQCString& val );
494 void setContentTypeParam(
const TQCString& attr,
const TQCString& val);
499 DwHeaders& headers()
const;
505 void setNeedsAssembly();
511 void assembleIfNeeded();
521 TQCString contentTransferEncodingStr()
const;
522 int contentTransferEncoding( DwEntity *entity = 0 )
const;
523 void setContentTransferEncodingStr(
const TQCString& cteString, DwEntity *entity = 0 );
524 void setContentTransferEncoding(
int cte, DwEntity *entity = 0 );
530 TQCString
cteStr()
const {
return contentTransferEncodingStr(); }
531 int cte( DwEntity *entity = 0 )
const {
return contentTransferEncoding( entity ); }
532 void setCteStr(
const TQCString& aStr, DwEntity *entity = 0 ) {
533 setContentTransferEncodingStr( aStr, entity );
535 void setCte(
int aCte, DwEntity *entity = 0 ) {
536 setContentTransferEncoding( aCte, entity );
546 void setBodyFromUnicode(
const TQString & str, DwEntity *entity = 0 );
550 TQString bodyToUnicode(
const TQTextCodec* codec=0)
const;
553 TQCString body()
const;
556 void setBody(
const TQCString& aStr);
557 void setBody(
const DwString& aStr);
558 void setBody(
const char* aStr);
561 void setMultiPartBody(
const TQCString & aStr );
572 void setBodyEncoded(
const TQCString& aStr, DwEntity *entity = 0 );
573 void setBodyEncodedBinary(
const TQByteArray& aStr, DwEntity *entity = 0 );
578 static TQValueList<int> determineAllowedCtes(
const KMime::CharFreq& cf,
595 void setBodyAndGuessCte(
const TQByteArray& aBuf, TQValueList<int>& allowedCte,
596 bool allow8Bit =
false,
597 bool willBeSigned =
false,
598 DwEntity *entity = 0 );
600 void setBodyAndGuessCte(
const TQCString& aBuf,
601 TQValueList<int>& allowedCte,
602 bool allow8Bit =
false,
603 bool willBeSigned =
false,
604 DwEntity *entity = 0 );
609 TQCString bodyDecoded()
const;
610 TQByteArray bodyDecodedBinary()
const;
614 int numBodyParts()
const;
618 DwBodyPart * findDwBodyPart(
int type,
int subtype )
const;
622 DwBodyPart * findDwBodyPart(
const TQCString& type,
const TQCString& subtype )
const;
626 DwBodyPart* findDwBodyPart( DwBodyPart* part,
const TQString & partSpecifier );
630 DwBodyPart * dwBodyPart(
int aIdx )
const;
634 int partNumber( DwBodyPart * aDwBodyPart )
const;
638 DwBodyPart * getFirstDwBodyPart()
const;
639 DwMessage * getTopLevelPart()
const {
return mMsg; }
644 static void bodyPart(DwBodyPart* aDwBodyPart, KMMessagePart* aPart,
645 bool withBody =
true );
650 void bodyPart(
int aIdx, KMMessagePart* aPart)
const;
653 DwBodyPart* createDWBodyPart(
const KMMessagePart* aPart);
656 void addDwBodyPart(DwBodyPart * aDwPart);
659 void addBodyPart(
const KMMessagePart* aPart);
662 void deleteBodyParts();
668 bool deleteBodyPart(
int partIndex );
672 void setStatusFields();
678 static TQString generateMessageId(
const TQString& addr );
685 static TQCString html2source(
const TQCString & src );
701 static TQCString stripEmailAddr(
const TQCString& emailAddr);
705 static TQString stripEmailAddr(
const TQString& emailAddr);
712 static TQString quoteHtmlChars(
const TQString& str,
713 bool removeLineBreaks =
false );
719 static TQString emailAddrAsAnchor(
const TQString& emailAddr,
720 bool stripped=
true,
const TQString& cssStyle = TQString(),
bool link =
true);
725 static TQStringList stripAddressFromAddressList(
const TQString& address,
726 const TQStringList& addresses );
731 static TQStringList stripMyAddressesFromAddressList(
const TQStringList& list );
735 static bool addressIsInAddressList(
const TQString& address,
736 const TQStringList& addresses );
741 static TQString expandAliases(
const TQString& recipients );
746 static TQString guessEmailAddressFromLoginName(
const TQString& userName );
754 static TQString smartQuote(
const TQString &msg,
int maxLineLength );
757 static TQCString defaultCharset();
760 static const TQStringList &preferredCharsets();
763 TQString replaceHeadersInString(
const TQString & s )
const;
766 TQCString charset()
const;
776 void setCharset(
const TQCString& charset, DwEntity *entity = 0 );
779 const TQTextCodec * codec()
const;
786 { mDecodeHTML = aDecodeHTML; }
790 static void readConfig();
795 TQCString getRefStr()
const;
799 void setFolderOffset(off_t offs) {
if(mFolderOffset != offs) { mFolderOffset=offs; setDirty(
true); } }
803 void setFileName(
const TQString& file) {
if(mFileName != file) { mFileName=file; setDirty(
true); } }
807 void setOriginatingAccountName(
const TQString& account) {
if(mOriginatingAccountName != account) { mOriginatingAccountName=account; setDirty(
true); } }
813 void setMsgSize(
size_t sz) {
if(mMsgSize != sz) { mMsgSize = sz; setDirty(
true); } }
818 {
return (mMsgLength) ? mMsgLength : mMsgSize; }
819 void setMsgLength(
size_t sz) { mMsgLength = sz; }
822 size_t msgSizeServer()
const;
823 void setMsgSizeServer(
size_t sz);
827 void setUID(ulong uid);
830 KMMsgStatus
status()
const {
return mStatus; }
832 void setStatus(
const KMMsgStatus status,
int idx = -1);
833 void setStatus(
const char* s1,
const char* s2=0) { KMMsgBase::setStatus(s1, s2); }
836 void setEncryptionState(
const KMMsgEncryptionState,
int idx = -1);
839 void setSignatureState(
const KMMsgSignatureState,
int idx = -1);
841 void setMDNSentState( KMMsgMDNSentState status,
int idx=-1 );
849 KMMsgMDNSentState mdnSentState()
const {
return mMDNSentState; }
852 void link(
const KMMessage *aMsg, KMMsgStatus aStatus);
855 void getLink(
int n, ulong *retMsgSerNum, KMMsgStatus *reStatus)
const;
858 TQString formatString(
const TQString&)
const;
861 void updateBodyPart(
const TQString partSpecifier,
const TQByteArray & data);
876 void updateAttachmentState( DwBodyPart *part = 0 );
877 void updateInvitationState();
880 bool transferInProgress()
const;
882 void setTransferInProgress(
bool value,
bool force =
false);
888 TQCString mboxMessageSeparator();
905 TQString asQuotedString(
const TQString & headerStr,
906 const TQString & indentStr,
907 const TQString & selection=TQString(),
908 bool aStripSignature=
true,
909 bool allowDecryption=
true)
const;
913 TQString asPlainText(
bool stripSignature,
bool allowDecryption )
const;
921 TQString asPlainTextFromObjectTree( partNode *root,
bool stripSignature,
922 bool allowDecryption )
const;
932 void setMsgInfo( KMMsgInfo* msgInfo ) { mMsgInfo = msgInfo; }
937 bool isBeingParsed()
const {
return mIsParsed; }
938 void setIsBeingParsed(
bool t ) { mIsParsed = t; }
941 void deleteWhenUnused();
943 DwBodyPart* findPart(
int index );
948 void init( DwMessage* aMsg = 0 );
952 DwBodyPart* findPartInternal( DwEntity* root,
int index,
int &accu );
956 mutable DwMessage* mMsg;
957 mutable bool mNeedsAssembly :1;
959 bool mReadyToShow :1;
962 static const KMail::HeaderStrategy * sHeaderStrategy;
963 static TQString sForwardStr;
964 const TQTextCodec * mOverrideCodec;
967 TQString mOriginatingAccountName;
969 size_t mMsgSize, mMsgLength;
971 KMMsgEncryptionState mEncryptionState;
972 KMMsgSignatureState mSignatureState;
973 KMMsgMDNSentState mMDNSentState;
975 DwBodyPart* mLastUpdated;
978 static TQValueList<KMMessage*> sPendingDeletes;
A FolderStorage with an index for faster access to often used message properties.
TQString originatingAccountName() const
Get/set originating account name.
void undel()
Undelete the message.
void setReadyToShow(bool v)
Set if the message is ready to be shown.
void touch()
Touch the message - mark it as read.
TQString templates() const
Get or set the 'Templates' folder.
KMMessage * unencryptedMsg() const
Returns an unencrypted copy of this message or 0 if none exists.
bool readyToShow() const
Return if the message is ready to be shown.
void setOverrideCodec(const TQTextCodec *codec)
Set the charset the user selected for the message to display.
void del()
Mark the message as deleted.
void setDecodeHTML(bool aDecodeHTML)
Allow decoding of HTML for quoting.
TQCString cteStr() const
Cte is short for ContentTransferEncoding.
KMMsgEncryptionState encryptionState() const
Encryption status of the message.
size_t msgLength() const
Unlike the above function this works also, if the message is not in a folder.
KMMsgInfo * msgInfo()
Get the KMMsgInfo object that was set with setMsgInfo().
void setComplete(bool v)
Set if the message is a complete message.
KMMsgStatus status() const
Status of the message.
TQString fileName() const
Get/set filename in mail folder.
int getCursorPos()
Get stored cursor position.
off_t folderOffset() const
Get/set offset in mail folder.
KMMessage(KMFolder *parent=0)
Straight forward initialization.
size_t msgSize() const
Get/set size of message in the folder including the whole header in bytes.
void initStrippedSubjectMD5()
Calculate strippedSubject.
TQString drafts() const
Get or set the 'Drafts' folder.
KMMsgBase & toMsgBase()
Get KMMsgBase for this object.
bool hasUnencryptedMsg() const
Returns TRUE if the message contains an unencrypted copy of itself.
bool isComplete() const
Return true if the complete message is available without referring to the backing store.
KMMessage * takeUnencryptedMsg()
Returns an unencrypted copy of this message or 0 if none exists.
void setMsgInfo(KMMsgInfo *msgInfo)
Set the KMMsgInfo object corresponding to this message.
KMMsgSignatureState signatureState() const
Signature status of the message.
void setCursorPos(int pos)
Set cursor position as offset from message start.
DwBodyPart * lastUpdatedPart()
Returns the last DwBodyPart that was updated.
TQString decodeMailtoUrl(const TQString &url)
Decodes a mailto URL.
TQString encodeMailtoUrl(const TQString &str)
Encodes an email address as mailto URL.