Skip to content

Commit

Permalink
Merge branch 'release/v1.20.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
axllent committed Sep 26, 2024
2 parents 4ee3ba4 + 1aed5fd commit 2c326ac
Show file tree
Hide file tree
Showing 15 changed files with 528 additions and 619 deletions.
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.5]

### Chore
- Update node modules
- Use consistent margins for Mailpit label if set
- Improve tag detection in UI
- Improve link detection in the HTML preview

### Fix
- Use correct parameter order in SpamAssassin socket detection ([#364](https://github.com/axllent/mailpit/issues/364))


## [v1.20.4]

### Chore
Expand Down
3 changes: 3 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,9 @@ func initConfigFromEnv() {
if len(os.Getenv("MP_WEBHOOK_LIMIT")) > 0 {
webhook.RateLimit, _ = strconv.Atoi(os.Getenv("MP_WEBHOOK_LIMIT"))
}

// Demo mode
config.DemoMode = getEnabledFromEnv("MP_DEMO_MODE")
}

// load deprecated settings from environment and warn
Expand Down
9 changes: 9 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ var (

// DisableHTMLCheck DEPRECATED 2024/04/13 - kept here to display console warning only
DisableHTMLCheck = false

// DemoMode disables SMTP relay, link checking & HTTP send functionality
DemoMode = false
)

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

if DemoMode {
MaxMessages = 1000
// this deserves a warning
logger.Log().Info("demo mode enabled")
}

return nil
}

Expand Down
4 changes: 2 additions & 2 deletions internal/spamassassin/spamassassin.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func Ping() error {
}

var client *spamc.Client
if strings.HasPrefix("unix:", service) {
if strings.HasPrefix(service, "unix:") {
client = spamc.NewUnix(strings.TrimLeft(service, "unix:"))
} else {
client = spamc.NewTCP(service, timeout)
Expand Down Expand Up @@ -112,7 +112,7 @@ func Check(msg []byte) (Result, error) {
}
} else {
var client *spamc.Client
if strings.HasPrefix("unix:", service) {
if strings.HasPrefix(service, "unix:") {
client = spamc.NewUnix(strings.TrimLeft(service, "unix:"))
} else {
client = spamc.NewTCP(service, timeout)
Expand Down
41 changes: 26 additions & 15 deletions internal/storage/cron.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,25 +61,32 @@ func pruneMessages() {

// prune using `--max` if set
if config.MaxMessages > 0 {
q := sqlf.Select("ID, Size").
From(tenant("mailbox")).
OrderBy("Created DESC").
Limit(5000).
Offset(config.MaxMessages)

if err := q.QueryAndClose(context.TODO(), db, func(row *sql.Rows) {
var id string
total := CountTotal()
if total > float64(config.MaxAgeInHours) {
offset := config.MaxMessages
if config.DemoMode {
offset = 500
}
q := sqlf.Select("ID, Size").
From(tenant("mailbox")).
OrderBy("Created DESC").
Limit(5000).
Offset(offset)

if err := q.QueryAndClose(context.TODO(), db, func(row *sql.Rows) {
var id string

if err := row.Scan(&id, &size); err != nil {
logger.Log().Errorf("[db] %s", err.Error())
return
}
ids = append(ids, id)
prunedSize = prunedSize + int64(size)

if err := row.Scan(&id, &size); err != nil {
}); err != nil {
logger.Log().Errorf("[db] %s", err.Error())
return
}
ids = append(ids, id)
prunedSize = prunedSize + int64(size)

}); err != nil {
logger.Log().Errorf("[db] %s", err.Error())
return
}
}

Expand Down Expand Up @@ -166,6 +173,10 @@ func pruneMessages() {

logMessagesDeleted(len(ids))

if config.DemoMode {
vacuumDb()
}

websockets.Broadcast("prune", nil)
}

Expand Down
Loading

0 comments on commit 2c326ac

Please sign in to comment.