2 * kmail: KDE mail client
3 * Copyright (c) 1996-1998 Stefan Taferner <taferner@kde.org>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 #include <kiconloader.h>
35 KMMessagePart( QDataStream
& stream
);
36 virtual ~KMMessagePart();
38 /** Reset to text/plain with 7bit cte and clear all other properties. */
41 /** Obtains an independent copy (i.e. without explicitly shared data) of the
42 data contained in msgPart. */
43 void duplicate( const KMMessagePart
& msgPart
);
45 /** Get or set the message body */
46 QByteArray
body(void) const;
47 void setBody(const QByteArray
&aStr
);
49 /** Sets this body part's content to @p str. @p str is subject to
50 automatic charset and CTE detection.
52 void setBodyFromUnicode( const QString
& str
);
54 /** Returns the body part decoded to unicode.
56 QString
bodyToUnicode(const QTextCodec
* codec
=0) const;
58 /** Returns body as decoded string. Assumes that content-transfer-encoding
59 contains the correct encoding. This routine is meant for binary data.
60 No trailing 0 is appended. */
61 QByteArray
bodyDecodedBinary(void) const;
63 /** Returns body as decoded string. Assumes that content-transfer-encoding
64 contains the correct encoding. This routine is meant for text strings! */
65 QByteArray
bodyDecoded(void) const;
67 /** Sets body, encoded in the best fitting
68 content-transfer-encoding, which is determined by character
71 @param aBuf input buffer
72 @param allowedCte return: list of allowed cte's
73 @param allow8Bit whether "8bit" is allowed as cte.
74 @param willBeSigned whether "7bit"/"8bit" is allowed as cte according to RFC 3156
76 void setBodyAndGuessCte(const QByteArray
& aBuf
,
77 QList
<int>& allowedCte
,
78 bool allow8Bit
= false,
79 bool willBeSigned
= false);
81 /** Sets body, encoded according to the content-transfer-encoding.
82 BEWARE: The entire aStr is used including trailing 0 of text strings! */
83 void setBodyEncodedBinary(const QByteArray
& aStr
);
85 /** Sets body, encoded according to the content-transfer-encoding.
86 This one is for text strings, the trailing 0 is not used. */
87 void setBodyEncoded( const QByteArray
&aStr
);
89 /** Set a full message string as the body of the message part,
90 disallowing anything but 7bit or 8bit encoding.
91 (RFC 1521 section 7.3)
93 void setMessageBody( const QByteArray
&aBuf
);
95 /** Returns decoded length of body. */
96 int decodedSize() const;
98 /** Get or set the 'Content-Type' header field
99 The member functions that involve enumerated types (ints)
100 will work only for well-known types or subtypes. */
101 QByteArray
originalContentTypeStr(void) const
102 { return mOriginalContentTypeStr
; }
104 void setOriginalContentTypeStr( const QByteArray
&txt
)
105 { mOriginalContentTypeStr
= txt
; }
107 QByteArray
typeStr() const { return mType
; }
108 void setTypeStr( const QByteArray
& aStr
) { mType
= aStr
; }
110 void setType(int aType
);
112 QByteArray
subtypeStr() const { return mSubtype
; }
113 void setSubtypeStr( const QByteArray
& aStr
) { mSubtype
= aStr
; }
115 void setSubtype(int aSubtype
);
118 QByteArray
contentId() const { return mContentId
; }
119 void setContentId( const QByteArray
& aStr
) { mContentId
= aStr
; }
121 /** Set the 'Content-Type' by mime-magic from the contents of the body.
122 If autoDecode is true the decoded body will be used for mime type
123 determination (this does not change the body itself). */
124 void magicSetType(bool autoDecode
=true);
126 /** Get or set a custom content type parameter, consisting of an attribute
127 name and a corresponding value. */
128 QByteArray
parameterAttribute(void) const;
129 QString
parameterValue(void) const;
130 void setParameter(const QByteArray
&attribute
, const QString
&value
);
132 QByteArray
additionalCTypeParamStr(void) const
134 return mAdditionalCTypeParamStr
;
136 void setAdditionalCTypeParamStr( const QByteArray
¶m
)
138 mAdditionalCTypeParamStr
= param
;
141 /** Tries to find a good icon for the 'Content-Type' by scanning
142 the installed mimelnk files. Returns the found icon. If no matching
143 icon is found, the one for application/octet-stream is returned. */
144 QString
iconName( int size
= KIconLoader::Desktop
) const;
146 /** Get or set the 'Content-Transfer-Encoding' header field
147 The member functions that involve enumerated types (ints)
148 will work only for well-known encodings. */
149 QByteArray
contentTransferEncodingStr(void) const;
150 int contentTransferEncoding(void) const;
151 void setContentTransferEncodingStr(const QByteArray
&aStr
);
152 void setContentTransferEncoding(int aCte
);
154 /** Cte is short for ContentTransferEncoding.
155 These functions are an alternative to the ones with longer names. */
156 QByteArray
cteStr(void) const { return contentTransferEncodingStr(); }
157 int cte(void) const { return contentTransferEncoding(); }
158 void setCteStr(const QByteArray
& aStr
) { setContentTransferEncodingStr(aStr
); }
159 void setCte(int aCte
) { setContentTransferEncoding(aCte
); }
162 /** Get or set the 'Content-Description' header field */
163 QString
contentDescription() const;
164 QByteArray
contentDescriptionEncoded() const { return mContentDescription
; }
165 void setContentDescription(const QString
&aStr
);
167 /** Get or set the 'Content-Disposition' header field */
168 QByteArray
contentDisposition() const { return mContentDisposition
; }
169 void setContentDisposition( const QByteArray
& cd
) { mContentDisposition
= cd
; }
171 /** Get the message part charset.*/
172 QByteArray
charset() const { return mCharset
; }
174 /** Set the message part charset. */
175 void setCharset( const QByteArray
& c
);
177 /** Get a QTextCodec suitable for this message part */
178 const QTextCodec
* codec() const;
180 /** Get or set name parameter */
181 QString
name() const { return mName
; }
182 void setName( const QString
& name
) { mName
= name
; }
184 /** Returns name of filename part of 'Content-Disposition' header field,
186 QString
fileName(void) const;
188 /** Returns the part number */
189 QString
partSpecifier() const { return mPartSpecifier
; }
191 /** Sets the part number */
192 void setPartSpecifier( const QString
& part
) { mPartSpecifier
= part
; }
194 /** If this part is complete (contains a body) */
195 bool isComplete() { return !mBody
.isEmpty(); }
197 /** Returns the parent part */
198 KMMessagePart
* parent() { return mParent
; }
200 /** Set the parent of this part */
201 void setParent( KMMessagePart
* part
) { mParent
= part
; }
203 /** Returns true if the headers should be loaded */
204 bool loadHeaders() { return mLoadHeaders
; }
206 /** Set to true if the headers should be loaded */
207 void setLoadHeaders( bool load
) { mLoadHeaders
= load
; }
209 /** Returns true if the part itself (as returned by kioslave) should be loaded */
210 bool loadPart() { return mLoadPart
; }
212 /** Set to true if the part itself should be loaded */
213 void setLoadPart( bool load
) { mLoadPart
= load
; }
216 QByteArray mOriginalContentTypeStr
;
220 QByteArray mContentDescription
;
221 QByteArray mContentDisposition
;
222 QByteArray mContentId
;
224 QByteArray mAdditionalCTypeParamStr
;
226 QByteArray mParameterAttribute
;
227 QString mParameterValue
;
229 QString mPartSpecifier
;
230 mutable int mBodyDecodedSize
;
231 KMMessagePart
* mParent
;
237 #endif /*kmmsgpart_h*/