melib: add quoted body in reply draft
parent
91760e5be6
commit
c88ee18dda
|
@ -42,9 +42,53 @@ impl Default for Draft {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Draft {
|
impl Draft {
|
||||||
|
pub fn as_reply(envelope: &Envelope, bytes: &[u8]) -> Self {
|
||||||
|
let mut ret = Draft::default();
|
||||||
|
ret.headers_mut().insert(
|
||||||
|
"References".into(),
|
||||||
|
format!(
|
||||||
|
"{} {}",
|
||||||
|
envelope
|
||||||
|
.references()
|
||||||
|
.iter()
|
||||||
|
.fold(String::new(), |mut acc, x| {
|
||||||
|
if !acc.is_empty() {
|
||||||
|
acc.push(' ');
|
||||||
|
}
|
||||||
|
acc.push_str(&x.to_string());
|
||||||
|
acc
|
||||||
|
}),
|
||||||
|
envelope.message_id()
|
||||||
|
),
|
||||||
|
);
|
||||||
|
ret.headers_mut()
|
||||||
|
.insert("In-Reply-To".into(), envelope.message_id().into());
|
||||||
|
ret.headers_mut()
|
||||||
|
.insert("To".into(), envelope.field_from_to_string());
|
||||||
|
ret.headers_mut()
|
||||||
|
.insert("Cc".into(), envelope.field_cc_to_string());
|
||||||
|
let body = envelope.body_bytes(bytes);
|
||||||
|
ret.body = {
|
||||||
|
let reply_body_bytes = decode_rec(&body, None);
|
||||||
|
let reply_body = String::from_utf8_lossy(&reply_body_bytes);
|
||||||
|
let lines: Vec<&str> = reply_body.lines().collect();
|
||||||
|
let mut ret = String::with_capacity(reply_body.len() + lines.len());
|
||||||
|
for l in lines {
|
||||||
|
ret.push('>');
|
||||||
|
ret.push_str(l.trim());
|
||||||
|
ret.push('\n');
|
||||||
|
}
|
||||||
|
ret.pop();
|
||||||
|
ret
|
||||||
|
};
|
||||||
|
|
||||||
|
ret
|
||||||
|
}
|
||||||
|
|
||||||
pub fn headers_mut(&mut self) -> &mut FnvHashMap<String, String> {
|
pub fn headers_mut(&mut self) -> &mut FnvHashMap<String, String> {
|
||||||
&mut self.headers
|
&mut self.headers
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn headers(&self) -> &FnvHashMap<String, String> {
|
pub fn headers(&self) -> &FnvHashMap<String, String> {
|
||||||
&self.headers
|
&self.headers
|
||||||
}
|
}
|
||||||
|
|
|
@ -108,10 +108,15 @@ impl Composer {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let threads = &mailbox.threads;
|
let threads = &mailbox.threads;
|
||||||
let containers = &threads.containers();
|
let containers = &threads.containers();
|
||||||
|
|
||||||
let mut ret = Composer::default();
|
let mut ret = Composer::default();
|
||||||
|
|
||||||
let p = containers[msg];
|
let p = containers[msg];
|
||||||
|
let parent_message = &mailbox.collection[p.message().unwrap()];
|
||||||
|
let mut op = context.accounts[coordinates.0]
|
||||||
|
.backend
|
||||||
|
.operation(parent_message.hash());
|
||||||
|
let parent_bytes = op.as_bytes();
|
||||||
|
|
||||||
|
ret.draft = Draft::as_reply(parent_message, parent_bytes.unwrap());
|
||||||
ret.draft.headers_mut().insert(
|
ret.draft.headers_mut().insert(
|
||||||
"Subject".into(),
|
"Subject".into(),
|
||||||
if p.show_subject() {
|
if p.show_subject() {
|
||||||
|
@ -123,33 +128,6 @@ impl Composer {
|
||||||
mailbox.collection[p.message().unwrap()].subject().into()
|
mailbox.collection[p.message().unwrap()].subject().into()
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
let parent_message = &mailbox.collection[p.message().unwrap()];
|
|
||||||
ret.draft.headers_mut().insert(
|
|
||||||
"References".into(),
|
|
||||||
format!(
|
|
||||||
"{} {}",
|
|
||||||
parent_message
|
|
||||||
.references()
|
|
||||||
.iter()
|
|
||||||
.fold(String::new(), |mut acc, x| {
|
|
||||||
if !acc.is_empty() {
|
|
||||||
acc.push(' ');
|
|
||||||
}
|
|
||||||
acc.push_str(&x.to_string());
|
|
||||||
acc
|
|
||||||
}),
|
|
||||||
parent_message.message_id()
|
|
||||||
),
|
|
||||||
);
|
|
||||||
ret.draft
|
|
||||||
.headers_mut()
|
|
||||||
.insert("In-Reply-To".into(), parent_message.message_id().into());
|
|
||||||
ret.draft
|
|
||||||
.headers_mut()
|
|
||||||
.insert("To".into(), parent_message.field_from_to_string());
|
|
||||||
ret.draft
|
|
||||||
.headers_mut()
|
|
||||||
.insert("Cc".into(), parent_message.field_cc_to_string());
|
|
||||||
|
|
||||||
ret.account_cursor = coordinates.0;
|
ret.account_cursor = coordinates.0;
|
||||||
ret.reply_context = Some((
|
ret.reply_context = Some((
|
||||||
|
@ -436,7 +414,7 @@ impl Component for Composer {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
/* Switch to Pager mode if we're on Overview mode */
|
/* Switch to Pager mode if we're on Overview mode */
|
||||||
UIEventType::Input(Key::Char('p')) if self.mode.is_overview() => {
|
UIEventType::Input(Key::Char('v')) if self.mode.is_overview() => {
|
||||||
self.mode = ViewMode::Pager;
|
self.mode = ViewMode::Pager;
|
||||||
self.set_dirty();
|
self.set_dirty();
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Reference in New Issue