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