Skip to content

Fix wordwrap corrupting LF-delimited 7bit/8bit bodies > 998 bytes - #40

Merged
alecpl merged 1 commit into
pear:masterfrom
duritong:fix/wordwrap-lf-lines
Nov 16, 2026
Merged

alecpl merged 1 commit into
pear:masterfrom
duritong:fix/wordwrap-lf-lines

Conversation

@duritong

Copy link
Copy Markdown
Contributor

PHP's wordwrap($data, 998, $this->eol) only treats the exact $break sequence ($this->eol, default "\r\n") as a line break. When 7bit/8bit content uses "\n" line endings (such as GnuPG ASCII-armored PGP blocks on Unix) and exceeds 998 bytes total, wordwrap() treated the entire body as a single line and wrapped at spaces inside armor headers and footers (roundcube/roundcubemail#10413).

Only invoke wordwrap() on individual lines that actually exceed 998 characters between CR/LF line breaks.

@alecpl

alecpl commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

Could you try to change the code so it does not creates an array of lines? Something more memory efficient.

PHP's wordwrap($data, 998, $this->eol) only treats the exact $break
sequence ($this->eol, default "\r\n") as a line break. When 7bit/8bit
content uses "\n" line endings (such as GnuPG ASCII-armored PGP blocks on
Unix) and exceeds 998 bytes total, wordwrap() treated the entire body as a
single line and wrapped at spaces inside armor headers and footers
(roundcube/roundcubemail#10413).

Use preg_replace_callback('/(*ANYCRLF)^[^\r\n]{999,}/m', ...) so wordwrap()
is only invoked on individual lines exceeding 998 characters between CR/LF
line breaks without allocating an array of lines.
@duritong
duritong force-pushed the fix/wordwrap-lf-lines branch from ec42167 to d6320b9 Compare November 16, 2026 12:17
@alecpl
alecpl merged commit 0e67c88 into pear:master Nov 16, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants