Browse Source

Add toggle encrypt action in composer

Does nothing for now, will be used in a future commit.
jmap-eventsource
Manos Pitsidianakis 1 year ago
parent
commit
08df7f39b2
Signed by untrusted user: epilys GPG Key ID: 73627C2F690DF710
  1. 21
      src/command.rs
  2. 1
      src/command/actions.rs
  3. 48
      src/components/mail/compose.rs

21
src/command.rs

@ -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> {

1
src/command/actions.rs

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

48
src/components/mail/compose.rs

@ -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,6 +453,33 @@ impl Composer {
None,
);
}
if self.encrypt_mail.is_true() {
write_string_to_grid(
&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,
theme_default.attrs,
(pos_inc(upper_left!(area), (0, 2)), bottom_right!(area)),
None,
);
} else {
write_string_to_grid(
"☐ don't encrypt",
grid,
theme_default.fg,
theme_default.bg,
theme_default.attrs,
(pos_inc(upper_left!(area), (0, 2)), bottom_right!(area)),
None,
);
}
if attachments_no == 0 {
write_string_to_grid(
"no attachments",
@ -458,7 +487,7 @@ impl Composer {
theme_default.fg,
theme_default.bg,
theme_default.attrs,
(pos_inc(upper_left!(area), (0, 2)), bottom_right!(area)),
(pos_inc(upper_left!(area), (0, 3)), bottom_right!(area)),
None,
);
} else {
@ -468,7 +497,7 @@ impl Composer {
theme_default.fg,
theme_default.bg,
theme_default.attrs,
(pos_inc(upper_left!(area), (0, 2)), bottom_right!(area)),
(pos_inc(upper_left!(area), (0, 3)), bottom_right!(area)),
None,
);
for (i, a) in self.draft.attachments().iter().enumerate() {
@ -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;
}
_ => {}
},
_ => {}

Loading…
Cancel
Save