From e6ab9e1008dc780067785cdf94aeb62831c91e04 Mon Sep 17 00:00:00 2001 From: Ralph Slooten Date: Fri, 6 Jun 2025 17:38:53 +1200 Subject: [PATCH] Fix: Fix sendmail symlink detection for macOS (#514) --- main.go | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/main.go b/main.go index 81eec8c..135ed2e 100644 --- a/main.go +++ b/main.go @@ -1,3 +1,4 @@ +// Package main is the entrypoint package main import ( @@ -10,26 +11,11 @@ import ( ) 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*" + // if the command executable contains "send" in the name (eg: sendmail), then run the sendmail command + if strings.Contains(strings.ToLower(filepath.Base(os.Args[0])), "send") { 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)) -}