summaryrefslogtreecommitdiffstats
path: root/kioslaves/imap4/mimeheader.h
blob: a56ec6cb80f1c6b2d79fe173192f4df2807ffc89 (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 <qptrlist.h>
#include <qdict.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 &);


  QCString outputParameter (QDict < QString > *);

  int parsePart (mimeIO &, const QString&);
  int parseBody (mimeIO &, QCString &, const QString&, bool mbox = false);

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

  QString getDispositionParm (const QCString&);
  void setDispositionParm (const QCString&, const QString&);
  QDictIterator < QString > getDispositionIterator ();

  QString getTypeParm (const QCString&);
  void setTypeParm (const QCString&, const QString&);
  QDictIterator < QString > getTypeIterator ();

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

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

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

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

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

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

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

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

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

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

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

  QCString getPostBody ()
  {
    return postMultipartBody;
  }
  void setPostBody (QCString & 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);
  }
  QPtrListIterator < mimeHeader > getNestedIterator ()
  {
    return QPtrListIterator < 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 QString &);

#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 QString &)
  {
  }
  QString typeStr ()
  {
    return QString (contentType.left (contentType.find ('/')));
  }
  void setTypeStr (const QString & _str)
  {
    contentType = QCString (_str.latin1 ()) + "/" + subtypeStr ().latin1 ();
  }
  QString subtypeStr ()
  {
    return QString (contentType.
                    right (contentType.length () - contentType.find ('/') -
                           1));
  }
  void setSubtypeStr (const QString & _str)
  {
    contentType = QCString (typeStr ().latin1 ()) + "/" + _str.latin1 ();
  }
  QString cteStr ()
  {
    return QString (getEncoding ());
  }
  void setCteStr (const QString & _str)
  {
    setEncoding (_str.latin1 ());
  }
  QString contentDisposition ()
  {
    return QString (_contentDisposition);
  }
  QString body ()
  {
    return QString (postMultipartBody);
  }
  QString charset ()
  {
    return getTypeParm ("charset");
  }
  QString bodyDecoded ();
  void setBodyEncoded (const QByteArray &);
  void setBodyEncodedBinary (const QByteArray &);
  QByteArray bodyDecodedBinary ();
  QString name ()
  {
    return QString (getTypeParm ("name"));
  }
  void setName (const QString & _str)
  {
    setTypeParm ("name", _str);
  }
  QString fileName ()
  {
    return QString (getDispositionParm ("filename"));
  }
  QString contentDescription ()
  {
    return QString (rfcDecoder::decodeRFC2047String (_contentDescription));
  }
  void setContentDescription (const QString & _str)
  {
    _contentDescription = rfcDecoder::encodeRFC2047String (_str).latin1 ();
  }
  QString msgIdMD5 ()
  {
    return QString (contentMD5);
  }
  QString iconName ();
  QString magicSetType (bool aAutoDecode = true);
  QString headerAsString ();
  ulong size ()
  {
    return 0;
  }
  void fromString (const QByteArray &)
  {;
  }
  void setContentDisposition (const QString & _str)
  {
    setDisposition (_str.latin1 ());
  }
#endif

protected:
  static void addParameter (const QCString&, QDict < QString > *);
  static QString getParameter (const QCString&, QDict < QString > *);
  static void setParameter (const QCString&, const QString&, QDict < QString > *);

  QPtrList < mimeHdrLine > originalHdrLines;

private:
  QPtrList < mimeHdrLine > additionalHdrLines;
  QDict < QString > typeList;
  QDict < QString > dispositionList;
  QCString contentType;
  QCString _contentDisposition;
  QCString contentEncoding;
  QCString _contentDescription;
  QCString contentID;
  QCString contentMD5;
  unsigned long contentLength;
  QCString mimeContent;
  QCString preMultipartBody;
  QCString postMultipartBody;
  mimeHeader *nestedMessage;
  QPtrList < mimeHeader > nestedParts;
  QString partSpecifier;

};

#endif