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 17 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>
1 change: 1 addition & 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,6 +165,7 @@ 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
{
public SmtpClient() { }
Expand Down
3 changes: 0 additions & 3 deletions src/libraries/System.Net.Mail/src/Resources/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,4 @@
<data name="SmtpGetIisPickupDirectoryNotSupported" xml:space="preserve">
<value>IIS delivery is not supported.</value>
</data>
<data name="SystemNetMail_PlatformNotSupported" xml:space="preserve">
<value>System.Net.Mail is not supported on this platform.</value>
</data>
</root>
70 changes: 38 additions & 32 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,22 @@
<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 +72,48 @@
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\MailWriter.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,160 @@
// 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
public event SendCompletedEventHandler? SendCompleted;
#pragma warning restore CS0067
public SmtpClient()
{
Initialize();
}

public SmtpClient(string? host)
{
Initialize();
}

public SmtpClient(string? host, int port)
{
Initialize();
}

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

public string? Host
{
get => throw new PlatformNotSupportedException();
set => throw new PlatformNotSupportedException();
}

public int Port
{
get => throw new PlatformNotSupportedException();
set => throw new PlatformNotSupportedException();
}

public bool UseDefaultCredentials
{
get => throw new PlatformNotSupportedException();
set => throw new PlatformNotSupportedException();
}

public ICredentialsByHost? Credentials
{
get => throw new PlatformNotSupportedException();
set => throw new PlatformNotSupportedException();
}

public int Timeout
{
get => throw new PlatformNotSupportedException();
set => throw new PlatformNotSupportedException();
}

public ServicePoint ServicePoint
{
get => throw new PlatformNotSupportedException();
}

public SmtpDeliveryMethod DeliveryMethod
{
get => throw new PlatformNotSupportedException();
set => throw new PlatformNotSupportedException();
}

public SmtpDeliveryFormat DeliveryFormat
{
get => throw new PlatformNotSupportedException();
set => throw new PlatformNotSupportedException();
}

public string? PickupDirectoryLocation
{
get => throw new PlatformNotSupportedException();
set => throw new PlatformNotSupportedException();
}

/// <summary>
/// <para>Set to true if we need SSL</para>
/// </summary>
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>
public X509CertificateCollection ClientCertificates => throw new PlatformNotSupportedException();

public string? TargetName
{
get => throw new PlatformNotSupportedException();
set => throw new PlatformNotSupportedException();
}

private bool ServerSupportsEai => throw new PlatformNotSupportedException();

public void Send(string from, string recipients, string? subject, string? body) => throw new PlatformNotSupportedException();

public void Send(MailMessage message) => throw new PlatformNotSupportedException();

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

public void SendAsync(MailMessage message, object? userToken) => throw new PlatformNotSupportedException();

public void SendAsyncCancel() => throw new PlatformNotSupportedException();

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

public Task SendMailAsync(MailMessage message) => throw new PlatformNotSupportedException();

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

public Task SendMailAsync(MailMessage message, CancellationToken cancellationToken) => throw new PlatformNotSupportedException();

protected void OnSendCompleted(AsyncCompletedEventArgs e) => throw new PlatformNotSupportedException();

public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

protected virtual void Dispose(bool disposing)
{ }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Globalization;
using System.IO;
using System.Net.NetworkInformation;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Authentication;
using System.Security.Cryptography.X509Certificates;
Expand All @@ -31,6 +32,7 @@ public enum SmtpDeliveryFormat
International = 1, // SMTPUTF8 - Email Address Internationalization (EAI)
}

[UnsupportedOSPlatform("browser")]
public class SmtpClient : IDisposable
{
private string? _host;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ namespace System.Net.Mail
public class SmtpFailedRecipientException : SmtpException, ISerializable
{
private readonly string? _failedRecipient;

#pragma warning disable CS0649 // Browser - never assigned to
internal bool fatal;
#pragma warning restore CS0649

public SmtpFailedRecipientException() : base() { }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@
using Xunit;

[assembly: ActiveIssue("https://github.com/dotnet/runtime/issues/34690", TestPlatforms.Windows, TargetFrameworkMonikers.Netcoreapp, TestRuntimes.Mono)]
[assembly: SkipOnMono("System.Net.Mail is not supported on wasm", TestPlatforms.Browser)]
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace System.Net.Mail.Tests
{
[PlatformSpecific(~TestPlatforms.Browser)] // SmtpClient is not supported on Browser
public class LoggingTest
{
[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ public void SubjectAndEncodingTest()
}

[Fact]
[PlatformSpecific(~TestPlatforms.Browser)] // Not passing as internal System.Net.Mail.MailWriter stripped from build
public void SentSpecialLengthMailAttachment_Base64Decode_Success()
{
// The special length follows pattern: (3N - 1) * 0x4400 + 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@

namespace System.Net.Mail.Functional.Tests
{
[PlatformSpecific(~TestPlatforms.Browser)] // SmtpClient is not supported on Browser
public class SmtpClientCredentialsTest
{
private readonly string UserName = "user";
private readonly string Password = Guid.NewGuid().ToString();
private readonly string Password = Guid.NewGuid().ToString();

[Fact]
public void Credentials_Unset_Null()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

namespace System.Net.Mail.Tests
{
[PlatformSpecific(~TestPlatforms.Browser)] // SmtpClient is not supported on Browser
public class SmtpClientTest : FileCleanupTestBase
{
private SmtpClient _smtp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
<PropertyGroup>
<IncludeRemoteExecutor>true</IncludeRemoteExecutor>
<TargetFrameworks>$(NetCoreAppCurrent)</TargetFrameworks>
<!-- Doesn't run tests on Browser since it is not supported. -->
<IgnoreForCI Condition="'$(TargetOS)' == 'Browser'">true</IgnoreForCI>
</PropertyGroup>
<ItemGroup>
<Compile Include="AlternateViewCollectionTest.cs" />
Expand Down Expand Up @@ -31,4 +29,4 @@
<Compile Include="$(CommonTestPath)System\Threading\Tasks\TaskTimeoutExtensions.cs"
Link="Common\System\Threading\Tasks\TaskTimeoutExtensions.cs" />
</ItemGroup>
</Project>
</Project>
Loading