summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManos Pitsidianakis <el13635@mail.ntua.gr>2019-03-31 20:08:37 +0300
committerManos Pitsidianakis <el13635@mail.ntua.gr>2019-06-10 19:40:41 +0300
commit5d9af8e32b3b54753211f8ee50979ec035baec78 (patch)
tree88d9d74f17695288d29d76ef313fce38cf4951b8
parent37716c85df474653d62aa28b86f487dd182648fe (diff)
ui: improve contact additions from mail view
-rw-r--r--melib/src/addressbook.rs36
-rw-r--r--ui/src/components/mail/view.rs67
2 files changed, 52 insertions, 51 deletions
diff --git a/melib/src/addressbook.rs b/melib/src/addressbook.rs
index 3db7f1ed..3d5e2f8d 100644
--- a/melib/src/addressbook.rs
+++ b/melib/src/addressbook.rs
@@ -149,32 +149,32 @@ impl Card {
pub fn set_id(&mut self, new: Uuid) {
self.id = new;
}
- pub fn set_title(&mut self, new: &str) {
- self.title = new.to_string();
+ pub fn set_title(&mut self, new: String) {
+ self.title = new;
}
- pub fn set_firstname(&mut self, new: &str) {
- self.firstname = new.to_string();
+ pub fn set_firstname(&mut self, new: String) {
+ self.firstname = new;
}
- pub fn set_lastname(&mut self, new: &str) {
- self.lastname = new.to_string();
+ pub fn set_lastname(&mut self, new: String) {
+ self.lastname = new;
}
- pub fn set_additionalname(&mut self, new: &str) {
- self.additionalname = new.to_string();
+ pub fn set_additionalname(&mut self, new: String) {
+ self.additionalname = new;
}
- pub fn set_name_prefix(&mut self, new: &str) {
- self.name_prefix = new.to_string();
+ pub fn set_name_prefix(&mut self, new: String) {
+ self.name_prefix = new;
}
- pub fn set_name_suffix(&mut self, new: &str) {
- self.name_suffix = new.to_string();
+ pub fn set_name_suffix(&mut self, new: String) {
+ self.name_suffix = new;
}
- pub fn set_email(&mut self, new: &str) {
- self.email = new.to_string();
+ pub fn set_email(&mut self, new: String) {
+ self.email = new;
}
- pub fn set_url(&mut self, new: &str) {
- self.url = new.to_string();
+ pub fn set_url(&mut self, new: String) {
+ self.url = new;
}
- pub fn set_key(&mut self, new: &str) {
- self.key = new.to_string();
+ pub fn set_key(&mut self, new: String) {
+ self.key = new;
}
pub fn set_extra_property(&mut self, key: &str, value: String) {
diff --git a/ui/src/components/mail/view.rs b/ui/src/components/mail/view.rs
index b09a55d6..b8fd4b88 100644
--- a/ui/src/components/mail/view.rs
+++ b/ui/src/components/mail/view.rs
@@ -394,53 +394,54 @@ impl Component for MailView {
match event.event_type {
UIEventType::Input(Key::Char('c')) => {
- /*
- let mut new_card: Card = Card::new();
- new_card.set_email(&envelope.from()[0].get_email());
- new_card.set_firstname(&envelope.from()[0].get_display_name());
-
- if cfg!(feature = "debug_log") {
- eprintln!("{:?}", new_card);
- }
-
- */
if let ViewMode::ContactSelector(_) = self.mode {
if let ViewMode::ContactSelector(s) =
std::mem::replace(&mut self.mode, ViewMode::Normal)
- {
- for c in s.collect() {
- let mut new_card: Card = Card::new();
- let email = String::from_utf8(c).unwrap();
- new_card.set_email(&email);
- new_card.set_firstname("");
- context.accounts[self.coordinates.0]
- .address_book
- .add_card(new_card);
+ {
+ let account = &mut context.accounts[self.coordinates.0];
+ let mut results = Vec::new();
+ {
+ let mailbox = &account[self.coordinates.1]
+ .as_ref()
+ .unwrap();
+ let envelope: &Envelope = &mailbox.collection[&self.coordinates.2];
+ for c in s.collect() {
+ let c = usize::from_ne_bytes({
+ [c[0], c[1], c[2], c[3], c[4], c[5], c[6], c[7]]
+ });
+ for (idx, env) in envelope.from().iter().chain(envelope.to().iter()).enumerate() {
+ if idx != c {
+ continue;
+ }
+
+ let mut new_card: Card = Card::new();
+ new_card.set_email(env.get_email());
+ new_card.set_lastname(env.get_display_name());
+ results.push(new_card);
+ }
+ }
+ }
+ for c in results {
+ account.address_book.add_card(c);
+ }
}
- //if cfg!(feature = "debug_log") {
- //eprintln!("{:?}", s.collect());
- //}
- }
return true;
}
-
let accounts = &context.accounts;
let mailbox = &accounts[self.coordinates.0][self.coordinates.1]
.as_ref()
.unwrap();
let envelope: &Envelope = &mailbox.collection[&self.coordinates.2];
+
let mut entries = Vec::new();
- entries.push((
- envelope.from()[0].get_email().into_bytes(),
- format!("{}", envelope.from()[0]),
- ));
- entries.push((
- envelope.to()[0].get_email().into_bytes(),
- format!("{}", envelope.to()[0]),
- ));
+ for (idx, env) in envelope.from().iter().chain(envelope.to().iter()).enumerate() {
+ entries.push((
+ idx.to_ne_bytes().to_vec(),
+ format!("{}", env),
+ ));
+ }
self.mode = ViewMode::ContactSelector(Selector::new(entries, true));
self.dirty = true;
- //context.accounts.context(self.coordinates.0).address_book.add_card(new_card);
}
UIEventType::Input(Key::Esc) | UIEventType::Input(Key::Alt('')) => {
self.cmd_buf.clear();