Skip to content

Commit

Permalink
[release/5.0] [wasm][net] System.Net.Mail should not throw PNSE for f…
Browse files Browse the repository at this point in the history
…ull assembly. (#43213)

Co-authored-by: Kenneth Pouncey <kjpou@pt.lu>
  • Loading branch information
github-actions[bot] and kjpou1 authored Oct 13, 2020
1 parent b928f03 commit d90f149
Show file tree
Hide file tree
Showing 16 changed files with 233 additions and 66 deletions.
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>
</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")]
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.
// 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

0 comments on commit d90f149

Please sign in to comment.