forked from andyedinborough/aenetmail
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Attachment.cs
47 lines (39 loc) · 1.34 KB
/
Attachment.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
using System;
namespace AE.Net.Mail {
public class Attachment : ObjectWHeaders {
public virtual string Filename {
get { return Headers["Content-Disposition"]["filename"].NotEmpty(Headers["Content-Disposition"]["name"]); }
}
private string _ContentDisposition;
private string ContentDisposition {
get { return _ContentDisposition ?? (_ContentDisposition = Headers["Content-Disposition"].Value.ToLower()); }
}
public virtual bool OnServer { get; internal set; }
internal bool IsAttachment {
get {
return ContentDisposition == "attachment" || ContentDisposition == "inline";
}
}
public virtual void Save(string filename) {
using (var file = new System.IO.FileStream(filename, System.IO.FileMode.Create))
Save(file);
}
public virtual void Save(System.IO.Stream stream) {
var data = GetData();
stream.Write(data, 0, data.Length);
}
public virtual byte[] GetData() {
byte[] data;
if (ContentTransferEncoding.Is("base64") && Utilities.IsValidBase64String(Body)) {
try {
data = Convert.FromBase64String(Body);
} catch (Exception) {
data = Encoding.GetBytes(Body);
}
} else {
data = Encoding.GetBytes(Body);
}
return data;
}
}
}