2022-07-29 13:23:08 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2022-09-21 05:41:43 +02:00
|
|
|
"strings"
|
2022-07-29 13:23:08 +02:00
|
|
|
|
|
|
|
"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
|
2022-09-21 05:41:43 +02:00
|
|
|
if normalize(filepath.Base(exec)) == normalize(filepath.Base(os.Args[0])) {
|
2022-07-29 13:23:08 +02:00
|
|
|
cmd.Execute()
|
|
|
|
} else {
|
|
|
|
// symlinked
|
|
|
|
sendmail.Run()
|
|
|
|
}
|
|
|
|
}
|
2022-09-21 05:41:43 +02:00
|
|
|
|
|
|
|
// 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))
|
|
|
|
}
|