using System;
using System.Text;
namespace System.Net.Mail
{
/// Represents the address of an electronic mail sender or recipient.
// Token: 0x0200013E RID: 318
public class MailAddress
{
/// Initializes a new instance of the class using the specified address.
/// A that contains an e-mail address.
///
/// is null.
///
/// is ("").
///
/// is not in a recognized format.
// Token: 0x06000ACE RID: 2766 RVA: 0x00020550 File Offset: 0x0001E750
public MailAddress(string address)
: this(address, null)
{
}
/// Initializes a new instance of the class using the specified address and display name.
/// A that contains an e-mail address.
/// A that contains the display name associated with . This parameter can be null.
///
/// is null.
///
/// is ("").
///
/// is not in a recognized format.-or- contains non-ASCII characters.
// Token: 0x06000ACF RID: 2767 RVA: 0x0002055C File Offset: 0x0001E75C
public MailAddress(string address, string displayName)
: this(address, displayName, Encoding.Default)
{
}
/// Initializes a new instance of the class using the specified address, display name, and encoding.
/// A that contains an e-mail address.
/// A that contains the display name associated with .
/// The that defines the character set used for .
///
/// is null.-or- is null.
///
/// is ("").-or- is ("").
///
/// is not in a recognized format.-or- contains non-ASCII characters.
// Token: 0x06000AD0 RID: 2768 RVA: 0x0002056C File Offset: 0x0001E76C
public MailAddress(string address, string displayName, Encoding displayNameEncoding)
{
if (address == null)
{
throw new ArgumentNullException("address");
}
int num = address.IndexOf('"');
if (num == 0)
{
int num2 = address.IndexOf('"', num + 1);
if (num2 == -1)
{
throw MailAddress.CreateFormatException();
}
this.displayName = address.Substring(num + 1, num2 - 1).Trim();
address = address.Substring(num2 + 1);
}
int num3 = address.IndexOf('<');
if (num3 != -1)
{
if (num3 + 1 >= address.Length)
{
throw MailAddress.CreateFormatException();
}
int num4 = address.IndexOf('>', num3 + 1);
if (num4 == -1)
{
throw MailAddress.CreateFormatException();
}
if (this.displayName == null)
{
this.displayName = address.Substring(0, num3).Trim();
}
address = address.Substring(++num3, num4 - num3);
}
if (displayName != null)
{
this.displayName = displayName.Trim();
}
this.address = address.Trim();
}
/// Gets the e-mail address specified when this instance was created.
/// A that contains the e-mail address.
// Token: 0x170002B5 RID: 693
// (get) Token: 0x06000AD1 RID: 2769 RVA: 0x00020664 File Offset: 0x0001E864
public string Address
{
get
{
return this.address;
}
}
/// Gets the display name composed from the display name and address information specified when this instance was created.
/// A that contains the display name; otherwise, ("") if no display name information was specified when this instance was created.
// Token: 0x170002B6 RID: 694
// (get) Token: 0x06000AD2 RID: 2770 RVA: 0x0002066C File Offset: 0x0001E86C
public string DisplayName
{
get
{
if (this.displayName == null)
{
return string.Empty;
}
return this.displayName;
}
}
/// Gets the host portion of the address specified when this instance was created.
/// A that contains the name of the host computer that accepts e-mail for the property.
// Token: 0x170002B7 RID: 695
// (get) Token: 0x06000AD3 RID: 2771 RVA: 0x00020688 File Offset: 0x0001E888
public string Host
{
get
{
return this.Address.Substring(this.address.IndexOf("@") + 1);
}
}
/// Gets the user information from the address specified when this instance was created.
/// A that contains the user name portion of the .
// Token: 0x170002B8 RID: 696
// (get) Token: 0x06000AD4 RID: 2772 RVA: 0x000206A8 File Offset: 0x0001E8A8
public string User
{
get
{
return this.Address.Substring(0, this.address.IndexOf("@"));
}
}
/// Compares two mail addresses.
/// true if the two mail addresses are equal; otherwise, false.
/// A instance to compare to the current instance.
// Token: 0x06000AD5 RID: 2773 RVA: 0x000206C8 File Offset: 0x0001E8C8
public override bool Equals(object obj)
{
return this.Equals(obj as MailAddress);
}
// Token: 0x06000AD6 RID: 2774 RVA: 0x000206D8 File Offset: 0x0001E8D8
private bool Equals(MailAddress other)
{
return other != null && this.Address == other.Address;
}
/// Returns a hash value for a mail address.
/// An integer hash value.
// Token: 0x06000AD7 RID: 2775 RVA: 0x000206F4 File Offset: 0x0001E8F4
public override int GetHashCode()
{
return this.address.GetHashCode();
}
/// Returns a string representation of this instance.
/// A that contains the contents of this .
// Token: 0x06000AD8 RID: 2776 RVA: 0x00020704 File Offset: 0x0001E904
public override string ToString()
{
StringBuilder stringBuilder = new StringBuilder();
if (this.DisplayName != null && this.DisplayName.Length > 0)
{
stringBuilder.Append("\"");
stringBuilder.Append(this.DisplayName);
stringBuilder.Append("\"");
stringBuilder.Append(" ");
stringBuilder.Append("<");
stringBuilder.Append(this.Address);
stringBuilder.Append(">");
}
else
{
stringBuilder.Append(this.Address);
}
return stringBuilder.ToString();
}
// Token: 0x06000AD9 RID: 2777 RVA: 0x000207A4 File Offset: 0x0001E9A4
private static FormatException CreateFormatException()
{
return new FormatException("The specified string is not in the form required for an e-mail address.");
}
// Token: 0x04000B07 RID: 2823
private string address;
// Token: 0x04000B08 RID: 2824
private string displayName;
}
}