Merge pull request #260 from pcc/topmost
[mono.git] / mcs / class / System / System.Net.Mail / LinkedResource.cs
1 //
2 // System.Net.Mail.LinkedResource.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
32 using System.IO;
33 using System.Net.Mime;
34 using System.Text;
35
36 namespace System.Net.Mail {
37         public class LinkedResource : AttachmentBase
38         {
39                 #region Fields
40                 
41                 Uri contentLink;
42
43                 #endregion // Fields
44
45                 #region Constructors
46
47                 public LinkedResource (string fileName) : base (fileName)
48                 {
49                         if (fileName == null)
50                                 throw new ArgumentNullException ();
51                 }
52                 
53                 public LinkedResource (string fileName, ContentType contentType) : base (fileName, contentType)
54                 {
55                         if (fileName == null)
56                                 throw new ArgumentNullException ();
57                 }
58                 
59                 public LinkedResource (string fileName, string mediaType) : base (fileName, mediaType)
60                 {
61                         if (fileName == null)
62                                 throw new ArgumentNullException ();
63                 }
64
65                 public LinkedResource (Stream contentStream) : base (contentStream)
66                 {
67                         if (contentStream == null)
68                                 throw new ArgumentNullException ();
69                 }
70                 
71                 public LinkedResource (Stream contentStream, ContentType contentType) : base (contentStream, contentType)
72                 {
73                         if (contentStream == null)
74                                 throw new ArgumentNullException ();
75                 }
76                 
77                 public LinkedResource (Stream contentStream, string mediaType) : base (contentStream, mediaType)
78                 {
79                         if (contentStream == null)
80                                 throw new ArgumentNullException ();
81                 }
82
83                 #endregion // Constructors
84
85                 #region Properties
86
87                 public Uri ContentLink {
88                         get { return contentLink; }
89                         set { contentLink = value; }
90                 }
91
92                 #endregion // Properties
93
94                 #region Methods
95
96                 public static LinkedResource CreateLinkedResourceFromString (string content)
97                 {
98                         if (content == null)
99                                 throw new ArgumentNullException ();
100                         MemoryStream ms = new MemoryStream (Encoding.Default.GetBytes (content));
101                         LinkedResource lr = new LinkedResource (ms);
102                         lr.TransferEncoding = TransferEncoding.QuotedPrintable;
103                         return lr;
104                 }
105                 
106                 public static LinkedResource CreateLinkedResourceFromString (string content, ContentType contentType)
107                 {
108                         if (content == null)
109                                 throw new ArgumentNullException ();
110                         MemoryStream ms = new MemoryStream (Encoding.Default.GetBytes (content));
111                         LinkedResource lr = new LinkedResource (ms, contentType);
112                         lr.TransferEncoding = TransferEncoding.QuotedPrintable;
113                         return lr;
114                 }
115                 
116                 public static LinkedResource CreateLinkedResourceFromString (string content, Encoding contentEncoding, string mediaType)
117                 {
118                         if (content == null)
119                                 throw new ArgumentNullException ();
120                         MemoryStream ms = new MemoryStream (contentEncoding.GetBytes (content));
121                         LinkedResource lr = new LinkedResource (ms, mediaType);
122                         lr.TransferEncoding = TransferEncoding.QuotedPrintable;
123                         return lr;
124                 }
125
126                 #endregion // Methods
127         }
128 }
129