Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
Message.cs
Go to the documentation of this file.
4using System.Text;
5
6namespace System.Net.Mail;
7
8internal sealed class Message
9{
10 internal sealed class EmptySendContext
11 {
13
15
17 {
19 _result = result;
20 }
21 }
22
24
26
28
30
32
34
36
38
40
42
43 private string _subject;
44
46
48
50
52 {
53 get
54 {
55 if (_priority != (MailPriority)(-1))
56 {
57 return _priority;
58 }
59 return MailPriority.Normal;
60 }
61 set
62 {
64 }
65 }
66
68 {
69 get
70 {
71 return _from;
72 }
73 [param: DisallowNull]
74 set
75 {
76 if (value == null)
77 {
78 throw new ArgumentNullException("value");
79 }
80 _from = value;
81 }
82 }
83
85 {
86 get
87 {
88 return _sender;
89 }
90 set
91 {
92 _sender = value;
93 }
94 }
95
97 {
98 get
99 {
100 return _replyTo;
101 }
102 set
103 {
104 _replyTo = value;
105 }
106 }
107
109
111
113
115
116 internal string Subject
117 {
118 get
119 {
120 return _subject;
121 }
122 set
123 {
124 Encoding encoding = null;
125 try
126 {
128 }
129 catch (ArgumentException)
130 {
131 }
132 if (encoding != null && value != null)
133 {
134 try
135 {
138 }
139 catch (FormatException)
140 {
141 }
142 }
143 if (value != null && MailBnfHelper.HasCROrLF(value))
144 {
146 }
147 _subject = value;
148 if (_subject != null)
149 {
150 _subject = _subject.Normalize(NormalizationForm.FormC);
151 if (_subjectEncoding == null && !MimeBasePart.IsAscii(_subject, permitCROrLF: false))
152 {
154 }
155 }
156 }
157 }
158
160 {
161 get
162 {
163 return _subjectEncoding;
164 }
165 set
166 {
168 }
169 }
170
171 internal HeaderCollection Headers
172 {
173 get
174 {
175 if (_headers == null)
176 {
178 if (System.Net.NetEventSource.Log.IsEnabled())
179 {
180 System.Net.NetEventSource.Associate(this, _headers, "Headers");
181 }
182 }
183 return _headers;
184 }
185 }
186
188 {
189 get
190 {
191 return _headersEncoding;
192 }
193 set
194 {
196 }
197 }
198
200 {
201 get
202 {
203 if (_envelopeHeaders == null)
204 {
206 if (System.Net.NetEventSource.Log.IsEnabled())
207 {
208 System.Net.NetEventSource.Associate(this, _envelopeHeaders, "EnvelopeHeaders");
209 }
210 }
211 return _envelopeHeaders;
212 }
213 }
214
215 internal MimeBasePart Content
216 {
217 get
218 {
219 return _content;
220 }
221 [param: DisallowNull]
222 set
223 {
224 if (value == null)
225 {
226 throw new ArgumentNullException("value");
227 }
228 _content = value;
229 }
230 }
231
232 internal Message()
233 {
234 }
235
236 internal Message(string from, string to)
237 : this()
238 {
239 if (from == null)
240 {
241 throw new ArgumentNullException("from");
242 }
243 if (to == null)
244 {
245 throw new ArgumentNullException("to");
246 }
247 if (from.Length == 0)
248 {
249 throw new ArgumentException(System.SR.Format(System.SR.net_emptystringcall, "from"), "from");
250 }
251 if (to.Length == 0)
252 {
254 }
255 _from = new MailAddress(from);
256 _to = new MailAddressCollection { to };
257 }
258
259 internal Message(MailAddress from, MailAddress to)
260 : this()
261 {
262 _from = from;
263 To.Add(to);
264 }
265
266 internal void EmptySendCallback(IAsyncResult result)
267 {
268 Exception result2 = null;
269 if (!result.CompletedSynchronously)
270 {
271 EmptySendContext emptySendContext = (EmptySendContext)result.AsyncState;
272 try
273 {
274 emptySendContext._writer.EndGetContentStream(result).Close();
275 }
276 catch (Exception ex)
277 {
278 result2 = ex;
279 }
280 emptySendContext._result.InvokeCallback(result2);
281 }
282 }
283
284 internal IAsyncResult BeginSend(BaseWriter writer, bool sendEnvelope, bool allowUnicode, AsyncCallback callback, object state)
285 {
286 PrepareHeaders(sendEnvelope, allowUnicode);
287 writer.WriteHeaders(Headers, allowUnicode);
288 if (Content != null)
289 {
290 return Content.BeginSend(writer, callback, allowUnicode, state);
291 }
292 System.Net.LazyAsyncResult lazyAsyncResult = new System.Net.LazyAsyncResult(this, state, callback);
293 IAsyncResult asyncResult = writer.BeginGetContentStream(EmptySendCallback, new EmptySendContext(writer, lazyAsyncResult));
294 if (asyncResult.CompletedSynchronously)
295 {
296 writer.EndGetContentStream(asyncResult).Close();
297 lazyAsyncResult.InvokeCallback();
298 }
299 return lazyAsyncResult;
300 }
301
303 {
304 if (asyncResult == null)
305 {
306 throw new ArgumentNullException("asyncResult");
307 }
308 if (Content != null)
309 {
310 Content.EndSend(asyncResult);
311 return;
312 }
313 if (!(asyncResult is System.Net.LazyAsyncResult lazyAsyncResult) || lazyAsyncResult.AsyncObject != this)
314 {
316 }
317 if (lazyAsyncResult.EndCalled)
318 {
320 }
321 lazyAsyncResult.InternalWaitForCompletion();
322 lazyAsyncResult.EndCalled = true;
323 if (lazyAsyncResult.Result is Exception source)
324 {
326 }
327 }
328
329 internal void Send(BaseWriter writer, bool sendEnvelope, bool allowUnicode)
330 {
331 if (sendEnvelope)
332 {
333 PrepareEnvelopeHeaders(sendEnvelope, allowUnicode);
334 writer.WriteHeaders(EnvelopeHeaders, allowUnicode);
335 }
336 PrepareHeaders(sendEnvelope, allowUnicode);
337 writer.WriteHeaders(Headers, allowUnicode);
338 if (Content != null)
339 {
340 Content.Send(writer, allowUnicode);
341 }
342 else
343 {
344 writer.GetContentStream().Close();
345 }
346 }
347
348 internal void PrepareEnvelopeHeaders(bool sendEnvelope, bool allowUnicode)
349 {
350 if (_headersEncoding == null)
351 {
353 }
354 EncodeHeaders(EnvelopeHeaders, allowUnicode);
355 string @string = MailHeaderInfo.GetString(MailHeaderID.XSender);
356 if (!IsHeaderSet(@string))
357 {
358 MailAddress mailAddress = Sender ?? From;
359 EnvelopeHeaders.InternalSet(@string, mailAddress.Encode(@string.Length, allowUnicode));
360 }
361 string string2 = MailHeaderInfo.GetString(MailHeaderID.XReceiver);
362 EnvelopeHeaders.Remove(string2);
363 foreach (MailAddress item in To)
364 {
365 EnvelopeHeaders.InternalAdd(string2, item.Encode(string2.Length, allowUnicode));
366 }
367 foreach (MailAddress item2 in CC)
368 {
369 EnvelopeHeaders.InternalAdd(string2, item2.Encode(string2.Length, allowUnicode));
370 }
371 foreach (MailAddress item3 in Bcc)
372 {
373 EnvelopeHeaders.InternalAdd(string2, item3.Encode(string2.Length, allowUnicode));
374 }
375 }
376
377 internal void PrepareHeaders(bool sendEnvelope, bool allowUnicode)
378 {
379 if (_headersEncoding == null)
380 {
382 }
383 Headers.Remove(MailHeaderInfo.GetString(MailHeaderID.ContentType));
384 Headers[MailHeaderInfo.GetString(MailHeaderID.MimeVersion)] = "1.0";
385 string @string = MailHeaderInfo.GetString(MailHeaderID.Sender);
386 if (Sender != null)
387 {
388 Headers.InternalAdd(@string, Sender.Encode(@string.Length, allowUnicode));
389 }
390 else
391 {
392 Headers.Remove(@string);
393 }
394 @string = MailHeaderInfo.GetString(MailHeaderID.From);
395 Headers.InternalAdd(@string, From.Encode(@string.Length, allowUnicode));
397 if (To.Count > 0)
398 {
399 Headers.InternalAdd(@string, To.Encode(@string.Length, allowUnicode));
400 }
401 else
402 {
403 Headers.Remove(@string);
404 }
406 if (CC.Count > 0)
407 {
408 Headers.InternalAdd(@string, CC.Encode(@string.Length, allowUnicode));
409 }
410 else
411 {
412 Headers.Remove(@string);
413 }
414 @string = MailHeaderInfo.GetString(MailHeaderID.ReplyTo);
415 if (ReplyTo != null)
416 {
417 Headers.InternalAdd(@string, ReplyTo.Encode(@string.Length, allowUnicode));
418 }
419 else if (ReplyToList.Count > 0)
420 {
421 Headers.InternalAdd(@string, ReplyToList.Encode(@string.Length, allowUnicode));
422 }
423 else
424 {
425 Headers.Remove(@string);
426 }
427 Headers.Remove(MailHeaderInfo.GetString(MailHeaderID.Bcc));
428 if (_priority == MailPriority.High)
429 {
430 Headers[MailHeaderInfo.GetString(MailHeaderID.XPriority)] = "1";
431 Headers[MailHeaderInfo.GetString(MailHeaderID.Priority)] = "urgent";
432 Headers[MailHeaderInfo.GetString(MailHeaderID.Importance)] = "high";
433 }
434 else if (_priority == MailPriority.Low)
435 {
436 Headers[MailHeaderInfo.GetString(MailHeaderID.XPriority)] = "5";
437 Headers[MailHeaderInfo.GetString(MailHeaderID.Priority)] = "non-urgent";
438 Headers[MailHeaderInfo.GetString(MailHeaderID.Importance)] = "low";
439 }
440 else if (_priority != (MailPriority)(-1))
441 {
442 Headers.Remove(MailHeaderInfo.GetString(MailHeaderID.XPriority));
443 Headers.Remove(MailHeaderInfo.GetString(MailHeaderID.Priority));
444 Headers.Remove(MailHeaderInfo.GetString(MailHeaderID.Importance));
445 }
447 @string = MailHeaderInfo.GetString(MailHeaderID.Subject);
448 if (!string.IsNullOrEmpty(_subject))
449 {
450 if (allowUnicode)
451 {
452 Headers.InternalAdd(@string, _subject);
453 }
454 else
455 {
457 }
458 }
459 else
460 {
461 Headers.Remove(@string);
462 }
463 EncodeHeaders(_headers, allowUnicode);
464 }
465
466 internal void EncodeHeaders(HeaderCollection headers, bool allowUnicode)
467 {
468 if (_headersEncoding == null)
469 {
471 }
472 for (int i = 0; i < headers.Count; i++)
473 {
474 string key = headers.GetKey(i);
476 {
477 continue;
478 }
479 string[] values = headers.GetValues(key);
480 string empty = string.Empty;
481 for (int j = 0; j < values.Length; j++)
482 {
484 if (j == 0)
485 {
486 headers.Set(key, empty);
487 }
488 else
489 {
490 headers.Add(key, empty);
491 }
492 }
493 }
494 }
495
496 private bool IsHeaderSet(string headerName)
497 {
498 for (int i = 0; i < Headers.Count; i++)
499 {
500 if (string.Equals(Headers.GetKey(i), headerName, StringComparison.InvariantCultureIgnoreCase))
501 {
502 return true;
503 }
504 }
505 return false;
506 }
507}
void InvokeCallback(object result)
string Encode(int charsConsumed, bool allowUnicode)
string Encode(int charsConsumed, bool allowUnicode)
static bool IsUserSettable(string name)
static bool AllowsUnicode(string name)
static string GetString(MailHeaderID id)
System.Net.LazyAsyncResult _result
Definition Message.cs:12
EmptySendContext(BaseWriter writer, System.Net.LazyAsyncResult result)
Definition Message.cs:16
void PrepareHeaders(bool sendEnvelope, bool allowUnicode)
Definition Message.cs:377
MailAddress _sender
Definition Message.cs:25
void PrepareEnvelopeHeaders(bool sendEnvelope, bool allowUnicode)
Definition Message.cs:348
bool IsHeaderSet(string headerName)
Definition Message.cs:496
HeaderCollection _headers
Definition Message.cs:39
MailAddress Sender
Definition Message.cs:85
MailAddressCollection Bcc
Definition Message.cs:112
void EndSend(IAsyncResult asyncResult)
Definition Message.cs:302
void EncodeHeaders(HeaderCollection headers, bool allowUnicode)
Definition Message.cs:466
MailAddressCollection _replyToList
Definition Message.cs:27
IAsyncResult BeginSend(BaseWriter writer, bool sendEnvelope, bool allowUnicode, AsyncCallback callback, object state)
Definition Message.cs:284
MailAddressCollection ReplyToList
Definition Message.cs:108
MailPriority Priority
Definition Message.cs:52
HeaderCollection _envelopeHeaders
Definition Message.cs:41
MimeBasePart _content
Definition Message.cs:37
MailAddress ReplyTo
Definition Message.cs:97
MailAddressCollection _to
Definition Message.cs:31
Message(string from, string to)
Definition Message.cs:236
MailPriority _priority
Definition Message.cs:49
MailAddressCollection _cc
Definition Message.cs:33
MailAddress _from
Definition Message.cs:23
void Send(BaseWriter writer, bool sendEnvelope, bool allowUnicode)
Definition Message.cs:329
MailAddressCollection _bcc
Definition Message.cs:35
HeaderCollection EnvelopeHeaders
Definition Message.cs:200
MailAddress _replyTo
Definition Message.cs:29
void EmptySendCallback(IAsyncResult result)
Definition Message.cs:266
MailAddressCollection To
Definition Message.cs:110
Message(MailAddress from, MailAddress to)
Definition Message.cs:259
Encoding _headersEncoding
Definition Message.cs:47
MailAddressCollection CC
Definition Message.cs:114
Encoding _subjectEncoding
Definition Message.cs:45
Stream EndGetContentStream(IAsyncResult result)
void InternalAdd(string name, string value)
void InternalSet(string name, string value)
override string[] GetValues(string name)
override void Remove(string name)
override void Set(string name, string value)
override void Add(string name, string value)
static string GetDateTimeString(DateTime value, StringBuilder builder)
static bool HasCROrLF(string data)
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 readonly System.Net.NetEventSource Log
static void Associate(object first, object second, [CallerMemberName] string memberName=null)
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
static string MailSubjectInvalidFormat
Definition SR.cs:166
static string net_emptystringcall
Definition SR.cs:14
Definition SR.cs:7
static Encoding GetEncoding(int codepage)
Definition Encoding.cs:593
static DateTime Now
Definition DateTime.cs:103