• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.14.10 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
63namespace KMime {
64
65class ContentPrivate;
66class 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*/
112class 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
620 void replaceContent(Content *oldContent, Content *newContent);
637 // KDE5: Do not convert multipart->single-part automatically.
638 void removeContent( Content *content, bool del = false );
639
646 void changeEncoding( Headers::contentEncoding e );
647
655 void toStream( QTextStream &ts, bool scrambleFromLines = false );
656
657 // NOTE: The charset methods below are accessed by the headers which
658 // have this Content as a parent.
659
667 // TODO: Split this up into a charset for encoding and one for decoding, and make the one for
668 // encoding UTF-8 by default.
669 QByteArray defaultCharset() const;
670
678 void setDefaultCharset( const QByteArray &cs );
679
686 bool forceDefaultCharset() const;
687
697 virtual void setForceDefaultCharset( bool b );
698
706 Content *content( const ContentIndex &index ) const;
707
713 ContentIndex indexForContent( Content *content ) const;
714
720 virtual bool isTopLevel() const;
721
728 void setParent( Content *parent );
729
734 Content* parent() const;
735
740 Content* topLevel() const;
741
746 ContentIndex index() const;
747
754 //AK_REVIEW: move to MessageViewer/ObjectTreeParser
755 bool bodyIsMessage() const;
756
775 //AK_REVIEW: move to MessageViewer/ObjectTreeParser
776 boost::shared_ptr<Message> bodyAsMessage() const;
777
778 protected:
784 virtual QByteArray assembleHeaders();
785
791 KMIME_DEPRECATED QByteArray rawHeader( const char *name ) const;
792
797 KMIME_DEPRECATED QList<QByteArray> rawHeaders( const char *name ) const;
798
802 // KDE5: Not needed outside. Move to Private class.
803 bool decodeText();
804
809 template <class T> KMIME_DEPRECATED T *headerInstance( T *ptr, bool create );
810
815 // KDE5: Not needed outside. Move to Private class.
816 Headers::Base::List h_eaders;
817
818 //@cond PRIVATE
819 ContentPrivate *d_ptr;
820 explicit Content( ContentPrivate *d );
821 //@endcond
822
823 private:
824 Q_DECLARE_PRIVATE( Content )
825 Q_DISABLE_COPY( Content )
826};
827
828// some compilers (for instance Compaq C++) need template inline functions
829// here rather than in the *.cpp file
830
831template <class T> T *Content::headerInstance( T */*ptr*/, bool create )
832{
833 return header<T>( create );
834}
835
836template <typename T> T *Content::header( bool create )
837{
838 Headers::Base *h = headerByType( T::staticType() );
839 if ( h ) {
840 // Make sure the header is actually of the right type.
841 Q_ASSERT( dynamic_cast<T*>( h ) );
842 } else if ( create ) {
843 h = new T( this );
844 setHeader( h );
845 }
846 return static_cast<T*>( h );
847}
848
849} // namespace KMime
850
851#endif // __KMIME_CONTENT_H__
KMime::ContentIndex
A class to uniquely identify message parts (Content) in a hierarchy.
Definition kmime_contentindex.h:55
KMime::Content
A class that encapsulates MIME encoded Content.
Definition kmime_content.h:113
KMime::Content::contentDescription
Headers::ContentDescription * contentDescription(bool create=true)
Returns the Content-Description header.
KMime::Content::contentType
Headers::ContentType * contentType(bool create=true)
Returns the Content-Type header.
KMime::Content::setHeader
virtual void setHeader(Headers::Base *h)
Sets the specified header to this Content.
Definition kmime_content.cpp:748
KMime::Content::headerByType
virtual Headers::Base * headerByType(const char *type)
Returns the first header of type type, if it exists.
Definition kmime_content.cpp:720
KMime::Content::contentTransferEncoding
Headers::ContentTransferEncoding * contentTransferEncoding(bool create=true)
Returns the Content-Transfer-Encoding header.
KMime::Content::contentDisposition
Headers::ContentDisposition * contentDisposition(bool create=true)
Returns the Content-Disposition header.
KMime::Content::headerInstance
KMIME_DEPRECATED T * headerInstance(T *ptr, bool create)
Returns the first header of type T, if it exists.
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:836
KMime::Content::contentID
Headers::ContentID * contentID(bool create=true)
Returns the Content-ID header.
KMime::Content::h_eaders
Headers::Base::List h_eaders
The list of headers in this Content.
Definition kmime_content.h:816
KMime::Content::contentLocation
Headers::ContentLocation * contentLocation(bool create=true)
Returns the Content-Location header.
KMime::Headers::Base
Baseclass of all header-classes.
Definition kmime_headers.h:125
KMime::Headers::Base::List
QList< KMime::Headers::Base * > List
A list of headers.
Definition kmime_headers.h:130
KMime::Headers::ContentDescription
Represents a "Content-Description" header.
Definition kmime_headers.h:1287
KMime::Headers::ContentDisposition
Represents a "Content-Disposition" header.
Definition kmime_headers.h:1183
KMime::Headers::ContentID
Represents a "Content-ID" header.
Definition kmime_headers.h:983
KMime::Headers::ContentLocation
Represents a "Content-Location" header.
Definition kmime_headers.h:1296
KMime::Headers::ContentTransferEncoding
Represents a "Content-Transfer-Encoding" header.
Definition kmime_headers.h:891
KMime::Headers::ContentType
Represents a "Content-Type" header.
Definition kmime_headers.h:1032
KMime::Headers::Generic
Represents an arbitrary header, that can contain any header-field.
Definition kmime_headers.h:1240
KMime::KAutoDeleteHash
The KAutoDeleteHash class is a convenience QHash subclass that provides automatic deletion of the val...
Definition kautodeletehash.h:50
KMime::KAutoDeleteHash::KAutoDeleteHash
KAutoDeleteHash()
Constructs an empty hash.
Definition kautodeletehash.h:55
kmime_contentindex.h
This file is part of the API for handling MIME data and defines the ContentIndex class.
kmime_headers.h
This file is part of the API for handling MIME data and defines the various header classes:
KMime::Headers::contentEncoding
contentEncoding
Various possible values for the "Content-Transfer-Encoding" header.
Definition kmime_headers.h:74
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Wed Jan 24 2024 00:00:00 by doxygen 1.10.0 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-4.14.10 API Reference

Skip menu "kdepimlibs-4.14.10 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