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

KMIME Library

  • kmime
kmime_message.cpp
1/*
2 kmime_message.cpp
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
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Library General Public
10 License as published by the Free Software Foundation; either
11 version 2 of the License, or (at your option) any later version.
12
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Library General Public License for more details.
17
18 You should have received a copy of the GNU Library General Public License
19 along with this library; see the file COPYING.LIB. If not, write to
20 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA.
22*/
23
24#include "kmime_message.h"
25#include "kmime_message_p.h"
26#include "kmime_util_p.h"
27
28#include <KGlobal>
29
30using namespace KMime;
31
32namespace KMime {
33
34Message::Message()
35 : Content( new MessagePrivate( this ) )
36{
37}
38
39Message::Message(MessagePrivate * d)
40 : Content( d )
41{
42}
43
44Message::~Message()
45{
46}
47
48void Message::parse()
49{
50 // KDE5: remove this virtual reimplementation.
51 Content::parse();
52}
53
54QByteArray Message::assembleHeaders()
55{
56 // Create the mandatory fields (RFC5322) if they do not exist already.
57 date( true );
58 from( true );
59
60 // Make sure the mandatory MIME-Version field (RFC2045) is present and valid.
61 Headers::MIMEVersion *mimeVersion = header<Headers::MIMEVersion>( true );
62 mimeVersion->from7BitString( "1.0" );
63
64 // Assemble all header fields.
65 return Content::assembleHeaders();
66}
67
68void Message::clear()
69{
70 // KDE5: remove this virtual reimplementation.
71 Content::clear();
72}
73
74Headers::Base *Message::getHeaderByType( const char *type )
75{
76 // KDE5: remove this virtual reimplementation.
77 return headerByType( type );
78}
79
80Headers::Base *Message::headerByType( const char *type )
81{
82 // KDE5: remove this virtual reimplementation.
83 return Content::headerByType( type );
84}
85
86void Message::setHeader( Headers::Base *h )
87{
88 // KDE5: remove this virtual reimplementation.
89 Content::setHeader( h );
90}
91
92bool Message::removeHeader( const char *type )
93{
94 // KDE5: remove this virtual reimplementation.
95 return Content::removeHeader( type );
96}
97
98bool Message::isTopLevel() const
99{
100 return Content::isTopLevel();
101}
102
103Content *Message::mainBodyPart( const QByteArray &type )
104{
105 KMime::Content *c = this;
106 while ( c ) {
107 // not a multipart message
108 const KMime::Headers::ContentType * const contentType = c->contentType();
109 if ( !contentType->isMultipart() ) {
110 if ( contentType->mimeType() == type || type.isEmpty() ) {
111 return c;
112 }
113 return 0;
114 }
115
116 // empty multipart
117 if ( c->contents().count() == 0 ) {
118 return 0;
119 }
120
121 // multipart/alternative
122 if ( contentType->subType() == "alternative" ) {
123 if ( type.isEmpty() ) {
124 return c->contents().first();
125 }
126 foreach ( Content *c1, c->contents() ) {
127 if ( c1->contentType()->mimeType() == type ) {
128 return c1;
129 }
130 }
131 return 0;
132 }
133
134 c = c->contents().first();
135 }
136
137 return 0;
138}
139
140QString Message::mimeType()
141{
142 static const QString &message_rfc822 = KGlobal::staticQString( QLatin1String( "message/rfc822" ) );
143 return message_rfc822;
144}
145
146
147// @cond PRIVATE
148#define kmime_mk_header_accessor( type, method ) \
149Headers::type *Message::method( bool create ) { \
150 return header<Headers::type>( create ); \
151}
152
153kmime_mk_header_accessor( MessageID, messageID )
154kmime_mk_header_accessor( Subject, subject )
155kmime_mk_header_accessor( Date, date )
156kmime_mk_header_accessor( Organization, organization )
157kmime_mk_header_accessor( From, from )
158kmime_mk_header_accessor( ReplyTo, replyTo )
159kmime_mk_header_accessor( To, to )
160kmime_mk_header_accessor( Cc, cc )
161kmime_mk_header_accessor( Bcc, bcc )
162kmime_mk_header_accessor( References, references )
163kmime_mk_header_accessor( UserAgent, userAgent )
164kmime_mk_header_accessor( InReplyTo, inReplyTo )
165kmime_mk_header_accessor( Sender, sender )
166
167#undef kmime_mk_header_accessor
168// @endcond
169
170}
171
KMime::Content
A class that encapsulates MIME encoded Content.
Definition kmime_content.h:113
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::parse
virtual void parse()
Parses the Content.
Definition kmime_content.cpp:184
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::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::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::clear
virtual void clear()
Clears the content, deleting all headers and sub-Contents.
Definition kmime_content.cpp:279
KMime::Headers::Base
Baseclass of all header-classes.
Definition kmime_headers.h:125
KMime::Headers::ContentType
Represents a "Content-Type" header.
Definition kmime_headers.h:1032
KMime::Headers::ContentType::subType
QByteArray subType() const
Returns the mime sub-type (second part of the mimetype).
Definition kmime_headers.cpp:1760
KMime::Headers::ContentType::isMultipart
bool isMultipart() const
Returns true if the associated MIME entity is a mulitpart container.
Definition kmime_headers.cpp:1824
KMime::Headers::ContentType::mimeType
QByteArray mimeType() const
Returns the mimetype.
Definition kmime_headers.cpp:1743
KMime::Headers::MIMEVersion
Represents a "MIME-Version" header.
Definition kmime_headers.h:953
KMime::KAutoDeleteHash
The KAutoDeleteHash class is a convenience QHash subclass that provides automatic deletion of the val...
Definition kautodeletehash.h:50
KMime::Message::isTopLevel
virtual bool isTopLevel() const
Returns true if this is the top-level node in the MIME tree.
Definition kmime_message.cpp:98
KMime::Message::mainBodyPart
Content * mainBodyPart(const QByteArray &type=QByteArray())
Returns the first main body part of a given type, taking multipart/mixed and multipart/alternative no...
Definition kmime_message.cpp:103
KMime::Message::mimeType
static QString mimeType()
Returns the MIME type used for Messages.
Definition kmime_message.cpp:140
KMime::Message::date
virtual KMime::Headers::Date * date(bool create=true)
Returns the Date header.
KMime::Message::parse
virtual void parse()
Parses the Content.
Definition kmime_message.cpp:48
KMime::Message::Message
Message()
Creates an empty Message.
Definition kmime_message.cpp:34
KMime::Message::assembleHeaders
virtual QByteArray assembleHeaders()
Reimplement this method if you need to assemble additional headers in a derived class.
Definition kmime_message.cpp:54
KMime::Message::~Message
~Message()
Destroys this Message.
Definition kmime_message.cpp:44
KMime::Message::from
virtual KMime::Headers::From * from(bool create=true)
Returns the From header.
KMime::Message::headerByType
virtual KMime::Headers::Base * headerByType(const char *type)
Returns the first header of type type, if it exists.
Definition kmime_message.cpp:80
KMime::Message::clear
virtual void clear()
Clears the content, deleting all headers and sub-Contents.
Definition kmime_message.cpp:68
KMime::Message::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_message.cpp:92
KMime::Message::getHeaderByType
virtual KMIME_DEPRECATED KMime::Headers::Base * getHeaderByType(const char *type)
Tries to find a type header in the Content and returns it.
Definition kmime_message.cpp:74
KMime::Message::setHeader
virtual void setHeader(KMime::Headers::Base *h)
Sets the specified header to this Content.
Definition kmime_message.cpp:86
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