From d3cbf184e606d5b7ade9cfb125db01f45d7180ae Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Sat, 23 Sep 2023 18:49:51 +0300 Subject: [PATCH] compose: add extra_submission_headers fields in composer form and autocomplete for Newsgroups Submitting to NNTP/Usenet servers requires you to specify which news groups the post/article is going to. This commit places all extra_submission_headers from a backend (in this case only NNTP implements this) in the composing form fields. Fixes #267 nntp should add Newsgroups header if missing Signed-off-by: Manos Pitsidianakis --- meli/src/mail/compose.rs | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/meli/src/mail/compose.rs b/meli/src/mail/compose.rs index f929f733..31b366ec 100644 --- a/meli/src/mail/compose.rs +++ b/meli/src/mail/compose.rs @@ -207,6 +207,14 @@ impl Composer { .iter() .any(|hn| hn.as_str() == h.name()) }); + + for h in context.accounts[&account_hash] + .backend_capabilities + .extra_submission_headers + { + ret.draft.set_header(h.clone(), String::new()); + } + for (h, v) in account_settings!(context[account_hash].composing.default_header_values).iter() { @@ -582,6 +590,33 @@ To: {} self.form.set_cursor(old_cursor); let headers = self.draft.headers(); let account_hash = self.account_hash; + for k in context.accounts[&account_hash] + .backend_capabilities + .extra_submission_headers + { + if matches!(*k, HeaderName::NEWSGROUPS) { + self.form.push_cl(( + k.into(), + headers[k].to_string(), + Box::new(move |c, term| { + c.accounts[&account_hash] + .mailbox_entries + .values() + .filter_map(|v| { + if v.path.starts_with(term) { + Some(v.path.to_string()) + } else { + None + } + }) + .map(AutoCompleteEntry::from) + .collect::>() + }), + )); + } else { + self.form.push((k.into(), headers[k].to_string())); + } + } for k in &[ HeaderName::DATE, HeaderName::FROM, @@ -590,7 +625,7 @@ To: {} HeaderName::BCC, HeaderName::SUBJECT, ] { - if k == HeaderName::TO || k == HeaderName::CC || k == HeaderName::BCC { + if matches!(*k, HeaderName::TO | HeaderName::CC | HeaderName::BCC) { self.form.push_cl(( k.into(), headers[k].to_string(),