Browse Source

melib/imap: use LITERAL+ with APPEND

Closes #50
tags/alpha-0.6.0
Manos Pitsidianakis 9 months ago
parent
commit
1b8529c59c
Signed by: epilys GPG Key ID: 73627C2F690DF710
1 changed files with 31 additions and 11 deletions
  1. +31
    -11
      melib/src/backends/imap.rs

+ 31
- 11
melib/src/backends/imap.rs View File

@ -65,6 +65,7 @@ pub static SUPPORTED_CAPABILITIES: &[&str] = &[
"IMAP4REV1",
"SPECIAL-USE",
"UNSELECT",
"LITERAL+",
];
#[derive(Debug, Default)]
@ -407,18 +408,37 @@ impl MailBackend for ImapType {
let mut response = String::with_capacity(8 * 1024);
let mut conn = connection.lock().await;
let flags = flags.unwrap_or_else(Flag::empty);
conn.send_command(
format!(
"APPEND \"{}\" ({}) {{{}}}",
&path,
flags_to_imap_list!(flags),
bytes.len()
let has_literal_plus: bool = uid_store
.capabilities
.lock()
.unwrap()
.iter()
.any(|cap| cap.eq_ignore_ascii_case(b"LITERAL+"));
if has_literal_plus {
conn.send_command(
format!(
"APPEND \"{}\" ({}) {{{}+}}",
&path,
flags_to_imap_list!(flags),
bytes.len()
)
.as_bytes(),
)
.as_bytes(),
)
.await?;
// wait for "+ Ready for literal data" reply
conn.wait_for_continuation_request().await?;
.await?;
} else {
conn.send_command(
format!(
"APPEND \"{}\" ({}) {{{}}}",
&path,
flags_to_imap_list!(flags),
bytes.len()
)
.as_bytes(),
)
.await?;
// wait for "+ Ready for literal data" reply
conn.wait_for_continuation_request().await?;
}
conn.send_literal(&bytes).await?;
conn.read_response(&mut response, RequiredResponses::empty())
.await?;

Loading…
Cancel
Save