mirror of
https://github.com/axllent/mailpit.git
synced 2025-08-13 20:04:49 +02:00
Add undocumented "demonstration mode"
This commit is contained in:
@@ -305,6 +305,9 @@ func initConfigFromEnv() {
|
|||||||
if len(os.Getenv("MP_WEBHOOK_LIMIT")) > 0 {
|
if len(os.Getenv("MP_WEBHOOK_LIMIT")) > 0 {
|
||||||
webhook.RateLimit, _ = strconv.Atoi(os.Getenv("MP_WEBHOOK_LIMIT"))
|
webhook.RateLimit, _ = strconv.Atoi(os.Getenv("MP_WEBHOOK_LIMIT"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Demo mode
|
||||||
|
config.DemoMode = getEnabledFromEnv("MP_DEMO_MODE")
|
||||||
}
|
}
|
||||||
|
|
||||||
// load deprecated settings from environment and warn
|
// load deprecated settings from environment and warn
|
||||||
|
@@ -178,6 +178,9 @@ var (
|
|||||||
|
|
||||||
// DisableHTMLCheck DEPRECATED 2024/04/13 - kept here to display console warning only
|
// DisableHTMLCheck DEPRECATED 2024/04/13 - kept here to display console warning only
|
||||||
DisableHTMLCheck = false
|
DisableHTMLCheck = false
|
||||||
|
|
||||||
|
// DemoMode disables SMTP relay, link checking & HTTP send functionality
|
||||||
|
DemoMode = false
|
||||||
)
|
)
|
||||||
|
|
||||||
// AutoTag struct for auto-tagging
|
// AutoTag struct for auto-tagging
|
||||||
@@ -467,6 +470,12 @@ func VerifyConfig() error {
|
|||||||
logger.Log().Warnf("[relay] auto-relaying all new messages via %s:%d", SMTPRelayConfig.Host, SMTPRelayConfig.Port)
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -61,25 +61,32 @@ func pruneMessages() {
|
|||||||
|
|
||||||
// prune using `--max` if set
|
// prune using `--max` if set
|
||||||
if config.MaxMessages > 0 {
|
if config.MaxMessages > 0 {
|
||||||
q := sqlf.Select("ID, Size").
|
total := CountTotal()
|
||||||
From(tenant("mailbox")).
|
if total > float64(config.MaxAgeInHours) {
|
||||||
OrderBy("Created DESC").
|
offset := config.MaxMessages
|
||||||
Limit(5000).
|
if config.DemoMode {
|
||||||
Offset(config.MaxMessages)
|
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) {
|
if err := q.QueryAndClose(context.TODO(), db, func(row *sql.Rows) {
|
||||||
var id string
|
var id string
|
||||||
|
|
||||||
if err := row.Scan(&id, &size); err != nil {
|
if err := row.Scan(&id, &size); 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())
|
logger.Log().Errorf("[db] %s", err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ids = append(ids, id)
|
|
||||||
prunedSize = prunedSize + int64(size)
|
|
||||||
|
|
||||||
}); err != nil {
|
|
||||||
logger.Log().Errorf("[db] %s", err.Error())
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -166,6 +173,10 @@ func pruneMessages() {
|
|||||||
|
|
||||||
logMessagesDeleted(len(ids))
|
logMessagesDeleted(len(ids))
|
||||||
|
|
||||||
|
if config.DemoMode {
|
||||||
|
vacuumDb()
|
||||||
|
}
|
||||||
|
|
||||||
websockets.Broadcast("prune", nil)
|
websockets.Broadcast("prune", nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -601,6 +601,11 @@ func LinkCheck(w http.ResponseWriter, r *http.Request) {
|
|||||||
// 200: LinkCheckResponse
|
// 200: LinkCheckResponse
|
||||||
// default: ErrorResponse
|
// default: ErrorResponse
|
||||||
|
|
||||||
|
if config.DemoMode {
|
||||||
|
httpError(w, "this functionality has been disabled for demonstration purposes")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
vars := mux.Vars(r)
|
vars := mux.Vars(r)
|
||||||
id := vars["id"]
|
id := vars["id"]
|
||||||
|
|
||||||
|
@@ -37,6 +37,11 @@ func ReleaseMessage(w http.ResponseWriter, r *http.Request) {
|
|||||||
// 200: OKResponse
|
// 200: OKResponse
|
||||||
// default: ErrorResponse
|
// default: ErrorResponse
|
||||||
|
|
||||||
|
if config.DemoMode {
|
||||||
|
httpError(w, "this functionality has been disabled for demonstration purposes")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
vars := mux.Vars(r)
|
vars := mux.Vars(r)
|
||||||
|
|
||||||
id := vars["id"]
|
id := vars["id"]
|
||||||
|
@@ -11,6 +11,7 @@ import (
|
|||||||
"net/mail"
|
"net/mail"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/axllent/mailpit/config"
|
||||||
"github.com/axllent/mailpit/internal/tools"
|
"github.com/axllent/mailpit/internal/tools"
|
||||||
"github.com/axllent/mailpit/server/smtpd"
|
"github.com/axllent/mailpit/server/smtpd"
|
||||||
"github.com/jhillyerd/enmime"
|
"github.com/jhillyerd/enmime"
|
||||||
@@ -141,6 +142,11 @@ func SendMessageHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
// 200: sendMessageResponse
|
// 200: sendMessageResponse
|
||||||
// default: jsonErrorResponse
|
// default: jsonErrorResponse
|
||||||
|
|
||||||
|
if config.DemoMode {
|
||||||
|
httpJSONError(w, "this functionality has been disabled for demonstration purposes")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
decoder := json.NewDecoder(r.Body)
|
decoder := json.NewDecoder(r.Body)
|
||||||
|
|
||||||
data := SendRequest{}
|
data := SendRequest{}
|
||||||
|
Reference in New Issue
Block a user