-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSharpMimeAddress.cs
78 lines (72 loc) · 2.53 KB
/
SharpMimeAddress.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// -----------------------------------------------------------------------
//
// Copyright (C) 2003-2006 Angel Marin
//
// This file is part of SharpMimeTools
//
// SharpMimeTools is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// SharpMimeTools is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with SharpMimeTools; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
// -----------------------------------------------------------------------
using System;
namespace anmar.SharpMimeTools
{
/// <summary>
/// rfc 2822 email address
/// </summary>
public class SharpMimeAddress
{
/// <summary>
/// Initializes a new address from a RFC 2822 name-addr specification string
/// </summary>
/// <param name="dir">RFC 2822 name-addr address</param>
///
public SharpMimeAddress(String dir)
{
Name = SharpMimeTools.parseFrom(dir, 1);
Address = SharpMimeTools.parseFrom(dir, 2);
}
/// <summary>
/// Get the address name.
/// </summary>
public string Name { get; private set; }
/// <summary>
/// Get the email address.
/// </summary>
public string Address { get; private set; }
/// <summary>
/// Gets the length of the decoded address
/// </summary>
public int Length
{
get
{
return Name.Length + Address.Length;
}
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public override String ToString()
{
if (Name.Equals(String.Empty) && Address.Equals(String.Empty))
return "";
if (Name.Equals(String.Empty))
return String.Format("<{0}>", Address);
else
return String.Format("\"{0}\" <{1}>", Name, Address);
}
}
}