private static bool ShouldGenerateAllRecipients(IReadOnlyMailRecipientCollection recipients) { foreach (MailRecipient mailRecipient in recipients) { if (mailRecipient.AckStatus != AckStatus.Success || mailRecipient.ExtendedProperties.GetValue <bool>("Microsoft.Exchange.Transport.MailboxTransport.RetryOnDuplicateDelivery ", false)) { return(true); } } return(false); }
public static SmtpResponse GenerateResponse(MessageAction messageLevelAction, IReadOnlyMailRecipientCollection recipients, SmtpResponse smtpResponse, TimeSpan?retryInterval) { if (recipients == null) { throw new ArgumentNullException("recipients", "Required argument is not provided"); } bool flag = SmtpResponseGenerator.ShouldGenerateAllRecipients(recipients); if (!flag && retryInterval == null && messageLevelAction != MessageAction.RetryQueue) { return(smtpResponse); } StringBuilder stringBuilder = new StringBuilder(); SmtpResponseGenerator.GenerateBanner(stringBuilder, smtpResponse.StatusCode, smtpResponse.EnhancedStatusCode); stringBuilder.AppendFormat(CultureInfo.InvariantCulture, "{0}{1}{2} {3} {4}{5}{6}", new object[] { smtpResponse.StatusCode, flag ? "-" : " ", flag ? smtpResponse.StatusCode : string.Empty, smtpResponse.EnhancedStatusCode, SmtpResponseGenerator.FlattenStatusText(smtpResponse), SmtpResponseGenerator.GenerateAdditionalContextForMessage(messageLevelAction, retryInterval), "\r\n" }); if (flag) { IEnumerator <MailRecipient> enumerator = recipients.GetEnumerator(); bool flag2 = enumerator.MoveNext(); while (flag2) { MailRecipient mailRecipient = enumerator.Current; flag2 = enumerator.MoveNext(); bool value = mailRecipient.ExtendedProperties.GetValue <bool>("Microsoft.Exchange.Transport.MailboxTransport.RetryOnDuplicateDelivery ", false); mailRecipient.ExtendedProperties.Remove("Microsoft.Exchange.Transport.MailboxTransport.RetryOnDuplicateDelivery "); SmtpResponse responseForRecipient = SmtpResponseGenerator.GetResponseForRecipient(mailRecipient, value); stringBuilder.AppendFormat(CultureInfo.InvariantCulture, "{0}{1}{2} {3} {4}{5}{6}", new object[] { smtpResponse.StatusCode, flag2 ? "-" : " ", responseForRecipient.StatusCode, responseForRecipient.EnhancedStatusCode, SmtpResponseGenerator.FlattenStatusText(responseForRecipient), SmtpResponseGenerator.GenerateAdditionalContextForRecipient(mailRecipient, value), "\r\n" }); } } return(SmtpResponse.Parse(stringBuilder.ToString())); }