Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
MailBnfHelper.cs
Go to the documentation of this file.
1using System.Text;
2
3namespace System.Net.Mime;
4
5internal static class MailBnfHelper
6{
7 internal static readonly bool[] Atext = CreateCharactersAllowedInAtoms();
8
9 internal static readonly bool[] Qtext = CreateCharactersAllowedInQuotedStrings();
10
11 internal static readonly bool[] Dtext = CreateCharactersAllowedInDomainLiterals();
12
13 internal static readonly bool[] Ftext = CreateCharactersAllowedInHeaderNames();
14
15 internal static readonly bool[] Ttext = CreateCharactersAllowedInTokens();
16
17 internal static readonly bool[] Ctext = CreateCharactersAllowedInComments();
18
19 private static readonly string[] s_months = new string[13]
20 {
21 null, "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep",
22 "Oct", "Nov", "Dec"
23 };
24
25 private static bool[] CreateCharactersAllowedInAtoms()
26 {
27 bool[] array = new bool[128];
28 for (int i = 48; i <= 57; i++)
29 {
30 array[i] = true;
31 }
32 for (int j = 65; j <= 90; j++)
33 {
34 array[j] = true;
35 }
36 for (int k = 97; k <= 122; k++)
37 {
38 array[k] = true;
39 }
40 array[33] = true;
41 array[35] = true;
42 array[36] = true;
43 array[37] = true;
44 array[38] = true;
45 array[39] = true;
46 array[42] = true;
47 array[43] = true;
48 array[45] = true;
49 array[47] = true;
50 array[61] = true;
51 array[63] = true;
52 array[94] = true;
53 array[95] = true;
54 array[96] = true;
55 array[123] = true;
56 array[124] = true;
57 array[125] = true;
58 array[126] = true;
59 return array;
60 }
61
63 {
64 bool[] array = new bool[128];
65 for (int i = 1; i <= 9; i++)
66 {
67 array[i] = true;
68 }
69 array[11] = true;
70 array[12] = true;
71 for (int j = 14; j <= 33; j++)
72 {
73 array[j] = true;
74 }
75 for (int k = 35; k <= 91; k++)
76 {
77 array[k] = true;
78 }
79 for (int l = 93; l <= 127; l++)
80 {
81 array[l] = true;
82 }
83 return array;
84 }
85
87 {
88 bool[] array = new bool[128];
89 for (int i = 1; i <= 8; i++)
90 {
91 array[i] = true;
92 }
93 array[11] = true;
94 array[12] = true;
95 for (int j = 14; j <= 31; j++)
96 {
97 array[j] = true;
98 }
99 for (int k = 33; k <= 90; k++)
100 {
101 array[k] = true;
102 }
103 for (int l = 94; l <= 127; l++)
104 {
105 array[l] = true;
106 }
107 return array;
108 }
109
111 {
112 bool[] array = new bool[128];
113 for (int i = 33; i <= 57; i++)
114 {
115 array[i] = true;
116 }
117 for (int j = 59; j <= 126; j++)
118 {
119 array[j] = true;
120 }
121 return array;
122 }
123
124 private static bool[] CreateCharactersAllowedInTokens()
125 {
126 bool[] array = new bool[128];
127 for (int i = 33; i <= 126; i++)
128 {
129 array[i] = true;
130 }
131 array[40] = false;
132 array[41] = false;
133 array[60] = false;
134 array[62] = false;
135 array[64] = false;
136 array[44] = false;
137 array[59] = false;
138 array[58] = false;
139 array[92] = false;
140 array[34] = false;
141 array[47] = false;
142 array[91] = false;
143 array[93] = false;
144 array[63] = false;
145 array[61] = false;
146 return array;
147 }
148
149 private static bool[] CreateCharactersAllowedInComments()
150 {
151 bool[] array = new bool[128];
152 for (int i = 1; i <= 8; i++)
153 {
154 array[i] = true;
155 }
156 array[11] = true;
157 array[12] = true;
158 for (int j = 14; j <= 31; j++)
159 {
160 array[j] = true;
161 }
162 for (int k = 33; k <= 39; k++)
163 {
164 array[k] = true;
165 }
166 for (int l = 42; l <= 91; l++)
167 {
168 array[l] = true;
169 }
170 for (int m = 93; m <= 127; m++)
171 {
172 array[m] = true;
173 }
174 return array;
175 }
176
177 internal static bool SkipCFWS(string data, ref int offset)
178 {
179 int num = 0;
180 while (offset < data.Length)
181 {
182 if (data[offset] > '\u007f')
183 {
185 }
186 if (data[offset] == '\\' && num > 0)
187 {
188 offset += 2;
189 }
190 else if (data[offset] == '(')
191 {
192 num++;
193 }
194 else if (data[offset] == ')')
195 {
196 num--;
197 }
198 else if (data[offset] != ' ' && data[offset] != '\t' && num == 0)
199 {
200 return true;
201 }
202 if (num < 0)
203 {
205 }
206 offset++;
207 }
208 return false;
209 }
210
211 internal static void ValidateHeaderName(string data)
212 {
213 int i;
214 for (i = 0; i < data.Length; i++)
215 {
216 if (data[i] > Ftext.Length || !Ftext[(uint)data[i]])
217 {
219 }
220 }
221 if (i == 0)
222 {
224 }
225 }
226
227 internal static string ReadQuotedString(string data, ref int offset, StringBuilder builder)
228 {
229 return ReadQuotedString(data, ref offset, builder, doesntRequireQuotes: false, permitUnicodeInDisplayName: false);
230 }
231
232 internal static string ReadQuotedString(string data, ref int offset, StringBuilder builder, bool doesntRequireQuotes, bool permitUnicodeInDisplayName)
233 {
234 if (!doesntRequireQuotes)
235 {
236 offset++;
237 }
238 int num = offset;
239 StringBuilder stringBuilder = ((builder != null) ? builder : new StringBuilder());
240 while (offset < data.Length)
241 {
242 if (data[offset] == '\\')
243 {
244 stringBuilder.Append(data, num, offset - num);
245 num = ++offset;
246 }
247 else
248 {
249 if (data[offset] == '"')
250 {
251 stringBuilder.Append(data, num, offset - num);
252 offset++;
253 if (builder == null)
254 {
255 return stringBuilder.ToString();
256 }
257 return null;
258 }
259 if (data[offset] == '=' && data.Length > offset + 3 && data[offset + 1] == '\r' && data[offset + 2] == '\n' && (data[offset + 3] == ' ' || data[offset + 3] == '\t'))
260 {
261 offset += 3;
262 }
263 else if (permitUnicodeInDisplayName)
264 {
265 if (data[offset] <= '\u007f' && !Qtext[(uint)data[offset]])
266 {
268 }
269 }
270 else if (data[offset] > '\u007f' || !Qtext[(uint)data[offset]])
271 {
273 }
274 }
275 offset++;
276 }
277 if (doesntRequireQuotes)
278 {
279 stringBuilder.Append(data, num, offset - num);
280 if (builder == null)
281 {
282 return stringBuilder.ToString();
283 }
284 return null;
285 }
287 }
288
289 internal static string ReadParameterAttribute(string data, ref int offset, StringBuilder builder)
290 {
291 if (!SkipCFWS(data, ref offset))
292 {
293 return null;
294 }
295 return ReadToken(data, ref offset, null);
296 }
297
298 internal static string ReadToken(string data, ref int offset, StringBuilder builder)
299 {
300 int num = offset;
301 while (offset < data.Length)
302 {
303 if (data[offset] > '\u007f')
304 {
306 }
307 if (!Ttext[(uint)data[offset]])
308 {
309 break;
310 }
311 offset++;
312 }
313 if (num == offset && offset < data.Length)
314 {
316 }
317 return data.Substring(num, offset - num);
318 }
319
320 internal static string GetDateTimeString(DateTime value, StringBuilder builder)
321 {
322 StringBuilder stringBuilder = ((builder != null) ? builder : new StringBuilder());
323 stringBuilder.Append(value.Day);
324 stringBuilder.Append(' ');
325 stringBuilder.Append(s_months[value.Month]);
326 stringBuilder.Append(' ');
327 stringBuilder.Append(value.Year);
328 stringBuilder.Append(' ');
329 if (value.Hour <= 9)
330 {
331 stringBuilder.Append('0');
332 }
333 stringBuilder.Append(value.Hour);
334 stringBuilder.Append(':');
335 if (value.Minute <= 9)
336 {
337 stringBuilder.Append('0');
338 }
339 stringBuilder.Append(value.Minute);
340 stringBuilder.Append(':');
341 if (value.Second <= 9)
342 {
343 stringBuilder.Append('0');
344 }
345 stringBuilder.Append(value.Second);
346 string text = TimeZoneInfo.Local.GetUtcOffset(value).ToString();
347 if (text[0] != '-')
348 {
349 stringBuilder.Append(" +");
350 }
351 else
352 {
353 stringBuilder.Append(' ');
354 }
355 string[] array = text.Split(':');
356 stringBuilder.Append(array[0]);
357 stringBuilder.Append(array[1]);
358 if (builder == null)
359 {
360 return stringBuilder.ToString();
361 }
362 return null;
363 }
364
365 internal static void GetTokenOrQuotedString(string data, StringBuilder builder, bool allowUnicode)
366 {
367 int i = 0;
368 int num = 0;
369 for (; i < data.Length; i++)
370 {
371 if (CheckForUnicode(data[i], allowUnicode) || (Ttext[(uint)data[i]] && data[i] != ' '))
372 {
373 continue;
374 }
375 builder.Append('"');
376 for (; i < data.Length; i++)
377 {
378 if (!CheckForUnicode(data[i], allowUnicode))
379 {
380 if (IsFWSAt(data, i))
381 {
382 i += 2;
383 }
384 else if (!Qtext[(uint)data[i]])
385 {
386 builder.Append(data, num, i - num);
387 builder.Append('\\');
388 num = i;
389 }
390 }
391 }
392 builder.Append(data, num, i - num);
393 builder.Append('"');
394 return;
395 }
396 if (data.Length == 0)
397 {
398 builder.Append("\"\"");
399 }
400 builder.Append(data);
401 }
402
403 private static bool CheckForUnicode(char ch, bool allowUnicode)
404 {
405 if (ch < '\u007f')
406 {
407 return false;
408 }
409 if (!allowUnicode)
410 {
412 }
413 return true;
414 }
415
416 internal static bool IsAllowedWhiteSpace(char c)
417 {
418 if (c != '\t' && c != ' ' && c != '\r')
419 {
420 return c == '\n';
421 }
422 return true;
423 }
424
425 internal static bool HasCROrLF(string data)
426 {
427 for (int i = 0; i < data.Length; i++)
428 {
429 if (data[i] == '\r' || data[i] == '\n')
430 {
431 return true;
432 }
433 }
434 return false;
435 }
436
437 internal static bool IsFWSAt(string data, int index)
438 {
439 if (data[index] == '\r' && index + 2 < data.Length && data[index + 1] == '\n')
440 {
441 if (data[index + 2] != ' ')
442 {
443 return data[index + 2] == '\t';
444 }
445 return true;
446 }
447 return false;
448 }
449}
static string GetDateTimeString(DateTime value, StringBuilder builder)
static bool IsFWSAt(string data, int index)
static void ValidateHeaderName(string data)
static readonly bool[] Ftext
static bool[] CreateCharactersAllowedInAtoms()
static bool HasCROrLF(string data)
static bool CheckForUnicode(char ch, bool allowUnicode)
static readonly string[] s_months
static bool[] CreateCharactersAllowedInQuotedStrings()
static readonly bool[] Dtext
static bool[] CreateCharactersAllowedInHeaderNames()
static readonly bool[] Qtext
static string ReadToken(string data, ref int offset, StringBuilder builder)
static readonly bool[] Ttext
static bool[] CreateCharactersAllowedInDomainLiterals()
static readonly bool[] Atext
static string ReadQuotedString(string data, ref int offset, StringBuilder builder)
static bool IsAllowedWhiteSpace(char c)
static void GetTokenOrQuotedString(string data, StringBuilder builder, bool allowUnicode)
static readonly bool[] Ctext
static string ReadParameterAttribute(string data, ref int offset, StringBuilder builder)
static bool[] CreateCharactersAllowedInTokens()
static bool[] CreateCharactersAllowedInComments()
static string ReadQuotedString(string data, ref int offset, StringBuilder builder, bool doesntRequireQuotes, bool permitUnicodeInDisplayName)
static bool SkipCFWS(string data, ref int offset)
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string MailHeaderFieldMalformedHeader
Definition SR.cs:38
static string InvalidHeaderName
Definition SR.cs:48
static string MailHeaderFieldInvalidCharacter
Definition SR.cs:140
Definition SR.cs:7
override string ToString()
StringBuilder Append(char value, int repeatCount)
static TimeZoneInfo Local