Add add_addresses_to_contacts command
parent
32901f57d2
commit
b88c3c573d
|
@ -742,6 +742,17 @@ Alternatives(&[to_stream!(One(Literal("add-attachment")), One(Filepath)), to_str
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
{ tags: ["add-addresses-to-contacts "],
|
||||||
|
desc: "add-addresses-to-contacts",
|
||||||
|
tokens: &[One(Literal("add-addresses-to-contacts"))],
|
||||||
|
parser:(
|
||||||
|
fn add_addresses_to_contacts(input: &[u8]) -> IResult<&[u8], Action> {
|
||||||
|
let (input, _) = tag("add-addresses-to-contacts")(input.trim())?;
|
||||||
|
let (input, _) = eof(input)?;
|
||||||
|
Ok((input, View(AddAddressesToContacts)))
|
||||||
|
}
|
||||||
|
)
|
||||||
|
},
|
||||||
{ tags: ["tag", "tag add", "tag remove"],
|
{ tags: ["tag", "tag add", "tag remove"],
|
||||||
desc: "tag [add/remove], edits message's tags.",
|
desc: "tag [add/remove], edits message's tags.",
|
||||||
tokens: &[One(Literal("tag")), One(Alternatives(&[to_stream!(One(Literal("add"))), to_stream!(One(Literal("remove")))]))],
|
tokens: &[One(Literal("tag")), One(Alternatives(&[to_stream!(One(Literal("add"))), to_stream!(One(Literal("remove")))]))],
|
||||||
|
@ -900,7 +911,13 @@ fn account_action(input: &[u8]) -> IResult<&[u8], Action> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn view(input: &[u8]) -> IResult<&[u8], Action> {
|
fn view(input: &[u8]) -> IResult<&[u8], Action> {
|
||||||
alt((filter, pipe, save_attachment, export_mail))(input)
|
alt((
|
||||||
|
filter,
|
||||||
|
pipe,
|
||||||
|
save_attachment,
|
||||||
|
export_mail,
|
||||||
|
add_addresses_to_contacts,
|
||||||
|
))(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_command(input: &[u8]) -> Result<Action, MeliError> {
|
pub fn parse_command(input: &[u8]) -> Result<Action, MeliError> {
|
||||||
|
|
|
@ -78,6 +78,7 @@ pub enum ViewAction {
|
||||||
Filter(String),
|
Filter(String),
|
||||||
SaveAttachment(usize, String),
|
SaveAttachment(usize, String),
|
||||||
ExportMail(String),
|
ExportMail(String),
|
||||||
|
AddAddressesToContacts,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|
|
@ -1030,6 +1030,41 @@ impl MailView {
|
||||||
))));
|
))));
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn start_contact_selector(&mut self, context: &mut Context) {
|
||||||
|
let account = &context.accounts[&self.coordinates.0];
|
||||||
|
if !account.contains_key(self.coordinates.2) {
|
||||||
|
context
|
||||||
|
.replies
|
||||||
|
.push_back(UIEvent::StatusEvent(StatusEvent::DisplayMessage(
|
||||||
|
"Email not found".into(),
|
||||||
|
)));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let envelope: EnvelopeRef = account.collection.get_env(self.coordinates.2);
|
||||||
|
|
||||||
|
let mut entries = Vec::new();
|
||||||
|
for addr in envelope.from().iter().chain(envelope.to().iter()) {
|
||||||
|
let mut new_card: Card = Card::new();
|
||||||
|
new_card.set_email(addr.get_email());
|
||||||
|
if let Some(display_name) = addr.get_display_name() {
|
||||||
|
new_card.set_name(display_name);
|
||||||
|
}
|
||||||
|
entries.push((new_card, format!("{}", addr)));
|
||||||
|
}
|
||||||
|
drop(envelope);
|
||||||
|
self.mode = ViewMode::ContactSelector(Selector::new(
|
||||||
|
"select contacts to add",
|
||||||
|
entries,
|
||||||
|
false,
|
||||||
|
Some(Box::new(move |id: ComponentId, results: &[Card]| {
|
||||||
|
Some(UIEvent::FinishedUIDialog(id, Box::new(results.to_vec())))
|
||||||
|
})),
|
||||||
|
context,
|
||||||
|
));
|
||||||
|
self.dirty = true;
|
||||||
|
self.initialised = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Component for MailView {
|
impl Component for MailView {
|
||||||
|
@ -1943,36 +1978,17 @@ impl Component for MailView {
|
||||||
);
|
);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
UIEvent::Action(View(ViewAction::AddAddressesToContacts)) => {
|
||||||
|
self.start_contact_selector(context);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
UIEvent::Input(ref key)
|
UIEvent::Input(ref key)
|
||||||
if !self.mode.is_contact_selector()
|
if !self.mode.is_contact_selector()
|
||||||
&& shortcut!(
|
&& shortcut!(
|
||||||
key == shortcuts[MailView::DESCRIPTION]["add_addresses_to_contacts"]
|
key == shortcuts[MailView::DESCRIPTION]["add_addresses_to_contacts"]
|
||||||
) =>
|
) =>
|
||||||
{
|
{
|
||||||
let account = &context.accounts[&self.coordinates.0];
|
self.start_contact_selector(context);
|
||||||
let envelope: EnvelopeRef = account.collection.get_env(self.coordinates.2);
|
|
||||||
|
|
||||||
let mut entries = Vec::new();
|
|
||||||
for addr in envelope.from().iter().chain(envelope.to().iter()) {
|
|
||||||
let mut new_card: Card = Card::new();
|
|
||||||
new_card.set_email(addr.get_email());
|
|
||||||
if let Some(display_name) = addr.get_display_name() {
|
|
||||||
new_card.set_name(display_name);
|
|
||||||
}
|
|
||||||
entries.push((new_card, format!("{}", addr)));
|
|
||||||
}
|
|
||||||
drop(envelope);
|
|
||||||
self.mode = ViewMode::ContactSelector(Selector::new(
|
|
||||||
"select contacts to add",
|
|
||||||
entries,
|
|
||||||
false,
|
|
||||||
Some(Box::new(move |id: ComponentId, results: &[Card]| {
|
|
||||||
Some(UIEvent::FinishedUIDialog(id, Box::new(results.to_vec())))
|
|
||||||
})),
|
|
||||||
context,
|
|
||||||
));
|
|
||||||
self.dirty = true;
|
|
||||||
self.initialised = false;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
UIEvent::Input(Key::Esc) | UIEvent::Input(Key::Alt(''))
|
UIEvent::Input(Key::Esc) | UIEvent::Input(Key::Alt(''))
|
||||||
|
|
Loading…
Reference in New Issue