Skip to content

Commit

Permalink
Allow string.Empty as a valid addrspec for MailboxAddress
Browse files Browse the repository at this point in the history
SMTP allows empty return-path addr-specs in MAIL FROM.

Fixes issue #302
  • Loading branch information
jstedfast committed Apr 24, 2017
1 parent 8d2771f commit 54369a4
Showing 1 changed file with 14 additions and 31 deletions.
45 changes: 14 additions & 31 deletions MimeKit/MailboxAddress.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,6 @@ internal MailboxAddress (Encoding encoding, string name, string address, int at)
/// <para>-or-</para>
/// <para><paramref name="address"/> is <c>null</c>.</para>
/// </exception>
/// <exception cref="System.ArgumentException">
/// <paramref name="address"/> is an empty string.
/// </exception>
/// <exception cref="ParseException">
/// <paramref name="address"/> is malformed.
/// </exception>
Expand Down Expand Up @@ -117,9 +114,6 @@ public MailboxAddress (Encoding encoding, string name, IEnumerable<string> route
/// <para>-or-</para>
/// <para><paramref name="address"/> is <c>null</c>.</para>
/// </exception>
/// <exception cref="System.ArgumentException">
/// <paramref name="address"/> is an empty string.
/// </exception>
/// <exception cref="ParseException">
/// <paramref name="address"/> is malformed.
/// </exception>
Expand All @@ -140,9 +134,6 @@ public MailboxAddress (string name, IEnumerable<string> route, string address) :
/// <para>-or-</para>
/// <para><paramref name="address"/> is <c>null</c>.</para>
/// </exception>
/// <exception cref="System.ArgumentException">
/// <paramref name="address"/> is an empty string.
/// </exception>
/// <exception cref="ParseException">
/// <paramref name="address"/> is malformed.
/// </exception>
Expand All @@ -165,9 +156,6 @@ public MailboxAddress (IEnumerable<string> route, string address) : this (Encodi
/// <para>-or-</para>
/// <para><paramref name="address"/> is <c>null</c>.</para>
/// </exception>
/// <exception cref="System.ArgumentException">
/// <paramref name="address"/> is an empty string.
/// </exception>
/// <exception cref="ParseException">
/// <paramref name="address"/> is malformed.
/// </exception>
Expand All @@ -192,9 +180,6 @@ public MailboxAddress (Encoding encoding, string name, string address) : base (e
/// <exception cref="System.ArgumentNullException">
/// <paramref name="address"/> is <c>null</c>.
/// </exception>
/// <exception cref="System.ArgumentException">
/// <paramref name="address"/> is an empty string.
/// </exception>
/// <exception cref="ParseException">
/// <paramref name="address"/> is malformed.
/// </exception>
Expand All @@ -218,9 +203,6 @@ public MailboxAddress (string name, string address) : this (Encoding.UTF8, name,
/// <exception cref="System.ArgumentNullException">
/// <paramref name="address"/> is <c>null</c>.
/// </exception>
/// <exception cref="System.ArgumentException">
/// <paramref name="address"/> is an empty string.
/// </exception>
/// <exception cref="ParseException">
/// <paramref name="address"/> is malformed.
/// </exception>
Expand Down Expand Up @@ -262,9 +244,6 @@ public DomainList Route {
/// <exception cref="System.ArgumentNullException">
/// <paramref name="value"/> is <c>null</c>.
/// </exception>
/// <exception cref="System.ArgumentException">
/// <paramref name="value"/> is an empty string.
/// </exception>
/// <exception cref="ParseException">
/// <paramref name="value"/> is malformed.
/// </exception>
Expand All @@ -274,22 +253,26 @@ public string Address {
if (value == null)
throw new ArgumentNullException (nameof (value));

if (value.Length == 0)
throw new ArgumentException ("The address cannot be empty.", nameof (value));

if (value == address)
return;

var buffer = CharsetUtils.UTF8.GetBytes (value);
string addrspec;
int index = 0;
if (value.Length > 0) {
var buffer = CharsetUtils.UTF8.GetBytes (value);
string addrspec;
int index = 0;
int atIndex;

TryParseAddrspec (buffer, ref index, buffer.Length, new byte[0], true, out addrspec, out at);
TryParseAddrspec (buffer, ref index, buffer.Length, new byte[0], true, out addrspec, out atIndex);

if (index != buffer.Length)
throw new ParseException (string.Format ("Unexpected token at offset {0}", index), index, index);
if (index != buffer.Length)
throw new ParseException (string.Format ("Unexpected token at offset {0}", index), index, index);

address = addrspec;
address = addrspec;
at = atIndex;
} else {
address = string.Empty;
at = -1;
}

OnChanged ();
}
Expand Down

0 comments on commit 54369a4

Please sign in to comment.