Skip to content

Commit

Permalink
It's better than nothing
Browse files Browse the repository at this point in the history
  • Loading branch information
binwiederhier committed Nov 16, 2023
1 parent b42958d commit 7f1855a
Show file tree
Hide file tree
Showing 3 changed files with 654 additions and 13 deletions.
1 change: 1 addition & 0 deletions docs/releases.md
Original file line number Diff line number Diff line change
Expand Up @@ -1287,6 +1287,7 @@ and the [ntfy Android app](https://github.com/binwiederhier/ntfy-android/release

**Bug fixes + maintenance:**

* Support for HTML-only emails ([#690](https://github.com/binwiederhier/ntfy/issues/690), thanks to [@teastrainer](https://github.com/teastrainer) and [@CrazyWolf13](https://github.com/CrazyWolf13) for reporting)
* Fix ACL issue with topic patterns containing underscores ([#840](https://github.com/binwiederhier/ntfy/issues/840), thanks to [@Joe-0237](https://github.com/Joe-0237) for reporting)
* Re-add `tzdata` to Docker images for amd64 image ([#894](https://github.com/binwiederhier/ntfy/issues/894), [#307](https://github.com/binwiederhier/ntfy/pull/307))
* Add special logic to ignore `Priority` header if it resembled a RFC 9218 value ([#851](https://github.com/binwiederhier/ntfy/pull/851)/[#895](https://github.com/binwiederhier/ntfy/pull/895), thanks to [@gusdleon](https://github.com/gusdleon), see also [#351](https://github.com/binwiederhier/ntfy/issues/351), [#353](https://github.com/binwiederhier/ntfy/issues/353), [#461](https://github.com/binwiederhier/ntfy/issues/461))
Expand Down
19 changes: 9 additions & 10 deletions server/smtp_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ var (
errUnsupportedContentType = errors.New("unsupported content type")
)

var (
onlySpacesRegex = regexp.MustCompile(`(?m)^\s+$`)
consecutiveNewLinesRegex = regexp.MustCompile(`\n{3,}`)
)

const (
maxMultipartDepth = 2
)
Expand Down Expand Up @@ -319,14 +324,8 @@ func readHTMLMailBody(reader io.Reader, transferEncoding string) (string, error)
return removeExtraEmptyLines(stripped), nil
}

func removeExtraEmptyLines(str string) string {
// Replace lines that contain only spaces with empty lines
re := regexp.MustCompile(`(?m)^\s+$`)
str = re.ReplaceAllString(str, "")

// Remove more than 2 consecutive empty lines
re = regexp.MustCompile(`\n{3,}`)
str = re.ReplaceAllString(str, "\n\n")

return str
func removeExtraEmptyLines(s string) string {
s = onlySpacesRegex.ReplaceAllString(s, "")
s = consecutiveNewLinesRegex.ReplaceAllString(s, "\n\n")
return s
}
Loading

0 comments on commit 7f1855a

Please sign in to comment.