• 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_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 
30 using namespace KMime;
31 
32 namespace KMime {
33 
34 Message::Message()
35  : Content( new MessagePrivate( this ) )
36 {
37 }
38 
39 Message::Message(MessagePrivate * d)
40  : Content( d )
41 {
42 }
43 
44 Message::~Message()
45 {
46 }
47 
48 void Message::parse()
49 {
50  // KDE5: remove this virtual reimplementation.
51  Content::parse();
52 }
53 
54 QByteArray 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 
68 void Message::clear()
69 {
70  // KDE5: remove this virtual reimplementation.
71  Content::clear();
72 }
73 
74 Headers::Base *Message::getHeaderByType( const char *type )
75 {
76  // KDE5: remove this virtual reimplementation.
77  return headerByType( type );
78 }
79 
80 Headers::Base *Message::headerByType( const char *type )
81 {
82  // KDE5: remove this virtual reimplementation.
83  return Content::headerByType( type );
84 }
85 
86 void Message::setHeader( Headers::Base *h )
87 {
88  // KDE5: remove this virtual reimplementation.
89  Content::setHeader( h );
90 }
91 
92 bool Message::removeHeader( const char *type )
93 {
94  // KDE5: remove this virtual reimplementation.
95  return Content::removeHeader( type );
96 }
97 
98 bool Message::isTopLevel() const
99 {
100  return Content::isTopLevel();
101 }
102 
103 Content *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 
140 QString 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 ) \
149 Headers::type *Message::method( bool create ) { \
150  return header<Headers::type>( create ); \
151 }
152 
153 kmime_mk_header_accessor( MessageID, messageID )
154 kmime_mk_header_accessor( Subject, subject )
155 kmime_mk_header_accessor( Date, date )
156 kmime_mk_header_accessor( Organization, organization )
157 kmime_mk_header_accessor( From, from )
158 kmime_mk_header_accessor( ReplyTo, replyTo )
159 kmime_mk_header_accessor( To, to )
160 kmime_mk_header_accessor( Cc, cc )
161 kmime_mk_header_accessor( Bcc, bcc )
162 kmime_mk_header_accessor( References, references )
163 kmime_mk_header_accessor( UserAgent, userAgent )
164 kmime_mk_header_accessor( InReplyTo, inReplyTo )
165 kmime_mk_header_accessor( Sender, sender )
166 
167 #undef kmime_mk_header_accessor
168 // @endcond
169 
170 }
171 
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::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::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::Content::contents
List contents() const
For multipart contents, this will return a list of all multipart child contents.
Definition: kmime_content.cpp:526
KMime::Content::setHeader
virtual void setHeader(Headers::Base *h)
Sets the specified header to this Content.
Definition: kmime_content.cpp:725
KMime::Message::clear
virtual void clear()
Clears the content, deleting all headers and sub-Contents.
Definition: kmime_message.cpp:68
KMime::Message::setHeader
virtual void setHeader(KMime::Headers::Base *h)
Sets the specified header to this Content.
Definition: kmime_message.cpp:86
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::Headers::ContentType::mimeType
QByteArray mimeType() const
Returns the mimetype.
Definition: kmime_headers.cpp:1743
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::Headers::MIMEVersion
Represents a "MIME-Version" header.
Definition: kmime_headers.h:952
KMime::Message::Message
Message()
Creates an empty Message.
Definition: kmime_message.cpp:34
KMime::Content::parse
virtual void parse()
Parses the Content.
Definition: kmime_content.cpp:184
KMime::Message::date
virtual KMime::Headers::Date * date(bool create=true)
Returns the Date header.
KMime::Headers::Base
Baseclass of all header-classes.
Definition: kmime_headers.h:124
KMime::Content::isTopLevel
virtual bool isTopLevel() const
Returns true if this is the top-level node in the MIME tree.
Definition: kmime_content.cpp:928
KMime::Content::contentType
Headers::ContentType * contentType(bool create=true)
Returns the Content-Type header.
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::from
virtual KMime::Headers::From * from(bool create=true)
Returns the From header.
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::parse
virtual void parse()
Parses the Content.
Definition: kmime_message.cpp:48
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:744
KMime::Content::clear
virtual void clear()
Clears the content, deleting all headers and sub-Contents.
Definition: kmime_content.cpp:279
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::mimeType
static QString mimeType()
Returns the MIME type used for Messages.
Definition: kmime_message.cpp:140
KMime::Headers::Generics::Structured::from7BitString
virtual void from7BitString(const QByteArray &s)
Parses the given string.
Definition: kmime_headers.cpp:320
KMime::Content
A class that encapsulates MIME encoded Content.
Definition: kmime_content.h:112
KMime::Message::~Message
~Message()
Destroys this Message.
Definition: kmime_message.cpp:44
KMime::Headers::ContentType
Represents a "Content-Type" header.
Definition: kmime_headers.h:1031
KMime::Content::headerByType
virtual Headers::Base * headerByType(const char *type)
Returns the first header of type type, if it exists.
Definition: kmime_content.cpp:697
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