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_util_p.h"
26 
27 using namespace KMime;
28 
29 namespace KMime
30 {
31 
33 {
34 }
35 
37 {
38 }
39 
41 {
42  // Create the mandatory fields (RFC5322) if they do not exist already.
43  date(true);
44  from(true);
45 
46  // Make sure the mandatory MIME-Version field (RFC2045) is present and valid.
47  Headers::MIMEVersion *mimeVersion = header<Headers::MIMEVersion>(true);
48  mimeVersion->from7BitString("1.0");
49 
50  // Assemble all header fields.
51  return Content::assembleHeaders();
52 }
53 
55 {
56  KMime::Content *c = this;
57  while (c) {
58  // not a multipart message
60  if (!contentType->isMultipart()) {
61  if (contentType->mimeType() == type || type.isEmpty()) {
62  return c;
63  }
64  return nullptr;
65  }
66 
67  // empty multipart
68  if (c->contents().isEmpty()) {
69  return nullptr;
70  }
71 
72  // multipart/alternative
73  if (contentType->subType() == "alternative") {
74  if (type.isEmpty()) {
75  return c->contents().at(0);
76  }
77  foreach (Content *c1, c->contents()) {
78  if (c1->contentType()->mimeType() == type) {
79  return c1;
80  }
81  }
82  return nullptr;
83  }
84 
85  c = c->contents().at(0);
86  }
87 
88  return nullptr;
89 }
90 
92 {
93  return QStringLiteral("message/rfc822");
94 }
95 
96 // @cond PRIVATE
97 #define kmime_mk_header_accessor( type, method ) \
98  Headers::type *Message::method( bool create ) { \
99  return header<Headers::type>( create ); \
100  }
101 
102 kmime_mk_header_accessor(MessageID, messageID)
103 kmime_mk_header_accessor(Subject, subject)
104 kmime_mk_header_accessor(Date, date)
105 kmime_mk_header_accessor(Organization, organization)
106 kmime_mk_header_accessor(From, from)
107 kmime_mk_header_accessor(ReplyTo, replyTo)
108 kmime_mk_header_accessor(To, to)
109 kmime_mk_header_accessor(Cc, cc)
110 kmime_mk_header_accessor(Bcc, bcc)
111 kmime_mk_header_accessor(References, references)
112 kmime_mk_header_accessor(UserAgent, userAgent)
113 kmime_mk_header_accessor(InReplyTo, inReplyTo)
114 kmime_mk_header_accessor(Sender, sender)
115 
116 #undef kmime_mk_header_accessor
117 // @endcond
118 
119 }
120 
virtual QByteArray assembleHeaders()
Reimplement this method if you need to assemble additional headers in a derived class.
QByteArray subType() const
Returns the mime sub-type (second part of the mimetype).
KMime::Headers::InReplyTo * inReplyTo(bool create=true)
Returns the In-Reply-To header.
bool isMultipart() const
Returns true if the associated MIME entity is a mulitpart container.
QByteArray assembleHeaders() override
Reimplement this method if you need to assemble additional headers in a derived class.
Subject
KMime::Headers::UserAgent * userAgent(bool create=true)
Returns the User-Agent header.
KMime::Headers::Sender * sender(bool create=true)
Returns the Sender header.
Organization
bool isEmpty() const const
Content * mainBodyPart(const QByteArray &type=QByteArray())
Returns the first main body part of a given type, taking multipart/mixed and multipart/alternative no...
void from7BitString(const char *s, size_t len) override
Parses the given string.
QByteArray mimeType() const
Returns the mimetype.
KMime::Headers::Organization * organization(bool create=true)
Returns the Organization header.
~Message() override
Destroys this Message.
KMime::Headers::MessageID * messageID(bool create=true)
Returns the Message-ID header.
KMime::Headers::From * from(bool create=true)
Returns the From header.
QVector< Content * > contents() const
For multipart contents, this will return a list of all multipart child contents.
Represents a "MIME-Version" header.
Message()
Creates an empty Message.
KMime::Headers::Cc * cc(bool create=true)
Returns the Cc header.
KMime::Headers::Subject * subject(bool create=true)
Returns the Subject header.
Headers::ContentType * contentType(bool create=true)
Returns the Content-Type header.
KMime::Headers::Date * date(bool create=true)
Returns the Date header.
KMime::Headers::To * to(bool create=true)
Returns the To header.
KMime::Headers::ReplyTo * replyTo(bool create=true)
Returns the Reply-To header.
static QString mimeType()
Returns the MIME type used for Messages.
A class that encapsulates MIME encoded Content.
KMime::Headers::Bcc * bcc(bool create=true)
Returns the Bcc header.
KMime::Headers::References * references(bool create=true)
Returns the References header.
Represents a "Content-Type" header.
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sun Jul 5 2020 23:12:25 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.