New test.
[mono.git] / mcs / class / System / System.Net.Mail / AttachmentBase.cs
1 //
2 // System.Net.Mail.AttachmentBase.cs
3 //
4 // Author:
5 //      John Luke (john.luke@gmail.com)
6 //
7 // Copyright (C) John Luke, 2005
8 //
9
10 //
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:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
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.
29 //
30
31 #if NET_2_0
32
33 using System.IO;
34 using System.Net.Mime;
35 using System.Text;
36
37 namespace System.Net.Mail {
38         public abstract class AttachmentBase : IDisposable
39         {
40                 #region Fields
41
42                 string id;
43                 ContentType contentType = new ContentType ();
44                 Stream contentStream;
45                 TransferEncoding transferEncoding;
46
47                 #endregion // Fields
48
49                 #region Constructors
50
51                 protected AttachmentBase (Stream contentStream)
52                 {
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;
59                 }
60
61                 protected AttachmentBase (Stream contentStream, ContentType contentType)
62                 {
63                         if (contentStream == null || contentType == null)
64                                 throw new ArgumentNullException ();
65                         this.contentStream = contentStream;
66                         this.contentType = contentType;
67                         transferEncoding = TransferEncoding.Base64;
68                 }
69
70                 protected AttachmentBase (Stream contentStream, string mediaType)
71                 {
72                         if (contentStream == null)
73                                 throw new ArgumentNullException ();
74                         this.contentStream = contentStream;
75                         contentType.MediaType = mediaType;
76                         transferEncoding = TransferEncoding.Base64;
77                 }
78
79                 protected AttachmentBase (string fileName)
80                 {
81                         if (fileName == null)
82                                 throw new ArgumentNullException ();
83                         contentStream = File.OpenRead (fileName);
84                         contentType.MediaType = MediaTypeNames.Application.Octet;
85                         contentType.CharSet = null;
86                         transferEncoding = TransferEncoding.Base64;
87                 }
88
89                 protected AttachmentBase (string fileName, ContentType contentType)
90                 {
91                         if (fileName == null)
92                                 throw new ArgumentNullException ();
93                         contentStream = File.OpenRead (fileName);
94                         this.contentType = contentType;
95                         transferEncoding = TransferEncoding.Base64;
96                 }
97
98                 protected AttachmentBase (string fileName, string mediaType)
99                 {
100                         if (fileName == null)
101                                 throw new ArgumentNullException ();
102                         contentStream = File.OpenRead (fileName);
103                         contentType.MediaType = mediaType;
104                         transferEncoding = TransferEncoding.Base64;
105                 }
106
107                 #endregion // Constructors
108
109                 #region Properties
110
111                 public string ContentId {
112                         get { return id; }
113                         set {
114                                 if (value == null)
115                                         throw new ArgumentNullException ();
116                                 id = value;
117                         }
118                 }
119
120                 public Stream ContentStream {
121                         get { return contentStream; }
122                 }
123
124                 public ContentType ContentType {
125                         get { return contentType; }
126                         set { contentType = value; }
127                 }
128
129                 public TransferEncoding TransferEncoding {
130                         get { return transferEncoding; }
131                         set { transferEncoding = value; }
132                 }
133
134                 #endregion // Properties
135
136                 #region Methods
137
138                 public void Dispose ()
139                 {
140                         Dispose (true);
141                         //GC.SuppressFinalize (this);
142                 }
143
144                 [MonoTODO]
145                 protected virtual void Dispose (bool disposing)
146                 {
147                 }
148
149                 #endregion // Methods
150         }
151 }
152
153 #endif // NET_2_0