parent
f348cc9a55
commit
499113acd2
|
@ -203,12 +203,36 @@ impl Draft {
|
||||||
Ok(ret)
|
Ok(ret)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn finalise(self) -> Result<String> {
|
pub fn finalise(mut self) -> Result<String> {
|
||||||
let mut ret = String::new();
|
let mut ret = String::new();
|
||||||
|
|
||||||
|
if self.headers.contains_key("From") && !self.headers.contains_key("Message-ID") {
|
||||||
|
if let super::parser::IResult::Done(_, addr) =
|
||||||
|
super::parser::mailbox(self.headers["From"].as_bytes())
|
||||||
|
{
|
||||||
|
if let Some(fqdn) = addr.get_fqdn() {
|
||||||
|
if self
|
||||||
|
.headers
|
||||||
|
.insert("Message-ID".into(), random::gen_message_id(&fqdn))
|
||||||
|
.is_none()
|
||||||
|
{
|
||||||
|
let pos = self
|
||||||
|
.header_order
|
||||||
|
.iter()
|
||||||
|
.position(|h| h == "Subject")
|
||||||
|
.unwrap();
|
||||||
|
self.header_order.insert(pos, "Message-ID".into());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
for k in &self.header_order {
|
for k in &self.header_order {
|
||||||
let v = &self.headers[k];
|
let v = &self.headers[k];
|
||||||
ret.extend(format!("{}: {}\n", k, v).chars());
|
if v.is_ascii() {
|
||||||
|
ret.extend(format!("{}: {}\n", k, v).chars());
|
||||||
|
} else {
|
||||||
|
ret.extend(format!("{}: {}\n", k, mime::encode_header(v)).chars());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ret.push_str("MIME-Version: 1.0\n");
|
ret.push_str("MIME-Version: 1.0\n");
|
||||||
|
|
||||||
|
|
|
@ -1 +1,18 @@
|
||||||
//use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
pub fn encode_header(value: &str) -> String {
|
||||||
|
eprintln!("encoding \"{}\"", value);
|
||||||
|
let mut ret = String::with_capacity(5 / 3 * value.len());
|
||||||
|
for word in value.split_whitespace() {
|
||||||
|
if word.is_ascii() {
|
||||||
|
ret.push_str(word);
|
||||||
|
} else {
|
||||||
|
ret.push_str(
|
||||||
|
format!("=?UTF-8?B?{}?=", BASE64_MIME.encode(word.as_bytes()).trim()).as_str(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
ret.push(' ');
|
||||||
|
}
|
||||||
|
ret.pop();
|
||||||
|
ret
|
||||||
|
}
|
||||||
|
|
|
@ -503,7 +503,7 @@ impl Component for Composer {
|
||||||
if let Err(e) = account.save_draft(draft) {
|
if let Err(e) = account.save_draft(draft) {
|
||||||
if cfg!(debug_assertions) {
|
if cfg!(debug_assertions) {
|
||||||
eprint!("{}:{}_{}: ", file!(), line!(), column!());
|
eprint!("{}:{}_{}: ", file!(), line!(), column!());
|
||||||
eprintln!("{:?} could not save draft", e);
|
eprintln!("{:?} could not save draft", e);
|
||||||
}
|
}
|
||||||
context.replies.push_back(UIEvent::Notification(
|
context.replies.push_back(UIEvent::Notification(
|
||||||
Some("Could not save draft.".into()),
|
Some("Could not save draft.".into()),
|
||||||
|
@ -547,6 +547,7 @@ eprintln!("{:?} could not save draft", e);
|
||||||
.expect("Failed to start mailer command");
|
.expect("Failed to start mailer command");
|
||||||
{
|
{
|
||||||
let mut stdin = msmtp.stdin.as_mut().expect("failed to open stdin");
|
let mut stdin = msmtp.stdin.as_mut().expect("failed to open stdin");
|
||||||
|
self.update_draft();
|
||||||
let draft = self.draft.clone().finalise().unwrap();
|
let draft = self.draft.clone().finalise().unwrap();
|
||||||
stdin
|
stdin
|
||||||
.write_all(draft.as_bytes())
|
.write_all(draft.as_bytes())
|
||||||
|
@ -560,7 +561,7 @@ eprintln!("{:?} could not save draft", e);
|
||||||
) {
|
) {
|
||||||
if cfg!(debug_assertions) {
|
if cfg!(debug_assertions) {
|
||||||
eprint!("{}:{}_{}: ", file!(), line!(), column!());
|
eprint!("{}:{}_{}: ", file!(), line!(), column!());
|
||||||
eprintln!("{:?} could not save sent msg", e);
|
eprintln!("{:?} could not save sent msg", e);
|
||||||
}
|
}
|
||||||
context.replies.push_back(UIEvent::Notification(
|
context.replies.push_back(UIEvent::Notification(
|
||||||
Some("Could not save in 'Sent' folder.".into()),
|
Some("Could not save in 'Sent' folder.".into()),
|
||||||
|
|
Loading…
Reference in New Issue