| 1 | package mainscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/ |
| 2 | |
| 3 | import ( |
| 4 | "encoding/jsonscip-go gomod github.com/golang/go/src go1.25.0 `encoding/json`/" |
| 5 | "fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/" |
| 6 | "logscip-go gomod github.com/golang/go/src go1.25.0 log/" |
| 7 | "net/smtpscip-go gomod github.com/golang/go/src go1.25.0 `net/smtp`/" |
| 8 | "osscip-go gomod github.com/golang/go/src go1.25.0 os/" |
| 9 | "runtimescip-go gomod github.com/golang/go/src go1.25.0 runtime/" |
| 10 | "stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/" |
| 11 | "timescip-go gomod github.com/golang/go/src go1.25.0 time/" |
| 12 | |
| 13 | "launchpad.net/email-reminder/internal/configscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/" |
| 14 | "launchpad.net/email-reminder/internal/eventsscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/" |
| 15 | "launchpad.net/email-reminder/internal/utilscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/util`/" |
| 16 | ) |
| 17 | |
| 18 | type Notifierscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/Notifier# interface { |
| 19 | Sendscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/Notifier#Send.(body, subject string, recipients []utilscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/util`/.EmailRecipientscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/util`/EmailRecipient#) []error |
| 20 | SendDebugscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/Notifier#SendDebug.(now timescip-go gomod github.com/golang/go/src go1.25.0 time/.Timescip-go gomod github.com/golang/go/src go1.25.0 time/Time#, event eventsscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/.Eventscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/Event#, when string, failures []error, defaultRecipient utilscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/util`/.EmailRecipientscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/util`/EmailRecipient#) |
| 21 | } |
| 22 | |
| 23 | type SmtpNotifierscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/SmtpNotifier# struct { |
| 24 | Confscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/SmtpNotifier#Conf. configscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/.Configscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config# |
| 25 | } |
| 26 | |
| 27 | func (n *SmtpNotifierscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/SmtpNotifier#) Sendscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/SmtpNotifier#Send().(body, subject string, recipients []utilscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/util`/.EmailRecipientscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/util`/EmailRecipient#) []error { |
| 28 | var errs []error |
| 29 | |
| 30 | for _, to := range recipients { |
| 31 | fullBody := utilscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/util`/.FullBodyscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/util`/FullBody().(body, to, configscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/.VersionNumberscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/VersionNumber.) |
| 32 | if err := sendEmailscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/sendEmail().(fullBody, subject, to, n.Confscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/SmtpNotifier#Conf.); err != nil { |
| 33 | if n.Confscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/SmtpNotifier#Conf..Verbosescip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#Verbose. { |
| 34 | logscip-go gomod github.com/golang/go/src go1.25.0 log/.Printfscip-go gomod github.com/golang/go/src go1.25.0 log/Printf().("Failed to send reminder to %s: %v", to.NameAndEmailscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/util`/EmailRecipient#NameAndEmail().(), err) |
| 35 | } |
| 36 | errs = append(errs, err) |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | return errs |
| 41 | } |
| 42 | |
| 43 | func (n *SmtpNotifierscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/SmtpNotifier#) SendDebugscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/SmtpNotifier#SendDebug().(now timescip-go gomod github.com/golang/go/src go1.25.0 time/.Timescip-go gomod github.com/golang/go/src go1.25.0 time/Time#, event eventsscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/.Eventscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/Event#, when string, failures []error, defaultRecipient utilscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/util`/.EmailRecipientscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/util`/EmailRecipient#) { |
| 44 | eventName := stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.TrimSpacescip-go gomod github.com/golang/go/src go1.25.0 strings/TrimSpace().(event.Namescip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/Event#Name.) |
| 45 | if eventName == "" { |
| 46 | eventName = event.Stringscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/Event#String().() |
| 47 | } |
| 48 | |
| 49 | occurrenceLine := "Since this event is OCCURRING TODAY, you should really check your reminders manually." |
| 50 | if when != "today" { |
| 51 | occurrenceLine = fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprintf().("Since this event is scheduled for %s, please double-check your reminders manually.", when) |
| 52 | } |
| 53 | |
| 54 | if n.Confscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/SmtpNotifier#Conf..Verbosescip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#Verbose. { |
| 55 | logscip-go gomod github.com/golang/go/src go1.25.0 log/.Printfscip-go gomod github.com/golang/go/src go1.25.0 log/Printf().("Sending debug email to %s for %s", defaultRecipient.Emailscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/util`/EmailRecipient#Email., event) |
| 56 | } |
| 57 | |
| 58 | body := fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprintf().(`WARNING: Due to an error, the email reminder for the event "%s" could not be processed and all I could do was to let you know that there was a problem. |
| 59 | |
| 60 | %s |
| 61 | |
| 62 | Please forward this email to the email-reminder author so that this problem can be fixed in future versions: |
| 63 | |
| 64 | Francois Marier <[email protected]> |
| 65 | |
| 66 | Thanks! |
| 67 | |
| 68 | -------------------------------------------------------------- |
| 69 | %s`, eventName, occurrenceLine, composeDebugInfoscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/composeDebugInfo().(now, event, failures)) |
| 70 | subject := fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprintf().("Email-reminder ERROR: %s", eventName) |
| 71 | |
| 72 | if err := sendEmailscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/sendEmail().(body, subject, defaultRecipient, n.Confscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/SmtpNotifier#Conf.); err != nil { |
| 73 | logscip-go gomod github.com/golang/go/src go1.25.0 log/.Printfscip-go gomod github.com/golang/go/src go1.25.0 log/Printf().("Could not send debug email for %s: %v", event, err) |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | func sendEmailscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/sendEmail().(body string, subject string, recipient utilscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/util`/.EmailRecipientscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/util`/EmailRecipient#, conf configscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/.Configscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#) error { |
| 78 | msg := utilscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/util`/.AssembleRawMessagescip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/util`/AssembleRawMessage().(body, subject, recipient.NameAndEmailscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/util`/EmailRecipient#NameAndEmail().(), conf.MailFromscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#MailFrom., configscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/.VersionNumberscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/VersionNumber.) |
| 79 | if conf.Verbosescip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#Verbose. { |
| 80 | logscip-go gomod github.com/golang/go/src go1.25.0 log/.Printlnscip-go gomod github.com/golang/go/src go1.25.0 log/Println().(msg) |
| 81 | } |
| 82 | if conf.Simulatescip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#Simulate. { |
| 83 | return nil |
| 84 | } |
| 85 | |
| 86 | var auth smtpscip-go gomod github.com/golang/go/src go1.25.0 `net/smtp`/.Authscip-go gomod github.com/golang/go/src go1.25.0 `net/smtp`/Auth# |
| 87 | if conf.SmtpUsernamescip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#SmtpUsername. != "" && conf.SmtpPasswordscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#SmtpPassword. != "" { |
| 88 | auth = smtpscip-go gomod github.com/golang/go/src go1.25.0 `net/smtp`/.PlainAuthscip-go gomod github.com/golang/go/src go1.25.0 `net/smtp`/PlainAuth().("", conf.SmtpUsernamescip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#SmtpUsername., conf.SmtpPasswordscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#SmtpPassword., conf.SmtpServerscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#SmtpServer.) |
| 89 | } |
| 90 | if conf.SmtpSslscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#SmtpSsl. { |
| 91 | if err := utilscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/util`/.SendMailImplicitTLSscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/util`/SendMailImplicitTLS().(conf.SmtpServerscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#SmtpServer., auth, conf.MailFromscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#MailFrom., []string{recipient.Emailscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/util`/EmailRecipient#Email.}, []byte(msg)); err != nil { |
| 92 | return fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Errorf().("could not send '%s' email (TLS) to '%s': %w", subject, recipient.Emailscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/util`/EmailRecipient#Email., err) |
| 93 | } |
| 94 | } else if err := utilscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/util`/.SendMailPlaintextscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/util`/SendMailPlaintext().(conf.SmtpServerscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#SmtpServer., auth, conf.MailFromscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#MailFrom., []string{recipient.Emailscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/util`/EmailRecipient#Email.}, []byte(msg)); err != nil { |
| 95 | return fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Errorf().("could not send '%s' email to '%s': %w", subject, recipient.Emailscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/util`/EmailRecipient#Email., err) |
| 96 | } |
| 97 | return nil |
| 98 | } |
| 99 | |
| 100 | func composeDebugInfoscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/cmd/send-reminders`/composeDebugInfo().(now timescip-go gomod github.com/golang/go/src go1.25.0 time/.Timescip-go gomod github.com/golang/go/src go1.25.0 time/Time#, event eventsscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/.Eventscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/Event#, failures []error) string { |
| 101 | info := []string{ |
| 102 | fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprintf().("Email-reminder: %s", configscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/.VersionNumberscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/VersionNumber.), |
| 103 | fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprintf().("Go: %s (%s/%s)", runtimescip-go gomod github.com/golang/go/src go1.25.0 runtime/.Versionscip-go gomod github.com/golang/go/src go1.25.0 runtime/Version().(), runtimescip-go gomod github.com/golang/go/src go1.25.0 runtime/.GOOSscip-go gomod github.com/golang/go/src go1.25.0 runtime/GOOS., runtimescip-go gomod github.com/golang/go/src go1.25.0 runtime/.GOARCHscip-go gomod github.com/golang/go/src go1.25.0 runtime/GOARCH.), |
| 104 | } |
| 105 | |
| 106 | if hostname, err := osscip-go gomod github.com/golang/go/src go1.25.0 os/.Hostnamescip-go gomod github.com/golang/go/src go1.25.0 os/Hostname().(); err == nil && stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.TrimSpacescip-go gomod github.com/golang/go/src go1.25.0 strings/TrimSpace().(hostname) != "" { |
| 107 | info = append(info, fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprintf().("Hostname: '%s'", hostname)) |
| 108 | } |
| 109 | |
| 110 | if pathVar, ok := osscip-go gomod github.com/golang/go/src go1.25.0 os/.LookupEnvscip-go gomod github.com/golang/go/src go1.25.0 os/LookupEnv().("PATH"); ok { |
| 111 | info = append(info, fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprintf().("PATH: '%q'", pathVar)) |
| 112 | } else { |
| 113 | info = append(info, "PATH: <unset>") |
| 114 | } |
| 115 | |
| 116 | if homeVar, ok := osscip-go gomod github.com/golang/go/src go1.25.0 os/.LookupEnvscip-go gomod github.com/golang/go/src go1.25.0 os/LookupEnv().("HOME"); ok { |
| 117 | info = append(info, fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprintf().("HOME: '%q'", homeVar)) |
| 118 | } else { |
| 119 | info = append(info, "HOME: <unset>") |
| 120 | } |
| 121 | |
| 122 | if output, err := utilscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/util`/.SecureExecCommandscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/util`/SecureExecCommand().("/usr/bin/lsb_release", "-s", "-d"); err == nil { |
| 123 | if trimmed := stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.TrimSpacescip-go gomod github.com/golang/go/src go1.25.0 strings/TrimSpace().(string(output)); trimmed != "" { |
| 124 | info = append(info, fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprintf().("OS: %s", trimmed)) |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | if output, err := utilscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/util`/.SecureExecCommandscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/util`/SecureExecCommand().("/usr/bin/uname", "-a"); err == nil { |
| 129 | if trimmed := stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.TrimSpacescip-go gomod github.com/golang/go/src go1.25.0 strings/TrimSpace().(string(output)); trimmed != "" { |
| 130 | info = append(info, fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprintf().("Kernel: %s", trimmed)) |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | info = append(info, fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprintf().("Time: %s", now.Formatscip-go gomod github.com/golang/go/src go1.25.0 time/Time#Format().(timescip-go gomod github.com/golang/go/src go1.25.0 time/.RFC3339scip-go gomod github.com/golang/go/src go1.25.0 time/RFC3339.))) |
| 135 | info = append(info, "Error(s):") |
| 136 | |
| 137 | for _, failure := range failures { |
| 138 | info = append(info, fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprintf().("- %v", failure)) |
| 139 | } |
| 140 | |
| 141 | if data, err := jsonscip-go gomod github.com/golang/go/src go1.25.0 `encoding/json`/.MarshalIndentscip-go gomod github.com/golang/go/src go1.25.0 `encoding/json`/MarshalIndent().(event, "", " "); err == nil { |
| 142 | info = append(info, "Event:") |
| 143 | info = append(info, string(data)) |
| 144 | } else { |
| 145 | info = append(info, fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprintf().("Event: <unable to serialize: %v>", err)) |
| 146 | } |
| 147 | |
| 148 | return stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Joinscip-go gomod github.com/golang/go/src go1.25.0 strings/Join().(info, "\n") |
| 149 | } |