summaryrefslogtreecommitdiff
path: root/services
diff options
context:
space:
mode:
authorBobby <[email protected]>2025-12-29 10:46:00 +0530
committerBobby <[email protected]>2025-12-29 10:46:00 +0530
commitf59ca1976a1075e9e8fdf1e5fcdb7cfc853493b8 (patch)
tree1123c3d0785a44261151bc46f2b38a4db9eb57b7 /services
parentcccf44496a056d15d5d86d9fbd74633f21e852bb (diff)
downloadlain-f59ca1976a1075e9e8fdf1e5fcdb7cfc853493b8.tar.xz
lain-f59ca1976a1075e9e8fdf1e5fcdb7cfc853493b8.zip
feat: Enhance email viewer with new UI actions, sender profile pictures, and raw header display.
Diffstat (limited to 'services')
-rw-r--r--services/emails.go48
1 files changed, 35 insertions, 13 deletions
diff --git a/services/emails.go b/services/emails.go
index 4b440f4..fa1d4b2 100644
--- a/services/emails.go
+++ b/services/emails.go
@@ -65,7 +65,11 @@ func GetEmailDetails(userEmail string, emailID uint) (fiber.Map, error) {
return nil, err
}
- // Get attachments
+ prefs, err := repository.GetPreferencesByEmail(userEmail)
+ if err != nil {
+ return nil, err
+ }
+
attachments, _ := repository.GetAttachmentsByEmailID(emailID)
var attachmentMaps []fiber.Map
@@ -78,7 +82,6 @@ func GetEmailDetails(userEmail string, emailID uint) (fiber.Map, error) {
})
}
- // Sanitize HTML body
body := message.BodyHTML
if body == "" {
body = "<pre>" + format.DecodeHTML(message.BodyText) + "</pre>"
@@ -86,18 +89,37 @@ func GetEmailDetails(userEmail string, emailID uint) (fiber.Map, error) {
body = format.SanitizeHTML(body)
}
+ bodyText := message.BodyText
+ if bodyText == "" && message.BodyHTML != "" {
+ bodyText = format.HTMLToPlainText(message.BodyHTML)
+ }
+
+ fromName := message.FromName
+ fromEmail := message.From
+ fromFormatted := fromEmail
+ if fromName != "" && fromName != fromEmail {
+ fromFormatted = fromName + " <" + fromEmail + ">"
+ }
+
+ toFormatted := message.To
+
return fiber.Map{
- "ID": message.ID,
- "Subject": format.DecodeHTML(message.Subject),
- "From": format.DecodeHTML(message.From),
- "FromName": format.DecodeHTML(message.FromName),
- "To": format.DecodeHTML(message.To),
- "CC": format.DecodeHTML(message.CC),
- "Date": message.Date,
- "Body": body,
- "IsRead": message.IsRead,
- "IsFlagged": message.IsFlagged,
- "Attachments": attachmentMaps,
+ "ID": message.ID,
+ "MessageID": message.MessageID,
+ "Subject": format.DecodeHTML(message.Subject),
+ "From": format.DecodeHTML(fromFormatted),
+ "FromName": format.DecodeHTML(fromName),
+ "FromEmail": format.DecodeHTML(fromEmail),
+ "To": format.DecodeHTML(toFormatted),
+ "CC": format.DecodeHTML(message.CC),
+ "Date": message.Date,
+ "DateFormatted": format.FormatEmailDate(message.Date, prefs.DateFormat, prefs.TimeFormat, prefs.PrettyDates, prefs.TimeZone),
+ "Body": body,
+ "BodyText": format.DecodeHTML(bodyText),
+ "RawHeaders": message.RawHeaders,
+ "IsRead": message.IsRead,
+ "IsFlagged": message.IsFlagged,
+ "Attachments": attachmentMaps,
}, nil
}