Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
MimeBasePart.cs
Go to the documentation of this file.
3using System.Text;
4
5namespace System.Net.Mime;
6
7internal class MimeBasePart
8{
9 internal sealed class MimePartAsyncResult : System.Net.LazyAsyncResult
10 {
11 internal MimePartAsyncResult(MimeBasePart part, object state, AsyncCallback callback)
12 : base(part, state, callback)
13 {
14 }
15 }
16
17 private static readonly char[] s_decodeEncodingSplitChars = new char[3] { '?', '\r', '\n' };
18
20
22
24
25 private static readonly char[] s_headerValueSplitChars = new char[3] { '\r', '\n', ' ' };
26
27 private static readonly char[] s_questionMarkSplitChars = new char[1] { '?' };
28
29 internal string ContentID
30 {
31 get
32 {
33 return Headers[MailHeaderInfo.GetString(MailHeaderID.ContentID)];
34 }
35 set
36 {
37 if (string.IsNullOrEmpty(value))
38 {
39 Headers.Remove(MailHeaderInfo.GetString(MailHeaderID.ContentID));
40 }
41 else
42 {
43 Headers[MailHeaderInfo.GetString(MailHeaderID.ContentID)] = value;
44 }
45 }
46 }
47
48 internal string ContentLocation
49 {
50 get
51 {
52 return Headers[MailHeaderInfo.GetString(MailHeaderID.ContentLocation)];
53 }
54 set
55 {
56 if (string.IsNullOrEmpty(value))
57 {
58 Headers.Remove(MailHeaderInfo.GetString(MailHeaderID.ContentLocation));
59 }
60 else
61 {
62 Headers[MailHeaderInfo.GetString(MailHeaderID.ContentLocation)] = value;
63 }
64 }
65 }
66
67 internal NameValueCollection Headers
68 {
69 get
70 {
71 if (_headers == null)
72 {
74 }
75 if (_contentType == null)
76 {
78 }
79 _contentType.PersistIfNeeded(_headers, forcePersist: false);
80 if (_contentDisposition != null)
81 {
82 _contentDisposition.PersistIfNeeded(_headers, forcePersist: false);
83 }
84 return _headers;
85 }
86 }
87
89 {
90 get
91 {
92 return _contentType ?? (_contentType = new ContentType());
93 }
94 set
95 {
96 if (value == null)
97 {
98 throw new ArgumentNullException("value");
99 }
101 _contentType.PersistIfNeeded((HeaderCollection)Headers, forcePersist: true);
102 }
103 }
104
105 internal MimeBasePart()
106 {
107 }
108
109 internal static bool ShouldUseBase64Encoding(Encoding encoding)
110 {
111 if (encoding != Encoding.Unicode && encoding != Encoding.UTF8 && encoding != Encoding.UTF32)
112 {
113 return encoding == Encoding.BigEndianUnicode;
114 }
115 return true;
116 }
117
118 internal static string EncodeHeaderValue(string value, Encoding encoding, bool base64Encoding)
119 {
120 return EncodeHeaderValue(value, encoding, base64Encoding, 0);
121 }
122
123 internal static string EncodeHeaderValue(string value, Encoding encoding, bool base64Encoding, int headerLength)
124 {
125 if (IsAscii(value, permitCROrLF: false))
126 {
127 return value;
128 }
129 if (encoding == null)
130 {
131 encoding = Encoding.GetEncoding("utf-8");
132 }
133 EncodedStreamFactory encodedStreamFactory = new EncodedStreamFactory();
134 IEncodableStream encoderForHeader = encodedStreamFactory.GetEncoderForHeader(encoding, base64Encoding, headerLength);
135 encoderForHeader.EncodeString(value, encoding);
136 return encoderForHeader.GetEncodedString();
137 }
138
139 internal static string DecodeHeaderValue(string value)
140 {
141 if (string.IsNullOrEmpty(value))
142 {
143 return string.Empty;
144 }
145 string text = string.Empty;
146 string[] array = value.Split(s_headerValueSplitChars, StringSplitOptions.RemoveEmptyEntries);
147 string[] array2 = array;
148 foreach (string text2 in array2)
149 {
150 string[] array3 = text2.Split(s_questionMarkSplitChars);
151 if (array3.Length != 5 || array3[0] != "=" || array3[4] != "=")
152 {
153 return value;
154 }
155 string name = array3[1];
156 bool useBase64Encoding = array3[2] == "B";
157 byte[] bytes = Encoding.ASCII.GetBytes(array3[3]);
158 EncodedStreamFactory encodedStreamFactory = new EncodedStreamFactory();
159 IEncodableStream encoderForHeader = encodedStreamFactory.GetEncoderForHeader(Encoding.GetEncoding(name), useBase64Encoding, 0);
160 int count = encoderForHeader.DecodeBytes(bytes, 0, bytes.Length);
161 Encoding encoding = Encoding.GetEncoding(name);
162 text += encoding.GetString(bytes, 0, count);
163 }
164 return text;
165 }
166
167 internal static Encoding DecodeEncoding(string value)
168 {
169 if (string.IsNullOrEmpty(value))
170 {
171 return null;
172 }
173 string[] array = value.Split(s_decodeEncodingSplitChars);
174 if (array.Length < 5 || array[0] != "=" || array[4] != "=")
175 {
176 return null;
177 }
178 string name = array[1];
179 return Encoding.GetEncoding(name);
180 }
181
182 internal static bool IsAscii(string value, bool permitCROrLF)
183 {
184 if (value == null)
185 {
186 throw new ArgumentNullException("value");
187 }
188 foreach (char c in value)
189 {
190 if (c > '\u007f')
191 {
192 return false;
193 }
194 if (!permitCROrLF && (c == '\r' || c == '\n'))
195 {
196 return false;
197 }
198 }
199 return true;
200 }
201
202 internal void PrepareHeaders(bool allowUnicode)
203 {
204 _contentType.PersistIfNeeded((HeaderCollection)Headers, forcePersist: false);
206 if (_contentDisposition != null)
207 {
210 }
211 }
212
213 internal virtual void Send(BaseWriter writer, bool allowUnicode)
214 {
215 throw new NotImplementedException();
216 }
217
218 internal virtual IAsyncResult BeginSend(BaseWriter writer, AsyncCallback callback, bool allowUnicode, object state)
219 {
220 throw new NotImplementedException();
221 }
222
224 {
225 if (asyncResult == null)
226 {
227 throw new ArgumentNullException("asyncResult");
228 }
230 if (lazyAsyncResult == null || lazyAsyncResult.AsyncObject != this)
231 {
232 throw new ArgumentException(System.SR.net_io_invalidasyncresult, "asyncResult");
233 }
234 if (lazyAsyncResult.EndCalled)
235 {
237 }
238 lazyAsyncResult.InternalWaitForCompletion();
239 lazyAsyncResult.EndCalled = true;
240 if (lazyAsyncResult.Result is Exception)
241 {
242 throw (Exception)lazyAsyncResult.Result;
243 }
244 }
245}
static string GetString(MailHeaderID id)
void PersistIfNeeded(HeaderCollection headers, bool forcePersist)
string Encode(bool allowUnicode)
void PersistIfNeeded(HeaderCollection headers, bool forcePersist)
IEncodableStream GetEncoderForHeader(Encoding encoding, bool useBase64Encoding, int headerTextLength)
void InternalSet(string name, string value)
MimePartAsyncResult(MimeBasePart part, object state, AsyncCallback callback)
static string EncodeHeaderValue(string value, Encoding encoding, bool base64Encoding, int headerLength)
void EndSend(IAsyncResult asyncResult)
static bool IsAscii(string value, bool permitCROrLF)
static string EncodeHeaderValue(string value, Encoding encoding, bool base64Encoding)
virtual void Send(BaseWriter writer, bool allowUnicode)
NameValueCollection Headers
static bool ShouldUseBase64Encoding(Encoding encoding)
static Encoding DecodeEncoding(string value)
virtual IAsyncResult BeginSend(BaseWriter writer, AsyncCallback callback, bool allowUnicode, object state)
static readonly char[] s_questionMarkSplitChars
ContentDisposition _contentDisposition
void PrepareHeaders(bool allowUnicode)
static string DecodeHeaderValue(string value)
static readonly char[] s_headerValueSplitChars
static readonly char[] s_decodeEncodingSplitChars
static string net_io_invalidendcall
Definition SR.cs:22
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string net_io_invalidasyncresult
Definition SR.cs:20
Definition SR.cs:7
static Encoding BigEndianUnicode
Definition Encoding.cs:521
static Encoding Unicode
Definition Encoding.cs:519
static Encoding UTF8
Definition Encoding.cs:526
static Encoding GetEncoding(int codepage)
Definition Encoding.cs:593
static Encoding UTF32
Definition Encoding.cs:528
static Encoding ASCII
Definition Encoding.cs:511
unsafe string GetString(byte *bytes, int byteCount)
Definition Encoding.cs:973
int DecodeBytes(byte[] buffer, int offset, int count)
int EncodeString(string value, Encoding encoding)