mirror of
https://github.com/axllent/mailpit.git
synced 2025-08-13 20:04:49 +02:00
Fix: Fix sendmail symlink detection for macOS (#514)
This commit is contained in:
26
main.go
26
main.go
@@ -1,3 +1,4 @@
|
|||||||
|
// Package main is the entrypoint
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@@ -10,26 +11,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
exec, err := os.Executable()
|
// if the command executable contains "send" in the name (eg: sendmail), then run the sendmail command
|
||||||
if err != nil {
|
if strings.Contains(strings.ToLower(filepath.Base(os.Args[0])), "send") {
|
||||||
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()
|
sendmail.Run()
|
||||||
|
} else {
|
||||||
|
// else run mailpit
|
||||||
|
cmd.Execute()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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