nntp should add Newsgroups header if missing #267

Closed
opened 2023-07-29 14:03:18 +03:00 by Manos Pitsidianakis · 2 comments

Newsgroups header is required, therefore if the user has not set it manually, the backend should add it.

Possible solution: pass mailbox_hash to composer and then forward it to the backend.

diff --git a/melib/src/nntp/mod.rs b/melib/src/nntp/mod.rs
index b336d790..036f4d38 100644
--- a/melib/src/nntp/mod.rs
+++ b/melib/src/nntp/mod.rs
@@ -54,6 +54,7 @@ use futures::{lock::Mutex as FutureMutex, stream::Stream};
 use crate::{
     backends::*,
     conf::AccountSettings,
+    email::parser::BytesExt,
     email::*,
     error::{Error, Result, ResultIntoError},
     utils::futures::timeout,
@@ -580,11 +581,12 @@ impl MailBackend for NntpType {
 
     fn submit(
         &self,
-        bytes: Vec<u8>,
+        mut bytes: Vec<u8>,
         mailbox_hash: Option<MailboxHash>,
         _flags: Option<Flag>,
     ) -> ResultFuture<()> {
         let connection = self.connection.clone();
+        let uid_store = self.uid_store.clone();
         Ok(Box::pin(async move {
             match timeout(Some(Duration::from_secs(60 * 16)), connection.lock()).await {
                 Ok(mut conn) => {
@@ -599,6 +601,16 @@ impl MailBackend for NntpType {
                     let mut res = String::with_capacity(8 * 1024);
                     if let Some(mailbox_hash) = mailbox_hash {
                         conn.select_group(mailbox_hash, false, &mut res).await?;
+                        if !bytes.contains_subsequence(HeaderName::NEWSGROUPS.as_bytes()) {
+                            let f = &uid_store.mailboxes.lock().await[&mailbox_hash]
+                                .nntp_path
+                                .to_string();
+                            let hdr = format!("{}: {f}\n", HeaderName::NEWSGROUPS);
+                            let mut new = Vec::with_capacity(bytes.len() + hdr.len());
+                            new.extend_from_slice(hdr.as_bytes());
+                            new.extend_from_slice(&bytes);
+                            bytes = new;
+                        }
                     }
                     conn.send_command(b"POST").await?;
                     conn.read_response(&mut res, false, &["340 "]).await?;

Reported by @r3k2

Newsgroups header is required, therefore if the user has not set it manually, the backend should add it. Possible solution: pass mailbox_hash to composer and then forward it to the backend. ```diff diff --git a/melib/src/nntp/mod.rs b/melib/src/nntp/mod.rs index b336d790..036f4d38 100644 --- a/melib/src/nntp/mod.rs +++ b/melib/src/nntp/mod.rs @@ -54,6 +54,7 @@ use futures::{lock::Mutex as FutureMutex, stream::Stream}; use crate::{ backends::*, conf::AccountSettings, + email::parser::BytesExt, email::*, error::{Error, Result, ResultIntoError}, utils::futures::timeout, @@ -580,11 +581,12 @@ impl MailBackend for NntpType { fn submit( &self, - bytes: Vec<u8>, + mut bytes: Vec<u8>, mailbox_hash: Option<MailboxHash>, _flags: Option<Flag>, ) -> ResultFuture<()> { let connection = self.connection.clone(); + let uid_store = self.uid_store.clone(); Ok(Box::pin(async move { match timeout(Some(Duration::from_secs(60 * 16)), connection.lock()).await { Ok(mut conn) => { @@ -599,6 +601,16 @@ impl MailBackend for NntpType { let mut res = String::with_capacity(8 * 1024); if let Some(mailbox_hash) = mailbox_hash { conn.select_group(mailbox_hash, false, &mut res).await?; + if !bytes.contains_subsequence(HeaderName::NEWSGROUPS.as_bytes()) { + let f = &uid_store.mailboxes.lock().await[&mailbox_hash] + .nntp_path + .to_string(); + let hdr = format!("{}: {f}\n", HeaderName::NEWSGROUPS); + let mut new = Vec::with_capacity(bytes.len() + hdr.len()); + new.extend_from_slice(hdr.as_bytes()); + new.extend_from_slice(&bytes); + bytes = new; + } } conn.send_command(b"POST").await?; conn.read_response(&mut res, false, &["340 "]).await?; ``` Reported by @r3k2

@epilys I can try to dig into this in the next days, since I have some time off from work, anything other that you already have above I should take into consideration?

Cheers

@epilys I can try to dig into this in the next days, since I have some time off from work, anything other that you already have above I should take into consideration? Cheers

@r3k2 I think a good plan would be extending the Composer component to have extra functionality depending on the account's backend. So if it's an nntp account, it could have an extra input field in the composing tab for specifying Newsgroups, and it can even validate the value before sending.

@r3k2 I think a good plan would be extending the Composer component to have extra functionality depending on the account's backend. So if it's an nntp account, it could have an extra input field in the composing tab for specifying `Newsgroups`, and it can even validate the value before sending.
Sign in to join this conversation.
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: meli/meli#267
There is no content yet.