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 "kmime_export.h"
00052 #include "kmime_contentindex.h"
00053 #include "kmime_util.h"
00054 #include "kmime_headers.h"
00055
00056 #include <QtCore/QTextStream>
00057 #include <QtCore/QByteArray>
00058 #include <QtCore/QList>
00059
00060 #include <boost/shared_ptr.hpp>
00061
00062
00063 namespace KMime {
00064
00065 class ContentPrivate;
00066 class Message;
00067
00106
00107
00108
00109
00110
00111
00112 class KMIME_EXPORT Content
00113 {
00114 public:
00115
00119 typedef QList<KMime::Content*> List;
00120
00124 Content();
00125
00131 explicit Content( Content* parent );
00132
00139 Content( const QByteArray &head, const QByteArray &body );
00140
00149
00150 Content( const QByteArray &head, const QByteArray &body, Content *parent );
00151
00155 virtual ~Content();
00156
00160 bool hasContent() const;
00161
00172 void setContent( const QList<QByteArray> &l );
00173
00187 void setContent( const QByteArray &s );
00188
00207 virtual void parse();
00208
00218 bool isFrozen() const;
00219
00226 void setFrozen( bool frozen = true );
00227
00247 virtual void assemble();
00248
00252
00253 virtual void clear();
00254
00266 void clearContents( bool del = true );
00267
00273 QByteArray head() const;
00274
00285 void setHead( const QByteArray &head );
00286
00294 KDE_DEPRECATED Headers::Generic *getNextHeader( QByteArray &head );
00295
00303
00304 KDE_DEPRECATED Headers::Generic *nextHeader( QByteArray &head );
00305
00310
00311 KDE_DEPRECATED virtual Headers::Base *getHeaderByType( const char *type );
00312
00318
00319 virtual Headers::Base *headerByType( const char *type );
00320
00332 template <typename T> T *header( bool create = false );
00333
00339 virtual QList<Headers::Base*> headersByType( const char *type );
00340
00352
00353 virtual void setHeader( Headers::Base *h );
00354
00360 void appendHeader( Headers::Base *h );
00361
00367 void prependHeader( Headers::Base *h );
00368
00375
00376
00377 virtual bool removeHeader( const char *type );
00378
00383
00384
00385 bool hasHeader( const char *type );
00386
00392 Headers::ContentType *contentType( bool create = true );
00393
00399 Headers::ContentTransferEncoding *contentTransferEncoding( bool create = true );
00400
00406 Headers::ContentDisposition *contentDisposition( bool create = true );
00407
00413 Headers::ContentDescription *contentDescription( bool create = true );
00414
00421 Headers::ContentLocation *contentLocation( bool create = true );
00422
00428 Headers::ContentID *contentID( bool create = true );
00429
00435 int size();
00436
00440 int storageSize() const;
00441
00445 int lineCount() const;
00446
00455 QByteArray body() const;
00456
00467 void setBody( const QByteArray &body );
00468
00483 QByteArray encodedContent( bool useCrLf = false );
00484
00491 QByteArray encodedBody();
00492
00499
00500
00501
00502 QByteArray decodedContent();
00503
00517
00518
00519 QString decodedText( bool trimText = false,
00520 bool removeTrailingNewlines = false );
00521
00531 void fromUnicodeString( const QString &s );
00532
00536 Content *textContent();
00537
00543 List attachments( bool incAlternatives = false );
00544
00550 List contents() const;
00551
00568
00569 void addContent( Content *content, bool prepend = false );
00570
00587
00588 void removeContent( Content *content, bool del = false );
00589
00596 void changeEncoding( Headers::contentEncoding e );
00597
00605 void toStream( QTextStream &ts, bool scrambleFromLines = false );
00606
00607
00608
00609
00616 QByteArray defaultCharset() const;
00617
00625 void setDefaultCharset( const QByteArray &cs );
00626
00633 bool forceDefaultCharset() const;
00634
00644 virtual void setForceDefaultCharset( bool b );
00645
00653 Content *content( const ContentIndex &index ) const;
00654
00660 ContentIndex indexForContent( Content *content ) const;
00661
00667 virtual bool isTopLevel() const;
00668
00675 void setParent( Content *parent );
00676
00681 Content* parent() const;
00682
00687 Content* topLevel() const;
00688
00693 ContentIndex index() const;
00694
00701
00702 bool bodyIsMessage() const;
00703
00722
00723 boost::shared_ptr<Message> bodyAsMessage() const;
00724
00725 protected:
00731 virtual QByteArray assembleHeaders();
00732
00737 KDE_DEPRECATED QByteArray rawHeader( const char *name ) const;
00738
00743 KDE_DEPRECATED QList<QByteArray> rawHeaders( const char *name ) const;
00744
00748
00749 bool decodeText();
00750
00755 template <class T> KDE_DEPRECATED T *headerInstance( T *ptr, bool create );
00756
00761
00762 Headers::Base::List h_eaders;
00763
00764
00765 ContentPrivate *d_ptr;
00766 explicit Content( ContentPrivate *d );
00767
00768
00769 private:
00770 Q_DECLARE_PRIVATE( Content )
00771 Q_DISABLE_COPY( Content )
00772 };
00773
00774
00775
00776
00777 template <class T> T *Content::headerInstance( T *ptr, bool create )
00778 {
00779 return header<T>( create );
00780 }
00781
00782 template <typename T> T *Content::header( bool create )
00783 {
00784 Headers::Base *h = headerByType( T::staticType() );
00785 if( h ) {
00786
00787 Q_ASSERT( dynamic_cast<T*>( h ) );
00788 } else if( create ) {
00789 h = new T( this );
00790 setHeader( h );
00791 }
00792 return static_cast<T*>( h );
00793 }
00794
00795 }
00796
00797 #endif // __KMIME_CONTENT_H__