Skip to content

Commit 11bff49

Browse files
Integrate partial source code of MailKit.
1 parent 5215731 commit 11bff49

25 files changed

+4481
-5
lines changed

Directory.Packages.props

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
<PackageVersion Include="Microsoft.EntityFrameworkCore.Relational" Version="9.0.11" />
1010
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.11" />
1111
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
12-
<PackageVersion Include="MimeKitLite" Version="4.14.0" />
1312
<PackageVersion Include="Moq" Version="4.20.72" />
1413
<PackageVersion Include="PosInformatique.FluentAssertions.Json" Version="1.6.0" />
1514
<PackageVersion Include="PosInformatique.Moq.Analyzers" Version="2.0.1-rc.2" />

src/EmailAddresses/EmailAddresses.csproj

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
$([System.IO.File]::ReadAllText("$(MSBuildProjectDirectory)/CHANGELOG.md"))
1313
</PackageReleaseNotes>
1414

15+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
1516
</PropertyGroup>
1617

1718
<ItemGroup>
@@ -23,8 +24,4 @@
2324
<Content Include="Icon.png" Pack="true" PackagePath="" />
2425
<Content Include="README.md" Pack="true" PackagePath="" />
2526
</ItemGroup>
26-
27-
<ItemGroup>
28-
<PackageReference Include="MimeKitLite" />
29-
</ItemGroup>
3027
</Project>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[*.cs]
2+
3+
# For MailKit source code, disable warnings.
4+
dotnet_analyzer_diagnostic.severity = none
5+
dotnet_diagnostic.CS1574.severity = none
6+
dotnet_diagnostic.CS1734.severity = none
7+
dotnet_diagnostic.CS8600.severity = none
8+
dotnet_diagnostic.CS8604.severity = none
9+
dotnet_diagnostic.CS8618.severity = none
10+
dotnet_diagnostic.CS8625.severity = none
11+
dotnet_diagnostic.IDE0005.severity = none
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
//
2+
// AddressParserFlags.cs
3+
//
4+
// Author: Jeffrey Stedfast <jestedfa@microsoft.com>
5+
//
6+
// Copyright (c) 2013-2025 .NET Foundation and Contributors
7+
//
8+
// Permission is hereby granted, free of charge, to any person obtaining a copy
9+
// of this software and associated documentation files (the "Software"), to deal
10+
// in the Software without restriction, including without limitation the rights
11+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
// copies of the Software, and to permit persons to whom the Software is
13+
// furnished to do so, subject to the following conditions:
14+
//
15+
// The above copyright notice and this permission notice shall be included in
16+
// all copies or substantial portions of the Software.
17+
//
18+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
// THE SOFTWARE.
25+
//
26+
27+
using System;
28+
29+
namespace MimeKit {
30+
[Flags]
31+
internal enum AddressParserFlags
32+
{
33+
AllowMailboxAddress = 1 << 0,
34+
AllowGroupAddress = 1 << 1,
35+
ThrowOnError = 1 << 2,
36+
Internal = 1 << 3,
37+
38+
TryParse = AllowMailboxAddress | AllowGroupAddress,
39+
InternalTryParse = TryParse | Internal,
40+
Parse = TryParse | ThrowOnError
41+
}
42+
}
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
//
2+
// DomainList.cs
3+
//
4+
// Author: Jeffrey Stedfast <jestedfa@microsoft.com>
5+
//
6+
// Copyright (c) 2013-2025 .NET Foundation and Contributors
7+
//
8+
// Permission is hereby granted, free of charge, to any person obtaining a copy
9+
// of this software and associated documentation files (the "Software"), to deal
10+
// in the Software without restriction, including without limitation the rights
11+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
// copies of the Software, and to permit persons to whom the Software is
13+
// furnished to do so, subject to the following conditions:
14+
//
15+
// The above copyright notice and this permission notice shall be included in
16+
// all copies or substantial portions of the Software.
17+
//
18+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
// THE SOFTWARE.
25+
//
26+
27+
using System;
28+
using System.Text;
29+
using System.Collections;
30+
using System.Globalization;
31+
using System.Collections.Generic;
32+
33+
using MimeKit.Utils;
34+
35+
namespace MimeKit {
36+
/// <summary>
37+
/// A domain list.
38+
/// </summary>
39+
/// <remarks>
40+
/// Represents a list of domains, such as those that an email was routed through.
41+
/// </remarks>
42+
internal class DomainList : IEnumerable<string>
43+
{
44+
readonly static byte[] DomainSentinels = new [] { (byte) ',', (byte) ':' };
45+
IList<string> domains;
46+
47+
/// <summary>
48+
/// Initialize a new instance of the <see cref="DomainList"/> class.
49+
/// </summary>
50+
/// <remarks>
51+
/// Creates a new <see cref="DomainList"/> based on the domains provided.
52+
/// </remarks>
53+
/// <param name="domains">A domain list.</param>
54+
/// <exception cref="System.ArgumentNullException">
55+
/// <paramref name="domains"/> is <see langword="null"/>.
56+
/// </exception>
57+
public DomainList (IEnumerable<string> domains)
58+
{
59+
if (domains is null)
60+
throw new ArgumentNullException (nameof (domains));
61+
62+
this.domains = new List<string> (domains);
63+
}
64+
65+
/// <summary>
66+
/// Initialize a new instance of the <see cref="DomainList"/> class.
67+
/// </summary>
68+
/// <remarks>
69+
/// Creates a new <see cref="DomainList"/>.
70+
/// </remarks>
71+
public DomainList ()
72+
{
73+
domains = Array.Empty<string> ();
74+
}
75+
76+
#region IEnumerable implementation
77+
78+
/// <summary>
79+
/// Get an enumerator for the list of domains.
80+
/// </summary>
81+
/// <remarks>
82+
/// Gets an enumerator for the list of domains.
83+
/// </remarks>
84+
/// <returns>The enumerator.</returns>
85+
public IEnumerator<string> GetEnumerator ()
86+
{
87+
return domains.GetEnumerator ();
88+
}
89+
90+
#endregion
91+
92+
#region IEnumerable implementation
93+
94+
/// <summary>
95+
/// Get an enumerator for the list of domains.
96+
/// </summary>
97+
/// <remarks>
98+
/// Gets an enumerator for the list of domains.
99+
/// </remarks>
100+
/// <returns>The enumerator.</returns>
101+
IEnumerator IEnumerable.GetEnumerator ()
102+
{
103+
return domains.GetEnumerator ();
104+
}
105+
106+
#endregion
107+
108+
/// <summary>
109+
/// Try to parse a list of domains.
110+
/// </summary>
111+
/// <remarks>
112+
/// Attempts to parse a <see cref="DomainList"/> from the text buffer starting at the
113+
/// specified index. The index will only be updated if a <see cref="DomainList"/> was
114+
/// successfully parsed.
115+
/// </remarks>
116+
/// <returns><see langword="true" /> if a <see cref="DomainList"/> was successfully parsed;
117+
/// otherwise, <see langword="false" />.</returns>
118+
/// <param name="buffer">The buffer to parse.</param>
119+
/// <param name="index">The index to start parsing.</param>
120+
/// <param name="endIndex">An index of the end of the input.</param>
121+
/// <param name="throwOnError">A flag indicating whether an
122+
/// exception should be thrown on error.</param>
123+
/// <param name="route">The parsed DomainList.</param>
124+
internal static bool TryParse (byte[] buffer, ref int index, int endIndex, bool throwOnError, out DomainList route)
125+
{
126+
var domains = new List<string> ();
127+
int startIndex = index;
128+
129+
route = null;
130+
131+
do {
132+
// skip over the '@'
133+
index++;
134+
135+
if (index >= endIndex) {
136+
if (throwOnError)
137+
throw new ParseException (string.Format (CultureInfo.InvariantCulture, "Incomplete domain-list at offset: {0}", startIndex), startIndex, index);
138+
139+
return false;
140+
}
141+
142+
if (!ParseUtils.TryParseDomain (buffer, ref index, endIndex, DomainSentinels, throwOnError, out var domain))
143+
return false;
144+
145+
domains.Add (domain);
146+
147+
// Note: obs-domain-list allows for null domains between commas
148+
do {
149+
if (!ParseUtils.SkipCommentsAndWhiteSpace (buffer, ref index, endIndex, throwOnError))
150+
return false;
151+
152+
if (index >= endIndex || buffer[index] != (byte) ',')
153+
break;
154+
155+
index++;
156+
} while (true);
157+
158+
if (!ParseUtils.SkipCommentsAndWhiteSpace (buffer, ref index, endIndex, throwOnError))
159+
return false;
160+
} while (index < buffer.Length && buffer[index] == (byte) '@');
161+
162+
route = new DomainList (domains);
163+
164+
return true;
165+
}
166+
}
167+
}

0 commit comments

Comments
 (0)