Skip to content

fix(email): collapse excessive blank lines in HTML-to-text conversion#16

Merged
qasim-nylas merged 1 commit intonylas:mainfrom
mqasimca:fix/html-to-text-newlines
Feb 3, 2026
Merged

fix(email): collapse excessive blank lines in HTML-to-text conversion#16
qasim-nylas merged 1 commit intonylas:mainfrom
mqasimca:fix/html-to-text-newlines

Conversation

@mqasimca
Copy link
Contributor

@mqasimca mqasimca commented Feb 3, 2026

Summary

Fixes excessive blank lines in HTML-to-text email conversion, particularly for table-heavy marketing emails (Yahoo, Azure, ChatGPT newsletters, etc.).

Problem: The StripHTML function was creating many consecutive blank lines when processing HTML emails that use nested tables for layout. Each </tr> tag added a newline, and the cleanup only collapsed 3+ newlines to 2, leaving many double-newlines.

Solution:

  • Trim whitespace from each line first
  • Then collapse consecutive empty lines to at most one blank line
  • Preserves paragraph separation while eliminating excessive whitespace

Before

Did you just use your app password?




Hi Muhammad,




An app password for your account...

After

Did you just use your app password?

Hi Muhammad,

An app password for your account...

Changes

  • internal/cli/common/html.go: Improved StripHTML function to collapse consecutive empty lines after trimming

Test Plan

  • All existing TestStripHTML tests pass (22 test cases)
  • Tested with Yahoo IMAP emails (3 emails)
  • Tested with Microsoft Graph emails (10 emails)
  • make ci passes (fmt, vet, lint, unit tests, security scan, vuln check)

Email Types Verified

Provider Email Type Result
Yahoo Security notifications ✅ Clean
Yahoo OpenPGP verification ✅ Clean
Microsoft Marketing (Azure, ChatGPT) ✅ Clean
Microsoft npm OTP notifications ✅ Clean
Microsoft Nylas reminders ✅ Clean
Microsoft Plain text / replies ✅ Clean

Improve StripHTML function to handle table-heavy HTML emails (common in
marketing emails) by collapsing consecutive empty lines to a single
blank line. This prevents excessive whitespace in email display while
preserving readability with paragraph separation.
@qasim-nylas qasim-nylas merged commit eff0f6c into nylas:main Feb 3, 2026
2 checks passed
@mqasimca mqasimca deleted the fix/html-to-text-newlines branch February 4, 2026 14:25
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