Add save-draft command

pull/234/head
Manos Pitsidianakis 4 years ago
parent 64e5d4af4f
commit 4ae7a57d45
No known key found for this signature in database
GPG Key ID: 73627C2F690DF710

@ -355,6 +355,8 @@ remove attachment with given index
.It Cm toggle sign
toggle between signing and not signing this message.
If the gpg invocation fails then the mail won't be sent.
.It Cm save-draft
saves a copy of the draft in the Draft folder
.El
.Pp
generic commands:

@ -1070,6 +1070,16 @@ impl Component for Composer {
self.dirty = true;
return true;
}
Action::Compose(ComposeAction::SaveDraft) => {
save_draft(
self.draft.clone().finalise().unwrap().as_bytes(),
context,
SpecialUsageMailbox::Drafts,
Flag::SEEN | Flag::DRAFT,
self.account_cursor,
);
return true;
}
Action::Compose(ComposeAction::ToggleSign) => {
let is_true = self.sign_mail.is_true();
self.sign_mail = ToggleFlag::from(!is_true);
@ -1338,14 +1348,25 @@ pub fn save_draft(
flags: Flag,
account_cursor: usize,
) {
if let Err(MeliError {
summary, details, ..
}) = context.accounts[account_cursor].save_special(bytes, mailbox_type, flags)
{
context.replies.push_back(UIEvent::Notification(
summary.map(|s| s.into()),
details.into(),
Some(NotificationType::ERROR),
));
match context.accounts[account_cursor].save_special(bytes, mailbox_type, flags) {
Err(MeliError {
summary, details, ..
}) => {
context.replies.push_back(UIEvent::Notification(
summary.map(|s| s.into()),
details.into(),
Some(NotificationType::ERROR),
));
}
Ok(mailbox_hash) => {
context.replies.push_back(UIEvent::Notification(
Some("Draft saved".into()),
format!(
"Draft saved in `{}`",
&context.accounts[account_cursor].mailbox_entries[&mailbox_hash].name
),
Some(NotificationType::INFO),
));
}
}
}

@ -896,8 +896,8 @@ impl Account {
bytes: &[u8],
mailbox_type: SpecialUsageMailbox,
flags: Flag,
) -> Result<()> {
let mut failure = true;
) -> Result<MailboxHash> {
let mut saved_at: Option<MailboxHash> = None;
for mailbox in &[
self.special_use_mailbox(mailbox_type),
self.special_use_mailbox(SpecialUsageMailbox::Inbox),
@ -918,12 +918,14 @@ impl Account {
melib::ERROR,
);
} else {
failure = false;
saved_at = Some(mailbox);
break;
}
}
if failure {
if let Some(mailbox_hash) = saved_at {
Ok(mailbox_hash)
} else {
let file = crate::types::create_temp_file(bytes, None, None, false);
debug!("message saved in {}", file.path.display());
melib::log(
@ -939,7 +941,6 @@ impl Account {
))
.set_summary("Could not save in any mailbox"));
}
Ok(())
}
pub fn save(&self, bytes: &[u8], mailbox_hash: MailboxHash, flags: Option<Flag>) -> Result<()> {

@ -482,6 +482,17 @@ define_commands!([
}
)
},
{ tags: ["save-draft"],
desc: "save draft",
tokens: &[One(Literal("save-draft"))],
parser:(
fn save_draft(input: &[u8]) -> IResult<&[u8], Action> {
let (input, _) = tag("save-draft")(input.trim())?;
let (input, _) = eof(input)?;
Ok((input, Compose(SaveDraft)))
}
)
},
{ tags: ["toggle sign "],
desc: "switch between sign/unsign for this draft",
tokens: &[One(Literal("toggle")), One(Literal("sign"))],
@ -678,7 +689,7 @@ fn listing_action(input: &[u8]) -> IResult<&[u8], Action> {
}
fn compose_action(input: &[u8]) -> IResult<&[u8], Action> {
alt((add_attachment, remove_attachment, toggle_sign))(input)
alt((add_attachment, remove_attachment, toggle_sign, save_draft))(input)
}
fn account_action(input: &[u8]) -> IResult<&[u8], Action> {

@ -83,6 +83,7 @@ pub enum ComposeAction {
AddAttachment(String),
AddAttachmentPipe(String),
RemoveAttachment(usize),
SaveDraft,
ToggleSign,
}

Loading…
Cancel
Save