From 34c1748f4b9bfc14a95a0ad9620ad47c59a9030c Mon Sep 17 00:00:00 2001 From: Lars Liedtke Date: Tue, 30 May 2023 06:02:25 +0200 Subject: [PATCH 1/3] Feature: Add Message-Id to MessageSummary (#116) --- storage/database.go | 4 +++- storage/structs.go | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/storage/database.go b/storage/database.go index 0dcf8c2..83e5d64 100644 --- a/storage/database.go +++ b/storage/database.go @@ -321,7 +321,7 @@ func List(start, limit int) ([]MessageSummary, error) { results := []MessageSummary{} q := sqlf.From("mailbox"). - Select(`Created, ID, Subject, Metadata, Size, Attachments, Read, Tags`). + Select(`Created, ID, MessageID, Subject, Metadata, Size, Attachments, Read, Tags`). OrderBy("Created DESC"). Limit(limit). Offset(start) @@ -329,6 +329,7 @@ func List(start, limit int) ([]MessageSummary, error) { if err := q.QueryAndClose(nil, db, func(row *sql.Rows) { var created int64 var id string + var messageID string var subject string var metadata string var size int @@ -354,6 +355,7 @@ func List(start, limit int) ([]MessageSummary, error) { em.Created = time.UnixMilli(created) em.ID = id + em.MessageID = messageID em.Subject = subject em.Size = size em.Attachments = attachments diff --git a/storage/structs.go b/storage/structs.go index 2b0f49f..2f01e91 100644 --- a/storage/structs.go +++ b/storage/structs.go @@ -69,6 +69,8 @@ type Attachment struct { type MessageSummary struct { // Database ID ID string + // Message ID + MessageID string // Read status Read bool // From address From 3d96b2cad09afc7b831939244074a1a925a7a11e Mon Sep 17 00:00:00 2001 From: Ralph Slooten Date: Tue, 30 May 2023 16:51:34 +1200 Subject: [PATCH 2/3] Add Message-ID to MessageSummary --- storage/database.go | 9 ++++++--- storage/search.go | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/storage/database.go b/storage/database.go index 83e5d64..5b50932 100644 --- a/storage/database.go +++ b/storage/database.go @@ -211,7 +211,7 @@ func Close() { // Store will save an email to the database tables func Store(body []byte) (string, error) { - // Parse message body with enmime. + // Parse message body with enmime env, err := enmime.ReadEnvelope(bytes.NewReader(body)) if err != nil { logger.Log().Warningf("[db] %s", err.Error()) @@ -303,6 +303,7 @@ func Store(body []byte) (string, error) { c.Created = created c.ID = id + c.MessageID = messageID c.Attachments = attachments c.Subject = subject c.Size = size @@ -338,7 +339,7 @@ func List(start, limit int) ([]MessageSummary, error) { var read int em := MessageSummary{} - if err := row.Scan(&created, &id, &subject, &metadata, &size, &attachments, &read, &tags); err != nil { + if err := row.Scan(&created, &id, &messageID, &subject, &metadata, &size, &attachments, &read, &tags); err != nil { logger.Log().Error(err) return } @@ -401,6 +402,7 @@ func Search(search string, start, limit int) ([]MessageSummary, error) { if err := q.QueryAndClose(nil, db, func(row *sql.Rows) { var created int64 var id string + var messageID string var subject string var metadata string var size int @@ -410,7 +412,7 @@ func Search(search string, start, limit int) ([]MessageSummary, error) { var ignore string em := MessageSummary{} - if err := row.Scan(&created, &id, &subject, &metadata, &size, &attachments, &read, &tags, &ignore, &ignore, &ignore, &ignore); err != nil { + if err := row.Scan(&created, &id, &messageID, &subject, &metadata, &size, &attachments, &read, &tags, &ignore, &ignore, &ignore, &ignore); err != nil { logger.Log().Error(err) return } @@ -427,6 +429,7 @@ func Search(search string, start, limit int) ([]MessageSummary, error) { em.Created = time.UnixMilli(created) em.ID = id + em.MessageID = messageID em.Subject = subject em.Size = size em.Attachments = attachments diff --git a/storage/search.go b/storage/search.go index abf6438..a3824cd 100644 --- a/storage/search.go +++ b/storage/search.go @@ -14,7 +14,7 @@ func searchParser(args []string, start, limit int) *sqlf.Stmt { } q := sqlf.From("mailbox"). - Select(`Created, ID, Subject, Metadata, Size, Attachments, Read, Tags, + Select(`Created, ID, MessageID, Subject, Metadata, Size, Attachments, Read, Tags, IFNULL(json_extract(Metadata, '$.To'), '{}') as ToJSON, IFNULL(json_extract(Metadata, '$.From'), '{}') as FromJSON, IFNULL(json_extract(Metadata, '$.Cc'), '{}') as CcJSON, From db5d8f672a8e7f8c42b78a156b9659fa19712659 Mon Sep 17 00:00:00 2001 From: Ralph Slooten Date: Tue, 30 May 2023 16:52:39 +1200 Subject: [PATCH 3/3] Swagger: Update swagger field descriptions, add MessageID --- server/apiv1/api.go | 18 +++++++++--------- server/apiv1/thumbnails.go | 4 ++-- server/ui/api/v1/swagger.json | 36 +++++++++++++++++++++-------------- storage/tags.go | 4 ++-- 4 files changed, 35 insertions(+), 27 deletions(-) diff --git a/server/apiv1/api.go b/server/apiv1/api.go index 15bce45..0dfbed7 100644 --- a/server/apiv1/api.go +++ b/server/apiv1/api.go @@ -147,7 +147,7 @@ func GetMessage(w http.ResponseWriter, r *http.Request) { // Parameters: // + name: ID // in: path - // description: Message ID + // description: Database ID // required: true // type: string // @@ -188,7 +188,7 @@ func DownloadAttachment(w http.ResponseWriter, r *http.Request) { // Parameters: // + name: ID // in: path - // description: Message ID + // description: Database ID // required: true // type: string // + name: PartID @@ -237,7 +237,7 @@ func GetHeaders(w http.ResponseWriter, r *http.Request) { // Parameters: // + name: ID // in: path - // description: Message ID + // description: Database ID // required: true // type: string // @@ -284,7 +284,7 @@ func DownloadRaw(w http.ResponseWriter, r *http.Request) { // Parameters: // + name: ID // in: path - // description: Message ID + // description: Database ID // required: true // type: string // @@ -330,7 +330,7 @@ func DeleteMessages(w http.ResponseWriter, r *http.Request) { // Parameters: // + name: ids // in: body - // description: Message IDs to delete + // description: Database IDs to delete // required: false // type: DeleteRequest // @@ -381,7 +381,7 @@ func SetReadStatus(w http.ResponseWriter, r *http.Request) { // Parameters: // + name: ids // in: body - // description: Message IDs to update + // description: Database IDs to update // required: false // type: SetReadStatusRequest // @@ -459,7 +459,7 @@ func SetTags(w http.ResponseWriter, r *http.Request) { // Parameters: // + name: ids // in: body - // description: Message IDs to update + // description: Database IDs to update // required: true // type: SetTagsRequest // @@ -502,7 +502,7 @@ func ReleaseMessage(w http.ResponseWriter, r *http.Request) { // // # Release message // - // Release a message via a preconfigured external SMTP server.. + // Release a message via a pre-configured external SMTP server.. // // Consumes: // - application/json @@ -515,7 +515,7 @@ func ReleaseMessage(w http.ResponseWriter, r *http.Request) { // Parameters: // + name: ID // in: path - // description: Message ID + // description: Database ID // required: true // type: string // + name: to diff --git a/server/apiv1/thumbnails.go b/server/apiv1/thumbnails.go index 0ad9ccd..c90b3c7 100644 --- a/server/apiv1/thumbnails.go +++ b/server/apiv1/thumbnails.go @@ -39,12 +39,12 @@ func Thumbnail(w http.ResponseWriter, r *http.Request) { // Parameters: // + name: ID // in: path - // description: message id + // description: Database ID // required: true // type: string // + name: PartID // in: path - // description: attachment part id + // description: Attachment part ID // required: true // type: string // diff --git a/server/ui/api/v1/swagger.json b/server/ui/api/v1/swagger.json index 3336174..db1a885 100644 --- a/server/ui/api/v1/swagger.json +++ b/server/ui/api/v1/swagger.json @@ -66,7 +66,7 @@ "parameters": [ { "type": "string", - "description": "Message ID", + "description": "Database ID", "name": "ID", "in": "path", "required": true @@ -103,7 +103,7 @@ "parameters": [ { "type": "string", - "description": "Message ID", + "description": "Database ID", "name": "ID", "in": "path", "required": true @@ -142,7 +142,7 @@ "parameters": [ { "type": "string", - "description": "Message ID", + "description": "Database ID", "name": "ID", "in": "path", "required": true @@ -183,14 +183,14 @@ "parameters": [ { "type": "string", - "description": "message id", + "description": "Database ID", "name": "ID", "in": "path", "required": true }, { "type": "string", - "description": "attachment part id", + "description": "Attachment part ID", "name": "PartID", "in": "path", "required": true @@ -224,7 +224,7 @@ "parameters": [ { "type": "string", - "description": "Message ID", + "description": "Database ID", "name": "ID", "in": "path", "required": true @@ -242,7 +242,7 @@ }, "/api/v1/message/{ID}/release": { "post": { - "description": "Release a message via a preconfigured external SMTP server..", + "description": "Release a message via a pre-configured external SMTP server..", "consumes": [ "application/json" ], @@ -261,7 +261,7 @@ "parameters": [ { "type": "string", - "description": "Message ID", + "description": "Database ID", "name": "ID", "in": "path", "required": true @@ -347,11 +347,11 @@ "operationId": "SetReadStatus", "parameters": [ { - "description": "Message IDs to update", + "description": "Database IDs to update", "name": "ids", "in": "body", "schema": { - "description": "Message IDs to update", + "description": "Database IDs to update", "type": "object", "$ref": "#/definitions/SetReadStatusRequest" } @@ -385,11 +385,11 @@ "operationId": "Delete", "parameters": [ { - "description": "Message IDs to delete", + "description": "Database IDs to delete", "name": "ids", "in": "body", "schema": { - "description": "Message IDs to delete", + "description": "Database IDs to delete", "type": "object", "$ref": "#/definitions/DeleteRequest" } @@ -466,12 +466,12 @@ "operationId": "SetTags", "parameters": [ { - "description": "Message IDs to update", + "description": "Database IDs to update", "name": "ids", "in": "body", "required": true, "schema": { - "description": "Message IDs to update", + "description": "Database IDs to update", "type": "object", "$ref": "#/definitions/SetTagsRequest" } @@ -751,6 +751,10 @@ "description": "Database ID", "type": "string" }, + "MessageID": { + "description": "Message ID", + "type": "string" + }, "Read": { "description": "Read status", "type": "boolean" @@ -901,6 +905,10 @@ "description": "Whether message relaying (release) is enabled", "type": "boolean" }, + "RecipientAllowlist": { + "description": "Allowlist of accepted recipients", + "type": "string" + }, "ReturnPath": { "description": "Enforced Return-Path (if set) for relay bounces", "type": "string" diff --git a/storage/tags.go b/storage/tags.go index d9cdf2c..e304335 100644 --- a/storage/tags.go +++ b/storage/tags.go @@ -12,7 +12,7 @@ import ( "github.com/leporo/sqlf" ) -// SetTags will set the tags for a given message ID, used via API +// SetTags will set the tags for a given database ID, used via API func SetTags(id string, tags []string) error { applyTags := []string{} reg := regexp.MustCompile(`\s+`) @@ -61,7 +61,7 @@ func findTags(message *[]byte) []string { return tags } -// Get message tags from the database for a given message ID. +// Get message tags from the database for a given database ID // Used when parsing a raw email. func getMessageTags(id string) []string { tags := []string{}