Skip to content

Commit

Permalink
Merge branch 'release/v1.20.6'
Browse files Browse the repository at this point in the history
  • Loading branch information
axllent committed Oct 14, 2024
2 parents 2c326ac + 51e29ba commit 4ff9fdf
Show file tree
Hide file tree
Showing 24 changed files with 272 additions and 204 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/close-stale-issues.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
with:
days-before-issue-stale: 7
days-before-issue-close: 3
exempt-issue-labels: "enhancement,bug,javascript,docker"
exempt-issue-labels: "enhancement,bug,awaiting feedback"
stale-issue-label: "stale"
stale-issue-message: "This issue has been marked as stale because it has been open for 7 days with no activity."
close-issue-message: "This issue was closed because there has been no activity since being marked as stale."
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ jobs:
# validate the swagger file
- name: Validate OpenAPI definition
if: startsWith(matrix.os, 'ubuntu') == true
uses: char0n/swagger-editor-validate@v1
uses: swaggerexpert/swagger-editor-validate@v1
with:
definition-file: server/ui/api/v1/swagger.json
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@

Notable changes to Mailpit will be documented in this file.

## [v1.20.6]

### Chore
- Bump Go compile version to 1.23
- Update node modules
- Update swagger file tests
- Code cleanup
- Update Go dependencies
- Update minimum Go version (1.22.0)
- Update node dependencies


## [v1.20.5]

### Chore
Expand Down
33 changes: 17 additions & 16 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
module github.com/axllent/mailpit

go 1.21.0
go 1.23

toolchain go1.22.1
toolchain go1.23.2

require (
github.com/PuerkitoBio/goquery v1.9.2
github.com/PuerkitoBio/goquery v1.10.0
github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de
github.com/axllent/semver v0.0.1
github.com/gomarkdown/markdown v0.0.0-20240730141124-034f12af3bf6
github.com/gomarkdown/markdown v0.0.0-20240930133441-72d49d9543d8
github.com/gorilla/mux v1.8.1
github.com/gorilla/websocket v1.5.3
github.com/jhillyerd/enmime v1.3.0
github.com/klauspost/compress v1.17.9
github.com/klauspost/compress v1.17.11
github.com/kovidgoyal/imaging v1.6.3
github.com/leporo/sqlf v1.4.0
github.com/lithammer/shortuuid/v4 v4.0.0
github.com/mhale/smtpd v0.8.3
github.com/reiver/go-telnet v0.0.0-20180421082511-9ff0b2ab096e
github.com/rqlite/gorqlite v0.0.0-20240808172217-12ae7d03ef19
github.com/rqlite/gorqlite v0.0.0-20241013203532-4385768ae85d
github.com/sirupsen/logrus v1.9.3
github.com/spf13/cobra v1.8.1
github.com/spf13/pflag v1.0.5
github.com/tg123/go-htpasswd v1.2.2
github.com/vanng822/go-premailer v1.21.0
golang.org/x/net v0.28.0
golang.org/x/text v0.18.0
golang.org/x/time v0.6.0
github.com/vanng822/go-premailer v1.22.0
golang.org/x/net v0.30.0
golang.org/x/text v0.19.0
golang.org/x/time v0.7.0
gopkg.in/yaml.v3 v3.0.1
modernc.org/sqlite v1.32.0
modernc.org/sqlite v1.33.1
)

require (
Expand All @@ -54,12 +54,13 @@ require (
github.com/ssor/bom v0.0.0-20170718123548-6386211fdfcf // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/vanng822/css v1.0.1 // indirect
golang.org/x/crypto v0.26.0 // indirect
golang.org/x/image v0.20.0 // indirect
golang.org/x/sys v0.25.0 // indirect
golang.org/x/crypto v0.28.0 // indirect
golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c // indirect
golang.org/x/image v0.21.0 // indirect
golang.org/x/sys v0.26.0 // indirect
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
modernc.org/gc/v3 v3.0.0-20240801135723-a856999a2e4a // indirect
modernc.org/libc v1.60.1 // indirect
modernc.org/gc/v3 v3.0.0-20241004144649-1aea3fae8852 // indirect
modernc.org/libc v1.61.0 // indirect
modernc.org/mathutil v1.6.0 // indirect
modernc.org/memory v1.8.0 // indirect
modernc.org/strutil v1.2.0 // indirect
Expand Down
106 changes: 68 additions & 38 deletions go.sum

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions internal/html2text/html2text.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,6 @@ func clean(text string) string {
}, text)

text = re.ReplaceAllString(text, " ")

return strings.TrimSpace(text)
}
25 changes: 15 additions & 10 deletions internal/pop3client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,17 @@ type Conn struct {

// Opt represents the client configuration.
type Opt struct {
// Host name
Host string `json:"host"`
Port int `json:"port"`

// Default is 3 seconds.
// Port number
Port int `json:"port"`
// DialTimeout default is 3 seconds.
DialTimeout time.Duration `json:"dial_timeout"`
Dialer Dialer `json:"-"`

TLSEnabled bool `json:"tls_enabled"`
// Dialer
Dialer Dialer `json:"-"`
// TLSEnabled sets whether SLS is enabled
TLSEnabled bool `json:"tls_enabled"`
// TLSSkipVerify skips TLS verification (ie: self-signed)
TLSSkipVerify bool `json:"tls_skip_verify"`
}

Expand All @@ -49,16 +52,15 @@ type Dialer interface {
// MessageID contains the ID and size of an individual message.
type MessageID struct {
// ID is the numerical index (non-unique) of the message.
ID int
ID int
// Size in bytes
Size int

// UID is only present if the response is to the UIDL command.
UID string
}

var (
lineBreak = []byte("\r\n")

lineBreak = []byte("\r\n")
respOK = []byte("+OK") // `+OK` without additional info
respOKInfo = []byte("+OK ") // `+OK <info>`
respErr = []byte("-ERR") // `-ERR` without additional info
Expand Down Expand Up @@ -126,6 +128,7 @@ func (c *Conn) Send(b string) error {
if _, err := c.w.WriteString(b + "\r\n"); err != nil {
return err
}

return c.w.Flush()
}

Expand Down Expand Up @@ -223,12 +226,14 @@ func (c *Conn) Auth(user, password string) error {
// User sends the username to the server.
func (c *Conn) User(s string) error {
_, err := c.Cmd("USER", false, s)

return err
}

// Pass sends the password to the server.
func (c *Conn) Pass(s string) error {
_, err := c.Cmd("PASS", false, s)

return err
}

Expand Down
37 changes: 21 additions & 16 deletions internal/spamassassin/spamc/spamc.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
"strconv"
"strings"
"time"

"github.com/axllent/mailpit/internal/tools"
)

// ProtoVersion is the protocol version
Expand Down Expand Up @@ -81,6 +83,7 @@ func (c *Client) dial() (connection, error) {
}
return net.DialUnix("unix", nil, unixAddr)
}

panic("Client.net must be either \"tcp\" or \"unix\"")
}

Expand All @@ -107,33 +110,33 @@ func (c *Client) report(email []byte) ([]string, error) {
}

bw := bufio.NewWriter(conn)
_, err = bw.WriteString("REPORT SPAMC/" + ProtoVersion + "\r\n")
if err != nil {
if _, err := bw.WriteString("REPORT SPAMC/" + ProtoVersion + "\r\n"); err != nil {
return nil, err
}
_, err = bw.WriteString("Content-length: " + strconv.Itoa(len(email)) + "\r\n\r\n")
if err != nil {

if _, err := bw.WriteString("Content-length: " + strconv.Itoa(len(email)) + "\r\n\r\n"); err != nil {
return nil, err
}
_, err = bw.Write(email)
if err != nil {

if _, err := bw.Write(email); err != nil {
return nil, err
}
err = bw.Flush()
if err != nil {

if err := bw.Flush(); err != nil {
return nil, err
}

// Client is supposed to close its writing side of the connection
// after sending its request.
err = conn.CloseWrite()
if err != nil {
if err := conn.CloseWrite(); err != nil {
return nil, err
}

var (
lines []string
br = bufio.NewReader(conn)
)

for {
line, err := br.ReadString('\n')
if err == io.EOF {
Expand Down Expand Up @@ -171,11 +174,12 @@ func (c *Client) parseOutput(output []string) Result {
continue
}
}

// summary
if spamMainRe.MatchString(row) {
res := spamMainRe.FindStringSubmatch(row)
if len(res) == 4 {
if strings.ToLower(res[1]) == "true" || strings.ToLower(res[1]) == "yes" {
if tools.InArray(res[1], []string{"true", "yes"}) {
result.Spam = true
} else {
result.Spam = false
Expand All @@ -197,8 +201,8 @@ func (c *Client) parseOutput(output []string) Result {
reachedRules = true
continue
}

// details
// row = strings.Trim(row, " \t\r\n")
if reachedRules && spamDetailsRe.MatchString(row) {
res := spamDetailsRe.FindStringSubmatch(row)
if len(res) == 5 {
Expand All @@ -207,6 +211,7 @@ func (c *Client) parseOutput(output []string) Result {
}
}
}

return result
}

Expand All @@ -222,12 +227,11 @@ func (c *Client) Ping() error {
return err
}

_, err = io.WriteString(conn, fmt.Sprintf("PING SPAMC/%s\r\n\r\n", ProtoVersion))
if err != nil {
if _, err := io.WriteString(conn, fmt.Sprintf("PING SPAMC/%s\r\n\r\n", ProtoVersion)); err != nil {
return err
}
err = conn.CloseWrite()
if err != nil {

if err := conn.CloseWrite(); err != nil {
return err
}

Expand All @@ -241,5 +245,6 @@ func (c *Client) Ping() error {
return err
}
}

return nil
}
8 changes: 5 additions & 3 deletions internal/storage/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,12 @@ var (

// InitDB will initialise the database
func InitDB() error {
var (
dsn string
err error
)

p := config.Database
var dsn string

if p == "" {
// when no path is provided then we create a temporary file
Expand Down Expand Up @@ -74,8 +78,6 @@ func InitDB() error {
}
}

var err error

db, err = sql.Open(sqlDriver, dsn)
if err != nil {
return err
Expand Down
15 changes: 15 additions & 0 deletions internal/storage/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,21 @@ func GetAttachmentPart(id, partID string) (*enmime.Part, error) {
return nil, errors.New("attachment not found")
}

// AttachmentSummary returns a summary of the attachment without any binary data
func AttachmentSummary(a *enmime.Part) Attachment {
o := Attachment{}
o.PartID = a.PartID
o.FileName = a.FileName
if o.FileName == "" {
o.FileName = a.ContentID
}
o.ContentType = a.ContentType
o.ContentID = a.ContentID
o.Size = float64(len(a.Content))

return o
}

// LatestID returns the latest message ID
//
// If a query argument is set in the request the function will return the
Expand Down
11 changes: 8 additions & 3 deletions internal/storage/reindex.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,14 @@ func ReindexAll() {
logger.Log().Infof("reindexing %d messages", total)

type updateStruct struct {
ID string
// ID in database
ID string
// SearchText for searching
SearchText string
Snippet string
Metadata string
// Snippet for UI
Snippet string
// Metadata info
Metadata string
}

parser := enmime.NewParser(enmime.DisableCharacterDetection(true))
Expand Down Expand Up @@ -137,5 +141,6 @@ func chunkBy[T any](items []T, chunkSize int) (chunks [][]T) {
for chunkSize < len(items) {
items, chunks = items[chunkSize:], append(chunks, items[0:chunkSize:chunkSize])
}

return append(chunks, items)
}
1 change: 1 addition & 0 deletions internal/storage/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ func DeleteSearch(search, timezone string) error {
}

dbLastAction = time.Now()

addDeletedSize(int64(deleteSize))

logMessagesDeleted(total)
Expand Down
17 changes: 0 additions & 17 deletions internal/storage/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package storage
import (
"net/mail"
"time"

"github.com/jhillyerd/enmime"
)

// Message data excluding physical attachments
Expand Down Expand Up @@ -114,21 +112,6 @@ type DBMailSummary struct {
ReplyTo []*mail.Address
}

// AttachmentSummary returns a summary of the attachment without any binary data
func AttachmentSummary(a *enmime.Part) Attachment {
o := Attachment{}
o.PartID = a.PartID
o.FileName = a.FileName
if o.FileName == "" {
o.FileName = a.ContentID
}
o.ContentType = a.ContentType
o.ContentID = a.ContentID
o.Size = float64(len(a.Content))

return o
}

// ListUnsubscribe contains a summary of List-Unsubscribe & List-Unsubscribe-Post headers
// including validation of the link structure
type ListUnsubscribe struct {
Expand Down
Loading

0 comments on commit 4ff9fdf

Please sign in to comment.