Documentation
¶
Overview ¶
Package email is the email rendering toolkit: it turns a Markdown body template plus data into the plain-text and HTML parts of a mail, wrapped in the shared layout, and manages the DB-backed, editable per-template overrides. It is deliberately domain- and transport-agnostic: the caller injects the template functions and the JIRA-URL resolver (so shared helpers stay in plexams) and provides a TemplateStore for the overrides. The SMTP sending and the domain data gathering stay in the plexams package.
Index ¶
- func BuildExamPlanningRecipients(withConstraints []*model.ZPAExamWithConstraints, teachers []*model.Teacher, ...) []*model.ExamPlanningMailRecipient
- func BuildKdp(plannedExams []*model.PlannedExam) ([]*KdpSlot, []CsvKdpRoom)
- func DateDE(t time.Time) string
- func EmbeddedSource(name string) (string, error)
- func IsExahmSeb(exam *model.PlannedExam) bool
- func RenderAssembledMarkdown(data any) ([]byte, error)
- func SortPublishedRoomsExams(exams []*PublishedRoomsExam)
- func StudentRegsCSV(regs []*model.EnhancedStudentReg) []byte
- func StudentRegsOfPrimussExams(primussExams []*model.EnhancedPrimussExam) []*model.EnhancedStudentReg
- func TemplateNames() ([]string, error)
- func Templates() embed.FS
- func TimeDE(t time.Time) string
- func WeekdayDE(t time.Time) string
- type Attachment
- type CsvKdpRoom
- type KdpEmail
- type KdpExamInRoom
- type KdpRoom
- type KdpSlot
- type LbaPerson
- type LbaProgram
- type LbaRepeaterEmail
- type LbaRepeaterExam
- type PublishedRoomsEmail
- type PublishedRoomsExam
- type PublishedRoomsRoom
- type PublishedRoomsShared
- type Renderer
- func (r *Renderer) List(ctx context.Context) ([]*model.EmailTemplate, error)
- func (r *Renderer) Render(name string, jira bool, data any) (text []byte, html []byte, err error)
- func (r *Renderer) RenderSource(name, source string, jira bool, data any) (text []byte, html []byte, err error)
- func (r *Renderer) Reset(ctx context.Context, name string) (bool, error)
- func (r *Renderer) Set(ctx context.Context, name, markdown string) (*model.EmailTemplate, error)
- type RoomRequestEmail
- type RoomRequestEmailDay
- type RoomRequestEmailRoom
- type RoomRequestEmailTime
- type SMTPConfig
- type SecretariatRoomsEmail
- type Sender
- func (s *Sender) BeginCollection()
- func (s *Sender) DefaultMail() string
- func (s *Sender) DryRunOverride() (string, bool)
- func (s *Sender) DryRunRecipient() string
- func (s *Sender) EffectiveCc() string
- func (s *Sender) EffectiveNoreplyMail() string
- func (s *Sender) EffectiveNoreplyName() string
- func (s *Sender) EffectiveTestMail() string
- func (s *Sender) FlushCollection() (int, string, error)
- func (s *Sender) RecipientInfo(run bool, recipients ...string) string
- func (s *Sender) ResetDryRunOverride()
- func (s *Sender) Send(run bool, to, cc []string, subject string, text, html []byte, ...) error
- func (s *Sender) SendTest() error
- func (s *Sender) SetDryRunOverride(email string)
- func (s *Sender) SetPlaner(name, email, testMail, cc, noreplyMail, noreplyName string)
- type TemplateStore
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildExamPlanningRecipients ¶ added in v1.213.3
func BuildExamPlanningRecipients( withConstraints []*model.ZPAExamWithConstraints, teachers []*model.Teacher, allExams []*model.ZPAExam, ) []*model.ExamPlanningMailRecipient
BuildExamPlanningRecipients computes the recipients of the consolidated exam-planning info email from already-fetched inputs: one entry per examer with at least one exam I plan (in withConstraints and not NotPlannedByMe, any faculty) listing those exams, plus the active FK07 examers I plan nothing for. Examers of other faculties without a planned exam are excluded. No slot/date is included.
teachers is the local teacher master data (for names/FK/email); allExams is the current ZPA exam set (to know which examers have any exam at all this semester).
func BuildKdp ¶ added in v1.213.3
func BuildKdp(plannedExams []*model.PlannedExam) ([]*KdpSlot, []CsvKdpRoom)
BuildKdp aggregates, for all EXaHM/SEB exams that have a plan entry, the per-slot/room/exam seat allocation. It returns the ordered slot/room/exam view (day/time, then room, then ancode) and the room-oriented CSV rows. Pure over the already-fetched exams; slotTime resolves a plan entry's (day, slot) to its start.
func DateDE ¶ added in v1.213.3
DateDE renders t as e.g. "Mo, 06.07.2026" — the German weekday abbreviation and the date. Used in the room/NTA/KDP/LBA overview emails.
func EmbeddedSource ¶
EmbeddedSource returns the built-in source of a template by name (for the plexams-side attachment rendering and the parse guard).
func IsExahmSeb ¶ added in v1.213.3
func IsExahmSeb(exam *model.PlannedExam) bool
IsExahmSeb reports whether the exam carries an EXaHM or SEB room constraint.
func RenderAssembledMarkdown ¶ added in v1.213.3
RenderAssembledMarkdown renders the standalone "Anmeldungen" Markdown attachment (assembledExamMarkdown.tmpl) for the given assembled-exam mail data.
func SortPublishedRoomsExams ¶ added in v1.213.3
func SortPublishedRoomsExams(exams []*PublishedRoomsExam)
SortPublishedRoomsExams orders the exams chronologically by their slot start (stable).
func StudentRegsCSV ¶ added in v1.213.3
func StudentRegsCSV(regs []*model.EnhancedStudentReg) []byte
StudentRegsCSV renders the student registrations of an exam as the semicolon-separated "Anmeldungen" CSV attachment. The Mtknr is written as an Excel formula (="000123") so Excel/Numbers keep the leading zeros as text. Gender/email come from the ZPA student record when present.
func StudentRegsOfPrimussExams ¶ added in v1.213.3
func StudentRegsOfPrimussExams(primussExams []*model.EnhancedPrimussExam) []*model.EnhancedStudentReg
StudentRegsOfPrimussExams flattens the student registrations across an assembled exam's Primuss sections, in section then registration order.
func TemplateNames ¶
TemplateNames returns the sorted file names of the editable Markdown email body templates (the *.md.tmpl files; the emailBaseHTML/jiraOnHTML layout is not editable).
func Templates ¶
Templates exposes the embedded template FS (for callers that still render a template directly, e.g. the standalone Markdown attachment).
Types ¶
type Attachment ¶
Attachment is a library-neutral mail attachment, so callers do not depend on the concrete mail library (the go-mail dependency stays confined to this package).
type CsvKdpRoom ¶ added in v1.213.3
type CsvKdpRoom struct {
Tag string `csv:"Tag"`
Datum string `csv:"Datum"`
Beginn string `csv:"Beginn"`
Raum string `csv:"Raum"`
Ancode int `csv:"Ancode"`
Modul string `csv:"Modul"`
Erstpruefer string `csv:"Erstprüfer"`
Typ string `csv:"Typ"`
Plaetze int `csv:"Plätze"`
NTAPlaetze int `csv:"davon NTA"`
Reserve int `csv:"Reserve"`
DauerMin int `csv:"Dauer (min)"`
NTADauern string `csv:"NTA-Dauern (min)"`
}
CsvKdpRoom is one row of the room-oriented CSV: per slot, room and exam how many seats (incl. NTA and reserve) the KDP has to configure.
type KdpEmail ¶ added in v1.213.3
type KdpEmail struct {
SemesterName string
PlanerName string
Slots []*KdpSlot // ordered by day/time, then room
}
KdpEmail is the data for the KDP EXaHM/SEB room-overview email.
type KdpExamInRoom ¶ added in v1.213.3
type KdpExamInRoom struct {
Ancode int
Module string
Examer string
Type string // "EXaHM" / "SEB"
Seats int // students actually taking the exam here (normal + NTA)
NtaSeats int // of those, with NTA (extended time)
ReserveSeats int // additional reserve seats (spare)
Detail string // human-readable seat/duration breakdown
}
KdpExamInRoom is one EXaHM/SEB exam's allocation in one room in one slot.
type KdpRoom ¶ added in v1.213.3
type KdpRoom struct {
RoomName string
Exams []*KdpExamInRoom
}
KdpRoom groups the exams running in one room in one slot.
type KdpSlot ¶ added in v1.213.3
type KdpSlot struct {
Date string
Time string
Rooms []*KdpRoom
// contains filtered or unexported fields
}
KdpSlot groups the EXaHM/SEB rooms used in one slot.
type LbaPerson ¶ added in v1.213.3
LbaPerson is a person shown in the LBA-BA email, with their email so the LBA-BA can contact them directly.
type LbaProgram ¶ added in v1.213.3
LbaProgram is a study program with its number of registrations.
type LbaRepeaterEmail ¶ added in v1.213.3
type LbaRepeaterEmail struct {
SemesterName string
PlanerName string
Exams []*LbaRepeaterExam
}
LbaRepeaterEmail is the data for the LBA-BA overview email.
type LbaRepeaterExam ¶ added in v1.213.3
type LbaRepeaterExam struct {
Module string
Examer LbaPerson
Date string
Time string
Invigilators []LbaPerson // unique, in room order
Programs []LbaProgram // programs with registrations (count > 0)
// contains filtered or unexported fields
}
LbaRepeaterExam is one repeat exam of a non-prof (LBA / Prof HC / external) that I planned, reduced to what the Lehrbeauftragten-Beauftragte:r needs: the module, the examer and the invigilators (each with email), when it is, and the programs with registrations.
func BuildLbaRepeaterExams ¶ added in v1.213.3
func BuildLbaRepeaterExams( plannedExams []*model.PlannedExam, examer func(id int) *model.Teacher, invigilatorForRoom func(room string, start time.Time) *model.Teacher, ) []*LbaRepeaterExam
BuildLbaRepeaterExams collects the repeat exams of LBAs (non-profs) that I planned, with their time and invigilators, ordered chronologically. Pure over the already-fetched exams: examer resolves an examer ID to its teacher (nil ⇒ skip the exam, e.g. lookup error); only non-profs are kept. invigilatorForRoom resolves a room in a slot to its invigilator (nil ⇒ skip that room). The exam's start time is its PlanEntry.Starttime.
type PublishedRoomsEmail ¶ added in v1.213.3
type PublishedRoomsEmail struct {
Teacher *model.Teacher
PlanerName string
Exams []*PublishedRoomsExam
}
PublishedRoomsEmail is the data for one examer's "rooms published" email.
type PublishedRoomsExam ¶ added in v1.213.3
type PublishedRoomsExam struct {
Ancode int
Module string
Date string // e.g. "Mo, 13.07.2026"
Time string // e.g. "08:30"
Rooms []*PublishedRoomsRoom
// contains filtered or unexported fields
}
PublishedRoomsExam is one exam of the examer with its rooms and the co-usage.
func BuildPublishedRoomsExam ¶ added in v1.213.3
func BuildPublishedRoomsExam(exam *model.PlannedExam, examsInSlot map[time.Time][]*model.PlannedExam, examerShort func(*model.PlannedExam) string, ) *PublishedRoomsExam
BuildPublishedRoomsExam renders one exam for the examer email: per room the exam's own seat blocks and, grouped per other exam, the co-usage of that room in the same slot. Returns nil if the exam has no plan entry or no real rooms. examsInSlot maps a (day, slot) to all exams placed there (pre-fetched by the caller); examerShort resolves an exam to its examer's short name; slotTime resolves a plan entry to its start.
type PublishedRoomsRoom ¶ added in v1.213.3
type PublishedRoomsRoom struct {
RoomName string
Allocations []string // seat blocks of this room (non-NTA first, then by duration)
}
PublishedRoomsRoom is one room of an exam with its seat blocks and co-usage.
type PublishedRoomsShared ¶ added in v1.213.3
type PublishedRoomsShared struct {
}
PublishedRoomsShared is one other exam sharing a room, with its seat blocks.
type Renderer ¶
type Renderer struct {
// contains filtered or unexported fields
}
Renderer turns Markdown body templates + data into the text and HTML parts of a mail. Template funcs and the JIRA-URL resolver are injected so shared helpers stay in the caller (plexams); overrides come from the injected store (nil = embedded defaults only).
func New ¶
func New(store TemplateStore, funcs map[string]any, jiraURL func() string) *Renderer
New builds a Renderer. store may be nil (then only embedded defaults are used, e.g. in tests). funcs is the template function set; jiraURL resolves the JIRA service-desk URL for the plain-text note (may be nil).
func (*Renderer) List ¶
List returns every editable template with its effective Markdown, whether the built-in default is in use, and the default itself (for preview / reset).
func (*Renderer) Render ¶
Render renders a Markdown body template and returns the plain-text part (the rendered Markdown, readable as-is) and the HTML part (Markdown → HTML wrapped in the shared base layout). The shared chrome (JIRA note / callout, footer) is added here for both parts so they cannot drift.
func (*Renderer) RenderSource ¶ added in v1.214.0
func (r *Renderer) RenderSource(name, source string, jira bool, data any) (text []byte, html []byte, err error)
RenderSource is Render for an explicitly supplied Markdown source (instead of the stored override / embedded default). It is used for the live preview of not-yet-saved edits: the GUI sends the edited Markdown, and it is rendered against representative sample data.
type RoomRequestEmail ¶ added in v1.213.3
type RoomRequestEmail struct {
SemesterName string
PlanerName string
Rooms []*RoomRequestEmailRoom
}
RoomRequestEmail is the data for the Gebäudemanagement room-request email.
type RoomRequestEmailDay ¶ added in v1.213.3
type RoomRequestEmailDay struct {
Date string
Times []*RoomRequestEmailTime
}
RoomRequestEmailDay groups the time ranges of a room on one day.
type RoomRequestEmailRoom ¶ added in v1.213.3
type RoomRequestEmailRoom struct {
Room string
Days []*RoomRequestEmailDay
}
RoomRequestEmailRoom groups the days a room is occupied. Shared by the room-request and the secretariat-rooms emails (room -> days -> time ranges).
func BuildRoomRequestRooms ¶ added in v1.213.3
func BuildRoomRequestRooms(requests []*model.RoomRequest) []*RoomRequestEmailRoom
BuildRoomRequestRooms groups the active room requests by room and then by day, with their (buffered) time ranges. Requests are sorted by room, then by start.
func BuildSecretariatRooms ¶ added in v1.213.3
func BuildSecretariatRooms(plannedRooms []*model.PlannedRoom, roomInfo map[string]*model.Room, ) []*RoomRequestEmailRoom
BuildSecretariatRooms lists, per room that does not have to be requested separately, when it is occupied by an exam. Overlapping times (e.g. caused by NTAs) are merged. roomInfo maps a room name to its master data (a room is skipped when unknown, deactivated, needing a request or an ONLINE pseudo-room). The room's start time is its PlannedRoom.Starttime.
type RoomRequestEmailTime ¶ added in v1.213.3
RoomRequestEmailTime is one time range a room is occupied.
type SMTPConfig ¶
type SMTPConfig struct {
Server string
Port int
Username string
Password string
// Hostname is the fully-qualified name of the sending host, used for the SMTP HELO/EHLO
// greeting and as the Message-ID domain. Without it go-mail derives both from
// os.Hostname() (e.g. "docker-desktop" in a container), which strict mail servers reject
// (554 5.7.1). Empty falls back to defaultMailHostname.
Hostname string
// TestMail receives all dry-run sends (run == false); falls back to PlanerEmail.
TestMail string
// CC is added to the Cc of every real send (a shared/filterable mailbox).
CC string
// ReplyMail is the Reply-To for mails answerable by email; falls back to PlanerEmail.
ReplyMail string
// NoreplyMail is the config-level Reply-To address for JIRA-only mails; when both it
// and the planner override are empty, effectiveNoreplyMail falls back to
// defaultNoreplyMail.
NoreplyMail string
// NoreplyName is the config-level display name for the JIRA-only Reply-To; when both it
// and the planner override are empty, effectiveNoreplyName falls back to
// defaultNoreplyName.
NoreplyName string
// EnvelopeFrom, when set, is the SMTP envelope sender (MAIL FROM / Return-Path),
// decoupled from the visible From header. Use it to send through a shared account
// (e.g. noreply@hm.edu, which must match the SMTP-authenticated user) while keeping
// the planner's address as From. Bounces then go to this address; SPF checks the
// domain here. Empty means go-mail uses the From header as the envelope sender.
EnvelopeFrom string
PlanerName string
PlanerEmail string
}
SMTPConfig holds everything the Sender needs: the SMTP server credentials, the dry-run and Cc/Reply-To addresses, and the planner identity used as From / fallback recipient.
type SecretariatRoomsEmail ¶ added in v1.213.3
type SecretariatRoomsEmail struct {
SemesterName string
PlanerName string
Rooms []*RoomRequestEmailRoom
}
SecretariatRoomsEmail is the data for the rooms-occupancy email to the secretariat: per (non-request) room, on which day at which times it is used by an exam.
type Sender ¶
type Sender struct {
// contains filtered or unexported fields
}
Sender sends mails over SMTP and supports a dry-run collector that bundles a whole batch into one summary mail of .eml attachments.
func NewSender ¶
func NewSender(cfg SMTPConfig) *Sender
NewSender builds a Sender for the given SMTP configuration.
func (*Sender) BeginCollection ¶
func (s *Sender) BeginCollection()
BeginCollection starts capturing dry-run mails (replacing any stale collector). Pair every call with FlushCollection.
func (*Sender) DefaultMail ¶ added in v1.246.0
DefaultMail is the derived default for the dry-run recipient and Cc: the planner email with a +plexams tag (oliver.braun@hm.edu → oliver.braun+plexams@hm.edu). Empty when no valid planner email is set.
func (*Sender) DryRunOverride ¶ added in v1.246.0
DryRunOverride returns the active session override and whether one is set.
func (*Sender) DryRunRecipient ¶ added in v1.246.0
DryRunRecipient is the address all dry-run mails go to: the session override (if set), otherwise the effective test mail (planner override → config → derived default).
func (*Sender) EffectiveCc ¶ added in v1.246.0
EffectiveCc is the Cc added to every real send: planner override → config → DefaultMail.
func (*Sender) EffectiveNoreplyMail ¶ added in v1.246.0
EffectiveNoreplyMail is the JIRA-only Reply-To address: planner override → config → default.
func (*Sender) EffectiveNoreplyName ¶ added in v1.246.0
EffectiveNoreplyName is the JIRA-only Reply-To display name: planner override → config → default.
func (*Sender) EffectiveTestMail ¶ added in v1.246.0
EffectiveTestMail is the address dry-run sends go to: planner override → config → DefaultMail.
func (*Sender) FlushCollection ¶
FlushCollection sends the captured dry-run mails as one summary mail (each attached as an .eml) to the dry-run address, then clears the collector. Returns the number of mails and the recipient. A no-op (count 0) when no collector is active or nothing was captured.
func (*Sender) RecipientInfo ¶
RecipientInfo describes a send for progress/log output; on a dry run it makes explicit that the mail went to the dry-run address only and lists who it would have reached.
func (*Sender) ResetDryRunOverride ¶ added in v1.246.0
func (s *Sender) ResetDryRunOverride()
ResetDryRunOverride clears the session dry-run override, restoring the configured default.
func (*Sender) Send ¶
func (s *Sender) Send(run bool, to, cc []string, subject string, text, html []byte, attachments []*Attachment, jira bool) error
Send sends one mail. jira == true marks a mail answered via JIRA (Reply-To = noreply). On a real send the configured Cc is added. With a dry run (run == false): if a collector is active the mail is captured as .eml, otherwise it goes to the dry-run address with the real recipients prefixed into the subject.
func (*Sender) SetDryRunOverride ¶ added in v1.246.0
SetDryRunOverride redirects dry-run sends to email for this session only; an empty/blank email clears the override (same as ResetDryRunOverride).
func (*Sender) SetPlaner ¶ added in v1.236.0
SetPlaner updates the From identity and the planner-level sender overrides (dry-run recipient, Cc, noreply address/name). The Sender caches its own copy of the planner, so callers must call this whenever the running planner changes (read from the DB, edited in the GUI) — otherwise the From address stays stale/empty. Empty override values fall back to the config value and then the derived default (see the Effective* methods).
type TemplateStore ¶
type TemplateStore interface {
EmailTemplateOverride(ctx context.Context, name string) (string, bool, error)
EmailTemplateOverrides(ctx context.Context) (map[string]string, error)
SetEmailTemplateOverride(ctx context.Context, name, markdown string) error
DeleteEmailTemplateOverride(ctx context.Context, name string) (bool, error)
}
TemplateStore persists per-template Markdown overrides (the editable layer over the embedded defaults). *db.DB satisfies it.