summaryrefslogtreecommitdiffstats
path: root/kioslaves/imap4/mimeheader.h
blob: 0eb46630b172fc9c8479f96b97851575c0914b50 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
/***************************************************************************
                          mimeheader.h  -  description
                             -------------------
    begin                : Fri Oct 20 2000
    copyright            : (C) 2000 by Sven Carstens
    email                : s.carstens@gmx.de
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef MIMEHEADER_H
#define MIMEHEADER_H

#include <tqptrlist.h>
#include <tqdict.h>

#include "mimehdrline.h"
#include "mimeio.h"
#include "rfcdecoder.h"

/**
  *@author Sven Carstens
  */

class mimeHeader
{
public:
  mimeHeader ();
  virtual ~ mimeHeader ();

  virtual void addHdrLine (mimeHdrLine *);
  virtual void outputHeader (mimeIO &);
  virtual void outputPart (mimeIO &);


  TQCString outputParameter (TQDict < TQString > *);

  int parsePart (mimeIO &, const TQString&);
  int parseBody (mimeIO &, TQCString &, const TQString&, bool mbox = false);

  // parse a header. returns true if it had a leading 'From ' line
  bool parseHeader (mimeIO &);

  TQString getDispositionParm (const TQCString&);
  void setDispositionParm (const TQCString&, const TQString&);
  TQDictIterator < TQString > getDispositionIterator ();

  TQString getTypeParm (const TQCString&);
  void setTypeParm (const TQCString&, const TQString&);
  TQDictIterator < TQString > getTypeIterator ();

  // recursively serialize all important contents to the QDataStream
  void serialize(TQDataStream& stream);

  const TQCString& getType ()
  {
    return contentType;
  }
  void setType (const TQCString & _str)
  {
    contentType = _str;
  }

  const TQCString& getDescription ()
  {
    return _contentDescription;
  }
  void setDescription (const TQCString & _str)
  {
    _contentDescription = _str;
  }

  TQCString getDisposition ()
  {
    return _contentDisposition;
  }
  void setDisposition (const TQCString & _str)
  {
    _contentDisposition = _str;
  }

  TQCString getEncoding ()
  {
    return contentEncoding;
  }
  void setEncoding (const TQCString & _str)
  {
    contentEncoding = _str;
  }

  TQCString getMD5 ()
  {
    return contentMD5;
  }
  void setMD5 (const TQCString & _str)
  {
    contentMD5 = _str;
  }

  TQCString getID ()
  {
    return contentID;
  }
  void setID (const TQCString & _str)
  {
    contentID = _str;
  }

  unsigned long getLength ()
  {
    return contentLength;
  }
  void setLength (unsigned long _len)
  {
    contentLength = _len;
  }

  const TQString & getPartSpecifier ()
  {
    return partSpecifier;
  }
  void setPartSpecifier (const TQString & _str)
  {
    partSpecifier = _str;
  }

  TQPtrListIterator < mimeHdrLine > getOriginalIterator ();
  TQPtrListIterator < mimeHdrLine > getAdditionalIterator ();
  void setContent (const TQCString &aContent)
  {
    mimeContent = aContent;
  }
  TQCString getContent ()
  {
    return mimeContent;
  }

  TQCString getBody ()
  {
    return preMultipartBody + postMultipartBody;
  }
  TQCString getPreBody ()
  {
    return preMultipartBody;
  }
  void setPreBody (TQCString & inBody)
  {
    preMultipartBody = inBody;
  }

  TQCString getPostBody ()
  {
    return postMultipartBody;
  }
  void setPostBody (TQCString & inBody)
  {
    postMultipartBody = inBody;
    contentLength = inBody.length ();
  }

  mimeHeader *getNestedMessage ()
  {
    return nestedMessage;
  }
  void setNestedMessage (mimeHeader * inPart, bool destroy = true)
  {
    if (nestedMessage && destroy)
      delete nestedMessage;
    nestedMessage = inPart;
  }

//  mimeHeader *getNestedPart() { return nestedPart; };
  void addNestedPart (mimeHeader * inPart)
  {
    nestedParts.append (inPart);
  }
  TQPtrListIterator < mimeHeader > getNestedIterator ()
  {
    return TQPtrListIterator < mimeHeader > (nestedParts);
  }

  // clears all parts and deletes them from memory
  void clearNestedParts ()
  {
    nestedParts.clear ();
  }

  // clear all parameters to content-type
  void clearTypeParameters ()
  {
    typeList.clear ();
  }

  // clear all parameters to content-disposition
  void clearDispositionParameters ()
  {
    dispositionList.clear ();
  }

  // return the specified body part or NULL
  mimeHeader *bodyPart (const TQString &);

#ifdef KMAIL_COMPATIBLE
  ulong msgSize ()
  {
    return contentLength;
  }
  uint numBodyParts ()
  {
    return nestedParts.count ();
  }
  mimeHeader *bodyPart (int which, mimeHeader ** ret = NULL)
  {
    if (ret)
      (*ret) = nestedParts.at (which);
    return nestedParts.at (which);
  }
  void write (const TQString &)
  {
  }
  TQString typeStr ()
  {
    return TQString (contentType.left (contentType.find ('/')));
  }
  void setTypeStr (const TQString & _str)
  {
    contentType = TQCString (_str.latin1 ()) + "/" + subtypeStr ().latin1 ();
  }
  TQString subtypeStr ()
  {
    return TQString (contentType.
                    right (contentType.length () - contentType.find ('/') -
                           1));
  }
  void setSubtypeStr (const TQString & _str)
  {
    contentType = TQCString (typeStr ().latin1 ()) + "/" + _str.latin1 ();
  }
  TQString cteStr ()
  {
    return TQString (getEncoding ());
  }
  void setCteStr (const TQString & _str)
  {
    setEncoding (_str.latin1 ());
  }
  TQString contentDisposition ()
  {
    return TQString (_contentDisposition);
  }
  TQString body ()
  {
    return TQString (postMultipartBody);
  }
  TQString charset ()
  {
    return getTypeParm ("charset");
  }
  TQString bodyDecoded ();
  void setBodyEncoded (const TQByteArray &);
  void setBodyEncodedBinary (const TQByteArray &);
  TQByteArray bodyDecodedBinary ();
  TQString name ()
  {
    return TQString (getTypeParm ("name"));
  }
  void setName (const TQString & _str)
  {
    setTypeParm ("name", _str);
  }
  TQString fileName ()
  {
    return TQString (getDispositionParm ("filename"));
  }
  TQString contentDescription ()
  {
    return TQString (rfcDecoder::decodeRFC2047String (_contentDescription));
  }
  void setContentDescription (const TQString & _str)
  {
    _contentDescription = rfcDecoder::encodeRFC2047String (_str).latin1 ();
  }
  TQString msgIdMD5 ()
  {
    return TQString (contentMD5);
  }
  TQString iconName ();
  TQString magicSetType (bool aAutoDecode = true);
  TQString headerAsString ();
  ulong size ()
  {
    return 0;
  }
  void fromString (const TQByteArray &)
  {;
  }
  void setContentDisposition (const TQString & _str)
  {
    setDisposition (_str.latin1 ());
  }
#endif

protected:
  static void addParameter (const TQCString&, TQDict < TQString > *);
  static TQString getParameter (const TQCString&, TQDict < TQString > *);
  static void setParameter (const TQCString&, const TQString&, TQDict < TQString > *);

  TQPtrList < mimeHdrLine > originalHdrLines;

private:
  TQPtrList < mimeHdrLine > additionalHdrLines;
  TQDict < TQString > typeList;
  TQDict < TQString > dispositionList;
  TQCString contentType;
  TQCString _contentDisposition;
  TQCString contentEncoding;
  TQCString _contentDescription;
  TQCString contentID;
  TQCString contentMD5;
  unsigned long contentLength;
  TQCString mimeContent;
  TQCString preMultipartBody;
  TQCString postMultipartBody;
  mimeHeader *nestedMessage;
  TQPtrList < mimeHeader > nestedParts;
  TQString partSpecifier;

};

#endif