Skip to content

Commit 4b77a9f

Browse files
committed
Allow changing the FormatOptions.Default values
Fixes issue #993
1 parent 6e9322c commit 4b77a9f

File tree

2 files changed

+4
-57
lines changed

2 files changed

+4
-57
lines changed

MimeKit/FormatOptions.cs

Lines changed: 4 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,9 @@ public class FormatOptions
106106
/// <exception cref="ArgumentOutOfRangeException">
107107
/// <paramref name="value"/> is out of range. It must be between 60 and 998.
108108
/// </exception>
109-
/// <exception cref="System.InvalidOperationException">
110-
/// <see cref="Default"/> cannot be changed.
111-
/// </exception>
112109
public int MaxLineLength {
113110
get { return maxLineLength; }
114111
set {
115-
if (this == Default)
116-
throw new InvalidOperationException ("The default formatting options cannot be changed.");
117-
118112
if (value < MinimumLineLength || value > MaximumLineLength)
119113
throw new ArgumentOutOfRangeException (nameof (value));
120114

@@ -133,15 +127,9 @@ public int MaxLineLength {
133127
/// <exception cref="System.ArgumentOutOfRangeException">
134128
/// <paramref name="value"> is not a valid <see cref="NewLineFormat"/>.</paramref>
135129
/// </exception>
136-
/// <exception cref="System.InvalidOperationException">
137-
/// <see cref="Default"/> cannot be changed.
138-
/// </exception>
139130
public NewLineFormat NewLineFormat {
140131
get { return newLineFormat; }
141132
set {
142-
if (this == Default)
143-
throw new InvalidOperationException ("The default formatting options cannot be changed.");
144-
145133
switch (newLineFormat) {
146134
case NewLineFormat.Unix:
147135
case NewLineFormat.Dos:
@@ -165,17 +153,9 @@ public NewLineFormat NewLineFormat {
165153
/// that writing the message back to a stream will always end with a new-line sequence.</para>
166154
/// </remarks>
167155
/// <value><c>true</c> in order to ensure that the message will end with a new-line sequence; otherwise, <c>false</c>.</value>
168-
/// <exception cref="System.InvalidOperationException">
169-
/// <see cref="Default"/> cannot be changed.
170-
/// </exception>
171156
public bool EnsureNewLine {
172157
get { return ensureNewLine; }
173-
set {
174-
if (this == Default)
175-
throw new InvalidOperationException ("The default formatting options cannot be changed.");
176-
177-
ensureNewLine = value;
178-
}
158+
set { ensureNewLine = value; }
179159
}
180160

181161
internal IMimeFilter CreateNewLineFilter (bool ensureNewLine = false)
@@ -229,17 +209,9 @@ public HashSet<HeaderId> HiddenHeaders {
229209
/// (<a href="https://tools.ietf.org/html/rfc6855">rfc6855</a>).</para>
230210
/// </remarks>
231211
/// <value><c>true</c> if the new internationalized formatting should be used; otherwise, <c>false</c>.</value>
232-
/// <exception cref="System.InvalidOperationException">
233-
/// <see cref="Default"/> cannot be changed.
234-
/// </exception>
235212
public bool International {
236213
get { return international; }
237-
set {
238-
if (this == Default)
239-
throw new InvalidOperationException ("The default formatting options cannot be changed.");
240-
241-
international = value;
242-
}
214+
set { international = value; }
243215
}
244216

245217
/// <summary>
@@ -260,12 +232,7 @@ public bool International {
260232
/// <value><c>true</c> if the formatter should be allowed to use us-ascii and/or iso-8859-1 when encoding headers; otherwise, <c>false</c>.</value>
261233
public bool AllowMixedHeaderCharsets {
262234
get { return allowMixedHeaderCharsets; }
263-
set {
264-
if (this == Default)
265-
throw new InvalidOperationException ("The default formatting options cannot be changed.");
266-
267-
allowMixedHeaderCharsets = value;
268-
}
235+
set { allowMixedHeaderCharsets = value; }
269236
}
270237

271238
/// <summary>
@@ -288,9 +255,6 @@ public bool AllowMixedHeaderCharsets {
288255
public ParameterEncodingMethod ParameterEncodingMethod {
289256
get { return parameterEncodingMethod; }
290257
set {
291-
if (this == Default)
292-
throw new InvalidOperationException ("The default formatting options cannot be changed.");
293-
294258
switch (value) {
295259
case ParameterEncodingMethod.Rfc2047:
296260
case ParameterEncodingMethod.Rfc2231:
@@ -315,12 +279,7 @@ public ParameterEncodingMethod ParameterEncodingMethod {
315279
/// <value><c>true</c> if Content-Type and Content-Disposition parameters should always be quoted; otherwise, <c>false</c>.</value>
316280
public bool AlwaysQuoteParameterValues {
317281
get { return alwaysQuoteParameterValues; }
318-
set {
319-
if (this == Default)
320-
throw new InvalidOperationException ("The default formatting options cannot be changed.");
321-
322-
alwaysQuoteParameterValues = value;
323-
}
282+
set { alwaysQuoteParameterValues = value; }
324283
}
325284

326285
static FormatOptions ()

UnitTests/FormatOptionsTests.cs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,5 @@ public void TestArgumentExceptions ()
4141

4242
Assert.DoesNotThrow (() => format.MaxLineLength = 72);
4343
}
44-
45-
[Test]
46-
public void TestInvalidOperationExceptions ()
47-
{
48-
Assert.Throws<InvalidOperationException> (() => FormatOptions.Default.MaxLineLength = 998, "MaxLineLength");
49-
Assert.Throws<InvalidOperationException> (() => FormatOptions.Default.EnsureNewLine = true, "EnsureNewLine");
50-
Assert.Throws<InvalidOperationException> (() => FormatOptions.Default.International = true, "International");
51-
Assert.Throws<InvalidOperationException> (() => FormatOptions.Default.NewLineFormat = NewLineFormat.Dos, "NewLineFormat");
52-
Assert.Throws<InvalidOperationException> (() => FormatOptions.Default.AllowMixedHeaderCharsets = true, "AllowMixedHeaderCharsets");
53-
Assert.Throws<InvalidOperationException> (() => FormatOptions.Default.ParameterEncodingMethod = ParameterEncodingMethod.Rfc2047, "ParameterEncodingMethod");
54-
Assert.Throws<InvalidOperationException> (() => FormatOptions.Default.AlwaysQuoteParameterValues = true, "AlwaysQuoteParameterValues");
55-
}
5644
}
5745
}

0 commit comments

Comments
 (0)