internal string ToEncodedString() { if (this.fullAddress == null) { if ((this.encodedDisplayName != null) && (this.encodedDisplayName != string.Empty)) { StringBuilder builder = new StringBuilder(); MailBnfHelper.GetDotAtomOrQuotedString(this.encodedDisplayName, builder); builder.Append(" <"); builder.Append(this.Address); builder.Append('>'); this.fullAddress = builder.ToString(); } else { this.fullAddress = this.Address; } } return(this.fullAddress); }
public MailAddress(string address, string displayName, Encoding displayNameEncoding) { if (address == null) { throw new ArgumentNullException("address"); } if (address == string.Empty) { throw new ArgumentException(SR.GetString("net_emptystringcall", new object[] { "address" }), "address"); } this.displayNameEncoding = displayNameEncoding; this.displayName = displayName; this.ParseValue(address); if ((this.displayName != null) && (this.displayName != string.Empty)) { if ((this.displayName[0] == '"') && (this.displayName[this.displayName.Length - 1] == '"')) { this.displayName = this.displayName.Substring(1, this.displayName.Length - 2); } this.displayName = this.displayName.Trim(); } if ((this.displayName != null) && (this.displayName.Length > 0)) { if (!MimeBasePart.IsAscii(this.displayName, false) || (this.displayNameEncoding != null)) { if (this.displayNameEncoding == null) { this.displayNameEncoding = Encoding.GetEncoding("utf-8"); } this.encodedDisplayName = MimeBasePart.EncodeHeaderValue(this.displayName, this.displayNameEncoding, MimeBasePart.ShouldUseBase64Encoding(displayNameEncoding)); StringBuilder builder = new StringBuilder(); int offset = 0; MailBnfHelper.ReadQuotedString(this.encodedDisplayName, ref offset, builder, true); this.encodedDisplayName = builder.ToString(); } else { this.encodedDisplayName = this.displayName; } } }
private void ParseValue(string address) { string str = null; int index = address.IndexOf('"'); if (index > 0) { throw new FormatException(SR.GetString("MailAddressInvalidFormat")); } if (index == 0) { index = address.IndexOf('"', 1); if (index < 0) { throw new FormatException(SR.GetString("MailAddressInvalidFormat")); } str = address.Substring(1, index - 1); if (address.Length == (index + 1)) { throw new FormatException(SR.GetString("MailAddressInvalidFormat")); } address = address.Substring(index + 1); } if (str == null) { index = address.IndexOf('<'); if (index > 0) { str = address.Substring(0, index); address = address.Substring(index); } } if (this.displayName == null) { this.displayName = str; } index = 0; address = MailBnfHelper.ReadMailAddress(address, ref index, out this.encodedDisplayName); this.GetParts(address); }
internal void PrepareHeaders(bool sendEnvelope) { this.Headers[MailHeaderInfo.GetString(MailHeaderID.MimeVersion)] = "1.0"; this.Headers[MailHeaderInfo.GetString(MailHeaderID.From)] = this.From.ToEncodedString(); if (this.Sender != null) { this.Headers[MailHeaderInfo.GetString(MailHeaderID.Sender)] = this.Sender.ToEncodedString(); } else { this.Headers.Remove(MailHeaderInfo.GetString(MailHeaderID.Sender)); } if (this.To.Count > 0) { this.Headers[MailHeaderInfo.GetString(MailHeaderID.To)] = this.To.ToEncodedString(); } else { this.Headers.Remove(MailHeaderInfo.GetString(MailHeaderID.To)); } if (this.CC.Count > 0) { this.Headers[MailHeaderInfo.GetString(MailHeaderID.Cc)] = this.CC.ToEncodedString(); } else { this.Headers.Remove(MailHeaderInfo.GetString(MailHeaderID.Cc)); } if (this.replyTo != null) { this.Headers[MailHeaderInfo.GetString(MailHeaderID.ReplyTo)] = this.ReplyTo.ToEncodedString(); } else { this.Headers.Remove(MailHeaderInfo.GetString(MailHeaderID.ReplyTo)); } if (this.priority == MailPriority.High) { this.Headers[MailHeaderInfo.GetString(MailHeaderID.XPriority)] = "1"; this.Headers[MailHeaderInfo.GetString(MailHeaderID.Priority)] = "urgent"; this.Headers[MailHeaderInfo.GetString(MailHeaderID.Importance)] = "high"; } else if (this.priority == MailPriority.Low) { this.Headers[MailHeaderInfo.GetString(MailHeaderID.XPriority)] = "5"; this.Headers[MailHeaderInfo.GetString(MailHeaderID.Priority)] = "non-urgent"; this.Headers[MailHeaderInfo.GetString(MailHeaderID.Importance)] = "low"; } else if (this.priority != ~MailPriority.Normal) { this.Headers.Remove(MailHeaderInfo.GetString(MailHeaderID.XPriority)); this.Headers.Remove(MailHeaderInfo.GetString(MailHeaderID.Priority)); this.Headers.Remove(MailHeaderInfo.GetString(MailHeaderID.Importance)); } this.Headers[MailHeaderInfo.GetString(MailHeaderID.Date)] = MailBnfHelper.GetDateTimeString(DateTime.Now, null); if ((this.subject != null) && (this.subject != string.Empty)) { this.Headers[MailHeaderInfo.GetString(MailHeaderID.Subject)] = MimeBasePart.EncodeHeaderValue(this.subject, this.subjectEncoding, MimeBasePart.ShouldUseBase64Encoding(this.subjectEncoding)); } else { this.Headers.Remove(MailHeaderInfo.GetString(MailHeaderID.Subject)); } }