61 lines
1.4 KiB
Rust
61 lines
1.4 KiB
Rust
use crate::prelude::{Host, Mailbox};
|
|
use std::{fmt, str::FromStr};
|
|
|
|
#[cfg(feature = "serde")]
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
mod error;
|
|
mod link;
|
|
mod parser;
|
|
pub use {
|
|
error::Error,
|
|
link::Link,
|
|
parser::{GemtextNode, Parser},
|
|
};
|
|
|
|
#[derive(Clone, Debug, PartialEq)]
|
|
pub struct Recipients {
|
|
pub boxes: Vec<Mailbox>,
|
|
}
|
|
|
|
impl fmt::Display for Recipients {
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
write!(f, ":")?;
|
|
self.boxes.iter().try_for_each(|b| write!(f, " {b}"))
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Clone, PartialEq)]
|
|
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
|
|
pub struct Message {
|
|
pub id: String,
|
|
pub from: Mailbox,
|
|
pub senders: Vec<Mailbox>,
|
|
pub recipients: Vec<Mailbox>,
|
|
pub timstamp: Option<String>,
|
|
pub title: Option<String>,
|
|
pub body: String,
|
|
}
|
|
|
|
impl fmt::Display for Message {
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
if !self.senders.is_empty() {
|
|
write!(f, "< ")?;
|
|
self.senders.iter().try_for_each(|s| writeln!(f, "{s}"))?;
|
|
}
|
|
if !self.recipients.is_empty() {
|
|
write!(f, ": ")?;
|
|
self.recipients.iter().try_for_each(|r| write!(f, " {r}"))?;
|
|
writeln!(f)?;
|
|
}
|
|
write!(f, "{}\r\n", self.body)
|
|
}
|
|
}
|
|
|
|
impl FromStr for Message {
|
|
type Err = String;
|
|
|
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
|
todo!()
|
|
}
|
|
}
|