diff --git a/MimeKit/MailboxAddress.cs b/MimeKit/MailboxAddress.cs
index 12a70e454d..bf001adb14 100644
--- a/MimeKit/MailboxAddress.cs
+++ b/MimeKit/MailboxAddress.cs
@@ -238,6 +238,30 @@ public string Address {
}
}
+ ///
+ /// Get the local-part of the email address.
+ ///
+ ///
+ /// Gets the local-part of the email address, sometimes referred to as the "user" portion of an email address.
+ ///
+ public string LocalPart {
+ get {
+ return at != -1 ? address.Substring (0, at) : address;
+ }
+ }
+
+ ///
+ /// Get the domain of the email address.
+ ///
+ ///
+ /// Gets the domain of the email address.
+ ///
+ public string Domain {
+ get {
+ return at != -1 ? address.Substring (at + 1) : string.Empty;
+ }
+ }
+
///
/// Get whether or not the address is an international address.
///
diff --git a/UnitTests/MailboxAddressTests.cs b/UnitTests/MailboxAddressTests.cs
index a92ed9b78e..7e9f0b41b4 100644
--- a/UnitTests/MailboxAddressTests.cs
+++ b/UnitTests/MailboxAddressTests.cs
@@ -95,6 +95,20 @@ public void ArgumentExceptionTests ()
Assert.DoesNotThrow (() => new SecureMailboxAddress (Encoding.UTF8, "Routed Address", new[] { "route1", "route2", "route3" }, "user@domain.com", "ffff"));
}
+ [Test]
+ public void TestLocalPartAndDomain ()
+ {
+ var mailbox = new MailboxAddress ("User Name", "user@domain.com");
+
+ Assert.AreEqual ("user", mailbox.LocalPart, "LocalPart");
+ Assert.AreEqual ("domain.com", mailbox.Domain, "Domain");
+
+ mailbox = new MailboxAddress ("User Name", "user");
+
+ Assert.AreEqual ("user", mailbox.LocalPart, "Unix LocalPart");
+ Assert.AreEqual (string.Empty, mailbox.Domain, "Unix non-Domain");
+ }
+
[Test]
public void TestSetEmptyAddress ()
{