15#ifndef __KMIME_HEADERS_H__
16#define __KMIME_HEADERS_H__
25#include "kmime_header_parsing.h"
29#include <tqstringlist.h>
31#include <tqdatetime.h>
32#include <tqasciidict.h>
48enum contentCategory { CCsingle,
53enum contentEncoding { CE7Bit,
60enum contentDisposition { CDinline,
65static const TQCString Latin1( "ISO-8859-1");
67#define mk_trivial_subclass_with_name( subclass, subclassName, baseclass ) \
68class subclass : public Generics::baseclass { \
70 subclass() : Generics::baseclass() {} \
71 subclass( Content * p ) : Generics::baseclass( p ) {} \
72 subclass( Content * p, const TQCString & s ) \
73 : Generics::baseclass( p ) { from7BitString( s ); } \
74 subclass( Content * p, const TQString & s, const TQCString & cs ) \
75 : Generics::baseclass( p ) { fromUnicodeString( s, cs ); } \
78 const char * type() const { return #subclassName; } \
81#define mk_trivial_subclass( subclass, baseclass ) \
82mk_trivial_subclass_with_name( subclass, subclass, baseclass )
84#define mk_parsing_subclass_with_name( subclass, subclassName, baseclass ) \
85class subclass : public Generics::baseclass { \
87 subclass() : Generics::baseclass() {} \
88 subclass( Content * p ) : Generics::baseclass( p ) {} \
89 subclass( Content * p, const TQCString & s ) \
90 : Generics::baseclass( p ) { from7BitString( s ); } \
91 subclass( Content * p, const TQString & s, const TQCString & 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 ) \
101mk_parsing_subclass_with_name( subclass, subclass, baseclass )
114 typedef TQPtrList<Base> List;
117 Base() : e_ncCS(0), p_arent(0) {}
141 TQCString rfc2047Charset();
144 void setRFC2047Charset( const TQCString &cs);
166 virtual const char* type() { return ""; }
169 bool is( const char* t) { return (strcasecmp(t, type())==0); }
178 TQCString typeIntro() { return (TQCString(type())+ ": "); }
216class TDE_EXPORT GUnstructured : public Base {
219 GUnstructured() : Base() {}
221 GUnstructured( Content * p, const TQCString & s )
223 GUnstructured( Content * p, const TQString & s, const TQCString & cs )
227 virtual void from7BitString( const TQCString& str );
228 virtual TQCString as7BitString( bool withHeaderType= true );
230 virtual void fromUnicodeString( const TQString & str,
231 const TQCString & suggestedCharset);
232 virtual TQString asUnicodeString();
234 virtual void clear() { d_ecoded.truncate(0); }
235 virtual bool isEmpty() { return (d_ecoded.isEmpty()); }
269class TDE_EXPORT GStructured : public Base {
271 GStructured() : Base() {}
273 GStructured( Content * p, const TQCString & s )
275 GStructured( Content * p, const TQString & s, const TQCString & cs )
284 bool writeAtom( char* & dcursor, const char * const dend, const TQString & input );
285 bool writeAtom( char* & dcursor, const char * const dend,
286 const TQPair<const char*,int> & input );
287 bool writeToken( char* & dcursor, const char * const dend, const TQString & input );
288 bool writeToken( char* & dcursor, const char * const dend,
289 const TQPair<const char*int> & input );
291 bool writeGenericQuotedString( char* & dcursor, const char * const dend,
292 const TQString & input, bool withCRLF= false );
293 bool writeComment( char* & dcursor, const char * const dend,
294 const TQString & input, bool withCRLF= false );
295 bool writePhrase( char* & dcursor, const char * const dend,
296 const TQString & input, bool withCRLF= false );
297 bool writeDotAtom( char* & dcursor, const char * const dend,
298 const TQString & input, bool withCRLF= false );
303class TDE_EXPORT GAddress : public GStructured {
305 GAddress() : GStructured() {}
306 GAddress( Content * p ) : GStructured( p ) {}
307 GAddress( Content * p, const TQCString & s )
308 : GStructured( p ) { from7BitString(s); }
309 GAddress( Content * p, const TQString & s, const TQCString & cs )
310 : GStructured( p ) { fromUnicodeString( s, cs ); }
319class TDE_EXPORT MailboxList : public GAddress {
321 MailboxList() : GAddress() {}
322 MailboxList( Content * p ) : GAddress( p ) {}
323 MailboxList( Content * p, const TQCString & s )
325 MailboxList( Content * p, const TQString & s, const TQCString & cs )
330 bool parse( const char* & scursor, const char * const send, bool isCRLF= false );
343class TDE_EXPORT AddressList : public GAddress {
345 AddressList() : GAddress() {}
346 AddressList( Content * p ) : GAddress( p ) {}
347 AddressList( Content * p, const TQCString & s )
349 AddressList( Content * p, const TQString & s, const TQCString & cs )
354 bool parse( const char* & scursor, const char * const send, bool isCRLF= false );
361class TDE_EXPORT GIdent : public GAddress {
363 GIdent() : GAddress() {}
364 GIdent( Content * p ) : GAddress( p ) {}
365 GIdent( Content * p, const TQCString & s )
367 GIdent( Content * p, const TQString & s, const TQCString & cs )
372 bool parse( const char* & scursor, const char * const send, bool isCRLF= false );
379mk_parsing_subclass(GSingleIdent, GIdent);
382class TDE_EXPORT GToken : public GStructured {
384 GToken() : GStructured() {}
385 GToken( Content * p ) : GStructured( p ) {}
386 GToken( Content * p, const TQCString & s )
388 GToken( Content * p, const TQString & s, const TQCString & cs )
393 bool parse( const char* & scursor, const char * const send, bool isCRLF= false );
402 GPhraseList( Content * p ) : GStructured( p ) {}
403 GPhraseList( Content * p, const TQCString & s )
404 : GStructured( p ) { from7BitString(s); }
405 GPhraseList( Content * p, const TQString & s, const TQCString & cs )
406 : GStructured( p ) { fromUnicodeString( s, cs ); }
410 bool parse( const char* & scursor, const char * const send, bool isCRLF= false );
412 TQStringList mPhraseList;
417 GDotAtom() : GStructured() {}
418 GDotAtom( Content * p ) : GStructured( p ) {}
419 GDotAtom( Content * p, const TQCString & s )
420 : GStructured( p ) { from7BitString(s); }
421 GDotAtom( Content * p, const TQString & s, const TQCString & cs )
422 : GStructured( p ) { fromUnicodeString( s, cs ); }
426 bool parse( const char* & scursor, const char * const send, bool isCRLF= false );
431class TDE_EXPORT GParametrized : public GStructured {
433 GParametrized() : GStructured() {}
434 GParametrized( Content * p ) : GStructured( p ) {}
435 GParametrized( Content * p, const TQCString & s )
436 : GStructured( p ) { from7BitString(s); }
437 GParametrized( Content * p, const TQString & s, const TQCString & cs )
438 : GStructured( p ) { fromUnicodeString( s, cs ); }
442 TQMap<TQString,TQString> mParameterHash;
447class TDE_EXPORT GContentType : public GParametrized {
449 GContentType() : GParametrized() {}
450 GContentType( Content * p ) : GParametrized( p ) {}
451 GContentType( Content * p, const TQCString & s )
452 : GParametrized( p ) { from7BitString(s); }
453 GContentType( Content * p, const TQString & s, const TQCString & cs )
454 : GParametrized( p ) { fromUnicodeString( s, cs ); }
458 bool parse( const char* & scursor, const char * const send, bool isCRLF= false );
461 TQCString mMimeSubType;
465class TDE_EXPORT GCISTokenWithParameterList : public GParametrized {
467 GCISTokenWithParameterList() : GParametrized() {}
468 GCISTokenWithParameterList( Content * p ) : GParametrized( p ) {}
469 GCISTokenWithParameterList( Content * p, const TQCString & s )
470 : GParametrized( p ) { from7BitString(s); }
471 GCISTokenWithParameterList( Content * p, const TQString & s, const TQCString & cs )
472 : GParametrized( p ) { fromUnicodeString( s, cs ); }
473 ~GCISTokenWithParameterList() {}
476 bool parse( const char* & scursor, const char * const send, bool isCRLF= false );
492class TDE_EXPORT ReturnPath : public Generics::GAddress {
494 ReturnPath() : Generics::GAddress() {}
495 ReturnPath( Content * p ) : Generics::GAddress( p ) {}
496 ReturnPath( Content * p, const TQCString & s )
498 ReturnPath( Content * p, const TQString & s, const TQCString & 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)
514mk_trivial_subclass( From,MailboxList);
515mk_trivial_subclass(Sender,SingleMailbox);
516mk_trivial_subclass_with_name( ReplyTo,Reply- To,AddressList);
517mk_trivial_subclass(Cc,AddressList);
518mk_trivial_subclass(Bcc,AddressList);
520mk_trivial_subclass_with_name( MailCopiesTo,Mail-Copies- To,AddressList);
524mk_trivial_subclass_with_name(ContentTransferEncoding,
525 Content-Transfer-Encoding,GToken);
529mk_trivial_subclass(Keywords,GPhraseList);
533mk_trivial_subclass_with_name(MIMEVersion,MIME-Version,GDotAtom);
537mk_trivial_subclass_with_name( MessageID,Message-ID,GSingleIdent);
538mk_trivial_subclass_with_name(ContentID, Content-ID,GSingleIdent);
540mk_trivial_subclass_with_name(InReplyTo,In-Reply- To,GIdent);
549mk_trivial_subclass_with_name(ContentDisposition, Content-Disposition,
550 GCISTokenWithParameterList);
572 Generic( const char *t)
574 Generic( const char *t, Content *p)
576 Generic( const char *t, Content *p, const TQCString &s)
578 Generic( const char *t, Content *p, const TQString &s, const TQCString &cs)
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);
599 Subject( Content * p, const TQCString & s )
601 Subject( Content * p, const TQString & s, const TQCString & cs )
605 virtual const char* type() { return "Subject"; }
608 return ( asUnicodeString().find( TQString( "Re:"), 0, false ) == 0 );
618 Organization( Content * p, const TQCString & s )
620 Organization( Content * p, const TQString & s, const TQCString & cs)
624 virtual const char* type() { return "Organization"; }
637class TDE_EXPORT Control : public Base {
640 Control() : Base() {}
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); }
662class TDE_EXPORT Date : public Base {
665 Date() : Base(), 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); }
693class TDE_EXPORT Newsgroups : public Base {
696 Newsgroups() : Base() {}
706 virtual void clear() { g_roups.resize(0); }
707 virtual bool isEmpty() { return g_roups.isEmpty(); }
708 virtual const char* type() { return "Newsgroups"; }
710 TQCString firstGroup();
711 bool isCrossposted() { return ( g_roups.find( ',')>-1 ); }
712 TQStringList getGroups();
721class TDE_EXPORT FollowUpTo : public Newsgroups {
724 FollowUpTo() : Newsgroups() {}
725 FollowUpTo( Content *p) : Newsgroups(p) {}
726 FollowUpTo( Content *p, const TQCString &s) : Newsgroups(p,s) {}
727 FollowUpTo( Content *p, const TQString &s) : Newsgroups(p,s) {}
730 virtual const char* type() { return "Followup-To"; }
736class TDE_EXPORT Lines : public Base {
739 Lines() : Base(),l_ines(-1) {}
741 Lines( Content *p, unsigned int i) : Base(p),l_ines(i) {}
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; }
765class TDE_EXPORT UserAgent : public Base {
768 UserAgent() : Base() {}
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"
794typedef Headers::Base* (*headerCreator)(void);
811class HeaderFactory : public TQAsciiDict<headerCreator>
822 static Headers::Base* create( const char* aType )
825 s_elf = new HeaderFactory;
826 headerCreator * hc = (*s_elf)[aType];
837 static Headers::Base* create( const TQCString& aType )
839 return create( aType.data() );
851 static Headers::Base* upgrade( Headers::Generic* aType ) { (void)aType; return new Headers::Base; }
This class encapsulates a mime-encoded content.
|