Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
Attachment.cs
Go to the documentation of this file.
1using System.IO;
3using System.Text;
4
5namespace System.Net.Mail;
6
8{
9 private string _name;
10
12
13 public string? Name
14 {
15 get
16 {
17 return _name;
18 }
19 set
20 {
22 if (encoding != null)
23 {
24 _nameEncoding = encoding;
26 base.MimePart.ContentType.Name = value;
27 }
28 else
29 {
30 _name = value;
31 SetContentTypeName(allowUnicode: true);
32 }
33 }
34 }
35
37 {
38 get
39 {
40 return _nameEncoding;
41 }
42 set
43 {
45 if (_name != null && _name != string.Empty)
46 {
47 SetContentTypeName(allowUnicode: true);
48 }
49 }
50 }
51
53
54 internal Attachment()
55 {
56 base.MimePart.ContentDisposition = new ContentDisposition();
57 }
58
59 public Attachment(string fileName)
60 : base(fileName)
61 {
62 Name = Path.GetFileName(fileName);
63 base.MimePart.ContentDisposition = new ContentDisposition();
64 }
65
66 public Attachment(string fileName, string? mediaType)
67 : base(fileName, mediaType)
68 {
69 Name = Path.GetFileName(fileName);
70 base.MimePart.ContentDisposition = new ContentDisposition();
71 }
72
73 public Attachment(string fileName, ContentType contentType)
74 : base(fileName, contentType)
75 {
76 if (string.IsNullOrEmpty(contentType.Name))
77 {
78 Name = Path.GetFileName(fileName);
79 }
80 else
81 {
82 Name = contentType.Name;
83 }
84 base.MimePart.ContentDisposition = new ContentDisposition();
85 }
86
87 public Attachment(Stream contentStream, string? name)
88 : base(contentStream, null, null)
89 {
90 Name = name;
91 base.MimePart.ContentDisposition = new ContentDisposition();
92 }
93
94 public Attachment(Stream contentStream, string? name, string? mediaType)
95 : base(contentStream, null, mediaType)
96 {
97 Name = name;
98 base.MimePart.ContentDisposition = new ContentDisposition();
99 }
100
101 public Attachment(Stream contentStream, ContentType contentType)
102 : base(contentStream, contentType)
103 {
104 Name = contentType.Name;
105 base.MimePart.ContentDisposition = new ContentDisposition();
106 }
107
108 internal void SetContentTypeName(bool allowUnicode)
109 {
110 if (!allowUnicode && _name != null && _name.Length != 0 && !MimeBasePart.IsAscii(_name, permitCROrLF: false))
111 {
112 Encoding encoding = NameEncoding ?? Encoding.GetEncoding("utf-8");
113 base.MimePart.ContentType.Name = MimeBasePart.EncodeHeaderValue(_name, encoding, MimeBasePart.ShouldUseBase64Encoding(encoding));
114 }
115 else
116 {
117 base.MimePart.ContentType.Name = _name;
118 }
119 }
120
121 internal override void PrepareForSending(bool allowUnicode)
122 {
123 if (_name != null && _name != string.Empty)
124 {
125 SetContentTypeName(allowUnicode);
126 }
127 base.PrepareForSending(allowUnicode);
128 }
129
130 public static Attachment CreateAttachmentFromString(string content, string? name)
131 {
132 Attachment attachment = new Attachment();
133 attachment.SetContentFromString(content, null, string.Empty);
134 attachment.Name = name;
135 return attachment;
136 }
137
138 public static Attachment CreateAttachmentFromString(string content, string? name, Encoding? contentEncoding, string? mediaType)
139 {
140 Attachment attachment = new Attachment();
141 attachment.SetContentFromString(content, contentEncoding, mediaType);
142 attachment.Name = name;
143 return attachment;
144 }
145
146 public static Attachment CreateAttachmentFromString(string content, ContentType contentType)
147 {
148 Attachment attachment = new Attachment();
149 attachment.SetContentFromString(content, contentType);
150 attachment.Name = contentType.Name;
151 return attachment;
152 }
153}
static ? string GetFileName(string? path)
Definition Path.cs:200
void SetContentFromString(string content, ContentType contentType)
static Attachment CreateAttachmentFromString(string content, string? name, Encoding? contentEncoding, string? mediaType)
void SetContentTypeName(bool allowUnicode)
Attachment(Stream contentStream, string? name, string? mediaType)
Definition Attachment.cs:94
Attachment(string fileName, ContentType contentType)
Definition Attachment.cs:73
Attachment(string fileName, string? mediaType)
Definition Attachment.cs:66
static Attachment CreateAttachmentFromString(string content, string? name)
override void PrepareForSending(bool allowUnicode)
Attachment(string fileName)
Definition Attachment.cs:59
Attachment(Stream contentStream, ContentType contentType)
ContentDisposition? ContentDisposition
Definition Attachment.cs:52
static Attachment CreateAttachmentFromString(string content, ContentType contentType)
Attachment(Stream contentStream, string? name)
Definition Attachment.cs:87
static bool IsAscii(string value, bool permitCROrLF)
static string EncodeHeaderValue(string value, Encoding encoding, bool base64Encoding)
static bool ShouldUseBase64Encoding(Encoding encoding)
static Encoding DecodeEncoding(string value)
static string DecodeHeaderValue(string value)
static Encoding GetEncoding(int codepage)
Definition Encoding.cs:593