Mail -> MBox
This commit is contained in:
parent
134486743f
commit
3e2777d226
2 changed files with 14 additions and 14 deletions
|
@ -1,5 +1,5 @@
|
||||||
name = "gleambox"
|
name = "gleambox"
|
||||||
version = "0.0.3"
|
version = "0.0.4"
|
||||||
|
|
||||||
description = "WIP mbox parser in Gleam"
|
description = "WIP mbox parser in Gleam"
|
||||||
licences = ["LGPL-3.0-only"]
|
licences = ["LGPL-3.0-only"]
|
||||||
|
|
|
@ -5,48 +5,48 @@ import gleam/string
|
||||||
import gleam/pair
|
import gleam/pair
|
||||||
import gleam/regex
|
import gleam/regex
|
||||||
|
|
||||||
pub type Mail {
|
pub type MBox {
|
||||||
Mail(headers: Dict(String, String), body: String)
|
MBox(headers: Dict(String, String), body: String)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse(mboxcontents: String) -> Mail {
|
pub fn parse(mboxcontents: String) -> MBox {
|
||||||
Mail(headers: parse_headers(mboxcontents), body: parse_body(mboxcontents))
|
MBox(headers: parse_headers(mboxcontents), body: parse_body(mboxcontents))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_headers(mbox: Mail) -> Dict(String, String) {
|
pub fn get_headers(mbox: MBox) -> Dict(String, String) {
|
||||||
mbox.headers
|
mbox.headers
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_header(mbox: Mail, key: String) -> Result(String, Nil) {
|
pub fn get_header(mbox: MBox, key: String) -> Result(String, Nil) {
|
||||||
mbox.headers
|
mbox.headers
|
||||||
|> dict.get(key)
|
|> dict.get(key)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_body(mbox: Mail) -> String {
|
pub fn get_body(mbox: MBox) -> String {
|
||||||
mbox.body
|
mbox.body
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_from(mbox: Mail) -> Result(String, Nil) {
|
pub fn get_from(mbox: MBox) -> Result(String, Nil) {
|
||||||
get_header(mbox, "From")
|
get_header(mbox, "From")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_to(mbox: Mail) -> Result(String, Nil) {
|
pub fn get_to(mbox: MBox) -> Result(String, Nil) {
|
||||||
get_header(mbox, "To")
|
get_header(mbox, "To")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_date(mbox: Mail) -> Result(String, Nil) {
|
pub fn get_date(mbox: MBox) -> Result(String, Nil) {
|
||||||
get_header(mbox, "Date")
|
get_header(mbox, "Date")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_subject(mbox: Mail) -> Result(String, Nil) {
|
pub fn get_subject(mbox: MBox) -> Result(String, Nil) {
|
||||||
get_header(mbox, "Subject")
|
get_header(mbox, "Subject")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_message_id(mbox: Mail) -> Result(String, Nil) {
|
pub fn get_message_id(mbox: MBox) -> Result(String, Nil) {
|
||||||
get_header(mbox, "Message-ID")
|
get_header(mbox, "Message-ID")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_references(mbox: Mail) -> List(String) {
|
pub fn get_references(mbox: MBox) -> List(String) {
|
||||||
get_header(mbox, "References")
|
get_header(mbox, "References")
|
||||||
|> result.unwrap(or: "Error")
|
|> result.unwrap(or: "Error")
|
||||||
|> string.split(" ")
|
|> string.split(" ")
|
||||||
|
|
Loading…
Reference in a new issue