Skip to content

Commit 2c326ac

Browse files
committed
Merge branch 'release/v1.20.5'
2 parents 4ee3ba4 + 1aed5fd commit 2c326ac

File tree

15 files changed

+528
-619
lines changed

15 files changed

+528
-619
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@
22

33
Notable changes to Mailpit will be documented in this file.
44

5+
## [v1.20.5]
6+
7+
### Chore
8+
- Update node modules
9+
- Use consistent margins for Mailpit label if set
10+
- Improve tag detection in UI
11+
- Improve link detection in the HTML preview
12+
13+
### Fix
14+
- Use correct parameter order in SpamAssassin socket detection ([#364](https://github.com/axllent/mailpit/issues/364))
15+
16+
517
## [v1.20.4]
618

719
### Chore

cmd/root.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,9 @@ func initConfigFromEnv() {
305305
if len(os.Getenv("MP_WEBHOOK_LIMIT")) > 0 {
306306
webhook.RateLimit, _ = strconv.Atoi(os.Getenv("MP_WEBHOOK_LIMIT"))
307307
}
308+
309+
// Demo mode
310+
config.DemoMode = getEnabledFromEnv("MP_DEMO_MODE")
308311
}
309312

310313
// load deprecated settings from environment and warn

config/config.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,9 @@ var (
178178

179179
// DisableHTMLCheck DEPRECATED 2024/04/13 - kept here to display console warning only
180180
DisableHTMLCheck = false
181+
182+
// DemoMode disables SMTP relay, link checking & HTTP send functionality
183+
DemoMode = false
181184
)
182185

183186
// AutoTag struct for auto-tagging
@@ -467,6 +470,12 @@ func VerifyConfig() error {
467470
logger.Log().Warnf("[relay] auto-relaying all new messages via %s:%d", SMTPRelayConfig.Host, SMTPRelayConfig.Port)
468471
}
469472

473+
if DemoMode {
474+
MaxMessages = 1000
475+
// this deserves a warning
476+
logger.Log().Info("demo mode enabled")
477+
}
478+
470479
return nil
471480
}
472481

internal/spamassassin/spamassassin.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func Ping() error {
7171
}
7272

7373
var client *spamc.Client
74-
if strings.HasPrefix("unix:", service) {
74+
if strings.HasPrefix(service, "unix:") {
7575
client = spamc.NewUnix(strings.TrimLeft(service, "unix:"))
7676
} else {
7777
client = spamc.NewTCP(service, timeout)
@@ -112,7 +112,7 @@ func Check(msg []byte) (Result, error) {
112112
}
113113
} else {
114114
var client *spamc.Client
115-
if strings.HasPrefix("unix:", service) {
115+
if strings.HasPrefix(service, "unix:") {
116116
client = spamc.NewUnix(strings.TrimLeft(service, "unix:"))
117117
} else {
118118
client = spamc.NewTCP(service, timeout)

internal/storage/cron.go

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -61,25 +61,32 @@ func pruneMessages() {
6161

6262
// prune using `--max` if set
6363
if config.MaxMessages > 0 {
64-
q := sqlf.Select("ID, Size").
65-
From(tenant("mailbox")).
66-
OrderBy("Created DESC").
67-
Limit(5000).
68-
Offset(config.MaxMessages)
69-
70-
if err := q.QueryAndClose(context.TODO(), db, func(row *sql.Rows) {
71-
var id string
64+
total := CountTotal()
65+
if total > float64(config.MaxAgeInHours) {
66+
offset := config.MaxMessages
67+
if config.DemoMode {
68+
offset = 500
69+
}
70+
q := sqlf.Select("ID, Size").
71+
From(tenant("mailbox")).
72+
OrderBy("Created DESC").
73+
Limit(5000).
74+
Offset(offset)
75+
76+
if err := q.QueryAndClose(context.TODO(), db, func(row *sql.Rows) {
77+
var id string
78+
79+
if err := row.Scan(&id, &size); err != nil {
80+
logger.Log().Errorf("[db] %s", err.Error())
81+
return
82+
}
83+
ids = append(ids, id)
84+
prunedSize = prunedSize + int64(size)
7285

73-
if err := row.Scan(&id, &size); err != nil {
86+
}); err != nil {
7487
logger.Log().Errorf("[db] %s", err.Error())
7588
return
7689
}
77-
ids = append(ids, id)
78-
prunedSize = prunedSize + int64(size)
79-
80-
}); err != nil {
81-
logger.Log().Errorf("[db] %s", err.Error())
82-
return
8390
}
8491
}
8592

@@ -166,6 +173,10 @@ func pruneMessages() {
166173

167174
logMessagesDeleted(len(ids))
168175

176+
if config.DemoMode {
177+
vacuumDb()
178+
}
179+
169180
websockets.Broadcast("prune", nil)
170181
}
171182

0 commit comments

Comments
 (0)