diff --git a/MimeKit/Encodings/Base64Encoder.cs b/MimeKit/Encodings/Base64Encoder.cs index 78bbfea738..8c0ce6ffae 100644 --- a/MimeKit/Encodings/Base64Encoder.cs +++ b/MimeKit/Encodings/Base64Encoder.cs @@ -37,12 +37,7 @@ namespace MimeKit.Encodings { /// public class Base64Encoder : IMimeEncoder { - static ReadOnlySpan base64_alphabet => new byte[64] { - 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, - 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, - 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, - 0x77, 0x78, 0x79, 0x7A, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x2B, 0x2F - }; + static ReadOnlySpan base64_alphabet => "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"u8; readonly int quartetsPerLine; readonly bool rfc2047; diff --git a/MimeKit/Encodings/HexEncoder.cs b/MimeKit/Encodings/HexEncoder.cs index c3eb5bdb72..955bcb181a 100644 --- a/MimeKit/Encodings/HexEncoder.cs +++ b/MimeKit/Encodings/HexEncoder.cs @@ -38,10 +38,7 @@ namespace MimeKit.Encodings { /// public class HexEncoder : IMimeEncoder { - static ReadOnlySpan hex_alphabet => new byte[16] { - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, // '0' -> '7' - 0x38, 0x39, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, // '8' -> 'F' - }; + static ReadOnlySpan hex_alphabet => "0123456789ABCDEF"u8; /// /// Initialize a new instance of the class. diff --git a/MimeKit/Encodings/QEncoder.cs b/MimeKit/Encodings/QEncoder.cs index 2ce46518f2..e9e15dc0e1 100644 --- a/MimeKit/Encodings/QEncoder.cs +++ b/MimeKit/Encodings/QEncoder.cs @@ -58,10 +58,7 @@ public enum QEncodeMode : byte { /// public class QEncoder : IMimeEncoder { - static ReadOnlySpan hex_alphabet => new byte[16] { - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, // '0' -> '7' - 0x38, 0x39, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, // '8' -> 'F' - }; + static ReadOnlySpan hex_alphabet => "0123456789ABCDEF"u8; readonly CharType mask; diff --git a/MimeKit/Encodings/QuotedPrintableEncoder.cs b/MimeKit/Encodings/QuotedPrintableEncoder.cs index bb184f57e9..fbe3f2209f 100644 --- a/MimeKit/Encodings/QuotedPrintableEncoder.cs +++ b/MimeKit/Encodings/QuotedPrintableEncoder.cs @@ -39,10 +39,7 @@ namespace MimeKit.Encodings { /// public class QuotedPrintableEncoder : IMimeEncoder { - static ReadOnlySpan hex_alphabet => new byte[16] { - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, // '0' -> '7' - 0x38, 0x39, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, // '8' -> 'F' - }; + static ReadOnlySpan hex_alphabet => "0123456789ABCDEF"u8; readonly short tripletsPerLine; readonly short maxLineLength; diff --git a/MimeKit/Header.cs b/MimeKit/Header.cs index ac0c48db44..0c83c31713 100644 --- a/MimeKit/Header.cs +++ b/MimeKit/Header.cs @@ -964,7 +964,7 @@ static byte[] EncodeReferencesHeader (ParserOptions options, FormatOptions forma static bool IsWhiteSpace (char c) { - return c == ' ' || c == '\t' || c == '\r' || c == '\n'; + return c is ' ' or '\t' or '\r' or '\n'; } readonly struct Word @@ -1223,7 +1223,7 @@ static void AppendComment (FormatOptions format, Encoding encoding, ref ValueStr static bool IsMailingListCommandSpecial (char c) { - return c == '<' || c == '(' || c == ','; + return c is '<' or '(' or ','; } static byte[] EncodeMailingListCommandHeader (ParserOptions options, FormatOptions format, Encoding encoding, string field, string value) diff --git a/MimeKit/IO/Filters/ArmoredFromFilter.cs b/MimeKit/IO/Filters/ArmoredFromFilter.cs index 65c917dc3d..b6c776cc6e 100644 --- a/MimeKit/IO/Filters/ArmoredFromFilter.cs +++ b/MimeKit/IO/Filters/ArmoredFromFilter.cs @@ -41,7 +41,7 @@ namespace MimeKit.IO.Filters { /// public class ArmoredFromFilter : MimeFilterBase { - static readonly byte[] From = { (byte) 'F', (byte) 'r', (byte) 'o', (byte) 'm', (byte) ' ' }; + static ReadOnlySpan From => "From "u8; bool midline; diff --git a/MimeKit/IO/Filters/CharsetFilter.cs b/MimeKit/IO/Filters/CharsetFilter.cs index bc13909f62..a9ca036fa5 100644 --- a/MimeKit/IO/Filters/CharsetFilter.cs +++ b/MimeKit/IO/Filters/CharsetFilter.cs @@ -125,8 +125,8 @@ public CharsetFilter (Encoding sourceEncoding, Encoding targetEncoding) SourceEncoding = sourceEncoding; TargetEncoding = targetEncoding; - decoder = (Decoder) SourceEncoding.GetDecoder (); - encoder = (Encoder) TargetEncoding.GetEncoder (); + decoder = SourceEncoding.GetDecoder (); + encoder = TargetEncoding.GetEncoder (); } /// diff --git a/MimeKit/IO/Filters/MboxFromFilter.cs b/MimeKit/IO/Filters/MboxFromFilter.cs index 3f2ee6c4d7..cfcb97bae2 100644 --- a/MimeKit/IO/Filters/MboxFromFilter.cs +++ b/MimeKit/IO/Filters/MboxFromFilter.cs @@ -38,7 +38,7 @@ namespace MimeKit.IO.Filters { /// public class MboxFromFilter : MimeFilterBase { - static readonly byte[] From = { (byte) 'F', (byte) 'r', (byte) 'o', (byte) 'm', (byte) ' ' }; + static ReadOnlySpan From => "From "u8; bool midline; /// diff --git a/MimeKit/InternetAddress.cs b/MimeKit/InternetAddress.cs index 0230ef2499..3de89518ef 100644 --- a/MimeKit/InternetAddress.cs +++ b/MimeKit/InternetAddress.cs @@ -373,7 +373,7 @@ internal static bool TryParseLocalPart (byte[] text, ref int index, int endIndex return true; } - static ReadOnlySpan CommaGreaterThanOrSemiColon => new[] { (byte) ',', (byte) '>', (byte) ';' }; + static ReadOnlySpan CommaGreaterThanOrSemiColon => ",>;"u8; internal static bool TryParseAddrspec (byte[] text, ref int index, int endIndex, ReadOnlySpan sentinels, RfcComplianceMode compliance, bool throwOnError, out string addrspec, out int at) { diff --git a/MimeKit/MimeKit.csproj b/MimeKit/MimeKit.csproj index 6411d8763b..c444ab1531 100644 --- a/MimeKit/MimeKit.csproj +++ b/MimeKit/MimeKit.csproj @@ -4,7 +4,7 @@ An Open Source library for creating and parsing MIME, S/MIME, PGP messages on desktop and mobile platforms. MimeKit 4.3.0 - 10 + 12 Jeffrey Stedfast <_LegacyFrameworks>net462;net47 <_LegacyFrameworks Condition=" Exists('C:\Windows') ">$(_LegacyFrameworks);net48 diff --git a/MimeKit/MimeKitLite.csproj b/MimeKit/MimeKitLite.csproj index b50c250128..9b24b122c8 100644 --- a/MimeKit/MimeKitLite.csproj +++ b/MimeKit/MimeKitLite.csproj @@ -4,7 +4,7 @@ An Open Source library for creating and parsing MIME, S/MIME, PGP messages on desktop and mobile platforms. MimeKit Lite 4.3.0 - 10 + 12 Jeffrey Stedfast <_LegacyFrameworks>net462;net47 <_LegacyFrameworks Condition=" Exists('C:\Windows') ">$(_LegacyFrameworks);net48 diff --git a/MimeKit/MimeParser.cs b/MimeKit/MimeParser.cs index acbbcdb6ed..60ed8dffb4 100644 --- a/MimeKit/MimeParser.cs +++ b/MimeKit/MimeParser.cs @@ -48,7 +48,7 @@ enum BoundaryType class Boundary { - public static readonly byte[] MboxFrom = Encoding.ASCII.GetBytes ("From "); + public static readonly byte[] MboxFrom = "From "u8.ToArray(); public byte[] Marker { get; private set; } public int FinalLength { get { return Marker.Length; } } diff --git a/MimeKit/MimePart.cs b/MimeKit/MimePart.cs index 366985a347..52cb5af023 100644 --- a/MimeKit/MimePart.cs +++ b/MimeKit/MimePart.cs @@ -719,7 +719,7 @@ public override void WriteTo (FormatOptions options, Stream stream, bool content } if (ContentTransferEncoding == ContentEncoding.UUEncode) { - var buffer = Encoding.ASCII.GetBytes ("end"); + var buffer = "end"u8.ToArray (); if (cancellable != null) { cancellable.Write (buffer, 0, buffer.Length, cancellationToken); @@ -803,7 +803,7 @@ public override async Task WriteToAsync (FormatOptions options, Stream stream, b } if (ContentTransferEncoding == ContentEncoding.UUEncode) { - var buffer = Encoding.ASCII.GetBytes ("end"); + var buffer = "end"u8.ToArray(); await stream.WriteAsync (buffer, 0, buffer.Length, cancellationToken).ConfigureAwait (false); await stream.WriteAsync (options.NewLineBytes, 0, options.NewLineBytes.Length, cancellationToken).ConfigureAwait (false); diff --git a/MimeKit/Tnef/TnefPropertyReader.cs b/MimeKit/Tnef/TnefPropertyReader.cs index 0c72bfb63f..53cc056f13 100644 --- a/MimeKit/Tnef/TnefPropertyReader.cs +++ b/MimeKit/Tnef/TnefPropertyReader.cs @@ -747,13 +747,13 @@ public int ReadTextValue (char[] buffer, int offset, int count) switch (propertyTag.ValueTnefType) { case TnefPropertyType.Unicode: ReadInt32 (); - decoder = (Decoder) Encoding.Unicode.GetDecoder (); + decoder = Encoding.Unicode.GetDecoder (); break; case TnefPropertyType.String8: case TnefPropertyType.Binary: case TnefPropertyType.Object: ReadInt32 (); - decoder = (Decoder) GetMessageEncoding ().GetDecoder (); + decoder = GetMessageEncoding ().GetDecoder (); break; } } diff --git a/MimeKit/Utils/CharsetUtils.cs b/MimeKit/Utils/CharsetUtils.cs index 5058062c46..54f4de97ec 100644 --- a/MimeKit/Utils/CharsetUtils.cs +++ b/MimeKit/Utils/CharsetUtils.cs @@ -489,7 +489,7 @@ internal static char[] ConvertToUnicode (ParserOptions options, byte[] input, in for (int i = 0; i < codepages.Length; i++) { encoding = Encoding.GetEncoding (codepages[i], new EncoderReplacementFallback ("?"), invalid); - decoder = (Decoder) encoding.GetDecoder (); + decoder = encoding.GetDecoder (); count = decoder.GetCharCount (input, startIndex, length, true); if (invalid.InvalidByteCount < min) { @@ -505,7 +505,7 @@ internal static char[] ConvertToUnicode (ParserOptions options, byte[] input, in } encoding = GetEncoding (best, "?"); - decoder = (Decoder) encoding.GetDecoder (); + decoder = encoding.GetDecoder (); var output = new char[bestCharCount]; diff --git a/MimeKit/Utils/ParseUtils.cs b/MimeKit/Utils/ParseUtils.cs index f5c7f98e83..f7f76b8412 100644 --- a/MimeKit/Utils/ParseUtils.cs +++ b/MimeKit/Utils/ParseUtils.cs @@ -390,7 +390,7 @@ public static bool TryParseDomain (byte[] text, ref int index, int endIndex, Rea return TryParseDotAtom (text, ref index, endIndex, sentinels, throwOnError, "domain", out domain); } - static ReadOnlySpan GreaterThanOrAt => new[] { (byte) '>', (byte) '@' }; + static ReadOnlySpan GreaterThanOrAt => ">@"u8; public static bool TryParseMsgId (byte[] text, ref int index, int endIndex, bool requireAngleAddr, bool throwOnError, out string msgid) {