Skip to content

Fix CRLF encoding in EightBitStream - #130757

Merged
rzikm merged 3 commits into
dotnet:mainfrom
rzikm:smtp-encoding
Jul 16, 2026
Merged

rzikm merged 3 commits into
dotnet:mainfrom
rzikm:smtp-encoding

Conversation

@rzikm

@rzikm rzikm commented Jul 15, 2026

Copy link
Copy Markdown
Member

Improve handling of CRLF line endings in the EightBitStream class. This change ensures that CR characters are correctly processed and written.

Copilot AI review requested due to automatic review settings July 15, 2026 08:05
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
12 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @karelz, @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates System.Net.Mime.EightBitStream (used by System.Net.Mail) to handle CRLF line endings correctly when \r and \n are split across separate Write calls, preserving SMTP dot-stuffing behavior at line boundaries.

Changes:

  • Track whether the previous write ended with \r and defer emitting it until the next byte is known.
  • Update line-ending detection to treat split \r\n sequences as CRLF and reset line length correctly.
  • Add disposal-time handling to emit a trailing standalone \r that was deferred.

rzikm and others added 2 commits July 15, 2026 13:06
- Emit the deferred trailing CR in Close() before the underlying stream
  is closed. DelegatedStream.Close() closes the inner stream first, so
  writing in Dispose(bool) hit an already-closed stream.
- Clarify the misleading 'seven bit data' comment in EncodeLines.
- Add tests for CRLF split across writes and trailing-CR flush on
  sync/async disposal.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 0d67b329-86d5-4c3a-9694-aecd651258e3
DelegatedStream does not override DisposeAsync, so call base.DisposeAsync()
after flushing the deferred CR to ensure the underlying stream is disposed
in the async path, matching the synchronous Close() behavior.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 0d67b329-86d5-4c3a-9694-aecd651258e3
Copilot AI review requested due to automatic review settings July 15, 2026 11:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

@rzikm

rzikm commented Jul 15, 2026

Copy link
Copy Markdown
Member Author

/ba-g CI failure is unrelated

@rzikm
rzikm enabled auto-merge (squash) July 15, 2026 17:50
@rzikm
rzikm merged commit 6e0eb83 into dotnet:main Jul 16, 2026
87 of 89 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 16, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants