@@ -63,6 +63,7 @@ public class ExperimentalMimeParser : MimeReader, IMimeParser
63
63
Stream content ;
64
64
65
65
bool parsingMessageHeaders ;
66
+ bool hasBodySeparator ;
66
67
int depth ;
67
68
68
69
bool persistent ;
@@ -335,6 +336,7 @@ protected override void OnHeadersBegin (long beginOffset, int beginLineNumber, C
335
336
{
336
337
headers . Clear ( ) ;
337
338
preHeaderLength = 0 ;
339
+ hasBodySeparator = false ;
338
340
}
339
341
340
342
/// <summary>
@@ -378,6 +380,22 @@ protected override void OnHeadersEnd (long beginOffset, int beginLineNumber, lon
378
380
parsingMessageHeaders = false ;
379
381
}
380
382
383
+ /// <summary>
384
+ /// Called when the body separator is encountered in the stream.
385
+ /// </summary>
386
+ /// <remarks>
387
+ /// <para>Called when the body separator is encountered in the stream.</para>
388
+ /// <para>This method is always called before <see cref="OnHeadersEnd"/> if a body separator is found.</para>
389
+ /// </remarks>
390
+ /// <param name="beginOffset">The offset into the stream where the body separator began.</param>
391
+ /// <param name="lineNumber">The line number where the body separator was found.</param>
392
+ /// <param name="endOffset">The offset into the stream where the body separator ended.</param>
393
+ /// <param name="cancellationToken">The cancellation token.</param>
394
+ protected override void OnBodySeparator ( long beginOffset , int lineNumber , long endOffset , CancellationToken cancellationToken )
395
+ {
396
+ hasBodySeparator = true ;
397
+ }
398
+
381
399
#endregion Header Events
382
400
383
401
#region MimeMessage Events
@@ -447,7 +465,7 @@ protected override void OnMimeMessageEnd (long beginOffset, int beginLineNumber,
447
465
protected override void OnMimePartBegin ( ContentType contentType , long beginOffset , int beginLineNumber , CancellationToken cancellationToken )
448
466
{
449
467
var toplevel = stack . Count > 0 && stack . Peek ( ) is MimeMessage ;
450
- var part = Options . CreateEntity ( contentType , headers , toplevel , depth ) ;
468
+ var part = Options . CreateEntity ( contentType , headers , hasBodySeparator , toplevel , depth ) ;
451
469
452
470
PushEntity ( part ) ;
453
471
}
@@ -555,7 +573,7 @@ protected override void OnMimePartEnd (ContentType contentType, long beginOffset
555
573
protected override void OnMessagePartBegin ( ContentType contentType , long beginOffset , int beginLineNumber , CancellationToken cancellationToken )
556
574
{
557
575
var toplevel = stack . Count > 0 && stack . Peek ( ) is MimeMessage ;
558
- var rfc822 = Options . CreateEntity ( contentType , headers , toplevel , depth ) ;
576
+ var rfc822 = Options . CreateEntity ( contentType , headers , hasBodySeparator , toplevel , depth ) ;
559
577
560
578
parsingMessageHeaders = true ;
561
579
PushEntity ( rfc822 ) ;
@@ -600,7 +618,7 @@ protected override void OnMessagePartEnd (ContentType contentType, long beginOff
600
618
protected override void OnMultipartBegin ( ContentType contentType , long beginOffset , int beginLineNumber , CancellationToken cancellationToken )
601
619
{
602
620
var toplevel = stack . Count > 0 && stack . Peek ( ) is MimeMessage ;
603
- var multipart = Options . CreateEntity ( contentType , headers , toplevel , depth ) ;
621
+ var multipart = Options . CreateEntity ( contentType , headers , hasBodySeparator , toplevel , depth ) ;
604
622
605
623
PushEntity ( multipart ) ;
606
624
depth ++ ;
@@ -838,7 +856,7 @@ public HeaderList ParseHeaders (CancellationToken cancellationToken = default)
838
856
throw ;
839
857
}
840
858
841
- var parsed = new HeaderList ( Options ) ;
859
+ var parsed = new HeaderList ( Options , hasBodySeparator ) ;
842
860
foreach ( var header in headers )
843
861
parsed . Add ( header ) ;
844
862
@@ -873,7 +891,7 @@ public async Task<HeaderList> ParseHeadersAsync (CancellationToken cancellationT
873
891
throw ;
874
892
}
875
893
876
- var parsed = new HeaderList ( Options ) ;
894
+ var parsed = new HeaderList ( Options , hasBodySeparator ) ;
877
895
foreach ( var header in headers )
878
896
parsed . Add ( header ) ;
879
897
0 commit comments