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

KMIME Library

  • sources
  • kde-4.12
  • kdepimlibs
  • 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  KMIME_DEPRECATED Headers::Generic *getNextHeader( QByteArray &head );
295 
303  // KDE5: Remove this. This method has nothing to do with *this object.
304  KMIME_DEPRECATED Headers::Generic *nextHeader( QByteArray &head );
305 
311  // KDE5: Make non-virtual.
312  KMIME_DEPRECATED virtual Headers::Base *getHeaderByType( const char *type );
313 
320  // KDE5: Make non-virtual.
321  virtual Headers::Base *headerByType( const char *type );
322 
334  template <typename T> T *header( bool create = false );
335 
342  virtual QList<Headers::Base*> headersByType( const char *type );
343 
355  // KDE5: make non-virtual.
356  virtual void setHeader( Headers::Base *h );
357 
363  void appendHeader( Headers::Base *h );
364 
370  void prependHeader( Headers::Base *h );
371 
378  // TODO probably provide removeHeader<T>() too.
379  // KDE5: make non-virtual.
380  virtual bool removeHeader( const char *type );
381 
386  // TODO probably provide hasHeader<T>() too.
387  // TODO: KDE5: make const
388  bool hasHeader( const char *type );
389 
395  Headers::ContentType *contentType( bool create = true );
396 
402  Headers::ContentTransferEncoding *contentTransferEncoding( bool create = true );
403 
409  Headers::ContentDisposition *contentDisposition( bool create = true );
410 
416  Headers::ContentDescription *contentDescription( bool create = true );
417 
424  Headers::ContentLocation *contentLocation( bool create = true );
425 
431  Headers::ContentID *contentID( bool create = true );
432 
438  int size();
439 
443  int storageSize() const;
444 
448  int lineCount() const;
449 
458  QByteArray body() const;
459 
470  void setBody( const QByteArray &body );
471 
479  QByteArray preamble() const;
480 
490  void setPreamble( const QByteArray &preamble );
491 
499  QByteArray epilogue() const;
500 
509  void setEpilogue( const QByteArray &epilogue );
510 
525  QByteArray encodedContent( bool useCrLf = false );
526 
533  QByteArray encodedBody();
534 
541  // TODO: KDE5: BIC: Rename this to decodedBody(), since only the body is returned.
542  // In contrast, setContent() sets the head and the body!
543  // Also, try to make this const.
544  QByteArray decodedContent();
545 
559  // TODO: KDE5: BIC: Convert to enums. Also, what if trimText = true but removeTrailingNewlines
560  // is false?
561  QString decodedText( bool trimText = false,
562  bool removeTrailingNewlines = false );
563 
580  void fromUnicodeString( const QString &s );
581 
585  Content *textContent();
586 
592  List attachments( bool incAlternatives = false );
593 
599  List contents() const;
600 
617  // KDE5: Do not convert single-part->multipart automatically.
618  void addContent( Content *content, bool prepend = false );
619 
636  // KDE5: Do not convert multipart->single-part automatically.
637  void removeContent( Content *content, bool del = false );
638 
645  void changeEncoding( Headers::contentEncoding e );
646 
654  void toStream( QTextStream &ts, bool scrambleFromLines = false );
655 
656  // NOTE: The charset methods below are accessed by the headers which
657  // have this Content as a parent.
658 
666  // TODO: Split this up into a charset for encoding and one for decoding, and make the one for
667  // encoding UTF-8 by default.
668  QByteArray defaultCharset() const;
669 
677  void setDefaultCharset( const QByteArray &cs );
678 
685  bool forceDefaultCharset() const;
686 
696  virtual void setForceDefaultCharset( bool b );
697 
705  Content *content( const ContentIndex &index ) const;
706 
712  ContentIndex indexForContent( Content *content ) const;
713 
719  virtual bool isTopLevel() const;
720 
727  void setParent( Content *parent );
728 
733  Content* parent() const;
734 
739  Content* topLevel() const;
740 
745  ContentIndex index() const;
746 
753  //AK_REVIEW: move to MessageViewer/ObjectTreeParser
754  bool bodyIsMessage() const;
755 
774  //AK_REVIEW: move to MessageViewer/ObjectTreeParser
775  boost::shared_ptr<Message> bodyAsMessage() const;
776 
777  protected:
783  virtual QByteArray assembleHeaders();
784 
790  KMIME_DEPRECATED QByteArray rawHeader( const char *name ) const;
791 
796  KMIME_DEPRECATED QList<QByteArray> rawHeaders( const char *name ) const;
797 
801  // KDE5: Not needed outside. Move to Private class.
802  bool decodeText();
803 
808  template <class T> KMIME_DEPRECATED T *headerInstance( T *ptr, bool create );
809 
814  // KDE5: Not needed outside. Move to Private class.
815  Headers::Base::List h_eaders;
816 
817  //@cond PRIVATE
818  ContentPrivate *d_ptr;
819  explicit Content( ContentPrivate *d );
820  //@endcond
821 
822  private:
823  Q_DECLARE_PRIVATE( Content )
824  Q_DISABLE_COPY( Content )
825 };
826 
827 // some compilers (for instance Compaq C++) need template inline functions
828 // here rather than in the *.cpp file
829 
830 template <class T> T *Content::headerInstance( T */*ptr*/, bool create )
831 {
832  return header<T>( create );
833 }
834 
835 template <typename T> T *Content::header( bool create )
836 {
837  Headers::Base *h = headerByType( T::staticType() );
838  if ( h ) {
839  // Make sure the header is actually of the right type.
840  Q_ASSERT( dynamic_cast<T*>( h ) );
841  } else if ( create ) {
842  h = new T( this );
843  setHeader( h );
844  }
845  return static_cast<T*>( h );
846 }
847 
848 } // namespace KMime
849 
850 #endif // __KMIME_CONTENT_H__
KMime::Headers::ContentDisposition
Represents a "Content-Disposition" header.
Definition: kmime_headers.h:1182
KMime::Content::List
QList< KMime::Content * > List
Describes a list of Content objects.
Definition: kmime_content.h:119
KMime::Content::header
T * header(bool create=false)
Returns the first header of type T, if it exists.
Definition: kmime_content.h:835
KMime::Headers::ContentID
Represents a "Content-ID" header.
Definition: kmime_headers.h:982
KMime::Headers::Generic
Represents an arbitrary header, that can contain any header-field.
Definition: kmime_headers.h:1239
KMime::Headers::Base
Baseclass of all header-classes.
Definition: kmime_headers.h:124
kmime_headers.h
This file is part of the API for handling MIME data and defines the various header classes: ...
KMime::Headers::ContentLocation
Represents a "Content-Location" header.
Definition: kmime_headers.h:1295
KMime::Headers::ContentDescription
Represents a "Content-Description" header.
Definition: kmime_headers.h:1286
KMime::Headers::Base::List
QList< KMime::Headers::Base * > List
A list of headers.
Definition: kmime_headers.h:130
KMime::Content::h_eaders
Headers::Base::List h_eaders
The list of headers in this Content.
Definition: kmime_content.h:815
KMime::Content
A class that encapsulates MIME encoded Content.
Definition: kmime_content.h:112
KMime::Headers::ContentTransferEncoding
Represents a "Content-Transfer-Encoding" header.
Definition: kmime_headers.h:890
KMime::Headers::ContentType
Represents a "Content-Type" header.
Definition: kmime_headers.h:1031
kmime_contentindex.h
This file is part of the API for handling MIME data and defines the ContentIndex class.
KMime::ContentIndex
A class to uniquely identify message parts (Content) in a hierarchy.
Definition: kmime_contentindex.h:54
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:00:11 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KMIME Library

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

kdepimlibs API Reference

Skip menu "kdepimlibs API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kldap
  • kmbox
  • kmime
  • kpimidentities
  • kpimtextedit
  • kresources
  • ktnef
  • kxmlrpcclient
  • microblog

Search



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