File indexing completed on 2024-03-24 05:21:19
0001 /* 0002 kmime_message.h 0003 0004 KMime, the KDE Internet mail/usenet news message library. 0005 SPDX-FileCopyrightText: 2001 the KMime authors. 0006 See file AUTHORS for details 0007 0008 SPDX-License-Identifier: LGPL-2.0-or-later 0009 */ 0010 #pragma once 0011 0012 #include "kmime_export.h" 0013 #include "kmime_content.h" 0014 #include "kmime_headers.h" 0015 0016 #include <QMetaType> 0017 #include <QSharedPointer> 0018 0019 namespace KMime 0020 { 0021 0022 class MessagePrivate; 0023 0024 /** 0025 * Represents a (email) message. 0026 * 0027 * Sample how to create a multipart message: 0028 * \code 0029 * // Set the multipart message. 0030 * Message *m = new Message; 0031 * Headers::ContentType *ct = m->contentType(); 0032 * ct->setMimeType( "multipart/mixed" ); 0033 * ct->setBoundary( multiPartBoundary() ); 0034 * Headers::ContentTransferEncoding *cte = m->contentTransferEncoding(); 0035 * cte->setEncoding(Headers::CE7Bit); 0036 * cte->setDecoded(true); 0037 * 0038 * // Set the headers. 0039 * m->from()->fromUnicodeString( "some@mailaddy.com", "utf-8" ); 0040 * m->to()->fromUnicodeString( "someother@mailaddy.com", "utf-8" ); 0041 * m->cc()->fromUnicodeString( "some@mailaddy.com", "utf-8" ); 0042 * m->date()->setDateTime( QDateTime::currentLocalDateTime() ); 0043 * m->subject()->fromUnicodeString( "My Subject", "utf-8" ); 0044 * 0045 * // Set the first multipart, the body message. 0046 * KMime::Content *b = new KMime::Content; 0047 * b->contentType()->setMimeType( "text/plain" ); 0048 * b->setBody( "Some text..." ); 0049 * 0050 * // Set the second multipart, the attachment. 0051 * KMime::Content *a = new KMime::Content; 0052 * KMime::Headers::ContentDisposition *d = new KMime::Headers::ContentDisposition( attachMessage ); 0053 * d->setFilename( "cal.ics" ); 0054 * d->setDisposition( KMime::Headers::CDattachment ); 0055 * a->contentType()->setMimeType( "text/plain" ); 0056 * a->setHeader( d ); 0057 * a->setBody( "Some text in the attachment..." ); 0058 * 0059 * // Attach the both multiparts and assemble the message. 0060 * m->appendContent( b ); 0061 * m->appendContent( a ); 0062 * m->assemble(); 0063 * \endcode 0064 */ 0065 class KMIME_EXPORT Message : public Content 0066 { 0067 public: 0068 /** 0069 A shared pointer to a message object. 0070 */ 0071 typedef QSharedPointer<Message> Ptr; 0072 /** 0073 Creates an empty Message. 0074 */ 0075 Message(); 0076 0077 /** 0078 Destroys this Message. 0079 */ 0080 ~Message() override; 0081 0082 /** 0083 Returns the Message-ID header. 0084 @param create If true, create the header if it doesn't exist yet. 0085 */ 0086 KMime::Headers::MessageID *messageID(bool create = true); 0087 0088 /** 0089 Returns the Subject header. 0090 @param create If true, create the header if it doesn't exist yet. 0091 */ 0092 KMime::Headers::Subject *subject(bool create = true); 0093 0094 /** 0095 Returns the Date header. 0096 @param create If true, create the header if it doesn't exist yet. 0097 */ 0098 KMime::Headers::Date *date(bool create = true); 0099 0100 /** 0101 Returns the From header. 0102 @param create If true, create the header if it doesn't exist yet. 0103 */ 0104 KMime::Headers::From *from(bool create = true); 0105 0106 /** 0107 Returns the Organization header. 0108 @param create If true, create the header if it doesn't exist yet. 0109 */ 0110 KMime::Headers::Organization *organization(bool create = true); 0111 0112 /** 0113 Returns the Reply-To header. 0114 @param create If true, create the header if it doesn't exist yet. 0115 */ 0116 KMime::Headers::ReplyTo *replyTo(bool create = true); 0117 0118 /** 0119 Returns the To header. 0120 @param create If true, create the header if it doesn't exist yet. 0121 */ 0122 KMime::Headers::To *to(bool create = true); 0123 0124 /** 0125 Returns the Cc header. 0126 @param create If true, create the header if it doesn't exist yet. 0127 */ 0128 KMime::Headers::Cc *cc(bool create = true); 0129 0130 /** 0131 Returns the Bcc header. 0132 @param create If true, create the header if it doesn't exist yet. 0133 */ 0134 KMime::Headers::Bcc *bcc(bool create = true); 0135 0136 /** 0137 Returns the References header. 0138 @param create If true, create the header if it doesn't exist yet. 0139 */ 0140 KMime::Headers::References *references(bool create = true); 0141 0142 /** 0143 Returns the User-Agent header. 0144 @param create If true, create the header if it doesn't exist yet. 0145 */ 0146 KMime::Headers::UserAgent *userAgent(bool create = true); 0147 0148 /** 0149 Returns the In-Reply-To header. 0150 @param create If true, create the header if it doesn't exist yet. 0151 */ 0152 KMime::Headers::InReplyTo *inReplyTo(bool create = true); 0153 0154 /** 0155 Returns the Sender header. 0156 @param create If true, create the header if it doesn't exist yet. 0157 */ 0158 KMime::Headers::Sender *sender(bool create = true); 0159 0160 /** 0161 Returns the first main body part of a given type, taking multipart/mixed 0162 and multipart/alternative nodes into consideration. 0163 Eg. \c bodyPart("text/html") will return a html content object if that is 0164 provided in a multipart/alternative node, but not if it's the non-first 0165 child node of a multipart/mixed node (ie. an attachment). 0166 @param type The mimetype of the body part, if not given, the first 0167 body part will be returned, regardless of it's type. 0168 */ 0169 Content *mainBodyPart(const QByteArray &type = QByteArray()); 0170 0171 /** 0172 Returns the MIME type used for Messages 0173 */ 0174 static QString mimeType(); 0175 0176 protected: 0177 QByteArray assembleHeaders() override; 0178 0179 private: 0180 Q_DECLARE_PRIVATE(Message) 0181 0182 }; // class Message 0183 0184 } // namespace KMime 0185 0186 Q_DECLARE_METATYPE(KMime::Message*) 0187 Q_DECLARE_METATYPE(KMime::Message::Ptr) 0188