1
0
mirror of https://github.com/axllent/mailpit.git synced 2025-07-05 00:48:52 +02:00

Feature: Allow version checking to be disabled (#524)

This commit is contained in:
Ben Edmunds
2025-06-19 11:29:20 +01:00
committed by GitHub
parent 3aae06ff6b
commit 95e3ef6fca
4 changed files with 44 additions and 32 deletions

View File

@ -93,6 +93,7 @@ func init() {
rootCmd.Flags().StringVarP(&config.Database, "database", "d", config.Database, "Database to store persistent data") rootCmd.Flags().StringVarP(&config.Database, "database", "d", config.Database, "Database to store persistent data")
rootCmd.Flags().BoolVar(&config.DisableWAL, "disable-wal", config.DisableWAL, "Disable WAL for local database (allows NFS mounted DBs)") rootCmd.Flags().BoolVar(&config.DisableWAL, "disable-wal", config.DisableWAL, "Disable WAL for local database (allows NFS mounted DBs)")
rootCmd.Flags().BoolVar(&config.DisableVersionCheck, "disable-version-check", config.DisableVersionCheck, "Disable version update checking")
rootCmd.Flags().IntVar(&config.Compression, "compression", config.Compression, "Compression level to store raw messages (0-3)") rootCmd.Flags().IntVar(&config.Compression, "compression", config.Compression, "Compression level to store raw messages (0-3)")
rootCmd.Flags().StringVar(&config.Label, "label", config.Label, "Optional label identify this Mailpit instance") 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().StringVar(&config.TenantID, "tenant-id", config.TenantID, "Database tenant ID to isolate data")
@ -204,6 +205,8 @@ func initConfigFromEnv() {
config.DisableWAL = getEnabledFromEnv("MP_DISABLE_WAL") config.DisableWAL = getEnabledFromEnv("MP_DISABLE_WAL")
config.DisableVersionCheck = getEnabledFromEnv("MP_DISABLE_VERSION_CHECK")
if len(os.Getenv("MP_COMPRESSION")) > 0 { if len(os.Getenv("MP_COMPRESSION")) > 0 {
config.Compression, _ = strconv.Atoi(os.Getenv("MP_COMPRESSION")) config.Compression, _ = strconv.Atoi(os.Getenv("MP_COMPRESSION"))
} }

View File

@ -213,6 +213,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
// DisableVersionCheck disables version checking
DisableVersionCheck bool
// DemoMode disables SMTP relay, link checking & HTTP send functionality // DemoMode disables SMTP relay, link checking & HTTP send functionality
DemoMode = false DemoMode = false
) )

View File

@ -97,32 +97,36 @@ func Load() AppInformation {
info.RuntimeStats.SMTPRejected = smtpRejected info.RuntimeStats.SMTPRejected = smtpRejected
info.RuntimeStats.SMTPIgnored = smtpIgnored info.RuntimeStats.SMTPIgnored = smtpIgnored
mu.RLock() if config.DisableVersionCheck {
cacheValid := time.Now().Before(vCache.expiry) info.LatestVersion = "disabled"
cacheValue := vCache.value
mu.RUnlock()
if cacheValid {
info.LatestVersion = cacheValue
} else { } else {
mu.Lock() mu.RLock()
// Re-check after acquiring write lock in case another goroutine refreshed it cacheValid := time.Now().Before(vCache.expiry)
if time.Now().Before(vCache.expiry) { cacheValue := vCache.value
info.LatestVersion = vCache.value mu.RUnlock()
if cacheValid {
info.LatestVersion = cacheValue
} else { } else {
latest, _, _, err := updater.GithubLatest(config.Repo, config.RepoBinaryName) mu.Lock()
if err == nil { // Re-check after acquiring write lock in case another goroutine refreshed it
vCache = versionCache{value: latest, expiry: time.Now().Add(15 * time.Minute)} if time.Now().Before(vCache.expiry) {
info.LatestVersion = latest info.LatestVersion = vCache.value
} else { } else {
latest, _, _, err := updater.GithubLatest(config.Repo, config.RepoBinaryName)
if err == nil {
vCache = versionCache{value: latest, expiry: time.Now().Add(15 * time.Minute)}
info.LatestVersion = latest
} else {
logger.Log().Errorf("Failed to fetch latest version: %v", err) logger.Log().Errorf("Failed to fetch latest version: %v", err)
vCache.errCount++ vCache.errCount++
vCache.value = "" vCache.value = ""
vCache.expiry = time.Now().Add(getBackoff(vCache.errCount)) vCache.expiry = time.Now().Add(getBackoff(vCache.errCount))
info.LatestVersion = "" info.LatestVersion = ""
}
} }
mu.Unlock()
} }
mu.Unlock()
} }
info.Database = config.Database info.Database = config.Database

View File

@ -91,20 +91,22 @@ export default {
<div class="modal-body"> <div class="modal-body">
<div class="row g-3"> <div class="row g-3">
<div class="col-xl-6"> <div class="col-xl-6">
<div class="row g-3" v-if="mailbox.appInfo.LatestVersion == ''"> <div v-if="mailbox.appInfo.LatestVersion != 'disabled'">
<div class="col"> <div class="row g-3" v-if="mailbox.appInfo.LatestVersion == ''">
<div class="alert alert-warning mb-3"> <div class="col">
There might be a newer version available. The check failed. <div class="alert alert-warning mb-3">
There might be a newer version available. The check failed.
</div>
</div> </div>
</div> </div>
</div> <div class="row g-3"
<div class="row g-3" v-else-if="mailbox.appInfo.Version != mailbox.appInfo.LatestVersion">
v-else-if="mailbox.appInfo.Version != mailbox.appInfo.LatestVersion"> <div class="col">
<div class="col"> <a class="btn btn-warning d-block mb-3"
<a class="btn btn-warning d-block mb-3" :href="'https://github.com/axllent/mailpit/releases/tag/' + mailbox.appInfo.LatestVersion">
:href="'https://github.com/axllent/mailpit/releases/tag/' + mailbox.appInfo.LatestVersion"> A new version of Mailpit ({{ mailbox.appInfo.LatestVersion }}) is available.
A new version of Mailpit ({{ mailbox.appInfo.LatestVersion }}) is available. </a>
</a> </div>
</div> </div>
</div> </div>
<div class="row g-3"> <div class="row g-3">