compose: pass body text when replying

Get rendered body text when creating a new reply Composer instead of
rendering the text in the Composer constructor.

Closes #86
jmap-eventsource
Manos Pitsidianakis 2020-11-24 10:34:28 +02:00
parent bf56c88918
commit b46cd09ca6
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
2 changed files with 26 additions and 21 deletions

View File

@ -212,7 +212,7 @@ impl Composer {
pub fn reply_to(
coordinates: (AccountHash, MailboxHash, EnvelopeHash),
bytes: &[u8],
reply_body: String,
context: &mut Context,
reply_to_all: bool,
) -> Self {
@ -313,10 +313,7 @@ impl Composer {
ret.draft.set_header("To", envelope.field_from_to_string());
}
}
let body = envelope.body_bytes(bytes);
ret.draft.body = {
let reply_body_bytes = decode_rec(&body, None);
let reply_body = String::from_utf8_lossy(&reply_body_bytes);
let mut ret = format!(
"On {} {} wrote:\n",
envelope.date_as_str(),
@ -337,10 +334,10 @@ impl Composer {
pub fn reply_to_select(
coordinates: (AccountHash, MailboxHash, EnvelopeHash),
bytes: &[u8],
reply_body: String,
context: &mut Context,
) -> Self {
let mut ret = Composer::reply_to(coordinates, bytes, context, false);
let mut ret = Composer::reply_to(coordinates, reply_body, context, false);
let account = &context.accounts[&coordinates.0];
let parent_message = account.collection.get_env(coordinates.2);
/* If message is from a mailing list and we detect a List-Post header, ask user if they
@ -385,18 +382,18 @@ impl Composer {
pub fn reply_to_author(
coordinates: (AccountHash, MailboxHash, EnvelopeHash),
bytes: &[u8],
reply_body: String,
context: &mut Context,
) -> Self {
Composer::reply_to(coordinates, bytes, context, false)
Composer::reply_to(coordinates, reply_body, context, false)
}
pub fn reply_to_all(
coordinates: (AccountHash, MailboxHash, EnvelopeHash),
bytes: &[u8],
reply_body: String,
context: &mut Context,
) -> Self {
Composer::reply_to(coordinates, bytes, context, true)
Composer::reply_to(coordinates, reply_body, context, true)
}
pub fn set_draft(&mut self, draft: Draft) {

View File

@ -382,7 +382,7 @@ impl MailView {
}
fn perform_action(&mut self, action: PendingReplyAction, context: &mut Context) {
let bytes = match self.state {
let reply_body = match self.state {
MailViewState::Init {
ref mut pending_action,
..
@ -396,21 +396,29 @@ impl MailView {
}
return;
}
MailViewState::Loaded { ref bytes, .. } => bytes,
MailViewState::Loaded { ref display, .. } => {
self.attachment_displays_to_text(&display, context, false)
}
MailViewState::Error { .. } => {
return;
}
};
let composer = match action {
PendingReplyAction::Reply => {
Box::new(Composer::reply_to_select(self.coordinates, bytes, context))
}
PendingReplyAction::ReplyToAuthor => {
Box::new(Composer::reply_to_author(self.coordinates, bytes, context))
}
PendingReplyAction::ReplyToAll => {
Box::new(Composer::reply_to_all(self.coordinates, bytes, context))
}
PendingReplyAction::Reply => Box::new(Composer::reply_to_select(
self.coordinates,
reply_body,
context,
)),
PendingReplyAction::ReplyToAuthor => Box::new(Composer::reply_to_author(
self.coordinates,
reply_body,
context,
)),
PendingReplyAction::ReplyToAll => Box::new(Composer::reply_to_all(
self.coordinates,
reply_body,
context,
)),
};
context