Feature: Include message attachment checksums (MD5, SHA1 & SHA254) in API message summary

This commit is contained in:
Ralph Slooten
2026-02-01 14:58:36 +13:00
parent 38c0c4fd47
commit 0bfbb4cc5f
3 changed files with 40 additions and 2 deletions

View File

@@ -3,6 +3,9 @@ package storage
import (
"bytes"
"context"
"crypto/md5" // #nosec
"crypto/sha1" // #nosec
"crypto/sha256"
"database/sql"
"encoding/base64"
"encoding/hex"
@@ -505,6 +508,14 @@ func AttachmentSummary(a *enmime.Part) Attachment {
o.ContentID = a.ContentID
o.Size = uint64(len(a.Content))
md5Hash := md5.Sum(a.Content) // #nosec
sha1Hash := sha1.Sum(a.Content) // #nosec
sha256Hash := sha256.Sum256(a.Content)
o.Checksums.MD5 = hex.EncodeToString(md5Hash[:])
o.Checksums.SHA1 = hex.EncodeToString(sha1Hash[:])
o.Checksums.SHA256 = hex.EncodeToString(sha256Hash[:])
return o
}

View File

@@ -48,7 +48,7 @@ type Message struct {
Attachments []Attachment
}
// Attachment struct for inline and attachments
// Attachment struct for inline images and attachments
//
// swagger:model Attachment
type Attachment struct {
@@ -62,6 +62,15 @@ type Attachment struct {
ContentID string
// Size in bytes
Size uint64
// File checksums
Checksums struct {
// MD5 checksum hash of file
MD5 string
// SHA1 checksum hash of file
SHA1 string
// SHA256 checksum hash of file
SHA256 string
}
}
// MessageSummary struct for frontend messages

View File

@@ -1345,9 +1345,27 @@
"x-go-package": "github.com/axllent/mailpit/internal/stats"
},
"Attachment": {
"description": "Attachment struct for inline and attachments",
"description": "Attachment struct for inline images and attachments",
"type": "object",
"properties": {
"Checksums": {
"description": "File checksums",
"type": "object",
"properties": {
"MD5": {
"description": "MD5 checksum hash of file",
"type": "string"
},
"SHA1": {
"description": "SHA1 checksum hash of file",
"type": "string"
},
"SHA256": {
"description": "SHA256 checksum hash of file",
"type": "string"
}
}
},
"ContentID": {
"description": "Content ID",
"type": "string"