-
Notifications
You must be signed in to change notification settings - Fork 1
/
maskEmail.cs
105 lines (89 loc) · 2.64 KB
/
maskEmail.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
using System;
using System.Text;
using System.Web;
public partial class lab_maskemail_EmailMask : System.Web.UI.UserControl
{
private string emailAddress;
public string EmailAddress
{
get { return emailAddress; }
set { emailAddress = value; }
}
private string visibleAddress;
public string VisibleAddress
{
get
{
// if unassigned return emailAddress
if (visibleAddress==null || visibleAddress.Length == 0)
{
return emailAddress;
}
else
{
return visibleAddress;
}
}
set { visibleAddress = value; }
}
private string mouseoverTag;
public string MouseoverTag
{
get { return mouseoverTag; }
set { mouseoverTag = value; }
}
private string subject;
public string Subject
{
get { return subject; }
set { subject = value; }
}
private string cssClass;
public string CssClass
{
get { return cssClass;}
set { cssClass = value; }
}
protected void Page_Load(object sender, EventArgs e)
{
// The MIN required for control is an email address, confirm it exists
if (emailAddress == null || emailAddress.Length == 0)
{
ltEmail.Text = "Assign EmailAddress to Control";
return;
}
// Build ASCII encoded Link
StringBuilder asciiLink = new StringBuilder();
asciiLink.Append("<a href=\"mailto:");
asciiLink.Append(ASCIIEncode(EmailAddress));
if(subject != null && subject.Length > 0 )
{
asciiLink.Append("?subject=" + subject);
}
asciiLink.Append("\"");
if (mouseoverTag != null && mouseoverTag.Length > 0)
{
asciiLink.Append(" title=\"" + mouseoverTag + "\"");
}
if (cssClass !=null && cssClass.Length > 0)
{
asciiLink.Append(" class=\"" + cssClass + "\"");
}
asciiLink.Append(">");
asciiLink.Append(ASCIIEncode(VisibleAddress));
asciiLink.Append("</a>");
ltEmail.Text = asciiLink.ToString();
}
protected string ASCIIEncode(string regularText)
{
regularText = regularText.Trim();
StringBuilder encodeSB = new StringBuilder();
char regularLetter;
for (int j = 0; j < regularText.Length; j++)
{
// peel off 1 character at a time
regularLetter = regularText[j];
encodeSB.Append("&#" + Convert.ToInt32(regularLetter).ToString() + ";");
}
return encodeSB.ToString();
}