PeterO.Mail.NamedAddress
## PeterO.Mail.NamedAddress
public class NamedAddress
Represents an email address and a name for that address. Can represent a group of email addresses instead.
Member Summary
[Address](#Address)
- Gets the email address associated with this object.[AddressesEqual(PeterO.Mail.NamedAddress)](#AddressesEqual_PeterO_Mail_NamedAddress)
- Determines whether the email addresses stored this object are the same between this object and the given object, regardless of the display names they store.[DisplayName](#DisplayName)
- Gets the display name for this email address.[Equals(object)](#Equals_object)
- Determines whether this object and another object are equal.[GetHashCode()](#GetHashCode)
- Calculates the hash code of this object.[GroupAddresses](#GroupAddresses)
- Gets a read-only list of addresses that make up the group, if this object represents a group, or an empty list otherwise.[IsGroup](#IsGroup)
- Gets a value indicating whether this represents a group of addresses rather than a single address.[Name](#Name)
- Gets the display name for this email address, or the email address’s value if the display name is null.[ParseAddresses(string)](#ParseAddresses_string)
- Generates a list of NamedAddress objects from a comma-separated list of addresses.[ToDisplayString()](#ToDisplayString)
- Converts this named-address object to a text string intended for display to end users.[ToDisplayString(System.Collections.Generic.IList)](#ToDisplayString_System_Collections_Generic_IList)
- Generates a string containing the display names and email addresses of the given named-address objects, separated by commas.[ToDisplayStringShort(System.Collections.Generic.IList)](#ToDisplayStringShort_System_Collections_Generic_IList)
- Generates a string containing the display names of the given named-address objects, separated by commas.[ToString()](#ToString)
- Converts this object to a text string.
public NamedAddress( string address);
Initializes a new instance of the PeterO.Mail.NamedAddress class. Examples:
-
john@example.com
-
"John Doe" <john@example.com>
-
=?utf-8?q?John
=
27s_Office?=<john@example.com>
-
John <john@example.com>
-
"Group" : Tom <tom@example.com>, Jane <jane@example.com>;
Parameters:
- address: A text string identifying a single email address or a group of email addresses. Comments, or text within parentheses, can appear. Multiple email addresses are not allowed unless they appear in the group syntax given earlier. Encoded words under RFC 2047 that appear within comments or display names will be decoded. An RFC 2047 encoded word consists of “=?”, a character encoding name, such as
utf-8
, either “?B?” or “?Q?” (in upper or lower case), a series of bytes in the character encoding, further encoded using B or Q encoding, and finally “?=”. B encoding uses Base64, while in Q encoding, spaces are changed to “_”, equals are changed to “=3D”, and most bytes other than the basic digits 0 to 9 (0x30 to 0x39) and the basic letters A/a to Z/z (0x41 to 0x5a, 0x61 to 0x7a) are changed to “=” followed by their 2-digit hexadecimal form. An encoded word’s maximum length is 75 characters. See the third example.
.
Exceptions:
-
System.ArgumentNullException: The parameter address is null.
-
System.ArgumentException: Address has an invalid syntax.; Address has an invalid syntax.
public NamedAddress( string displayName, PeterO.Mail.Address address);
Initializes a new instance of the PeterO.Mail.NamedAddress class using the given display name and email address.
Parameters:
-
displayName: The display name of the email address. Can be null or empty. Encoded words under RFC 2047 will not be decoded.
-
address: An email address.
Exceptions:
- System.ArgumentNullException: The parameter address is null.
public NamedAddress( string displayName, string address);
Initializes a new instance of the PeterO.Mail.NamedAddress class using the given display name and email address.
Parameters:
-
displayName: The display name of the email address. Can be null or empty. Encoded words under RFC 2047 will not be decoded.
-
address: An email address.
Exceptions:
- System.ArgumentNullException: The parameter address is null.
public NamedAddress( string displayName, string localPart, string domain);
Initializes a new instance of the PeterO.Mail.NamedAddress class using the given name and an email address made up of its local part and domain.
Parameters:
-
displayName: The display name of the email address. Can be null or empty.
-
localPart: The local part of the email address (before the “@”).
-
domain: The domain of the email address (before the “@”).
Exceptions:
- System.ArgumentNullException: The parameter localPart or domain is null.
public NamedAddress( string groupName, System.Collections.Generic.IList mailboxes);
Initializes a new instance of the PeterO.Mail.NamedAddress class. Takes a group name and several named email addresses as parameters, and forms a group with them.
Parameters:
-
groupName: The group’s name.
-
mailboxes: A list of named addresses that make up the group.
Exceptions:
-
System.ArgumentNullException: The parameter groupName or mailboxes is null.
-
System.ArgumentException: GroupName is empty.; A mailbox in the list is a group.
public PeterO.Mail.Address Address { get; }
Gets the email address associated with this object.
Returns:
The email address associated with this object. This value is null if this object represents a group of addresses instead.
public string DisplayName { get; }
Gets the display name for this email address.
Returns:
The display name for this email address. Returns null if the display name is absent.
public System.Collections.Generic.IList GroupAddresses { get; }
Gets a read-only list of addresses that make up the group, if this object represents a group, or an empty list otherwise.
Returns:
A list of addresses that make up the group, if this object represents a group, or an empty list otherwise.
public bool IsGroup { get; }
Gets a value indicating whether this represents a group of addresses rather than a single address.
Returns:
true
If this represents a group of addresses; otherwise, false
.
public string Name { get; }
Gets the display name for this email address, or the email address’s value if the display name is null. Returns an empty string if the address and display name are null.
Returns:
The name for this email address.
public bool AddressesEqual( PeterO.Mail.NamedAddress na);
Determines whether the email addresses stored this object are the same between this object and the given object, regardless of the display names they store. For groups, the email addresses must be equal and in the same order in both objects.
Parameters:
- na: A named address object to compare with this one. Can be null.
Return Value:
Either true
or false
.
public override bool Equals( object obj);
Determines whether this object and another object are equal. For groups, the named addresses (display name/email address pairs) must be equal and in the same order in both objects.
Parameters:
- obj: An arbitrary object to compare with this one.
Return Value:
true
if this object and another object are equal and have the same type; otherwise, false
.
public override int GetHashCode();
Calculates the hash code of this object. The exact algorithm used by this method is not guaranteed to be the same between versions of this library, and no application or process IDs are used in the hash code calculation.
Return Value:
A 32-bit hash code.
public static System.Collections.Generic.IList ParseAddresses( string addressValue);
Generates a list of NamedAddress objects from a comma-separated list of addresses. Each address must follow the syntax accepted by the one-argument constructor of NamedAddress.
Parameters:
- addressValue: A comma-separated list of addresses in the form of a text string.
Return Value:
A list of addresses generated from the addressValue parameter.
Exceptions:
- System.ArgumentNullException: The parameter addressValue is null.
public static string ToDisplayString( System.Collections.Generic.IList addresses);
Generates a string containing the display names and email addresses of the given named-address objects, separated by commas. The generated string is intended to be displayed to end users, and is not intended to be parsed by computer programs.
Parameters:
- addresses: A list of named address objects.
Return Value:
A string containing the display names and email addresses of the given named-address objects, separated by commas.
Exceptions:
- System.ArgumentNullException: The parameter addresses is null.
public string ToDisplayString();
Converts this named-address object to a text string intended for display to end users. The returned string is not intended to be parsed by computer programs.
Return Value:
A text string of this named-address object, intended for display to end-users.
public static string ToDisplayStringShort( System.Collections.Generic.IList addresses);
Generates a string containing the display names of the given named-address objects, separated by commas. The generated string is intended to be displayed to end users, and is not intended to be parsed by computer programs. If a named address has no display name, its email address is used as the display name.
Parameters:
- addresses: A list of named address objects.
Return Value:
A string containing the display names of the given named-address objects, separated by commas.
Exceptions:
- System.ArgumentNullException: The parameter addresses is null.
public override string ToString();
Converts this object to a text string. This will generally be the form of this NamedAddress object as it could appear in a “To” header field.
Return Value:
A string representation of this object.