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:
12
main.go
12
main.go
@@ -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))
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user