/usr/include/Wt/Mail/Message is in libwt-dev 3.3.4+dfsg-6ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 | // This may look like C code, but it's really -*- C++ -*-
/*
* Copyright (C) 2011 Emweb bvba, Kessel-Lo, Belgium.
*
* See the LICENSE file for terms of use.
*/
#ifndef WT_MAIL_MESSAGE_H_
#define WT_MAIL_MESSAGE_H_
#include <Wt/WLocalDateTime>
#include <Wt/Mail/Mailbox>
namespace Wt {
class WStringStream;
namespace Mail {
/*! \brief Enumeration for a recipient type.
*
* \sa Message::addRecipient()
*/
enum RecipientType {
To, //!< To: recipient
Cc, //!< Cc: recipient
Bcc //!< Bcc: recipient (is omitted from the recipients in the message itself)
};
/*! \class Message Wt/Mail/Message Wt/Mail/Message
* \brief A mail message.
*
* This class represents a MIME-compliant mail message.
*
* The message can have a plain text body and an optional HTML body,
* which when present is encoded as an MIME multipart/alternative. It
* is recommended to send the same contents both in a plain text and
* an HTML variant.
*
* Recipient names, names, and body text may contain unicode text.
*
* \sa Client::send()
*
* \ingroup mail
*/
class WT_API Message
{
public:
/*! \class Header
* \brief An SMTP message header.
*
* An SMTP message header is a name/value pair, as defined by RFC 822.
*/
class WT_API Header
{
public:
/*! \brief Default constructor.
*/
Header();
/*! \brief Constructs a header with a given name and value.
*/
Header(const std::string& name, const std::string& value);
/*! \brief Copy constructor.
*/
Header(const Header& other);
/*! \brief Sets the header name.
*/
void setName(const std::string& name);
/*! \brief Returns the header name.
*
* \sa setName()
*/
const std::string& name() const { return name_; }
/*! \brief Sets the header value.
*/
void setValue(const std::string& value);
/*! \brief Returns the header value.
*
* \sa setValue()
*/
const std::string& value() const { return value_; }
private:
std::string name_, value_;
};
struct Recipient {
RecipientType type;
Mailbox mailbox;
};
/*! \brief Default constructor.
*
* Creates an empty message. You need to add at least a sender and a recipient
* to create a valid email message.
*/
Message();
/*! \brief Sets the sender mailbox.
*/
void setFrom(const Mailbox& from);
/*! \brief Returns the sender mailbox.
*
* \sa setFrom()
*/
const Mailbox& from() const { return from_; }
/*! \brief Sets the reply-to mailbox.
*/
void setReplyTo(const Mailbox& replyTo);
/*! \brief Returns the reply-to mailbox.
*
* \sa setReplyTo()
*/
const Mailbox& replyTo() const { return replyTo_; }
/*! \brief Sets a subject.
*/
void setSubject(const WString& subject);
/*! \brief Returns the subject.
*
* \sa setSubject()
*/
const WString& subject() const { return subject_; }
/*! \brief Sets a date.
*
* According to RFC 2822, the date should express local time.
*/
void setDate(const WLocalDateTime& date);
/*! \brief Returns the date.
*/
WLocalDateTime date() const { return date_; }
/*! \brief Sets the plain text body.
*
* This is the plain text mail contents.
*
* \sa addHtmlBody()
*/
void setBody(const WString& text);
/*! \brief Returns the plain text body.
*
* \sa setBody()
*/
const WString& body() const { return body_; }
/*! \brief Adds a recipient.
*
* A mail can have multiple recipients.
*/
void addRecipient(RecipientType type, const Mailbox& recipient);
/*! \brief Returns the recipients.
*
* \sa addRecipient()
*/
const std::vector<Recipient>& recipients() const { return recipients_; }
/*! \brief Sets a header value.
*
* If a header with that value was already defined, it is replaced with
* the new value. Otherwise, the header is added.
*
* \sa addHeader()
*/
void setHeader(const std::string& name, const std::string& value);
/*! \brief Adds a header value.
*
* A header is added, even if a header with the same name already
* was present.
*
* \sa setHeader()
*/
void addHeader(const std::string& name, const std::string& value);
/*! \brief Returns the headers.
*/
const std::vector<Header>& headers() const { return headers_; }
/*! \brief Returns a header value.
*
* Returns 0 if no header with that name is found.
*/
const std::string *getHeader(const std::string& name) const;
/*! \brief Adds an HTML body.
*
* The \p text should be an HTML version of the plain text body.
*/
void addHtmlBody(const WString& text);
/*! \brief Returns the HTML body.
*
* \sa setHtmlBody()
*/
const WString& htmlBody() const { return htmlBody_; }
/*! \brief Adds an attachment.
*
* Ownership of the \p data stream is not transferred; you should keep this
* object valid until the message has been sent using Client::send() or
* written using write().
*/
void addAttachment(const std::string& mimeType, const std::string& fileName,
std::istream *data);
/*! \brief Writes the message to the stream.
*
* This writes the message as a MIME 1.0 message to the output stream.
*/
void write(std::ostream& out) const;
private:
struct Attachment {
std::string mimeType;
std::string fileName;
std::istream *data;
};
Mailbox from_, replyTo_;
std::vector<Recipient> recipients_;
std::vector<Header> headers_;
std::vector<Attachment> attachments_;
WString subject_, body_, htmlBody_;
WLocalDateTime date_;
static std::string generateBoundary();
static void encodeAttachment(const Attachment& attachment,
std::ostream& out);
static void encodeChar(WStringStream& s, unsigned char c);
static void encodeWord(const WString& text, std::ostream& out,
bool quoteIfNeeded);
static void encodeQuotedPrintable(const WString& text, std::ostream& out);
friend class Mailbox;
};
}
}
#endif // WT_MAIL_MESSAGE_H_
|