diff --git a/cmd/root.go b/cmd/root.go index 4f7d3ba..9afd61d 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -1,9 +1,11 @@ +// Package cmd is the main application package cmd import ( "fmt" "os" "strconv" + "strings" "github.com/axllent/mailpit/config" "github.com/axllent/mailpit/server" @@ -109,20 +111,26 @@ func init() { if len(os.Getenv("MP_WEBROOT")) > 0 { config.Webroot = os.Getenv("MP_WEBROOT") } + if len(os.Getenv("MP_USE_MESSAGE_DATES")) > 0 { + v := strings.ToLower(os.Getenv("MP_USE_MESSAGE_DATES")) + config.UseMessageDates = v != "0" && v != "false" && v != "yes" + } // deprecated 2022/08/06 if len(os.Getenv("MP_AUTH_FILE")) > 0 { + fmt.Println("MP_AUTH_FILE has been deprecated, use MP_UI_AUTH_FILE") config.UIAuthFile = os.Getenv("MP_AUTH_FILE") } // deprecated 2022/08/06 if len(os.Getenv("MP_SSL_CERT")) > 0 { + fmt.Println("MP_SSL_CERT has been deprecated, use MP_UI_SSL_CERT") config.UISSLCert = os.Getenv("MP_SSL_CERT") } // deprecated 2022/08/06 if len(os.Getenv("MP_SSL_KEY")) > 0 { + fmt.Println("MP_SSL_KEY has been deprecated, use MP_UI_SSL_KEY") config.UISSLKey = os.Getenv("MP_SSL_KEY") } - // deprecated 2022/08/28 if len(os.Getenv("MP_DATA_DIR")) > 0 { fmt.Println("MP_DATA_DIR has been deprecated, use MP_DATA_FILE") @@ -134,6 +142,7 @@ func init() { rootCmd.Flags().StringVarP(&config.HTTPListen, "listen", "l", config.HTTPListen, "HTTP bind interface and port for UI") rootCmd.Flags().IntVarP(&config.MaxMessages, "max", "m", config.MaxMessages, "Max number of messages to store") rootCmd.Flags().StringVar(&config.Webroot, "webroot", config.Webroot, "Set the webroot for web UI & API") + rootCmd.Flags().BoolVar(&config.UseMessageDates, "use-message-dates", false, "Use message dates as the received dates") rootCmd.Flags().StringVar(&config.UIAuthFile, "ui-auth-file", config.UIAuthFile, "A password file for web UI authentication") rootCmd.Flags().StringVar(&config.UISSLCert, "ui-ssl-cert", config.UISSLCert, "SSL certificate for web UI - requires ui-ssl-key") diff --git a/config/config.go b/config/config.go index 91903c8..ea012a7 100644 --- a/config/config.go +++ b/config/config.go @@ -1,3 +1,4 @@ +// Package config handles the application configuration package config import ( @@ -26,6 +27,9 @@ var ( // MaxMessages is the maximum number of messages a mailbox can have (auto-pruned every minute) MaxMessages = 500 + // UseMessageDates sets the Created date using the message date, not the delivered date + UseMessageDates bool + // VerboseLogging for console output VerboseLogging = false diff --git a/storage/database.go b/storage/database.go index e21ea43..0adcbcc 100644 --- a/storage/database.go +++ b/storage/database.go @@ -201,6 +201,13 @@ func Store(body []byte) (string, error) { Attachments: len(env.Attachments), } + // use message date instead of created date + if config.UseMessageDates { + if mDate, err := env.Date(); err == nil { + obj.Created = mDate + } + } + // generate the search text searchText := createSearchText(env)