Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
MailMessage.cs
Go to the documentation of this file.
4using System.Text;
5
6namespace System.Net.Mail;
7
8public class MailMessage : IDisposable
9{
11
13
15
16 private string _body = string.Empty;
17
19
21
22 private bool _isBodyHtml;
23
24 private bool _disposed;
25
26 private readonly Message _message;
27
29
31 {
32 get
33 {
34 return _message.From;
35 }
36 [param: DisallowNull]
37 set
38 {
39 if (value == null)
40 {
41 throw new ArgumentNullException("value");
42 }
43 _message.From = value;
44 }
45 }
46
48 {
49 get
50 {
51 return _message.Sender;
52 }
53 [param: DisallowNull]
54 set
55 {
56 _message.Sender = value;
57 }
58 }
59
60 [Obsolete("ReplyTo has been deprecated. Use ReplyToList instead, which can accept multiple addresses.")]
62 {
63 get
64 {
65 return _message.ReplyTo;
66 }
67 set
68 {
69 _message.ReplyTo = value;
70 }
71 }
72
74
76
78
80
82 {
83 get
84 {
85 return _message.Priority;
86 }
87 set
88 {
89 _message.Priority = value;
90 }
91 }
92
94 {
95 get
96 {
98 }
99 set
100 {
101 if (7u < (uint)value && value != DeliveryNotificationOptions.Never)
102 {
103 throw new ArgumentOutOfRangeException("value");
104 }
106 }
107 }
108
109 public string Subject
110 {
111 get
112 {
113 if (_message.Subject == null)
114 {
115 return string.Empty;
116 }
117 return _message.Subject;
118 }
119 [param: AllowNull]
120 set
121 {
122 _message.Subject = value;
123 }
124 }
125
127 {
128 get
129 {
131 }
132 set
133 {
134 _message.SubjectEncoding = value;
135 }
136 }
137
139
141 {
142 get
143 {
145 }
146 set
147 {
148 _message.HeadersEncoding = value;
149 }
150 }
151
152 public string Body
153 {
154 get
155 {
156 if (_body == null)
157 {
158 return string.Empty;
159 }
160 return _body;
161 }
162 [param: AllowNull]
163 set
164 {
165 _body = value;
166 if (_bodyEncoding == null && _body != null)
167 {
168 if (MimeBasePart.IsAscii(_body, permitCROrLF: true))
169 {
171 }
172 else
173 {
175 }
176 }
177 }
178 }
179
181 {
182 get
183 {
184 return _bodyEncoding;
185 }
186 set
187 {
189 }
190 }
191
193 {
194 get
195 {
197 }
198 set
199 {
201 }
202 }
203
204 public bool IsBodyHtml
205 {
206 get
207 {
208 return _isBodyHtml;
209 }
210 set
211 {
213 }
214 }
215
217 {
218 get
219 {
220 if (_disposed)
221 {
222 throw new ObjectDisposedException(GetType().FullName);
223 }
225 }
226 }
227
229 {
230 get
231 {
232 if (_disposed)
233 {
234 throw new ObjectDisposedException(GetType().FullName);
235 }
236 return _views ?? (_views = new AlternateViewCollection());
237 }
238 }
239
240 public MailMessage()
241 {
242 _message = new Message();
243 if (System.Net.NetEventSource.Log.IsEnabled())
244 {
246 }
247 }
248
249 public MailMessage(string from, string to)
250 {
251 if (from == null)
252 {
253 throw new ArgumentNullException("from");
254 }
255 if (to == null)
256 {
257 throw new ArgumentNullException("to");
258 }
259 if (from.Length == 0)
260 {
261 throw new ArgumentException(System.SR.Format(System.SR.net_emptystringcall, "from"), "from");
262 }
263 if (to.Length == 0)
264 {
266 }
267 _message = new Message(from, to);
268 if (System.Net.NetEventSource.Log.IsEnabled())
269 {
271 }
272 }
273
274 public MailMessage(string from, string to, string? subject, string? body)
275 : this(from, to)
276 {
277 Subject = subject;
278 Body = body;
279 }
280
282 {
283 if (from == null)
284 {
285 throw new ArgumentNullException("from");
286 }
287 if (to == null)
288 {
289 throw new ArgumentNullException("to");
290 }
291 _message = new Message(from, to);
292 }
293
294 public void Dispose()
295 {
296 Dispose(disposing: true);
297 }
298
299 protected virtual void Dispose(bool disposing)
300 {
301 if (disposing && !_disposed)
302 {
303 _disposed = true;
304 if (_views != null)
305 {
306 _views.Dispose();
307 }
308 if (_attachments != null)
309 {
311 }
312 if (_bodyView != null)
313 {
315 }
316 }
317 }
318
319 private void SetContent(bool allowUnicode)
320 {
321 if (_bodyView != null)
322 {
324 _bodyView = null;
325 }
326 if (AlternateViews.Count == 0 && Attachments.Count == 0)
327 {
328 if (!string.IsNullOrEmpty(_body))
329 {
331 _message.Content = _bodyView.MimePart;
332 }
333 }
334 else if (AlternateViews.Count == 0 && Attachments.Count > 0)
335 {
336 MimeMultiPart mimeMultiPart = new MimeMultiPart(MimeMultiPartType.Mixed);
337 if (!string.IsNullOrEmpty(_body))
338 {
340 }
341 else
342 {
344 }
345 mimeMultiPart.Parts.Add(_bodyView.MimePart);
346 foreach (Attachment attachment in Attachments)
347 {
348 if (attachment != null)
349 {
350 attachment.PrepareForSending(allowUnicode);
351 mimeMultiPart.Parts.Add(attachment.MimePart);
352 }
353 }
354 _message.Content = mimeMultiPart;
355 }
356 else
357 {
358 MimeMultiPart mimeMultiPart2 = null;
359 MimeMultiPart mimeMultiPart3 = new MimeMultiPart(MimeMultiPartType.Alternative);
360 if (!string.IsNullOrEmpty(_body))
361 {
363 mimeMultiPart3.Parts.Add(_bodyView.MimePart);
364 }
365 foreach (AlternateView alternateView in AlternateViews)
366 {
367 if (alternateView == null)
368 {
369 continue;
370 }
371 alternateView.PrepareForSending(allowUnicode);
372 if (alternateView.LinkedResources.Count > 0)
373 {
374 MimeMultiPart mimeMultiPart4 = new MimeMultiPart(MimeMultiPartType.Related);
375 mimeMultiPart4.ContentType.Parameters["type"] = alternateView.ContentType.MediaType;
376 mimeMultiPart4.ContentLocation = alternateView.MimePart.ContentLocation;
377 mimeMultiPart4.Parts.Add(alternateView.MimePart);
378 foreach (LinkedResource linkedResource in alternateView.LinkedResources)
379 {
380 linkedResource.PrepareForSending(allowUnicode);
381 mimeMultiPart4.Parts.Add(linkedResource.MimePart);
382 }
383 mimeMultiPart3.Parts.Add(mimeMultiPart4);
384 }
385 else
386 {
387 mimeMultiPart3.Parts.Add(alternateView.MimePart);
388 }
389 }
390 if (Attachments.Count > 0)
391 {
392 mimeMultiPart2 = new MimeMultiPart(MimeMultiPartType.Mixed);
393 mimeMultiPart2.Parts.Add(mimeMultiPart3);
394 foreach (Attachment attachment2 in Attachments)
395 {
396 if (attachment2 != null)
397 {
398 attachment2.PrepareForSending(allowUnicode);
399 mimeMultiPart2.Parts.Add(attachment2.MimePart);
400 }
401 }
402 _message.Content = mimeMultiPart2;
403 }
404 else if (mimeMultiPart3.Parts.Count == 1 && string.IsNullOrEmpty(_body))
405 {
406 _message.Content = mimeMultiPart3.Parts[0];
407 }
408 else
409 {
410 _message.Content = mimeMultiPart3;
411 }
412 }
413 if (_bodyView != null && _bodyTransferEncoding != TransferEncoding.Unknown)
414 {
415 _bodyView.TransferEncoding = _bodyTransferEncoding;
416 }
417 }
418
419 internal void Send(BaseWriter writer, bool sendEnvelope, bool allowUnicode)
420 {
421 SetContent(allowUnicode);
422 _message.Send(writer, sendEnvelope, allowUnicode);
423 }
424
425 internal IAsyncResult BeginSend(BaseWriter writer, bool sendEnvelope, bool allowUnicode, AsyncCallback callback, object state)
426 {
427 SetContent(allowUnicode);
428 return _message.BeginSend(writer, sendEnvelope, allowUnicode, callback, state);
429 }
430
432 {
434 }
435
437 {
439 {
440 StringBuilder stringBuilder = new StringBuilder(" NOTIFY=");
441 bool flag = false;
443 {
444 stringBuilder.Append("NEVER");
445 return stringBuilder.ToString();
446 }
448 {
449 stringBuilder.Append("SUCCESS");
450 flag = true;
451 }
453 {
454 if (flag)
455 {
456 stringBuilder.Append(',');
457 }
458 stringBuilder.Append("FAILURE");
459 flag = true;
460 }
462 {
463 if (flag)
464 {
465 stringBuilder.Append(',');
466 }
467 stringBuilder.Append("DELAY");
468 }
469 return stringBuilder.ToString();
470 }
471 return string.Empty;
472 }
473}
override void Dispose(bool disposing)
LinkedResourceCollection LinkedResources
static AlternateView CreateAlternateViewFromString(string content)
virtual void PrepareForSending(bool allowUnicode)
override void PrepareForSending(bool allowUnicode)
AlternateViewCollection _views
TransferEncoding _bodyTransferEncoding
MailMessage(string from, string to)
void EndSend(IAsyncResult asyncResult)
MailAddressCollection Bcc
AlternateViewCollection AlternateViews
DeliveryNotificationOptions _deliveryStatusNotification
AttachmentCollection Attachments
void Send(BaseWriter writer, bool sendEnvelope, bool allowUnicode)
AttachmentCollection _attachments
MailMessage(string from, string to, string? subject, string? body)
MailAddressCollection ReplyToList
MailAddressCollection To
TransferEncoding BodyTransferEncoding
readonly Message _message
MailMessage(MailAddress from, MailAddress to)
string BuildDeliveryStatusNotificationString()
MailAddressCollection CC
virtual void Dispose(bool disposing)
void SetContent(bool allowUnicode)
IAsyncResult BeginSend(BaseWriter writer, bool sendEnvelope, bool allowUnicode, AsyncCallback callback, object state)
MailAddress Sender
Definition Message.cs:85
MailAddressCollection Bcc
Definition Message.cs:112
void EndSend(IAsyncResult asyncResult)
Definition Message.cs:302
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 Headers
Definition Message.cs:172
MailAddress ReplyTo
Definition Message.cs:97
void Send(BaseWriter writer, bool sendEnvelope, bool allowUnicode)
Definition Message.cs:329
MailAddressCollection To
Definition Message.cs:110
MailAddressCollection CC
Definition Message.cs:114
StringDictionary Parameters
static bool IsAscii(string value, bool permitCROrLF)
Collection< MimeBasePart > Parts
static readonly System.Net.NetEventSource Log
static void Associate(object first, object second, [CallerMemberName] string memberName=null)
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string net_emptystringcall
Definition SR.cs:14
Definition SR.cs:7
static Encoding GetEncoding(int codepage)
Definition Encoding.cs:593
static Encoding ASCII
Definition Encoding.cs:511
override string ToString()
StringBuilder Append(char value, int repeatCount)