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 "createreplymessagejob.h" 0008 0009 #include "../util.h" 0010 #include "kmkernel.h" 0011 #include <KEmailAddress> 0012 #include <MailCommon/MailUtil> 0013 #include <MessageComposer/Composer> 0014 0015 CreateReplyMessageJob::CreateReplyMessageJob(QObject *parent) 0016 : QObject(parent) 0017 { 0018 } 0019 0020 CreateReplyMessageJob::~CreateReplyMessageJob() 0021 { 0022 delete mMessageFactory; 0023 } 0024 0025 void CreateReplyMessageJob::setSettings(const CreateReplyMessageJobSettings &settings) 0026 { 0027 mSettings = settings; 0028 } 0029 0030 /// Small helper function to get the composer context from a reply 0031 inline KMail::Composer::TemplateContext replyContext(const MessageComposer::MessageFactoryNG::MessageReply &reply) 0032 { 0033 if (reply.replyAll) { 0034 return KMail::Composer::ReplyToAll; 0035 } else { 0036 return KMail::Composer::Reply; 0037 } 0038 } 0039 0040 void CreateReplyMessageJob::start() 0041 { 0042 const auto col = CommonKernel->collectionFromId(mSettings.item.parentCollection().id()); 0043 mMessageFactory = new MessageComposer::MessageFactoryNG(mSettings.msg, mSettings.item.id(), col); 0044 mMessageFactory->setIdentityManager(KMKernel::self()->identityManager()); 0045 mMessageFactory->setFolderIdentity(MailCommon::Util::folderIdentity(mSettings.item)); 0046 mMessageFactory->setMailingListAddresses(KMail::Util::mailingListsFromMessage(mSettings.item)); 0047 mMessageFactory->putRepliesInSameFolder(KMail::Util::putRepliesInSameFolder(mSettings.item)); 0048 mMessageFactory->setSelection(mSettings.selection); 0049 mMessageFactory->setTemplate(mSettings.templateStr); 0050 mMessageFactory->setReplyAsHtml(mSettings.replyAsHtml); 0051 if (mSettings.noQuote) { 0052 mMessageFactory->setQuote(false); 0053 } 0054 connect(mMessageFactory, &MessageComposer::MessageFactoryNG::createReplyDone, this, &CreateReplyMessageJob::slotCreateReplyDone); 0055 mMessageFactory->setReplyStrategy(mSettings.replyStrategy); 0056 mMessageFactory->createReplyAsync(); 0057 } 0058 0059 void CreateReplyMessageJob::slotCreateReplyDone(const MessageComposer::MessageFactoryNG::MessageReply &reply) 0060 { 0061 KMime::Message::Ptr rmsg = reply.msg; 0062 if (mSettings.url.isValid()) { 0063 rmsg->to()->fromUnicodeString(KEmailAddress::decodeMailtoUrl(mSettings.url), "utf-8"); 0064 } 0065 bool lastEncrypt = false; 0066 bool lastSign = false; 0067 KMail::Util::lastEncryptAndSignState(lastEncrypt, lastSign, mSettings.msg); 0068 0069 KMail::Composer *win = KMail::makeComposer(rmsg, 0070 lastSign, 0071 lastEncrypt, 0072 (mSettings.replyStrategy == MessageComposer::ReplyNone) ? KMail::Composer::Reply : replyContext(reply), 0073 0, 0074 mSettings.selection, 0075 mSettings.templateStr); 0076 win->setFocusToEditor(); 0077 win->show(); 0078 deleteLater(); 0079 } 0080 0081 #include "moc_createreplymessagejob.cpp"