1
0
mirror of https://github.com/axllent/mailpit.git synced 2025-01-08 00:39:22 +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:
// + 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

View File

@ -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
//

View File

@ -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"

View File

@ -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
@ -321,7 +322,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 +330,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
@ -337,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
}
@ -354,6 +356,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
@ -399,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
@ -408,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
}
@ -425,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

View File

@ -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,

View File

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

View File

@ -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{}