Fix HTML content type handling with case-insensitive validation
- Normalize content_type to lowercase before processing to handle case-insensitive input (e.g., "HTML", "Html") - Add validation in Validate() to ensure only valid content types are accepted - Return descriptive error message if invalid content type is provided - Fix condition in ToNotification() to properly detect and default content type - Update SMTP notifier auto-detection to work correctly when content type is not explicitly set Issues fixed: 1. Dynamically detecting content type now works correctly (was always defaulting to "text") 2. Client can now specify content type in request as "HTML", "html", or "Html" - all work 3. Invalid content types are rejected with clear error messages 4. Auto-detection still works if neither explicit type nor valid HTML markers are found Example scenarios: - No content_type field: auto-detects based on body (checks for <, <html, <!DOCTYPE, <p>, <div>, <br>) - content_type: "html": sends as HTML with multipart/alternative - content_type: "HTML": normalized to "html", sends as HTML - content_type: "invalid": returns validation error - content_type: "text": explicitly sends as plain text, skips auto-detection 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -145,9 +145,9 @@ func (s *SMTPNotifier) buildMessage(notification *domain.Notification) string {
|
||||
builder.WriteString(fmt.Sprintf("Subject: %s\r\n", notification.Subject))
|
||||
builder.WriteString("MIME-Version: 1.0\r\n")
|
||||
|
||||
// Auto-detect HTML if content type not set
|
||||
// Auto-detect HTML if content type not explicitly set to text
|
||||
contentType := notification.ContentType
|
||||
if contentType == "" {
|
||||
if contentType == "" || contentType == "auto" {
|
||||
contentType = detectContentType(notification.Body)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user