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 "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 KDE5: 00108 * Do not convert singlepart <-> multipart automatically. 00109 * A bunch of methods probably don't need to be virtual (since they're not needed 00110 in either Message or NewsArticle). 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 ); // KDE5: Merge with the above. 00132 00139 Content( const QByteArray &head, const QByteArray &body ); 00140 00149 // KDE5: Merge with the above. 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 // KDE5: make non-virtual. 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 // KDE5: Remove this. This method has nothing to do with *this object. 00304 KDE_DEPRECATED Headers::Generic *nextHeader( QByteArray &head ); 00305 00310 // KDE5: Make non-virtual. 00311 KDE_DEPRECATED virtual Headers::Base *getHeaderByType( const char *type ); 00312 00318 // KDE5: Make non-virtual. 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 // KDE5: make non-virtual. 00353 virtual void setHeader( Headers::Base *h ); 00354 00360 void appendHeader( Headers::Base *h ); 00361 00367 void prependHeader( Headers::Base *h ); 00368 00375 // TODO probably provide removeHeader<T>() too. 00376 // KDE5: make non-virtual. 00377 virtual bool removeHeader( const char *type ); 00378 00383 // TODO probably provide hasHeader<T>() too. 00384 // TODO: KDE5: make const 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 // TODO: KDE5: BIC: Rename this to decodedBody(), since only the body is returned. 00500 // In contrast, setContent() sets the head and the body! 00501 // Also, try to make this const. 00502 QByteArray decodedContent(); 00503 00517 // TODO: KDE5: BIC: Convert to enums. Also, what if trimText = true but removeTrailingNewlines 00518 // is false? 00519 QString decodedText( bool trimText = false, 00520 bool removeTrailingNewlines = false ); 00521 00538 void fromUnicodeString( const QString &s ); 00539 00543 Content *textContent(); 00544 00550 List attachments( bool incAlternatives = false ); 00551 00557 List contents() const; 00558 00575 // KDE5: Do not convert single-part->multipart automatically. 00576 void addContent( Content *content, bool prepend = false ); 00577 00594 // KDE5: Do not convert multipart->single-part automatically. 00595 void removeContent( Content *content, bool del = false ); 00596 00603 void changeEncoding( Headers::contentEncoding e ); 00604 00612 void toStream( QTextStream &ts, bool scrambleFromLines = false ); 00613 00614 // NOTE: The charset methods below are accessed by the headers which 00615 // have this Content as a parent. 00616 00624 // TODO: Split this up into a charset for encoding and one for decoding, and make the one for 00625 // encoding UTF-8 by default. 00626 QByteArray defaultCharset() const; 00627 00635 void setDefaultCharset( const QByteArray &cs ); 00636 00643 bool forceDefaultCharset() const; 00644 00654 virtual void setForceDefaultCharset( bool b ); 00655 00663 Content *content( const ContentIndex &index ) const; 00664 00670 ContentIndex indexForContent( Content *content ) const; 00671 00677 virtual bool isTopLevel() const; 00678 00685 void setParent( Content *parent ); 00686 00691 Content* parent() const; 00692 00697 Content* topLevel() const; 00698 00703 ContentIndex index() const; 00704 00711 //AK_REVIEW: move to MessageViewer/ObjectTreeParser 00712 bool bodyIsMessage() const; 00713 00732 //AK_REVIEW: move to MessageViewer/ObjectTreeParser 00733 boost::shared_ptr<Message> bodyAsMessage() const; 00734 00735 protected: 00741 virtual QByteArray assembleHeaders(); 00742 00747 KDE_DEPRECATED QByteArray rawHeader( const char *name ) const; 00748 00753 KDE_DEPRECATED QList<QByteArray> rawHeaders( const char *name ) const; 00754 00758 // KDE5: Not needed outside. Move to Private class. 00759 bool decodeText(); 00760 00765 template <class T> KDE_DEPRECATED T *headerInstance( T *ptr, bool create ); 00766 00771 // KDE5: Not needed outside. Move to Private class. 00772 Headers::Base::List h_eaders; 00773 00774 //@cond PRIVATE 00775 ContentPrivate *d_ptr; 00776 explicit Content( ContentPrivate *d ); 00777 //@endcond 00778 00779 private: 00780 Q_DECLARE_PRIVATE( Content ) 00781 Q_DISABLE_COPY( Content ) 00782 }; 00783 00784 // some compilers (for instance Compaq C++) need template inline functions 00785 // here rather than in the *.cpp file 00786 00787 template <class T> T *Content::headerInstance( T *ptr, bool create ) 00788 { 00789 return header<T>( create ); 00790 } 00791 00792 template <typename T> T *Content::header( bool create ) 00793 { 00794 Headers::Base *h = headerByType( T::staticType() ); 00795 if( h ) { 00796 // Make sure the header is actually of the right type. 00797 Q_ASSERT( dynamic_cast<T*>( h ) ); 00798 } else if( create ) { 00799 h = new T( this ); 00800 setHeader( h ); 00801 } 00802 return static_cast<T*>( h ); 00803 } 00804 00805 } // namespace KMime 00806 00807 #endif // __KMIME_CONTENT_H__
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon Apr 30 2012 21:48:40 by doxygen 1.8.0 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon Apr 30 2012 21:48:40 by doxygen 1.8.0 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.