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
00085 Content( const QByteArray &head, const QByteArray &body );
00086
00090 virtual ~Content();
00091
00095 bool hasContent() const;
00096
00103 void setContent( const QList<QByteArray> &l );
00104
00111 void setContent( const QByteArray &s );
00112
00116 virtual void parse();
00117
00121 virtual void assemble();
00122
00126 virtual void clear();
00127
00133 QByteArray head() const;
00134
00142 void setHead( const QByteArray &head );
00143
00152 KDE_DEPRECATED Headers::Generic *getNextHeader( QByteArray &head );
00153
00160 Headers::Generic *nextHeader( QByteArray &head );
00161
00166 KDE_DEPRECATED virtual Headers::Base *getHeaderByType( const char *type );
00167
00172 virtual Headers::Base *headerByType( const char *type );
00173
00179 virtual QList<Headers::Base*> headersByType( const char *type );
00180
00181 virtual void setHeader( Headers::Base *h );
00182
00183 virtual bool removeHeader( const char *type );
00184
00185 bool hasHeader( const char *type );
00186
00192 Headers::ContentType *contentType( bool create=true );
00193
00199 Headers::ContentTransferEncoding *contentTransferEncoding( bool create=true );
00200
00206 Headers::ContentDisposition *contentDisposition( bool create=true );
00207
00213 Headers::ContentDescription *contentDescription( bool create=true );
00214
00221 Headers::ContentLocation *contentLocation( bool create=true );
00222
00223
00227 int size();
00228
00232 int storageSize() const;
00233
00237 int lineCount() const;
00238
00244 QByteArray body() const;
00245
00253 void setBody( const QByteArray &body );
00254
00261 QByteArray encodedContent( bool useCrLf = false );
00262
00266 QByteArray decodedContent();
00267
00281 QString decodedText( bool trimText = false,
00282 bool removeTrailingNewlines = false );
00283
00289 void fromUnicodeString( const QString &s );
00290
00294 Content *textContent();
00295
00301 List attachments( bool incAlternatives = false );
00302
00306 List contents() const;
00307
00318 void addContent( Content *c, bool prepend = false );
00319
00329 void removeContent( Content *c, bool del = false );
00330
00331 void changeEncoding( Headers::contentEncoding e );
00332
00340 void toStream( QTextStream &ts, bool scrambleFromLines = false );
00341
00348 QByteArray defaultCharset() const;
00349
00357 void setDefaultCharset( const QByteArray &cs );
00358
00365 bool forceDefaultCharset() const;
00366
00376 virtual void setForceDefaultCharset( bool b );
00377
00385 Content *content( const ContentIndex &index ) const;
00386
00392 ContentIndex indexForContent( Content *content ) const;
00393
00398 virtual bool isTopLevel() const;
00399
00400 protected:
00406 virtual QByteArray assembleHeaders();
00407
00408 QByteArray rawHeader( const char *name ) const;
00409 QList<QByteArray> rawHeaders( const char *name ) const;
00410 bool decodeText();
00411 template <class T> T *headerInstance( T *ptr, bool create );
00412
00413 Headers::Base::List h_eaders;
00414
00415
00416 ContentPrivate *d_ptr;
00417 explicit Content( ContentPrivate *d );
00418
00419
00420 private:
00421 Q_DECLARE_PRIVATE( Content )
00422 Q_DISABLE_COPY( Content )
00423 };
00424
00425
00426
00427
00428 template <class T> T *Content::headerInstance( T *ptr, bool create )
00429 {
00430 T dummy;
00431
00432 ptr=static_cast <T*> ( headerByType( dummy.type() ) );
00433 if ( !ptr && create ) {
00434 ptr = new T( this );
00435 h_eaders.append( ptr );
00436 }
00437
00438 return ptr;
00439 }
00440
00441 }
00442
00443 #endif // __KMIME_CONTENT_H__