Skip to content

Commit

Permalink
Get rid of the internal FormatOptions.CloneDefault() method
Browse files Browse the repository at this point in the history
I don't think we need this, and if it turns out we do,
this isn't a great way of doing it.
  • Loading branch information
jstedfast committed Feb 3, 2024
1 parent b0d742d commit d982a8a
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 32 deletions.
18 changes: 9 additions & 9 deletions MimeKit/Cryptography/ApplicationPkcs7Mime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ static async Task<ApplicationPkcs7Mime> CompressAsync (SecureMimeContext ctx, Mi
throw new ArgumentNullException (nameof (entity));

using (var memory = new MemoryBlockStream ()) {
var options = FormatOptions.CloneDefault ();
var options = FormatOptions.Default.Clone ();
options.NewLineFormat = NewLineFormat.Dos;

if (doAsync)
Expand Down Expand Up @@ -805,7 +805,7 @@ public static ApplicationPkcs7Mime Encrypt (SecureMimeContext ctx, CmsRecipientC
throw new ArgumentNullException (nameof (entity));

using (var memory = new MemoryBlockStream ()) {
var options = FormatOptions.CloneDefault ();
var options = FormatOptions.Default.Clone ();
options.NewLineFormat = NewLineFormat.Dos;

entity.WriteTo (options, memory, cancellationToken);
Expand Down Expand Up @@ -854,7 +854,7 @@ public static async Task<ApplicationPkcs7Mime> EncryptAsync (SecureMimeContext c
throw new ArgumentNullException (nameof (entity));

using (var memory = new MemoryBlockStream ()) {
var options = FormatOptions.CloneDefault ();
var options = FormatOptions.Default.Clone ();
options.NewLineFormat = NewLineFormat.Dos;

await entity.WriteToAsync (options, memory, cancellationToken).ConfigureAwait (false);
Expand Down Expand Up @@ -981,7 +981,7 @@ public static ApplicationPkcs7Mime Encrypt (SecureMimeContext ctx, IEnumerable<M
throw new ArgumentNullException (nameof (entity));

using (var memory = new MemoryBlockStream ()) {
var options = FormatOptions.CloneDefault ();
var options = FormatOptions.Default.Clone ();
options.NewLineFormat = NewLineFormat.Dos;

entity.WriteTo (options, memory, cancellationToken);
Expand Down Expand Up @@ -1036,7 +1036,7 @@ public static async Task<ApplicationPkcs7Mime> EncryptAsync (SecureMimeContext c
throw new ArgumentNullException (nameof (entity));

using (var memory = new MemoryBlockStream ()) {
var options = FormatOptions.CloneDefault ();
var options = FormatOptions.Default.Clone ();
options.NewLineFormat = NewLineFormat.Dos;

await entity.WriteToAsync (options, memory, cancellationToken).ConfigureAwait (false);
Expand Down Expand Up @@ -1173,7 +1173,7 @@ public static ApplicationPkcs7Mime Sign (SecureMimeContext ctx, CmsSigner signer
throw new ArgumentNullException (nameof (entity));

using (var memory = new MemoryBlockStream ()) {
var options = FormatOptions.CloneDefault ();
var options = FormatOptions.Default.Clone ();
options.NewLineFormat = NewLineFormat.Dos;

entity.WriteTo (options, memory, cancellationToken);
Expand Down Expand Up @@ -1226,7 +1226,7 @@ public static async Task<ApplicationPkcs7Mime> SignAsync (SecureMimeContext ctx,
throw new ArgumentNullException (nameof (entity));

using (var memory = new MemoryBlockStream ()) {
var options = FormatOptions.CloneDefault ();
var options = FormatOptions.Default.Clone ();
options.NewLineFormat = NewLineFormat.Dos;

await entity.WriteToAsync (options, memory, cancellationToken).ConfigureAwait (false);
Expand Down Expand Up @@ -1363,7 +1363,7 @@ public static ApplicationPkcs7Mime Sign (SecureMimeContext ctx, MailboxAddress s
throw new ArgumentNullException (nameof (entity));

using (var memory = new MemoryBlockStream ()) {
var options = FormatOptions.CloneDefault ();
var options = FormatOptions.Default.Clone ();
options.NewLineFormat = NewLineFormat.Dos;

entity.WriteTo (options, memory, cancellationToken);
Expand Down Expand Up @@ -1420,7 +1420,7 @@ public static async Task<ApplicationPkcs7Mime> SignAsync (SecureMimeContext ctx,
throw new ArgumentNullException (nameof (entity));

using (var memory = new MemoryBlockStream ()) {
var options = FormatOptions.CloneDefault ();
var options = FormatOptions.Default.Clone ();
options.NewLineFormat = NewLineFormat.Dos;

await entity.WriteToAsync (options, memory, cancellationToken).ConfigureAwait (false);
Expand Down
8 changes: 4 additions & 4 deletions MimeKit/Cryptography/MultipartEncrypted.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ static async Task<MultipartEncrypted> SignAndEncryptAsync (OpenPgpContext ctx, M
throw new ArgumentNullException (nameof (entity));

using (var memory = new MemoryBlockStream ()) {
var options = FormatOptions.CloneDefault ();
var options = FormatOptions.Default.Clone ();
options.NewLineFormat = NewLineFormat.Dos;

if (doAsync)
Expand Down Expand Up @@ -277,7 +277,7 @@ static async Task<MultipartEncrypted> SignAndEncryptAsync (OpenPgpContext ctx, M
throw new ArgumentNullException (nameof (entity));

using (var memory = new MemoryBlockStream ()) {
var options = FormatOptions.CloneDefault ();
var options = FormatOptions.Default.Clone ();
options.NewLineFormat = NewLineFormat.Dos;

if (doAsync)
Expand Down Expand Up @@ -642,7 +642,7 @@ static async Task<MultipartEncrypted> SignAndEncryptAsync (OpenPgpContext ctx, P
throw new ArgumentNullException (nameof (entity));

using (var memory = new MemoryBlockStream ()) {
var options = FormatOptions.CloneDefault ();
var options = FormatOptions.Default.Clone ();
options.NewLineFormat = NewLineFormat.Dos;

if (doAsync)
Expand Down Expand Up @@ -789,7 +789,7 @@ static async Task<MultipartEncrypted> SignAndEncryptAsync (OpenPgpContext ctx, P
throw new ArgumentNullException (nameof (entity));

using (var memory = new MemoryBlockStream ()) {
var options = FormatOptions.CloneDefault ();
var options = FormatOptions.Default.Clone ();
options.NewLineFormat = NewLineFormat.Dos;

if (doAsync)
Expand Down
4 changes: 2 additions & 2 deletions MimeKit/Cryptography/MultipartSigned.cs
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ public DigitalSignatureCollection Verify (CryptographyContext ctx, CancellationT

using (var cleartext = new MemoryBlockStream ()) {
// Note: see rfc2015 or rfc3156, section 5.1
var options = FormatOptions.CloneDefault ();
var options = FormatOptions.Default.Clone ();
options.NewLineFormat = NewLineFormat.Dos;
options.VerifyingSignature = true;

Expand Down Expand Up @@ -834,7 +834,7 @@ public async Task<DigitalSignatureCollection> VerifyAsync (CryptographyContext c

using (var cleartext = new MemoryBlockStream ()) {
// Note: see rfc2015 or rfc3156, section 5.1
var options = FormatOptions.CloneDefault ();
var options = FormatOptions.Default.Clone ();
options.NewLineFormat = NewLineFormat.Dos;
options.VerifyingSignature = true;

Expand Down
14 changes: 0 additions & 14 deletions MimeKit/FormatOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -331,19 +331,5 @@ public FormatOptions Clone ()
international = international
};
}

/// <summary>
/// Get the default formatting options in a thread-safe way.
/// </summary>
/// <remarks>
/// Gets the default formatting options in a thread-safe way.
/// </remarks>
/// <returns>The default formatting options.</returns>
internal static FormatOptions CloneDefault ()
{
lock (Default) {
return Default.Clone ();
}
}
}
}
2 changes: 1 addition & 1 deletion MimeKit/MessagePartial.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ public static IEnumerable<MimeMessage> Split (MimeMessage message, int maxSize)
if (maxSize < 1)
throw new ArgumentOutOfRangeException (nameof (maxSize));

var options = FormatOptions.CloneDefault ();
var options = FormatOptions.Default.Clone ();
foreach (HeaderId id in Enum.GetValues (typeof (HeaderId))) {
switch (id) {
case HeaderId.Subject:
Expand Down
4 changes: 2 additions & 2 deletions MimeKit/MimeEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1807,7 +1807,7 @@ public static MimeEntity Load (ParserOptions options, ContentType contentType, S
if (content is null)
throw new ArgumentNullException (nameof (content));

var format = FormatOptions.CloneDefault ();
var format = FormatOptions.Default.Clone ();
format.NewLineFormat = NewLineFormat.Dos;

var encoded = contentType.Encode (format, Encoding.UTF8);
Expand Down Expand Up @@ -1860,7 +1860,7 @@ public static async Task<MimeEntity> LoadAsync (ParserOptions options, ContentTy
if (content is null)
throw new ArgumentNullException (nameof (content));

var format = FormatOptions.CloneDefault ();
var format = FormatOptions.Default.Clone ();
format.NewLineFormat = NewLineFormat.Dos;

var encoded = contentType.Encode (format, Encoding.UTF8);
Expand Down

0 comments on commit d982a8a

Please sign in to comment.