Imported Upstream version 4.3.2.467

Former-commit-id: 9c2cb47f45fa221e661ab616387c9cda183f283d
This commit is contained in:
Xamarin Public Jenkins
2016-02-22 11:00:01 -05:00
parent f302175246
commit f3e3aab35a
4097 changed files with 122406 additions and 82300 deletions

View File

@ -136,7 +136,7 @@ namespace System.Net.Mail {
sw.Flush ();
ms.Position = 0;
Attachment a = new Attachment (ms, name, mediaType);
a.TransferEncoding = ContentType.GuessTransferEncoding (contentEncoding);
a.TransferEncoding = MailMessage.GuessTransferEncoding (contentEncoding);
a.ContentType.CharSet = sw.Encoding.BodyName;
return a;
}

View File

@ -145,7 +145,7 @@ namespace System.Net.Mail {
}
internal TransferEncoding ContentTransferEncoding {
get { return ContentType.GuessTransferEncoding (BodyEncoding); }
get { return GuessTransferEncoding (BodyEncoding); }
}
public Encoding BodyEncoding {
@ -244,9 +244,63 @@ namespace System.Net.Mail {
private Encoding GuessEncoding (string s)
{
return ContentType.GuessEncoding (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;
}
static Encoding utf8unmarked;
static Encoding UTF8Unmarked {
get {
if (utf8unmarked == null)
utf8unmarked = new UTF8Encoding (false);
return utf8unmarked;
}
}
#endregion // Methods
}
}

View File

@ -29,15 +29,24 @@
//
#if SECURITY_DEP
#if MONOTOUCH || MONODROID
using System.Security.Cryptography.X509Certificates;
#else
#if MONO_SECURITY_ALIAS
extern alias MonoSecurity;
#endif
#if MONO_X509_ALIAS
extern alias PrebuiltSystem;
using X509CertificateCollection = PrebuiltSystem::System.Security.Cryptography.X509Certificates.X509CertificateCollection;
using System.Security.Cryptography.X509Certificates;
#endif
#if MONO_SECURITY_ALIAS
using MSI = MonoSecurity::Mono.Security.Interface;
#else
using MSI = Mono.Security.Interface;
#endif
#if MONO_X509_ALIAS
using X509CertificateCollection = PrebuiltSystem::System.Security.Cryptography.X509Certificates.X509CertificateCollection;
#else
using X509CertificateCollection = System.Security.Cryptography.X509Certificates.X509CertificateCollection;
#endif
using System.Security.Cryptography.X509Certificates;
#endif
using System;
@ -50,14 +59,15 @@ using System.Net.Mime;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Reflection;
using System.Net.Configuration;
using System.Configuration;
using System.Net.Security;
using System.Security.Authentication;
using System.Threading.Tasks;
using Mono.Net.Security;
namespace System.Net.Mail {
[Obsolete ("SmtpClient and its network of types are poorly designed, we strongly recommend you use https://github.com/jstedfast/MailKit and https://github.com/jstedfast/MimeKit instead")]
public class SmtpClient
: IDisposable
{
@ -275,7 +285,7 @@ namespace System.Net.Mail {
private static string EncodeAddress(MailAddress address)
{
if (!String.IsNullOrEmpty (address.DisplayName)) {
string encodedDisplayName = ContentType.EncodeSubjectRFC2047 (address.DisplayName, Encoding.UTF8);
string encodedDisplayName = MailMessage.EncodeSubjectRFC2047 (address.DisplayName, Encoding.UTF8);
return "\"" + encodedDisplayName + "\" <" + address.Address + ">";
}
return address.ToString ();
@ -297,7 +307,7 @@ namespace System.Net.Mail {
private string EncodeSubjectRFC2047 (MailMessage message)
{
return ContentType.EncodeSubjectRFC2047 (message.Subject, message.SubjectEncoding);
return MailMessage.EncodeSubjectRFC2047 (message.Subject, message.SubjectEncoding);
}
private string EncodeBody (MailMessage message)
@ -581,10 +591,21 @@ namespace System.Net.Mail {
// FIXME: parse the list of extensions so we don't bother wasting
// our time trying commands if they aren't supported.
status = SendCommand ("EHLO " + Dns.GetHostName ());
// get the host name (not fully qualified)
string fqdn = Dns.GetHostName ();
try {
// we'll try for the fully qualified name - ref: bug #33551
fqdn = Dns.GetHostEntry (fqdn).HostName;
}
catch (SocketException) {
// we could not resolve our name but will continue with the partial name
// IOW we won't fail to send email because of this - ref: bug #37246
}
status = SendCommand ("EHLO " + fqdn);
if (IsError (status)) {
status = SendCommand ("HELO " + Dns.GetHostName ());
status = SendCommand ("HELO " + fqdn);
if (IsError (status))
throw new SmtpException (status.StatusCode, status.Description);
@ -601,10 +622,10 @@ namespace System.Net.Mail {
ResetExtensions();
writer = new StreamWriter (stream);
reader = new StreamReader (stream);
status = SendCommand ("EHLO " + Dns.GetHostName ());
status = SendCommand ("EHLO " + fqdn);
if (IsError (status)) {
status = SendCommand ("HELO " + Dns.GetHostName ());
status = SendCommand ("HELO " + fqdn);
if (IsError (status))
throw new SmtpException (status.StatusCode, status.Description);
@ -697,7 +718,7 @@ namespace System.Net.Mail {
SendHeader ("Reply-To", EncodeAddresses (message.ReplyToList));
foreach (string s in message.Headers.AllKeys)
SendHeader (s, ContentType.EncodeSubjectRFC2047 (message.Headers [s], message.HeadersEncoding));
SendHeader (s, MailMessage.EncodeSubjectRFC2047 (message.Headers [s], message.HeadersEncoding));
AddPriorityHeader (message);
@ -742,7 +763,7 @@ namespace System.Net.Mail {
static void SendMailAsyncCompletedHandler (TaskCompletionSource<object> source, AsyncCompletedEventArgs e, SendCompletedEventHandler handler, SmtpClient client)
{
if ((object) handler != e.UserState)
if (source != e.UserState)
return;
client.SendCompleted -= handler;
@ -781,13 +802,8 @@ namespace System.Net.Mail {
CheckCancellation ();
if (escapeDots) {
int i;
for (i = 0; i < line.Length; i++) {
if (line[i] != '.')
break;
}
if (i > 0 && i == line.Length) {
line += ".";
if (line.Length > 0 && line[0] == '.') {
line = "." + line;
}
}
writer.Write (line);
@ -1139,21 +1155,6 @@ try {
return "unknown";
}
#if SECURITY_DEP
RemoteCertificateValidationCallback callback = delegate (object sender,
X509Certificate certificate,
X509Chain chain,
SslPolicyErrors sslPolicyErrors) {
// honor any exciting callback defined on ServicePointManager
if (ServicePointManager.ServerCertificateValidationCallback != null)
return ServicePointManager.ServerCertificateValidationCallback (sender, certificate, chain, sslPolicyErrors);
// otherwise provide our own
if (sslPolicyErrors != SslPolicyErrors.None)
throw new InvalidOperationException ("SSL authentication error: " + sslPolicyErrors);
return true;
};
#endif
private void InitiateSecureConnection () {
SmtpResponse response = SendCommand ("STARTTLS");
@ -1161,11 +1162,14 @@ try {
throw new SmtpException (SmtpStatusCode.GeneralFailure, "Server does not support secure connections.");
}
#if SECURITY_DEP
SslStream sslStream = new SslStream (stream, false, callback, null);
#if SECURITY_DEP
var tlsProvider = MonoTlsProviderFactory.GetProviderInternal ();
var settings = MSI.MonoTlsSettings.CopyDefaultSettings ();
settings.UseServicePointManagerCallback = true;
var sslStream = tlsProvider.CreateSslStream (stream, false, settings);
CheckCancellation ();
sslStream.AuthenticateAsClient (Host, this.ClientCertificates, SslProtocols.Default, false);
stream = sslStream;
stream = sslStream.AuthenticatedStream;
#else
throw new SystemException ("You are using an incomplete System.dll build");

View File

@ -0,0 +1,36 @@
//
// SmtpDeliveryFormat.cs:
//
// Authors:
// Marek Safar (marek.safar@gmail.com)
//
// (C) 2015 Xamarin, Inc. (http://www.xamarin.com)
//
// 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.Mail {
public enum SmtpDeliveryFormat
{
SevenBit = 0,
International = 1
}
}