//! The words of every mail iz sends: rule mails, reminders, admin notices and the test mail, in English //! and Turkish. Pure text: no I/O, no HTML (the web layer escapes the plain text when it builds the HTML part). //! //! The strings are keyed by [`K`] and matched exhaustively on `(key, language)`, so a missing translation //! does not compile. Values (names, titles, times) are cleaned with [`clean_text`] before they are placed, //! so no value can add a line to a subject. The brand in every text is the single word `iz`. use jiff::Timestamp; use crate::rules::clean_text; use crate::zones::{parse_zone, utc_to_local}; /// The language a mail is written in: the recipient's own choice, else the directory's, else English. #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum MailLang { /// English. En, /// Turkish. Tr, } impl MailLang { /// The language for a member: `locale_override` first, then the directory `locale`, else English. pub fn of(locale_override: Option<&str>, locale: Option<&str>) -> MailLang { match locale_override.or(locale) { Some("tr") => MailLang::Tr, _ => MailLang::En, } } } /// A subject and a plain-text body, ready to be stored in the outbox. #[derive(Debug, Clone, PartialEq, Eq)] pub struct Mail { /// The subject, plain text, already cleaned and short. pub subject: String, /// The body, plain text with `\n` line breaks. pub body: String, } /// Every fixed string of a mail. Matched exhaustively in [`text`]. #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum K { /// Heading label of the key and title line. Key, /// Label of the column. Column, /// Label of the deadline day. Deadline, /// Label of the assignees. Assignees, /// Label of the meeting time. When, /// Label of the link back to the board. Link, /// Sentence: the task moved to a column. SentStatus, /// Sentence: the task was created. SentCreated, /// Sentence: someone was assigned. SentAssigned, /// Sentence: someone was removed from the assignees. SentUnassigned, /// Sentence: a comment was posted. SentCommented, /// Sentence: a deadline or meeting time was set. SentDeadlineSet, /// Sentence: a deadline or meeting time was cleared. SentDeadlineCleared, /// Sentence: the title changed. SentRetitled, /// Sentence: a dependency was added. SentLinked, /// Sentence: a dependency was removed. SentUnlinked, /// Sentence: the task was deleted. SentDeleted, /// Sentence: the task stopped being blocked. SentUnblocked, /// Subject prefix of a reminder, before the title. ReminderSubject, /// The reminder body's first line, before the meeting time. ReminderLead, /// Subject of the test mail. TestSubject, /// Body of the test mail. TestBody, } /// The text of `key` in `lang`. Exhaustive over both languages. pub fn text(lang: MailLang, key: K) -> &'static str { use MailLang::{En, Tr}; match (key, lang) { (K::Key, En) => "Task", (K::Key, Tr) => "Kart", (K::Column, En) => "Column", (K::Column, Tr) => "Sütun", (K::Deadline, En) => "Deadline", (K::Deadline, Tr) => "Son tarih", (K::Assignees, En) => "Assignees", (K::Assignees, Tr) => "Atananlar", (K::When, En) => "Meeting time", (K::When, Tr) => "Toplantı saati", (K::Link, En) => "Open the task", (K::Link, Tr) => "Kartı aç", (K::SentStatus, En) => "moved the task to the column", (K::SentStatus, Tr) => "kartı sütuna taşıdı", (K::SentCreated, En) => "created the task", (K::SentCreated, Tr) => "kartı oluşturdu", (K::SentAssigned, En) => "assigned", (K::SentAssigned, Tr) => "kişisini atadı", (K::SentUnassigned, En) => "removed the assignment of", (K::SentUnassigned, Tr) => "kişisinin atamasını kaldırdı", (K::SentCommented, En) => "commented on the task", (K::SentCommented, Tr) => "karta yorum yaptı", (K::SentDeadlineSet, En) => "set the deadline or meeting time", (K::SentDeadlineSet, Tr) => "son tarihi veya toplantı saatini belirledi", (K::SentDeadlineCleared, En) => "cleared the deadline or meeting time", (K::SentDeadlineCleared, Tr) => "son tarihi veya toplantı saatini kaldırdı", (K::SentRetitled, En) => "changed the title", (K::SentRetitled, Tr) => "kartın başlığını değiştirdi", (K::SentLinked, En) => "added a dependency", (K::SentLinked, Tr) => "bir bağımlılık ekledi", (K::SentUnlinked, En) => "removed a dependency", (K::SentUnlinked, Tr) => "bir bağımlılığı kaldırdı", (K::SentDeleted, En) => "deleted the task", (K::SentDeleted, Tr) => "kartı sildi", (K::SentUnblocked, En) => "The task is no longer blocked.", (K::SentUnblocked, Tr) => "Kart artık engelli değil.", (K::ReminderSubject, En) => "Reminder:", (K::ReminderSubject, Tr) => "Hatırlatma:", (K::ReminderLead, En) => "A meeting for this task is coming up.", (K::ReminderLead, Tr) => "Bu kart için bir toplantı yaklaşıyor.", (K::TestSubject, En) => "iz test mail", (K::TestSubject, Tr) => "iz deneme e-postası", (K::TestBody, En) => "This is a test mail from iz. No other action follows from it.", (K::TestBody, Tr) => { "Bu, iz uygulamasından bir deneme e-postasıdır. Başka bir işlem yapmaz." } } } /// The meeting time as text in a member's zone: `2026-10-28 14:30 Europe/Istanbul`. Unknown zones are /// shown in UTC with the zone name `UTC`, so the text is never empty for a stored instant. pub fn when_text(stamp: &str, zoneinfo: &str) -> Option { let at: Timestamp = stamp.parse().ok()?; let zone = parse_zone(zoneinfo).ok(); let name = zone .as_ref() .and_then(|z| z.iana_name().map(str::to_owned)) .unwrap_or_else(|| "UTC".to_owned()); let zone = zone.unwrap_or(jiff::tz::TimeZone::UTC); let local = utc_to_local(&zone, at); Some(format!("{} {}", local.strftime("%Y-%m-%d %H:%M"), name)) } /// Everything a rule mail says about one task and one event. pub struct RuleMail<'a> { /// The recipient's language. pub lang: MailLang, /// The trigger word of the event. pub kind: &'a str, /// Who did it, by name. pub actor: &'a str, /// The person the event names, by name (assigned and unassigned events). pub subject_name: &'a str, /// The task key, for example `IZ-42`. pub key: &'a str, /// The task title. pub title: &'a str, /// The column name. pub column: &'a str, /// The deadline day, if any. pub deadline: Option<&'a str>, /// The assignee names, sorted as the store lists them. pub assignees: &'a [String], /// The meeting time in the recipient's zone, if any. pub when: Option<&'a str>, /// The link back to the task. pub link: &'a str, /// Whether the details block is included (the rule's `include_details`). pub details: bool, /// The subject, already rendered from the rule's template. pub subject: &'a str, } /// The body of a rule mail: the event sentence, then the details the rule opts into, then the link. pub fn rule_body(m: &RuleMail<'_>) -> String { let lang = m.lang; let actor = clean_text(m.actor); let subject_name = clean_text(m.subject_name); let sentence = match m.kind { "status" => format!( "{actor} {} {}.", text(lang, K::SentStatus), clean_text(m.column) ), "created" => format!("{actor} {}.", text(lang, K::SentCreated)), "assigned" => format!("{actor} {} {subject_name}.", text(lang, K::SentAssigned)), "unassigned" => format!("{actor} {} {subject_name}.", text(lang, K::SentUnassigned)), "commented" => format!("{actor} {}.", text(lang, K::SentCommented)), "deadline_set" => format!("{actor} {}.", text(lang, K::SentDeadlineSet)), "deadline_cleared" => format!("{actor} {}.", text(lang, K::SentDeadlineCleared)), "retitled" => format!("{actor} {}.", text(lang, K::SentRetitled)), "linked" => format!("{actor} {}.", text(lang, K::SentLinked)), "unlinked" => format!("{actor} {}.", text(lang, K::SentUnlinked)), "deleted" => format!("{actor} {}.", text(lang, K::SentDeleted)), _ => text(lang, K::SentUnblocked).to_owned(), }; let mut lines = vec![ format!( "{}: {} — {}", text(lang, K::Key), clean_text(m.key), clean_text(m.title) ), sentence, ]; if m.details { lines.push(format!( "{}: {}", text(lang, K::Column), clean_text(m.column) )); if let Some(day) = m.deadline { lines.push(format!("{}: {}", text(lang, K::Deadline), clean_text(day))); } let names: Vec = m.assignees.iter().map(|n| clean_text(n)).collect(); if !names.is_empty() { lines.push(format!( "{}: {}", text(lang, K::Assignees), names.join(", ") )); } if let Some(when) = m.when { lines.push(format!("{}: {}", text(lang, K::When), clean_text(when))); } } lines.push(format!("{}: {}", text(lang, K::Link), clean_text(m.link))); lines.join("\n") } /// A reminder for a meeting: subject with the title and key, body with the meeting time in the /// recipient's zone and the link. pub fn reminder(lang: MailLang, key: &str, title: &str, when: &str, link: &str) -> Mail { Mail { subject: clean_text(&format!( "{} {} ({})", text(lang, K::ReminderSubject), title, key )) .chars() .take(crate::limits::MAIL_SUBJECT_MAX) .collect(), body: [ text(lang, K::ReminderLead).to_owned(), format!( "{}: {} — {}", text(lang, K::Key), clean_text(key), clean_text(title) ), format!("{}: {}", text(lang, K::When), clean_text(when)), format!("{}: {}", text(lang, K::Link), clean_text(link)), ] .join("\n"), } } /// The test mail sent to the admin who asks for one. pub fn test_mail(lang: MailLang) -> Mail { Mail { subject: text(lang, K::TestSubject).to_owned(), body: text(lang, K::TestBody).to_owned(), } } #[cfg(test)] mod tests { use super::*; #[test] fn every_key_has_text_in_both_languages() { for key in [ K::Key, K::Column, K::Deadline, K::Assignees, K::When, K::Link, K::TestSubject, ] { assert!(!text(MailLang::En, key).is_empty()); assert!(!text(MailLang::Tr, key).is_empty()); } } #[test] fn the_locale_override_wins_over_the_directory() { assert_eq!(MailLang::of(Some("en"), Some("tr")), MailLang::En); assert_eq!(MailLang::of(None, Some("tr")), MailLang::Tr); assert_eq!(MailLang::of(None, None), MailLang::En); } #[test] fn meeting_time_is_shown_in_the_members_zone() { let text = when_text("2026-10-28T12:00:00.000000000Z", "Europe/Istanbul").unwrap(); assert_eq!(text, "2026-10-28 15:00 Europe/Istanbul"); } }