4 KMime, the KDE internet mail/usenet news message library.
5 Copyright (c) 2001-2002 the KMime authors.
6 See file AUTHORS for details
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License version 2.0 as
10 published by the Free Software Foundation.
11 You should have received a copy of the GNU General Public License
12 along with this program; if not, write to the Free Software Foundation,
13 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, US
15 #ifndef __KMIME_HEADERS_H__
16 #define __KMIME_HEADERS_H__
20 // - header's base class defining the common interface
21 // - generic base classes for different types of fields
22 // - incompatible, GStructured-based field classes
23 // - compatible, GUnstructured-based field classes
25 #include "kmime_header_parsing.h"
29 #include <qstringlist.h>
31 #include <qdatetime.h>
32 #include <qasciidict.h>
38 #include <kdepimmacros.h>
48 enum contentCategory
{ CCsingle
,
53 enum contentEncoding
{ CE7Bit
,
60 enum contentDisposition
{ CDinline
,
65 static const QCString
Latin1("ISO-8859-1");
67 #define mk_trivial_subclass_with_name( subclass, subclassName, baseclass ) \
68 class subclass : public Generics::baseclass { \
70 subclass() : Generics::baseclass() {} \
71 subclass( Content * p ) : Generics::baseclass( p ) {} \
72 subclass( Content * p, const QCString & s ) \
73 : Generics::baseclass( p ) { from7BitString( s ); } \
74 subclass( Content * p, const QString & s, const QCString & cs ) \
75 : Generics::baseclass( p ) { fromUnicodeString( s, cs ); } \
78 const char * type() const { return #subclassName; } \
81 #define mk_trivial_subclass( subclass, baseclass ) \
82 mk_trivial_subclass_with_name( subclass, subclass, baseclass )
84 #define mk_parsing_subclass_with_name( subclass, subclassName, baseclass ) \
85 class subclass : public Generics::baseclass { \
87 subclass() : Generics::baseclass() {} \
88 subclass( Content * p ) : Generics::baseclass( p ) {} \
89 subclass( Content * p, const QCString & s ) \
90 : Generics::baseclass( p ) { from7BitString( s ); } \
91 subclass( Content * p, const QString & s, const QCString & cs ) \
92 : Generics::baseclass( p ) { fromUnicodeString( s, cs ); } \
95 const char * type() const { return #subclassName; } \
97 bool parse( const char* & scursor, const char * const send, bool isCRLF=false ); \
100 #define mk_parsing_subclass( subclass, baseclass ) \
101 mk_parsing_subclass_with_name( subclass, subclass, baseclass )
105 // HEADER'S BASE CLASS. DEFINES THE COMMON INTERFACE
109 /** Baseclass of all header-classes. It represents a
110 header-field as described in RFC-822. */
111 class KDE_EXPORT Base
{
114 typedef QPtrList
<Base
> List
;
116 /** Create an empty header. */
117 Base() : e_ncCS(0), p_arent(0) {}
119 /** Create an empty header with a parent-content. */
120 Base(KMime::Content
*parent
) : e_ncCS(0), p_arent(parent
) {}
125 /** Return the parent of this header. */
126 KMime::Content
* parent() { return p_arent
; }
128 /** Set the parent for this header. */
129 void setParent(KMime::Content
*p
) { p_arent
=p
; }
131 /** Parse the given string. Take care of RFC2047-encoded
132 strings. A default charset is given. If the last parameter
133 is true the default charset is used in any case */
134 virtual void from7BitString(const QCString
&) {}
136 /** Return the encoded header. The parameter specifies
137 whether the header-type should be included. */
138 virtual QCString
as7BitString(bool=true) { return QCString(); }
140 /** Return the charset that is used for RFC2047-encoding */
141 QCString
rfc2047Charset();
143 /** Set the charset for RFC2047-encoding */
144 void setRFC2047Charset(const QCString
&cs
);
146 /** Return the default charset */
147 QCString
defaultCS();
149 /** Return if the default charset is mandatory */
152 /** Parse the given string and set the charset. */
153 virtual void fromUnicodeString(const QString
&, const QCString
&) {}
155 /** Return the decoded content of the header without
157 virtual QString
asUnicodeString() { return QString(); }
160 virtual void clear() {}
162 /** Do we have data? */
163 virtual bool isEmpty() { return false; }
165 /** Return the type of this header (e.g. "From") */
166 virtual const char* type() { return ""; }
168 /** Check if this header is of type t. */
169 bool is(const char* t
) { return (strcasecmp(t
, type())==0); }
171 /** Check if this header is a MIME header */
172 bool isMimeHeader() { return (strncasecmp(type(), "Content-", 8)==0); }
174 /** Check if this header is a X-Header */
175 bool isXHeader() { return (strncmp(type(), "X-", 2)==0); }
178 QCString
typeIntro() { return (QCString(type())+": "); }
188 // GENERIC BASE CLASSES FOR DIFFERENT TYPES OF FIELDS
194 /** Abstract base class for unstructured header fields
195 (e.g. "Subject", "Comment", "Content-description").
197 Features: Decodes the header according to RFC2047, incl. RFC2231
198 extensions to encoded-words.
200 Subclasses need only re-implement @p const @p char* @p type().
202 A macro to automate this is named
204 MK_TRIVIAL_GUnstructured_SUBCLASS(classname,headername);
207 The ContentDescription class then reads:
209 MK_TRIVIAL_GUnstructured_SUBCLASS(ContentDescription,Content-Description);
214 // - uses old decodeRFC2047String function, instead of our own...
216 class KDE_EXPORT GUnstructured
: public Base
{
219 GUnstructured() : Base() {}
220 GUnstructured( Content
* p
) : Base( p
) {}
221 GUnstructured( Content
* p
, const QCString
& s
)
222 : Base( p
) { from7BitString(s
); }
223 GUnstructured( Content
* p
, const QString
& s
, const QCString
& cs
)
224 : Base( p
) { fromUnicodeString( s
, cs
); }
227 virtual void from7BitString( const QCString
& str
);
228 virtual QCString
as7BitString( bool withHeaderType
=true );
230 virtual void fromUnicodeString( const QString
& str
,
231 const QCString
& suggestedCharset
);
232 virtual QString
asUnicodeString();
234 virtual void clear() { d_ecoded
.truncate(0); }
235 virtual bool isEmpty() { return (d_ecoded
.isEmpty()); }
241 /** This is the base class for all structured header fields. It
242 contains parsing methods for all basic token types found in
247 At the basic level, there are tokens & tspecials (rfc2045),
248 atoms & specials, quoted-strings, domain-literals (all rfc822) and
249 encoded-words (rfc2047).
251 As a special token, we have the comment. It is one of the basic
252 tokens defined in rfc822, but it's parsing relies in part on the
253 basic token parsers (e.g. comments may contain encoded-words).
254 Also, most upper-level parsers (notably those for phrase and
255 dot-atom) choose to ignore any comment when parsing.
257 Then there are the real composite tokens, which are made up of one
258 or more of the basic tokens (and semantically invisible comments):
259 phrases (rfc822 with rfc2047) and dot-atoms (rfc2822).
261 This finishes the list of supported token types. Subclasses will
262 provide support for more higher-level tokens, where necessary,
265 @short Base class for structured header fields.
266 @author Marc Mutz <mutz@kde.org>
269 class KDE_EXPORT GStructured
: public Base
{
271 GStructured() : Base() {}
272 GStructured( Content
* p
) : Base( p
) {}
273 GStructured( Content
* p
, const QCString
& s
)
274 : Base( p
) { from7BitString(s
); }
275 GStructured( Content
* p
, const QString
& s
, const QCString
& cs
)
276 : Base( p
) { fromUnicodeString( s
, cs
); }
282 // the assembly squad:
284 bool writeAtom( char* & dcursor
, const char * const dend
, const QString
& input
);
285 bool writeAtom( char* & dcursor
, const char * const dend
,
286 const QPair
<const char*,int> & input
);
287 bool writeToken( char* & dcursor
, const char * const dend
, const QString
& input
);
288 bool writeToken( char* & dcursor
, const char * const dend
,
289 const QPair
<const char*int> & input
);
291 bool writeGenericQuotedString( char* & dcursor
, const char * const dend
,
292 const QString
& input
, bool withCRLF
=false );
293 bool writeComment( char* & dcursor
, const char * const dend
,
294 const QString
& input
, bool withCRLF
=false );
295 bool writePhrase( char* & dcursor
, const char * const dend
,
296 const QString
& input
, bool withCRLF
=false );
297 bool writeDotAtom( char* & dcursor
, const char * const dend
,
298 const QString
& input
, bool withCRLF
=false );
303 class KDE_EXPORT GAddress
: public GStructured
{
305 GAddress() : GStructured() {}
306 GAddress( Content
* p
) : GStructured( p
) {}
307 GAddress( Content
* p
, const QCString
& s
)
308 : GStructured( p
) { from7BitString(s
); }
309 GAddress( Content
* p
, const QString
& s
, const QCString
& cs
)
310 : GStructured( p
) { fromUnicodeString( s
, cs
); }
317 /** Base class for headers that deal with (possibly multiple)
318 addresses, but don't allow groups: */
319 class KDE_EXPORT MailboxList
: public GAddress
{
321 MailboxList() : GAddress() {}
322 MailboxList( Content
* p
) : GAddress( p
) {}
323 MailboxList( Content
* p
, const QCString
& s
)
324 : GAddress( p
) { from7BitString(s
); }
325 MailboxList( Content
* p
, const QString
& s
, const QCString
& cs
)
326 : GAddress( p
) { fromUnicodeString( s
, cs
); }
330 bool parse( const char* & scursor
, const char * const send
, bool isCRLF
=false );
332 /** The list of mailboxes */
333 QValueList
<Types::Mailbox
> mMailboxList
;
337 /** Base class for headers that deal with exactly one mailbox
339 mk_parsing_subclass(SingleMailbox
,MailboxList
);
341 /** Base class for headers that deal with (possibly multiple)
342 addresses, allowing groups. */
343 class KDE_EXPORT AddressList
: public GAddress
{
345 AddressList() : GAddress() {}
346 AddressList( Content
* p
) : GAddress( p
) {}
347 AddressList( Content
* p
, const QCString
& s
)
348 : GAddress( p
) { from7BitString(s
); }
349 AddressList( Content
* p
, const QString
& s
, const QCString
& cs
)
350 : GAddress( p
) { fromUnicodeString( s
, cs
); }
354 bool parse( const char* & scursor
, const char * const send
, bool isCRLF
=false );
356 /** The list of addresses */
357 QValueList
<Types::Address
> mAddressList
;
360 /** Base class for headers which deal with a list of msg-id's */
361 class KDE_EXPORT GIdent
: public GAddress
{
363 GIdent() : GAddress() {}
364 GIdent( Content
* p
) : GAddress( p
) {}
365 GIdent( Content
* p
, const QCString
& s
)
366 : GAddress( p
) { from7BitString(s
); }
367 GIdent( Content
* p
, const QString
& s
, const QCString
& cs
)
368 : GAddress( p
) { fromUnicodeString( s
, cs
); }
372 bool parse( const char* & scursor
, const char * const send
, bool isCRLF
=false );
374 /** The list of msg-id's */
375 QValueList
<Types::AddrSpec
> mMsgIdList
;
378 /** Base class for headers which deal with a list of msg-id's */
379 mk_parsing_subclass(GSingleIdent
,GIdent
);
381 /** Base class for headers which deal with a single atom. */
382 class KDE_EXPORT GToken
: public GStructured
{
384 GToken() : GStructured() {}
385 GToken( Content
* p
) : GStructured( p
) {}
386 GToken( Content
* p
, const QCString
& s
)
387 : GStructured( p
) { from7BitString(s
); }
388 GToken( Content
* p
, const QString
& s
, const QCString
& cs
)
389 : GStructured( p
) { fromUnicodeString( s
, cs
); }
393 bool parse( const char* & scursor
, const char * const send
, bool isCRLF
=false );
399 class KDE_EXPORT GPhraseList
: public GStructured
{
401 GPhraseList() : GStructured() {}
402 GPhraseList( Content
* p
) : GStructured( p
) {}
403 GPhraseList( Content
* p
, const QCString
& s
)
404 : GStructured( p
) { from7BitString(s
); }
405 GPhraseList( Content
* p
, const QString
& s
, const QCString
& cs
)
406 : GStructured( p
) { fromUnicodeString( s
, cs
); }
410 bool parse( const char* & scursor
, const char * const send
, bool isCRLF
=false );
412 QStringList mPhraseList
;
415 class KDE_EXPORT GDotAtom
: public GStructured
{
417 GDotAtom() : GStructured() {}
418 GDotAtom( Content
* p
) : GStructured( p
) {}
419 GDotAtom( Content
* p
, const QCString
& s
)
420 : GStructured( p
) { from7BitString(s
); }
421 GDotAtom( Content
* p
, const QString
& s
, const QCString
& cs
)
422 : GStructured( p
) { fromUnicodeString( s
, cs
); }
426 bool parse( const char* & scursor
, const char * const send
, bool isCRLF
=false );
431 class KDE_EXPORT GParametrized
: public GStructured
{
433 GParametrized() : GStructured() {}
434 GParametrized( Content
* p
) : GStructured( p
) {}
435 GParametrized( Content
* p
, const QCString
& s
)
436 : GStructured( p
) { from7BitString(s
); }
437 GParametrized( Content
* p
, const QString
& s
, const QCString
& cs
)
438 : GStructured( p
) { fromUnicodeString( s
, cs
); }
442 QMap
<QString
,QString
> mParameterHash
;
447 class KDE_EXPORT GContentType
: public GParametrized
{
449 GContentType() : GParametrized() {}
450 GContentType( Content
* p
) : GParametrized( p
) {}
451 GContentType( Content
* p
, const QCString
& s
)
452 : GParametrized( p
) { from7BitString(s
); }
453 GContentType( Content
* p
, const QString
& s
, const QCString
& cs
)
454 : GParametrized( p
) { fromUnicodeString( s
, cs
); }
458 bool parse( const char* & scursor
, const char * const send
, bool isCRLF
=false );
461 QCString mMimeSubType
;
465 class KDE_EXPORT GCISTokenWithParameterList
: public GParametrized
{
467 GCISTokenWithParameterList() : GParametrized() {}
468 GCISTokenWithParameterList( Content
* p
) : GParametrized( p
) {}
469 GCISTokenWithParameterList( Content
* p
, const QCString
& s
)
470 : GParametrized( p
) { from7BitString(s
); }
471 GCISTokenWithParameterList( Content
* p
, const QString
& s
, const QCString
& cs
)
472 : GParametrized( p
) { fromUnicodeString( s
, cs
); }
473 ~GCISTokenWithParameterList() {}
476 bool parse( const char* & scursor
, const char * const send
, bool isCRLF
=false );
482 } // namespace Generics
486 // INCOMPATIBLE, GSTRUCTURED-BASED FIELDS:
491 /** Represents the Return-Path header field. */
492 class KDE_EXPORT ReturnPath
: public Generics::GAddress
{
494 ReturnPath() : Generics::GAddress() {}
495 ReturnPath( Content
* p
) : Generics::GAddress( p
) {}
496 ReturnPath( Content
* p
, const QCString
& s
)
497 : Generics::GAddress( p
) { from7BitString(s
); }
498 ReturnPath( Content
* p
, const QString
& s
, const QCString
& cs
)
499 : Generics::GAddress( p
) { fromUnicodeString( s
, cs
); }
502 const char * type() const { return "Return-Path"; }
505 bool parse( const char* & scursor
, const char * const send
, bool isCRLF
=false );
508 #if defined(KMIME_NEW_STYLE_CLASSTREE)
509 // classes whose names collide with earlier ones:
513 // rfc(2)822 headers:
514 mk_trivial_subclass(From
,MailboxList
);
515 mk_trivial_subclass(Sender
,SingleMailbox
);
516 mk_trivial_subclass_with_name(ReplyTo
,Reply
-To
,AddressList
);
517 mk_trivial_subclass(Cc
,AddressList
);
518 mk_trivial_subclass(Bcc
,AddressList
);
520 mk_trivial_subclass_with_name(MailCopiesTo
,Mail
-Copies
-To
,AddressList
);
524 mk_trivial_subclass_with_name(ContentTransferEncoding
,
525 Content
-Transfer
-Encoding
,GToken
);
529 mk_trivial_subclass(Keywords
,GPhraseList
);
533 mk_trivial_subclass_with_name(MIMEVersion
,MIME
-Version
,GDotAtom
);
537 mk_trivial_subclass_with_name(MessageID
,Message
-ID
,GSingleIdent
);
538 mk_trivial_subclass_with_name(ContentID
,Content
-ID
,GSingleIdent
);
539 mk_trivial_subclass(Supersedes
,GSingleIdent
);
540 mk_trivial_subclass_with_name(InReplyTo
,In
-Reply
-To
,GIdent
);
541 mk_trivial_subclass(References
,GIdent
);
545 mk_trivial_subclass_with_name(ContentType
,ContentType
,GContentType
);
547 // GCISTokenWithParameterList:
549 mk_trivial_subclass_with_name(ContentDisposition
,Content
-Disposition
,
550 GCISTokenWithParameterList
);
558 // COMPATIBLE GUNSTRUCTURED-BASED FIELDS:
563 /** Represents an arbitrary header, that can contain
565 Adds a type over GUnstructured.
568 class KDE_EXPORT Generic
: public Generics::GUnstructured
{
571 Generic() : Generics::GUnstructured(), t_ype(0) {}
572 Generic(const char *t
)
573 : Generics::GUnstructured(), t_ype(0) { setType(t
); }
574 Generic(const char *t
, Content
*p
)
575 : Generics::GUnstructured( p
), t_ype(0) { setType(t
); }
576 Generic(const char *t
, Content
*p
, const QCString
&s
)
577 : Generics::GUnstructured( p
, s
), t_ype(0) { setType(t
); }
578 Generic(const char *t
, Content
*p
, const QString
&s
, const QCString
&cs
)
579 : Generics::GUnstructured( p
, s
, cs
), t_ype(0) { setType(t
); }
580 ~Generic() { delete[] t_ype
; }
582 virtual void clear() { delete[] t_ype
; GUnstructured::clear(); }
583 virtual bool isEmpty() { return (t_ype
==0 || GUnstructured::isEmpty()); }
584 virtual const char* type() { return t_ype
; }
585 void setType(const char *type
);
593 /** Represents a "Subject" header */
594 class KDE_EXPORT Subject
: public Generics::GUnstructured
{
597 Subject() : Generics::GUnstructured() {}
598 Subject( Content
* p
) : Generics::GUnstructured( p
) {}
599 Subject( Content
* p
, const QCString
& s
)
600 : Generics::GUnstructured( p
, s
) {}
601 Subject( Content
* p
, const QString
& s
, const QCString
& cs
)
602 : Generics::GUnstructured( p
, s
, cs
) {}
605 virtual const char* type() { return "Subject"; }
608 return ( asUnicodeString().find( QString("Re:"), 0, false ) == 0 );
612 /** Represents a "Organization" header */
613 class KDE_EXPORT Organization
: public Generics::GUnstructured
{
616 Organization() : Generics::GUnstructured() {}
617 Organization( Content
* p
) : Generics::GUnstructured( p
) {}
618 Organization( Content
* p
, const QCString
& s
)
619 : Generics::GUnstructured( p
, s
) {};
620 Organization( Content
* p
, const QString
& s
, const QCString
& cs
)
621 : Generics::GUnstructured( p
, s
, cs
) {}
624 virtual const char* type() { return "Organization"; }
630 // NOT YET CONVERTED STUFF BELOW:
636 /** Represents a "Control" header */
637 class KDE_EXPORT Control
: public Base
{
640 Control() : Base() {}
641 Control(Content
*p
) : Base(p
) {}
642 Control(Content
*p
, const QCString
&s
) : Base(p
) { from7BitString(s
); }
643 Control(Content
*p
, const QString
&s
) : Base(p
) { fromUnicodeString(s
, Latin1
); }
646 virtual void from7BitString(const QCString
&s
);
647 virtual QCString
as7BitString(bool incType
=true);
648 virtual void fromUnicodeString(const QString
&s
, const QCString
&);
649 virtual QString
asUnicodeString();
650 virtual void clear() { c_trlMsg
.truncate(0); }
651 virtual bool isEmpty() { return (c_trlMsg
.isEmpty()); }
652 virtual const char* type() { return "Control"; }
654 bool isCancel() { return (c_trlMsg
.find("cancel", 0, false)!=-1); }
661 /** Represents a "Date" header */
662 class KDE_EXPORT Date
: public Base
{
665 Date() : Base(), t_ime(0) {}
666 Date(Content
*p
) : Base(p
), t_ime(0) {}
667 Date(Content
*p
, time_t t
) : Base(p
), t_ime(t
) {}
668 Date(Content
*p
, const QCString
&s
) : Base(p
) { from7BitString(s
); }
669 Date(Content
*p
, const QString
&s
) : Base(p
) { fromUnicodeString(s
, Latin1
); }
672 virtual void from7BitString(const QCString
&s
);
673 virtual QCString
as7BitString(bool incType
=true);
674 virtual void fromUnicodeString(const QString
&s
, const QCString
&);
675 virtual QString
asUnicodeString();
676 virtual void clear() { t_ime
=0; }
677 virtual bool isEmpty() { return (t_ime
==0); }
678 virtual const char* type() { return "Date"; }
680 time_t unixTime() { return t_ime
; }
681 void setUnixTime(time_t t
) { t_ime
=t
; }
682 void setUnixTime() { t_ime
=time(0); }
692 /** Represents a "Newsgroups" header */
693 class KDE_EXPORT Newsgroups
: public Base
{
696 Newsgroups() : Base() {}
697 Newsgroups(Content
*p
) : Base(p
) {}
698 Newsgroups(Content
*p
, const QCString
&s
) : Base(p
) { from7BitString(s
); }
699 Newsgroups(Content
*p
, const QString
&s
) : Base(p
) { fromUnicodeString(s
, Latin1
); }
702 virtual void from7BitString(const QCString
&s
);
703 virtual QCString
as7BitString(bool incType
=true);
704 virtual void fromUnicodeString(const QString
&s
, const QCString
&);
705 virtual QString
asUnicodeString();
706 virtual void clear() { g_roups
.resize(0); }
707 virtual bool isEmpty() { return g_roups
.isEmpty(); }
708 virtual const char* type() { return "Newsgroups"; }
710 QCString
firstGroup();
711 bool isCrossposted() { return ( g_roups
.find(',')>-1 ); }
712 QStringList
getGroups();
720 /** Represents a "Followup-To" header */
721 class KDE_EXPORT FollowUpTo
: public Newsgroups
{
724 FollowUpTo() : Newsgroups() {}
725 FollowUpTo(Content
*p
) : Newsgroups(p
) {}
726 FollowUpTo(Content
*p
, const QCString
&s
) : Newsgroups(p
,s
) {}
727 FollowUpTo(Content
*p
, const QString
&s
) : Newsgroups(p
,s
) {}
730 virtual const char* type() { return "Followup-To"; }
735 /** Represents a "Lines" header */
736 class KDE_EXPORT Lines
: public Base
{
739 Lines() : Base(),l_ines(-1) {}
740 Lines(Content
*p
) : Base(p
),l_ines(-1) {}
741 Lines(Content
*p
, unsigned int i
) : Base(p
),l_ines(i
) {}
742 Lines(Content
*p
, const QCString
&s
) : Base(p
) { from7BitString(s
); }
743 Lines(Content
*p
, const QString
&s
) : Base(p
) { fromUnicodeString(s
, Latin1
); }
746 virtual void from7BitString(const QCString
&s
);
747 virtual QCString
as7BitString(bool incType
=true);
748 virtual void fromUnicodeString(const QString
&s
, const QCString
&);
749 virtual QString
asUnicodeString();
750 virtual void clear() { l_ines
=-1; }
751 virtual bool isEmpty() { return (l_ines
==-1); }
752 virtual const char* type() { return "Lines"; }
754 int numberOfLines() { return l_ines
; }
755 void setNumberOfLines(int i
) { l_ines
=i
; }
764 /** Represents a "User-Agent" header */
765 class KDE_EXPORT UserAgent
: public Base
{
768 UserAgent() : Base() {}
769 UserAgent(Content
*p
) : Base(p
) {}
770 UserAgent(Content
*p
, const QCString
&s
) : Base(p
) { from7BitString(s
); }
771 UserAgent(Content
*p
, const QString
&s
) : Base(p
) { fromUnicodeString(s
, Latin1
); }
774 virtual void from7BitString(const QCString
&s
);
775 virtual QCString
as7BitString(bool incType
=true);
776 virtual void fromUnicodeString(const QString
&s
, const QCString
&);
777 virtual QString
asUnicodeString();
778 virtual void clear() { u_agent
.resize(0); }
779 virtual bool isEmpty() { return (u_agent
.isEmpty()); }
780 virtual const char* type() { return "User-Agent"; }
788 #if !defined(KMIME_NEW_STYLE_CLASSTREE)
789 #include "kmime_headers_obs.h"
791 } //namespace Headers
794 typedef Headers::Base
* (*headerCreator
)(void);
796 /** This is a factory for KMime::Headers. You can create new header
797 objects by type with @ref create and @ref upgrade an existing
798 @ref Headers::Generic to a specialized header object.
800 If you are a header class author, you can register your class
801 (let's call it Foo) so:
806 @short Factory for KMime::Headers
807 @author Marc Mutz <mutz@kde.org>
808 @see KMime::Headers::Base KMime::Headers::Generic
811 class HeaderFactory
: public QAsciiDict
<headerCreator
>
819 /** Create a new header object of type @p aType, or a fitting
820 generic substitute, if available and known
822 static Headers::Base
* create( const char* aType
)
825 s_elf
= new HeaderFactory
;
826 headerCreator
* hc
= (*s_elf
)[aType
];
833 /** This is a wrapper around the above function, provided for
834 convenience. It differs from the above only in what arguments it
837 static Headers::Base
* create( const QCString
& aType
)
839 return create( aType
.data() );
842 /** Consume @p aType and build a header object that corresponds to
843 the type that @p aType->type() returns.
844 @param aType generic header to upgrade. This will be deleted
845 if necessary, so don't use references to it after
846 calling this function.
847 @return A corresponding header object (if available), or a generic
848 object for this kind of header (if known), or @p aType (else).
849 @see Headers::Generic create
851 static Headers::Base
* upgrade( Headers::Generic
* aType
) { (void)aType
; return new Headers::Base
; }
860 #endif // __KMIME_HEADERS_H__