mirror of
https://github.com/axllent/mailpit.git
synced 2024-12-28 23:06:43 +02:00
cc9fba7adf
This prevents invoking sendmail when the executed name differs from the actual binary name (eg: running `mailpit` instead of `mailpit.exe`). See #14
35 lines
697 B
Go
35 lines
697 B
Go
package main
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
|
|
"github.com/axllent/mailpit/cmd"
|
|
sendmail "github.com/axllent/mailpit/sendmail/cmd"
|
|
)
|
|
|
|
func main() {
|
|
exec, err := os.Executable()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
// running directly
|
|
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))
|
|
}
|