• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.10.5 API Reference
  • KDE Home
  • Contact Us
 

KMIME Library

  • kmime
kmime_content.h
Go to the documentation of this file.
1 /*
2  kmime_content.h
3 
4  KMime, the KDE Internet mail/usenet news message library.
5  Copyright (c) 2001 the KMime authors.
6  See file AUTHORS for details
7  Copyright (c) 2006 Volker Krause <vkrause@kde.org>
8  Copyright (c) 2009 Constantin Berzan <exit3219@gmail.com>
9 
10  This library is free software; you can redistribute it and/or
11  modify it under the terms of the GNU Library General Public
12  License as published by the Free Software Foundation; either
13  version 2 of the License, or (at your option) any later version.
14 
15  This library is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  Library General Public License for more details.
19 
20  You should have received a copy of the GNU Library General Public License
21  along with this library; see the file COPYING.LIB. If not, write to
22  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23  Boston, MA 02110-1301, USA.
24 */
48 #ifndef __KMIME_CONTENT_H__
49 #define __KMIME_CONTENT_H__
50 
51 #include "kmime_export.h"
52 #include "kmime_contentindex.h"
53 #include "kmime_util.h"
54 #include "kmime_headers.h"
55 
56 #include <QtCore/QTextStream>
57 #include <QtCore/QByteArray>
58 #include <QtCore/QList>
59 
60 #include <boost/shared_ptr.hpp>
61 
62 
63 namespace KMime {
64 
65 class ContentPrivate;
66 class Message;
67 
106 /*
107  KDE5:
108  * Do not convert singlepart <-> multipart automatically.
109  * A bunch of methods probably don't need to be virtual (since they're not needed
110  in either Message or NewsArticle).
111 */
112 class KMIME_EXPORT Content
113 {
114  public:
115 
119  typedef QList<KMime::Content*> List;
120 
124  Content();
125 
131  explicit Content( Content* parent ); // KDE5: Merge with the above.
132 
139  Content( const QByteArray &head, const QByteArray &body );
140 
149  // KDE5: Merge with the above.
150  Content( const QByteArray &head, const QByteArray &body, Content *parent );
151 
155  virtual ~Content();
156 
160  bool hasContent() const;
161 
172  void setContent( const QList<QByteArray> &l );
173 
187  void setContent( const QByteArray &s );
188 
207  virtual void parse();
208 
218  bool isFrozen() const;
219 
226  void setFrozen( bool frozen = true );
227 
247  virtual void assemble();
248 
252  // KDE5: make non-virtual.
253  virtual void clear();
254 
266  void clearContents( bool del = true );
267 
273  QByteArray head() const;
274 
285  void setHead( const QByteArray &head );
286 
294  KDE_DEPRECATED Headers::Generic *getNextHeader( QByteArray &head );
295 
303  // KDE5: Remove this. This method has nothing to do with *this object.
304  KDE_DEPRECATED Headers::Generic *nextHeader( QByteArray &head );
305 
310  // KDE5: Make non-virtual.
311  KDE_DEPRECATED virtual Headers::Base *getHeaderByType( const char *type );
312 
318  // KDE5: Make non-virtual.
319  virtual Headers::Base *headerByType( const char *type );
320 
332  template <typename T> T *header( bool create = false );
333 
339  virtual QList<Headers::Base*> headersByType( const char *type );
340 
352  // KDE5: make non-virtual.
353  virtual void setHeader( Headers::Base *h );
354 
360  void appendHeader( Headers::Base *h );
361 
367  void prependHeader( Headers::Base *h );
368 
375  // TODO probably provide removeHeader<T>() too.
376  // KDE5: make non-virtual.
377  virtual bool removeHeader( const char *type );
378 
383  // TODO probably provide hasHeader<T>() too.
384  // TODO: KDE5: make const
385  bool hasHeader( const char *type );
386 
392  Headers::ContentType *contentType( bool create = true );
393 
399  Headers::ContentTransferEncoding *contentTransferEncoding( bool create = true );
400 
406  Headers::ContentDisposition *contentDisposition( bool create = true );
407 
413  Headers::ContentDescription *contentDescription( bool create = true );
414 
421  Headers::ContentLocation *contentLocation( bool create = true );
422 
428  Headers::ContentID *contentID( bool create = true );
429 
435  int size();
436 
440  int storageSize() const;
441 
445  int lineCount() const;
446 
455  QByteArray body() const;
456 
467  void setBody( const QByteArray &body );
468 
476  QByteArray preamble() const;
477 
487  void setPreamble( const QByteArray &preamble );
488 
496  QByteArray epilogue() const;
497 
506  void setEpilogue( const QByteArray &epilogue );
507 
522  QByteArray encodedContent( bool useCrLf = false );
523 
530  QByteArray encodedBody();
531 
538  // TODO: KDE5: BIC: Rename this to decodedBody(), since only the body is returned.
539  // In contrast, setContent() sets the head and the body!
540  // Also, try to make this const.
541  QByteArray decodedContent();
542 
556  // TODO: KDE5: BIC: Convert to enums. Also, what if trimText = true but removeTrailingNewlines
557  // is false?
558  QString decodedText( bool trimText = false,
559  bool removeTrailingNewlines = false );
560 
577  void fromUnicodeString( const QString &s );
578 
582  Content *textContent();
583 
589  List attachments( bool incAlternatives = false );
590 
596  List contents() const;
597 
614  // KDE5: Do not convert single-part->multipart automatically.
615  void addContent( Content *content, bool prepend = false );
616 
633  // KDE5: Do not convert multipart->single-part automatically.
634  void removeContent( Content *content, bool del = false );
635 
642  void changeEncoding( Headers::contentEncoding e );
643 
651  void toStream( QTextStream &ts, bool scrambleFromLines = false );
652 
653  // NOTE: The charset methods below are accessed by the headers which
654  // have this Content as a parent.
655 
663  // TODO: Split this up into a charset for encoding and one for decoding, and make the one for
664  // encoding UTF-8 by default.
665  QByteArray defaultCharset() const;
666 
674  void setDefaultCharset( const QByteArray &cs );
675 
682  bool forceDefaultCharset() const;
683 
693  virtual void setForceDefaultCharset( bool b );
694 
702  Content *content( const ContentIndex &index ) const;
703 
709  ContentIndex indexForContent( Content *content ) const;
710 
716  virtual bool isTopLevel() const;
717 
724  void setParent( Content *parent );
725 
730  Content* parent() const;
731 
736  Content* topLevel() const;
737 
742  ContentIndex index() const;
743 
750  //AK_REVIEW: move to MessageViewer/ObjectTreeParser
751  bool bodyIsMessage() const;
752 
771  //AK_REVIEW: move to MessageViewer/ObjectTreeParser
772  boost::shared_ptr<Message> bodyAsMessage() const;
773 
774  protected:
780  virtual QByteArray assembleHeaders();
781 
786  KDE_DEPRECATED QByteArray rawHeader( const char *name ) const;
787 
792  KDE_DEPRECATED QList<QByteArray> rawHeaders( const char *name ) const;
793 
797  // KDE5: Not needed outside. Move to Private class.
798  bool decodeText();
799 
804  template <class T> KDE_DEPRECATED T *headerInstance( T *ptr, bool create );
805 
810  // KDE5: Not needed outside. Move to Private class.
811  Headers::Base::List h_eaders;
812 
813  //@cond PRIVATE
814  ContentPrivate *d_ptr;
815  explicit Content( ContentPrivate *d );
816  //@endcond
817 
818  private:
819  Q_DECLARE_PRIVATE( Content )
820  Q_DISABLE_COPY( Content )
821 };
822 
823 // some compilers (for instance Compaq C++) need template inline functions
824 // here rather than in the *.cpp file
825 
826 template <class T> T *Content::headerInstance( T *ptr, bool create )
827 {
828  return header<T>( create );
829 }
830 
831 template <typename T> T *Content::header( bool create )
832 {
833  Headers::Base *h = headerByType( T::staticType() );
834  if ( h ) {
835  // Make sure the header is actually of the right type.
836  Q_ASSERT( dynamic_cast<T*>( h ) );
837  } else if ( create ) {
838  h = new T( this );
839  setHeader( h );
840  }
841  return static_cast<T*>( h );
842 }
843 
844 } // namespace KMime
845 
846 #endif // __KMIME_CONTENT_H__
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Sat Jul 13 2013 01:25:45 by doxygen 1.8.3.1 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KMIME Library

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

kdepimlibs-4.10.5 API Reference

Skip menu "kdepimlibs-4.10.5 API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal