summaryrefslogtreecommitdiffstats
path: root/libkmime/kmime_headers_obs.h
blob: 8905d1c5957ba6d26a5cce2af62ba412792d1152 (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
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
/*
    kmime_headers.h

    KMime, the KDE internet mail/usenet news message library.
    Copyright (c) 2001 the KMime authors.
    See file AUTHORS for details

    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.
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software Foundation,
    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, US
*/
#ifndef __KMIME_HEADERS_OBS_H__
#define __KMIME_HEADERS_OBS_H__

#if defined(KMIME_NEW_STYPE_CLASSTREE)
#error You cannot use this file with the new header classes!
#endif

#include <kdemacros.h>

/** Represents a "Message-Id" header */
class KDE_EXPORT MessageID : public Base {

  public:
    MessageID() : Base()  {}
    MessageID(Content *p) : Base(p) {}
    MessageID(Content *p, const TQCString &s) : Base(p) { from7BitString(s); }
    MessageID(Content *p, const TQString &s) : Base(p)  { fromUnicodeString(s, Latin1); }
    ~MessageID()  {}

    virtual void from7BitString(const TQCString &s);
    virtual TQCString as7BitString(bool incType=true);
    virtual void fromUnicodeString(const TQString &s, const TQCString&);
    virtual TQString asUnicodeString();
    virtual void clear()            { m_id.resize(0); }
    virtual bool isEmpty()          { return (m_id.isEmpty()); }
    virtual const char* type()      { return "Message-Id"; }

    void generate(const TQCString &fqdn);

  protected:
    TQCString m_id;

};

/** Represents a "Supersedes" header */
class KDE_EXPORT Supersedes : public MessageID {

  public:
    Supersedes() : MessageID()  {}
    Supersedes(Content *p) : MessageID(p)  {}
    Supersedes(Content *p, const TQCString &s) : MessageID(p,s)  {}
    Supersedes(Content *p, const TQString &s)  : MessageID(p,s)  {}
    ~Supersedes()                   {}

    virtual const char* type()      { return "Supersedes"; }

};

/** This class encapsulates an address-field, containing
    an email-address and a real name */
class KDE_EXPORT AddressField : public Base {

  public:
    AddressField() : Base()  {}
    AddressField(Content *p) : Base(p)  {}
    AddressField(Content *p, const TQCString &s) : Base(p)  { from7BitString(s); }
    AddressField(Content *p, const TQString &s, const TQCString &cs) : Base(p)  { fromUnicodeString(s, cs); }
    AddressField(const AddressField &a):  Base(a.p_arent)  { n_ame=a.n_ame; e_mail=a.e_mail.copy(); e_ncCS=a.e_ncCS; }
    ~AddressField()  {}

    AddressField& operator=(const AddressField &a)  { n_ame=a.n_ame; e_mail=a.e_mail.copy(); e_ncCS=a.e_ncCS; return (*this); }

    virtual void from7BitString(const TQCString &s);
    virtual TQCString as7BitString(bool incType=true);
    virtual void fromUnicodeString(const TQString &s, const TQCString &cs);
    virtual TQString asUnicodeString();
    virtual void clear()              { n_ame.truncate(0); e_mail.resize(0); }
    virtual bool isEmpty()            { return (e_mail.isEmpty() && n_ame.isEmpty()); }

    bool hasName()                    { return ( !n_ame.isEmpty() ); }
    bool hasEmail()                   { return ( !e_mail.isEmpty() ); }
    TQString name()                    { return n_ame; }
    TQCString nameAs7Bit();
    TQCString email()                  { return e_mail; }
    void setName(const TQString &s)    { n_ame=s; }
    void setNameFrom7Bit(const TQCString &s);
    void setEmail(const TQCString &s)  { e_mail=s; }

  protected:
    TQString n_ame;
    TQCString e_mail;
};
typedef TQPtrList<AddressField> ObsAddressList;

/** Represent a "From" header */
class KDE_EXPORT From : public AddressField {

  public:
    From() : AddressField()  {}
    From(Content *p) : AddressField(p)  {}
    From(Content *p, const TQCString &s) : AddressField(p,s)  {}
    From(Content *p, const TQString &s, const TQCString &cs) : AddressField(p,s,cs)  {}
    ~From()  {}

    virtual const char* type()      { return "From"; }
};


/** Represents a "Reply-To" header */
class KDE_EXPORT ReplyTo : public AddressField {

  public:
    ReplyTo() : AddressField()  {}
    ReplyTo(Content *p) : AddressField(p)  {}
    ReplyTo(Content *p, const TQCString &s) : AddressField(p,s)  {}
    ReplyTo(Content *p, const TQString &s, const TQCString &cs) : AddressField(p,s,cs)  {}
    ~ReplyTo()  {}

    virtual const char* type()      { return "Reply-To"; }

};


/** Represents a "Mail-Copies-To" header
    http://www.newsreaders.com/misc/mail-copies-to.html */
class KDE_EXPORT MailCopiesTo : public AddressField {

  public:
    MailCopiesTo() : AddressField()  {}
    MailCopiesTo(Content *p) : AddressField(p)  {}
    MailCopiesTo(Content *p, const TQCString &s) : AddressField(p,s)  {}
    MailCopiesTo(Content *p, const TQString &s, const TQCString &cs) : AddressField(p,s,cs)  {}
    ~MailCopiesTo()  {}

    bool isValid();
    bool alwaysCopy();
    bool neverCopy();

    virtual const char* type()      { return "Mail-Copies-To"; }

};

/** Represents a "To" header */
class KDE_EXPORT To : public Base {

  public:
    To() : Base(),a_ddrList(0)  {}
    To(Content *p) : Base(p),a_ddrList(0)  {}
    To(Content *p, const TQCString &s) : Base(p),a_ddrList(0)  { from7BitString(s); }
    To(Content *p, const TQString &s, const TQCString &cs) : Base(p),a_ddrList(0)  { fromUnicodeString(s,cs); }
    ~To()  { delete a_ddrList; }

    virtual void from7BitString(const TQCString &s);
    virtual TQCString as7BitString(bool incType=true);
    virtual void fromUnicodeString(const TQString &s, const TQCString &cs);
    virtual TQString asUnicodeString();
    virtual void clear()            { delete a_ddrList; a_ddrList=0; }
    virtual bool isEmpty()          { return (!a_ddrList || a_ddrList->isEmpty()
                                              || a_ddrList->first()->isEmpty()); }
    virtual const char* type()      { return "To"; }

    void addAddress(const AddressField &a);
    void emails(TQStrList *l);
    void names(TQStringList *l);
    void displayNames(TQStringList *l);

  protected:
    ObsAddressList *a_ddrList;

};


/** Represents a "CC" header */
class KDE_EXPORT CC : public To {

  public:
    CC() : To()  {}
    CC(Content *p) : To(p)  {}
    CC(Content *p, const TQCString &s) : To(p,s)  {}
    CC(Content *p, const TQString &s, const TQCString &cs) : To(p,s,cs)  {}
    ~CC()  {}

    virtual const char* type()      { return "CC"; }

};


/** Represents a "BCC" header */
class KDE_EXPORT BCC : public To {

  public:
    BCC() : To()  {}
    BCC(Content *p) : To(p)  {}
    BCC(Content *p, const TQCString &s) : To(p,s)  {}
    BCC(Content *p, const TQString &s, const TQCString &cs) : To(p,s,cs)  {}
    ~BCC()  {}

    virtual const char* type()      { return "BCC"; }

};

/** Represents a "References" header */
class KDE_EXPORT References : public Base {

  public:
    References() : Base(),p_os(-1)  {}
    References(Content *p) : Base(p),p_os(-1)  {}
    References(Content *p, const TQCString &s) : Base(p),p_os(-1)  { from7BitString(s); }
    References(Content *p, const TQString &s) : Base(p),p_os(-1)  { fromUnicodeString(s, Latin1); }
    ~References()                 {}

    virtual void from7BitString(const TQCString &s);
    virtual TQCString as7BitString(bool incType=true);
    virtual void fromUnicodeString(const TQString &s, const TQCString&);
    virtual TQString asUnicodeString();
    virtual void clear()            { r_ef.resize(0); p_os=0; }
    virtual bool isEmpty()          { return (r_ef.isEmpty()); }
    virtual const char* type()      { return "References"; }

    int count();
    TQCString first();
    TQCString next();
    TQCString at(unsigned int i);
    void append(const TQCString &s);

  protected:
    TQCString r_ef;
    int p_os;

};

/** Represents a "Content-Type" header */
class KDE_EXPORT ContentType : public Base {

  public:
    ContentType() : Base(),m_imeType("invalid/invalid"),c_ategory(CCsingle)  {}
    ContentType(Content *p) : Base(p),m_imeType("invalid/invalid"),c_ategory(CCsingle)  {}
    ContentType(Content *p, const TQCString &s) : Base(p)  { from7BitString(s); }
    ContentType(Content *p, const TQString &s) : Base(p)  { fromUnicodeString(s, Latin1); }
    ~ContentType()  {}

    virtual void from7BitString(const TQCString &s);
    virtual TQCString as7BitString(bool incType=true);
    virtual void fromUnicodeString(const TQString &s, const TQCString&);
    virtual TQString asUnicodeString();
    virtual void clear()            { m_imeType.resize(0); p_arams.resize(0); }
    virtual bool isEmpty()          { return (m_imeType.isEmpty()); }
    virtual const char* type()      { return "Content-Type"; }


    //mime-type handling
    TQCString mimeType()                     { return m_imeType; }
    TQCString mediaType();
    TQCString subType();
    void setMimeType(const TQCString &s);
    bool isMediatype(const char *s);
    bool isSubtype(const char *s);
    bool isText();
    bool isPlainText();
    bool isHTMLText();
    bool isImage();
    bool isMultipart();
    bool isPartial();

    //parameter handling
    TQCString charset();
    void setCharset(const TQCString &s);
    TQCString boundary();
    void setBoundary(const TQCString &s);
    TQString name();
    void setName(const TQString &s, const TQCString &cs);
    TQCString id();
    void setId(const TQCString &s);
    int partialNumber();
    int partialCount();
    void setPartialParams(int total, int number);

    //category
    contentCategory category()            { return c_ategory; }
    void setCategory(contentCategory c)   { c_ategory=c; }

  protected:
    TQCString getParameter(const char *name);
    void setParameter(const TQCString &name, const TQCString &value, bool doubleQuotes=false);
    TQCString m_imeType, p_arams;
    contentCategory c_ategory;

};


/** Represents a "Content-Transfer-Encoding" header */
class KDE_EXPORT CTEncoding : public Base {

  public:
    CTEncoding() : Base(),c_te(CE7Bit),d_ecoded(true)  {}
    CTEncoding(Content *p) : Base(p),c_te(CE7Bit),d_ecoded(true)  {}
    CTEncoding(Content *p, const TQCString &s) : Base(p)  { from7BitString(s); }
    CTEncoding(Content *p, const TQString &s) : Base(p)  { fromUnicodeString(s, Latin1); }
    ~CTEncoding()  {}

    virtual void from7BitString(const TQCString &s);
    virtual TQCString as7BitString(bool incType=true);
    virtual void fromUnicodeString(const TQString &s, const TQCString&);
    virtual TQString asUnicodeString();
    virtual void clear()            { d_ecoded=true; c_te=CE7Bit; }
    virtual const char* type()      { return "Content-Transfer-Encoding"; }

    contentEncoding cte()                   { return c_te; }
    void setCte(contentEncoding e)          { c_te=e; }
    bool decoded()                          { return d_ecoded; }
    void setDecoded(bool d=true)            { d_ecoded=d; }
    bool needToEncode()                     { return (d_ecoded && (c_te==CEquPr || c_te==CEbase64)); }

  protected:
    contentEncoding c_te;
    bool d_ecoded;

};


/** Represents a "Content-Disposition" header */
class KDE_EXPORT CDisposition : public Base {

  public:
    CDisposition() : Base(),d_isp(CDinline)  {}
    CDisposition(Content *p) : Base(p),d_isp(CDinline)  {}
    CDisposition(Content *p, const TQCString &s) : Base(p)  { from7BitString(s); }
    CDisposition(Content *p, const TQString &s, const TQCString &cs) : Base(p)  { fromUnicodeString(s, cs); }
    ~CDisposition()  {}

    virtual void from7BitString(const TQCString &s);
    virtual TQCString as7BitString(bool incType=true);
    virtual void fromUnicodeString(const TQString &s, const TQCString &cs);
    virtual TQString asUnicodeString();
    virtual void clear()            { f_ilename.truncate(0); d_isp=CDinline; }
    virtual const char* type()      { return "Content-Disposition"; }

    contentDisposition disposition()          { return d_isp; }
    void setDisposition(contentDisposition d) { d_isp=d; }
    bool isAttachment()                       { return (d_isp==CDattachment); }

    TQString filename()                        { return f_ilename; }
    void setFilename(const TQString &s)        { f_ilename=s; }

  protected:
    contentDisposition d_isp;
    TQString f_ilename;

};


/** Represents a "Content-Description" header */
class KDE_EXPORT CDescription : public Generics::GUnstructured {

  public:
    CDescription() : Generics::GUnstructured()  {}
    CDescription( Content * p ) : Generics::GUnstructured( p )  {}
    CDescription( Content * p, const TQCString & s )
      : Generics::GUnstructured( p, s ) {};
    CDescription( Content * p, const TQString & s, const TQCString & cs )
      : Generics::GUnstructured( p, s, cs ) {}
    ~CDescription()  {}

    virtual const char* type()      { return "Content-Description"; }
};

#endif  // __KMIME_HEADERS_OBS_H__