Changeset View
Changeset View
Standalone View
Standalone View
messagecomposer/src/helper/messagefactoryng.cpp
Show First 20 Lines • Show All 219 Lines • ▼ Show 20 Line(s) | 209 | { | |||
---|---|---|---|---|---|
220 | 220 | | |||
221 | // strip all my addresses from the list of recipients | 221 | // strip all my addresses from the list of recipients | ||
222 | const KMime::Types::Mailbox::List recipients = toList; | 222 | const KMime::Types::Mailbox::List recipients = toList; | ||
223 | 223 | | |||
224 | toList = stripMyAddressesFromAddressList(recipients, m_identityManager); | 224 | toList = stripMyAddressesFromAddressList(recipients, m_identityManager); | ||
225 | break; | 225 | break; | ||
226 | } | 226 | } | ||
227 | case MessageComposer::ReplyAll: | 227 | case MessageComposer::ReplyAll: | ||
228 | { | 228 | if (auto hdr = m_origMsg->headerByType("Mail-Followup-To")) { | ||
229 | KMime::Types::Mailbox::List recipients; | 229 | toList = KMime::Types::Mailbox::listFrom7BitString(hdr->as7BitString(false)); | ||
230 | KMime::Types::Mailbox::List ccRecipients; | 230 | } else { | ||
231 | 231 | auto ccList = stripMyAddressesFromAddressList(m_origMsg->cc(false)->mailboxes(), m_identityManager); | |||
232 | QString sender; | | |||
233 | if (auto hrd = m_origMsg->sender(false)) { | | |||
234 | sender = hrd->asUnicodeString(); | | |||
235 | } | | |||
236 | // add addresses from the Reply-To header to the list of recipients | | |||
237 | if (!replyToList.isEmpty()) { | | |||
238 | recipients = replyToList; | | |||
239 | 232 | | |||
240 | // strip all possible mailing list addresses from the list of Reply-To addresses | | |||
241 | for (const KMime::Types::Mailbox &mailbox : qAsConst(m_mailingListAddresses)) { | | |||
242 | foreach (const KMime::Types::Mailbox &recipient, recipients) { //Don't use for(...:...) | | |||
243 | if (mailbox == recipient) { | | |||
244 | recipients.removeAll(recipient); | | |||
245 | } | | |||
246 | } | | |||
247 | } | | |||
248 | } | | |||
249 | bool stripMyAddresses = true; | | |||
250 | if (!m_mailingListAddresses.isEmpty()) { | 233 | if (!m_mailingListAddresses.isEmpty()) { | ||
251 | // this is a mailing list message | 234 | toList = stripMyAddressesFromAddressList(m_origMsg->to()->mailboxes(), m_identityManager); | ||
252 | if (recipients.isEmpty() && !m_origMsg->from()->asUnicodeString().isEmpty()) { | 235 | bool addMailingList = true; | ||
253 | // The sender didn't set a Reply-to address, so we add the From | 236 | for (const KMime::Types::Mailbox &m : m_mailingListAddresses) { | ||
254 | // address to the list of CC recipients. | 237 | if (toList.contains(m)) { | ||
255 | ccRecipients += m_origMsg->from()->mailboxes(); | 238 | addMailingList = false; | ||
256 | qCDebug(MESSAGECOMPOSER_LOG) << "Added" << m_origMsg->from()->asUnicodeString() << "to the list of CC recipients"; | 239 | break; | ||
257 | } | | |||
258 | | ||||
259 | // if it is a mailing list, add the posting address | | |||
260 | recipients.prepend(m_mailingListAddresses[ 0 ]); | | |||
261 | } else { | | |||
262 | const QString fromAddress = m_origMsg->from()->asUnicodeString(); | | |||
263 | if (!fromAddress.isEmpty()) { | | |||
264 | if (!sender.isEmpty() && m_identityManager->thatIsMe(fromAddress)) { | | |||
265 | // strip all my addresses from the list of recipients | | |||
266 | toList = recipients; | | |||
267 | toList += m_origMsg->from()->mailboxes(); | | |||
268 | stripMyAddresses = false; | | |||
269 | } else { | | |||
270 | // this is a normal message | | |||
271 | if (recipients.isEmpty()) { | | |||
272 | // in case of replying to a normal message only then add the From | | |||
273 | // address to the list of recipients if there was no Reply-to address | | |||
274 | recipients += m_origMsg->from()->mailboxes(); | | |||
275 | qCDebug(MESSAGECOMPOSER_LOG) << "Added" << m_origMsg->from()->asUnicodeString() << "to the list of recipients"; | | |||
276 | } | | |||
277 | } | | |||
278 | } | | |||
279 | } | | |||
280 | if (stripMyAddresses) { | | |||
281 | // strip all my addresses from the list of recipients | | |||
282 | toList = stripMyAddressesFromAddressList(recipients, m_identityManager); | | |||
283 | } | 240 | } | ||
284 | | ||||
285 | // merge To header and CC header into a list of CC recipients | | |||
286 | if (!m_origMsg->cc()->asUnicodeString().isEmpty() || !m_origMsg->to()->asUnicodeString().isEmpty()) { | | |||
287 | KMime::Types::Mailbox::List list; | | |||
288 | if (!m_origMsg->to()->asUnicodeString().isEmpty()) { | | |||
289 | list += m_origMsg->to()->mailboxes(); | | |||
290 | } | 241 | } | ||
291 | if (!m_origMsg->cc()->asUnicodeString().isEmpty()) { | 242 | if (addMailingList) { | ||
292 | list += m_origMsg->cc()->mailboxes(); | 243 | toList += m_mailingListAddresses.front(); | ||
293 | } | 244 | } | ||
294 | 245 | | |||
295 | for (const KMime::Types::Mailbox &mailbox : qAsConst(list)) { | 246 | ccList += authorMailboxes(m_origMsg, m_mailingListAddresses); | ||
296 | if (!recipients.contains(mailbox) | 247 | } else { | ||
297 | && !ccRecipients.contains(mailbox)) { | 248 | // Doesn't seem to be a mailing list. | ||
298 | ccRecipients += mailbox; | 249 | auto originalFromList = m_origMsg->from()->mailboxes(); | ||
299 | qCDebug(MESSAGECOMPOSER_LOG) << "Added" << mailbox.prettyAddress() << "to the list of CC recipients"; | 250 | auto originalToList = m_origMsg->to()->mailboxes(); | ||
300 | } | | |||
301 | } | | |||
302 | } | | |||
303 | 251 | | |||
304 | if (!ccRecipients.isEmpty()) { | 252 | if (m_identityManager->thatIsMe(KMime::Types::Mailbox::listToUnicodeString(originalFromList)) | ||
305 | // strip all my addresses from the list of CC recipients | 253 | && !m_identityManager->thatIsMe(KMime::Types::Mailbox::listToUnicodeString(originalToList)) | ||
306 | if (stripMyAddresses) { | 254 | ) { | ||
307 | ccRecipients = stripMyAddressesFromAddressList(ccRecipients, m_identityManager); | 255 | // Sender seems to be one of our own identities and recipient is not, | ||
256 | // so we assume that this is a reply to a "sent" mail where the user | ||||
257 | // wants to add additional information for the recipient. | ||||
258 | toList = originalToList; | ||||
259 | } else { | ||||
260 | // "Normal" case: reply to sender. | ||||
261 | toList = stripMyAddressesFromAddressList(m_origMsg->to()->mailboxes(), m_identityManager); | ||||
262 | toList += authorMailboxes(m_origMsg, m_mailingListAddresses); | ||||
308 | } | 263 | } | ||
309 | | ||||
310 | // in case of a reply to self, toList might be empty. if that's the case | | |||
311 | // then propagate a cc recipient to To: (if there is any). | | |||
312 | if (toList.isEmpty() && !ccRecipients.isEmpty()) { | | |||
313 | toList << ccRecipients.at(0); | | |||
314 | ccRecipients.pop_front(); | | |||
315 | } | 264 | } | ||
316 | 265 | | |||
317 | for (const KMime::Types::Mailbox &mailbox : qAsConst(ccRecipients)) { | 266 | for (const KMime::Types::Mailbox &mailbox : ccList) { | ||
318 | msg->cc()->addAddress(mailbox); | 267 | msg->cc()->addAddress(mailbox); | ||
319 | } | 268 | } | ||
320 | } | 269 | } | ||
321 | | ||||
322 | if (toList.isEmpty() && !recipients.isEmpty()) { | | |||
323 | // reply to self without other recipients | | |||
324 | toList << recipients.at(0); | | |||
325 | } | | |||
326 | break; | 270 | break; | ||
327 | } | | |||
328 | case MessageComposer::ReplyAuthor: | 271 | case MessageComposer::ReplyAuthor: | ||
329 | toList = authorMailboxes(m_origMsg, m_mailingListAddresses); | 272 | toList = authorMailboxes(m_origMsg, m_mailingListAddresses); | ||
330 | replyAll = false; | 273 | replyAll = false; | ||
331 | break; | 274 | break; | ||
332 | case MessageComposer::ReplyNone: | 275 | case MessageComposer::ReplyNone: | ||
333 | // the addressees will be set by the caller | 276 | // the addressees will be set by the caller | ||
334 | break; | 277 | break; | ||
335 | default: | 278 | default: | ||
▲ Show 20 Lines • Show All 736 Lines • Show Last 20 Lines |