• 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*/
47
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
489
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::contentDescription
Headers::ContentDescription * contentDescription(bool create=true)
Returns the Content-Description header.
KMime::Content::hasContent
bool hasContent() const
Returns true if this Content object is not empty.
Definition kmime_content.cpp:100
KMime::Content::contentType
Headers::ContentType * contentType(bool create=true)
Returns the Content-Type header.
KMime::Content::decodedText
QString decodedText(bool trimText=false, bool removeTrailingNewlines=false)
Returns the decoded text.
Definition kmime_content.cpp:433
KMime::Content::setHeader
virtual void setHeader(Headers::Base *h)
Sets the specified header to this Content.
Definition kmime_content.cpp:748
KMime::Content::encodedBody
QByteArray encodedBody()
Like encodedContent(), with the difference that only the body will be returned, i....
Definition kmime_content.cpp:322
KMime::Content::topLevel
Content * topLevel() const
Returns the toplevel content object, 0 if there is no such object.
Definition kmime_content.cpp:979
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::rawHeader
KMIME_DEPRECATED QByteArray rawHeader(const char *name) const
Returns the raw string representing the header of type name.
Definition kmime_content.cpp:836
KMime::Content::clearContents
void clearContents(bool del=true)
Removes all sub-Contents from this content.
Definition kmime_content.cpp:289
KMime::Content::isFrozen
bool isFrozen() const
Returns whether this Content is frozen.
Definition kmime_content.cpp:244
KMime::Content::storageSize
int storageSize() const
Returns the size of this Content and all sub-Contents.
Definition kmime_content.cpp:801
KMime::Content::getHeaderByType
virtual KMIME_DEPRECATED Headers::Base * getHeaderByType(const char *type)
Tries to find a type header in the Content and returns it.
Definition kmime_content.cpp:715
KMime::Content::decodeText
bool decodeText()
Returns whether this object holds text content.
Definition kmime_content.cpp:846
KMime::Content::getNextHeader
KMIME_DEPRECATED Headers::Generic * getNextHeader(QByteArray &head)
Extracts and removes the next header from head.
Definition kmime_content.cpp:693
KMime::Content::index
ContentIndex index() const
Returns the index of this Content based on the topLevel() object.
Definition kmime_content.cpp:991
KMime::Content::headersByType
virtual QList< Headers::Base * > headersByType(const char *type)
Returns all type headers in the Content.
Definition kmime_content.cpp:733
KMime::Content::removeContent
void removeContent(Content *content, bool del=false)
Removes the given sub-Content.
Definition kmime_content.cpp:611
KMime::Content::setEpilogue
void setEpilogue(const QByteArray &epilogue)
Sets the MIME preamble.
Definition kmime_content.cpp:179
KMime::Content::epilogue
QByteArray epilogue() const
Returns the MIME preamble.
Definition kmime_content.cpp:174
KMime::Content::contentTransferEncoding
Headers::ContentTransferEncoding * contentTransferEncoding(bool create=true)
Returns the Content-Transfer-Encoding header.
KMime::Content::hasHeader
bool hasHeader(const char *type)
Definition kmime_content.cpp:780
KMime::Content::attachments
List attachments(bool incAlternatives=false)
Returns a list of attachments.
Definition kmime_content.cpp:507
KMime::Content::parent
Content * parent() const
Returns the parent content object, or 0 if the content doesn't have a parent.
Definition kmime_content.cpp:974
KMime::Content::setDefaultCharset
void setDefaultCharset(const QByteArray &cs)
Sets the default charset.
Definition kmime_content.cpp:886
KMime::Content::head
QByteArray head() const
Returns the Content header raw data.
Definition kmime_content.cpp:140
KMime::Content::bodyAsMessage
boost::shared_ptr< Message > bodyAsMessage() const
If this content is an encapsulated message, in which case bodyIsMessage() will return true,...
Definition kmime_content.cpp:1001
KMime::Content::nextHeader
KMIME_DEPRECATED Headers::Generic * nextHeader(QByteArray &head)
Extracts and removes the next header from head.
Definition kmime_content.cpp:698
KMime::Content::contentDisposition
Headers::ContentDisposition * contentDisposition(bool create=true)
Returns the Content-Disposition header.
KMime::Content::assemble
virtual void assemble()
Generates the MIME content.
Definition kmime_content.cpp:254
KMime::Content::setContent
void setContent(const QList< QByteArray > &l)
Sets the Content to the given raw data, containing the Content head and body separated by two linefee...
Definition kmime_content.cpp:105
KMime::Content::decodedContent
QByteArray decodedContent()
Returns the decoded Content body.
Definition kmime_content.cpp:381
KMime::Content::addContent
void addContent(Content *content, bool prepend=false)
Adds a new sub-Content.
Definition kmime_content.cpp:537
KMime::Content::textContent
Content * textContent()
Returns the first Content with mimetype text/.
Definition kmime_content.cpp:490
KMime::Content::headerInstance
KMIME_DEPRECATED T * headerInstance(T *ptr, bool create)
Returns the first header of type T, if it exists.
KMime::Content::content
Content * content(const ContentIndex &index) const
Returns the Content specified by the given index.
Definition kmime_content.cpp:917
KMime::Content::parse
virtual void parse()
Parses the Content.
Definition kmime_content.cpp:184
KMime::Content::body
QByteArray body() const
Returns the Content body raw data.
Definition kmime_content.cpp:153
KMime::Content::removeHeader
virtual bool removeHeader(const char *type)
Searches for the first header of type type, and deletes it, removing it from this Content.
Definition kmime_content.cpp:767
KMime::Content::prependHeader
void prependHeader(Headers::Base *h)
Prepends the specified header to the headers of this Content.
Definition kmime_content.cpp:761
KMime::Content::List
QList< KMime::Content * > List
Describes a list of Content objects.
Definition kmime_content.h:119
KMime::Content::isTopLevel
virtual bool isTopLevel() const
Returns true if this is the top-level node in the MIME tree.
Definition kmime_content.cpp:951
KMime::Content::encodedContent
QByteArray encodedContent(bool useCrLf=false)
Returns a QByteArray containing the encoded Content, including the Content header and all sub-Content...
Definition kmime_content.cpp:299
KMime::Content::toStream
void toStream(QTextStream &ts, bool scrambleFromLines=false)
Saves the encoded Content to the given textstream.
Definition kmime_content.cpp:680
KMime::Content::bodyIsMessage
bool bodyIsMessage() const
Definition kmime_content.cpp:1010
KMime::Content::Content
Content()
Creates an empty Content object.
Definition kmime_content.cpp:61
KMime::Content::lineCount
int lineCount() const
Line count of this Content and all sub-Contents.
Definition kmime_content.cpp:820
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::size
int size()
Returns the size of the Content body after encoding.
Definition kmime_content.cpp:785
KMime::Content::defaultCharset
QByteArray defaultCharset() const
Returns the charset that is used to decode RFC2047 strings in all headers and to decode the body if t...
Definition kmime_content.cpp:881
KMime::Content::rawHeaders
KMIME_DEPRECATED QList< QByteArray > rawHeaders(const char *name) const
Returns a list of raw strings representing all header of type name.
Definition kmime_content.cpp:841
KMime::Content::indexForContent
ContentIndex indexForContent(Content *content) const
Returns the ContentIndex for the given Content, or an invalid index if the Content is not found withi...
Definition kmime_content.cpp:931
KMime::Content::setForceDefaultCharset
virtual void setForceDefaultCharset(bool b)
Enables/disables the force mode, housekeeping.
Definition kmime_content.cpp:904
KMime::Content::contentID
Headers::ContentID * contentID(bool create=true)
Returns the Content-ID header.
KMime::Content::assembleHeaders
virtual QByteArray assembleHeaders()
Reimplement this method if you need to assemble additional headers in a derived class.
Definition kmime_content.cpp:267
KMime::Content::setFrozen
void setFrozen(bool frozen=true)
Freezes this Content if frozen is true; otherwise unfreezes it.
Definition kmime_content.cpp:249
KMime::Content::clear
virtual void clear()
Clears the content, deleting all headers and sub-Contents.
Definition kmime_content.cpp:279
KMime::Content::contents
List contents() const
For multipart contents, this will return a list of all multipart child contents.
Definition kmime_content.cpp:532
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::Content::forceDefaultCharset
bool forceDefaultCharset() const
Use the default charset even if a different charset is declared in the article.
Definition kmime_content.cpp:899
KMime::Content::setParent
void setParent(Content *parent)
Sets a new parent to the Content and add to its contents list.
Definition kmime_content.cpp:956
KMime::Content::setPreamble
void setPreamble(const QByteArray &preamble)
Sets the MIME preamble.
Definition kmime_content.cpp:168
KMime::Content::setBody
void setBody(const QByteArray &body)
Sets the Content body raw data.
Definition kmime_content.cpp:158
KMime::Content::changeEncoding
void changeEncoding(Headers::contentEncoding e)
Changes the encoding of this Content to e.
Definition kmime_content.cpp:650
KMime::Content::preamble
QByteArray preamble() const
Returns the MIME preamble.
Definition kmime_content.cpp:163
KMime::Content::fromUnicodeString
void fromUnicodeString(const QString &s)
Sets the Content body to the given string using charset of the content type.
Definition kmime_content.cpp:474
KMime::Content::setHead
void setHead(const QByteArray &head)
Sets the Content header raw data.
Definition kmime_content.cpp:145
KMime::Content::appendHeader
void appendHeader(Headers::Base *h)
Appends the specified header to the headers of this Content.
Definition kmime_content.cpp:755
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::Message
Represents a (email) message.
Definition kmime_message.h:82
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-2025 The KDE developers.
Generated on Fri Jan 17 2025 00:00:00 by doxygen 1.13.2 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