forked from andyedinborough/aenetmail
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathHeaderObject.cs
55 lines (48 loc) · 1.67 KB
/
HeaderObject.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
using System;
namespace AE.Net.Mail {
public abstract class ObjectWHeaders {
public string RawHeaders { get; internal set; }
private HeaderCollection _Headers;
public HeaderCollection Headers {
get {
return _Headers ?? (_Headers = HeaderCollection.Parse(RawHeaders));
}
internal set {
_Headers = value;
}
}
public string ContentTransferEncoding {
get { return Headers["Content-Transfer-Encoding"].Value ?? string.Empty; }
internal set {
Headers.Set("Content-Transfer-Encoding", new HeaderValue(value));
}
}
public string ContentType {
get { return Headers["Content-Type"].Value ?? string.Empty; }
internal set {
Headers.Set("Content-Type", new HeaderValue(value));
}
}
public string Charset {
get {
return Headers["Content-Transfer-Encoding"]["charset"].NotEmpty(
Headers["Content-Type"]["charset"]
);
}
}
public string Body { get; set; }
internal void SetBody(string value) {
if (ContentTransferEncoding.Is("quoted-printable")) {
value = Utilities.DecodeQuotedPrintable(value, Utilities.ParseCharsetToEncoding(Charset));
} else if (ContentTransferEncoding.Is("base64")
//only decode the content if it is a text document
&& ContentType.StartsWith("text/", StringComparison.OrdinalIgnoreCase)
&& Utilities.IsValidBase64String(value)) {
value = System.Text.Encoding.UTF8.GetString(Convert.FromBase64String(value));
ContentTransferEncoding = string.Empty;
}
Body = value;
}
}
}