Git commit 87b20815f8fe1d484bb5010021e8e3f14c5d3667 by Jan Kundr?t. Committed on 05/01/2013 at 14:31. Pushed by jkt into branch 'master'.
GUI: use the new replying code M +54 -0 src/Gui/ComposeWidget.cpp M +3 -0 src/Gui/ComposeWidget.h M +12 -19 src/Gui/MessageView.cpp M +4 -3 src/Gui/Window.cpp M +6 -5 src/Gui/Window.h M +9 -0 src/Imap/Parser/MailAddress.cpp M +1 -0 src/Imap/Parser/MailAddress.h http://commits.kde.org/trojita/87b20815f8fe1d484bb5010021e8e3f14c5d3667 diff --git a/src/Gui/ComposeWidget.cpp b/src/Gui/ComposeWidget.cpp index 554bbc7..d35828b 100644 --- a/src/Gui/ComposeWidget.cpp +++ b/src/Gui/ComposeWidget.cpp @@ -42,6 +42,8 @@ #include "Common/SettingsNames.h" #include "MSA/Sendmail.h" #include "MSA/SMTP.h" +#include "Imap/Model/ItemRoles.h" +#include "Imap/Model/MailboxTree.h" #include "Imap/Model/Model.h" #include "Imap/Tasks/AppendTask.h" #include "Imap/Tasks/GenUrlAuthTask.h" @@ -710,5 +712,57 @@ bool ComposeWidget::shouldBuildMessageLocally() const && QSettings().value(Common::SettingsNames::smtpUseBurlKey, false).toBool()); } +/** @short Massage the list of recipients so that they match the desired type of reply + +In case of an error, the original list of recipients is left as is. +*/ +bool ComposeWidget::setReplyMode(const Composer::ReplyMode mode) +{ + if (!m_replyingTo.isValid()) + return false; + + using namespace Imap::Mailbox; + using namespace Imap::Message; + Model *model = dynamic_cast<Model *>(const_cast<QAbstractItemModel *>(m_replyingTo.model())); + TreeItemMessage *messagePtr = dynamic_cast<TreeItemMessage *>(static_cast<TreeItem *>(m_replyingTo.internalPointer())); + Envelope envelope = messagePtr->envelope(model); + + // Prepare the list of recipients + Composer::RecipientList originalRecipients; + Q_FOREACH(const MailAddress &addr, envelope.from) + originalRecipients << qMakePair(Composer::ADDRESS_FROM, addr); + Q_FOREACH(const MailAddress &addr, envelope.to) + originalRecipients << qMakePair(Composer::ADDRESS_TO, addr); + Q_FOREACH(const MailAddress &addr, envelope.cc) + originalRecipients << qMakePair(Composer::ADDRESS_CC, addr); + Q_FOREACH(const MailAddress &addr, envelope.bcc) + originalRecipients << qMakePair(Composer::ADDRESS_BCC, addr); + Q_FOREACH(const MailAddress &addr, envelope.sender) + originalRecipients << qMakePair(Composer::ADDRESS_SENDER, addr); + Q_FOREACH(const MailAddress &addr, envelope.replyTo) + originalRecipients << qMakePair(Composer::ADDRESS_REPLY_TO, addr); + + // The List-Post header + QList<QUrl> headerListPost; + Q_FOREACH(const QVariant &item, m_replyingTo.data(RoleMessageHeaderListPost).toList()) + headerListPost << item.toUrl(); + + // Determine the new list of reicpients + Composer::RecipientList list; + if (!Composer::Util::replyRecipientList( + mode, originalRecipients, headerListPost, m_replyingTo.data(RoleMessageHeaderListPostNo).toBool(), list)) { + return false; + } + + while (!m_recipients.isEmpty()) + removeRecipient(0); + + Q_FOREACH(const Composer::RecipientList::value_type &recipient, list) { + addRecipient(m_recipients.size(), recipient.first, recipient.second.asPrettyString()); + } + + return true; +} + } diff --git a/src/Gui/ComposeWidget.h b/src/Gui/ComposeWidget.h index d018d47..9990e9e 100644 --- a/src/Gui/ComposeWidget.h +++ b/src/Gui/ComposeWidget.h @@ -64,6 +64,9 @@ protected: void changeEvent(QEvent *e); bool eventFilter(QObject *o, QEvent *e); +public slots: + bool setReplyMode(const Composer::ReplyMode mode); + private slots: void collapseRecipients(); void completeRecipient(QAction *act); diff --git a/src/Gui/MessageView.cpp b/src/Gui/MessageView.cpp index cd5ea9d..924d044 100644 --- a/src/Gui/MessageView.cpp +++ b/src/Gui/MessageView.cpp @@ -47,6 +47,7 @@ #include "TagListWidget.h" #include "UserAgentWebPage.h" #include "Window.h" +#include "ComposeWidget.h" #include "Imap/Model/MailboxTree.h" #include "Imap/Model/MsgListModel.h" @@ -426,25 +427,17 @@ void MessageView::reply(MainWindow *mainWindow, Composer::ReplyMode mode) if (!message.isValid()) return; - const Imap::Message::Envelope &e = envelope(); - - QList<QPair<Composer::RecipientKind,QString> > recipients; - for (QList<Imap::Message::MailAddress>::const_iterator it = e.from.begin(); it != e.from.end(); ++it) { - recipients << qMakePair(Composer::ADDRESS_TO, QString::fromUtf8("%1@%2").arg(it->mailbox, it->host)); - } - if (mode == Composer::REPLY_ALL) { - for (QList<Imap::Message::MailAddress>::const_iterator it = e.to.begin(); it != e.to.end(); ++it) { - recipients << qMakePair(Composer::ADDRESS_CC, QString::fromUtf8("%1@%2").arg(it->mailbox, it->host)); - } - for (QList<Imap::Message::MailAddress>::const_iterator it = e.cc.begin(); it != e.cc.end(); ++it) { - recipients << qMakePair(Composer::ADDRESS_TO, QString::fromUtf8("%1@%2").arg(it->mailbox, it->host)); - } - } - mainWindow->invokeComposeDialog(Composer::Util::replySubject(e.subject), quoteText(), recipients, - QList<QByteArray>() << e.messageId, - message.data(Imap::Mailbox::RoleMessageHeaderReferences).value<QList<QByteArray> >() << e.messageId, - message - ); + QByteArray messageId = message.data(Imap::Mailbox::RoleMessageMessageId).toByteArray(); + + ComposeWidget *w = mainWindow->invokeComposeDialog( + Composer::Util::replySubject(message.data(Imap::Mailbox::RoleMessageSubject).toString()), quoteText(), + QList<QPair<Composer::RecipientKind,QString> >(), + QList<QByteArray>() << messageId, + message.data(Imap::Mailbox::RoleMessageHeaderReferences).value<QList<QByteArray> >() << messageId, + message + ); + bool ok = w->setReplyMode(mode); + Q_ASSERT(ok); } void MessageView::externalsRequested(const QUrl &url) diff --git a/src/Gui/Window.cpp b/src/Gui/Window.cpp index dc039ed..1474a00 100644 --- a/src/Gui/Window.cpp +++ b/src/Gui/Window.cpp @@ -1170,9 +1170,9 @@ void MainWindow::slotComposeMailUrl(const QUrl &url) invokeComposeDialog(QString(), QString(), recipients); } -void MainWindow::invokeComposeDialog(const QString &subject, const QString &body, - const RecipientsType &recipients, const QList<QByteArray> &inReplyTo, - const QList<QByteArray> &references, const QModelIndex &replyingToMessage) +ComposeWidget *MainWindow::invokeComposeDialog(const QString &subject, const QString &body, + const RecipientsType &recipients, const QList<QByteArray> &inReplyTo, + const QList<QByteArray> &references, const QModelIndex &replyingToMessage) { QSettings s; ComposeWidget *w = new ComposeWidget(this); @@ -1191,6 +1191,7 @@ void MainWindow::invokeComposeDialog(const QString &subject, const QString &body w->setData(recipients, subject, body, inReplyTo, trimmedReferences, replyingToMessage); Util::centerWidgetOnScreen(w); w->show(); + return w; } void MainWindow::slotMailboxDeleteFailed(const QString &mailbox, const QString &msg) diff --git a/src/Gui/Window.h b/src/Gui/Window.h index cd1650a..3df71e1 100644 --- a/src/Gui/Window.h +++ b/src/Gui/Window.h @@ -63,6 +63,7 @@ namespace Gui { class AbstractAddressbook; +class ComposeWidget; class MailBoxTreeView; class MessageView; class MessageListWidget; @@ -75,11 +76,11 @@ class MainWindow: public QMainWindow typedef QList<QPair<Composer::RecipientKind,QString> > RecipientsType; public: MainWindow(); - void invokeComposeDialog(const QString &subject = QString(), const QString &body = QString(), - const RecipientsType &recipients = RecipientsType(), - const QList<QByteArray> &inReplyTo = QList<QByteArray>(), - const QList<QByteArray> &references = QList<QByteArray>(), - const QModelIndex &replyingToMessage = QModelIndex()); + ComposeWidget *invokeComposeDialog(const QString &subject = QString(), const QString &body = QString(), + const RecipientsType &recipients = RecipientsType(), + const QList<QByteArray> &inReplyTo = QList<QByteArray>(), + const QList<QByteArray> &references = QList<QByteArray>(), + const QModelIndex &replyingToMessage = QModelIndex()); QSize sizeHint() const; Imap::Mailbox::Model *imapModel() const; diff --git a/src/Imap/Parser/MailAddress.cpp b/src/Imap/Parser/MailAddress.cpp index b5b765b..5ae10e4 100644 --- a/src/Imap/Parser/MailAddress.cpp +++ b/src/Imap/Parser/MailAddress.cpp @@ -243,6 +243,15 @@ QByteArray MailAddress::asMailHeader() const return result; } +/** @short The mail address usable for manipulation by user */ +QString MailAddress::asPrettyString() const +{ + return name.isEmpty() ? + QString() : + name + QLatin1Char(' ') + + QLatin1Char('<') + asSMTPMailbox() + QLatin1Char('>'); +} + QTextStream &operator<<(QTextStream &stream, const MailAddress &address) { stream << '"' << address.name << "\" <"; diff --git a/src/Imap/Parser/MailAddress.h b/src/Imap/Parser/MailAddress.h index 05c77f9..ffe9faa 100644 --- a/src/Imap/Parser/MailAddress.h +++ b/src/Imap/Parser/MailAddress.h @@ -69,6 +69,7 @@ public: QByteArray asSMTPMailbox() const; QByteArray asMailHeader() const; + QString asPrettyString() const; static QString prettyList(const QList<MailAddress> &list, FormattingMode mode); static QString prettyList(const QVariantList &list, FormattingMode mode);
