Commit aabadbf7 authored by Sandro Knauß's avatar Sandro Knauß 🐝
Browse files

MessageCore: move logic to detect identity for message into Messagecore.

We need to detect the identity of a message to know, if Autocrypt is
enabled the core logic should be shared. In future we may want to add
more ways to detect the identity, like the header Delivered-To,
X-Original-To or [X-]Envelope-To. But this needs to be determined later.
parent d094caa9
Pipeline #47279 passed with stage
in 16 minutes and 51 seconds
......@@ -22,6 +22,7 @@
#include <KEmailAddress>
#include <MessageCore/MailingList>
#include <MessageCore/StringUtil>
#include <MessageCore/Util>
#include "helper/messagehelper.h"
#include <KLocalizedString>
#include "messagecomposer_debug.h"
......@@ -901,11 +902,7 @@ uint MessageFactoryNG::identityUoid(const KMime::Message::Ptr &msg)
uint id = idString.toUInt(&ok);
if (!ok || id == 0) {
id = mIdentityManager->identityForAddress(msg->to()->asUnicodeString() + QLatin1String(", ") + msg->cc()->asUnicodeString()).uoid();
}
if (id == 0 && mFolderId > 0) {
id = mFolderId;
id = MessageCore::Util::identityForMessage(msg.data(), mIdentityManager, mFolderId).uoid();
}
return id;
}
......
......@@ -27,6 +27,7 @@ set(messagecore_helper_LIB_SRCS
set(messagecore_utils_LIB_SRCS
utils/stringutil.cpp
utils/util.cpp
utils/colorutil.cpp
)
......@@ -104,6 +105,7 @@ ecm_generate_headers(MessageCore_Camelcaseutils_HEADERS
HEADER_NAMES
ColorUtil
StringUtil
Util
REQUIRED_HEADERS MessageCore_utils_HEADERS
PREFIX MessageCore
RELATIVE utils
......
/* SPDX-FileCopyrightText: 2020 Sandro Knauß <knauss@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "util.h"
#include <KIdentityManagement/Identity>
#include <KIdentityManagement/IdentityManager>
#include <KMime/Message>
using namespace MessageCore;
const KIdentityManagement::Identity &Util::identityForMessage(KMime::Message *msg, const KIdentityManagement::IdentityManager *const identMgr, uint folderIdentityId)
{
const auto &identity = identMgr->identityForAddress(msg->to()->asUnicodeString() + QLatin1String(", ") + msg->cc()->asUnicodeString());
if (identity.isNull()) {
return identMgr->identityForUoidOrDefault(folderIdentityId);
}
return identity;
}
/* SPDX-FileCopyrightText: 2020 Sandro Knauß <knauss@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#ifndef MESSAGECORE_UTILS_H
#define MESSAGECORE_UTILS_H
#include "messagecore_export.h"
#include <KIdentityManagement/Identity>
namespace KIdentityManagement {
class IdentityManager;
}
namespace KMime {
class Message;
}
namespace MessageCore {
/**
* This namespace contain helper functions
*/
namespace Util {
Q_REQUIRED_RESULT MESSAGECORE_EXPORT const KIdentityManagement::Identity &identityForMessage(KMime::Message *msg, const KIdentityManagement::IdentityManager *const identMgr, uint folderIdentityId);
}
}
#endif
......@@ -62,6 +62,7 @@
#include <messageflags.h>
#include <Akonadi/KMime/SpecialMailCollections>
#include <MailTransportAkonadi/ErrorAttribute>
#include <MessageCore/Util>
//Qt includes
#include <QClipboard>
......@@ -3149,24 +3150,13 @@ DKIMViewerMenu *ViewerPrivate::dkimViewerMenu()
return nullptr;
}
bool ViewerPrivate::isAutocryptEnabled(const KMime::Content *content)
bool ViewerPrivate::isAutocryptEnabled(KMime::Message *message)
{
if (!mIdentityManager) {
return false;
}
QString addresses;
if (content->headerByType("to")) {
addresses += content->headerByType("to")->asUnicodeString();
}
if (content->headerByType("cc")) {
if (!addresses.isEmpty()) {
addresses += QLatin1String(", ");
}
addresses += content->headerByType("cc")->asUnicodeString();
}
const auto id = mIdentityManager->identityForAddress(addresses);
const auto id = MessageCore::Util::identityForMessage(message, mIdentityManager, mFolderIdentity);
return id.autocryptEnabled();
}
......
......@@ -432,7 +432,7 @@ public:
void updateShowMultiMessagesButton(bool enablePreviousButton, bool enableNextButton);
MessageViewer::DKIMViewerMenu *dkimViewerMenu();
Q_REQUIRED_RESULT bool isAutocryptEnabled(const KMime::Content *content);
Q_REQUIRED_RESULT bool isAutocryptEnabled(KMime::Message *message);
void setIdentityManager(KIdentityManagement::IdentityManager *ident);
void setFolderIdentity(uint folderIdentity);
......
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