mirror of
https://github.com/pimalaya/himalaya.git
synced 2026-06-17 13:17:55 +08:00
add basic support of xdg-email (#162)
This commit is contained in:
+47
-1
@@ -1,7 +1,8 @@
|
||||
use error_chain::error_chain;
|
||||
use mailparse::{self, MailHeaderMap};
|
||||
use serde::Serialize;
|
||||
use std::{collections::HashMap, fmt};
|
||||
use std::{borrow::Cow, collections::HashMap, fmt};
|
||||
use url::Url;
|
||||
|
||||
use crate::{ctx::Ctx, msg::model::Msg};
|
||||
|
||||
@@ -187,6 +188,51 @@ impl Tpl {
|
||||
tpl
|
||||
}
|
||||
|
||||
pub fn mailto(ctx: &Ctx, url: &Url) -> Self {
|
||||
let mut headers = HashMap::new();
|
||||
|
||||
let mut cc = Vec::new();
|
||||
let mut bcc = Vec::new();
|
||||
let mut subject = Cow::default();
|
||||
let mut body = Cow::default();
|
||||
|
||||
for (key, val) in url.query_pairs() {
|
||||
match key.as_bytes() {
|
||||
b"cc" => {
|
||||
cc.push(val);
|
||||
}
|
||||
b"bcc" => {
|
||||
bcc.push(val);
|
||||
}
|
||||
b"subject" => {
|
||||
subject = val;
|
||||
}
|
||||
b"body" => {
|
||||
body = val;
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
headers.insert(String::from("To"), url.path().to_string());
|
||||
headers.insert(String::from("Subject"), subject.into());
|
||||
if !cc.is_empty() {
|
||||
headers.insert(String::from("Cc"), cc.join(", "));
|
||||
}
|
||||
if !bcc.is_empty() {
|
||||
headers.insert(String::from("Bcc"), cc.join(", "));
|
||||
}
|
||||
|
||||
let mut tpl = Self {
|
||||
headers,
|
||||
body: Some(body.into()),
|
||||
signature: ctx.config.signature(&ctx.account),
|
||||
raw: String::new(),
|
||||
};
|
||||
tpl.raw = tpl.to_string();
|
||||
tpl
|
||||
}
|
||||
|
||||
pub fn header<K: ToString, V: ToString>(&mut self, key: K, val: V) -> &Self {
|
||||
self.headers.insert(key.to_string(), val.to_string());
|
||||
self
|
||||
|
||||
Reference in New Issue
Block a user