| 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 | "fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/" |
| 22 | "logscip-go gomod github.com/golang/go/src go1.25.0 log/" |
| 23 | "stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/" |
| 24 | |
| 25 | "launchpad.net/email-reminder/internal/configscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/" |
| 26 | "launchpad.net/email-reminder/internal/utilscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/util`/" |
| 27 | ) |
| 28 | |
| 29 | type Userscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/User# struct { |
| 30 | XMLNamescip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/User#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:"email-reminder_user"` |
| 31 | FirstNamescip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/User#FirstName. string `xml:"first_name,omitempty"` |
| 32 | LastNamescip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/User#LastName. string `xml:"last_name,omitempty"` |
| 33 | Emailscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/User#Email. string `xml:"email"` |
| 34 | Eventsscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/User#Events. []Eventscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/Event# `xml:"events>event,omitempty"` |
| 35 | } |
| 36 | |
| 37 | func (u Userscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/User#) ToEmailRecipientscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/User#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# { |
| 38 | 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().(u.Emailscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/User#Email.) |
| 39 | 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 { |
| 40 | 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) |
| 41 | email = "" |
| 42 | } |
| 43 | |
| 44 | 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.: 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().(u.FirstNamescip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/User#FirstName.), LastNamescip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/util`/EmailRecipient#LastName.: 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().(u.LastNamescip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/User#LastName.)} |
| 45 | } |
| 46 | |
| 47 | func LoadUserEventsscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/LoadUserEvents().(filename string, contents []byte, 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#) (Userscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/User#, error) { |
| 48 | v := Userscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/User#{} |
| 49 | err := xmlscip-go gomod github.com/golang/go/src go1.25.0 `encoding/xml`/.Unmarshalscip-go gomod github.com/golang/go/src go1.25.0 `encoding/xml`/Unmarshal().(contents, &v) |
| 50 | if err != nil { |
| 51 | return v, 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().("error parsing XML: %w", err) |
| 52 | } |
| 53 | if len(v.Eventsscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/User#Events.) > conf.MaxEventsPerUserscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#MaxEventsPerUser. { |
| 54 | return v, 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().("too many events (%d), maximum allowed is %d", len(v.Eventsscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/events`/User#Events.), conf.MaxEventsPerUserscip-go gomod launchpad.net/email-reminder . `launchpad.net/email-reminder/internal/config`/Config#MaxEventsPerUser.) |
| 55 | } |
| 56 | return v, nil |
| 57 | } |