Skip to content

Commit

Permalink
Don't use FormatOptons to hold temporary state when writing out messages
Browse files Browse the repository at this point in the history
Added an internal HeaderList.Suppress property to hold the state instead.

This is a far better fix for issue #138
  • Loading branch information
jstedfast committed May 31, 2015
1 parent 97bbc4e commit 9b35e76
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
6 changes: 0 additions & 6 deletions MimeKit/FormatOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,6 @@ internal byte[] NewLineBytes {
get { return NewLineFormats[(int) NewLineFormat]; }
}

internal bool WriteHeaders {
get; set;
}

/// <summary>
/// Gets the message headers that should be hidden.
/// </summary>
Expand Down Expand Up @@ -208,7 +204,6 @@ public FormatOptions ()
HiddenHeaders = new HashSet<HeaderId> ();
//maxLineLength = DefaultMaxLineLength;
AllowMixedHeaderCharsets = true;
WriteHeaders = true;

if (Environment.NewLine.Length == 1)
newLineFormat = NewLineFormat.Unix;
Expand All @@ -231,7 +226,6 @@ public FormatOptions Clone ()
options.HiddenHeaders = new HashSet<HeaderId> (HiddenHeaders);
options.AllowMixedHeaderCharsets = AllowMixedHeaderCharsets;
options.international = international;
options.WriteHeaders = true;
return options;
}

Expand Down
7 changes: 6 additions & 1 deletion MimeKit/HeaderList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ public sealed class HeaderList : IList<Header>
{
static readonly StringComparer icase = StringComparer.OrdinalIgnoreCase;

// this table references the first header of each field
internal readonly ParserOptions Options;
internal bool Suppress;

// this table references the first header of each field
readonly Dictionary<string, Header> table;
readonly List<Header> headers;

Expand Down Expand Up @@ -655,6 +657,9 @@ public string this [string field] {
if (stream == null)
throw new ArgumentNullException ("stream");

if (Suppress)
return;

using (var filtered = new FilteredStream (stream)) {
filtered.Add (options.CreateNewLineFilter ());

Expand Down
5 changes: 1 addition & 4 deletions MimeKit/MimeEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -379,10 +379,7 @@ public virtual void Accept (MimeVisitor visitor)
if (stream == null)
throw new ArgumentNullException ("stream");

if (options.WriteHeaders)
Headers.WriteTo (options, stream, cancellationToken);
else
options.WriteHeaders = true;
Headers.WriteTo (options, stream, cancellationToken);

var cancellable = stream as ICancellableStream;

Expand Down
8 changes: 6 additions & 2 deletions MimeKit/MimeMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -954,8 +954,12 @@ public virtual void Accept (MimeVisitor visitor)
filtered.Flush (cancellationToken);
}

options.WriteHeaders = false;
Body.WriteTo (options, stream, cancellationToken);
try {
Body.Headers.Suppress = true;
Body.WriteTo (options, stream, cancellationToken);
} finally {
Body.Headers.Suppress = false;
}
}
}

Expand Down

0 comments on commit 9b35e76

Please sign in to comment.