KMime

message.h
1/*
2 kmime_message.h
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#pragma once
11
12#include "kmime_export.h"
13#include "content.h"
14#include "headers.h"
15
16#include <QMetaType>
17#include <QSharedPointer>
18
19namespace KMime
20{
21
22class MessagePrivate;
23
24/**
25 * Represents a (email) message.
26 *
27 * Sample how to create a multipart message:
28 * \code
29 * // Set the multipart message.
30 * Message *m = new Message;
31 * Headers::ContentType *ct = m->contentType();
32 * ct->setMimeType( "multipart/mixed" );
33 * ct->setBoundary( multiPartBoundary() );
34 * Headers::ContentTransferEncoding *cte = m->contentTransferEncoding();
35 * cte->setEncoding(Headers::CE7Bit);
36 *
37 * // Set the headers.
38 * m->from()->fromUnicodeString("some@mailaddy.com");
39 * m->to()->fromUnicodeString("someother@mailaddy.com");
40 * m->cc()->fromUnicodeString("some@mailaddy.com");
41 * m->date()->setDateTime(QDateTime::currentLocalDateTime());
42 * m->subject()->fromUnicodeString("My Subject");
43 *
44 * // Set the first multipart, the body message.
45 * KMime::Content *b = new KMime::Content;
46 * b->contentType()->setMimeType( "text/plain" );
47 * b->setBody( "Some text..." );
48 *
49 * // Set the second multipart, the attachment.
50 * KMime::Content *a = new KMime::Content;
51 * KMime::Headers::ContentDisposition *d = new KMime::Headers::ContentDisposition( attachMessage );
52 * d->setFilename( "cal.ics" );
53 * d->setDisposition( KMime::Headers::CDattachment );
54 * a->contentType()->setMimeType( "text/plain" );
55 * a->setHeader( d );
56 * a->setBody( "Some text in the attachment..." );
57 *
58 * // Attach the both multiparts and assemble the message.
59 * m->appendContent( b );
60 * m->appendContent( a );
61 * m->assemble();
62 * \endcode
63 */
64class KMIME_EXPORT Message : public Content
65{
66public:
67 /**
68 A shared pointer to a message object.
69 */
71 /**
72 Creates an empty Message.
73 */
75
76 /**
77 Destroys this Message.
78 */
79 ~Message() override;
80
81 /**
82 Returns the Message-ID header.
83 @param create If true, create the header if it doesn't exist yet.
84 */
86 /**
87 Returns the Message-ID header.
88 Can be @c nullptr if the header doesn't exist.
89 @since 24.08
90 */
91 [[nodiscard]] const KMime::Headers::MessageID *messageID() const;
92
93 /**
94 Returns the Subject header.
95 @param create If true, create the header if it doesn't exist yet.
96 */
97 KMime::Headers::Subject *subject(bool create = true);
98 /**
99 Returns the Subject header.
100 Can be @c nullptr if the header doesn't exist.
101 @since 24.08
102 */
103 [[nodiscard]] const KMime::Headers::Subject *subject() const;
104
105 /**
106 Returns the Date header.
107 @param create If true, create the header if it doesn't exist yet.
108 */
109 KMime::Headers::Date *date(bool create = true);
110 /**
111 Returns the Date header.
112 Can be @c nullptr if the header doesn't exist.
113 @since 24.08
114 */
115 [[nodiscard]] const KMime::Headers::Date *date() const;
116
117 /**
118 Returns the From header.
119 @param create If true, create the header if it doesn't exist yet.
120 */
121 KMime::Headers::From *from(bool create = true);
122 /**
123 Returns the From header.
124 Can be @c nullptr if the header doesn't exist.
125 @since 24.08
126 */
127 [[nodiscard]] const KMime::Headers::From *from() const;
128
129 /**
130 Returns the Organization header.
131 @param create If true, create the header if it doesn't exist yet.
132 */
134 /**
135 Returns the Organization header.
136 Can be @c nullptr if the header doesn't exist.
137 @since 24.08
138 */
139 [[nodiscard]] const KMime::Headers::Organization *organization() const;
140
141 /**
142 Returns the Reply-To header.
143 @param create If true, create the header if it doesn't exist yet.
144 */
145 KMime::Headers::ReplyTo *replyTo(bool create = true);
146 /**
147 Returns the Reply-To header.
148 Can be @c nullptr if the header doesn't exist.
149 @since 24.08
150 */
151 [[nodiscard]] const KMime::Headers::ReplyTo *replyTo() const;
152
153 /**
154 Returns the To header.
155 @param create If true, create the header if it doesn't exist yet.
156 */
157 KMime::Headers::To *to(bool create = true);
158 /**
159 Returns the To header.
160 Can be @c nullptr if the header doesn't exist.
161 @since 24.08
162 */
163 [[nodiscard]] const KMime::Headers::To *to() const;
164
165 /**
166 Returns the Cc header.
167 @param create If true, create the header if it doesn't exist yet.
168 */
169 KMime::Headers::Cc *cc(bool create = true);
170 /**
171 Returns the Cc header.
172 Can be @c nullptr if the header doesn't exist.
173 @since 24.08
174 */
175 [[nodiscard]] const KMime::Headers::Cc *cc() const;
176
177 /**
178 Returns the Bcc header.
179 @param create If true, create the header if it doesn't exist yet.
180 */
181 KMime::Headers::Bcc *bcc(bool create = true);
182 /**
183 Returns the Bcc header.
184 Can be @c nullptr if the header doesn't exist.
185 @since 24.08
186 */
187 [[nodiscard]] const KMime::Headers::Bcc *bcc() const;
188
189 /**
190 Returns the References header.
191 @param create If true, create the header if it doesn't exist yet.
192 */
194 /**
195 Returns the References header.
196 Can be @c nullptr if the header doesn't exist.
197 @since 24.08
198 */
199 [[nodiscard]] const KMime::Headers::References *references() const;
200
201 /**
202 Returns the User-Agent header.
203 @param create If true, create the header if it doesn't exist yet.
204 */
206 /**
207 Returns the User-Agent header.
208 Can be @c nullptr if the header doesn't exist.
209 @since 24.08
210 */
211 [[nodiscard]] const KMime::Headers::UserAgent *userAgent() const;
212
213 /**
214 Returns the In-Reply-To header.
215 @param create If true, create the header if it doesn't exist yet.
216 */
218 /**
219 Returns the In-Reply-To header.
220 Can be @c nullptr if the header doesn't exist.
221 @since 24.08
222 */
223 [[nodiscard]] const KMime::Headers::InReplyTo *inReplyTo() const;
224
225 /**
226 Returns the Sender header.
227 @param create If true, create the header if it doesn't exist yet.
228 */
229 KMime::Headers::Sender *sender(bool create = true);
230 /**
231 Returns the Sender header.
232 Can be @c nullptr if the header doesn't exist.
233 @since 24.08
234 */
235 [[nodiscard]] const KMime::Headers::Sender *sender() const;
236
237 /**
238 Returns the first main body part of a given type, taking multipart/mixed
239 and multipart/alternative nodes into consideration.
240 Eg. \c bodyPart("text/html") will return a html content object if that is
241 provided in a multipart/alternative node, but not if it's the non-first
242 child node of a multipart/mixed node (ie. an attachment).
243 @param type The mimetype of the body part, if not given, the first
244 body part will be returned, regardless of it's type.
245 */
246 [[nodiscard]] Content *mainBodyPart(const QByteArray &type = QByteArray());
247 [[nodiscard]] const Content *mainBodyPart(const QByteArray &type = QByteArray()) const;
248
249 /**
250 Returns the MIME type used for Messages
251 */
252 [[nodiscard]] static QString mimeType();
253
254protected:
255 QByteArray assembleHeaders() override;
256
257private:
258 Q_DECLARE_PRIVATE(Message)
259
260}; // class Message
261
262} // namespace KMime
263
264Q_DECLARE_METATYPE(KMime::Message*)
265Q_DECLARE_METATYPE(KMime::Message::Ptr)
266
A class that encapsulates MIME encoded Content.
Definition content.h:90
Represents a "Bcc" header.
Definition headers.h:796
Represents a "Cc" header.
Definition headers.h:786
Represents a "Date" header.
Definition headers.h:1301
Represent a "From" header.
Definition headers.h:756
Represents a "In-Reply-To" header.
Definition headers.h:962
Represents a "Message-ID" header.
Definition headers.h:918
Represents a "Organization" header.
Definition headers.h:1227
Represents a "References" header.
Definition headers.h:972
Represents a "ReplyTo" header.
Definition headers.h:806
Represents a "Sender" header.
Definition headers.h:766
Represents a "Subject" header.
Definition headers.h:1217
Represents a "To" header.
Definition headers.h:776
Represents a "User-Agent" header.
Definition headers.h:1418
Represents a (email) message.
Definition message.h:65
const KMime::Headers::Date * date() const
Returns the Date header.
const KMime::Headers::From * from() const
Returns the From header.
KMime::Headers::Cc * cc(bool create=true)
Returns the Cc header.
const KMime::Headers::Sender * sender() const
Returns the Sender header.
KMime::Headers::To * to(bool create=true)
Returns the To header.
const KMime::Headers::References * references() const
Returns the References header.
QSharedPointer< Message > Ptr
A shared pointer to a message object.
Definition message.h:70
~Message() override
Destroys this Message.
const KMime::Headers::To * to() const
Returns the To header.
const KMime::Headers::Cc * cc() const
Returns the Cc header.
KMime::Headers::UserAgent * userAgent(bool create=true)
Returns the User-Agent header.
KMime::Headers::InReplyTo * inReplyTo(bool create=true)
Returns the In-Reply-To header.
Message()
Creates an empty Message.
KMime::Headers::References * references(bool create=true)
Returns the References header.
const KMime::Headers::Bcc * bcc() const
Returns the Bcc header.
KMime::Headers::Sender * sender(bool create=true)
Returns the Sender header.
const KMime::Headers::MessageID * messageID() const
Returns the Message-ID header.
const KMime::Headers::Organization * organization() const
Returns the Organization header.
KMime::Headers::MessageID * messageID(bool create=true)
Returns the Message-ID header.
KMime::Headers::ReplyTo * replyTo(bool create=true)
Returns the Reply-To header.
KMime::Headers::Subject * subject(bool create=true)
Returns the Subject header.
KMime::Headers::Date * date(bool create=true)
Returns the Date header.
const KMime::Headers::InReplyTo * inReplyTo() const
Returns the In-Reply-To header.
const KMime::Headers::ReplyTo * replyTo() const
Returns the Reply-To header.
const KMime::Headers::UserAgent * userAgent() const
Returns the User-Agent header.
KMime::Headers::From * from(bool create=true)
Returns the From header.
KMime::Headers::Bcc * bcc(bool create=true)
Returns the Bcc header.
KMime::Headers::Organization * organization(bool create=true)
Returns the Organization header.
const KMime::Headers::Subject * subject() const
Returns the Subject header.
This file is part of the API for handling MIME data and defines the Content class.
This file is part of the API for handling MIME data and defines the various header classes:
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Aug 30 2024 11:45:35 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.