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

Continue to implement reply-to in recipient

parent 9109c1d6
......@@ -19,6 +19,7 @@
*/
#include "composerviewbase.h"
#include "config-messagecomposer.h"
#include "attachment/attachmentcontrollerbase.h"
#include "attachment/attachmentmodel.h"
......@@ -132,6 +133,9 @@ void ComposerViewBase::setMessage(const KMime::Message::Ptr &msg, bool allowDecr
m_recipientsEditor->setRecipientString(m_msg->to()->mailboxes(), MessageComposer::Recipient::To);
m_recipientsEditor->setRecipientString(m_msg->cc()->mailboxes(), MessageComposer::Recipient::Cc);
m_recipientsEditor->setRecipientString(m_msg->bcc()->mailboxes(), MessageComposer::Recipient::Bcc);
#ifdef IMPLEMENT_REPLY_TO_SUPPORT_RECIPIENT
m_recipientsEditor->setRecipientString(m_msg->replyTo()->mailboxes(), MessageComposer::Recipient::ReplyTo);
#endif
m_recipientsEditor->setFocusBottom();
// If we are loading from a draft, load unexpanded aliases as well
......@@ -159,6 +163,16 @@ void ComposerViewBase::setMessage(const KMime::Message::Ptr &msg, bool allowDecr
}
}
}
#ifdef IMPLEMENT_REPLY_TO_SUPPORT_RECIPIENT
if (auto hrd = m_msg->headerByType("X-KMail-UnExpanded-Reply-To")) {
const QStringList spl = hrd->asUnicodeString().split(QLatin1Char(','));
for (const QString &addr : spl) {
if (!m_recipientsEditor->addRecipient(addr, MessageComposer::Recipient::ReplyTo)) {
qCWarning(MESSAGECOMPOSER_LOG) << "Impossible to add recipient.";
}
}
}
#endif
}
// First, we copy the message and then parse it to the object tree parser.
......@@ -389,6 +403,10 @@ void ComposerViewBase::readyForSending()
job->setTo(m_recipientsEditor->recipientStringList(MessageComposer::Recipient::To));
job->setCc(m_recipientsEditor->recipientStringList(MessageComposer::Recipient::Cc));
job->setBcc(m_recipientsEditor->recipientStringList(MessageComposer::Recipient::Bcc));
#ifdef IMPLEMENT_REPLY_TO_SUPPORT_RECIPIENT
job->setReplyTo(m_recipientsEditor->recipientStringList(MessageComposer::Recipient::replyTo()));
#endif
connect(job, &MessageComposer::EmailAddressResolveJob::result, this, &ComposerViewBase::slotEmailAddressResolved);
job->start();
}
......@@ -409,12 +427,14 @@ void ComposerViewBase::slotEmailAddressResolved(KJob *job)
mExpandedTo = resolveJob->expandedTo();
mExpandedCc = resolveJob->expandedCc();
mExpandedBcc = resolveJob->expandedBcc();
mExpandedReplyTo = resolveJob->expandedReplyTo();
if (autoresizeImage) {
QStringList listEmails;
listEmails << mExpandedFrom;
listEmails << mExpandedTo;
listEmails << mExpandedCc;
listEmails << mExpandedBcc;
listEmails << mExpandedReplyTo;
MessageComposer::Utils resizeUtils;
autoresizeImage = resizeUtils.filterRecipients(listEmails);
}
......@@ -431,12 +451,17 @@ void ComposerViewBase::slotEmailAddressResolved(KJob *job)
case MessageComposer::Recipient::Bcc:
mExpandedBcc << r->email();
break;
#ifdef IMPLEMENT_REPLY_TO_SUPPORT_RECIPIENT
case MessageComposer::Recipient::ReplyTo:
mExpandedReplyTo << r->email();
break;
#endif
case MessageComposer::Recipient::Undefined:
Q_ASSERT(!"Unknown recpient type!");
break;
}
}
QStringList unExpandedTo, unExpandedCc, unExpandedBcc;
QStringList unExpandedTo, unExpandedCc, unExpandedBcc, unExpandedReplyTo;
foreach (const QString &exp, resolveJob->expandedTo()) {
if (!mExpandedTo.contains(exp)) { // this address was expanded, so save it explicitly
unExpandedTo << exp;
......@@ -452,6 +477,13 @@ void ComposerViewBase::slotEmailAddressResolved(KJob *job)
unExpandedBcc << exp;
}
}
#ifdef IMPLEMENT_REPLY_TO_SUPPORT_RECIPIENT
foreach (const QString &exp, resolveJob->expandedReplyTo()) {
if (!mExpandedReplyTo.contains(exp)) { // this address was expanded, so save it explicitly
unExpandedReplyTo << exp;
}
}
#endif
auto header = new KMime::Headers::Generic("X-KMail-UnExpanded-To");
header->from7BitString(unExpandedTo.join(QStringLiteral(", ")).toLatin1());
m_msg->setHeader(header);
......@@ -461,6 +493,11 @@ void ComposerViewBase::slotEmailAddressResolved(KJob *job)
header = new KMime::Headers::Generic("X-KMail-UnExpanded-BCC");
header->from7BitString(unExpandedBcc.join(QStringLiteral(", ")).toLatin1());
m_msg->setHeader(header);
#ifdef IMPLEMENT_REPLY_TO_SUPPORT_RECIPIENT
header = new KMime::Headers::Generic("X-KMail-UnExpanded-Reply-To");
header->from7BitString(unExpandedReplyTo.join(QStringLiteral(", ")).toLatin1());
m_msg->setHeader(header);
#endif
autoresizeImage = false;
}
......@@ -797,11 +834,17 @@ void ComposerViewBase::fillInfoPart(MessageComposer::InfoPart *infoPart, Compose
infoPart->setTo(mExpandedTo);
infoPart->setCc(mExpandedCc);
infoPart->setBcc(mExpandedBcc);
#ifdef IMPLEMENT_REPLY_TO_SUPPORT_RECIPIENT
infoPart->setReplyTo(mExpandedReplyTo);
#endif
} else {
infoPart->setFrom(from());
infoPart->setTo(m_recipientsEditor->recipientStringList(MessageComposer::Recipient::To));
infoPart->setCc(m_recipientsEditor->recipientStringList(MessageComposer::Recipient::Cc));
infoPart->setBcc(m_recipientsEditor->recipientStringList(MessageComposer::Recipient::Bcc));
#ifdef IMPLEMENT_REPLY_TO_SUPPORT_RECIPIENT
infoPart->setReplyTo(m_recipientsEditor->recipientStringList(MessageComposer::Recipient::ReplyTo));
#endif
}
infoPart->setSubject(subject());
infoPart->setUserAgent(QStringLiteral("KMail"));
......@@ -834,6 +877,11 @@ void ComposerViewBase::fillInfoPart(MessageComposer::InfoPart *infoPart, Compose
if (auto hdr = m_msg->headerByType("X-KMail-UnExpanded-BCC")) {
extras << hdr;
}
#ifdef IMPLEMENT_REPLY_TO_SUPPORT_RECIPIENT
if (auto hdr = m_msg->headerByType("X-KMail-UnExpanded-Reply-To")) {
extras << hdr;
}
#endif
if (auto hdr = m_msg->organization(false)) {
extras << hdr;
}
......@@ -1420,7 +1468,11 @@ QString ComposerViewBase::from() const
QString ComposerViewBase::replyTo() const
{
#ifdef IMPLEMENT_REPLY_TO_SUPPORT_RECIPIENT
return MessageComposer::Util::cleanedUpHeaderString(m_recipientsEditor->recipientString(MessageComposer::Recipient::ReplyTo));
#else
return MessageComposer::Util::cleanedUpHeaderString(m_replyTo);
#endif
}
QString ComposerViewBase::subject() const
......@@ -1493,7 +1545,12 @@ void ComposerViewBase::updateRecipients(const KIdentityManagement::Identity &ide
} else if (type == MessageComposer::Recipient::Cc) {
oldIdentList = oldIdent.cc();
newIdentList = ident.cc();
} else {
#ifdef IMPLEMENT_REPLY_TO_SUPPORT_RECIPIENT
} else if (type == MessageComposer::Recipient::replyTo()) {
oldIdentList = oldIdent.replyToAddr();
newIdentList = ident.replyToAddr();
#endif
} else {
return;
}
......@@ -1515,6 +1572,9 @@ void ComposerViewBase::identityChanged(const KIdentityManagement::Identity &iden
{
updateRecipients(ident, oldIdent, MessageComposer::Recipient::Bcc);
updateRecipients(ident, oldIdent, MessageComposer::Recipient::Cc);
#ifdef IMPLEMENT_REPLY_TO_SUPPORT_RECIPIENT
updateRecipients(ident, oldIdent, MessageComposer::Recipient::ReplyTo);
#endif
KIdentityManagement::Signature oldSig = const_cast<KIdentityManagement::Identity &>
(oldIdent).signature();
......
......@@ -354,7 +354,7 @@ private:
bool m_requestDeleveryConfirmation = false;
Kleo::CryptoMessageFormat m_cryptoMessageFormat;
QString mExpandedFrom, m_from, m_replyTo, m_subject;
QStringList mExpandedTo, mExpandedCc, mExpandedBcc;
QStringList mExpandedTo, mExpandedCc, mExpandedBcc, mExpandedReplyTo;
QList< QByteArray > m_charsets;
QMap<QByteArray, QString> m_customHeader;
......
......@@ -41,10 +41,11 @@ public:
}
QVariantMap mResultMap;
QString mFrom;
QStringList mTo;
QStringList mCc;
QStringList mBcc;
QString mFrom;
QStringList mReplyTo;
QString mDefaultDomainName;
int mJobCount = 0;
};
......@@ -112,6 +113,12 @@ void EmailAddressResolveJob::start()
connect(job, &AliasesExpandJob::result, this, &EmailAddressResolveJob::slotAliasExpansionDone);
jobs << job;
}
if (containsAliases(d->mReplyTo)) {
AliasesExpandJob *job = new AliasesExpandJob(d->mReplyTo.join(QStringLiteral(", ")), d->mDefaultDomainName, this);
job->setProperty("id", QStringLiteral("infoPartReplyTo"));
connect(job, &AliasesExpandJob::result, this, &EmailAddressResolveJob::slotAliasExpansionDone);
jobs << job;
}
d->mJobCount = jobs.count();
......@@ -166,6 +173,12 @@ void EmailAddressResolveJob::setBcc(const QStringList &bcc)
d->mResultMap.insert(QStringLiteral("infoPartBcc"), bcc.join(QStringLiteral(", ")));
}
void EmailAddressResolveJob::setReplyTo(const QStringList &replyTo)
{
d->mReplyTo = replyTo;
d->mResultMap.insert(QStringLiteral("infoPartReplyTo"), replyTo.join(QStringLiteral(", ")));
}
QString EmailAddressResolveJob::expandedFrom() const
{
return d->mResultMap.value(QStringLiteral("infoPartFrom")).toString();
......@@ -185,3 +198,8 @@ QStringList EmailAddressResolveJob::expandedBcc() const
{
return KEmailAddress::splitAddressList(d->mResultMap.value(QStringLiteral("infoPartBcc")).toString());
}
QStringList EmailAddressResolveJob::expandedReplyTo() const
{
return KEmailAddress::splitAddressList(d->mResultMap.value(QStringLiteral("infoPartReplyTo")).toString());
}
......@@ -78,6 +78,10 @@ public:
* Sets the from address to expand.
*/
virtual void setBcc(const QStringList &from);
/**
* Sets the Reply-To address to expand.
*/
virtual void setReplyTo(const QStringList &replyTo);
/**
* Returns the expanded From field
......@@ -100,6 +104,10 @@ public:
Q_REQUIRED_RESULT virtual QStringList expandedBcc() const;
void setDefaultDomainName(const QString &domainName);
/**
* Returns the expanded Reply-To field
*/
Q_REQUIRED_RESULT virtual QStringList expandedReplyTo() const;
private Q_SLOTS:
void slotAliasExpansionDone(KJob *);
......
......@@ -29,7 +29,7 @@
using namespace KPIM;
using namespace MessageComposer;
//#define IMPLEMENT_REPLY_TO 1
class MessageComposer::RecipientPrivate
{
public:
......
......@@ -249,7 +249,7 @@ void RecipientsEditor::slotLineAdded(MultiplyingLine *line)
if (count > 0) {
if (count == 1) {
RecipientLineNG *last_rec = qobject_cast< RecipientLineNG * >(lines().first());
if (last_rec && last_rec->recipientType() == Recipient::Bcc) {
if (last_rec && (last_rec->recipientType() == Recipient::Bcc || last_rec->recipientType() == Recipient::ReplyTo)) {
rec->setRecipientType(Recipient::To);
} else {
rec->setRecipientType(Recipient::Cc);
......
......@@ -79,14 +79,25 @@ RecipientsPicker::RecipientsPicker(QWidget *parent)
buttonBox->addButton(mUser2Button, QDialogButtonBox::ActionRole);
mUser3Button = new QPushButton;
buttonBox->addButton(mUser3Button, QDialogButtonBox::ActionRole);
#ifdef IMPLEMENT_REPLY_TO_SUPPORT_RECIPIENT
mUser4Button = new QPushButton;
buttonBox->addButton(mUser4Button, QDialogButtonBox::ActionRole);
#endif
connect(buttonBox, &QDialogButtonBox::rejected, this, &RecipientsPicker::reject);
mainLayout->addWidget(buttonBox);
#ifdef IMPLEMENT_REPLY_TO_SUPPORT_RECIPIENT
mUser4Button->setText(i18n("Add as &Reply-To"));
#endif
mUser3Button->setText(i18n("Add as &To"));
mUser2Button->setText(i18n("Add as CC"));
mUser1Button->setText(i18n("Add as &BCC"));
connect(mUser1Button, &QPushButton::clicked, this, &RecipientsPicker::slotBccClicked);
connect(mUser2Button, &QPushButton::clicked, this, &RecipientsPicker::slotCcClicked);
connect(mUser3Button, &QPushButton::clicked, this, &RecipientsPicker::slotToClicked);
#ifdef IMPLEMENT_REPLY_TO_SUPPORT_RECIPIENT
connect(mUser4Button, &QPushButton::clicked, this, &RecipientsPicker::slotReplyToClicked);
#endif
mView->emailAddressSelectionWidget()->searchLineEdit()->setFocus();
......@@ -106,6 +117,9 @@ void RecipientsPicker::slotSelectionChanged()
mUser1Button->setEnabled(hasSelection);
mUser2Button->setEnabled(hasSelection);
mUser3Button->setEnabled(hasSelection);
#ifdef IMPLEMENT_REPLY_TO_SUPPORT_RECIPIENT
mUser4Button->setEnabled(hasSelection);
#endif
}
void RecipientsPicker::setRecipients(const Recipient::List &)
......@@ -119,6 +133,10 @@ void RecipientsPicker::setDefaultType(Recipient::Type type)
mUser1Button->setDefault(type == Recipient::To);
mUser2Button->setDefault(type == Recipient::Cc);
mUser3Button->setDefault(type == Recipient::Bcc);
#ifdef IMPLEMENT_REPLY_TO_SUPPORT_RECIPIENT
mUser4Button->setDefault(type == Recipient::ReplyTo);
#endif
}
void RecipientsPicker::slotToClicked()
......@@ -126,6 +144,13 @@ void RecipientsPicker::slotToClicked()
pick(Recipient::To);
}
void RecipientsPicker::slotReplyToClicked()
{
#ifdef IMPLEMENT_REPLY_TO_SUPPORT_RECIPIENT
pick(Recipient::ReplyTo);
#endif
}
void RecipientsPicker::slotCcClicked()
{
pick(Recipient::Cc);
......
......@@ -22,6 +22,7 @@
#define MESSAGECOMPOSER_RECIPIENTSPICKER_H
#include <MessageComposer/Recipient>
#include "config-messagecomposer.h"
#include <kcontacts/addressee.h>
#include <QDialog>
......@@ -61,6 +62,7 @@ protected Q_SLOTS:
void slotToClicked();
void slotCcClicked();
void slotBccClicked();
void slotReplyToClicked();
void slotPicked();
void slotSearchLDAP();
void ldapSearchResult();
......@@ -72,6 +74,9 @@ private:
KLDAP::LdapSearchDialog *mLdapSearchDialog = nullptr;
Recipient::Type mDefaultType;
#ifdef IMPLEMENT_REPLY_TO_SUPPORT_RECIPIENT
QPushButton *mUser4Button = nullptr;
#endif
QPushButton *mUser3Button = nullptr;
QPushButton *mUser2Button = nullptr;
QPushButton *mUser1Button = nullptr;
......
......@@ -342,6 +342,7 @@ void removePrivateHeaderFields(const KMime::Message::Ptr &message, bool cleanUpH
message->removeHeader("X-KMail-UnExpanded-To");
message->removeHeader("X-KMail-UnExpanded-CC");
message->removeHeader("X-KMail-UnExpanded-BCC");
message->removeHeader("X-KMail-UnExpanded-Reply-To");
message->removeHeader("X-KMail-FccDisabled");
if (cleanUpHeader) {
......
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