Add `mailto` command to open composer with initial values from mailto template
parent
de2f46fe61
commit
660bacb926
|
@ -472,6 +472,10 @@ open list archive with
|
||||||
.El
|
.El
|
||||||
.Ss composing mail commands
|
.Ss composing mail commands
|
||||||
.Bl -tag -width 36n
|
.Bl -tag -width 36n
|
||||||
|
.It Cm mailto Ar MAILTO_ADDRESS
|
||||||
|
Opens a composer tab with initial values parsed from the
|
||||||
|
.Li mailto:
|
||||||
|
address.
|
||||||
.It Cm add-attachment Ar PATH
|
.It Cm add-attachment Ar PATH
|
||||||
in composer, add
|
in composer, add
|
||||||
.Ar PATH
|
.Ar PATH
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
use super::*;
|
use super::*;
|
||||||
use std::convert::TryFrom;
|
use std::convert::TryFrom;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Mailto {
|
pub struct Mailto {
|
||||||
pub address: Address,
|
pub address: Address,
|
||||||
pub subject: Option<String>,
|
pub subject: Option<String>,
|
||||||
|
@ -47,7 +47,13 @@ impl From<Mailto> for Draft {
|
||||||
ret.set_header("Bcc", bcc.unwrap_or_default());
|
ret.set_header("Bcc", bcc.unwrap_or_default());
|
||||||
ret.set_body(body.unwrap_or_default());
|
ret.set_body(body.unwrap_or_default());
|
||||||
ret.set_header("To", address.to_string());
|
ret.set_header("To", address.to_string());
|
||||||
debug!(ret)
|
ret
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<&Mailto> for Draft {
|
||||||
|
fn from(val: &Mailto) -> Self {
|
||||||
|
Draft::from(val.clone())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -184,6 +184,12 @@ impl From<nom::Err<nom::error::Error<&[u8]>>> for Error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'i> From<ParsingError<&'i [u8]>> for nom::error::Error<&'i [u8]> {
|
||||||
|
fn from(val: ParsingError<&'i [u8]>) -> nom::error::Error<&'i [u8]> {
|
||||||
|
nom::error::Error::new(val.input, ErrorKind::Satisfy)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
macro_rules! is_ctl_or_space {
|
macro_rules! is_ctl_or_space {
|
||||||
($var:ident) => {
|
($var:ident) => {
|
||||||
/* <any ASCII control character and DEL> */
|
/* <any ASCII control character and DEL> */
|
||||||
|
@ -952,7 +958,7 @@ pub mod generic {
|
||||||
let value = String::from_utf8_lossy(&input[..value_end]).to_string();
|
let value = String::from_utf8_lossy(&input[..value_end]).to_string();
|
||||||
match tag {
|
match tag {
|
||||||
b"subject" if subject.is_none() => {
|
b"subject" if subject.is_none() => {
|
||||||
subject = Some(value);
|
subject = Some(value.replace("%20", " "));
|
||||||
}
|
}
|
||||||
b"cc" if cc.is_none() => {
|
b"cc" if cc.is_none() => {
|
||||||
cc = Some(value);
|
cc = Some(value);
|
||||||
|
|
|
@ -500,6 +500,20 @@ define_commands!([
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
{ tags: ["mailto "],
|
||||||
|
desc: "mailto MAILTO_ADDRESS",
|
||||||
|
tokens: &[One(Literal("mailto")), One(QuotedStringValue)],
|
||||||
|
parser:(
|
||||||
|
fn mailto(input: &[u8]) -> IResult<&[u8], Action> {
|
||||||
|
let (input, _) = tag("mailto")(input.ltrim())?;
|
||||||
|
let (input, _) = is_a(" ")(input)?;
|
||||||
|
let (input, val) = map_res(not_line_ending, std::str::from_utf8)(input.trim())?;
|
||||||
|
let (_empty, _) = eof(input)?;
|
||||||
|
let (input, val) = melib::email::parser::generic::mailto(val.as_bytes()).map_err(|err| err.map(Into::into))?;
|
||||||
|
Ok((input, Compose(Mailto(val))))
|
||||||
|
}
|
||||||
|
)
|
||||||
|
},
|
||||||
/* Pipe pager contents to binary */
|
/* Pipe pager contents to binary */
|
||||||
{ tags: ["pipe "],
|
{ tags: ["pipe "],
|
||||||
desc: "pipe EXECUTABLE ARGS",
|
desc: "pipe EXECUTABLE ARGS",
|
||||||
|
@ -931,6 +945,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((
|
alt((
|
||||||
add_attachment,
|
add_attachment,
|
||||||
|
mailto,
|
||||||
remove_attachment,
|
remove_attachment,
|
||||||
toggle_sign,
|
toggle_sign,
|
||||||
toggle_encrypt,
|
toggle_encrypt,
|
||||||
|
|
|
@ -89,6 +89,7 @@ pub enum ComposeAction {
|
||||||
SaveDraft,
|
SaveDraft,
|
||||||
ToggleSign,
|
ToggleSign,
|
||||||
ToggleEncrypt,
|
ToggleEncrypt,
|
||||||
|
Mailto(melib::Mailto),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|
|
@ -1889,6 +1889,15 @@ impl Component for Listing {
|
||||||
.push_back(UIEvent::Action(Tab(New(Some(Box::new(mgr))))));
|
.push_back(UIEvent::Action(Tab(New(Some(Box::new(mgr))))));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
UIEvent::Action(Action::Compose(ComposeAction::Mailto(ref mailto))) => {
|
||||||
|
let account_hash = context.accounts[self.cursor_pos.0].hash();
|
||||||
|
let mut composer = Composer::with_account(account_hash, context);
|
||||||
|
composer.set_draft(mailto.into());
|
||||||
|
context
|
||||||
|
.replies
|
||||||
|
.push_back(UIEvent::Action(Tab(New(Some(Box::new(composer))))));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
UIEvent::StartupCheck(_)
|
UIEvent::StartupCheck(_)
|
||||||
| UIEvent::MailboxUpdate(_)
|
| UIEvent::MailboxUpdate(_)
|
||||||
| UIEvent::EnvelopeUpdate(_)
|
| UIEvent::EnvelopeUpdate(_)
|
||||||
|
|
Loading…
Reference in New Issue