From b5caa1355cff83596022952dea9d5ee09c433b73 Mon Sep 17 00:00:00 2001 From: vilmibm Date: Tue, 23 Mar 2021 21:58:17 +0000 Subject: [PATCH] restructure --- email/email.go | 18 ++++++++++++++++++ main.go | 7 +++++++ town.go => user/user.go | 15 +-------------- 3 files changed, 26 insertions(+), 14 deletions(-) create mode 100644 email/email.go create mode 100644 main.go rename town.go => user/user.go (60%) diff --git a/email/email.go b/email/email.go new file mode 100644 index 0000000..0e22961 --- /dev/null +++ b/email/email.go @@ -0,0 +1,18 @@ +package email + +import ( + "bytes" + "fmt" + "os/exec" +) + +func SendLocalEmail(username, subject, body string) error { + cmd := exec.Command("/usr/sbin/sendmail", username) + cmd.Stdin = bytes.NewBufferString(fmt.Sprintf("Subject: %s\n\n%s", subject, body)) + + if err := cmd.Run(); err != nil { + return fmt.Errorf("failed to send local email: %w", err) + } + + return nil +} diff --git a/main.go b/main.go new file mode 100644 index 0000000..2bf02be --- /dev/null +++ b/main.go @@ -0,0 +1,7 @@ +package main + +import "git.tilde.town/tildetown/town/email" + +func main() { + email.SendLocalEmail("vilmibm", "testing hi", "this is a body") +} diff --git a/town.go b/user/user.go similarity index 60% rename from town.go rename to user/user.go index 479c80a..8a7f639 100644 --- a/town.go +++ b/user/user.go @@ -1,9 +1,7 @@ -package town +package user import ( - "bytes" "fmt" - "os/exec" "os/user" ) @@ -28,14 +26,3 @@ func IsAdmin(u user.User) (bool, error) { return false, nil } - -func SendLocalEmail(username, subject, body string) error { - cmd := exec.Command("/usr/sbin/sendmail", "-s", subject, username) - cmd.Stdin = bytes.NewBufferString(body) - - if err := cmd.Run(); err != nil { - return fmt.Errorf("failed to send local email: %w", err) - } - - return nil -}