File indexing completed on 2024-12-22 05:01:11
0001 /* 0002 SPDX-FileCopyrightText: 2017-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "createforwardmessagejob.h" 0008 #include "../util.h" 0009 #include "kmkernel.h" 0010 #include <KEmailAddress> 0011 #include <MailCommon/MailUtil> 0012 #include <MessageComposer/Composer> 0013 0014 CreateForwardMessageJob::CreateForwardMessageJob(QObject *parent) 0015 : QObject(parent) 0016 { 0017 } 0018 0019 CreateForwardMessageJob::~CreateForwardMessageJob() 0020 { 0021 delete mMessageFactory; 0022 } 0023 0024 void CreateForwardMessageJob::setSettings(const CreateForwardMessageJobSettings &value) 0025 { 0026 mSettings = value; 0027 } 0028 0029 void CreateForwardMessageJob::start() 0030 { 0031 const auto col = CommonKernel->collectionFromId(mSettings.item.parentCollection().id()); 0032 mMessageFactory = new MessageComposer::MessageFactoryNG(mSettings.msg, mSettings.item.id(), col); 0033 connect(mMessageFactory, &MessageComposer::MessageFactoryNG::createForwardDone, this, &CreateForwardMessageJob::slotCreateForwardDone); 0034 mMessageFactory->setIdentityManager(KMKernel::self()->identityManager()); 0035 mMessageFactory->setFolderIdentity(MailCommon::Util::folderIdentity(mSettings.item)); 0036 mMessageFactory->setSelection(mSettings.selection); 0037 mMessageFactory->setTemplate(mSettings.templateStr); 0038 mMessageFactory->createForwardAsync(); 0039 } 0040 0041 void CreateForwardMessageJob::slotCreateForwardDone(const KMime::Message::Ptr &fmsg) 0042 { 0043 if (mSettings.url.isValid()) { 0044 fmsg->to()->fromUnicodeString(KEmailAddress::decodeMailtoUrl(mSettings.url).toLower(), "utf-8"); 0045 } 0046 bool lastEncrypt = false; 0047 bool lastSign = false; 0048 KMail::Util::lastEncryptAndSignState(lastEncrypt, lastSign, mSettings.msg); 0049 0050 if (mSettings.url.isValid()) { 0051 KMail::Composer *win = KMail::makeComposer(fmsg, lastSign, lastEncrypt, KMail::Composer::Forward); 0052 win->show(); 0053 } else { 0054 uint id = 0; 0055 if (auto hrd = mSettings.msg->headerByType("X-KMail-Identity")) { 0056 id = hrd->asUnicodeString().trimmed().toUInt(); 0057 } 0058 if (id == 0) { 0059 id = mSettings.identity; 0060 } 0061 KMail::Composer *win = KMail::makeComposer(fmsg, lastSign, lastEncrypt, KMail::Composer::Forward, id, QString(), mSettings.templateStr); 0062 win->show(); 0063 } 0064 deleteLater(); 0065 } 0066 0067 #include "moc_createforwardmessagejob.cpp"