1 | /* |
2 | kmime_message.h |
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 | #ifndef __KMIME_MESSAGE_H__ |
24 | #define __KMIME_MESSAGE_H__ |
25 | |
26 | #include "kmime_export.h" |
27 | #include "kmime_content.h" |
28 | #include "kmime_headers.h" |
29 | #include "boolflags.h" |
30 | |
31 | #include <QtCore/QMetaType> |
32 | |
33 | namespace boost { |
34 | template <typename T> class shared_ptr; |
35 | } |
36 | |
37 | namespace KMime { |
38 | |
39 | class MessagePrivate; |
40 | |
41 | /** |
42 | * Represents a (email) message. |
43 | * |
44 | * Sample how to create a multipart message: |
45 | * \code |
46 | * // Set the multipart message. |
47 | * Message *m = new Message; |
48 | * Headers::ContentType *ct = m->contentType(); |
49 | * ct->setMimeType( "multipart/mixed" ); |
50 | * ct->setBoundary( multiPartBoundary() ); |
51 | * ct->setCategory( Headers::CCcontainer ); |
52 | * m->contentTransferEncoding()->clear(); |
53 | * |
54 | * // Set the headers. |
55 | * m->from()->fromUnicodeString( "some@mailaddy.com", "utf-8" ); |
56 | * m->to()->fromUnicodeString( "someother@mailaddy.com", "utf-8" ); |
57 | * m->cc()->fromUnicodeString( "some@mailaddy.com", "utf-8" ); |
58 | * m->date()->setDateTime( KDateTime::currentLocalDateTime() ); |
59 | * m->subject()->fromUnicodeString( "My Subject", "utf-8" ); |
60 | * |
61 | * // Set the first multipart, the body message. |
62 | * KMime::Content *b = new KMime::Content; |
63 | * b->contentType()->setMimeType( "text/plain" ); |
64 | * b->setBody( "Some text..." ); |
65 | * |
66 | * // Set the second multipart, the attachment. |
67 | * KMime::Content *a = new KMime::Content; |
68 | * KMime::Headers::ContentDisposition *d = new KMime::Headers::ContentDisposition( attachMessage ); |
69 | * d->setFilename( "cal.ics" ); |
70 | * d->setDisposition( KMime::Headers::CDattachment ); |
71 | * a->contentType()->setMimeType( "text/plain" ); |
72 | * a->setHeader( d ); |
73 | * a->setBody( "Some text in the attachment..." ); |
74 | * |
75 | * // Attach the both multiparts and assemble the message. |
76 | * m->addContent( b ); |
77 | * m->addContent( a ); |
78 | * m->assemble(); |
79 | * \endcode |
80 | */ |
81 | class KMIME_EXPORT Message : public Content |
82 | { |
83 | public: |
84 | /** |
85 | A list of messages. |
86 | */ |
87 | typedef QList<KMime::Message*> List; |
88 | |
89 | /** |
90 | A shared pointer to a message object. |
91 | */ |
92 | typedef boost::shared_ptr<Message> Ptr; |
93 | |
94 | /** |
95 | Creates an empty Message. |
96 | */ |
97 | Message(); |
98 | |
99 | /** |
100 | Destroys this Message. |
101 | */ |
102 | ~Message(); |
103 | |
104 | /* reimpl */ |
105 | virtual void parse(); |
106 | |
107 | /* reimpl */ |
108 | virtual void clear(); |
109 | |
110 | /* reimpl */ |
111 | virtual KMIME_DEPRECATED KMime::Headers::Base *( const char *type ); |
112 | |
113 | /* reimpl */ |
114 | virtual KMime::Headers::Base *( const char *type ); |
115 | |
116 | /* reimpl */ |
117 | virtual void ( KMime::Headers::Base *h ); |
118 | |
119 | /* reimpl */ |
120 | virtual bool ( const char *type ); |
121 | |
122 | // KDE5: Why are these virtual? |
123 | /** |
124 | Returns the Message-ID header. |
125 | @param create If true, create the header if it doesn't exist yet. |
126 | */ |
127 | virtual KMime::Headers::MessageID *messageID( bool create = true ); |
128 | |
129 | /** |
130 | Returns the Subject header. |
131 | @param create If true, create the header if it doesn't exist yet. |
132 | */ |
133 | virtual KMime::Headers::Subject *subject( bool create = true ); |
134 | |
135 | /** |
136 | Returns the Date header. |
137 | @param create If true, create the header if it doesn't exist yet. |
138 | */ |
139 | virtual KMime::Headers::Date *date( bool create = true ); |
140 | |
141 | /** |
142 | Returns the From header. |
143 | @param create If true, create the header if it doesn't exist yet. |
144 | */ |
145 | virtual KMime::Headers::From *from( bool create = true ); |
146 | |
147 | /** |
148 | Returns the Organization header. |
149 | @param create If true, create the header if it doesn't exist yet. |
150 | */ |
151 | virtual KMime::Headers::Organization *organization( bool create = true ); |
152 | |
153 | /** |
154 | Returns the Reply-To header. |
155 | @param create If true, create the header if it doesn't exist yet. |
156 | */ |
157 | virtual KMime::Headers::ReplyTo *replyTo( bool create = true ); |
158 | |
159 | /** |
160 | Returns the To header. |
161 | @param create If true, create the header if it doesn't exist yet. |
162 | */ |
163 | virtual KMime::Headers::To *to( bool create = true ); |
164 | |
165 | /** |
166 | Returns the Cc header. |
167 | @param create If true, create the header if it doesn't exist yet. |
168 | */ |
169 | virtual KMime::Headers::Cc *cc( bool create = true ); |
170 | |
171 | /** |
172 | Returns the Bcc header. |
173 | @param create If true, create the header if it doesn't exist yet. |
174 | */ |
175 | virtual KMime::Headers::Bcc *bcc( bool create = true ); |
176 | |
177 | /** |
178 | Returns the References header. |
179 | @param create If true, create the header if it doesn't exist yet. |
180 | */ |
181 | virtual KMime::Headers::References *references( bool create = true ); |
182 | |
183 | /** |
184 | Returns the User-Agent header. |
185 | @param create If true, create the header if it doesn't exist yet. |
186 | */ |
187 | virtual KMime::Headers::UserAgent *userAgent( bool create = true ); |
188 | |
189 | /** |
190 | Returns the In-Reply-To header. |
191 | @param create If true, create the header if it doesn't exist yet. |
192 | */ |
193 | virtual KMime::Headers::InReplyTo *inReplyTo( bool create = true ); |
194 | |
195 | /** |
196 | Returns the Sender header. |
197 | @param create If true, create the header if it doesn't exist yet. |
198 | */ |
199 | virtual KMime::Headers::Sender *sender( bool create = true ); |
200 | |
201 | /* reimpl */ |
202 | virtual bool isTopLevel() const; |
203 | |
204 | /** |
205 | Returns the first main body part of a given type, taking multipart/mixed |
206 | and multipart/alternative nodes into consideration. |
207 | Eg. \c bodyPart("text/html") will return a html content object if that is |
208 | provided in a multipart/alternative node, but not if it's the non-first |
209 | child node of a multipart/mixed node (ie. an attachment). |
210 | @param type The mimetype of the body part, if not given, the first |
211 | body part will be returned, regardless of it's type. |
212 | */ |
213 | Content* mainBodyPart( const QByteArray &type = QByteArray() ); |
214 | |
215 | /** |
216 | Returns the MIME type used for Messages |
217 | */ |
218 | static QString mimeType(); |
219 | |
220 | protected: |
221 | /* reimpl */ |
222 | virtual QByteArray (); |
223 | |
224 | // @cond PRIVATE |
225 | explicit Message( MessagePrivate *d ); |
226 | // @endcond |
227 | |
228 | private: |
229 | Q_DECLARE_PRIVATE( Message ) |
230 | |
231 | }; // class Message |
232 | |
233 | } // namespace KMime |
234 | |
235 | #define KMIME_MESSAGE_METATYPE_DEFINED 1 |
236 | Q_DECLARE_METATYPE( KMime::Message* ) |
237 | |
238 | #endif // __KMIME_MESSAGE_H__ |
239 | |