tdeioslave/imap4

mimeheader.h
1/***************************************************************************
2 mimeheader.h - description
3 -------------------
4 begin : Fri Oct 20 2000
5 copyright : (C) 2000 by Sven Carstens
6 email : s.carstens@gmx.de
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18#ifndef MIMEHEADER_H
19#define MIMEHEADER_H
20
21#include <tqptrlist.h>
22#include <tqdict.h>
23
24#include "mimehdrline.h"
25#include "mimeio.h"
26#include "rfcdecoder.h"
27
33{
34public:
35 mimeHeader ();
36 virtual ~ mimeHeader ();
37
38 virtual void addHdrLine (mimeHdrLine *);
39 virtual void outputHeader (mimeIO &);
40 virtual void outputPart (mimeIO &);
41
42
43 TQCString outputParameter (TQDict < TQString > *);
44
45 int parsePart (mimeIO &, const TQString&);
46 int parseBody (mimeIO &, TQCString &, const TQString&, bool mbox = false);
47
48 // parse a header. returns true if it had a leading 'From ' line
49 bool parseHeader (mimeIO &);
50
51 TQString getDispositionParm (const TQCString&);
52 void setDispositionParm (const TQCString&, const TQString&);
53 TQDictIterator < TQString > getDispositionIterator ();
54
55 TQString getTypeParm (const TQCString&);
56 void setTypeParm (const TQCString&, const TQString&);
57 TQDictIterator < TQString > getTypeIterator ();
58
59 // recursively serialize all important contents to the TQDataStream
60 void serialize(TQDataStream& stream);
61
62 const TQCString& getType ()
63 {
64 return contentType;
65 }
66 void setType (const TQCString & _str)
67 {
68 contentType = _str;
69 }
70
71 const TQCString& getDescription ()
72 {
73 return _contentDescription;
74 }
75 void setDescription (const TQCString & _str)
76 {
77 _contentDescription = _str;
78 }
79
80 TQCString getDisposition ()
81 {
82 return _contentDisposition;
83 }
84 void setDisposition (const TQCString & _str)
85 {
86 _contentDisposition = _str;
87 }
88
89 TQCString getEncoding ()
90 {
91 return contentEncoding;
92 }
93 void setEncoding (const TQCString & _str)
94 {
95 contentEncoding = _str;
96 }
97
98 TQCString getMD5 ()
99 {
100 return contentMD5;
101 }
102 void setMD5 (const TQCString & _str)
103 {
104 contentMD5 = _str;
105 }
106
107 TQCString getID ()
108 {
109 return contentID;
110 }
111 void setID (const TQCString & _str)
112 {
113 contentID = _str;
114 }
115
116 unsigned long getLength ()
117 {
118 return contentLength;
119 }
120 void setLength (unsigned long _len)
121 {
122 contentLength = _len;
123 }
124
125 const TQString & getPartSpecifier ()
126 {
127 return partSpecifier;
128 }
129 void setPartSpecifier (const TQString & _str)
130 {
131 partSpecifier = _str;
132 }
133
134 TQPtrListIterator < mimeHdrLine > getOriginalIterator ();
135 TQPtrListIterator < mimeHdrLine > getAdditionalIterator ();
136 void setContent (const TQCString &aContent)
137 {
138 mimeContent = aContent;
139 }
140 TQCString getContent ()
141 {
142 return mimeContent;
143 }
144
145 TQCString getBody ()
146 {
147 return preMultipartBody + postMultipartBody;
148 }
149 TQCString getPreBody ()
150 {
151 return preMultipartBody;
152 }
153 void setPreBody (TQCString & inBody)
154 {
155 preMultipartBody = inBody;
156 }
157
158 TQCString getPostBody ()
159 {
160 return postMultipartBody;
161 }
162 void setPostBody (TQCString & inBody)
163 {
164 postMultipartBody = inBody;
165 contentLength = inBody.length ();
166 }
167
168 mimeHeader *getNestedMessage ()
169 {
170 return nestedMessage;
171 }
172 void setNestedMessage (mimeHeader * inPart, bool destroy = true)
173 {
174 if (nestedMessage && destroy)
175 delete nestedMessage;
176 nestedMessage = inPart;
177 }
178
179// mimeHeader *getNestedPart() { return nestedPart; };
180 void addNestedPart (mimeHeader * inPart)
181 {
182 nestedParts.append (inPart);
183 }
184 TQPtrListIterator < mimeHeader > getNestedIterator ()
185 {
186 return TQPtrListIterator < mimeHeader > (nestedParts);
187 }
188
189 // clears all parts and deletes them from memory
190 void clearNestedParts ()
191 {
192 nestedParts.clear ();
193 }
194
195 // clear all parameters to content-type
196 void clearTypeParameters ()
197 {
198 typeList.clear ();
199 }
200
201 // clear all parameters to content-disposition
202 void clearDispositionParameters ()
203 {
204 dispositionList.clear ();
205 }
206
207 // return the specified body part or NULL
208 mimeHeader *bodyPart (const TQString &);
209
210#ifdef KMAIL_COMPATIBLE
211 ulong msgSize ()
212 {
213 return contentLength;
214 }
215 uint numBodyParts ()
216 {
217 return nestedParts.count ();
218 }
219 mimeHeader *bodyPart (int which, mimeHeader ** ret = NULL)
220 {
221 if (ret)
222 (*ret) = nestedParts.at (which);
223 return nestedParts.at (which);
224 }
225 void write (const TQString &)
226 {
227 }
228 TQString typeStr ()
229 {
230 return TQString (contentType.left (contentType.find ('/')));
231 }
232 void setTypeStr (const TQString & _str)
233 {
234 contentType = TQCString (_str.latin1 ()) + "/" + subtypeStr ().latin1 ();
235 }
236 TQString subtypeStr ()
237 {
238 return TQString (contentType.
239 right (contentType.length () - contentType.find ('/') -
240 1));
241 }
242 void setSubtypeStr (const TQString & _str)
243 {
244 contentType = TQCString (typeStr ().latin1 ()) + "/" + _str.latin1 ();
245 }
246 TQString cteStr ()
247 {
248 return TQString (getEncoding ());
249 }
250 void setCteStr (const TQString & _str)
251 {
252 setEncoding (_str.latin1 ());
253 }
254 TQString contentDisposition ()
255 {
256 return TQString (_contentDisposition);
257 }
258 TQString body ()
259 {
260 return TQString (postMultipartBody);
261 }
262 TQString charset ()
263 {
264 return getTypeParm ("charset");
265 }
266 TQString bodyDecoded ();
267 void setBodyEncoded (const TQByteArray &);
268 void setBodyEncodedBinary (const TQByteArray &);
269 TQByteArray bodyDecodedBinary ();
270 TQString name ()
271 {
272 return TQString (getTypeParm ("name"));
273 }
274 void setName (const TQString & _str)
275 {
276 setTypeParm ("name", _str);
277 }
278 TQString fileName ()
279 {
280 return TQString (getDispositionParm ("filename"));
281 }
282 TQString contentDescription ()
283 {
284 return TQString (rfcDecoder::decodeRFC2047String (_contentDescription));
285 }
286 void setContentDescription (const TQString & _str)
287 {
288 _contentDescription = rfcDecoder::encodeRFC2047String (_str).latin1 ();
289 }
290 TQString msgIdMD5 ()
291 {
292 return TQString (contentMD5);
293 }
294 TQString iconName ();
295 TQString magicSetType (bool aAutoDecode = true);
296 TQString headerAsString ();
297 ulong size ()
298 {
299 return 0;
300 }
301 void fromString (const TQByteArray &)
302 {;
303 }
304 void setContentDisposition (const TQString & _str)
305 {
306 setDisposition (_str.latin1 ());
307 }
308#endif
309
310protected:
311 static void addParameter (const TQCString&, TQDict < TQString > *);
312 static TQString getParameter (const TQCString&, TQDict < TQString > *);
313 static void setParameter (const TQCString&, const TQString&, TQDict < TQString > *);
314
315 TQPtrList < mimeHdrLine > originalHdrLines;
316
317private:
318 TQPtrList < mimeHdrLine > additionalHdrLines;
319 TQDict < TQString > typeList;
320 TQDict < TQString > dispositionList;
321 TQCString contentType;
322 TQCString _contentDisposition;
323 TQCString contentEncoding;
324 TQCString _contentDescription;
325 TQCString contentID;
326 TQCString contentMD5;
327 unsigned long contentLength;
328 TQCString mimeContent;
329 TQCString preMultipartBody;
330 TQCString postMultipartBody;
331 mimeHeader *nestedMessage;
332 TQPtrList < mimeHeader > nestedParts;
333 TQString partSpecifier;
334
335};
336
337#endif
Definition: mimeio.h:29
static const TQString decodeRFC2047String(const TQString &_str, TQString &charset, TQString &language)
decode a RFC2047 String
Definition: rfcdecoder.cpp:337
static const TQString encodeRFC2047String(const TQString &_str, TQString &charset, TQString &language)
encode a RFC2047 String