diff --git a/main.go b/main.go index cfbbce4..7371c1f 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,7 @@ package main import ( "os" "path/filepath" + "strings" "github.com/axllent/mailpit/cmd" sendmail "github.com/axllent/mailpit/sendmail/cmd" @@ -15,10 +16,19 @@ func main() { } // running directly - if filepath.Base(exec) == filepath.Base(os.Args[0]) { + if normalize(filepath.Base(exec)) == normalize(filepath.Base(os.Args[0])) { cmd.Execute() } else { // symlinked 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)) +}