Commit 36a9c0c8 authored by Laurent Montel's avatar Laurent Montel 😁

Move method in messagecomposer

parent 52a1dd99
cmake_minimum_required(VERSION 3.0)
set(PIM_VERSION "5.5.45")
set(PIM_VERSION "5.5.46")
if (POLICY CMP0053)
cmake_policy(SET CMP0053 NEW)
......
......@@ -99,7 +99,7 @@ void MessageFactoryNG::slotCreateReplyDone(const KMime::Message::Ptr &msg, bool
{
applyCharset(msg);
MessageCore::Util::addLinkInformation(msg, m_id, Akonadi::MessageStatus::statusReplied());
MessageComposer::Util::addLinkInformation(msg, m_id, Akonadi::MessageStatus::statusReplied());
if (m_parentFolderId > 0) {
KMime::Headers::Generic *header = new KMime::Headers::Generic("X-KMail-Fcc");
header->fromUnicodeString(QString::number(m_parentFolderId), "utf-8");
......@@ -374,7 +374,7 @@ void MessageFactoryNG::slotCreateForwardDone(const KMime::Message::Ptr &msg)
{
applyCharset(msg);
MessageCore::Util::addLinkInformation(msg, m_id, Akonadi::MessageStatus::statusForwarded());
MessageComposer::Util::addLinkInformation(msg, m_id, Akonadi::MessageStatus::statusForwarded());
msg->assemble();
Q_EMIT createForwardDone(msg);
}
......@@ -468,13 +468,13 @@ QPair< KMime::Message::Ptr, QList< KMime::Content * > > MessageFactoryNG::create
#endif
if (numberOfItems == 0) {
attachments << createForwardAttachmentMessage(m_origMsg);
MessageCore::Util::addLinkInformation(msg, m_id, Akonadi::MessageStatus::statusForwarded());
MessageComposer::Util::addLinkInformation(msg, m_id, Akonadi::MessageStatus::statusForwarded());
} else {
// iterate through all the messages to be forwarded
attachments.reserve(items.count());
for (const Akonadi::Item &item : qAsConst(items)) {
attachments << createForwardAttachmentMessage(MessageCore::Util::message(item));
MessageCore::Util::addLinkInformation(msg, item.id(), Akonadi::MessageStatus::statusForwarded());
MessageComposer::Util::addLinkInformation(msg, item.id(), Akonadi::MessageStatus::statusForwarded());
}
}
......@@ -500,7 +500,7 @@ KMime::Content *MessageFactoryNG::createForwardAttachmentMessage(const KMime::Me
msgPart->setBody(fwdMsg->encodedContent());
msgPart->assemble();
MessageCore::Util::addLinkInformation(fwdMsg, 0, Akonadi::MessageStatus::statusForwarded());
MessageComposer::Util::addLinkInformation(fwdMsg, 0, Akonadi::MessageStatus::statusForwarded());
return msgPart;
}
......@@ -633,7 +633,7 @@ KMime::Message::Ptr MessageFactoryNG::createRedirect(const QString &toStr, const
msg->assemble();
MessageCore::Util::addLinkInformation(msg, m_id, Akonadi::MessageStatus::statusForwarded());
MessageComposer::Util::addLinkInformation(msg, m_id, Akonadi::MessageStatus::statusForwarded());
return msg;
}
......@@ -803,7 +803,7 @@ QPair< KMime::Message::Ptr, KMime::Content * > MessageFactoryNG::createForwardDi
part->contentDisposition()->setParameter(QStringLiteral("name"), i18n("forwarded message"));
part->fromUnicodeString(QString::fromLatin1(fMsg->encodedContent()));
part->assemble();
MessageCore::Util::addLinkInformation(msg, item.id(), Akonadi::MessageStatus::statusForwarded());
MessageComposer::Util::addLinkInformation(msg, item.id(), Akonadi::MessageStatus::statusForwarded());
digest->addContent(part);
}
digest->assemble();
......
......@@ -38,8 +38,6 @@
#include <kmime/kmime_content.h>
#include <kmime/kmime_headers.h>
#include <mailtransportakonadi/messagequeuejob.h>
#include <AkonadiCore/item.h>
#include <Akonadi/KMime/MessageStatus>
#include <AkonadiCore/agentinstance.h>
#include <AkonadiCore/agentinstancecreatejob.h>
#include <AkonadiCore/agentmanager.h>
......@@ -273,7 +271,7 @@ void MessageComposer::Util::addSendReplyForwardAction(const KMime::Message::Ptr
{
QList<Akonadi::Item::Id> originalMessageId;
QList<Akonadi::MessageStatus> linkStatus;
if (MessageCore::Util::getLinkInformation(message, originalMessageId, linkStatus)) {
if (MessageComposer::Util::getLinkInformation(message, originalMessageId, linkStatus)) {
for (Akonadi::Item::Id id : qAsConst(originalMessageId)) {
if (linkStatus.first() == Akonadi::MessageStatus::statusReplied()) {
qjob->sentActionAttribute().addAction(MailTransport::SentActionAttribute::Action::MarkAsReplied, QVariant(id));
......@@ -343,3 +341,68 @@ KMime::Content *MessageComposer::Util::findTypeInMessage(KMime::Content *data, c
}
return nullptr;
}
void MessageComposer::Util::addLinkInformation(const KMime::Message::Ptr &msg, Akonadi::Item::Id id, Akonadi::MessageStatus status)
{
Q_ASSERT(status.isReplied() || status.isForwarded() || status.isDeleted());
QString message;
if (auto hrd = msg->headerByType("X-KMail-Link-Message")) {
message = hrd->asUnicodeString();
}
if (!message.isEmpty()) {
message += QChar::fromLatin1(',');
}
QString type;
if (auto hrd = msg->headerByType("X-KMail-Link-Type")) {
type = hrd->asUnicodeString();
}
if (!type.isEmpty()) {
type += QChar::fromLatin1(',');
}
message += QString::number(id);
if (status.isReplied()) {
type += QLatin1String("reply");
} else if (status.isForwarded()) {
type += QLatin1String("forward");
}
KMime::Headers::Generic *header = new KMime::Headers::Generic("X-KMail-Link-Message");
header->fromUnicodeString(message, "utf-8");
msg->setHeader(header);
header = new KMime::Headers::Generic("X-KMail-Link-Type");
header->fromUnicodeString(type, "utf-8");
msg->setHeader(header);
}
bool MessageComposer::Util::getLinkInformation(const KMime::Message::Ptr &msg, QList<Akonadi::Item::Id> &id, QList<Akonadi::MessageStatus> &status)
{
auto hrdLinkMsg = msg->headerByType("X-KMail-Link-Message");
auto hrdLinkType = msg->headerByType("X-KMail-Link-Type");
if (!hrdLinkMsg || !hrdLinkType) {
return false;
}
const QStringList messages = hrdLinkMsg->asUnicodeString().split(QLatin1Char(','), QString::SkipEmptyParts);
const QStringList types = hrdLinkType->asUnicodeString().split(QLatin1Char(','), QString::SkipEmptyParts);
if (messages.isEmpty() || types.isEmpty()) {
return false;
}
for (const QString &idStr : messages) {
id << idStr.toLongLong();
}
for (const QString &typeStr : types) {
if (typeStr == QLatin1String("reply")) {
status << Akonadi::MessageStatus::statusReplied();
} else if (typeStr == QLatin1String("forward")) {
status << Akonadi::MessageStatus::statusForwarded();
}
}
return true;
}
......@@ -25,6 +25,8 @@
#include "messagecomposer_export.h"
#include "Libkleo/Enum"
#include <KMime/Message>
#include <AkonadiCore/Item>
#include <Akonadi/KMime/MessageStatus>
namespace KMime
{
......@@ -54,6 +56,26 @@ MESSAGECOMPOSER_EXPORT void removeNotNecessaryHeaders(const KMime::Message::Ptr
* find mimetype in message
*/
MESSAGECOMPOSER_EXPORT KMime::Content *findTypeInMessage(KMime::Content *data, const QByteArray &mimeType, const QByteArray &subType);
/**
* Adds private headers to the given @p message that links it to the original message.
*
* @param message The message to add the link information to.
* @param id The item id of the original message.
* @param status The status (replied or forwarded) that links the message to the original message.
*/
MESSAGECOMPOSER_EXPORT void addLinkInformation(const KMime::Message::Ptr &message, Akonadi::Item::Id item, Akonadi::MessageStatus status);
/**
* Reads the private headers of the given @p message to extract link information to its original message.
*
* @param message The message to read the link information from.
* @param id Will contain the item id of the original message.
* @param status Will contain the status (replied or forwarded) that linked the message to the original message.
* @returns Whether the mail contains valid link information or not.
*/
MESSAGECOMPOSER_EXPORT bool getLinkInformation(const KMime::Message::Ptr &msg, QList<Akonadi::Item::Id> &id, QList<Akonadi::MessageStatus> &status);
}
}
......
......@@ -38,67 +38,3 @@ bool MessageCore::Util::isStandaloneMessage(const Akonadi::Item &item)
return item.hasPayload<KMime::Message::Ptr>() && !item.isValid();
}
void MessageCore::Util::addLinkInformation(const KMime::Message::Ptr &msg, Akonadi::Item::Id id, Akonadi::MessageStatus status)
{
Q_ASSERT(status.isReplied() || status.isForwarded() || status.isDeleted());
QString message;
if (auto hrd = msg->headerByType("X-KMail-Link-Message")) {
message = hrd->asUnicodeString();
}
if (!message.isEmpty()) {
message += QChar::fromLatin1(',');
}
QString type;
if (auto hrd = msg->headerByType("X-KMail-Link-Type")) {
type = hrd->asUnicodeString();
}
if (!type.isEmpty()) {
type += QChar::fromLatin1(',');
}
message += QString::number(id);
if (status.isReplied()) {
type += QLatin1String("reply");
} else if (status.isForwarded()) {
type += QLatin1String("forward");
}
KMime::Headers::Generic *header = new KMime::Headers::Generic("X-KMail-Link-Message");
header->fromUnicodeString(message, "utf-8");
msg->setHeader(header);
header = new KMime::Headers::Generic("X-KMail-Link-Type");
header->fromUnicodeString(type, "utf-8");
msg->setHeader(header);
}
bool MessageCore::Util::getLinkInformation(const KMime::Message::Ptr &msg, QList<Akonadi::Item::Id> &id, QList<Akonadi::MessageStatus> &status)
{
auto hrdLinkMsg = msg->headerByType("X-KMail-Link-Message");
auto hrdLinkType = msg->headerByType("X-KMail-Link-Type");
if (!hrdLinkMsg || !hrdLinkType) {
return false;
}
const QStringList messages = hrdLinkMsg->asUnicodeString().split(QLatin1Char(','), QString::SkipEmptyParts);
const QStringList types = hrdLinkType->asUnicodeString().split(QLatin1Char(','), QString::SkipEmptyParts);
if (messages.isEmpty() || types.isEmpty()) {
return false;
}
for (const QString &idStr : messages) {
id << idStr.toLongLong();
}
for (const QString &typeStr : types) {
if (typeStr == QLatin1String("reply")) {
status << Akonadi::MessageStatus::statusReplied();
} else if (typeStr == QLatin1String("forward")) {
status << Akonadi::MessageStatus::statusForwarded();
}
}
return true;
}
......@@ -47,24 +47,7 @@ MESSAGECORE_EXPORT KMime::Message::Ptr message(const Akonadi::Item &item);
*/
MESSAGECORE_EXPORT bool isStandaloneMessage(const Akonadi::Item &item);
/**
* Adds private headers to the given @p message that links it to the original message.
*
* @param message The message to add the link information to.
* @param id The item id of the original message.
* @param status The status (replied or forwarded) that links the message to the original message.
*/
MESSAGECORE_EXPORT void addLinkInformation(const KMime::Message::Ptr &message, Akonadi::Item::Id item, Akonadi::MessageStatus status);
/**
* Reads the private headers of the given @p message to extract link information to its original message.
*
* @param message The message to read the link information from.
* @param id Will contain the item id of the original message.
* @param status Will contain the status (replied or forwarded) that linked the message to the original message.
* @returns Whether the mail contains valid link information or not.
*/
MESSAGECORE_EXPORT bool getLinkInformation(const KMime::Message::Ptr &msg, QList<Akonadi::Item::Id> &id, QList<Akonadi::MessageStatus> &status);
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment