2 // System.Net.Mail.AttachmentBase.cs
5 // John Luke (john.luke@gmail.com)
7 // Copyright (C) John Luke, 2005
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 using System.Net.Mime;
37 namespace System.Net.Mail {
38 public abstract class AttachmentBase : IDisposable
43 ContentType contentType = new ContentType ();
45 TransferEncoding transferEncoding;
51 protected AttachmentBase (Stream contentStream)
53 if (contentStream == null)
54 throw new ArgumentNullException ();
55 this.contentStream = contentStream;
56 contentType.MediaType = MediaTypeNames.Application.Octet;
57 contentType.CharSet = null;
58 transferEncoding = TransferEncoding.Base64;
61 protected AttachmentBase (Stream contentStream, ContentType contentType)
63 if (contentStream == null || contentType == null)
64 throw new ArgumentNullException ();
65 this.contentStream = contentStream;
66 this.contentType = contentType;
67 transferEncoding = TransferEncoding.Base64;
70 protected AttachmentBase (Stream contentStream, string mediaType)
72 if (contentStream == null)
73 throw new ArgumentNullException ();
74 this.contentStream = contentStream;
75 contentType.MediaType = mediaType;
76 transferEncoding = TransferEncoding.Base64;
79 protected AttachmentBase (string fileName)
82 throw new ArgumentNullException ();
83 contentStream = File.OpenRead (fileName);
84 contentType.MediaType = MediaTypeNames.Application.Octet;
85 contentType.CharSet = null;
86 transferEncoding = TransferEncoding.Base64;
89 protected AttachmentBase (string fileName, ContentType contentType)
92 throw new ArgumentNullException ();
93 contentStream = File.OpenRead (fileName);
94 this.contentType = contentType;
95 transferEncoding = TransferEncoding.Base64;
98 protected AttachmentBase (string fileName, string mediaType)
100 if (fileName == null)
101 throw new ArgumentNullException ();
102 contentStream = File.OpenRead (fileName);
103 contentType.MediaType = mediaType;
104 transferEncoding = TransferEncoding.Base64;
107 #endregion // Constructors
111 public string ContentId {
115 throw new ArgumentNullException ();
120 public Stream ContentStream {
121 get { return contentStream; }
124 public ContentType ContentType {
125 get { return contentType; }
126 set { contentType = value; }
129 public TransferEncoding TransferEncoding {
130 get { return transferEncoding; }
131 set { transferEncoding = value; }
134 #endregion // Properties
138 public void Dispose ()
141 //GC.SuppressFinalize (this);
145 protected virtual void Dispose (bool disposing)
149 #endregion // Methods