Commit dd5d5145 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Try to reduce duplicate code with akonadisender

parent c29b241b
Pipeline #73014 canceled with stage
......@@ -1063,13 +1063,31 @@ void ComposerViewBase::queueMessage(const KMime::Message::Ptr &message, MessageC
} else {
qjob->sentBehaviourAttribute().setSentBehaviour(MailTransport::SentBehaviourAttribute::MoveToDefaultSentCollection);
}
MessageComposer::Util::addSendReplyForwardAction(message, qjob);
fillQueueJobHeaders(qjob, message, infoPart);
MailTransport::Transport *transport = MailTransport::TransportManager::self()->transportById(infoPart->transportId());
if (transport && transport->specifySenderOverwriteAddress()) {
qjob->addressAttribute().setFrom(
KEmailAddress::extractEmailAddress(KEmailAddress::normalizeAddressesAndEncodeIdn(transport->senderOverwriteAddress())));
} else {
qjob->addressAttribute().setFrom(KEmailAddress::extractEmailAddress(KEmailAddress::normalizeAddressesAndEncodeIdn(infoPart->from())));
}
// if this header is not empty, it contains the real recipient of the message, either the primary or one of the
// secondary recipients. so we set that to the transport job, while leaving the message itself alone.
if (KMime::Headers::Base *realTo = message->headerByType("X-KMail-EncBccRecipients")) {
qjob->addressAttribute().setTo(MessageComposer::Util::cleanUpEmailListAndEncoding(realTo->asUnicodeString().split(QLatin1Char('%'))));
message->removeHeader("X-KMail-EncBccRecipients");
message->assemble();
qCDebug(MESSAGECOMPOSER_LOG) << "sending with-bcc encr mail to a/n recipient:" << qjob->addressAttribute().to();
} else {
qjob->addressAttribute().setTo(MessageComposer::Util::cleanUpEmailListAndEncoding(infoPart->to()));
qjob->addressAttribute().setCc(MessageComposer::Util::cleanUpEmailListAndEncoding(infoPart->cc()));
qjob->addressAttribute().setBcc(MessageComposer::Util::cleanUpEmailListAndEncoding(infoPart->bcc()));
}
MessageComposer::Util::addSendReplyForwardAction(message, qjob);
MessageCore::StringUtil::removePrivateHeaderFields(message, false);
addCustomHeaders(message);
MessageComposer::Util::addCustomHeaders(message, m_customHeader);
message->assemble();
connect(qjob, &MailTransport::MessageQueueJob::result, this, &ComposerViewBase::slotQueueResult);
m_pendingQueueJobs++;
......@@ -1104,29 +1122,6 @@ void ComposerViewBase::slotQueueResult(KJob *job)
}
}
void ComposerViewBase::fillQueueJobHeaders(MailTransport::MessageQueueJob *qjob, KMime::Message::Ptr message, const MessageComposer::InfoPart *infoPart)
{
MailTransport::Transport *transport = MailTransport::TransportManager::self()->transportById(infoPart->transportId());
if (transport && transport->specifySenderOverwriteAddress()) {
qjob->addressAttribute().setFrom(
KEmailAddress::extractEmailAddress(KEmailAddress::normalizeAddressesAndEncodeIdn(transport->senderOverwriteAddress())));
} else {
qjob->addressAttribute().setFrom(KEmailAddress::extractEmailAddress(KEmailAddress::normalizeAddressesAndEncodeIdn(infoPart->from())));
}
// if this header is not empty, it contains the real recipient of the message, either the primary or one of the
// secondary recipients. so we set that to the transport job, while leaving the message itself alone.
if (KMime::Headers::Base *realTo = message->headerByType("X-KMail-EncBccRecipients")) {
qjob->addressAttribute().setTo(MessageComposer::Util::cleanUpEmailListAndEncoding(realTo->asUnicodeString().split(QLatin1Char('%'))));
message->removeHeader("X-KMail-EncBccRecipients");
message->assemble();
qCDebug(MESSAGECOMPOSER_LOG) << "sending with-bcc encr mail to a/n recipient:" << qjob->addressAttribute().to();
} else {
qjob->addressAttribute().setTo(MessageComposer::Util::cleanUpEmailListAndEncoding(infoPart->to()));
qjob->addressAttribute().setCc(MessageComposer::Util::cleanUpEmailListAndEncoding(infoPart->cc()));
qjob->addressAttribute().setBcc(MessageComposer::Util::cleanUpEmailListAndEncoding(infoPart->bcc()));
}
}
void ComposerViewBase::initAutoSave()
{
qCDebug(MESSAGECOMPOSER_LOG) << "initialising autosave";
......@@ -1330,17 +1325,6 @@ void ComposerViewBase::writeAutoSaveToDisk(const KMime::Message::Ptr &message)
message->clear();
}
void ComposerViewBase::addCustomHeaders(const KMime::Message::Ptr &message)
{
QMapIterator<QByteArray, QString> customHeader(m_customHeader);
while (customHeader.hasNext()) {
customHeader.next();
auto header = new KMime::Headers::Generic(customHeader.key().constData());
header->fromUnicodeString(customHeader.value(), "utf-8");
message->setHeader(header);
}
}
void ComposerViewBase::saveMessage(const KMime::Message::Ptr &message, MessageComposer::MessageSender::SaveIn saveIn)
{
Akonadi::Collection target;
......@@ -1354,7 +1338,7 @@ void ComposerViewBase::saveMessage(const KMime::Message::Ptr &message, MessageCo
}
}
}
addCustomHeaders(message);
MessageComposer::Util::addCustomHeaders(message, m_customHeader);
message->assemble();
......@@ -1820,7 +1804,7 @@ void ComposerViewBase::collectImages(KMime::Content *root)
}
//-----------------------------------------------------------------------------
bool ComposerViewBase::inlineSigningEncryptionSelected()
bool ComposerViewBase::inlineSigningEncryptionSelected() const
{
if (!m_sign && !m_encrypt) {
return false;
......
......@@ -265,13 +265,13 @@ private Q_SLOTS:
void slotSaveMessage(KJob *job);
private:
Akonadi::Collection defaultSpecialTarget() const;
Q_REQUIRED_RESULT Akonadi::Collection defaultSpecialTarget() const;
/**
* Searches the mime tree, where root is the root node, for embedded images,
* extracts them froom the body and adds them to the editor.
*/
void collectImages(KMime::Content *root);
bool inlineSigningEncryptionSelected();
Q_REQUIRED_RESULT bool inlineSigningEncryptionSelected() const;
/**
* Applies the user changes to the message object of the composer
* and signs/encrypts the message if activated.
......@@ -280,13 +280,11 @@ private:
void readyForSending();
enum RecipientExpansion { UseExpandedRecipients, UseUnExpandedRecipients };
QVector<MessageComposer::Composer *> generateCryptoMessages(bool &wasCanceled);
Q_REQUIRED_RESULT QVector<MessageComposer::Composer *> generateCryptoMessages(bool &wasCanceled);
void fillGlobalPart(MessageComposer::GlobalPart *globalPart);
void fillInfoPart(MessageComposer::InfoPart *part, RecipientExpansion expansion);
void queueMessage(const KMime::Message::Ptr &message, MessageComposer::Composer *composer);
void saveMessage(const KMime::Message::Ptr &message, MessageComposer::MessageSender::SaveIn saveIn);
void fillQueueJobHeaders(MailTransport::MessageQueueJob *qjob, KMime::Message::Ptr message, const MessageComposer::InfoPart *infoPart);
QStringList cleanEmailList(const QStringList &emails);
void saveRecentAddresses(const KMime::Message::Ptr &ptr);
void updateRecipients(const KIdentityManagement::Identity &ident, const KIdentityManagement::Identity &oldIdent, MessageComposer::Recipient::Type type);
......@@ -318,7 +316,6 @@ private:
void initAutoSave();
void addFollowupReminder(const QString &messageId);
void addSendLaterItem(const Akonadi::Item &item);
void addCustomHeaders(const KMime::Message::Ptr &message);
bool addKeysToContext(const QString &gnupgHome,
const QVector<QPair<QStringList, std::vector<GpgME::Key>>> &data,
......
......@@ -490,3 +490,14 @@ QStringList MessageComposer::Util::cleanUpEmailListAndEncoding(const QStringList
{
return cleanEmailList(encodeIdn(emails));
}
void MessageComposer::Util::addCustomHeaders(const KMime::Message::Ptr &message, const QMap<QByteArray, QString> &custom)
{
QMapIterator<QByteArray, QString> customHeader(custom);
while (customHeader.hasNext()) {
customHeader.next();
auto header = new KMime::Headers::Generic(customHeader.key().constData());
header->fromUnicodeString(customHeader.value(), "utf-8");
message->setHeader(header);
}
}
......@@ -78,6 +78,7 @@ Q_REQUIRED_RESULT MESSAGECOMPOSER_EXPORT bool hasMissingAttachments(const QStrin
Q_REQUIRED_RESULT MESSAGECOMPOSER_EXPORT QStringList cleanEmailList(const QStringList &emails);
Q_REQUIRED_RESULT MESSAGECOMPOSER_EXPORT QStringList cleanUpEmailListAndEncoding(const QStringList &emails);
MESSAGECOMPOSER_EXPORT void addCustomHeaders(const KMime::Message::Ptr &message, const QMap<QByteArray, QString> &customHeader);
}
}
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