private void CacheModeratedRecipients() { if (this.moderatedRecipients != null) { throw new InvalidOperationException("Moderated recipients cached more than once"); } EmailRecipientCollection cc = this.initiationMessage.EmailMessage.Cc; List <string> list = new List <string>(cc.Count); foreach (EmailRecipient emailRecipient in cc) { string text = emailRecipient.DisplayName; if (string.IsNullOrEmpty(text)) { text = emailRecipient.SmtpAddress; if (string.IsNullOrEmpty(text)) { ModerationApprovalRequestWriter.diag.TraceDebug(0L, "skipping moderated recipient without address or display name"); continue; } } list.Add(text); } this.moderatedRecipients = list.AsReadOnly(); }
/// <summary> /// Gets a collection of email addresses from an email recipient collection from a config file /// </summary> /// <param name="recipients"> /// </param> /// <returns> /// </returns> public static MailAddressCollection GetMailAddressCollection(EmailRecipientCollection recipients) { if (recipients == null) { throw new ArgumentNullException("recipients"); } var result = new MailAddressCollection(); foreach (EmailRecipient item in recipients) { result.Add(item.Value); } return result; }
private static string FormatRecipients(EmailRecipientCollection recipientCollection) { if (recipientCollection.Count == 0) { return(string.Empty); } int num = 0; foreach (EmailRecipient emailRecipient in recipientCollection) { if (!string.IsNullOrEmpty(emailRecipient.DisplayName)) { num += emailRecipient.DisplayName.Length; } else if (!string.IsNullOrEmpty(emailRecipient.NativeAddress)) { num += emailRecipient.NativeAddress.Length; } } num += "; ".Length * recipientCollection.Count; StringBuilder stringBuilder = new StringBuilder(num); for (int i = 0; i < recipientCollection.Count; i++) { EmailRecipient emailRecipient2 = recipientCollection[i]; if (!string.IsNullOrEmpty(emailRecipient2.DisplayName)) { stringBuilder.Append(emailRecipient2.DisplayName); } else if (!string.IsNullOrEmpty(emailRecipient2.NativeAddress)) { stringBuilder.Append(emailRecipient2.NativeAddress); } else { ModerationApprovalRequestWriter.diag.TraceError <EmailRecipient>(0L, "Cannot get suitable value to write recipient address {0}.", emailRecipient2); } if (i < recipientCollection.Count - 1) { stringBuilder.Append("; "); } } return(stringBuilder.ToString()); }