Changeset View
Changeset View
Standalone View
Standalone View
messagecomposer/src/helper/messagefactoryng.cpp
Show First 20 Lines • Show All 84 Lines • ▼ Show 20 Line(s) | 76 | MessageFactoryNG::MessageFactoryNG(const KMime::Message::Ptr &origMsg, Akonadi::Item::Id id, const Akonadi::Collection &col, QObject *parent) | |||
---|---|---|---|---|---|
85 | , m_id(id) | 85 | , m_id(id) | ||
86 | { | 86 | { | ||
87 | } | 87 | } | ||
88 | 88 | | |||
89 | MessageFactoryNG::~MessageFactoryNG() | 89 | MessageFactoryNG::~MessageFactoryNG() | ||
90 | { | 90 | { | ||
91 | } | 91 | } | ||
92 | 92 | | |||
93 | // Return the addresses to use when replying to the author of msg. | ||||
94 | // See <https://cr.yp.to/proto/replyto.html>. | ||||
95 | static KMime::Types::Mailbox::List authorMailboxes( | ||||
96 | const KMime::Message::Ptr &msg, | ||||
97 | KMime::Types::Mailbox::List mailingLists) | ||||
98 | { | ||||
99 | if (auto mrt = msg->headerByType("Mail-Reply-To")) { | ||||
100 | return KMime::Types::Mailbox::listFrom7BitString(mrt->as7BitString(false)); | ||||
101 | } | ||||
102 | if (auto rt = msg->replyTo(false)) { | ||||
103 | // Did a mailing list munge Reply-To? | ||||
104 | auto mboxes = rt->mailboxes(); | ||||
105 | for (const auto &list : mailingLists) { | ||||
106 | mboxes.removeAll(list); | ||||
107 | } | ||||
108 | if (!mboxes.isEmpty()) { | ||||
109 | return mboxes; | ||||
110 | } | ||||
111 | } | ||||
112 | return msg->from(true)->mailboxes(); | ||||
113 | } | ||||
114 | | ||||
93 | void MessageFactoryNG::slotCreateReplyDone(const KMime::Message::Ptr &msg, bool replyAll) | 115 | void MessageFactoryNG::slotCreateReplyDone(const KMime::Message::Ptr &msg, bool replyAll) | ||
94 | { | 116 | { | ||
95 | applyCharset(msg); | 117 | applyCharset(msg); | ||
96 | 118 | | |||
97 | MessageComposer::Util::addLinkInformation(msg, m_id, Akonadi::MessageStatus::statusReplied()); | 119 | MessageComposer::Util::addLinkInformation(msg, m_id, Akonadi::MessageStatus::statusReplied()); | ||
98 | if (m_parentFolderId > 0) { | 120 | if (m_parentFolderId > 0) { | ||
99 | KMime::Headers::Generic *header = new KMime::Headers::Generic("X-KMail-Fcc"); | 121 | KMime::Headers::Generic *header = new KMime::Headers::Generic("X-KMail-Fcc"); | ||
100 | header->fromUnicodeString(QString::number(m_parentFolderId), "utf-8"); | 122 | header->fromUnicodeString(QString::number(m_parentFolderId), "utf-8"); | ||
▲ Show 20 Lines • Show All 61 Lines • ▼ Show 20 Line(s) | 183 | if (m_identityManager->thatIsMe(KMime::Types::Mailbox::listToUnicodeString(originalFromList)) | |||
162 | && !m_identityManager->thatIsMe(KMime::Types::Mailbox::listToUnicodeString(originalToList)) | 184 | && !m_identityManager->thatIsMe(KMime::Types::Mailbox::listToUnicodeString(originalToList)) | ||
163 | ) { | 185 | ) { | ||
164 | // Sender seems to be one of our own identities and recipient is not, | 186 | // Sender seems to be one of our own identities and recipient is not, | ||
165 | // so we assume that this is a reply to a "sent" mail where the user | 187 | // so we assume that this is a reply to a "sent" mail where the user | ||
166 | // wants to add additional information for the recipient. | 188 | // wants to add additional information for the recipient. | ||
167 | toList = originalToList; | 189 | toList = originalToList; | ||
168 | } else { | 190 | } else { | ||
169 | // "Normal" case: reply to sender. | 191 | // "Normal" case: reply to sender. | ||
170 | if (replyToList.isEmpty()) { | 192 | toList = authorMailboxes(m_origMsg, m_mailingListAddresses); | ||
171 | toList = originalFromList; | | |||
172 | } else { | | |||
173 | toList = replyToList; | | |||
174 | } | | |||
175 | } | 193 | } | ||
176 | 194 | | |||
177 | replyAll = false; | 195 | replyAll = false; | ||
178 | } | 196 | } | ||
179 | // strip all my addresses from the list of recipients | 197 | // strip all my addresses from the list of recipients | ||
180 | const KMime::Types::Mailbox::List recipients = toList; | 198 | const KMime::Types::Mailbox::List recipients = toList; | ||
181 | 199 | | |||
182 | toList = stripMyAddressesFromAddressList(recipients, m_identityManager); | 200 | toList = stripMyAddressesFromAddressList(recipients, m_identityManager); | ||
▲ Show 20 Lines • Show All 120 Lines • ▼ Show 20 Line(s) | 228 | { | |||
303 | 321 | | |||
304 | if (toList.isEmpty() && !recipients.isEmpty()) { | 322 | if (toList.isEmpty() && !recipients.isEmpty()) { | ||
305 | // reply to self without other recipients | 323 | // reply to self without other recipients | ||
306 | toList << recipients.at(0); | 324 | toList << recipients.at(0); | ||
307 | } | 325 | } | ||
308 | break; | 326 | break; | ||
309 | } | 327 | } | ||
310 | case MessageComposer::ReplyAuthor: | 328 | case MessageComposer::ReplyAuthor: | ||
311 | if (!replyToList.isEmpty()) { | 329 | toList = authorMailboxes(m_origMsg, m_mailingListAddresses); | ||
312 | KMime::Types::Mailbox::List recipients = replyToList; | | |||
313 | | ||||
314 | // strip the mailing list post address from the list of Reply-To | | |||
315 | // addresses since we want to reply in private | | |||
316 | for (const KMime::Types::Mailbox &mailbox : qAsConst(m_mailingListAddresses)) { | | |||
317 | foreach (const KMime::Types::Mailbox &recipient, recipients) { //Don't use for(...:...) | | |||
318 | if (mailbox == recipient) { | | |||
319 | recipients.removeAll(recipient); | | |||
320 | } | | |||
321 | } | | |||
322 | } | | |||
323 | | ||||
324 | if (!recipients.isEmpty()) { | | |||
325 | toList = recipients; | | |||
326 | } else { | | |||
327 | // there was only the mailing list post address in the Reply-To header, | | |||
328 | // so use the From address instead | | |||
329 | toList = m_origMsg->from()->mailboxes(); | | |||
330 | } | | |||
331 | } else if (!m_origMsg->from()->asUnicodeString().isEmpty()) { | | |||
332 | toList = m_origMsg->from()->mailboxes(); | | |||
333 | } | | |||
334 | | ||||
335 | replyAll = false; | 330 | replyAll = false; | ||
336 | break; | 331 | break; | ||
337 | case MessageComposer::ReplyNone: | 332 | case MessageComposer::ReplyNone: | ||
338 | // the addressees will be set by the caller | 333 | // the addressees will be set by the caller | ||
339 | break; | 334 | break; | ||
340 | default: | 335 | default: | ||
341 | Q_UNREACHABLE(); | 336 | Q_UNREACHABLE(); | ||
342 | } | 337 | } | ||
▲ Show 20 Lines • Show All 734 Lines • Show Last 20 Lines |