2026-11-17 18:37:15 +00:00
//! E-mail texts (Hungarian and English), as plain text and HTML.
//!
//! The payloads are written by the backend; the validity periods in the
//! texts match the token lifetimes there. The worker sends the result, the
//! backend renders it for the admin preview.
//!
//! The layout is deliberately plain for spam filters: one column, inline
//! styles, no images, no tracking, every link on the site's own domain, and
//! a plain-text part with the same content.
use serde_json ::Value ;
#[derive(Debug, Clone, PartialEq)]
pub struct Rendered {
pub subject : String ,
pub text : String ,
pub html : String ,
/// One-click unsubscribe address for the `List-Unsubscribe` header (RFC 8058).
pub unsubscribe_post_url : Option < String > ,
}
#[derive(Debug, PartialEq)]
pub enum TemplateError {
UnknownTemplate ( String ),
MissingField ( & 'static str ),
}
impl std ::fmt ::Display for TemplateError {
fn fmt ( & self , f : & mut std ::fmt ::Formatter < '_ > ) -> std ::fmt ::Result {
match self {
TemplateError ::UnknownTemplate ( t ) => write! ( f , "unknown e-mail template '{t}'" ),
TemplateError ::MissingField ( field ) => write! ( f , "e-mail payload has no '{field}'" ),
}
}
}
#[derive(Clone, Copy, PartialEq)]
enum Lang {
Hu ,
En ,
}
/// One e-mail: greeting, paragraphs, a button and a closing note.
struct Content {
subject : String ,
/// The line mail clients show after the subject in the inbox.
preheader : Option < String > ,
greeting : String ,
intro : String ,
/// A personal message, shown as a quote.
quote : Option < String > ,
/// A short list after the intro, with its heading.
points : Option < ( & 'static str , Vec <& 'static str > ) > ,
2026-11-23 20:28:11 +00:00
/// A code to type in, shown large in a box, with its label.
code : Option < ( & 'static str , String ) > ,
2026-11-17 18:37:15 +00:00
button : & 'static str ,
url : String ,
note : String ,
/// Why the recipient got this e-mail (for mails they did not ask for).
reason : Option < String > ,
/// Label and page of the unsubscribe link in the footer.
unsubscribe : Option < ( & 'static str , String ) > ,
unsubscribe_post_url : Option < String > ,
}
impl Content {
fn simple ( subject : String , greeting : String , intro : String , button : & 'static str , url : String , note : & str ) -> Self {
Self {
subject ,
preheader : None ,
greeting ,
intro ,
quote : None ,
points : None ,
button ,
url ,
note : note . to_owned (),
reason : None ,
unsubscribe : None ,
unsubscribe_post_url : None ,
2026-11-23 20:28:11 +00:00
code : None ,
2026-11-17 18:37:15 +00:00
}
}
}
pub fn render ( template : & str , locale : & str , payload : & Value ) -> Result < Rendered , TemplateError > {
let lang = if locale . eq_ignore_ascii_case ( "hu" ) { Lang ::Hu } else { Lang ::En };
let url = field ( payload , "url" ) ? ;
let greeting = | name : Option < String >| match ( lang , name ) {
( Lang ::Hu , Some ( n )) => format! ( "Szia {n} !" ),
( Lang ::Hu , None ) => "Szia!" . to_owned (),
( Lang ::En , Some ( n )) => format! ( "Hi {n} ," ),
( Lang ::En , None ) => "Hi," . to_owned (),
};
let content = match ( template , lang ) {
( "verify_email" , Lang ::Hu ) => Content ::simple (
2026-11-21 18:24:48 +00:00
"Add meg a jelszavad" . into (),
2026-11-17 18:37:15 +00:00
greeting ( name ( payload , "display_name" )),
2026-11-21 18:24:48 +00:00
"Köszönjük, hogy regisztráltál a Sorsfonalakon! Az alábbi gombbal megerősíted az e-mail-címed, és megadhatod a jelszavad. Utána már be is vagy lépve." . into (),
"Jelszó megadása" ,
2026-11-17 18:37:15 +00:00
url ,
2026-11-21 18:24:48 +00:00
"A link 3 napig érvényes, és csak egyszer használható. Ha nem te regisztráltál, nyugodtan hagyd figyelmen kívül ezt a levelet." ,
2026-11-17 18:37:15 +00:00
),
( "verify_email" , Lang ::En ) => Content ::simple (
2026-11-21 18:24:48 +00:00
"Set your password" . into (),
2026-11-17 18:37:15 +00:00
greeting ( name ( payload , "display_name" )),
2026-11-21 18:24:48 +00:00
"Thanks for signing up for Sorsfonalak! The button below confirms your e-mail address and lets you set your password. You will be logged in right after." . into (),
"Set password" ,
2026-11-17 18:37:15 +00:00
url ,
2026-11-21 18:24:48 +00:00
"The link is valid for 3 days and can be used once. If you did not sign up, you can safely ignore this e-mail." ,
),
( "account_exists" , Lang ::Hu ) => Content ::simple (
"Már van fiókod a Sorsfonalakon" . into (),
greeting ( name ( payload , "display_name" )),
"Ezzel az e-mail-címmel regisztrációt kezdtek a Sorsfonalakon, de neked már van fiókod. Beléphetsz úgy, ahogy eddig (például Google-lel), vagy az alábbi gombbal jelszót adhatsz meg." . into (),
"Jelszó megadása" ,
url ,
"A link 1 óráig érvényes, és csak egyszer használható. Ha nem te voltál, hagyd figyelmen kívül ezt a levelet: a fiókod nem változik." ,
),
( "account_exists" , Lang ::En ) => Content ::simple (
"You already have a Sorsfonalak account" . into (),
greeting ( name ( payload , "display_name" )),
"Someone started signing up for Sorsfonalak with this e-mail address, but you already have an account. Log in as before (e.g. with Google), or set a password with the button below." . into (),
"Set password" ,
url ,
"The link is valid for 1 hour and can be used once. If it was not you, ignore this e-mail: your account stays the same." ,
2026-11-17 18:37:15 +00:00
),
( "reset_password" , Lang ::Hu ) => Content ::simple (
"Új jelszó megadása" . into (),
greeting ( name ( payload , "display_name" )),
"Jelszó-visszaállítást kértél a Sorsfonalak-fiókodhoz. Az alábbi gombbal adhatsz meg új jelszót." . into (),
"Új jelszó megadása" ,
url ,
"A link 1 óráig érvényes, és csak egyszer használható. Ha nem te kérted, hagyd figyelmen kívül ezt a levelet: a jelszavad nem változik." ,
),
( "reset_password" , Lang ::En ) => Content ::simple (
"Set a new password" . into (),
greeting ( name ( payload , "display_name" )),
"You asked to reset the password of your Sorsfonalak account. Use the button below to set a new one."
. into (),
"Set a new password" ,
url ,
"The link is valid for 1 hour and can be used once. If you did not ask for this, ignore this e-mail: your password stays the same." ,
),
( "invite_accepted" , Lang ::Hu ) => {
let who = name ( payload , "invitee_name" );
Content ::simple (
match & who {
Some ( n ) => format! ( " {n} elfogadta a meghívásod" ),
None => "Elfogadták a meghívásod" . into (),
},
greeting ( None ),
format! (
" {} elfogadta a „Mennyire illünk össze?” meghívásod, és elkészült a szinasztriátok." ,
who . as_deref (). unwrap_or ( "A meghívott" )
),
"Szinasztria megnyitása" ,
url ,
"A szinasztriát mindketten látjátok, de egymás születési adatait nem." ,
)
}
( "invite_accepted" , Lang ::En ) => {
let who = name ( payload , "invitee_name" );
Content ::simple (
match & who {
Some ( n ) => format! ( " {n} accepted your invitation" ),
None => "Your invitation was accepted" . into (),
},
greeting ( None ),
format! (
" {} accepted your “How compatible are we?” invitation, and your synastry is ready." ,
who . as_deref (). unwrap_or ( "Your invitee" )
),
"Open synastry" ,
url ,
"You both see the synastry, but not each other's birth data." ,
)
}
( "invitation" , _ ) => invitation ( lang , payload , url ) ? ,
2026-11-19 10:12:51 +00:00
( "synastry_invite" , _ ) => synastry_invite ( lang , payload , url ) ? ,
2026-11-19 11:07:13 +00:00
( "waitlist_joined" , _ ) => waitlist_joined ( lang , payload , url ) ? ,
2026-11-20 12:06:10 +00:00
( "purchase_confirmation" , _ ) => purchase_confirmation ( lang , payload , url ) ? ,
2026-11-23 11:20:14 +00:00
( "gift" , _ ) => gift ( lang , payload , url ) ? ,
2026-11-23 20:28:11 +00:00
( "gift_package" , _ ) => gift_package ( lang , payload , url ) ? ,
2026-11-17 18:37:15 +00:00
_ => return Err ( TemplateError ::UnknownTemplate ( template . to_owned ())),
};
Ok ( content . render ( lang ))
}
/// An invitation to the closed site (sent by an administrator).
fn invitation ( lang : Lang , payload : & Value , url : String ) -> Result < Content , TemplateError > {
let inviter = name ( payload , "inviter_name" );
let message = message ( payload );
let until =
payload [ "expires_on" ]. as_str (). and_then ( | d | date ( lang , d )). ok_or ( TemplateError ::MissingField ( "expires_on" )) ? ;
// "2026. december 17." + "-ig" = "2026. december 17-ig"
let until_hu = until . trim_end_matches ( '.' );
let unsubscribe_url = field ( payload , "unsubscribe_url" ) ? ;
let unsubscribe_post_url = field ( payload , "unsubscribe_post_url" ) ? ;
2026-11-19 09:57:01 +00:00
// A package that comes with the invitation, and its promo code.
let gift = name ( payload , "package_name" ). zip (
payload [ "promo_code" ]
. as_str ()
. map ( | c | c . chars (). filter ( | c | c . is_ascii_alphanumeric () || * c == '-' ). take ( 40 ). collect ::< String > ())
. filter ( | c | ! c . is_empty ()),
);
let gift_line = | hu : bool | {
gift . as_ref (). map ( | ( package , code ) | {
if hu {
format! (
" Ajándékba egy „ {package} ” csomagot is kapsz: a regisztrációval magától jóváíródik. Ha mégis kellene, a promókódod: {code} ."
)
} else {
format! (
" You also get the “ {package} ” package as a gift: it is added when you sign up. Should you need it, your promo code is {code} ."
)
}
})
};
2026-11-17 18:37:15 +00:00
Ok ( match lang {
Lang ::Hu => Content {
subject : match & inviter {
Some ( n ) => format! ( " {n} meghívott a Sorsfonalakra" ),
None => "Meghívót kaptál a Sorsfonalakra" . into (),
},
preheader : Some ( format! ( "Születési képlet és rövid elemzés ingyen. A meghívó {until_hu} -ig érvényes." )),
greeting : "Szia!" . into (),
intro : match & inviter {
Some ( n ) => {
format! ( " {n} meghívott a Sorsfonalakra. Az oldal egyelőre zártkörű: csak meghívóval lehet belépni." )
}
None => {
"Meghívót kaptál a Sorsfonalakra. Az oldal egyelőre zártkörű: csak meghívóval lehet belépni." . into ()
}
2026-11-19 09:57:01 +00:00
} + & gift_line ( true ). unwrap_or_default (),
2026-11-17 18:37:15 +00:00
quote : message ,
points : Some ((
"Mit találsz ott?" ,
vec! [
"a születési képleted kiszámolva és megrajzolva, ingyen," ,
"egy rövid, személyre szóló elemzést róla," ,
"összevetést a szeretteiddel: mennyire illetek össze." ,
],
)),
button : "Meghívás elfogadása" ,
url ,
note : format ! (
"A meghívó {until_hu}-ig érvényes. Elfogadáskor Google-fiókkal lépsz be, és ezzel a linkkel bármelyik Google-fiókodat használhatod."
),
reason : Some ( match & inviter {
Some ( n ) => {
format! ( "Ezt a levelet azért kaptad, mert {n} megadta az e-mail-címed a Sorsfonalak meghívójában." )
}
None => {
"Ezt a levelet azért kaptad, mert valaki megadta az e-mail-címed a Sorsfonalak meghívójában." . into ()
}
}),
unsubscribe : Some (( "Nem kérek több meghívót" , unsubscribe_url )),
unsubscribe_post_url : Some ( unsubscribe_post_url ),
2026-11-23 20:28:11 +00:00
code : None ,
2026-11-17 18:37:15 +00:00
},
Lang ::En => Content {
subject : match & inviter {
Some ( n ) => format! ( " {n} invited you to Sorsfonalak" ),
None => "You are invited to Sorsfonalak" . into (),
},
preheader : Some ( format! (
"Your birth chart and a short reading, free. The invitation is valid until {until} ."
)),
greeting : "Hi," . into (),
intro : match & inviter {
Some ( n ) => format! ( " {n} invited you to Sorsfonalak. The site is invitation-only for now." ),
None => "You are invited to Sorsfonalak. The site is invitation-only for now." . into (),
2026-11-19 09:57:01 +00:00
} + & gift_line ( false ). unwrap_or_default (),
2026-11-17 18:37:15 +00:00
quote : message ,
points : Some ((
"What you will find there:" ,
vec! [
"your birth chart, calculated and drawn, for free," ,
"a short, personal reading of it," ,
"comparisons with your loved ones: how well you match." ,
],
)),
button : "Accept the invitation" ,
url ,
note : format ! (
"The invitation is valid until {until}. You sign in with Google, and with this link any of your Google accounts will do."
),
reason : Some ( match & inviter {
Some ( n ) => format! ( "You got this e-mail because {n} entered your address in a Sorsfonalak invitation." ),
None => "You got this e-mail because someone entered your address in a Sorsfonalak invitation." . into (),
}),
unsubscribe : Some (( "No more invitations, please" , unsubscribe_url )),
unsubscribe_post_url : Some ( unsubscribe_post_url ),
2026-11-23 20:28:11 +00:00
code : None ,
2026-11-17 18:37:15 +00:00
},
})
}
fn field ( payload : & Value , name : & 'static str ) -> Result < String , TemplateError > {
payload [ name ]. as_str (). filter ( | u | ! u . is_empty ()). map ( str ::to_owned ). ok_or ( TemplateError ::MissingField ( name ))
}
/// A user-supplied name, safe for a subject line.
fn name ( payload : & Value , field : & str ) -> Option < String > {
let name : String = payload [ field ]. as_str () ? . chars (). filter ( | c | ! c . is_control ()). take ( 60 ). collect ();
let name = name . trim ();
( ! name . is_empty ()). then ( || name . to_owned ())
}
2026-11-20 12:06:10 +00:00
/// The confirmation of a purchase: what was bought, and that the buyer asked
/// for immediate delivery and so gave up the 14-day withdrawal right (the
/// confirmation 45/2014. Korm. rendelet 29. § asks for).
fn purchase_confirmation ( lang : Lang , payload : & Value , url : String ) -> Result < Content , TemplateError > {
let package = name ( payload , "package_name" ). ok_or ( TemplateError ::MissingField ( "package_name" )) ? ;
let amount = field ( payload , "amount" ) ? ;
let contents =
payload [ "contents" ]. as_str (). map ( | c | c . chars (). filter ( | c | ! c . is_control ()). take ( 300 ). collect ::< String > ());
let paid_on =
payload [ "paid_on" ]. as_str (). and_then ( | d | date ( lang , d )). ok_or ( TemplateError ::MissingField ( "paid_on" )) ? ;
let terms_url = field ( payload , "terms_url" ) ? ;
let invoices_url = field ( payload , "invoices_url" ) ? ;
2026-11-24 17:08:17 +00:00
// Gift withdrawals come through the feedback page (easier to handle there).
let feedback_url = format! ( " {} /visszajelzes" , terms_url . trim_end_matches ( "/aszf" ));
2026-11-20 12:06:10 +00:00
let greeting = | hu : bool | match ( hu , name ( payload , "display_name" )) {
( true , Some ( n )) => format! ( "Szia {n} !" ),
( true , None ) => "Szia!" . to_owned (),
( false , Some ( n )) => format! ( "Hi {n} ," ),
( false , None ) => "Hi," . to_owned (),
};
2026-11-23 20:28:11 +00:00
// A package bought as a gift: its code, and where it went (none: the
// buyer hands it over, the card is attached).
let gift = payload [ "gift" ]. is_object (). then ( || {
let code = clean_code ( & payload [ "gift" ][ "promo_code" ]);
let to = payload [ "gift" ][ "recipient_email" ]
. as_str ()
. map ( | e | e . chars (). filter ( | c | ! c . is_control ()). take ( 254 ). collect ::< String > ());
let whom = name ( & payload [ "gift" ], "recipient_name" );
2026-11-24 13:46:35 +00:00
// `2026-12-24 08:00`, Budapest clock: when it is e-mailed.
let when = payload [ "gift" ][ "send_at" ]. as_str (). and_then ( | t | {
let ( day , clock ) = t . split_once ( ' ' ) ? ;
let clock : String = clock . chars (). filter ( | c | c . is_ascii_digit () || * c == ':' ). take ( 5 ). collect ();
Some (( date ( lang , day ) ? , clock ))
});
( code , to , whom , when )
2026-11-23 20:28:11 +00:00
});
let contents_hu = contents . as_ref (). map ( | c | format! ( " Tartalma: {c} ." )). unwrap_or_default ();
let contents_en = contents . as_ref (). map ( | c | format! ( " It contains: {c} ." )). unwrap_or_default ();
Ok ( match ( lang , gift ) {
( Lang ::Hu , None ) => Content {
2026-11-20 12:06:10 +00:00
subject : format ! ( "Köszönjük a vásárlást: {package}" ),
preheader : Some ( format! ( "A(z) {package} csomag a tiéd." )),
greeting : greeting ( true ),
2026-11-23 20:28:11 +00:00
intro : format ! ( "Megkaptuk a fizetésed ({amount}, {paid_on}), és jóváírtuk a(z) „{package}” csomagot.{contents_hu}" ),
2026-11-20 12:06:10 +00:00
quote : Some (
"A fizetés előtt kérted a szolgáltatás azonnali megkezdését, és tudomásul vetted, hogy ezzel elveszíted a 14 napos elállási jogodat. A csomagot ennek megfelelően azonnal teljesítettük."
. into (),
),
points : None ,
2026-11-23 20:28:11 +00:00
code : None ,
2026-11-20 12:06:10 +00:00
button : "Megnézem a csomagjaimat" ,
url ,
note : format ! (
"A számlát külön e-mailben küldjük, és a Számláim oldalon is letöltheted: {invoices_url}. A vásárlás feltételei (ÁSZF): {terms_url}. Ha valami nem működik, írj nekünk az info@sorsfonalak.hu címre."
),
reason : Some ( "Ezt a levelet a vásárlásod visszaigazolásaként kaptad." . into ()),
unsubscribe : None ,
unsubscribe_post_url : None ,
},
2026-11-24 13:46:35 +00:00
( Lang ::Hu , Some (( code , to , whom , when ))) => Content {
2026-11-23 20:28:11 +00:00
subject : format ! ( "Köszönjük a vásárlást: {package} (ajándék)" ),
preheader : Some ( match & to {
2026-11-24 13:46:35 +00:00
Some ( e ) if when . is_some () => format! ( "Az ajándékot időzítve küldjük el ide: {e} ." ),
2026-11-23 20:28:11 +00:00
Some ( e ) => format! ( "Az ajándékot elküldtük ide: {e} ." ),
None => "Az ajándékutalványt csatoltuk ehhez a levélhez." . into (),
}),
greeting : greeting ( true ),
intro : format ! (
"Megkaptuk a fizetésed ({amount}, {paid_on}): a(z) „{package}” csomagot ajándékba vetted{}.{contents_hu} {}" ,
whom . as_ref (). map ( | w | format! ( " {w} részére" )). unwrap_or_default (),
match & to {
2026-11-24 13:46:35 +00:00
Some ( e ) => match & when {
Some (( day , clock )) => format! ( "Az ajándékkódot az utalvánnyal együtt {day} , {clock} -kor küldjük el ide: {e} . Addig az Ajándékaim oldalon letöltheted az utalványt PDF-ben, vagy elküldheted azonnal is." ),
None => format! ( "Az ajándékkódot az utalvánnyal együtt elküldtük ide: {e} . Ha nem e-mailben adnád át, az Ajándékaim oldalon letöltheted az utalványt PDF-ben." ),
},
2026-11-23 20:28:11 +00:00
None => "Az ajándékutalványt PDF-ben csatoltuk ehhez a levélhez, és az Ajándékaim oldalon is letöltheted: kinyomtathatod, vagy továbbküldheted annak, akinek szánod." . into (),
}
),
quote : Some (
2026-11-24 17:08:17 +00:00
format! ( "A vásárlástól számított 14 napon belül, amíg az ajándékkódot nem váltották be, elállhatsz a vásárlástól: írd meg nekünk az oldalon, belépve ( {feedback_url} ), és visszatérítjük az árát. A fizetés előtt kérted, hogy a kód beváltásakor a szolgáltatás azonnal megkezdődjön: a beváltással az elállási jog megszűnik." ),
2026-11-23 20:28:11 +00:00
),
points : None ,
code : code . map ( | c | ( "AJÁNDÉKKÓD" , c )),
button : "Ajándékaim" ,
url ,
note : format ! (
"A kód egyszer váltható be, és nem jár le. A számlát külön e-mailben küldjük, és a Számláim oldalon is letöltheted: {invoices_url}. A vásárlás feltételei (ÁSZF): {terms_url}. Ha valami nem működik, írj nekünk az info@sorsfonalak.hu címre."
),
reason : Some ( "Ezt a levelet a vásárlásod visszaigazolásaként kaptad." . into ()),
unsubscribe : None ,
unsubscribe_post_url : None ,
},
( Lang ::En , None ) => Content {
2026-11-20 12:06:10 +00:00
subject : format ! ( "Thank you for your purchase: {package}" ),
preheader : Some ( format! ( "The {package} package is yours." )),
greeting : greeting ( false ),
intro : format ! ( "We received your payment ({amount}, {paid_on}) and added the “{package}” package to your account." ),
quote : Some (
"Before paying you asked us to start the service at once and acknowledged that you thereby lose your 14-day right of withdrawal. The package was delivered at once accordingly."
. into (),
),
points : None ,
2026-11-23 20:28:11 +00:00
code : None ,
2026-11-20 12:06:10 +00:00
button : "See my packages" ,
url ,
note : format ! (
"The invoice comes in a separate e-mail and can be downloaded on the Invoices page: {invoices_url}. Terms of purchase (ÁSZF): {terms_url}. If something does not work, write to info@sorsfonalak.hu."
),
reason : Some ( "You got this e-mail as the confirmation of your purchase." . into ()),
unsubscribe : None ,
unsubscribe_post_url : None ,
},
2026-11-24 13:46:35 +00:00
( Lang ::En , Some (( code , to , whom , when ))) => Content {
2026-11-23 20:28:11 +00:00
subject : format ! ( "Thank you for your purchase: {package} (gift)" ),
preheader : Some ( match & to {
Some ( e ) => format! ( "We sent the gift to {e} ." ),
None => "The gift card is attached to this e-mail." . into (),
}),
greeting : greeting ( false ),
intro : format ! (
"We received your payment ({amount}, {paid_on}): you bought the “{package}” package as a gift{}.{contents_en} {}" ,
whom . as_ref (). map ( | w | format! ( " for {w} " )). unwrap_or_default (),
match & to {
2026-11-24 13:46:35 +00:00
Some ( e ) => match & when {
Some (( day , clock )) => format! ( "We send the gift code with the gift card to {e} on {day} at {clock} . Until then you can download the card on the My gifts page, or send it at once." ),
None => format! ( "We sent the gift code with the gift card to {e} . To hand it over another way, download the card as a PDF on the My gifts page." ),
},
2026-11-23 20:28:11 +00:00
None => "The gift card is attached to this e-mail as a PDF, and you can download it on the My gifts page: print it, or forward it to the person it is for." . into (),
}
),
quote : Some (
2026-11-24 17:08:17 +00:00
format! ( "Within 14 days of the purchase, while the gift code is not redeemed, you may withdraw from the purchase: tell us on the site, logged in ( {feedback_url} ), and we refund it. Before paying you asked for the service to start as soon as the code is redeemed: redeeming it ends the right of withdrawal." ),
2026-11-23 20:28:11 +00:00
),
points : None ,
code : code . map ( | c | ( "GIFT CODE" , c )),
button : "My gifts" ,
url ,
note : format ! (
"The code can be redeemed once and does not expire. The invoice comes in a separate e-mail and can be downloaded on the Invoices page: {invoices_url}. Terms of purchase (ÁSZF): {terms_url}. If something does not work, write to info@sorsfonalak.hu."
),
reason : Some ( "You got this e-mail as the confirmation of your purchase." . into ()),
unsubscribe : None ,
unsubscribe_post_url : None ,
},
})
}
/// A promo code from a payload, as shown: letters, digits and dashes only.
fn clean_code ( value : & Value ) -> Option < String > {
value
. as_str ()
. map ( | c | c . chars (). filter ( | c | c . is_ascii_alphanumeric () || * c == '-' ). take ( 40 ). collect ::< String > ())
. filter ( | c | ! c . is_empty ())
}
/// A package someone bought for the recipient: who sends it, their message,
/// the code and its redeem link (the worker attaches the gift card as a PDF).
fn gift_package ( lang : Lang , payload : & Value , url : String ) -> Result < Content , TemplateError > {
let package = name ( payload , "package_name" ). ok_or ( TemplateError ::MissingField ( "package_name" )) ? ;
let code = clean_code ( & payload [ "promo_code" ]). ok_or ( TemplateError ::MissingField ( "promo_code" )) ? ;
let contents =
payload [ "contents" ]. as_str (). map ( | c | c . chars (). filter ( | c | ! c . is_control ()). take ( 300 ). collect ::< String > ());
let from = name ( payload , "from_name" );
let to = name ( payload , "recipient_name" );
2026-11-24 13:46:35 +00:00
// Bought for Christmas: said so, with the wishes.
let christmas = payload [ "christmas_year" ]. as_i64 (). is_some ();
let xmas = if christmas { "karácsonyi " } else { "" };
2026-11-23 20:28:11 +00:00
Ok ( match lang {
Lang ::Hu => Content {
subject : match & from {
2026-11-24 13:46:35 +00:00
Some ( f ) => format! ( " {f} {xmas} ajándékot küldött neked: „ {package} ” csomag" ),
None if christmas => format! ( "Karácsonyi ajándékot kaptál: „ {package} ” csomag a Sorsfonalakon" ),
2026-11-23 20:28:11 +00:00
None => format! ( "Ajándékot kaptál: „ {package} ” csomag a Sorsfonalakon" ),
},
preheader : Some ( "Születési képlet és személyre szóló elemzések: a kód beváltásával a tiéd." . into ()),
greeting : to . as_ref (). map_or_else ( || "Szia!" . into (), | t | format! ( "Szia {t} !" )),
intro : format ! (
2026-11-24 13:46:35 +00:00
"{}{} egy „{package}” csomagot a Sorsfonalakon.{}" ,
if christmas { "Boldog karácsonyt! " } else { "" },
2026-11-23 20:28:11 +00:00
match & from {
Some ( f ) => format! ( " {f} ajándékozott neked" ),
None => "Ajándékba kaptál" . into (),
},
contents . map ( | c | format! ( " Tartalma: {c} ." )). unwrap_or_default ()
),
quote : message ( payload ),
code : Some (( "AJÁNDÉKKÓD" , code )),
points : Some ((
"Így váltod be:" ,
vec! [
"kattints a gombra, és lépj be, vagy regisztrálj, ha még nincs fiókod;" ,
"a kód már ki lesz töltve, csak a beváltásra kell kattintanod;" ,
"utána a csomag a tiéd: elkészítheted a képleted és az elemzéseidet." ,
],
)),
button : "Ajándék beváltása" ,
url ,
note : "A kód egyszer váltható be, és nem jár le. Az ajándékutalványt PDF-ben is csatoltuk: kinyomtathatod vagy elteheted." . into (),
reason : Some ( match & from {
Some ( f ) => format! ( "Ezt a levelet azért kaptad, mert {f} a Sorsfonalakon ajándékot vásárolt neked erre a címre." ),
None => "Ezt a levelet azért kaptad, mert valaki a Sorsfonalakon ajándékot vásárolt neked erre a címre." . into (),
}),
unsubscribe : None ,
unsubscribe_post_url : None ,
},
Lang ::En => Content {
subject : match & from {
2026-11-24 13:46:35 +00:00
Some ( f ) if christmas => format! ( " {f} sent you a Christmas gift: the “ {package} ” package" ),
2026-11-23 20:28:11 +00:00
Some ( f ) => format! ( " {f} sent you a gift: the “ {package} ” package" ),
None => format! ( "A gift for you: the “ {package} ” package on Sorsfonalak" ),
},
preheader : Some ( "Your birth chart and personal readings: redeem the code and they are yours." . into ()),
greeting : to . as_ref (). map_or_else ( || "Hi," . into (), | t | format! ( "Hi {t} ," )),
intro : format ! (
"{} the “{package}” package on Sorsfonalak.{}" ,
match & from {
Some ( f ) => format! ( " {f} gave you" ),
None => "You got" . into (),
},
contents . map ( | c | format! ( " It contains: {c} ." )). unwrap_or_default ()
),
quote : message ( payload ),
code : Some (( "GIFT CODE" , code )),
points : Some ((
"How to redeem it:" ,
vec! [
"click the button and log in, or sign up if you have no account yet;" ,
"the code is filled in for you: just click Redeem;" ,
"the package is yours: make your chart and your readings." ,
],
)),
button : "Redeem the gift" ,
url ,
note : "The code can be redeemed once and does not expire. The gift card is attached as a PDF: print it or keep it." . into (),
reason : Some ( match & from {
Some ( f ) => format! ( "You got this e-mail because {f} bought you a gift on Sorsfonalak for this address." ),
None => "You got this e-mail because someone bought you a gift on Sorsfonalak for this address." . into (),
}),
unsubscribe : None ,
unsubscribe_post_url : None ,
},
2026-11-20 12:06:10 +00:00
})
}
2026-11-19 11:07:13 +00:00
/// The confirmation of a waitlist sign-up, with the link that takes the address off the list.
2026-11-23 11:20:14 +00:00
/// Something an administrator gave the user: a package or single units.
/// `gift` says what (e.g. "a(z) „Páros” csomagot", "2 kérdést"), `contents`
/// what a package holds.
fn gift ( lang : Lang , payload : & Value , url : String ) -> Result < Content , TemplateError > {
let clean = | s : & str | s . chars (). filter ( | c | ! c . is_control ()). take ( 300 ). collect ::< String > ();
let what = payload [ "gift" ]. as_str (). map ( clean ). filter ( | s | ! s . trim (). is_empty ());
let what = what . ok_or ( TemplateError ::MissingField ( "gift" )) ? ;
let contents = payload [ "contents" ]. as_str (). map ( clean ). filter ( | s | ! s . trim (). is_empty ());
let greeting = match ( lang , name ( payload , "display_name" )) {
( Lang ::Hu , Some ( n )) => format! ( "Szia {n} !" ),
( Lang ::Hu , None ) => "Szia!" . to_owned (),
( Lang ::En , Some ( n )) => format! ( "Hi {n} ," ),
( Lang ::En , None ) => "Hi," . to_owned (),
};
Ok ( match lang {
Lang ::Hu => Content {
subject : "Ajándékot kaptál a Sorsfonalaktól" . into (),
preheader : Some ( format! ( "Jóváírtuk {what} ." )),
greeting ,
intro : format ! (
"Ajándékba kaptad {what}, és már jóvá is írtuk a fiókodban.{} Rögtön felhasználhatod, nem jár le." ,
contents . map ( | c | format! ( " Tartalma: {c} ." )). unwrap_or_default ()
),
quote : None ,
points : None ,
button : "Megnézem" ,
url ,
note : "Ha kérdésed van, írj nekünk az info@sorsfonalak.hu címre." . into (),
reason : Some ( "Ezt a levelet azért kaptad, mert ajándékot írtunk jóvá a Sorsfonalak-fiókodban." . into ()),
unsubscribe : None ,
unsubscribe_post_url : None ,
2026-11-23 20:28:11 +00:00
code : None ,
2026-11-23 11:20:14 +00:00
},
Lang ::En => Content {
subject : "A gift from Sorsfonalak" . into (),
preheader : Some ( format! ( "Added to your account: {what} ." )),
greeting ,
intro : format ! (
"You got {what} as a gift, already added to your account.{} You can use it right away; it does not expire." ,
contents . map ( | c | format! ( " It contains: {c} ." )). unwrap_or_default ()
),
quote : None ,
points : None ,
button : "Take a look" ,
url ,
note : "If you have a question, write to info@sorsfonalak.hu." . into (),
reason : Some ( "You got this e-mail because a gift was added to your Sorsfonalak account." . into ()),
unsubscribe : None ,
unsubscribe_post_url : None ,
2026-11-23 20:28:11 +00:00
code : None ,
2026-11-23 11:20:14 +00:00
},
})
}
2026-11-19 11:07:13 +00:00
fn waitlist_joined ( lang : Lang , payload : & Value , url : String ) -> Result < Content , TemplateError > {
let unsubscribe_url = field ( payload , "unsubscribe_url" ) ? ;
let unsubscribe_post_url = field ( payload , "unsubscribe_post_url" ) ? ;
Ok ( match lang {
Lang ::Hu => Content {
subject : "Felírtunk a Sorsfonalak várólistájára" . into (),
preheader : Some ( "Amint bejuthatsz, ide írunk." . into ()),
greeting : "Szia!" . into (),
intro : "Köszönjük, hogy kíváncsi vagy a Sorsfonalakra! Az oldal egyelőre zártkörű, de felírtunk a várólistára: amint bejuthatsz, erre a címre írunk."
. into (),
quote : None ,
points : Some ((
"Mi vár rád?" ,
vec! [
"a születési képleted percre pontosan kiszámolva és megrajzolva, egy rövid elemzéssel," ,
"részletes elemzés, éves előrejelzés és kapcsolati összevetés azokkal, akiket szeretsz." ,
],
)),
button : "Körülnézek" ,
url ,
note : "Ha nem te iratkoztál fel, vagy meggondoltad magad, a lenti linkkel törölheted a címed a listáról." . into (),
reason : Some ( "Ezt a levelet azért kaptad, mert ezt a címet megadták a Sorsfonalak várólistáján." . into ()),
unsubscribe : Some (( "Leiratkozás a várólistáról" , unsubscribe_url )),
unsubscribe_post_url : Some ( unsubscribe_post_url ),
2026-11-23 20:28:11 +00:00
code : None ,
2026-11-19 11:07:13 +00:00
},
Lang ::En => Content {
subject : "You are on the Sorsfonalak waitlist" . into (),
preheader : Some ( "We will write as soon as you can get in." . into ()),
greeting : "Hi," . into (),
intro : "Thanks for your interest in Sorsfonalak! The site is invitation-only for now, but you are on the waitlist: we will write to this address as soon as you can get in."
. into (),
quote : None ,
points : Some ((
"What awaits you:" ,
vec! [
"your birth chart, calculated to the minute and drawn, with a short reading," ,
"detailed readings, a yearly forecast and comparisons with the people you love." ,
],
)),
button : "Take a look" ,
url ,
note : "If it was not you, or you changed your mind, the link below takes your address off the list." . into (),
reason : Some ( "You got this e-mail because this address was entered on the Sorsfonalak waitlist." . into ()),
unsubscribe : Some (( "Leave the waitlist" , unsubscribe_url )),
unsubscribe_post_url : Some ( unsubscribe_post_url ),
2026-11-23 20:28:11 +00:00
code : None ,
2026-11-19 11:07:13 +00:00
},
})
}
2026-11-19 10:12:51 +00:00
/// A user invites someone to compare their charts ("how compatible are we?").
fn synastry_invite ( lang : Lang , payload : & Value , url : String ) -> Result < Content , TemplateError > {
let inviter = name ( payload , "inviter_name" );
let message = message ( payload );
let until =
payload [ "expires_on" ]. as_str (). and_then ( | d | date ( lang , d )). ok_or ( TemplateError ::MissingField ( "expires_on" )) ? ;
let until_hu = until . trim_end_matches ( '.' );
let unsubscribe_url = field ( payload , "unsubscribe_url" ) ? ;
let unsubscribe_post_url = field ( payload , "unsubscribe_post_url" ) ? ;
Ok ( match lang {
Lang ::Hu => {
let who = inviter . clone (). unwrap_or_else ( || "Valaki" . into ());
Content {
subject : format ! ( "{who} kíváncsi, mennyire illetek össze" ),
preheader : Some ( format! (
"Születési képletek összevetése a Sorsfonalakon. A meghívó {until_hu} -ig érvényes."
)),
greeting : "Szia!" . into (),
intro : format ! (
"{who} szeretné összevetni a születési képleteteket a Sorsfonalakon, és megnézni, mennyire illetek össze."
),
quote : message ,
points : Some ((
"Mit kapsz?" ,
vec! [
"a saját születési képleted kiszámolva és megrajzolva, egy rövid elemzéssel, ingyen," ,
"a kettőtök összevetését: hol erős és hol kényes a kapcsolatotok." ,
],
)),
button : "Megnézem" ,
url ,
note : format ! (
"A meghívó {until_hu}-ig érvényes. Google-fiókkal lépsz be. A születési adataidat {who} nem látja, csak az összevetést."
),
reason : Some ( format! (
"Ezt a levelet azért kaptad, mert {who} megadta az e-mail-címed a Sorsfonalakon."
)),
unsubscribe : Some (( "Nem kérek több meghívót" , unsubscribe_url )),
unsubscribe_post_url : Some ( unsubscribe_post_url ),
2026-11-23 20:28:11 +00:00
code : None ,
2026-11-19 10:12:51 +00:00
}
}
Lang ::En => {
let who = inviter . clone (). unwrap_or_else ( || "Someone" . into ());
Content {
subject : format ! ( "{who} wonders how well you match" ),
preheader : Some ( format! (
"Comparing birth charts on Sorsfonalak. The invitation is valid until {until} ."
)),
greeting : "Hi," . into (),
intro : format ! (
"{who} would like to compare your birth charts on Sorsfonalak and see how well you match."
),
quote : message ,
points : Some ((
"What you get:" ,
vec! [
"your own birth chart, calculated and drawn, with a short reading, for free," ,
"the comparison of the two of you: where your relationship is strong and where it is delicate." ,
],
)),
button : "Take a look" ,
url ,
note : format ! (
"The invitation is valid until {until}. You sign in with Google. {who} does not see your birth data, only the comparison."
),
reason : Some ( format! ( "You got this e-mail because {who} entered your address on Sorsfonalak." )),
unsubscribe : Some (( "No more invitations, please" , unsubscribe_url )),
unsubscribe_post_url : Some ( unsubscribe_post_url ),
2026-11-23 20:28:11 +00:00
code : None ,
2026-11-19 10:12:51 +00:00
}
}
})
}
2026-11-17 18:37:15 +00:00
/// The personal message of an invitation: line breaks kept, other control characters dropped.
fn message ( payload : & Value ) -> Option < String > {
let text : String =
payload [ "message" ]. as_str () ? . chars (). filter ( | c | * c == '\n' || ! c . is_control ()). take ( 500 ). collect ();
let text = text . trim ();
( ! text . is_empty ()). then ( || text . to_owned ())
}
/// `2026-12-17` as "2026. december 17." or "17 December 2026".
fn date ( lang : Lang , iso : & str ) -> Option < String > {
const HU : [ & str ; 12 ] = [
"január" ,
"február" ,
"március" ,
"április" ,
"május" ,
"június" ,
"július" ,
"augusztus" ,
"szeptember" ,
"október" ,
"november" ,
"december" ,
];
const EN : [ & str ; 12 ] = [
"January" ,
"February" ,
"March" ,
"April" ,
"May" ,
"June" ,
"July" ,
"August" ,
"September" ,
"October" ,
"November" ,
"December" ,
];
let mut parts = iso . splitn ( 3 , '-' );
let ( y , m , d ) = ( parts . next () ? , parts . next () ? , parts . next () ? );
let ( y , m , d ) : ( u32 , usize , u32 ) = ( y . parse (). ok () ? , m . parse (). ok () ? , d . get ( .. 2 ) ? . parse (). ok () ? );
let month = m . checked_sub ( 1 ). filter ( |& i | i < 12 ) ? ;
Some ( match lang {
Lang ::Hu => format! ( " {y} . {} {d} ." , HU [ month ]),
Lang ::En => format! ( " {d} {} {y} " , EN [ month ]),
})
}
fn escape ( s : & str ) -> String {
let mut out = String ::with_capacity ( s . len ());
for c in s . chars () {
match c {
'&' => out . push_str ( "&" ),
'<' => out . push_str ( "<" ),
'>' => out . push_str ( ">" ),
'"' => out . push_str ( """ ),
'\'' => out . push_str ( "'" ),
_ => out . push ( c ),
}
}
out
}
const TEXT : & str = "#2a2620" ;
const MUTED : & str = "#6b645a" ;
const FAINT : & str = "#9b948a" ;
const GOLD : & str = "#9a7b3c" ;
impl Content {
fn render ( self , lang : Lang ) -> Rendered {
let footer = match lang {
Lang ::Hu => "Ezt a levelet a Sorsfonalak küldte." ,
Lang ::En => "This e-mail was sent by Sorsfonalak." ,
};
let mut text = format! ( " {} \n\n {} \n\n " , self . greeting , self . intro );
if let Some ( q ) = & self . quote {
for line in q . lines () {
text . push_str ( & format! ( "> {line} \n " ));
}
text . push ( '\n' );
}
2026-11-23 20:28:11 +00:00
if let Some (( label , code )) = & self . code {
text . push_str ( & format! ( " {label} : {code} \n\n " ));
}
2026-11-17 18:37:15 +00:00
if let Some (( heading , items )) = & self . points {
text . push_str ( heading );
text . push ( '\n' );
for item in items {
text . push_str ( & format! ( "- {item} \n " ));
}
text . push ( '\n' );
}
text . push_str ( & format! ( " {} : \n {} \n\n {} \n\n -- \n Sorsfonalak \n " , self . button , self . url , self . note ));
if let Some ( reason ) = & self . reason {
text . push_str ( & format! ( " \n {reason} \n " ));
}
if let Some (( label , url )) = & self . unsubscribe {
text . push_str ( & format! ( " {label} : {url} \n " ));
}
let preheader = self . preheader . as_deref (). map_or ( String ::new (), | p | {
format! (
r #"<div style="display:none;max-height:0;overflow:hidden;opacity:0;color:transparent">{}</div>"# ,
escape ( p )
)
});
let quote = self . quote . as_deref (). map_or ( String ::new (), | q | {
format! (
r #"<tr><td style="padding-bottom:24px"><div style="border-left:3px solid {GOLD};padding:4px 0 4px 16px;font-size:16px;line-height:1.6;font-style:italic;color:{TEXT}">{}</div></td></tr>
"# ,
escape ( q ). replace ( '\n' , "<br>" )
)
});
let points = self . points . as_ref (). map_or ( String ::new (), | ( heading , items ) | {
let items : String = items
. iter ()
. map ( | i | format! ( r #"<li style="margin:0 0 6px">{}</li>"# , escape ( i )))
. collect ();
format! (
r #"<tr><td style="font-size:16px;line-height:1.6;padding-bottom:24px">{}<ul style="margin:8px 0 0;padding-left:20px">{items}</ul></td></tr>
"# ,
escape ( heading )
)
});
2026-11-23 20:28:11 +00:00
let code = self . code . as_ref (). map_or ( String ::new (), | ( label , code ) | {
format! (
r #"<tr><td style="padding-bottom:24px"><div style="border:1px solid {GOLD};border-radius:8px;padding:14px 18px;text-align:center"><div style="font-size:12px;letter-spacing:2px;color:{GOLD}">{}</div><div style="font-family:'Courier New',Courier,monospace;font-size:24px;font-weight:bold;letter-spacing:2px;color:{TEXT};padding-top:6px">{}</div></div></td></tr>
"# ,
escape ( label ),
escape ( code )
)
});
2026-11-17 18:37:15 +00:00
let mut small = Vec ::new ();
if let Some ( reason ) = & self . reason {
small . push ( escape ( reason ));
}
if let Some (( label , url )) = & self . unsubscribe {
small . push ( format! ( r #"<a href="{}" style="color:{FAINT}">{}</a>"# , escape ( url ), escape ( label )));
}
small . push ( escape ( footer ));
let small = small . join ( "<br>" );
let html = format! (
r #"<!doctype html>
<html lang="{lang}">
<head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>{subject}</title></head>
<body style="margin:0;padding:0;background:#f4f1ea;font-family:Georgia,'Times New Roman',serif;color:{TEXT}">
{preheader}<table role="presentation" width="100%" cellpadding="0" cellspacing="0" style="background:#f4f1ea;padding:32px 16px">
<tr><td align="center">
<table role="presentation" width="100%" cellpadding="0" cellspacing="0" style="max-width:520px;background:#ffffff;border-radius:8px;padding:32px">
<tr><td style="font-size:20px;letter-spacing:2px;color:{GOLD};padding-bottom:24px">SORSFONALAK</td></tr>
<tr><td style="font-size:16px;line-height:1.6;padding-bottom:12px">{greeting}</td></tr>
<tr><td style="font-size:16px;line-height:1.6;padding-bottom:24px">{intro}</td></tr>
2026-11-23 20:28:11 +00:00
{quote}{code}{points}<tr><td style="padding-bottom:24px"><a href="{url}" style="display:inline-block;background:{GOLD};color:#ffffff;text-decoration:none;padding:12px 24px;border-radius:6px;font-size:16px">{button}</a></td></tr>
2026-11-17 18:37:15 +00:00
<tr><td style="font-size:14px;line-height:1.6;color:{MUTED};padding-bottom:16px">{note}</td></tr>
<tr><td style="font-size:12px;line-height:1.5;color:{FAINT};word-break:break-all">{url_text}</td></tr>
</table>
<p style="font-size:12px;line-height:1.5;color:{FAINT};max-width:520px">{small}</p>
</td></tr>
</table>
</body>
</html>
"# ,
lang = if lang == Lang ::Hu { "hu" } else { "en" },
subject = escape ( & self . subject ),
greeting = escape ( & self . greeting ),
intro = escape ( & self . intro ),
url = escape ( & self . url ),
button = escape ( self . button ),
note = escape ( & self . note ),
url_text = escape ( & self . url ),
);
Rendered { subject : self . subject , text , html , unsubscribe_post_url : self . unsubscribe_post_url }
}
}
#[cfg(test)]
mod tests {
use serde_json ::json ;
use super ::* ;
fn invitation_payload () -> Value {
json! ({
"url" : "https://sorsfonalak.test/meghivo/abc" ,
"inviter_name" : "Kata" ,
"message" : "Gyere, nézd meg! \n <b>Szia</b>" ,
"expires_on" : "2026-12-17" ,
"unsubscribe_url" : "https://sorsfonalak.test/leiratkozas?token=abc" ,
"unsubscribe_post_url" : "https://sorsfonalak.test/api/v1/public/invitations/unsubscribe?token=abc" ,
})
}
2026-11-19 11:07:13 +00:00
#[test]
fn waitlist_confirmation_has_the_leave_link () {
let hu = render ( "waitlist_joined" , "hu" , & invitation_payload ()). unwrap ();
assert_eq! ( hu . subject , "Felírtunk a Sorsfonalak várólistájára" );
assert! (
hu . text . contains ( "Leiratkozás a várólistáról: https://sorsfonalak.test/leiratkozas?token=abc" ),
"{}" ,
hu . text
);
assert! ( hu . unsubscribe_post_url . is_some ());
}
2026-11-19 10:12:51 +00:00
#[test]
fn synastry_invite_names_the_inviter () {
let hu = render ( "synastry_invite" , "hu" , & invitation_payload ()). unwrap ();
assert_eq! ( hu . subject , "Kata kíváncsi, mennyire illetek össze" );
assert! ( hu . text . contains ( "> Gyere, nézd meg!" ));
assert! ( hu . text . contains ( "A meghívó 2026. december 17-ig érvényes." ));
assert! ( hu . html . contains ( r #"href="https://sorsfonalak.test/meghivo/abc""# ));
assert! ( hu . text . contains ( "Nem kérek több meghívót" ));
let mut anonymous = invitation_payload ();
anonymous [ "inviter_name" ] = Value ::Null ;
assert_eq! ( render ( "synastry_invite" , "en" , & anonymous ). unwrap (). subject , "Someone wonders how well you match" );
}
2026-11-17 18:37:15 +00:00
#[test]
fn invitation_has_both_parts () {
let hu = render ( "invitation" , "hu" , & invitation_payload ()). unwrap ();
assert_eq! ( hu . subject , "Kata meghívott a Sorsfonalakra" );
assert! ( hu . text . contains ( "> Gyere, nézd meg! \n > <b>Szia</b>" ));
assert! ( hu . text . contains ( "A meghívó 2026. december 17-ig érvényes." ));
assert! ( hu . text . contains ( "Nem kérek több meghívót: https://sorsfonalak.test/leiratkozas?token=abc" ));
assert! ( hu . html . contains ( "Gyere, nézd meg!<br><b>Szia</b>" ));
assert! ( hu . html . contains ( r #"href="https://sorsfonalak.test/meghivo/abc""# ));
assert! ( hu . html . contains ( "display:none" ));
assert_eq! (
hu . unsubscribe_post_url . as_deref (),
Some ( "https://sorsfonalak.test/api/v1/public/invitations/unsubscribe?token=abc" )
);
let mut anonymous = invitation_payload ();
anonymous [ "inviter_name" ] = Value ::Null ;
anonymous [ "message" ] = Value ::Null ;
let en = render ( "invitation" , "en" , & anonymous ). unwrap ();
assert_eq! ( en . subject , "You are invited to Sorsfonalak" );
assert! ( en . text . contains ( "valid until 17 December 2026" ) && ! en . text . contains ( "> " ));
assert! ( ! en . html . contains ( "border-left" ));
2026-11-19 09:57:01 +00:00
let mut gift = invitation_payload ();
gift [ "package_name" ] = json! ( "Páros" );
gift [ "promo_code" ] = json! ( "ABCD-EFGH-JKLM" );
let hu = render ( "invitation" , "hu" , & gift ). unwrap ();
assert! ( hu . text . contains ( "Ajándékba egy „Páros” csomagot is kapsz" ), "{}" , hu . text );
assert! ( hu . html . contains ( "ABCD-EFGH-JKLM" ));
assert! ( ! render ( "invitation" , "hu" , & invitation_payload ()). unwrap (). text . contains ( "Ajándék" ));
2026-11-17 18:37:15 +00:00
let mut broken = invitation_payload ();
broken [ "unsubscribe_url" ] = Value ::Null ;
assert_eq! ( render ( "invitation" , "hu" , & broken ), Err ( TemplateError ::MissingField ( "unsubscribe_url" )));
}
2026-11-23 11:20:14 +00:00
#[test]
fn gifts_say_what_was_given () {
let payload = json! ({
"url" : "https://sorsfonalak.hu/csomagok" , "display_name" : "Anna" ,
"gift" : "a(z) „Páros” csomagot" , "contents" : "2 részletes képletelemzés, 3 kérdés" ,
});
let hu = render ( "gift" , "hu" , & payload ). unwrap ();
assert_eq! ( hu . subject , "Ajándékot kaptál a Sorsfonalaktól" );
assert! ( hu . text . contains ( "Ajándékba kaptad a(z) „Páros” csomagot" ), "{}" , hu . text );
assert! ( hu . text . contains ( "Tartalma: 2 részletes képletelemzés, 3 kérdés." ), "{}" , hu . text );
let units = json! ({ "url" : "https://sorsfonalak.hu/csomagok" , "gift" : "2 kérdést" });
let hu = render ( "gift" , "hu" , & units ). unwrap ();
assert! ( hu . text . contains ( "Szia!" ) && hu . text . contains ( "Ajándékba kaptad 2 kérdést," ) && ! hu . text . contains ( "Tartalma" ));
assert! ( render ( "gift" , "en" , & payload ). unwrap (). subject . starts_with ( "A gift" ));
assert_eq! ( render ( "gift" , "hu" , & json! ({ "url" : "x" })), Err ( TemplateError ::MissingField ( "gift" )));
}
2026-11-20 12:06:10 +00:00
#[test]
fn purchase_confirmations_confirm_the_waiver () {
let payload = serde_json ::json! ({
"url" : "https://sorsfonalak.hu/csomagok" , "display_name" : "Anna" , "package_name" : "Páros" ,
"contents" : "2 részletes képletelemzés, 1 kapcsolati elemzés" , "amount" : "6 \u{a0} 000 \u{a0} Ft" ,
"paid_on" : "2026-11-20" , "terms_url" : "https://sorsfonalak.hu/aszf" , "invoices_url" : "https://sorsfonalak.hu/szamlak"
});
let hu = render ( "purchase_confirmation" , "hu" , & payload ). unwrap ();
assert_eq! ( hu . subject , "Köszönjük a vásárlást: Páros" );
assert! ( hu . text . contains ( "2026. november 20." ) && hu . text . contains ( "Tartalma: 2 részletes képletelemzés" ));
assert! ( hu . text . contains ( "elveszíted a 14 napos elállási jogodat" ));
assert! ( hu . text . contains ( "https://sorsfonalak.hu/aszf" ) && hu . text . contains ( "https://sorsfonalak.hu/szamlak" ));
let en = render ( "purchase_confirmation" , "en" , & payload ). unwrap ();
assert! ( en . text . contains ( "right of withdrawal" ));
let missing = serde_json ::json! ({ "url" : "u" , "package_name" : "Páros" });
assert_eq! ( render ( "purchase_confirmation" , "hu" , & missing ), Err ( TemplateError ::MissingField ( "amount" )));
}
2026-11-23 20:28:11 +00:00
#[test]
fn gift_packages_carry_the_message_and_the_code () {
let payload = serde_json ::json! ({
"url" : "https://sorsfonalak.hu/bevaltas?kod=ABCD-EFGH-JKMN" , "package_name" : "Páros" ,
"contents" : "2 részletes képletelemzés, 1 kapcsolati elemzés" , "promo_code" : "ABCD-EFGH-JKMN" ,
"recipient_name" : "Bea" , "from_name" : "Ági" , "message" : "Boldog születésnapot! \n <b>Ölel</b>"
});
let hu = render ( "gift_package" , "hu" , & payload ). unwrap ();
assert! ( hu . text . starts_with ( "Szia Bea!" ));
assert_eq! ( hu . subject , "Ági ajándékot küldött neked: „Páros” csomag" );
assert! ( hu . text . contains ( "Ági ajándékozott neked egy „Páros” csomagot a Sorsfonalakon. Tartalma: 2 részletes" ));
assert! (
hu . text . contains ( "> Boldog születésnapot! \n > <b>Ölel</b>" )
&& hu . text . contains ( "AJÁNDÉKKÓD: ABCD-EFGH-JKMN" )
);
assert! ( hu . html . contains ( "<b>Ölel</b>" ) && hu . html . contains ( ">ABCD-EFGH-JKMN</div>" ));
assert! ( hu . text . contains ( "PDF-ben is csatoltuk" ) && hu . text . contains ( "mert Ági a Sorsfonalakon" ));
2026-11-24 13:46:35 +00:00
let mut xmas = payload . clone ();
xmas [ "christmas_year" ] = 2027. into ();
let hu = render ( "gift_package" , "hu" , & xmas ). unwrap ();
assert_eq! ( hu . subject , "Ági karácsonyi ajándékot küldött neked: „Páros” csomag" );
assert! ( hu . text . contains ( "Boldog karácsonyt! Ági ajándékozott neked" ));
2026-11-23 20:28:11 +00:00
let anonymous = serde_json ::json! ({ "url" : "u" , "package_name" : "Család" , "promo_code" : "X1-<script>" });
let hu = render ( "gift_package" , "hu" , & anonymous ). unwrap ();
assert_eq! ( hu . subject , "Ajándékot kaptál: „Család” csomag a Sorsfonalakon" );
assert! ( hu . text . contains ( "AJÁNDÉKKÓD: X1-script" ) && ! hu . text . contains ( "> " ) && hu . text . starts_with ( "Szia!" ));
assert! ( render ( "gift_package" , "en" , & payload ). unwrap (). text . contains ( "Ági gave you the “Páros” package" ));
let missing = serde_json ::json! ({ "url" : "u" , "package_name" : "Páros" });
assert_eq! ( render ( "gift_package" , "hu" , & missing ), Err ( TemplateError ::MissingField ( "promo_code" )));
}
#[test]
fn a_gift_purchase_is_confirmed_as_a_gift () {
let mut payload = serde_json ::json! ({
"url" : "https://sorsfonalak.hu/ajandekaim" , "display_name" : "Anna" , "package_name" : "Páros" ,
"contents" : "2 részletes képletelemzés" , "amount" : "6 \u{a0} 000 \u{a0} Ft" , "paid_on" : "2026-11-20" ,
"terms_url" : "https://sorsfonalak.hu/aszf" , "invoices_url" : "https://sorsfonalak.hu/szamlak" ,
"gift" : { "promo_code" : "ABCD-EFGH-JKMN" , "recipient_name" : "Bea" , "recipient_email" : "bea@example.com" }
});
let hu = render ( "purchase_confirmation" , "hu" , & payload ). unwrap ();
assert_eq! ( hu . subject , "Köszönjük a vásárlást: Páros (ajándék)" );
assert! (
hu . text . contains ( "ajándékba vetted Bea részére." ) && hu . text . contains ( "elküldtük ide: bea@example.com" )
);
2026-11-23 21:22:46 +00:00
assert! ( hu . text . contains ( "AJÁNDÉKKÓD: ABCD-EFGH-JKMN" ) && hu . text . contains ( "14 napon belül" ));
assert! ( hu . text . contains ( "a beváltással az elállási jog megszűnik" ));
2026-11-23 20:28:11 +00:00
assert! ( ! hu . text . contains ( "jóváírtuk" ));
2026-11-24 13:46:35 +00:00
payload [ "gift" ][ "send_at" ] = Value ::from ( "2026-12-24 08:00" );
let hu = render ( "purchase_confirmation" , "hu" , & payload ). unwrap ();
assert! ( hu . text . contains ( "2026. december 24., 08:00-kor küldjük el ide: bea@example.com" ), "{}" , hu . text );
2026-11-24 17:08:17 +00:00
assert! ( hu . text . contains ( "belépve (https://sorsfonalak.hu/visszajelzes)" ), "{}" , hu . text );
2026-11-23 20:28:11 +00:00
payload [ "gift" ][ "recipient_email" ] = Value ::Null ;
let hu = render ( "purchase_confirmation" , "hu" , & payload ). unwrap ();
assert! ( hu . text . contains ( "PDF-ben csatoltuk ehhez a levélhez" ));
assert! ( render ( "purchase_confirmation" , "en" , & payload ). unwrap (). text . contains ( "as a gift" ));
}
2026-11-17 18:37:15 +00:00
#[test]
fn dates () {
assert_eq! ( date ( Lang ::Hu , "2027-01-05" ). as_deref (), Some ( "2027. január 5." ));
assert_eq! ( date ( Lang ::En , "2027-01-05T10:00:00Z" ). as_deref (), Some ( "5 January 2027" ));
assert_eq! ( date ( Lang ::Hu , "2027-13-05" ), None );
}
}