-
-
Notifications
You must be signed in to change notification settings - Fork 155
/
main.go
35 lines (29 loc) · 775 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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])) ||
!strings.Contains(filepath.Base(os.Args[0]), "sendmail") {
cmd.Execute()
} else {
// symlinked as "*sendmail*"
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))
}