1
0
mirror of https://github.com/axllent/mailpit.git synced 2025-01-24 03:47:38 +02:00

Merge branch 'feature/message-summary-ids' into develop

This commit is contained in:
Ralph Slooten 2023-05-30 16:54:41 +12:00
commit 3a41d56cc6
7 changed files with 47 additions and 32 deletions

View File

@ -147,7 +147,7 @@ func GetMessage(w http.ResponseWriter, r *http.Request) {
// Parameters: // Parameters:
// + name: ID // + name: ID
// in: path // in: path
// description: Message ID // description: Database ID
// required: true // required: true
// type: string // type: string
// //
@ -188,7 +188,7 @@ func DownloadAttachment(w http.ResponseWriter, r *http.Request) {
// Parameters: // Parameters:
// + name: ID // + name: ID
// in: path // in: path
// description: Message ID // description: Database ID
// required: true // required: true
// type: string // type: string
// + name: PartID // + name: PartID
@ -237,7 +237,7 @@ func GetHeaders(w http.ResponseWriter, r *http.Request) {
// Parameters: // Parameters:
// + name: ID // + name: ID
// in: path // in: path
// description: Message ID // description: Database ID
// required: true // required: true
// type: string // type: string
// //
@ -284,7 +284,7 @@ func DownloadRaw(w http.ResponseWriter, r *http.Request) {
// Parameters: // Parameters:
// + name: ID // + name: ID
// in: path // in: path
// description: Message ID // description: Database ID
// required: true // required: true
// type: string // type: string
// //
@ -330,7 +330,7 @@ func DeleteMessages(w http.ResponseWriter, r *http.Request) {
// Parameters: // Parameters:
// + name: ids // + name: ids
// in: body // in: body
// description: Message IDs to delete // description: Database IDs to delete
// required: false // required: false
// type: DeleteRequest // type: DeleteRequest
// //
@ -381,7 +381,7 @@ func SetReadStatus(w http.ResponseWriter, r *http.Request) {
// Parameters: // Parameters:
// + name: ids // + name: ids
// in: body // in: body
// description: Message IDs to update // description: Database IDs to update
// required: false // required: false
// type: SetReadStatusRequest // type: SetReadStatusRequest
// //
@ -459,7 +459,7 @@ func SetTags(w http.ResponseWriter, r *http.Request) {
// Parameters: // Parameters:
// + name: ids // + name: ids
// in: body // in: body
// description: Message IDs to update // description: Database IDs to update
// required: true // required: true
// type: SetTagsRequest // type: SetTagsRequest
// //
@ -502,7 +502,7 @@ func ReleaseMessage(w http.ResponseWriter, r *http.Request) {
// //
// # Release message // # Release message
// //
// Release a message via a preconfigured external SMTP server.. // Release a message via a pre-configured external SMTP server..
// //
// Consumes: // Consumes:
// - application/json // - application/json
@ -515,7 +515,7 @@ func ReleaseMessage(w http.ResponseWriter, r *http.Request) {
// Parameters: // Parameters:
// + name: ID // + name: ID
// in: path // in: path
// description: Message ID // description: Database ID
// required: true // required: true
// type: string // type: string
// + name: to // + name: to

View File

@ -39,12 +39,12 @@ func Thumbnail(w http.ResponseWriter, r *http.Request) {
// Parameters: // Parameters:
// + name: ID // + name: ID
// in: path // in: path
// description: message id // description: Database ID
// required: true // required: true
// type: string // type: string
// + name: PartID // + name: PartID
// in: path // in: path
// description: attachment part id // description: Attachment part ID
// required: true // required: true
// type: string // type: string
// //

View File

@ -66,7 +66,7 @@
"parameters": [ "parameters": [
{ {
"type": "string", "type": "string",
"description": "Message ID", "description": "Database ID",
"name": "ID", "name": "ID",
"in": "path", "in": "path",
"required": true "required": true
@ -103,7 +103,7 @@
"parameters": [ "parameters": [
{ {
"type": "string", "type": "string",
"description": "Message ID", "description": "Database ID",
"name": "ID", "name": "ID",
"in": "path", "in": "path",
"required": true "required": true
@ -142,7 +142,7 @@
"parameters": [ "parameters": [
{ {
"type": "string", "type": "string",
"description": "Message ID", "description": "Database ID",
"name": "ID", "name": "ID",
"in": "path", "in": "path",
"required": true "required": true
@ -183,14 +183,14 @@
"parameters": [ "parameters": [
{ {
"type": "string", "type": "string",
"description": "message id", "description": "Database ID",
"name": "ID", "name": "ID",
"in": "path", "in": "path",
"required": true "required": true
}, },
{ {
"type": "string", "type": "string",
"description": "attachment part id", "description": "Attachment part ID",
"name": "PartID", "name": "PartID",
"in": "path", "in": "path",
"required": true "required": true
@ -224,7 +224,7 @@
"parameters": [ "parameters": [
{ {
"type": "string", "type": "string",
"description": "Message ID", "description": "Database ID",
"name": "ID", "name": "ID",
"in": "path", "in": "path",
"required": true "required": true
@ -242,7 +242,7 @@
}, },
"/api/v1/message/{ID}/release": { "/api/v1/message/{ID}/release": {
"post": { "post": {
"description": "Release a message via a preconfigured external SMTP server..", "description": "Release a message via a pre-configured external SMTP server..",
"consumes": [ "consumes": [
"application/json" "application/json"
], ],
@ -261,7 +261,7 @@
"parameters": [ "parameters": [
{ {
"type": "string", "type": "string",
"description": "Message ID", "description": "Database ID",
"name": "ID", "name": "ID",
"in": "path", "in": "path",
"required": true "required": true
@ -347,11 +347,11 @@
"operationId": "SetReadStatus", "operationId": "SetReadStatus",
"parameters": [ "parameters": [
{ {
"description": "Message IDs to update", "description": "Database IDs to update",
"name": "ids", "name": "ids",
"in": "body", "in": "body",
"schema": { "schema": {
"description": "Message IDs to update", "description": "Database IDs to update",
"type": "object", "type": "object",
"$ref": "#/definitions/SetReadStatusRequest" "$ref": "#/definitions/SetReadStatusRequest"
} }
@ -385,11 +385,11 @@
"operationId": "Delete", "operationId": "Delete",
"parameters": [ "parameters": [
{ {
"description": "Message IDs to delete", "description": "Database IDs to delete",
"name": "ids", "name": "ids",
"in": "body", "in": "body",
"schema": { "schema": {
"description": "Message IDs to delete", "description": "Database IDs to delete",
"type": "object", "type": "object",
"$ref": "#/definitions/DeleteRequest" "$ref": "#/definitions/DeleteRequest"
} }
@ -466,12 +466,12 @@
"operationId": "SetTags", "operationId": "SetTags",
"parameters": [ "parameters": [
{ {
"description": "Message IDs to update", "description": "Database IDs to update",
"name": "ids", "name": "ids",
"in": "body", "in": "body",
"required": true, "required": true,
"schema": { "schema": {
"description": "Message IDs to update", "description": "Database IDs to update",
"type": "object", "type": "object",
"$ref": "#/definitions/SetTagsRequest" "$ref": "#/definitions/SetTagsRequest"
} }
@ -751,6 +751,10 @@
"description": "Database ID", "description": "Database ID",
"type": "string" "type": "string"
}, },
"MessageID": {
"description": "Message ID",
"type": "string"
},
"Read": { "Read": {
"description": "Read status", "description": "Read status",
"type": "boolean" "type": "boolean"
@ -901,6 +905,10 @@
"description": "Whether message relaying (release) is enabled", "description": "Whether message relaying (release) is enabled",
"type": "boolean" "type": "boolean"
}, },
"RecipientAllowlist": {
"description": "Allowlist of accepted recipients",
"type": "string"
},
"ReturnPath": { "ReturnPath": {
"description": "Enforced Return-Path (if set) for relay bounces", "description": "Enforced Return-Path (if set) for relay bounces",
"type": "string" "type": "string"

View File

@ -211,7 +211,7 @@ func Close() {
// Store will save an email to the database tables // Store will save an email to the database tables
func Store(body []byte) (string, error) { func Store(body []byte) (string, error) {
// Parse message body with enmime. // Parse message body with enmime
env, err := enmime.ReadEnvelope(bytes.NewReader(body)) env, err := enmime.ReadEnvelope(bytes.NewReader(body))
if err != nil { if err != nil {
logger.Log().Warningf("[db] %s", err.Error()) logger.Log().Warningf("[db] %s", err.Error())
@ -303,6 +303,7 @@ func Store(body []byte) (string, error) {
c.Created = created c.Created = created
c.ID = id c.ID = id
c.MessageID = messageID
c.Attachments = attachments c.Attachments = attachments
c.Subject = subject c.Subject = subject
c.Size = size c.Size = size
@ -321,7 +322,7 @@ func List(start, limit int) ([]MessageSummary, error) {
results := []MessageSummary{} results := []MessageSummary{}
q := sqlf.From("mailbox"). 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"). OrderBy("Created DESC").
Limit(limit). Limit(limit).
Offset(start) Offset(start)
@ -329,6 +330,7 @@ func List(start, limit int) ([]MessageSummary, error) {
if err := q.QueryAndClose(nil, db, func(row *sql.Rows) { if err := q.QueryAndClose(nil, db, func(row *sql.Rows) {
var created int64 var created int64
var id string var id string
var messageID string
var subject string var subject string
var metadata string var metadata string
var size int var size int
@ -337,7 +339,7 @@ func List(start, limit int) ([]MessageSummary, error) {
var read int var read int
em := MessageSummary{} 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) logger.Log().Error(err)
return return
} }
@ -354,6 +356,7 @@ func List(start, limit int) ([]MessageSummary, error) {
em.Created = time.UnixMilli(created) em.Created = time.UnixMilli(created)
em.ID = id em.ID = id
em.MessageID = messageID
em.Subject = subject em.Subject = subject
em.Size = size em.Size = size
em.Attachments = attachments em.Attachments = attachments
@ -399,6 +402,7 @@ func Search(search string, start, limit int) ([]MessageSummary, error) {
if err := q.QueryAndClose(nil, db, func(row *sql.Rows) { if err := q.QueryAndClose(nil, db, func(row *sql.Rows) {
var created int64 var created int64
var id string var id string
var messageID string
var subject string var subject string
var metadata string var metadata string
var size int var size int
@ -408,7 +412,7 @@ func Search(search string, start, limit int) ([]MessageSummary, error) {
var ignore string var ignore string
em := MessageSummary{} 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) logger.Log().Error(err)
return return
} }
@ -425,6 +429,7 @@ func Search(search string, start, limit int) ([]MessageSummary, error) {
em.Created = time.UnixMilli(created) em.Created = time.UnixMilli(created)
em.ID = id em.ID = id
em.MessageID = messageID
em.Subject = subject em.Subject = subject
em.Size = size em.Size = size
em.Attachments = attachments em.Attachments = attachments

View File

@ -14,7 +14,7 @@ func searchParser(args []string, start, limit int) *sqlf.Stmt {
} }
q := sqlf.From("mailbox"). 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, '$.To'), '{}') as ToJSON,
IFNULL(json_extract(Metadata, '$.From'), '{}') as FromJSON, IFNULL(json_extract(Metadata, '$.From'), '{}') as FromJSON,
IFNULL(json_extract(Metadata, '$.Cc'), '{}') as CcJSON, IFNULL(json_extract(Metadata, '$.Cc'), '{}') as CcJSON,

View File

@ -69,6 +69,8 @@ type Attachment struct {
type MessageSummary struct { type MessageSummary struct {
// Database ID // Database ID
ID string ID string
// Message ID
MessageID string
// Read status // Read status
Read bool Read bool
// From address // From address

View File

@ -12,7 +12,7 @@ import (
"github.com/leporo/sqlf" "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 { func SetTags(id string, tags []string) error {
applyTags := []string{} applyTags := []string{}
reg := regexp.MustCompile(`\s+`) reg := regexp.MustCompile(`\s+`)
@ -61,7 +61,7 @@ func findTags(message *[]byte) []string {
return tags 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. // Used when parsing a raw email.
func getMessageTags(id string) []string { func getMessageTags(id string) []string {
tags := []string{} tags := []string{}