Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wasm][net] System.Net.Mail should not throw PNSE for full assembly. #42974

Merged
merged 21 commits into from
Oct 9, 2020
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
ef38eb6
[wasm][net] System.Net.Mail should not throw PNSE for full assembly.
kjpou1 Oct 2, 2020
3ad3cf2
Address review comment. Remove comment line
kjpou1 Oct 2, 2020
0a256af
Address review comments. Remove redundant defs
kjpou1 Oct 2, 2020
e57bd98
Activate tests on CI
kjpou1 Oct 2, 2020
0d69fcb
Merge branch 'master' of https://github.com/dotnet/runtime into wasm-…
kjpou1 Oct 5, 2020
62999df
Add `[UnsupportedOSPlatform("browser")]` to SmtpClient
kjpou1 Oct 5, 2020
14e90dc
Add back System.Net.Mail Unit tests
kjpou1 Oct 5, 2020
74b6bbb
Remove redundant $(TargetsBrowser) from ItemGroup
kjpou1 Oct 5, 2020
2940c52
Merge branch 'master' of https://github.com/dotnet/runtime into wasm-…
kjpou1 Oct 6, 2020
34d4f77
Add `[UnsupportedOSPlatform("browser")]` to SmtpClient methods and pr…
kjpou1 Oct 6, 2020
df2ad24
Merge branch 'master' of https://github.com/dotnet/runtime into wasm-…
kjpou1 Oct 7, 2020
26df263
Remove unnecessary Unsupported attribute at the method level
kjpou1 Oct 7, 2020
528bf7d
Remove unnecessary Unsupported attribute at the method level
kjpou1 Oct 7, 2020
7e532db
Modify message on skipped test.
kjpou1 Oct 7, 2020
d90010f
Merge branch 'master' of https://github.com/dotnet/runtime into wasm-…
kjpou1 Oct 8, 2020
0e5d51f
Address review comments and remove string resource
kjpou1 Oct 8, 2020
aeff320
Remove redundant AssemblyInfo per review comment
kjpou1 Oct 8, 2020
0541b46
Merge branch 'master' of https://github.com/dotnet/runtime into wasm-…
kjpou1 Oct 9, 2020
ec6d9d8
Remove condition attribute
kjpou1 Oct 9, 2020
54d1068
Attribute is needed
kjpou1 Oct 9, 2020
87d1a61
Fix build issues
kjpou1 Oct 9, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/libraries/System.Net.Mail/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@
<PropertyGroup>
<StrongNameKeyId>Open</StrongNameKeyId>
<IncludePlatformAttributes>true</IncludePlatformAttributes>
<UnsupportedOSPlatforms>browser</UnsupportedOSPlatforms>
kjpou1 marked this conversation as resolved.
Show resolved Hide resolved
</PropertyGroup>
</Project>
</Project>
29 changes: 29 additions & 0 deletions src/libraries/System.Net.Mail/ref/System.Net.Mail.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,36 +165,65 @@ public enum MailPriority
High = 2,
}
public delegate void SendCompletedEventHandler(object sender, System.ComponentModel.AsyncCompletedEventArgs e);
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
kjpou1 marked this conversation as resolved.
Show resolved Hide resolved
public partial class SmtpClient : System.IDisposable
{
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
public SmtpClient() { }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
public SmtpClient(string? host) { }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
public SmtpClient(string? host, int port) { }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
public System.Security.Cryptography.X509Certificates.X509CertificateCollection ClientCertificates { get { throw null; } }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
public System.Net.ICredentialsByHost? Credentials { get { throw null; } set { } }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
public System.Net.Mail.SmtpDeliveryFormat DeliveryFormat { get { throw null; } set { } }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
public System.Net.Mail.SmtpDeliveryMethod DeliveryMethod { get { throw null; } set { } }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
public bool EnableSsl { get { throw null; } set { } }
[System.Diagnostics.CodeAnalysis.DisallowNullAttribute]
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
public string? Host { get { throw null; } set { } }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
public string? PickupDirectoryLocation { get { throw null; } set { } }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
public int Port { get { throw null; } set { } }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
public System.Net.ServicePoint ServicePoint { get { throw null; } }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
public string? TargetName { get { throw null; } set { } }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
public int Timeout { get { throw null; } set { } }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
public bool UseDefaultCredentials { get { throw null; } set { } }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
public event System.Net.Mail.SendCompletedEventHandler? SendCompleted { add { } remove { } }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
public void Dispose() { }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
protected virtual void Dispose(bool disposing) { }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
protected void OnSendCompleted(System.ComponentModel.AsyncCompletedEventArgs e) { }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
public void Send(System.Net.Mail.MailMessage message) { }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
public void Send(string from, string recipients, string? subject, string? body) { }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
public void SendAsync(System.Net.Mail.MailMessage message, object? userToken) { }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
public void SendAsync(string from, string recipients, string? subject, string? body, object? userToken) { }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
public void SendAsyncCancel() { }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
public System.Threading.Tasks.Task SendMailAsync(System.Net.Mail.MailMessage message) { throw null; }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
public System.Threading.Tasks.Task SendMailAsync(string from, string recipients, string? subject, string? body) { throw null; }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
public System.Threading.Tasks.Task SendMailAsync(System.Net.Mail.MailMessage message, System.Threading.CancellationToken cancellationToken) { throw null; }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
public System.Threading.Tasks.Task SendMailAsync(string from, string recipients, string? subject, string? body, System.Threading.CancellationToken cancellationToken) { throw null; }
}
public enum SmtpDeliveryFormat
Expand Down
68 changes: 37 additions & 31 deletions src/libraries/System.Net.Mail/src/System.Net.Mail.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<!-- DesignTimeBuild requires all the TargetFramework Derived Properties to not be present in the first property group. -->
<PropertyGroup>
<GeneratePlatformNotSupportedAssemblyMessage Condition="'$(TargetsBrowser)' == 'true'">SR.SystemNetMail_PlatformNotSupported</GeneratePlatformNotSupportedAssemblyMessage>
</PropertyGroup>
<ItemGroup Condition="'$(TargetsBrowser)' != 'true'">
<ItemGroup>
<Compile Include="System\Net\Base64Stream.cs" />
<Compile Include="System\Net\Mime\MimePart.cs" />
<Compile Include="System\Net\Mime\Base64WriteStateInfo.cs" />
Expand Down Expand Up @@ -43,42 +40,23 @@
<Compile Include="System\Net\Mail\Attachment.cs" />
<Compile Include="System\Net\Mail\AttachmentCollection.cs" />
<Compile Include="System\Net\BufferedReadStream.cs" />
<Compile Include="System\Net\Mail\ISmtpAuthenticationModule.cs" />
<Compile Include="System\Net\Mail\LinkedResource.cs" />
<Compile Include="System\Net\Mail\LinkedResourceCollection.cs" />
<Compile Include="System\Net\Mail\MailAddress.cs" />
<Compile Include="System\Net\Mail\MailAddressCollection.cs" />
<Compile Include="System\Net\Mail\NetEventSource.Mail.cs" />
<Compile Include="System\Net\Mail\MailMessage.cs" />
<Compile Include="System\Net\Mail\MailPriority.cs" />
<Compile Include="System\Net\Mail\MailWriter.cs" />
<Compile Include="System\Net\Mime\MimeMultiPart.cs" />
<Compile Include="System\Net\Mime\MimeMultiPartType.cs" />
<Compile Include="System\Net\Mime\MimeWriter.cs" />
<Compile Include="System\Net\Mail\SmtpAuthenticationManager.cs" />
<Compile Include="System\Net\Mail\SmtpClient.cs" />
<Compile Include="System\Net\Mail\SmtpCommands.cs" />
<Compile Include="System\Net\Mail\SmtpConnection.cs" />
<Compile Include="System\Net\Mail\SmtpConnection.Auth.cs" />
<Compile Include="System\Net\Mail\SmtpException.cs" />
<Compile Include="System\Net\Mail\SmtpFailedRecipientException.cs" />
<Compile Include="System\Net\Mail\SmtpFailedRecipientsException.cs" />
<Compile Include="System\Net\Mail\SmtpReplyReader.cs" />
<Compile Include="System\Net\Mail\SmtpReplyReaderFactory.cs" />
<Compile Include="System\Net\Mail\SmtpStatusCode.cs" />
<Compile Include="System\Net\Mail\SmtpTransport.cs" />
<Compile Include="System\Net\Mail\SmtpLoginAuthenticationModule.cs" />
<Compile Include="System\Net\Mail\SmtpNegotiateAuthenticationModule.cs" />
<Compile Include="System\Net\Mail\SmtpNtlmAuthenticationModule.cs" />
<Compile Include="System\Net\DelegatedStream.cs" />
<Compile Include="$(CommonPath)System\Net\TlsStream.cs"
Link="Common\System\Net\TlsStream.cs" />
<Compile Include="$(CommonPath)System\Net\InternalException.cs"
Link="Common\System\Net\InternalException.cs" />
<Compile Include="$(CommonPath)System\Net\LazyAsyncResult.cs"
Link="Common\System\Net\LazyAsyncResult.cs" />
<Compile Include="$(CommonPath)System\Net\ContextAwareResult.cs"
Link="Common\System\Net\ContextAwareResult.cs" />
<Compile Include="$(CommonPath)System\Net\Mail\MailBnfHelper.cs"
Link="Common\System\Net\Mail\MailBnfHelper.cs" />
<Compile Include="$(CommonPath)System\Net\Logging\NetEventSource.Common.cs"
Expand All @@ -95,16 +73,47 @@
Link="Common\System\Net\Mail\QuotedPairReader.cs" />
<Compile Include="$(CommonPath)System\Net\Mail\DomainLiteralReader.cs"
Link="Common\System\Net\Mail\DomainLiteralReader.cs" />
<Compile Include="$(CommonPath)System\Net\SecurityProtocol.cs"
Link="Common\System\Net\SecurityProtocol.cs" />
<Compile Include="$(CommonPath)System\StringExtensions.cs"
Link="Common\System\StringExtensions.cs" />
<Compile Include="$(CommonPath)System\HexConverter.cs"
Link="Common\System\HexConverter.cs" />
</ItemGroup>

<ItemGroup Condition="'$(TargetsBrowser)' == 'true'">
<Compile Include="System\Net\Mail\SmtpClient.Browser.cs" />
</ItemGroup>

<!-- Non Browser specific files - internal and security -->
<ItemGroup Condition="'$(TargetsBrowser)' != 'true'">
<Compile Include="System\Net\Mail\SmtpClient.cs" />
<Compile Include="System\Net\Mail\ISmtpAuthenticationModule.cs" />
<Compile Include="System\Net\Mail\SmtpAuthenticationManager.cs" />
<Compile Include="System\Net\Mail\SmtpCommands.cs" />
<Compile Include="System\Net\Mail\SmtpConnection.cs" />
<Compile Include="System\Net\Mail\SmtpConnection.Auth.cs" />
<Compile Include="System\Net\Mail\SmtpReplyReader.cs" />
<Compile Include="System\Net\Mail\SmtpReplyReaderFactory.cs" />
<Compile Include="System\Net\Mail\SmtpTransport.cs" />
<Compile Include="System\Net\Mail\SmtpLoginAuthenticationModule.cs" />
<Compile Include="System\Net\Mail\SmtpNegotiateAuthenticationModule.cs" />
<Compile Include="System\Net\Mail\SmtpNtlmAuthenticationModule.cs" />
<Compile Include="System\Net\Mail\NetEventSource.Mail.cs" />
<Compile Include="$(CommonPath)System\Net\ContextAwareResult.cs"
Link="Common\System\Net\ContextAwareResult.cs" />
<Compile Include="$(CommonPath)System\Net\NTAuthentication.Common.cs"
Link="Common\System\Net\NTAuthentication.Common.cs" />
<Compile Include="$(CommonPath)System\Net\Security\SSPIHandleCache.cs"
Link="Common\System\Net\Security\SSPIHandleCache.cs" />
<Compile Include="$(CommonPath)System\Net\DebugCriticalHandleMinusOneIsInvalid.cs"
Link="Common\System\Net\DebugCriticalHandleMinusOneIsInvalid.cs" />
<Compile Include="$(CommonPath)System\Net\DebugCriticalHandleZeroOrMinusOneIsInvalid.cs"
Link="Common\System\Net\DebugCriticalHandleZeroOrMinusOneIsInvalid.cs" />
<Compile Include="$(CommonPath)System\Net\DebugSafeHandle.cs"
Link="Common\System\Net\DebugSafeHandle.cs" />
<Compile Include="$(CommonPath)System\Net\TlsStream.cs"
Link="Common\System\Net\TlsStream.cs" />
<Compile Include="$(CommonPath)System\Net\InternalException.cs"
Link="Common\System\Net\InternalException.cs" />
<Compile Include="$(CommonPath)System\Net\ExceptionCheck.cs"
Link="Common\System\Net\ExceptionCheck.cs" />
<Compile Include="$(CommonPath)System\Collections\Generic\BidirectionalDictionary.cs"
Expand All @@ -115,19 +124,16 @@
Link="Common\System\Net\ContextFlagsPal.cs" />
<Compile Include="$(CommonPath)System\Net\NegotiationInfoClass.cs"
Link="Common\System\Net\NegotiationInfoClass.cs" />
<Compile Include="$(CommonPath)System\Net\NTAuthentication.Common.cs"
Link="Common\System\Net\NTAuthentication.Common.cs" />
<Compile Include="$(CommonPath)System\Net\SecurityStatusPal.cs"
Link="Common\System\Net\SecurityStatusPal.cs" />
<Compile Include="$(CommonPath)System\Net\Security\SSPIHandleCache.cs"
Link="Common\System\Net\Security\SSPIHandleCache.cs" />
<Compile Include="$(CommonPath)System\Net\Security\NetEventSource.Security.cs"
Link="Common\System\Net\Security\NetEventSource.Security.cs" />
<Compile Include="$(CommonPath)System\HexConverter.cs"
Link="Common\System\HexConverter.cs" />
<Compile Include="$(CommonPath)System\Net\SecurityProtocol.cs"
Link="Common\System\Net\SecurityProtocol.cs" />
<Compile Include="$(CommonPath)Interop\Windows\Interop.UNICODE_STRING.cs"
Link="Common\Interop\Windows\Interop.UNICODE_STRING.cs" />
</ItemGroup>

<!-- Unix specific files -->
<ItemGroup Condition="'$(TargetsUnix)' == 'true'">
<Compile Include="$(CommonPath)System\Net\ContextAwareResult.Unix.cs"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
// Licensed to the .NET Foundation under one or more agreements.
kjpou1 marked this conversation as resolved.
Show resolved Hide resolved
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.ComponentModel;
using System.Runtime.Versioning;
using System.Security.Cryptography.X509Certificates;
using System.Threading;
using System.Threading.Tasks;

namespace System.Net.Mail
{
public delegate void SendCompletedEventHandler(object sender, AsyncCompletedEventArgs e);

public enum SmtpDeliveryMethod
{
Network,
SpecifiedPickupDirectory,
PickupDirectoryFromIis
}

// EAI Settings
public enum SmtpDeliveryFormat
{
SevenBit = 0, // Legacy
International = 1, // SMTPUTF8 - Email Address Internationalization (EAI)
}

[UnsupportedOSPlatform("browser")]
public class SmtpClient : IDisposable
{
#pragma warning disable CS0067 // Field is not used
[UnsupportedOSPlatform("browser")]
public event SendCompletedEventHandler? SendCompleted;
#pragma warning restore CS0067
[UnsupportedOSPlatform("browser")]
public SmtpClient()
{
Initialize();
}

[UnsupportedOSPlatform("browser")]
public SmtpClient(string? host)
{
Initialize();
}

[UnsupportedOSPlatform("browser")]
public SmtpClient(string? host, int port)
{
Initialize();
}

private void Initialize()
{
throw new PlatformNotSupportedException();
}

[UnsupportedOSPlatform("browser")]
public string? Host
{
get => throw new PlatformNotSupportedException();
set => throw new PlatformNotSupportedException();
}

[UnsupportedOSPlatform("browser")]
public int Port
{
get => throw new PlatformNotSupportedException();
set => throw new PlatformNotSupportedException();
}

[UnsupportedOSPlatform("browser")]
public bool UseDefaultCredentials
{
get => throw new PlatformNotSupportedException();
set => throw new PlatformNotSupportedException();
}

[UnsupportedOSPlatform("browser")]
public ICredentialsByHost? Credentials
{
get => throw new PlatformNotSupportedException();
set => throw new PlatformNotSupportedException();
}

[UnsupportedOSPlatform("browser")]
public int Timeout
{
get => throw new PlatformNotSupportedException();
set => throw new PlatformNotSupportedException();
}

[UnsupportedOSPlatform("browser")]
public ServicePoint ServicePoint
{
get => throw new PlatformNotSupportedException();
}

[UnsupportedOSPlatform("browser")]
public SmtpDeliveryMethod DeliveryMethod
{
get => throw new PlatformNotSupportedException();
set => throw new PlatformNotSupportedException();
}

[UnsupportedOSPlatform("browser")]
public SmtpDeliveryFormat DeliveryFormat
{
get => throw new PlatformNotSupportedException();
set => throw new PlatformNotSupportedException();
}

[UnsupportedOSPlatform("browser")]
public string? PickupDirectoryLocation
{
get => throw new PlatformNotSupportedException();
set => throw new PlatformNotSupportedException();
}

/// <summary>
/// <para>Set to true if we need SSL</para>
/// </summary>
[UnsupportedOSPlatform("browser")]
public bool EnableSsl
{
get => throw new PlatformNotSupportedException();
set => throw new PlatformNotSupportedException();
}

/// <summary>
/// Certificates used by the client for establishing an SSL connection with the server.
/// </summary>
[UnsupportedOSPlatform("browser")]
public X509CertificateCollection ClientCertificates => throw new PlatformNotSupportedException();

[UnsupportedOSPlatform("browser")]
public string? TargetName
{
get => throw new PlatformNotSupportedException();
set => throw new PlatformNotSupportedException();
}

[UnsupportedOSPlatform("browser")]
private bool ServerSupportsEai => throw new PlatformNotSupportedException();

[UnsupportedOSPlatform("browser")]
public void Send(string from, string recipients, string? subject, string? body) => throw new PlatformNotSupportedException();

[UnsupportedOSPlatform("browser")]
public void Send(MailMessage message) => throw new PlatformNotSupportedException();

[UnsupportedOSPlatform("browser")]
public void SendAsync(string from, string recipients, string? subject, string? body, object? userToken) => throw new PlatformNotSupportedException();

[UnsupportedOSPlatform("browser")]
public void SendAsync(MailMessage message, object? userToken) => throw new PlatformNotSupportedException();

[UnsupportedOSPlatform("browser")]
public void SendAsyncCancel() => throw new PlatformNotSupportedException();

//************* Task-based async public methods *************************
[UnsupportedOSPlatform("browser")]
public Task SendMailAsync(string from, string recipients, string? subject, string? body) => throw new PlatformNotSupportedException();

[UnsupportedOSPlatform("browser")]
public Task SendMailAsync(MailMessage message) => throw new PlatformNotSupportedException();

[UnsupportedOSPlatform("browser")]
public Task SendMailAsync(string from, string recipients, string? subject, string? body, CancellationToken cancellationToken) => throw new PlatformNotSupportedException();

[UnsupportedOSPlatform("browser")]
public Task SendMailAsync(MailMessage message, CancellationToken cancellationToken) => throw new PlatformNotSupportedException();

[UnsupportedOSPlatform("browser")]
protected void OnSendCompleted(AsyncCompletedEventArgs e) => throw new PlatformNotSupportedException();

[UnsupportedOSPlatform("browser")]
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

[UnsupportedOSPlatform("browser")]
protected virtual void Dispose(bool disposing)
{ }
}
}
Loading