1
0
mirror of https://github.com/axllent/mailpit.git synced 2025-08-13 20:04:49 +02:00

Fix: Normalize running binary name detection (Windows)

This prevents invoking sendmail when the executed name differs from the actual binary name (eg: running `mailpit` instead of `mailpit.exe`). See #14
This commit is contained in:
Ralph Slooten
2022-09-21 15:41:43 +12:00
parent 93665656cf
commit cc9fba7adf

12
main.go
View File

@@ -3,6 +3,7 @@ package main
import ( import (
"os" "os"
"path/filepath" "path/filepath"
"strings"
"github.com/axllent/mailpit/cmd" "github.com/axllent/mailpit/cmd"
sendmail "github.com/axllent/mailpit/sendmail/cmd" sendmail "github.com/axllent/mailpit/sendmail/cmd"
@@ -15,10 +16,19 @@ func main() {
} }
// running directly // running directly
if filepath.Base(exec) == filepath.Base(os.Args[0]) { if normalize(filepath.Base(exec)) == normalize(filepath.Base(os.Args[0])) {
cmd.Execute() cmd.Execute()
} else { } else {
// symlinked // symlinked
sendmail.Run() sendmail.Run()
} }
} }
// Normalize returns a lowercase string stripped of the file extension (if exists).
// Used for detecting Windows commands which ignores letter casing and `.exe`.
// eg: "MaIlpIT.Exe" returns "mailpit"
func normalize(s string) string {
s = strings.ToLower(s)
return strings.TrimSuffix(s, filepath.Ext(s))
}