KMime::Message Class

class KMime::Message

Represents a (email) message. More...

Header: #include <KMime/Message>
CMake: find_package(KPim6 REQUIRED COMPONENTS Mime)
target_link_libraries(mytarget PRIVATE KPim6::Mime)
Inherits: KMime::Content
Inherited By:

KMime::NewsArticle

Public Functions

Message()
(since 24.08) const KMime::Headers::Bcc *bcc() const
KMime::Headers::Bcc *bcc(KMime::CreatePolicy create = Create)
(since 24.08) const KMime::Headers::Cc *cc() const
KMime::Headers::Cc *cc(KMime::CreatePolicy create = Create)
(since 24.08) const KMime::Headers::Date *date() const
KMime::Headers::Date *date(KMime::CreatePolicy create = Create)
(since 24.08) const KMime::Headers::From *from() const
KMime::Headers::From *from(KMime::CreatePolicy create = Create)
(since 24.08) const KMime::Headers::InReplyTo *inReplyTo() const
KMime::Headers::InReplyTo *inReplyTo(KMime::CreatePolicy create = Create)
KMime::Content *mainBodyPart(const QByteArray &type = QByteArray())
(since 24.08) const KMime::Headers::MessageID *messageID() const
KMime::Headers::MessageID *messageID(KMime::CreatePolicy create = Create)
(since 24.08) const KMime::Headers::Organization *organization() const
KMime::Headers::Organization *organization(KMime::CreatePolicy create = Create)
(since 24.08) const KMime::Headers::References *references() const
KMime::Headers::References *references(KMime::CreatePolicy create = Create)
(since 24.08) const KMime::Headers::ReplyTo *replyTo() const
KMime::Headers::ReplyTo *replyTo(KMime::CreatePolicy create = Create)
(since 24.08) const KMime::Headers::Sender *sender() const
KMime::Headers::Sender *sender(KMime::CreatePolicy create = Create)
(since 24.08) const KMime::Headers::Subject *subject() const
KMime::Headers::Subject *subject(KMime::CreatePolicy create = Create)
(since 24.08) const KMime::Headers::To *to() const
KMime::Headers::To *to(KMime::CreatePolicy create = Create)
(since 24.08) const KMime::Headers::UserAgent *userAgent() const
KMime::Headers::UserAgent *userAgent(KMime::CreatePolicy create = Create)

Static Public Members

QString mimeType()

Detailed Description

Sample how to create a multipart message:

// Set the multipart message.
auto m = std::make_shared<KMime::Message>();
auto ct = m->contentType();
ct->setMimeType("multipart/mixed");
ct->setBoundary(KMime::multiPartBoundary());
auto cte = m->contentTransferEncoding();
cte->setEncoding(KMime::Headers::CE7Bit);

// Set the headers.
m->from()->fromUnicodeString("some@mailaddy.com");
m->to()->fromUnicodeString("someother@mailaddy.com");
m->cc()->fromUnicodeString("some@mailaddy.com");
m->date()->setDateTime(QDateTime::currentDateTime());
m->subject()->fromUnicodeString("My Subject");

// Set the first multipart, the body message.
auto b = std::make_unique<KMime::Content>();
b->contentType()->setMimeType("text/plain");
b->setBody("Some text...");

// Set the second multipart, the attachment.
auto a = std::make_unique<KMime::Content>();
auto d = std::make_unique<KMime::Headers::ContentDisposition>();
d->setFilename("cal.ics");
d->setDisposition(KMime::Headers::CDattachment);
a->contentType()->setMimeType("text/plain");
a->setHeader(std::move(d));
a->setBody("Some text in the attachment...");

// Attach the both multiparts and assemble the message.
m->appendContent(std::move(b));
m->appendContent(std::move(a));
m->assemble();

Member Function Documentation

Message::Message()

Creates an empty Message.

[since 24.08] const KMime::Headers::Bcc *Message::bcc() const

Returns the Bcc header.

Can be nullptr if the header doesn't exist.

This function was introduced in 24.08.

KMime::Headers::Bcc *Message::bcc(KMime::CreatePolicy create = Create)

Returns the Bcc header.

Ownership of the header remains with the Message object, the created header is automatically added to that.

create Whether to create the header if it doesn't exist yet.

[since 24.08] const KMime::Headers::Cc *Message::cc() const

Returns the Cc header.

Can be nullptr if the header doesn't exist.

This function was introduced in 24.08.

KMime::Headers::Cc *Message::cc(KMime::CreatePolicy create = Create)

Returns the Cc header.

Ownership of the header remains with the Message object, the created header is automatically added to that.

create Whether to create the header if it doesn't exist yet.

[since 24.08] const KMime::Headers::Date *Message::date() const

Returns the Date header.

Can be nullptr if the header doesn't exist.

This function was introduced in 24.08.

KMime::Headers::Date *Message::date(KMime::CreatePolicy create = Create)

Returns the Date header.

Ownership of the header remains with the Message object, the created header is automatically added to that.

create Whether to create the header if it doesn't exist yet.

[since 24.08] const KMime::Headers::From *Message::from() const

Returns the From header.

Can be nullptr if the header doesn't exist.

This function was introduced in 24.08.

KMime::Headers::From *Message::from(KMime::CreatePolicy create = Create)

Returns the From header.

Ownership of the header remains with the Message object, the created header is automatically added to that.

create Whether to create the header if it doesn't exist yet.

[since 24.08] const KMime::Headers::InReplyTo *Message::inReplyTo() const

Returns the In-Reply-To header.

Can be nullptr if the header doesn't exist.

This function was introduced in 24.08.

KMime::Headers::InReplyTo *Message::inReplyTo(KMime::CreatePolicy create = Create)

Returns the In-Reply-To header.

Ownership of the header remains with the Message object, the created header is automatically added to that.

create Whether to create the header if it doesn't exist yet.

KMime::Content *Message::mainBodyPart(const QByteArray &type = QByteArray())

Returns the first main body part of a given type, taking multipart/mixed and multipart/alternative nodes into consideration.

Eg. bodyPart("text/html") will return a html content object if that is provided in a multipart/alternative node, but not if it's the non-first child node of a multipart/mixed node (ie. an attachment).

type The mimetype of the body part, if not given, the first body part will be returned, regardless of it's type.

[since 24.08] const KMime::Headers::MessageID *Message::messageID() const

Returns the Message-ID header.

Can be nullptr if the header doesn't exist.

This function was introduced in 24.08.

KMime::Headers::MessageID *Message::messageID(KMime::CreatePolicy create = Create)

Returns the Message-ID header.

Ownership of the header remains with the Message object, the created header is automatically added to that.

create Whether to create the header if it doesn't exist yet.

[static] QString Message::mimeType()

Returns the MIME type used for Messages

[since 24.08] const KMime::Headers::Organization *Message::organization() const

Returns the Organization header.

Can be nullptr if the header doesn't exist.

This function was introduced in 24.08.

KMime::Headers::Organization *Message::organization(KMime::CreatePolicy create = Create)

Returns the Organization header.

Ownership of the header remains with the Message object, the created header is automatically added to that.

create Whether to create the header if it doesn't exist yet.

[since 24.08] const KMime::Headers::References *Message::references() const

Returns the References header.

Can be nullptr if the header doesn't exist.

This function was introduced in 24.08.

KMime::Headers::References *Message::references(KMime::CreatePolicy create = Create)

Returns the References header.

Ownership of the header remains with the Message object, the created header is automatically added to that.

create Whether to create the header if it doesn't exist yet.

[since 24.08] const KMime::Headers::ReplyTo *Message::replyTo() const

Returns the Reply-To header.

Can be nullptr if the header doesn't exist.

This function was introduced in 24.08.

KMime::Headers::ReplyTo *Message::replyTo(KMime::CreatePolicy create = Create)

Returns the Reply-To header.

Ownership of the header remains with the Message object, the created header is automatically added to that.

create Whether to create the header if it doesn't exist yet.

[since 24.08] const KMime::Headers::Sender *Message::sender() const

Returns the Sender header.

Can be nullptr if the header doesn't exist.

This function was introduced in 24.08.

KMime::Headers::Sender *Message::sender(KMime::CreatePolicy create = Create)

Returns the Sender header.

Ownership of the header remains with the Message object, the created header is automatically added to that.

create Whether to create the header if it doesn't exist yet.

[since 24.08] const KMime::Headers::Subject *Message::subject() const

Returns the Subject header.

Can be nullptr if the header doesn't exist.

This function was introduced in 24.08.

KMime::Headers::Subject *Message::subject(KMime::CreatePolicy create = Create)

Returns the Subject header.

Ownership of the header remains with the Message object, the created header is automatically added to that.

create Whether to create the header if it doesn't exist yet.

[since 24.08] const KMime::Headers::To *Message::to() const

Returns the To header.

Can be nullptr if the header doesn't exist.

This function was introduced in 24.08.

KMime::Headers::To *Message::to(KMime::CreatePolicy create = Create)

Returns the To header.

Ownership of the header remains with the Message object, the created header is automatically added to that.

create Whether to create the header if it doesn't exist yet.

[since 24.08] const KMime::Headers::UserAgent *Message::userAgent() const

Returns the User-Agent header.

Can be nullptr if the header doesn't exist.

This function was introduced in 24.08.

KMime::Headers::UserAgent *Message::userAgent(KMime::CreatePolicy create = Create)

Returns the User-Agent header.

Ownership of the header remains with the Message object, the created header is automatically added to that.

create Whether to create the header if it doesn't exist yet.