Add save-draft command
parent
64e5d4af4f
commit
4ae7a57d45
2
meli.1
2
meli.1
|
@ -355,6 +355,8 @@ remove attachment with given index
|
||||||
.It Cm toggle sign
|
.It Cm toggle sign
|
||||||
toggle between signing and not signing this message.
|
toggle between signing and not signing this message.
|
||||||
If the gpg invocation fails then the mail won't be sent.
|
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
|
.El
|
||||||
.Pp
|
.Pp
|
||||||
generic commands:
|
generic commands:
|
||||||
|
|
|
@ -1070,6 +1070,16 @@ impl Component for Composer {
|
||||||
self.dirty = true;
|
self.dirty = true;
|
||||||
return 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) => {
|
Action::Compose(ComposeAction::ToggleSign) => {
|
||||||
let is_true = self.sign_mail.is_true();
|
let is_true = self.sign_mail.is_true();
|
||||||
self.sign_mail = ToggleFlag::from(!is_true);
|
self.sign_mail = ToggleFlag::from(!is_true);
|
||||||
|
@ -1338,14 +1348,25 @@ pub fn save_draft(
|
||||||
flags: Flag,
|
flags: Flag,
|
||||||
account_cursor: usize,
|
account_cursor: usize,
|
||||||
) {
|
) {
|
||||||
if let Err(MeliError {
|
match context.accounts[account_cursor].save_special(bytes, mailbox_type, flags) {
|
||||||
summary, details, ..
|
Err(MeliError {
|
||||||
}) = context.accounts[account_cursor].save_special(bytes, mailbox_type, flags)
|
summary, details, ..
|
||||||
{
|
}) => {
|
||||||
context.replies.push_back(UIEvent::Notification(
|
context.replies.push_back(UIEvent::Notification(
|
||||||
summary.map(|s| s.into()),
|
summary.map(|s| s.into()),
|
||||||
details.into(),
|
details.into(),
|
||||||
Some(NotificationType::ERROR),
|
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],
|
bytes: &[u8],
|
||||||
mailbox_type: SpecialUsageMailbox,
|
mailbox_type: SpecialUsageMailbox,
|
||||||
flags: Flag,
|
flags: Flag,
|
||||||
) -> Result<()> {
|
) -> Result<MailboxHash> {
|
||||||
let mut failure = true;
|
let mut saved_at: Option<MailboxHash> = None;
|
||||||
for mailbox in &[
|
for mailbox in &[
|
||||||
self.special_use_mailbox(mailbox_type),
|
self.special_use_mailbox(mailbox_type),
|
||||||
self.special_use_mailbox(SpecialUsageMailbox::Inbox),
|
self.special_use_mailbox(SpecialUsageMailbox::Inbox),
|
||||||
|
@ -918,12 +918,14 @@ impl Account {
|
||||||
melib::ERROR,
|
melib::ERROR,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
failure = false;
|
saved_at = Some(mailbox);
|
||||||
break;
|
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);
|
let file = crate::types::create_temp_file(bytes, None, None, false);
|
||||||
debug!("message saved in {}", file.path.display());
|
debug!("message saved in {}", file.path.display());
|
||||||
melib::log(
|
melib::log(
|
||||||
|
@ -939,7 +941,6 @@ impl Account {
|
||||||
))
|
))
|
||||||
.set_summary("Could not save in any mailbox"));
|
.set_summary("Could not save in any mailbox"));
|
||||||
}
|
}
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn save(&self, bytes: &[u8], mailbox_hash: MailboxHash, flags: Option<Flag>) -> Result<()> {
|
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 "],
|
{ tags: ["toggle sign "],
|
||||||
desc: "switch between sign/unsign for this draft",
|
desc: "switch between sign/unsign for this draft",
|
||||||
tokens: &[One(Literal("toggle")), One(Literal("sign"))],
|
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> {
|
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> {
|
fn account_action(input: &[u8]) -> IResult<&[u8], Action> {
|
||||||
|
|
|
@ -83,6 +83,7 @@ pub enum ComposeAction {
|
||||||
AddAttachment(String),
|
AddAttachment(String),
|
||||||
AddAttachmentPipe(String),
|
AddAttachmentPipe(String),
|
||||||
RemoveAttachment(usize),
|
RemoveAttachment(usize),
|
||||||
|
SaveDraft,
|
||||||
ToggleSign,
|
ToggleSign,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue