Skip to main content

sofie_mail/
unsubscribe.rs

1use sofie_auth::SigningKeys;
2use sofie_core::Result;
3
4/// Where a bulk mail's unsubscribe link goes, below the app's public URL.
5pub const PATH: &str = "/mail/unsubscribe";
6pub(crate) const PURPOSE: &str = "sofie_mail.unsubscribe";
7
8/// The address and list, sealed: the link names neither, and nobody forges one.
9pub(crate) fn token(keys: &SigningKeys, address: &str, list: &str) -> Result<String> {
10    keys.seal_value(PURPOSE, format!("{address}\n{list}").as_bytes())
11}
12
13#[cfg(feature = "web")]
14pub(crate) fn opened(plain: &[u8]) -> Option<(String, String)> {
15    let text = std::str::from_utf8(plain).ok()?;
16    let (address, list) = text.split_once('\n')?;
17    Some((address.to_owned(), list.to_owned()))
18}