Add Newsgroups field when composing NNTP articles #305

Merged
Manos Pitsidianakis merged 2 commits from feature/add-nntp-newsgroups-header into master 2023-09-23 19:11:59 +03:00
8 changed files with 44 additions and 2 deletions

View File

@ -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::<Vec<AutoCompleteEntry>>()
}),
));
} 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(),

View File

@ -37,7 +37,7 @@ use super::email::{Envelope, EnvelopeHash, Flag};
use crate::{
conf::AccountSettings,
error::{Error, ErrorKind, Result},
LogLevel,
HeaderName, LogLevel,
};
#[macro_export]
@ -328,6 +328,7 @@ pub struct MailBackendCapabilities {
pub supports_search: bool,
pub supports_tags: bool,
pub supports_submission: bool,
pub extra_submission_headers: &'static [HeaderName],
}
#[derive(Debug, Copy, Clone)]

View File

@ -292,6 +292,7 @@ impl MailBackend for ImapType {
extensions: Some(extensions),
supports_tags: true,
supports_submission: false,
extra_submission_headers: &[],
}
}

View File

@ -299,6 +299,7 @@ impl MailBackend for JmapType {
extensions: None,
supports_tags: true,
supports_submission: true,
extra_submission_headers: &[],
};
let supports_submission: bool = self
.store

View File

@ -186,6 +186,7 @@ impl MailBackend for MaildirType {
extensions: None,
supports_tags: false,
supports_submission: false,
extra_submission_headers: &[],
};
CAPABILITIES
}

View File

@ -836,6 +836,7 @@ impl MailBackend for MboxType {
extensions: None,
supports_tags: false,
supports_submission: false,
extra_submission_headers: &[],
};
CAPABILITIES
}

View File

@ -217,6 +217,7 @@ impl MailBackend for NntpType {
extensions: Some(extensions),
supports_tags: false,
supports_submission,
extra_submission_headers: &[HeaderName::NEWSGROUPS],
}
}

View File

@ -603,6 +603,7 @@ impl MailBackend for NotmuchDb {
extensions: None,
supports_tags: true,
supports_submission: false,
extra_submission_headers: &[],
};
CAPABILITIES
}