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 
24 {
25 }
26 
28 {
29  // Create the mandatory fields (RFC5322) if they do not exist already.
30  date(true);
31  from(true);
32 
33  // Make sure the mandatory MIME-Version field (RFC2045) is present and valid.
34  auto *mimeVersion = header<Headers::MIMEVersion>(true);
35  mimeVersion->from7BitString("1.0");
36 
37  // Assemble all header fields.
38  return Content::assembleHeaders();
39 }
40 
42 {
43  KMime::Content *c = this;
44  while (c) {
45  // not a multipart message
47  if (!contentType->isMultipart()) {
48  if (contentType->mimeType() == type || type.isEmpty()) {
49  return c;
50  }
51  return nullptr;
52  }
53 
54  // empty multipart
55  if (c->contents().isEmpty()) {
56  return nullptr;
57  }
58 
59  // multipart/alternative
60  if (contentType->subType() == "alternative") {
61  if (type.isEmpty()) {
62  return c->contents().at(0);
63  }
64  const auto contents = c->contents();
65  for (Content *c1 : contents) {
66  if (c1->contentType()->mimeType() == type) {
67  return c1;
68  }
69  }
70  return nullptr;
71  }
72 
73  c = c->contents().at(0);
74  }
75 
76  return nullptr;
77 }
78 
80 {
81  return QStringLiteral("message/rfc822");
82 }
83 
84 // @cond PRIVATE
85 #define kmime_mk_header_accessor( type, method ) \
86  Headers::type *Message::method( bool create ) { \
87  return header<Headers::type>( create ); \
88  }
89 
90 kmime_mk_header_accessor(MessageID, messageID)
91 kmime_mk_header_accessor(Subject, subject)
92 kmime_mk_header_accessor(Date, date)
93 kmime_mk_header_accessor(Organization, organization)
94 kmime_mk_header_accessor(From, from)
95 kmime_mk_header_accessor(ReplyTo, replyTo)
96 kmime_mk_header_accessor(To, to)
97 kmime_mk_header_accessor(Cc, cc)
98 kmime_mk_header_accessor(Bcc, bcc)
99 kmime_mk_header_accessor(References, references)
100 kmime_mk_header_accessor(UserAgent, userAgent)
101 kmime_mk_header_accessor(InReplyTo, inReplyTo)
102 kmime_mk_header_accessor(Sender, sender)
103 
104 #undef kmime_mk_header_accessor
105 // @endcond
106 
107 }
108 
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...
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.
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.
Definition: kmime_content.h:98
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-2021 The KDE developers.
Generated on Sun Jun 20 2021 23:12:55 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.