1
0
mirror of https://github.com/axllent/mailpit.git synced 2025-02-03 13:12:03 +02:00

Feature: Option to use message dates as received dates (new messages only)

This commit is contained in:
Ralph Slooten 2023-03-10 16:42:14 +13:00
parent dfad730b21
commit a9ce35b741
3 changed files with 21 additions and 1 deletions

View File

@ -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")

View File

@ -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

View File

@ -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)