From ab02e8822bad9e7e1693b8e6a65b9d5d3e4c6318 Mon Sep 17 00:00:00 2001 From: Laurent Montel Date: Mon, 24 Sep 2018 13:19:34 +0200 Subject: [PATCH 1/2] Initialize with identity --- src/job/fillcomposerjob.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/job/fillcomposerjob.cpp b/src/job/fillcomposerjob.cpp index 02240266f..9e25d1093 100644 --- a/src/job/fillcomposerjob.cpp +++ b/src/job/fillcomposerjob.cpp @@ -40,7 +40,7 @@ FillComposerJob::~FillComposerJob() void FillComposerJob::start() { mMsg = KMime::Message::Ptr(new KMime::Message); - MessageHelper::initHeader(mMsg, KMKernel::self()->identityManager()); + MessageHelper::initHeader(mMsg, KMKernel::self()->identityManager(), mSettings.mIdentity); mMsg->contentType()->setCharset("utf-8"); if (!mSettings.mCc.isEmpty()) { mMsg->cc()->fromUnicodeString(mSettings.mCc, "utf-8"); From 23735c196825fab47f2f667c24f8ef7bb0eb3c28 Mon Sep 17 00:00:00 2001 From: Laurent Montel Date: Mon, 24 Sep 2018 13:20:06 +0200 Subject: [PATCH 2/2] Allow to restore with mailtransportname and identity name. bug reported by David. For example we will able to resend mail when we migrate mail in another computer. --- src/editor/kmcomposerwin.cpp | 92 ++++++++++++++++++++++++++++++++---- 1 file changed, 82 insertions(+), 10 deletions(-) diff --git a/src/editor/kmcomposerwin.cpp b/src/editor/kmcomposerwin.cpp index 2b598747f..0af83d9f6 100644 --- a/src/editor/kmcomposerwin.cpp +++ b/src/editor/kmcomposerwin.cpp @@ -1543,7 +1543,34 @@ void KMComposerWin::setMessage(const KMime::Message::Ptr &newMsg, bool lastSignS if (auto hrd = newMsg->headerByType("X-KMail-Identity")) { const QString identityStr = hrd->asUnicodeString(); if (!identityStr.isEmpty()) { - mId = identityStr.toUInt(); + const KIdentityManagement::Identity &ident = KMKernel::self()->identityManager()->identityForUoid(identityStr.toUInt()); + if (ident.isNull()) { + if (auto hrd = newMsg->headerByType("X-KMail-Identity-Name")) { + const QString identityStrName = hrd->asUnicodeString(); + const KIdentityManagement::Identity id = KMKernel::self()->identityManager()->modifyIdentityForName(identityStrName); + if (!id.isNull()) { + mId = id.uoid(); + } else { + mId = 0; + } + } else { + mId = 0; + } + } else { + mId = identityStr.toUInt(); + } + } + } else { + if (auto hrd = newMsg->headerByType("X-KMail-Identity-Name")) { + const QString identityStrName = hrd->asUnicodeString(); + const KIdentityManagement::Identity id = KMKernel::self()->identityManager()->modifyIdentityForName(identityStrName); + if (!id.isNull()) { + mId = id.uoid(); + } else { + mId = 0; + } + } else { + mId = 0; } } @@ -2996,16 +3023,61 @@ void KMComposerWin::slotIdentityChanged(uint uoid, bool initialChange) mMsg->setHeader(header); } } - const int transportId = ident.transport().isEmpty() ? -1 : ident.transport().toInt(); - const Transport *transport = TransportManager::self()->transportById(transportId, true); - if (!transport) { - mMsg->removeHeader("X-KMail-Transport"); - mComposerBase->transportComboBox()->setCurrentTransport(TransportManager::self()->defaultTransportId()); + + + if (initialChange) { + if (auto hrd = mMsg->headerByType("X-KMail-Transport")) { + const QString mailtransportStr = hrd->asUnicodeString(); + if (!mailtransportStr.isEmpty()) { + int transportId = mailtransportStr.toInt(); + const Transport *transport = TransportManager::self()->transportById(transportId, false); /*don't return default transport */ + if (transport) { + KMime::Headers::Generic *header = new KMime::Headers::Generic("X-KMail-Transport"); + header->fromUnicodeString(QString::number(transport->id()), "utf-8"); + mMsg->setHeader(header); + mComposerBase->transportComboBox()->setCurrentTransport(transport->id()); + } else { + if (auto hrd = mMsg->headerByType("X-KMail-Transport-Name")) { + const QString identityStrName = hrd->asUnicodeString(); + const Transport *transport = TransportManager::self()->transportByName(identityStrName, true); + if (transport) { + KMime::Headers::Generic *header = new KMime::Headers::Generic("X-KMail-Transport"); + header->fromUnicodeString(QString::number(transport->id()), "utf-8"); + mMsg->setHeader(header); + mComposerBase->transportComboBox()->setCurrentTransport(transport->id()); + } else { + mComposerBase->transportComboBox()->setCurrentTransport(TransportManager::self()->defaultTransportId()); + } + } else { + mComposerBase->transportComboBox()->setCurrentTransport(TransportManager::self()->defaultTransportId()); + } + } + } + } else { + const int transportId = ident.transport().isEmpty() ? -1 : ident.transport().toInt(); + const Transport *transport = TransportManager::self()->transportById(transportId, true); + if (transport) { + KMime::Headers::Generic *header = new KMime::Headers::Generic("X-KMail-Transport"); + header->fromUnicodeString(QString::number(transport->id()), "utf-8"); + mMsg->setHeader(header); + mComposerBase->transportComboBox()->setCurrentTransport(transport->id()); + } else { + mComposerBase->transportComboBox()->setCurrentTransport(TransportManager::self()->defaultTransportId()); + } + + } } else { - KMime::Headers::Generic *header = new KMime::Headers::Generic("X-KMail-Transport"); - header->fromUnicodeString(QString::number(transport->id()), "utf-8"); - mMsg->setHeader(header); - mComposerBase->transportComboBox()->setCurrentTransport(transport->id()); + const int transportId = ident.transport().isEmpty() ? -1 : ident.transport().toInt(); + const Transport *transport = TransportManager::self()->transportById(transportId, true); + if (!transport) { + mMsg->removeHeader("X-KMail-Transport"); + mComposerBase->transportComboBox()->setCurrentTransport(TransportManager::self()->defaultTransportId()); + } else { + KMime::Headers::Generic *header = new KMime::Headers::Generic("X-KMail-Transport"); + header->fromUnicodeString(QString::number(transport->id()), "utf-8"); + mMsg->setHeader(header); + mComposerBase->transportComboBox()->setCurrentTransport(transport->id()); + } } const bool fccIsDisabled = ident.disabledFcc();