Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

@@ -0,0 +1,90 @@
2009-09-23 Zoltan Varga <vargaz@gmail.com>
* ContentType.cs: Fix the net 2.1 build.
2009-04-02 Atsushi Enomoto <atsushi@ximian.com>
* ContentType.cs : when there are especials, quote parameter values.
2008-08-14 Atsushi Enomoto <atsushi@ximian.com>
* ContentType.cs : patch by Ted Unangst, fixed bug #392843.
handle RFC2047 encoding.
2008-02-16 Atsushi Enomoto <atsushi@ximian.com>
* ContentType.cs : Reject such MediaType that lacks '/'.
Do not reject such parameters that are not standard ones.
2007-12-05 Atsushi Enomoto <atsushi@ximian.com>
* ContentType.cs : for SubjectEncoding, null is returned instead of
ASCII (.net compat way). For this cosmetic change, BodyEncoding is
changed to fill ASCII automatically.
2007-12-05 Atsushi Enomoto <atsushi@ximian.com>
* ContentType.cs : added GuessTransferEncoding() to guess correct
encoding type for sys.net.mail.Attachment.
Here UTF8Encoding should not include BOM.
2007-10-22 Atsushi Enomoto <atsushi@ximian.com>
* ContentType.cs : moved couple of encoding stuff to here.
Encode non-ASCII value in RFC 2047.
2007-09-28 Marek Habersack <mhabersack@novell.com>
* ContentDisposition.cs: if the file name contains spaces, enclose
it in quotes. Fixes bug #324084.
2006-01-13 John Luke <john.luke@gmail.com>
* ContentDisposition.cs: use String.Compare instead
of comparing .ToLower's
2006-01-02 John Luke <john.luke@gmail.com>
* ContentDisposition.cs: remove [MonoTODO]'s
access and store the properties in Parameters
ToString is now just DispositionType + the parameters
* ContentType.cs: remove [MonoTODO]'s
use parameters to store Name, Boundary, and CharSet
ToString is now just MediaType + the parameters
throw FormatException for unrecognized paremeter in ctor
* TransferEncoding.cs: remove [Serializable]
2005-12-26 John Luke <john.luke@gmail.com>
* ContentDisposition.cs: Size is -1 by default
throw ArgumentNullException and ArgumentException for
set_DispositionType
* ContentType.cs: throw ArgumentNullException, ArgumentException,
and FormatException for set_MediaType
don't print Boundary,Name in ToString() if they are ""
2005-12-23 John Luke <john.luke@gmail.com>
* ContentDisposition.cs: override GetHashCode and
Equals, implement ToString,
fix Size to be long not int,
implement Inline property,
implement the ctors
* ContentType.cs: override GetHashCode and Equals
implement ToString, implement the ctors
2005-12-22 John Luke <john.luke@gmail.com>
minor updates I noticed for 2.0 final API
* DispositionTypeNames.cs: change to a static class
* MediaTypeNames.cs: change these to static classes
* TransferEncoding.cs: remove Binary and EightBit
add [Serializable] and fix the values
2004-09-09 Tim Coleman <tim@timcoleman.com>
* ContentType.cs: Changes to MIME headers
2004-09-04 Tim Coleman <tim@timcoleman.com>
* ContentDisposition.cs ContentType.cs DispositionTypeNames.cs
* MediaTypeNames.cs TransferEncoding.cs:
New class stubs for 2.0

View File

@@ -0,0 +1,253 @@
//
// System.Net.Mime.ContentDisposition.cs
//
// Authors:
// Tim Coleman (tim@timcoleman.com)
// John Luke (john.luke@gmail.com)
//
// Copyright (C) Tim Coleman, 2004
// Copyright (C) John Luke, 2005
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Text;
using System.Collections;
using System.Collections.Specialized;
using System.Globalization;
namespace System.Net.Mime {
public class ContentDisposition
{
// FIXME: "r" was not enough, neither was zzz
// so this will fail if the offset is not an even hour
const string rfc822 = "dd MMM yyyy HH':'mm':'ss zz00";
#region Fields
string dispositionType;
StringDictionary parameters = new StringDictionary ();
#endregion // Fields
#region Constructors
public ContentDisposition () : this (DispositionTypeNames.Attachment)
{
}
public ContentDisposition (string disposition)
{
if (disposition == null)
throw new ArgumentNullException ();
if (disposition.Length < 1)
throw new FormatException ();
Size = -1;
try {
int index = disposition.IndexOf (';');
if (index < 0) {
dispositionType = disposition.Trim ();
}
else {
string[] split = disposition.Split (';');
dispositionType = split[0].Trim ();
for (int i = 1; i < split.Length; i++)
Parse (split[i]);
}
} catch {
throw new FormatException ();
}
}
// the individual pieces
void Parse (string pair)
{
if (pair == null || pair.Length < 0)
return;
string[] split = pair.Split ('=');
if (split.Length == 2)
parameters.Add (split[0].Trim (), split[1].Trim ());
else
throw new FormatException ();
}
#endregion // Constructors
#region Properties
public DateTime CreationDate {
get {
if (parameters.ContainsKey ("creation-date"))
return DateTime.ParseExact (parameters["creation-date"], rfc822, null);
else
return DateTime.MinValue;
}
set {
if (value > DateTime.MinValue)
parameters["creation-date"] = value.ToString (rfc822);
else
parameters.Remove ("modification-date");
}
}
public string DispositionType {
get { return dispositionType; }
set {
if (value == null)
throw new ArgumentNullException ();
if (value.Length < 1)
throw new ArgumentException ();
dispositionType = value;
}
}
public string FileName {
get { return parameters["filename"]; }
set { parameters["filename"] = value; }
}
public bool Inline {
get { return String.Compare (dispositionType, DispositionTypeNames.Inline, true, CultureInfo.InvariantCulture) == 0; }
set {
if (value)
dispositionType = DispositionTypeNames.Inline;
else
dispositionType = DispositionTypeNames.Attachment;
}
}
public DateTime ModificationDate {
get {
if (parameters.ContainsKey ("modification-date"))
return DateTime.ParseExact (parameters["modification-date"], rfc822, null);
else
return DateTime.MinValue;
}
set {
if (value > DateTime.MinValue)
parameters["modification-date"] = value.ToString (rfc822);
else
parameters.Remove ("modification-date");
}
}
public StringDictionary Parameters {
get { return parameters; }
}
public DateTime ReadDate {
get {
if (parameters.ContainsKey ("read-date"))
return DateTime.ParseExact (parameters["read-date"], rfc822, null);
else
return DateTime.MinValue;
}
set {
if (value > DateTime.MinValue)
parameters["read-date"] = value.ToString (rfc822);
else
parameters.Remove ("read-date");
}
}
public long Size {
get {
if (parameters.ContainsKey ("size"))
return long.Parse (parameters["size"]);
else
return -1;
}
set {
if (value > -1)
parameters["size"] = value.ToString ();
else
parameters.Remove ("size");
}
}
#endregion // Properties
#region Methods
public override bool Equals (object obj)
{
return Equals (obj as ContentDisposition);
}
bool Equals (ContentDisposition other)
{
return other != null && ToString () == other.ToString ();
}
public override int GetHashCode ()
{
return ToString ().GetHashCode ();
}
public override string ToString ()
{
// the content-disposition header as in RFC 2183
// ex. attachment; filename=genome.jpeg; modification-date="Wed, 12 Feb 1997 16:29:51 -0500";
// the dates must be quoted and in RFC 822 format
//
// According to RFC 2183, the filename field value follows the definition
// given in RFC 1521, which is
//
// value := token / quoted-string
//
StringBuilder sb = new StringBuilder ();
sb.Append (DispositionType.ToLower ());
if (Parameters != null && Parameters.Count > 0) {
bool quote = false;
string key, value;
foreach (DictionaryEntry pair in Parameters)
{
if (pair.Value != null && pair.Value.ToString ().Length > 0) {
sb.Append ("; ");
sb.Append (pair.Key);
sb.Append ("=");
key = pair.Key.ToString ();
value = pair.Value.ToString ();
if ((key == "filename" && value.IndexOf (' ') != -1) || key.EndsWith ("date"))
quote = true;
else
quote = false;
if (quote)
sb.Append ("\"");
sb.Append (value);
if (quote)
sb.Append ("\"");
}
}
}
return sb.ToString ();
}
#endregion // Methods
}
}

View File

@@ -0,0 +1,235 @@
//
// System.Net.Mime.ContentType.cs
//
// Authors:
// Tim Coleman (tim@timcoleman.com)
// John Luke (john.luke@gmail.com)
//
// Copyright (C) Tim Coleman, 2004
// Copyright (C) John Luke, 2005
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Collections;
using System.Collections.Specialized;
using System.Text;
namespace System.Net.Mime {
public class ContentType
{
#region Fields
static Encoding utf8unmarked;
string mediaType;
StringDictionary parameters = new StringDictionary ();
#endregion // Fields
#region Constructors
public ContentType ()
{
mediaType = "application/octet-stream";
}
public ContentType (string contentType)
{
if (contentType == null)
throw new ArgumentNullException ("contentType");
if (contentType.Length == 0)
throw new ArgumentException ("contentType");
string[] split = contentType.Split (';');
this.MediaType = split[0].Trim ();
for (int i = 1; i < split.Length; i++)
Parse (split[i].Trim ());
}
// parse key=value pairs like:
// "charset=us-ascii"
static char [] eq = new char [] { '=' };
void Parse (string pair)
{
if (String.IsNullOrEmpty (pair))
return;
string [] split = pair.Split (eq, 2);
string key = split [0].Trim ();
string val = (split.Length > 1) ? split [1].Trim () : "";
int l = val.Length;
if (l >= 2 && val [0] == '"' && val [l - 1] == '"')
val = val.Substring (1, l - 2);
parameters [key] = val;
}
#endregion // Constructors
#region Properties
static Encoding UTF8Unmarked {
get {
if (utf8unmarked == null)
utf8unmarked = new UTF8Encoding (false);
return utf8unmarked;
}
}
public string Boundary {
get { return parameters["boundary"]; }
set { parameters["boundary"] = value; }
}
public string CharSet {
get { return parameters["charset"]; }
set { parameters["charset"] = value; }
}
public string MediaType {
get { return mediaType; }
set {
if (value == null)
throw new ArgumentNullException ();
if (value.Length < 1)
throw new ArgumentException ();
if (value.IndexOf ('/') < 1)
throw new FormatException ();
if (value.IndexOf (';') != -1)
throw new FormatException ();
mediaType = value;
}
}
public string Name {
get { return parameters["name"]; }
set { parameters["name"] = value; }
}
public StringDictionary Parameters {
get { return parameters; }
}
#endregion // Properties
#region Methods
public override bool Equals (object obj)
{
return Equals (obj as ContentType);
}
bool Equals (ContentType other)
{
return other != null && ToString () == other.ToString ();
}
public override int GetHashCode ()
{
return ToString ().GetHashCode ();
}
public override string ToString ()
{
StringBuilder sb = new StringBuilder ();
Encoding enc = CharSet != null ? Encoding.GetEncoding (CharSet) : Encoding.UTF8;
sb.Append (MediaType);
if (Parameters != null && Parameters.Count > 0) {
foreach (DictionaryEntry pair in parameters)
{
if (pair.Value != null && pair.Value.ToString ().Length > 0) {
sb.Append ("; ");
sb.Append (pair.Key);
sb.Append ("=");
sb.Append (WrapIfEspecialsExist (EncodeSubjectRFC2047 (pair.Value as string, enc)));
}
}
}
return sb.ToString ();
}
// see RFC 2047
static readonly char [] especials = {'(', ')', '<', '>', '@', ',', ';', ':', '<', '>', '/', '[', ']', '?', '.', '='};
static string WrapIfEspecialsExist (string s)
{
s = s.Replace ("\"", "\\\"");
if (s.IndexOfAny (especials) >= 0)
return '"' + s + '"';
else
return s;
}
internal static Encoding GuessEncoding (string s)
{
for (int i = 0; i < s.Length; i++)
if (s [i] >= '\u0080')
return UTF8Unmarked;
return null;
}
internal static TransferEncoding GuessTransferEncoding (Encoding enc)
{
if (Encoding.ASCII.Equals (enc))
return TransferEncoding.SevenBit;
else if (Encoding.UTF8.CodePage == enc.CodePage ||
#if !NET_2_1
Encoding.Unicode.CodePage == enc.CodePage || Encoding.UTF32.CodePage == enc.CodePage
#else
Encoding.Unicode.CodePage == enc.CodePage
#endif
)
return TransferEncoding.Base64;
else
return TransferEncoding.QuotedPrintable;
}
static char [] hex = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
internal static string To2047(byte [] bytes)
{
StringBuilder sb = new StringBuilder ();
foreach (byte i in bytes) {
if (i < 0x21 || i > 0x7E || i == '?' || i == '=' || i == '_') {
sb.Append ('=');
sb.Append (hex [(i >> 4) & 0x0f]);
sb.Append (hex [i & 0x0f]);
} else
sb.Append ((char) i);
}
return sb.ToString ();
}
internal static string EncodeSubjectRFC2047 (string s, Encoding enc)
{
if (s == null || Encoding.ASCII.Equals (enc))
return s;
for (int i = 0; i < s.Length; i++)
if (s [i] >= '\u0080') {
string quoted = To2047(enc.GetBytes (s));
return String.Concat ("=?", enc.HeaderName, "?Q?", quoted, "?=");
}
return s;
}
#endregion // Methods
}
}

View File

@@ -0,0 +1,38 @@
//
// System.Net.Mime.DispositionTypeNames.cs
//
// Author:
// Tim Coleman (tim@timcoleman.com)
//
// Copyright (C) Tim Coleman, 2004
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace System.Net.Mime {
public static class DispositionTypeNames
{
public const string Attachment = "attachment";
public const string Inline = "inline";
}
}

View File

@@ -0,0 +1,56 @@
//
// System.Net.Mime.MediaTypeNames.cs
//
// Author:
// Tim Coleman (tim@timcoleman.com)
//
// Copyright (C) Tim Coleman, 2004
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace System.Net.Mime {
public static class MediaTypeNames
{
public static class Application {
const string prefix = "application/";
public const string Octet = prefix + "octet-stream";
public const string Pdf = prefix + "pdf";
public const string Rtf = prefix + "rtf";
public const string Soap = prefix + "soap+xml";
public const string Zip = prefix + "zip";
}
public static class Image {
const string prefix = "image/";
public const string Gif = prefix + "gif";
public const string Jpeg = prefix + "jpeg";
public const string Tiff = prefix + "tiff";
}
public static class Text {
const string prefix = "text/";
public const string Html = prefix + "html";
public const string Plain = prefix + "plain";
public const string RichText = prefix + "richtext";
public const string Xml = prefix + "xml";
}
}
}

View File

@@ -0,0 +1,40 @@
//
// System.Net.Mail.TransferEncoding.cs
//
// Author:
// Tim Coleman (tim@timcoleman.com)
//
// Copyright (C) Tim Coleman, 2004
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace System.Net.Mime {
public enum TransferEncoding
{
QuotedPrintable = 0,
Base64 = 1,
SevenBit = 2,
Unknown = -1
}
}