• Skip to content
  • Skip to link menu
KDE 4.4 API Reference
  • KDE API Reference
  • KDE-PIM Libraries
  • Sitemap
  • Contact Us
 

KMIME Library

kmime_content.h

Go to the documentation of this file.
00001 /*
00002     kmime_content.h
00003 
00004     KMime, the KDE Internet mail/usenet news message library.
00005     Copyright (c) 2001 the KMime authors.
00006     See file AUTHORS for details
00007     Copyright (c) 2006 Volker Krause <vkrause@kde.org>
00008     Copyright (c) 2009 Constantin Berzan <exit3219@gmail.com>
00009 
00010     This library is free software; you can redistribute it and/or
00011     modify it under the terms of the GNU Library General Public
00012     License as published by the Free Software Foundation; either
00013     version 2 of the License, or (at your option) any later version.
00014 
00015     This library is distributed in the hope that it will be useful,
00016     but WITHOUT ANY WARRANTY; without even the implied warranty of
00017     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018     Library General Public License for more details.
00019 
00020     You should have received a copy of the GNU Library General Public License
00021     along with this library; see the file COPYING.LIB.  If not, write to
00022     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00023     Boston, MA 02110-1301, USA.
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   KDE5:
00083   * Do not convert singlepart <-> multipart automatically.
00084   * A bunch of methods probably don't need to be virtual (since they're not needed
00085     in either Message or NewsArticle).
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 ); // KDE5: Merge with the above.
00107 
00114     Content( const QByteArray &head, const QByteArray &body );
00115 
00124     // KDE5: Merge with the above.
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     // KDE5: make non-virtual.
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     // KDE5: Remove this. This method has nothing to do with *this object.
00259     KDE_DEPRECATED Headers::Generic *nextHeader( QByteArray &head );
00260 
00265     // KDE5: Make non-virtual.
00266     KDE_DEPRECATED virtual Headers::Base *getHeaderByType( const char *type );
00267 
00273     // KDE5: Make non-virtual.
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     // KDE5: make non-virtual.
00305     virtual void setHeader( Headers::Base *h );
00306 
00312     void appendHeader( Headers::Base *h );
00313 
00319     void prependHeader( Headers::Base *h );
00320 
00327     // TODO probably provide removeHeader<T>() too.
00328     // KDE5: make non-virtual.
00329     virtual bool removeHeader( const char *type );
00330 
00335     // TODO probably provide hasHeader<T>() too.
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     // TODO: KDE5: BIC: Rename this to decodedBody(), since only the body is returned.
00428     // In contrast, setContent() sets the head and the body!
00429     // Also, try to make this const.
00430     QByteArray decodedContent();
00431 
00445     // TODO: KDE5: BIC: Convert to enums. Also, what if trimText = true but removeTrailingNewlines
00446     //                  is false?
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     // KDE5: Do not convert single-part->multipart automatically.
00491     void addContent( Content *content, bool prepend = false );
00492 
00509     // KDE5: Do not convert multipart->single-part automatically.
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     // NOTE: The charset methods below are accessed by the headers which
00530     // have this Content as a parent.
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     // KDE5: Not needed outside. Move to Private class.
00640     bool decodeText();
00641 
00646     template <class T> KDE_DEPRECATED T *headerInstance( T *ptr, bool create );
00647 
00652     // KDE5: Not needed outside. Move to Private class.
00653     Headers::Base::List h_eaders;
00654 
00655     //@cond PRIVATE
00656     ContentPrivate *d_ptr;
00657     explicit Content( ContentPrivate *d );
00658     //@endcond
00659 
00660   private:
00661     Q_DECLARE_PRIVATE( Content )
00662     Q_DISABLE_COPY( Content )
00663 };
00664 
00665 // some compilers (for instance Compaq C++) need template inline functions
00666 // here rather than in the *.cpp file
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     // Make sure the header is actually of the right type.
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 } // namespace KMime
00688 
00689 #endif // __KMIME_CONTENT_H__

KMIME Library

Skip menu "KMIME Library"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

KDE-PIM Libraries

Skip menu "KDE-PIM Libraries"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kblog
  • kcal
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Generated for KDE-PIM Libraries by doxygen 1.6.2-20100208
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal