KMIME Library
kmime_content.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00048 #ifndef __KMIME_CONTENT_H__
00049 #define __KMIME_CONTENT_H__
00050
00051 #include <QtCore/QTextStream>
00052 #include <QtCore/QByteArray>
00053 #include <QtCore/QList>
00054
00055 #include "kmime_export.h"
00056 #include "kmime_contentindex.h"
00057 #include "kmime_util.h"
00058 #include "kmime_headers.h"
00059
00060 namespace KMime {
00061
00062 class ContentPrivate;
00063
00081
00082
00083
00084
00085
00086
00087 class KMIME_EXPORT Content
00088 {
00089 public:
00090
00094 typedef QList<KMime::Content*> List;
00095
00099 Content();
00100
00106 explicit Content( Content* parent );
00107
00114 Content( const QByteArray &head, const QByteArray &body );
00115
00124
00125 Content( const QByteArray &head, const QByteArray &body, Content *parent );
00126
00130 virtual ~Content();
00131
00135 bool hasContent() const;
00136
00146 void setContent( const QList<QByteArray> &l );
00147
00157 void setContent( const QByteArray &s );
00158
00165 virtual void parse();
00166
00176 bool isFrozen() const;
00177
00184 void setFrozen( bool frozen = true );
00185
00202 virtual void assemble();
00203
00207
00208 virtual void clear();
00209
00221 void clearContents( bool del = true );
00222
00228 QByteArray head() const;
00229
00240 void setHead( const QByteArray &head );
00241
00249 KDE_DEPRECATED Headers::Generic *getNextHeader( QByteArray &head );
00250
00258
00259 KDE_DEPRECATED Headers::Generic *nextHeader( QByteArray &head );
00260
00265
00266 KDE_DEPRECATED virtual Headers::Base *getHeaderByType( const char *type );
00267
00273
00274 virtual Headers::Base *headerByType( const char *type );
00275
00284 template <typename T> T *header( bool create = false );
00285
00291 virtual QList<Headers::Base*> headersByType( const char *type );
00292
00304
00305 virtual void setHeader( Headers::Base *h );
00306
00312 void appendHeader( Headers::Base *h );
00313
00319 void prependHeader( Headers::Base *h );
00320
00327
00328
00329 virtual bool removeHeader( const char *type );
00330
00335
00336 bool hasHeader( const char *type );
00337
00343 Headers::ContentType *contentType( bool create = true );
00344
00350 Headers::ContentTransferEncoding *contentTransferEncoding( bool create = true );
00351
00357 Headers::ContentDisposition *contentDisposition( bool create = true );
00358
00364 Headers::ContentDescription *contentDescription( bool create = true );
00365
00372 Headers::ContentLocation *contentLocation( bool create = true );
00373
00379 Headers::ContentID *contentID( bool create = true );
00380
00385 int size();
00386
00390 int storageSize() const;
00391
00395 int lineCount() const;
00396
00402 QByteArray body() const;
00403
00414 void setBody( const QByteArray &body );
00415
00422 QByteArray encodedContent( bool useCrLf = false );
00423
00427
00428
00429
00430 QByteArray decodedContent();
00431
00445
00446
00447 QString decodedText( bool trimText = false,
00448 bool removeTrailingNewlines = false );
00449
00455 void fromUnicodeString( const QString &s );
00456
00460 Content *textContent();
00461
00467 List attachments( bool incAlternatives = false );
00468
00472 List contents() const;
00473
00490
00491 void addContent( Content *content, bool prepend = false );
00492
00509
00510 void removeContent( Content *content, bool del = false );
00511
00518 void changeEncoding( Headers::contentEncoding e );
00519
00527 void toStream( QTextStream &ts, bool scrambleFromLines = false );
00528
00529
00530
00531
00538 QByteArray defaultCharset() const;
00539
00547 void setDefaultCharset( const QByteArray &cs );
00548
00555 bool forceDefaultCharset() const;
00556
00566 virtual void setForceDefaultCharset( bool b );
00567
00575 Content *content( const ContentIndex &index ) const;
00576
00582 ContentIndex indexForContent( Content *content ) const;
00583
00588 virtual bool isTopLevel() const;
00589
00596 void setParent( Content *parent );
00597
00602 Content* parent() const;
00603
00608 Content* topLevel() const;
00609
00614 ContentIndex index() const;
00615
00616 protected:
00622 virtual QByteArray assembleHeaders();
00623
00628 KDE_DEPRECATED QByteArray rawHeader( const char *name ) const;
00629
00634 KDE_DEPRECATED QList<QByteArray> rawHeaders( const char *name ) const;
00635
00639
00640 bool decodeText();
00641
00646 template <class T> KDE_DEPRECATED T *headerInstance( T *ptr, bool create );
00647
00652
00653 Headers::Base::List h_eaders;
00654
00655
00656 ContentPrivate *d_ptr;
00657 explicit Content( ContentPrivate *d );
00658
00659
00660 private:
00661 Q_DECLARE_PRIVATE( Content )
00662 Q_DISABLE_COPY( Content )
00663 };
00664
00665
00666
00667
00668 template <class T> T *Content::headerInstance( T *ptr, bool create )
00669 {
00670 return header<T>( create );
00671 }
00672
00673 template <typename T> T *Content::header( bool create )
00674 {
00675 T dummy;
00676 Headers::Base *h = headerByType( dummy.type() );
00677 if( h ) {
00678
00679 Q_ASSERT( dynamic_cast<T*>( h ) );
00680 } else if( create ) {
00681 h = new T( this );
00682 setHeader( h );
00683 }
00684 return static_cast<T*>( h );
00685 }
00686
00687 }
00688
00689 #endif // __KMIME_CONTENT_H__