@@ -63,11 +63,7 @@ async Task<bool> StepByteOrderMarkAsync (CancellationToken cancellationToken)
63
63
return false ;
64
64
}
65
65
66
- unsafe {
67
- fixed ( byte * inbuf = input ) {
68
- complete = StepByteOrderMark ( inbuf , ref bomIndex ) ;
69
- }
70
- }
66
+ complete = StepByteOrderMark ( ref bomIndex ) ;
71
67
} while ( ! complete && inputIndex == inputEnd ) ;
72
68
73
69
return complete ;
@@ -89,11 +85,7 @@ async Task StepMboxMarkerAsync (CancellationToken cancellationToken)
89
85
return ;
90
86
}
91
87
92
- unsafe {
93
- fixed ( byte * inbuf = input ) {
94
- complete = StepMboxMarkerStart ( inbuf , ref midline ) ;
95
- }
96
- }
88
+ complete = StepMboxMarkerStart ( ref midline ) ;
97
89
} while ( ! complete ) ;
98
90
99
91
var mboxMarkerOffset = GetOffset ( inputIndex ) ;
@@ -109,13 +101,8 @@ async Task StepMboxMarkerAsync (CancellationToken cancellationToken)
109
101
}
110
102
111
103
int startIndex = inputIndex ;
112
- int count ;
113
104
114
- unsafe {
115
- fixed ( byte * inbuf = input ) {
116
- complete = StepMboxMarker ( inbuf , out count ) ;
117
- }
118
- }
105
+ complete = StepMboxMarker ( out int count ) ;
119
106
120
107
// TODO: Remove beginOffset and lineNumber arguments from OnMboxMarkerReadAsync() in v5.0
121
108
await OnMboxMarkerReadAsync ( input , startIndex , count , mboxMarkerOffset , mboxMarkerLineNumber , cancellationToken ) . ConfigureAwait ( false ) ;
@@ -179,41 +166,27 @@ async Task StepHeadersAsync (CancellationToken cancellationToken)
179
166
}
180
167
181
168
// Scan ahead a bit to see if this looks like an invalid header.
182
- do {
183
- unsafe {
184
- fixed ( byte * inbuf = input ) {
185
- if ( TryDetectInvalidHeader ( inbuf , out invalid , out fieldNameLength , out headerFieldLength ) )
186
- break ;
187
- }
188
- }
189
-
169
+ while ( ! TryDetectInvalidHeader ( out invalid , out fieldNameLength , out headerFieldLength ) ) {
190
170
int atleast = ( inputEnd - inputIndex ) + 1 ;
191
171
192
172
if ( await ReadAheadAsync ( atleast , 0 , cancellationToken ) . ConfigureAwait ( false ) < atleast ) {
193
173
// Not enough input to even find the ':'... mark as invalid and continue?
194
174
invalid = true ;
195
175
break ;
196
176
}
197
- } while ( true ) ;
177
+ }
198
178
199
179
if ( invalid ) {
200
180
// Figure out why this is an invalid header.
201
181
202
182
if ( input [ inputIndex ] == ( byte ) '-' ) {
203
183
// Check for a boundary marker. If the message is properly formatted, this will NEVER happen.
204
- do {
205
- unsafe {
206
- fixed ( byte * inbuf = input ) {
207
- if ( TryCheckBoundaryWithinHeaderBlock ( inbuf ) )
208
- break ;
209
- }
210
- }
211
-
184
+ while ( ! TryCheckBoundaryWithinHeaderBlock ( ) ) {
212
185
int atleast = ( inputEnd - inputIndex ) + 1 ;
213
186
214
187
if ( await ReadAheadAsync ( atleast , 0 , cancellationToken ) . ConfigureAwait ( false ) < atleast )
215
188
break ;
216
- } while ( true ) ;
189
+ }
217
190
218
191
// Note: If a boundary was discovered, then the state will be updated to MimeParserState.Boundary.
219
192
if ( state == MimeParserState . Boundary )
@@ -222,19 +195,12 @@ async Task StepHeadersAsync (CancellationToken cancellationToken)
222
195
// Fall through and act as if we're consuming a header.
223
196
} else if ( input [ inputIndex ] == ( byte ) 'F' || input [ inputIndex ] == ( byte ) '>' ) {
224
197
// Check for an mbox-style From-line. Again, if the message is properly formatted and not truncated, this will NEVER happen.
225
- do {
226
- unsafe {
227
- fixed ( byte * inbuf = input ) {
228
- if ( TryCheckMboxMarkerWithinHeaderBlock ( inbuf ) )
229
- break ;
230
- }
231
- }
232
-
198
+ while ( ! TryCheckMboxMarkerWithinHeaderBlock ( ) ) {
233
199
int atleast = ( inputEnd - inputIndex ) + 1 ;
234
200
235
201
if ( await ReadAheadAsync ( atleast , 0 , cancellationToken ) . ConfigureAwait ( false ) < atleast )
236
202
break ;
237
- } while ( true ) ;
203
+ }
238
204
239
205
// state will be one of the following values:
240
206
// 1. Complete: This means that we've found an actual mbox marker
@@ -262,20 +228,13 @@ async Task StepHeadersAsync (CancellationToken cancellationToken)
262
228
bool midline = true ;
263
229
264
230
// Consume the header value.
265
- do {
266
- unsafe {
267
- fixed ( byte * inbuf = input ) {
268
- if ( StepHeaderValue ( inbuf , ref midline ) )
269
- break ;
270
- }
271
- }
272
-
231
+ while ( ! StepHeaderValue ( ref midline ) ) {
273
232
if ( await ReadAheadAsync ( 1 , 0 , cancellationToken ) . ConfigureAwait ( false ) == 0 ) {
274
233
state = MimeParserState . Content ;
275
234
eof = true ;
276
235
break ;
277
236
}
278
- } while ( true ) ;
237
+ }
279
238
280
239
if ( toplevel && headerCount == 0 && invalid && ! IsMboxMarker ( headerBuffer ) ) {
281
240
state = MimeParserState . Error ;
@@ -297,19 +256,13 @@ async Task<bool> SkipBoundaryMarkerAsync (string boundary, bool endBoundary, Can
297
256
long beginOffset = GetOffset ( inputIndex ) ;
298
257
int beginLineNumber = lineNumber ;
299
258
int startIndex = inputIndex ;
300
- bool result ;
301
259
302
260
if ( endBoundary )
303
261
await OnMultipartEndBoundaryBeginAsync ( beginOffset , beginLineNumber , cancellationToken ) . ConfigureAwait ( false ) ;
304
262
else
305
263
await OnMultipartBoundaryBeginAsync ( beginOffset , beginLineNumber , cancellationToken ) . ConfigureAwait ( false ) ;
306
264
307
- unsafe {
308
- fixed ( byte * inbuf = input ) {
309
- result = SkipBoundaryMarkerInternal ( inbuf , endBoundary ) ;
310
- }
311
- }
312
-
265
+ var result = SkipBoundaryMarkerInternal ( endBoundary ) ;
313
266
int count = inputIndex - startIndex ;
314
267
315
268
if ( endBoundary )
@@ -380,11 +333,7 @@ async Task<ScanContentResult> ScanContentAsync (ScanContentType type, long begin
380
333
381
334
int contentIndex = inputIndex ;
382
335
383
- unsafe {
384
- fixed ( byte * inbuf = input ) {
385
- incomplete = ScanContent ( inbuf , ref midline , ref formats ) ;
386
- }
387
- }
336
+ incomplete = ScanContent ( ref midline , ref formats ) ;
388
337
389
338
if ( contentIndex < inputIndex ) {
390
339
switch ( type ) {
@@ -447,23 +396,11 @@ async Task<int> ConstructMessagePartAsync (int depth, CancellationToken cancella
447
396
return 0 ;
448
397
}
449
398
450
- unsafe {
451
- fixed ( byte * inbuf = input ) {
452
- byte * start = inbuf + inputIndex ;
453
- byte * inend = inbuf + inputEnd ;
454
- byte * inptr = start ;
455
-
456
- * inend = ( byte ) '\n ' ;
457
-
458
- inptr = EndOfLine ( inptr , inend + 1 ) ;
459
-
460
- // Note: This isn't obvious, but if the "boundary" that was found is an Mbox "From " line, then
461
- // either the current stream offset is >= contentEnd -or- RespectContentLength is false. It will
462
- // *never* be an Mbox "From " marker in Entity mode.
463
- if ( ( boundary = CheckBoundary ( inputIndex , start , ( int ) ( inptr - start ) ) ) != BoundaryType . None )
464
- return GetLineCount ( beginLineNumber , beginOffset , GetEndOffset ( inputIndex ) ) ;
465
- }
466
- }
399
+ // Note: This isn't obvious, but if the "boundary" that was found is an Mbox "From " line, then
400
+ // either the current stream offset is >= contentEnd -or- RespectContentLength is false. It will
401
+ // *never* be an Mbox "From " marker in Entity mode.
402
+ if ( ( boundary = CheckBoundary ( ) ) != BoundaryType . None )
403
+ return GetLineCount ( beginLineNumber , beginOffset , GetEndOffset ( inputIndex ) ) ;
467
404
}
468
405
469
406
// Note: When parsing non-toplevel parts, the header parser will never result in the Error state.
0 commit comments