229 lines
12 KiB
C#
229 lines
12 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Net.Mime;
|
|
using System.Text;
|
|
|
|
namespace System.Net.Mail
|
|
{
|
|
/// <summary>Represents an attachment to an e-mail.</summary>
|
|
// Token: 0x02000137 RID: 311
|
|
public class Attachment : AttachmentBase
|
|
{
|
|
/// <summary>Initializes a new instance of the <see cref="T:System.Net.Mail.Attachment" /> class with the specified content string. </summary>
|
|
/// <param name="fileName">A <see cref="T:System.String" /> that contains a file path to use to create this attachment.</param>
|
|
/// <exception cref="T:System.ArgumentNullException">
|
|
/// <paramref name="fileName" /> is null.</exception>
|
|
/// <exception cref="T:System.ArgumentException">
|
|
/// <paramref name="fileName" /> is empty.</exception>
|
|
// Token: 0x06000A95 RID: 2709 RVA: 0x0001DCD8 File Offset: 0x0001BED8
|
|
public Attachment(string fileName)
|
|
: base(fileName)
|
|
{
|
|
this.InitName(fileName);
|
|
}
|
|
|
|
/// <summary>Initializes a new instance of the <see cref="T:System.Net.Mail.Attachment" /> class with the specified content string and MIME type information. </summary>
|
|
/// <param name="fileName">A <see cref="T:System.String" /> that contains the content for this attachment.</param>
|
|
/// <param name="mediaType">A <see cref="T:System.String" /> that contains the MIME Content-Header information for this attachment. This value can be null.</param>
|
|
/// <exception cref="T:System.ArgumentNullException">
|
|
/// <paramref name="fileName" /> is null.</exception>
|
|
/// <exception cref="T:System.FormatException">
|
|
/// <paramref name="mediaType" /> is not in the correct format.</exception>
|
|
// Token: 0x06000A96 RID: 2710 RVA: 0x0001DCF4 File Offset: 0x0001BEF4
|
|
public Attachment(string fileName, string mediaType)
|
|
: base(fileName, mediaType)
|
|
{
|
|
this.InitName(fileName);
|
|
}
|
|
|
|
/// <summary>Initializes a new instance of the <see cref="T:System.Net.Mail.Attachment" /> class with the specified content string and <see cref="T:System.Net.Mime.ContentType" />.</summary>
|
|
/// <param name="fileName">A <see cref="T:System.String" /> that contains a file path to use to create this attachment.</param>
|
|
/// <param name="contentType">A <see cref="T:System.Net.Mime.ContentType" /> that describes the data in <paramref name="string" />.</param>
|
|
/// <exception cref="T:System.ArgumentNullException">
|
|
/// <paramref name="fileName" /> is null.</exception>
|
|
/// <exception cref="T:System.ArgumentException">
|
|
/// <paramref name="mediaType" /> is not in the correct format.</exception>
|
|
// Token: 0x06000A97 RID: 2711 RVA: 0x0001DD10 File Offset: 0x0001BF10
|
|
public Attachment(string fileName, global::System.Net.Mime.ContentType contentType)
|
|
: base(fileName, contentType)
|
|
{
|
|
this.InitName(fileName);
|
|
}
|
|
|
|
/// <summary>Initializes a new instance of the <see cref="T:System.Net.Mail.Attachment" /> class with the specified stream and content type. </summary>
|
|
/// <param name="contentStream">A readable <see cref="T:System.IO.Stream" /> that contains the content for this attachment.</param>
|
|
/// <param name="contentType">A <see cref="T:System.Net.Mime.ContentType" /> that describes the data in <paramref name="stream" />.</param>
|
|
/// <exception cref="T:System.ArgumentNullException">
|
|
/// <paramref name="contentType" /> is null.-or-<paramref name="contentStream" /> is null.</exception>
|
|
// Token: 0x06000A98 RID: 2712 RVA: 0x0001DD2C File Offset: 0x0001BF2C
|
|
public Attachment(Stream contentStream, global::System.Net.Mime.ContentType contentType)
|
|
: base(contentStream, contentType)
|
|
{
|
|
}
|
|
|
|
/// <summary>Initializes a new instance of the <see cref="T:System.Net.Mail.Attachment" /> class with the specified stream and name.</summary>
|
|
/// <param name="contentStream">A readable <see cref="T:System.IO.Stream" /> that contains the content for this attachment.</param>
|
|
/// <param name="name">A <see cref="T:System.String" /> that contains the value for the <see cref="P:System.Net.Mime.ContentType.Name" /> property of the <see cref="T:System.Net.Mime.ContentType" /> associated with this attachment. This value can be null.</param>
|
|
/// <exception cref="T:System.ArgumentNullException">
|
|
/// <paramref name="contentStream" /> is null.</exception>
|
|
// Token: 0x06000A99 RID: 2713 RVA: 0x0001DD44 File Offset: 0x0001BF44
|
|
public Attachment(Stream contentStream, string name)
|
|
: base(contentStream)
|
|
{
|
|
this.Name = name;
|
|
}
|
|
|
|
/// <summary>Initializes a new instance of the <see cref="T:System.Net.Mail.Attachment" /> class with the specified stream, name, and MIME type information. </summary>
|
|
/// <param name="contentStream">A readable <see cref="T:System.IO.Stream" /> that contains the content for this attachment.</param>
|
|
/// <param name="name">A <see cref="T:System.String" /> that contains the value for the <see cref="P:System.Net.Mime.ContentType.Name" /> property of the <see cref="T:System.Net.Mime.ContentType" /> associated with this attachment. This value can be null.</param>
|
|
/// <param name="mediaType">A <see cref="T:System.String" /> that contains the MIME Content-Header information for this attachment. This value can be null.</param>
|
|
/// <exception cref="T:System.ArgumentNullException">
|
|
/// <paramref name="stream" /> is null.</exception>
|
|
/// <exception cref="T:System.FormatException">
|
|
/// <paramref name="mediaType" /> is not in the correct format.</exception>
|
|
// Token: 0x06000A9A RID: 2714 RVA: 0x0001DD60 File Offset: 0x0001BF60
|
|
public Attachment(Stream contentStream, string name, string mediaType)
|
|
: base(contentStream, mediaType)
|
|
{
|
|
this.Name = name;
|
|
}
|
|
|
|
/// <summary>Gets the MIME content disposition for this attachment.</summary>
|
|
/// <returns>A <see cref="T:System.Net.Mime.ContentDisposition" /> that provides the presentation information for this attachment. </returns>
|
|
// Token: 0x170002AD RID: 685
|
|
// (get) Token: 0x06000A9B RID: 2715 RVA: 0x0001DD7C File Offset: 0x0001BF7C
|
|
public global::System.Net.Mime.ContentDisposition ContentDisposition
|
|
{
|
|
get
|
|
{
|
|
return this.contentDisposition;
|
|
}
|
|
}
|
|
|
|
/// <summary>Gets or sets the MIME content type name value in the content type associated with this attachment.</summary>
|
|
/// <returns>A <see cref="T:System.String" /> that contains the value for the content type <paramref name="name" /> represented by the <see cref="P:System.Net.Mime.ContentType.Name" /> property.</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 <see cref="F:System.String.Empty" /> ("").</exception>
|
|
// Token: 0x170002AE RID: 686
|
|
// (get) Token: 0x06000A9C RID: 2716 RVA: 0x0001DD84 File Offset: 0x0001BF84
|
|
// (set) Token: 0x06000A9D RID: 2717 RVA: 0x0001DD94 File Offset: 0x0001BF94
|
|
public string Name
|
|
{
|
|
get
|
|
{
|
|
return base.ContentType.Name;
|
|
}
|
|
set
|
|
{
|
|
base.ContentType.Name = value;
|
|
}
|
|
}
|
|
|
|
/// <summary>Specifies the encoding for the <see cref="T:System.Net.Mail.Attachment" /><see cref="P:System.Net.Mail.Attachment.Name" />.</summary>
|
|
/// <returns>An <see cref="T:System.Text.Encoding" /> value that specifies the type of name encoding. The default value is determined from the name of the attachment.</returns>
|
|
// Token: 0x170002AF RID: 687
|
|
// (get) Token: 0x06000A9E RID: 2718 RVA: 0x0001DDA4 File Offset: 0x0001BFA4
|
|
// (set) Token: 0x06000A9F RID: 2719 RVA: 0x0001DDAC File Offset: 0x0001BFAC
|
|
public Encoding NameEncoding
|
|
{
|
|
get
|
|
{
|
|
return this.nameEncoding;
|
|
}
|
|
set
|
|
{
|
|
this.nameEncoding = value;
|
|
}
|
|
}
|
|
|
|
/// <summary>Creates a mail attachment using the content from the specified string, and the specified <see cref="T:System.Net.Mime.ContentType" />.</summary>
|
|
/// <returns>An object of type <see cref="T:System.Net.Mail.Attachment" />.</returns>
|
|
/// <param name="content">A <see cref="T:System.String" /> that contains the content for this attachment.</param>
|
|
/// <param name="contentType">A <see cref="T:System.Net.Mime.ContentType" /> object that represents the Multipurpose Internet Mail Exchange (MIME) protocol Content-Type header to be used.</param>
|
|
// Token: 0x06000AA0 RID: 2720 RVA: 0x0001DDB8 File Offset: 0x0001BFB8
|
|
public static Attachment CreateAttachmentFromString(string content, global::System.Net.Mime.ContentType contentType)
|
|
{
|
|
if (content == null)
|
|
{
|
|
throw new ArgumentNullException("content");
|
|
}
|
|
MemoryStream memoryStream = new MemoryStream();
|
|
StreamWriter streamWriter = new StreamWriter(memoryStream);
|
|
streamWriter.Write(content);
|
|
streamWriter.Flush();
|
|
memoryStream.Position = 0L;
|
|
return new Attachment(memoryStream, contentType)
|
|
{
|
|
TransferEncoding = global::System.Net.Mime.TransferEncoding.QuotedPrintable
|
|
};
|
|
}
|
|
|
|
/// <summary>Creates a mail attachment using the content from the specified string, and the specified MIME content type name.</summary>
|
|
/// <returns>An object of type <see cref="T:System.Net.Mail.Attachment" />.</returns>
|
|
/// <param name="content">A <see cref="T:System.String" /> that contains the content for this attachment.</param>
|
|
/// <param name="name">The MIME content type name value in the content type associated with this attachment.</param>
|
|
// Token: 0x06000AA1 RID: 2721 RVA: 0x0001DE08 File Offset: 0x0001C008
|
|
public static Attachment CreateAttachmentFromString(string content, string name)
|
|
{
|
|
if (content == null)
|
|
{
|
|
throw new ArgumentNullException("content");
|
|
}
|
|
MemoryStream memoryStream = new MemoryStream();
|
|
StreamWriter streamWriter = new StreamWriter(memoryStream);
|
|
streamWriter.Write(content);
|
|
streamWriter.Flush();
|
|
memoryStream.Position = 0L;
|
|
return new Attachment(memoryStream, new global::System.Net.Mime.ContentType("text/plain"))
|
|
{
|
|
TransferEncoding = global::System.Net.Mime.TransferEncoding.QuotedPrintable,
|
|
Name = name
|
|
};
|
|
}
|
|
|
|
/// <summary>Creates a mail attachment using the content from the specified string, the specified MIME content type name, character encoding, and MIME header information for the attachment.</summary>
|
|
/// <returns>An object of type <see cref="T:System.Net.Mail.Attachment" />.</returns>
|
|
/// <param name="content">A <see cref="T:System.String" /> that contains the content for this attachment.</param>
|
|
/// <param name="name">The MIME content type name value in the content type associated with this attachment.</param>
|
|
/// <param name="contentEncoding">An <see cref="T:System.Text.Encoding" />. This value can be null.</param>
|
|
/// <param name="mediaType">A <see cref="T:System.String" /> that contains the MIME Content-Header information for this attachment. This value can be null.</param>
|
|
// Token: 0x06000AA2 RID: 2722 RVA: 0x0001DE68 File Offset: 0x0001C068
|
|
public static Attachment CreateAttachmentFromString(string content, string name, Encoding contentEncoding, string mediaType)
|
|
{
|
|
if (content == null)
|
|
{
|
|
throw new ArgumentNullException("content");
|
|
}
|
|
MemoryStream memoryStream = new MemoryStream();
|
|
StreamWriter streamWriter = new StreamWriter(memoryStream, contentEncoding);
|
|
streamWriter.Write(content);
|
|
streamWriter.Flush();
|
|
memoryStream.Position = 0L;
|
|
return new Attachment(memoryStream, name, mediaType)
|
|
{
|
|
TransferEncoding = global::System.Net.Mime.ContentType.GuessTransferEncoding(contentEncoding),
|
|
ContentType =
|
|
{
|
|
CharSet = streamWriter.Encoding.BodyName
|
|
}
|
|
};
|
|
}
|
|
|
|
// Token: 0x06000AA3 RID: 2723 RVA: 0x0001DED8 File Offset: 0x0001C0D8
|
|
private void InitName(string fileName)
|
|
{
|
|
if (fileName == null)
|
|
{
|
|
throw new ArgumentNullException("fileName");
|
|
}
|
|
this.Name = Path.GetFileName(fileName);
|
|
}
|
|
|
|
// Token: 0x04000AF9 RID: 2809
|
|
private global::System.Net.Mime.ContentDisposition contentDisposition = new global::System.Net.Mime.ContentDisposition();
|
|
|
|
// Token: 0x04000AFA RID: 2810
|
|
private Encoding nameEncoding;
|
|
}
|
|
}
|