| 1 | // # Copyright (C) 2025 Francois Marier |
| 2 | // |
| 3 | // Email-Reminder is free software; you can redistribute it and/or |
| 4 | // modify it under the terms of the GNU General Public License as |
| 5 | // published by the Free Software Foundation; either version 3 of the |
| 6 | // License, or (at your option) any later version. |
| 7 | // |
| 8 | // Email-Reminder is distributed in the hope that it will be useful, |
| 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 11 | // General Public License for more details. |
| 12 | // |
| 13 | // You should have received a copy of the GNU General Public License |
| 14 | // along with Email-Reminder; if not, write to the Free Software |
| 15 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
| 16 | // 02110-1301, USA. |
| 17 | package eventsscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/ |
| 18 | |
| 19 | import ( |
| 20 | "encoding/xmlscip-go gomod github.com/golang/go/src go1.25.0 `encoding/xml`/" |
| 21 | "logscip-go gomod github.com/golang/go/src go1.25.0 log/" |
| 22 | "stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/" |
| 23 | |
| 24 | "launchpad.net/email-reminder/internal/utilscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/util`/" |
| 25 | ) |
| 26 | |
| 27 | type Recipientscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/Recipient# struct { |
| 28 | XMLNamescip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/Recipient#XMLName. xmlscip-go gomod github.com/golang/go/src go1.25.0 `encoding/xml`/.Namescip-go gomod github.com/golang/go/src go1.25.0 `encoding/xml`/Name# `xml:"recipient"` |
| 29 | Namescip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/Recipient#Name. string `xml:"name,attr,omitempty"` |
| 30 | Emailscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/Recipient#Email. string `xml:"email,attr"` |
| 31 | } |
| 32 | |
| 33 | // Splits Name into FirstName/LastName when needed |
| 34 | func (r Recipientscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/Recipient#) ToEmailRecipientscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/Recipient#ToEmailRecipient().() 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# { |
| 35 | email := 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().(r.Emailscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/Recipient#Email.) |
| 36 | if err := utilscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/util`/.ValidateEmailscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/util`/ValidateEmail().(email); err != nil { |
| 37 | 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().("Rejecting invalid email '%s': %s\n", email, err) |
| 38 | email = "" |
| 39 | } |
| 40 | |
| 41 | first := "" |
| 42 | last := "" |
| 43 | name := 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().(r.Namescip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/Recipient#Name.) |
| 44 | if name != "" && len(name) < 255 { // ignore excessively long names |
| 45 | parts := stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Fieldsscip-go gomod github.com/golang/go/src go1.25.0 strings/Fields().(name) |
| 46 | if len(parts) > 0 { |
| 47 | first = parts[0] |
| 48 | } |
| 49 | if len(parts) > 1 { |
| 50 | last = 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().(parts[1:], " ") |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | return 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#{Emailscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/util`/EmailRecipient#Email.: email, FirstNamescip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/util`/EmailRecipient#FirstName.: first, LastNamescip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/util`/EmailRecipient#LastName.: last} |
| 55 | } |