Explorar el Código

It's better than nothing

binwiederhier hace 2 años
padre
commit
7f1855ad4d
Se han modificado 3 ficheros con 603 adiciones y 12 borrados
  1. 1 0
      docs/releases.md
  2. 9 10
      server/smtp_server.go
  3. 593 2
      server/smtp_server_test.go

+ 1 - 0
docs/releases.md

@@ -1287,6 +1287,7 @@ and the [ntfy Android app](https://github.com/binwiederhier/ntfy-android/release
 
 
 **Bug fixes + maintenance:**
 **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)
 * 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))
 * 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))
 * 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))

+ 9 - 10
server/smtp_server.go

@@ -29,6 +29,11 @@ var (
 	errUnsupportedContentType = errors.New("unsupported content type")
 	errUnsupportedContentType = errors.New("unsupported content type")
 )
 )
 
 
+var (
+	onlySpacesRegex          = regexp.MustCompile(`(?m)^\s+$`)
+	consecutiveNewLinesRegex = regexp.MustCompile(`\n{3,}`)
+)
+
 const (
 const (
 	maxMultipartDepth = 2
 	maxMultipartDepth = 2
 )
 )
@@ -319,14 +324,8 @@ func readHTMLMailBody(reader io.Reader, transferEncoding string) (string, error)
 	return removeExtraEmptyLines(stripped), nil
 	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
 }
 }

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 593 - 2
server/smtp_server_test.go


Algunos archivos no se mostraron porque demasiados archivos cambiaron en este cambio