diff --git a/cmd/root.go b/cmd/root.go index e934408..ccdc950 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -82,6 +82,7 @@ func init() { initConfigFromEnv() rootCmd.Flags().StringVarP(&config.Database, "database", "d", config.Database, "Database to store persistent data") + rootCmd.Flags().StringVar(&config.Label, "label", config.Label, "Optional label identify this Mailpit instance") rootCmd.Flags().StringVar(&config.TenantID, "tenant-id", config.TenantID, "Database tenant ID to isolate data") rootCmd.Flags().IntVarP(&config.MaxMessages, "max", "m", config.MaxMessages, "Max number of messages to store") rootCmd.Flags().BoolVar(&config.UseMessageDates, "use-message-dates", config.UseMessageDates, "Use message dates as the received dates") @@ -172,6 +173,8 @@ func initConfigFromEnv() { config.TenantID = os.Getenv("MP_TENANT_ID") + config.Label = os.Getenv("MP_LABEL") + if len(os.Getenv("MP_MAX_MESSAGES")) > 0 { config.MaxMessages, _ = strconv.Atoi(os.Getenv("MP_MAX_MESSAGES")) } diff --git a/config/config.go b/config/config.go index b0d888c..ceb80bf 100644 --- a/config/config.go +++ b/config/config.go @@ -15,6 +15,7 @@ import ( "github.com/axllent/mailpit/internal/auth" "github.com/axllent/mailpit/internal/logger" "github.com/axllent/mailpit/internal/spamassassin" + "github.com/axllent/mailpit/internal/tools" "gopkg.in/yaml.v3" ) @@ -32,6 +33,10 @@ var ( // allowing multiple isolated instances of Mailpit to share a database. TenantID = "" + // Label to identify this Mailpit instance (optional). + // This gets applied to web UI, SMTP and optional POP3 server. + Label = "" + // MaxMessages is the maximum number of messages a mailbox can have (auto-pruned every minute) MaxMessages = 500 @@ -201,7 +206,9 @@ func VerifyConfig() error { Database = filepath.Join(Database, "mailpit.db") } - TenantID = strings.TrimSpace(TenantID) + Label = tools.Normalize(Label) + + TenantID = tools.Normalize(TenantID) if TenantID != "" { logger.Log().Infof("[db] using tenant \"%s\"", TenantID) re := regexp.MustCompile(`[^a-zA-Z0-9\_]`) diff --git a/internal/tools/utils.go b/internal/tools/utils.go index 2064f6f..d512475 100644 --- a/internal/tools/utils.go +++ b/internal/tools/utils.go @@ -2,6 +2,7 @@ package tools import ( "fmt" + "regexp" "strings" ) @@ -24,3 +25,14 @@ func InArray(k string, arr []string) bool { return false } + +// Normalize will remove any extra spaces, remove newlines, and trim leading and trailing spaces +func Normalize(s string) string { + nlRe := regexp.MustCompile(`\r?\r`) + re := regexp.MustCompile(`\s+`) + + s = nlRe.ReplaceAllString(s, " ") + s = re.ReplaceAllString(s, " ") + + return strings.TrimSpace(s) +} diff --git a/server/apiv1/webui.go b/server/apiv1/webui.go index d3c9a2d..10f86cd 100644 --- a/server/apiv1/webui.go +++ b/server/apiv1/webui.go @@ -12,6 +12,8 @@ import ( // // swagger:model WebUIConfiguration type webUIConfiguration struct { + // Optional label to identify this Mailpit instance + Label string // Message Relay information MessageRelay struct { // Whether message relaying (release) is enabled @@ -53,6 +55,7 @@ func WebUIConfig(w http.ResponseWriter, _ *http.Request) { // default: ErrorResponse conf := webUIConfiguration{} + conf.Label = config.Label conf.MessageRelay.Enabled = config.ReleaseEnabled if config.ReleaseEnabled { conf.MessageRelay.SMTPServer = fmt.Sprintf("%s:%d", config.SMTPRelayConfig.Host, config.SMTPRelayConfig.Port) diff --git a/server/pop3/server.go b/server/pop3/server.go index 92a227c..19e8bb4 100644 --- a/server/pop3/server.go +++ b/server/pop3/server.go @@ -112,7 +112,11 @@ func handleClient(conn net.Conn) { logger.Log().Debugf("[pop3] connection opened by %s", conn.RemoteAddr().String()) // First welcome the new connection - sendResponse(conn, "+OK Mailpit POP3 server") + serverName := "Mailpit" + if config.Label != "" { + serverName = fmt.Sprintf("Mailpit (%s)", config.Label) + } + sendResponse(conn, fmt.Sprintf("+OK %s POP3 server", serverName)) // Set 10 minutes timeout according to RFC1939 timeoutDuration := 600 * time.Second diff --git a/server/smtpd/smtpd.go b/server/smtpd/smtpd.go index 7e60325..06bf334 100644 --- a/server/smtpd/smtpd.go +++ b/server/smtpd/smtpd.go @@ -223,6 +223,10 @@ func listenAndServe(addr string, handler smtpd.MsgIDHandler, authHandler smtpd.A DisableReverseDNS: DisableReverseDNS, } + if config.Label != "" { + srv.Appname = fmt.Sprintf("Mailpit (%s)", config.Label) + } + if config.SMTPAuthAllowInsecure { srv.AuthMechs = map[string]bool{"CRAM-MD5": false, "PLAIN": true, "LOGIN": true} } diff --git a/server/ui-src/App.vue b/server/ui-src/App.vue index 200d917..35e336a 100644 --- a/server/ui-src/App.vue +++ b/server/ui-src/App.vue @@ -14,11 +14,16 @@ export default { }, beforeMount() { - document.title = document.title + ' - ' + location.hostname // load global config this.get(this.resolve('/api/v1/webui'), false, function (response) { mailbox.uiConfig = response.data + + if (mailbox.uiConfig.Label) { + document.title = document.title + ' - ' + mailbox.uiConfig.Label + } else { + document.title = document.title + ' - ' + location.hostname + } }) }, diff --git a/server/ui-src/components/ListMessages.vue b/server/ui-src/components/ListMessages.vue index 6d74582..2d90299 100644 --- a/server/ui-src/components/ListMessages.vue +++ b/server/ui-src/components/ListMessages.vue @@ -133,16 +133,14 @@ export default { {{ getRelativeCreated(message) }}
- {{ - message.From.Name ? - message.From.Name : message.From.Address - }} + + {{ message.From.Name ? message.From.Name : message.From.Address }} +
- {{ - message.From.Name ? - message.From.Name : message.From.Address - }} + + {{ message.From.Name ? message.From.Name : message.From.Address }} +
{{ getPrimaryEmailTo(message) }} diff --git a/server/ui-src/components/NavMailbox.vue b/server/ui-src/components/NavMailbox.vue index 4e4d577..5a11e9a 100644 --- a/server/ui-src/components/NavMailbox.vue +++ b/server/ui-src/components/NavMailbox.vue @@ -68,7 +68,12 @@ export default {