Files
2026-06-04 11:42:34 +02:00

335 lines
11 KiB
C#

using System;
using System.Collections;
using System.Collections.Specialized;
using System.Globalization;
using System.Text;
namespace System.Net.Mime
{
/// <summary>Represents a MIME protocol Content-Disposition header.</summary>
// Token: 0x0200014E RID: 334
public class ContentDisposition
{
/// <summary>Initializes a new instance of the <see cref="T:System.Net.Mime.ContentDisposition" /> class with a <see cref="P:System.Net.Mime.ContentDisposition.DispositionType" /> of <see cref="F:System.Net.Mime.DispositionTypeNames.Attachment" />. </summary>
// Token: 0x06000B6C RID: 2924 RVA: 0x00023020 File Offset: 0x00021220
public ContentDisposition()
: this("attachment")
{
}
/// <summary>Initializes a new instance of the <see cref="T:System.Net.Mime.ContentDisposition" /> class with the specified disposition information.</summary>
/// <param name="disposition">A <see cref="T:System.Net.Mime.DispositionTypeNames" /> value that contains the disposition.</param>
/// <exception cref="T:System.FormatException">
/// <paramref name="disposition" /> is null or equal to <see cref="F:System.String.Empty" /> ("").</exception>
// Token: 0x06000B6D RID: 2925 RVA: 0x00023030 File Offset: 0x00021230
public ContentDisposition(string disposition)
{
if (disposition == null)
{
throw new ArgumentNullException();
}
if (disposition.Length < 1)
{
throw new FormatException();
}
this.Size = -1L;
try
{
int num = disposition.IndexOf(';');
if (num < 0)
{
this.dispositionType = disposition.Trim();
}
else
{
string[] array = disposition.Split(new char[] { ';' });
this.dispositionType = array[0].Trim();
for (int i = 1; i < array.Length; i++)
{
this.Parse(array[i]);
}
}
}
catch
{
throw new FormatException();
}
}
// Token: 0x06000B6E RID: 2926 RVA: 0x00023100 File Offset: 0x00021300
private void Parse(string pair)
{
if (pair == null || pair.Length < 0)
{
return;
}
string[] array = pair.Split(new char[] { '=' });
if (array.Length == 2)
{
this.parameters.Add(array[0].Trim(), array[1].Trim());
return;
}
throw new FormatException();
}
/// <summary>Gets or sets the creation date for a file attachment.</summary>
/// <returns>A <see cref="T:System.DateTime" /> value that indicates the file creation date; otherwise, <see cref="F:System.DateTime.MinValue" /> if no date was specified.</returns>
// Token: 0x170002DB RID: 731
// (get) Token: 0x06000B6F RID: 2927 RVA: 0x00023164 File Offset: 0x00021364
// (set) Token: 0x06000B70 RID: 2928 RVA: 0x000231A8 File Offset: 0x000213A8
public DateTime CreationDate
{
get
{
if (this.parameters.ContainsKey("creation-date"))
{
return DateTime.ParseExact(this.parameters["creation-date"], "dd MMM yyyy HH':'mm':'ss zz00", null);
}
return DateTime.MinValue;
}
set
{
if (value > DateTime.MinValue)
{
this.parameters["creation-date"] = value.ToString("dd MMM yyyy HH':'mm':'ss zz00");
}
else
{
this.parameters.Remove("modification-date");
}
}
}
/// <summary>Gets or sets the disposition type for an e-mail attachment.</summary>
/// <returns>A <see cref="T:System.String" /> that contains the disposition type. The value is not restricted but is typically one of the <see cref="P:System.Net.Mime.ContentDisposition.DispositionType" /> values.</returns>
/// <exception cref="T:System.ArgumentNullException">The value specified for a set operation is null.</exception>
/// <exception cref="T:System.ArgumentException">The value specified for a set operation is equal to <see cref="F:System.String.Empty" /> ("").</exception>
// Token: 0x170002DC RID: 732
// (get) Token: 0x06000B71 RID: 2929 RVA: 0x000231F8 File Offset: 0x000213F8
// (set) Token: 0x06000B72 RID: 2930 RVA: 0x00023200 File Offset: 0x00021400
public string DispositionType
{
get
{
return this.dispositionType;
}
set
{
if (value == null)
{
throw new ArgumentNullException();
}
if (value.Length < 1)
{
throw new ArgumentException();
}
this.dispositionType = value;
}
}
/// <summary>Gets or sets the suggested file name for an e-mail attachment.</summary>
/// <returns>A <see cref="T:System.String" /> that contains the file name. </returns>
// Token: 0x170002DD RID: 733
// (get) Token: 0x06000B73 RID: 2931 RVA: 0x00023228 File Offset: 0x00021428
// (set) Token: 0x06000B74 RID: 2932 RVA: 0x0002323C File Offset: 0x0002143C
public string FileName
{
get
{
return this.parameters["filename"];
}
set
{
this.parameters["filename"] = value;
}
}
/// <summary>Gets or sets a <see cref="T:System.Boolean" /> value that determines the disposition type (Inline or Attachment) for an e-mail attachment.</summary>
/// <returns>true if content in the attachment is presented inline as part of the e-mail body; otherwise, false. </returns>
// Token: 0x170002DE RID: 734
// (get) Token: 0x06000B75 RID: 2933 RVA: 0x00023250 File Offset: 0x00021450
// (set) Token: 0x06000B76 RID: 2934 RVA: 0x0002326C File Offset: 0x0002146C
public bool Inline
{
get
{
return string.Compare(this.dispositionType, "inline", true, CultureInfo.InvariantCulture) == 0;
}
set
{
if (value)
{
this.dispositionType = "inline";
}
else
{
this.dispositionType = "attachment";
}
}
}
/// <summary>Gets or sets the modification date for a file attachment.</summary>
/// <returns>A <see cref="T:System.DateTime" /> value that indicates the file modification date; otherwise, <see cref="F:System.DateTime.MinValue" /> if no date was specified.</returns>
// Token: 0x170002DF RID: 735
// (get) Token: 0x06000B77 RID: 2935 RVA: 0x00023290 File Offset: 0x00021490
// (set) Token: 0x06000B78 RID: 2936 RVA: 0x000232D4 File Offset: 0x000214D4
public DateTime ModificationDate
{
get
{
if (this.parameters.ContainsKey("modification-date"))
{
return DateTime.ParseExact(this.parameters["modification-date"], "dd MMM yyyy HH':'mm':'ss zz00", null);
}
return DateTime.MinValue;
}
set
{
if (value > DateTime.MinValue)
{
this.parameters["modification-date"] = value.ToString("dd MMM yyyy HH':'mm':'ss zz00");
}
else
{
this.parameters.Remove("modification-date");
}
}
}
/// <summary>Gets the parameters included in the Content-Disposition header represented by this instance.</summary>
/// <returns>A writable <see cref="T:System.Collections.Specialized.StringDictionary" /> that contains parameter name/value pairs.</returns>
// Token: 0x170002E0 RID: 736
// (get) Token: 0x06000B79 RID: 2937 RVA: 0x00023324 File Offset: 0x00021524
public global::System.Collections.Specialized.StringDictionary Parameters
{
get
{
return this.parameters;
}
}
/// <summary>Gets or sets the read date for a file attachment.</summary>
/// <returns>A <see cref="T:System.DateTime" /> value that indicates the file read date; otherwise, <see cref="F:System.DateTime.MinValue" /> if no date was specified.</returns>
// Token: 0x170002E1 RID: 737
// (get) Token: 0x06000B7A RID: 2938 RVA: 0x0002332C File Offset: 0x0002152C
// (set) Token: 0x06000B7B RID: 2939 RVA: 0x00023370 File Offset: 0x00021570
public DateTime ReadDate
{
get
{
if (this.parameters.ContainsKey("read-date"))
{
return DateTime.ParseExact(this.parameters["read-date"], "dd MMM yyyy HH':'mm':'ss zz00", null);
}
return DateTime.MinValue;
}
set
{
if (value > DateTime.MinValue)
{
this.parameters["read-date"] = value.ToString("dd MMM yyyy HH':'mm':'ss zz00");
}
else
{
this.parameters.Remove("read-date");
}
}
}
/// <summary>Gets or sets the size of a file attachment.</summary>
/// <returns>A <see cref="T:System.Int32" /> that specifies the number of bytes in the file attachment. The default value is -1, which indicates that the file size is unknown.</returns>
// Token: 0x170002E2 RID: 738
// (get) Token: 0x06000B7C RID: 2940 RVA: 0x000233C0 File Offset: 0x000215C0
// (set) Token: 0x06000B7D RID: 2941 RVA: 0x000233F0 File Offset: 0x000215F0
public long Size
{
get
{
if (this.parameters.ContainsKey("size"))
{
return long.Parse(this.parameters["size"]);
}
return -1L;
}
set
{
if (value > -1L)
{
this.parameters["size"] = value.ToString();
}
else
{
this.parameters.Remove("size");
}
}
}
/// <summary>Determines whether the content-disposition header of the specified <see cref="T:System.Net.Mime.ContentDisposition" /> object is equal to the content-disposition header of this object.</summary>
/// <returns>true if the content-disposition headers are the same; otherwise false.</returns>
/// <param name="rparam">The <see cref="T:System.Net.Mime.ContentDisposition" /> object to compare with this object.</param>
// Token: 0x06000B7E RID: 2942 RVA: 0x00023434 File Offset: 0x00021634
public override bool Equals(object obj)
{
return this.Equals(obj as ContentDisposition);
}
// Token: 0x06000B7F RID: 2943 RVA: 0x00023444 File Offset: 0x00021644
private bool Equals(ContentDisposition other)
{
return other != null && this.ToString() == other.ToString();
}
/// <summary>Determines the hash code of the specified <see cref="T:System.Net.Mime.ContentDisposition" /> object</summary>
/// <returns>An integer hash value.</returns>
// Token: 0x06000B80 RID: 2944 RVA: 0x00023460 File Offset: 0x00021660
public override int GetHashCode()
{
return this.ToString().GetHashCode();
}
/// <summary>Returns a <see cref="T:System.String" /> representation of this instance.</summary>
/// <returns>A <see cref="T:System.String" /> that contains the property values for this instance.</returns>
// Token: 0x06000B81 RID: 2945 RVA: 0x00023470 File Offset: 0x00021670
public override string ToString()
{
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.Append(this.DispositionType.ToLower());
if (this.Parameters != null && this.Parameters.Count > 0)
{
foreach (object obj in this.Parameters)
{
DictionaryEntry dictionaryEntry = (DictionaryEntry)obj;
if (dictionaryEntry.Value != null && dictionaryEntry.Value.ToString().Length > 0)
{
stringBuilder.Append("; ");
stringBuilder.Append(dictionaryEntry.Key);
stringBuilder.Append("=");
string text = dictionaryEntry.Key.ToString();
string text2 = dictionaryEntry.Value.ToString();
bool flag = (text == "filename" && text2.IndexOf(' ') != -1) || text.EndsWith("date");
if (flag)
{
stringBuilder.Append("\"");
}
stringBuilder.Append(text2);
if (flag)
{
stringBuilder.Append("\"");
}
}
}
}
return stringBuilder.ToString();
}
// Token: 0x04000B74 RID: 2932
private const string rfc822 = "dd MMM yyyy HH':'mm':'ss zz00";
// Token: 0x04000B75 RID: 2933
private string dispositionType;
// Token: 0x04000B76 RID: 2934
private global::System.Collections.Specialized.StringDictionary parameters = new global::System.Collections.Specialized.StringDictionary();
}
}