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
00045 #ifndef __KMIME_CONTENT_H__
00046 #define __KMIME_CONTENT_H__
00047
00048 #include <QtCore/QTextStream>
00049 #include <QtCore/QByteArray>
00050 #include <QtCore/QList>
00051
00052 #include "kmime_export.h"
00053 #include "kmime_contentindex.h"
00054 #include "kmime_util.h"
00055 #include "kmime_headers.h"
00056
00057 namespace KMime {
00058
00059 class ContentPrivate;
00060
00068 class KMIME_EXPORT Content
00069 {
00070 public:
00071
00072 typedef QList<KMime::Content*> List;
00073
00077 Content();
00078
00084 explicit Content( Content* parent );
00085
00092 Content( const QByteArray &head, const QByteArray &body );
00093
00102 Content( const QByteArray &head, const QByteArray &body, Content *parent );
00103
00107 virtual ~Content();
00108
00112 bool hasContent() const;
00113
00120 void setContent( const QList<QByteArray> &l );
00121
00128 void setContent( const QByteArray &s );
00129
00133 virtual void parse();
00134
00138 virtual void assemble();
00139
00143 virtual void clear();
00144
00150 QByteArray head() const;
00151
00159 void setHead( const QByteArray &head );
00160
00169 KDE_DEPRECATED Headers::Generic *getNextHeader( QByteArray &head );
00170
00177 Headers::Generic *nextHeader( QByteArray &head );
00178
00183 KDE_DEPRECATED virtual Headers::Base *getHeaderByType( const char *type );
00184
00189 virtual Headers::Base *headerByType( const char *type );
00190
00196 virtual QList<Headers::Base*> headersByType( const char *type );
00197
00198 virtual void setHeader( Headers::Base *h );
00199
00200 virtual bool removeHeader( const char *type );
00201
00202 bool hasHeader( const char *type );
00203
00209 Headers::ContentType *contentType( bool create=true );
00210
00216 Headers::ContentTransferEncoding *contentTransferEncoding( bool create=true );
00217
00223 Headers::ContentDisposition *contentDisposition( bool create=true );
00224
00230 Headers::ContentDescription *contentDescription( bool create=true );
00231
00238 Headers::ContentLocation *contentLocation( bool create=true );
00239
00240
00244 int size();
00245
00249 int storageSize() const;
00250
00254 int lineCount() const;
00255
00261 QByteArray body() const;
00262
00270 void setBody( const QByteArray &body );
00271
00278 QByteArray encodedContent( bool useCrLf = false );
00279
00283 QByteArray decodedContent();
00284
00298 QString decodedText( bool trimText = false,
00299 bool removeTrailingNewlines = false );
00300
00306 void fromUnicodeString( const QString &s );
00307
00311 Content *textContent();
00312
00318 List attachments( bool incAlternatives = false );
00319
00323 List contents() const;
00324
00337 void addContent( Content *c, bool prepend = false );
00338
00348 void removeContent( Content *c, bool del = false );
00349
00350 void changeEncoding( Headers::contentEncoding e );
00351
00359 void toStream( QTextStream &ts, bool scrambleFromLines = false );
00360
00367 QByteArray defaultCharset() const;
00368
00376 void setDefaultCharset( const QByteArray &cs );
00377
00384 bool forceDefaultCharset() const;
00385
00395 virtual void setForceDefaultCharset( bool b );
00396
00404 Content *content( const ContentIndex &index ) const;
00405
00411 ContentIndex indexForContent( Content *content ) const;
00412
00417 virtual bool isTopLevel() const;
00418
00425 void setParent( Content *parent );
00426
00431 Content* parent() const;
00432
00437 Content* topLevel() const;
00438
00443 ContentIndex index() const;
00444
00445 protected:
00451 virtual QByteArray assembleHeaders();
00452
00453 QByteArray rawHeader( const char *name ) const;
00454 QList<QByteArray> rawHeaders( const char *name ) const;
00455 bool decodeText();
00456 template <class T> T *headerInstance( T *ptr, bool create );
00457
00458 Headers::Base::List h_eaders;
00459
00460
00461 ContentPrivate *d_ptr;
00462 explicit Content( ContentPrivate *d );
00463
00464
00465 private:
00466 Q_DECLARE_PRIVATE( Content )
00467 Q_DISABLE_COPY( Content )
00468 };
00469
00470
00471
00472
00473 template <class T> T *Content::headerInstance( T *ptr, bool create )
00474 {
00475 T dummy;
00476
00477 ptr=static_cast <T*> ( headerByType( dummy.type() ) );
00478 if ( !ptr && create ) {
00479 ptr = new T( this );
00480 h_eaders.append( ptr );
00481 }
00482
00483 return ptr;
00484 }
00485
00486 }
00487
00488 #endif // __KMIME_CONTENT_H__