1use std::path::{Path, PathBuf};
4
5use uuid::Uuid;
6
7use crate::constants::{CRON, KEYS, MAILBOX};
8use crate::home::UnifierHome;
9
10pub fn cron_dir(home: &UnifierHome, schedule: &str) -> PathBuf {
11 home.path().join(CRON).join(schedule)
12}
13
14pub fn mailbox_dir(home: &UnifierHome, recipient: &str) -> PathBuf {
15 home.path().join(MAILBOX).join(recipient)
16}
17
18pub fn key_path(home: &UnifierHome, key: &str) -> PathBuf {
19 home.path().join(KEYS).join(key)
20}
21
22pub fn message_path(dir: &Path, id: &Uuid) -> PathBuf {
23 dir.join(format!("{}.txt", id.hyphenated()))
24}
25
26pub fn parse_message_id(filename: &str) -> Option<Uuid> {
27 let stem = filename.strip_suffix(".txt")?;
28 Uuid::parse_str(stem).ok()
29}