Add toggle encrypt action in composer

Does nothing for now, will be used in a future commit.
jmap-eventsource
Manos Pitsidianakis 2020-10-07 17:16:07 +03:00
parent 5d968b7c40
commit 08df7f39b2
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
3 changed files with 66 additions and 6 deletions

View File

@ -542,6 +542,19 @@ define_commands!([
}
)
},
{ tags: ["toggle encrypt"],
desc: "toggle encryption for this draft",
tokens: &[One(Literal("toggle")), One(Literal("encrypt"))],
parser:(
fn toggle_encrypt(input: &[u8]) -> IResult<&[u8], Action> {
let (input, _) = tag("toggle")(input)?;
let (input, _) = is_a(" ")(input)?;
let (input, _) = tag("encrypt")(input)?;
let (input, _) = eof(input)?;
Ok((input, Compose(ToggleEncrypt)))
}
)
},
{ tags: ["create-mailbox "],
desc: "create-mailbox ACCOUNT MAILBOX_PATH",
tokens: &[One(Literal("create-mailbox")), One(AccountName), One(MailboxPath)],
@ -765,7 +778,13 @@ fn listing_action(input: &[u8]) -> IResult<&[u8], Action> {
}
fn compose_action(input: &[u8]) -> IResult<&[u8], Action> {
alt((add_attachment, remove_attachment, toggle_sign, save_draft))(input)
alt((
add_attachment,
remove_attachment,
toggle_sign,
toggle_encrypt,
save_draft,
))(input)
}
fn account_action(input: &[u8]) -> IResult<&[u8], Action> {

View File

@ -81,6 +81,7 @@ pub enum ComposeAction {
RemoveAttachment(usize),
SaveDraft,
ToggleSign,
ToggleEncrypt,
}
#[derive(Debug)]

View File

@ -81,6 +81,7 @@ pub struct Composer {
embed_area: Area,
embed: Option<EmbedStatus>,
sign_mail: ToggleFlag,
encrypt_mail: ToggleFlag,
dirty: bool,
has_changes: bool,
initialized: bool,
@ -103,6 +104,7 @@ impl Default for Composer {
mode: ViewMode::Edit,
sign_mail: ToggleFlag::Unset,
encrypt_mail: ToggleFlag::Unset,
dirty: true,
has_changes: false,
embed_area: ((0, 0), (0, 0)),
@ -451,9 +453,15 @@ impl Composer {
None,
);
}
if attachments_no == 0 {
if self.encrypt_mail.is_true() {
write_string_to_grid(
"no attachments",
&format!(
"☑ encrypt with {}",
account_settings!(context[self.account_hash].pgp.encrypt_key)
.as_ref()
.map(|s| s.as_str())
.unwrap_or("default key")
),
grid,
theme_default.fg,
theme_default.bg,
@ -463,7 +471,7 @@ impl Composer {
);
} else {
write_string_to_grid(
&format!("{} attachments ", attachments_no),
"☐ don't encrypt",
grid,
theme_default.fg,
theme_default.bg,
@ -471,6 +479,27 @@ impl Composer {
(pos_inc(upper_left!(area), (0, 2)), bottom_right!(area)),
None,
);
}
if attachments_no == 0 {
write_string_to_grid(
"no attachments",
grid,
theme_default.fg,
theme_default.bg,
theme_default.attrs,
(pos_inc(upper_left!(area), (0, 3)), bottom_right!(area)),
None,
);
} else {
write_string_to_grid(
&format!("{} attachments ", attachments_no),
grid,
theme_default.fg,
theme_default.bg,
theme_default.attrs,
(pos_inc(upper_left!(area), (0, 3)), bottom_right!(area)),
None,
);
for (i, a) in self.draft.attachments().iter().enumerate() {
if let Some(name) = a.content_type().name() {
write_string_to_grid(
@ -485,7 +514,7 @@ impl Composer {
theme_default.fg,
theme_default.bg,
theme_default.attrs,
(pos_inc(upper_left!(area), (0, 3 + i)), bottom_right!(area)),
(pos_inc(upper_left!(area), (0, 4 + i)), bottom_right!(area)),
None,
);
} else {
@ -495,7 +524,7 @@ impl Composer {
theme_default.fg,
theme_default.bg,
theme_default.attrs,
(pos_inc(upper_left!(area), (0, 3 + i)), bottom_right!(area)),
(pos_inc(upper_left!(area), (0, 4 + i)), bottom_right!(area)),
None,
);
}
@ -523,6 +552,11 @@ impl Component for Composer {
context[self.account_hash].pgp.auto_sign
));
}
if self.encrypt_mail.is_unset() {
self.encrypt_mail = ToggleFlag::InternalVal(*account_settings!(
context[self.account_hash].pgp.auto_encrypt
));
}
if !self.draft.headers().contains_key("From") || self.draft.headers()["From"].is_empty()
{
self.draft.set_header(
@ -1323,6 +1357,12 @@ impl Component for Composer {
self.dirty = true;
return true;
}
Action::Compose(ComposeAction::ToggleEncrypt) => {
let is_true = self.encrypt_mail.is_true();
self.encrypt_mail = ToggleFlag::from(!is_true);
self.dirty = true;
return true;
}
_ => {}
},
_ => {}