KMime

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 "kmime_content.h"
14 #include "kmime_headers.h"
15 
16 #include <QMetaType>
17 #include <QSharedPointer>
18 
19 namespace KMime
20 {
21 
22 class 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  * ct->setCategory( Headers::CCcontainer );
35  * Headers::ContentTransferEncoding *cte = m->contentTransferEncoding();
36  * cte->setEncoding(Headers::CE7Bit);
37  * cte->setDecoded(true);
38  *
39  * // Set the headers.
40  * m->from()->fromUnicodeString( "[email protected]", "utf-8" );
41  * m->to()->fromUnicodeString( "[email protected]", "utf-8" );
42  * m->cc()->fromUnicodeString( "[email protected]", "utf-8" );
43  * m->date()->setDateTime( QDateTime::currentLocalDateTime() );
44  * m->subject()->fromUnicodeString( "My Subject", "utf-8" );
45  *
46  * // Set the first multipart, the body message.
47  * KMime::Content *b = new KMime::Content;
48  * b->contentType()->setMimeType( "text/plain" );
49  * b->setBody( "Some text..." );
50  *
51  * // Set the second multipart, the attachment.
52  * KMime::Content *a = new KMime::Content;
53  * KMime::Headers::ContentDisposition *d = new KMime::Headers::ContentDisposition( attachMessage );
54  * d->setFilename( "cal.ics" );
55  * d->setDisposition( KMime::Headers::CDattachment );
56  * a->contentType()->setMimeType( "text/plain" );
57  * a->setHeader( d );
58  * a->setBody( "Some text in the attachment..." );
59  *
60  * // Attach the both multiparts and assemble the message.
61  * m->addContent( b );
62  * m->addContent( a );
63  * m->assemble();
64  * \endcode
65  */
66 class KMIME_EXPORT Message : public Content
67 {
68 public:
69  /**
70  A shared pointer to a message object.
71  */
73  /**
74  Creates an empty Message.
75  */
76  Message();
77 
78  /**
79  Destroys this Message.
80  */
81  ~Message() override;
82 
83  /**
84  Returns the Message-ID header.
85  @param create If true, create the header if it doesn't exist yet.
86  */
87  KMime::Headers::MessageID *messageID(bool create = true);
88 
89  /**
90  Returns the Subject header.
91  @param create If true, create the header if it doesn't exist yet.
92  */
93  KMime::Headers::Subject *subject(bool create = true);
94 
95  /**
96  Returns the Date header.
97  @param create If true, create the header if it doesn't exist yet.
98  */
99  KMime::Headers::Date *date(bool create = true);
100 
101  /**
102  Returns the From header.
103  @param create If true, create the header if it doesn't exist yet.
104  */
105  KMime::Headers::From *from(bool create = true);
106 
107  /**
108  Returns the Organization header.
109  @param create If true, create the header if it doesn't exist yet.
110  */
111  KMime::Headers::Organization *organization(bool create = true);
112 
113  /**
114  Returns the Reply-To header.
115  @param create If true, create the header if it doesn't exist yet.
116  */
117  KMime::Headers::ReplyTo *replyTo(bool create = true);
118 
119  /**
120  Returns the To header.
121  @param create If true, create the header if it doesn't exist yet.
122  */
123  KMime::Headers::To *to(bool create = true);
124 
125  /**
126  Returns the Cc header.
127  @param create If true, create the header if it doesn't exist yet.
128  */
129  KMime::Headers::Cc *cc(bool create = true);
130 
131  /**
132  Returns the Bcc header.
133  @param create If true, create the header if it doesn't exist yet.
134  */
135  KMime::Headers::Bcc *bcc(bool create = true);
136 
137  /**
138  Returns the References header.
139  @param create If true, create the header if it doesn't exist yet.
140  */
141  KMime::Headers::References *references(bool create = true);
142 
143  /**
144  Returns the User-Agent header.
145  @param create If true, create the header if it doesn't exist yet.
146  */
147  KMime::Headers::UserAgent *userAgent(bool create = true);
148 
149  /**
150  Returns the In-Reply-To header.
151  @param create If true, create the header if it doesn't exist yet.
152  */
153  KMime::Headers::InReplyTo *inReplyTo(bool create = true);
154 
155  /**
156  Returns the Sender header.
157  @param create If true, create the header if it doesn't exist yet.
158  */
159  KMime::Headers::Sender *sender(bool create = true);
160 
161  /**
162  Returns the first main body part of a given type, taking multipart/mixed
163  and multipart/alternative nodes into consideration.
164  Eg. \c bodyPart("text/html") will return a html content object if that is
165  provided in a multipart/alternative node, but not if it's the non-first
166  child node of a multipart/mixed node (ie. an attachment).
167  @param type The mimetype of the body part, if not given, the first
168  body part will be returned, regardless of it's type.
169  */
170  Content *mainBodyPart(const QByteArray &type = QByteArray());
171 
172  /**
173  Returns the MIME type used for Messages
174  */
175  static QString mimeType();
176 
177 protected:
178  QByteArray assembleHeaders() override;
179 
180 private:
181  Q_DECLARE_PRIVATE(Message)
182 
183 }; // class Message
184 
185 } // namespace KMime
186 
187 Q_DECLARE_METATYPE(KMime::Message*)
188 Q_DECLARE_METATYPE(KMime::Message::Ptr)
189 
Represents a "User-Agent" header.
A class that encapsulates MIME encoded Content.
Definition: kmime_content.h:97
Represent a "From" header.
Represents a "Sender" header.
Represents a "Message-ID" header.
Represents a "References" header.
Represents a "Organization" header.
Represents a "Bcc" header.
QSharedPointer< Message > Ptr
A shared pointer to a message object.
Definition: kmime_message.h:72
Represents a "Cc" header.
Represents a "To" header.
Defines the Content class.
Represents a "ReplyTo" header.
Represents a "Subject" header.
Represents a (email) message.
Definition: kmime_message.h:66
Represents a "Date" header.
Represents a "In-Reply-To" header.
Defines the various headers classes.
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Thu Nov 30 2023 03:52:14 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.