KMime

kmime_message.cpp
1 /*
2  kmime_message.cpp
3 
4  KMime, the KDE Internet mail/usenet news message library.
5  SPDX-FileCopyrightText: 2001 the KMime authors.
6  See file AUTHORS for details
7 
8  SPDX-License-Identifier: LGPL-2.0-or-later
9 */
10 
11 #include "kmime_message.h"
12 #include "kmime_util_p.h"
13 
14 using namespace KMime;
15 
16 namespace KMime
17 {
18 
20 {
21 }
22 
23 Message::~Message() = default;
24 
26 {
27  // Create the mandatory fields (RFC5322) if they do not exist already.
28  date(true);
29  from(true);
30 
31  // Make sure the mandatory MIME-Version field (RFC2045) is present and valid.
32  auto *mimeVersion = header<Headers::MIMEVersion>(true);
33  mimeVersion->from7BitString("1.0");
34 
35  // Assemble all header fields.
36  return Content::assembleHeaders();
37 }
38 
40 {
41  KMime::Content *c = this;
42  while (c) {
43  // not a multipart message
45  if (!contentType->isMultipart()) {
46  if (contentType->mimeType() == type || type.isEmpty()) {
47  return c;
48  }
49  return nullptr;
50  }
51 
52  // empty multipart
53  if (c->contents().isEmpty()) {
54  return nullptr;
55  }
56 
57  // multipart/alternative
58  if (contentType->subType() == "alternative") {
59  if (type.isEmpty()) {
60  return c->contents().at(0);
61  }
62  const auto contents = c->contents();
63  for (Content *c1 : contents) {
64  if (c1->contentType()->mimeType() == type) {
65  return c1;
66  }
67  }
68  return nullptr;
69  }
70 
71  c = c->contents().at(0);
72  }
73 
74  return nullptr;
75 }
76 
78 {
79  return QStringLiteral("message/rfc822");
80 }
81 
82 // @cond PRIVATE
83 #define kmime_mk_header_accessor( type, method ) \
84  Headers::type *Message::method( bool create ) { \
85  return header<Headers::type>( create ); \
86  }
87 
88 kmime_mk_header_accessor(MessageID, messageID)
89 kmime_mk_header_accessor(Subject, subject)
90 kmime_mk_header_accessor(Date, date)
91 kmime_mk_header_accessor(Organization, organization)
92 kmime_mk_header_accessor(From, from)
93 kmime_mk_header_accessor(ReplyTo, replyTo)
94 kmime_mk_header_accessor(To, to)
95 kmime_mk_header_accessor(Cc, cc)
96 kmime_mk_header_accessor(Bcc, bcc)
97 kmime_mk_header_accessor(References, references)
98 kmime_mk_header_accessor(UserAgent, userAgent)
99 kmime_mk_header_accessor(InReplyTo, inReplyTo)
100 kmime_mk_header_accessor(Sender, sender)
101 
102 #undef kmime_mk_header_accessor
103 // @endcond
104 
105 }
106 
KMime::Headers::From * from(bool create=true)
Returns the From header.
A class that encapsulates MIME encoded Content.
Definition: kmime_content.h:98
QByteArray mimeType() const
Returns the mimetype.
virtual QByteArray assembleHeaders()
Reimplement this method if you need to assemble additional headers in a derived class.
QByteArray assembleHeaders() override
Reimplement this method if you need to assemble additional headers in a derived class.
static QString mimeType()
Returns the MIME type used for Messages.
Represents a "Content-Type" header.
QByteArray subType() const
Returns the mime sub-type (second part of the mimetype).
~Message() override
Destroys this Message.
Message()
Creates an empty Message.
Headers::ContentType * contentType(bool create=true)
Returns the Content-Type header.
bool isMultipart() const
Returns true if the associated MIME entity is a multipart container.
Content * mainBodyPart(const QByteArray &type=QByteArray())
Returns the first main body part of a given type, taking multipart/mixed and multipart/alternative no...
KMime::Headers::Date * date(bool create=true)
Returns the Date header.
QVector< Content * > contents() const
For multipart contents, this will return a list of all multipart child contents.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sat May 21 2022 03:50:03 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.