Migrate to encodify

This commit is contained in:
Maurus Decimus
2026-09-28 10:45:15 +02:00
parent 42f7c87911
commit 5dc92c7329
29 changed files with 418 additions and 540 deletions
+28 -19
View File
@@ -12,6 +12,7 @@ use std::sync::atomic::{AtomicU32, Ordering};
use std::thread;
use std::time::Duration;
use encodify::base64::STANDARD;
use rusqlite::Connection;
use vandelay::db;
use vandelay::imap::client::{ConnectMode, ImapClient};
@@ -230,7 +231,6 @@ fn authenticate_oauthbearer_sasl_ir() {
#[test]
fn authenticate_oauthbearer_continuation_payload_uses_gs2_header() {
use base64::Engine;
let server = MockImap::start(|conn| {
conn.write_line("* OK Hello")?;
let (tag, _) = conn.read_command()?;
@@ -242,9 +242,7 @@ fn authenticate_oauthbearer_continuation_payload_uses_gs2_header() {
let mut line = String::new();
conn.reader.read_line(&mut line)?;
let payload = line.trim_end_matches(['\r', '\n']).to_owned();
let decoded = base64::engine::general_purpose::STANDARD
.decode(&payload)
.expect("base64");
let decoded = STANDARD.decode(&payload).expect("base64");
let text = std::str::from_utf8(&decoded).unwrap_or("");
assert!(
text.starts_with("n,[email protected],"),
@@ -1871,22 +1869,33 @@ fn mutf7_server_gets_the_folder_name_back_as_mutf7() {
}
#[test]
fn utf8_name_from_a_server_that_never_enabled_utf8_falls_back_on_select() {
let control: Script = Box::new(|conn: &mut MockConn| -> std::io::Result<()> {
fn utf8_name_from_a_server_that_never_enabled_utf8_is_selected_as_listed() {
assert_name_selected_as_listed(FRENCH_SENT_UTF8, FRENCH_SENT_UTF8, "utf8_no_enable");
}
#[test]
fn raw_ampersand_name_is_selected_as_listed_not_reencoded() {
assert_name_selected_as_listed("R&D", "R&D", "raw_ampersand");
}
#[test]
fn modified_utf7_name_is_selected_as_listed() {
assert_name_selected_as_listed(FRENCH_SENT_MUTF7, FRENCH_SENT_UTF8, "mutf7_as_listed");
}
fn assert_name_selected_as_listed(listed: &'static str, stored: &str, archive_name: &str) {
let control: Script = Box::new(move |conn: &mut MockConn| -> std::io::Result<()> {
auth_preamble(conn, "IMAP4rev2 LITERAL+ AUTH=PLAIN")?;
let (tag, cmd) = conn.read_command()?;
assert_eq!(cmd, "LIST \"\" \"*\"");
conn.write_line(&format!("* LIST () \"/\" \"{FRENCH_SENT_UTF8}\""))?;
conn.write_line(&format!("* LIST () \"/\" \"{listed}\""))?;
conn.write_line(&format!("{tag} OK LIST done"))?;
let (tag, _) = conn.read_command()?;
conn.write_line(&format!("{tag} OK LSUB done"))?;
let (tag, name) = read_select_mailbox(conn)?;
assert_eq!(name, FRENCH_SENT_MUTF7);
conn.write_line(&format!("{tag} NO [NONEXISTENT] Mailbox does not exist."))?;
let (tag, name) = read_select_mailbox(conn)?;
assert_eq!(
name, FRENCH_SENT_UTF8,
"a refused modified UTF-7 name must be retried as UTF-8"
name, listed,
"the name must go back exactly as the server listed it"
);
write_select(conn, &tag, 902, 2, 1)?;
let (tag, cmd) = conn.read_command()?;
@@ -1896,13 +1905,13 @@ fn utf8_name_from_a_server_that_never_enabled_utf8_falls_back_on_select() {
drain_until_close(conn);
Ok(())
});
let worker: Script = Box::new(|conn: &mut MockConn| -> std::io::Result<()> {
let worker: Script = Box::new(move |conn: &mut MockConn| -> std::io::Result<()> {
auth_preamble(conn, "IMAP4rev2 LITERAL+ AUTH=PLAIN")?;
let (tag, name) = read_select_mailbox(conn)?;
assert_eq!(name, FRENCH_SENT_MUTF7);
conn.write_line(&format!("{tag} NO [NONEXISTENT] Mailbox does not exist."))?;
let (tag, name) = read_select_mailbox(conn)?;
assert_eq!(name, FRENCH_SENT_UTF8);
assert_eq!(
name, listed,
"the fetch worker must agree with the coordinator"
);
write_select(conn, &tag, 902, 2, 1)?;
let (tag, _) = conn.read_command()?;
write_fetch_message(conn, 1, 1, MSG_BODY)?;
@@ -1912,7 +1921,7 @@ fn utf8_name_from_a_server_that_never_enabled_utf8_falls_back_on_select() {
});
let server = MockImap::start_scripts(vec![control, worker]);
let archive = tempfile("utf8_no_enable");
let archive = tempfile(archive_name);
let summary = run_import(&server, "alice", archive.clone(), |_| {}).expect("import");
let email = summary
.per_type
@@ -1925,7 +1934,7 @@ fn utf8_name_from_a_server_that_never_enabled_utf8_falls_back_on_select() {
assert_eq!(
conn.query_row::<String, _, _>("SELECT name FROM mailboxes", [], |r| r.get(0))
.unwrap(),
FRENCH_SENT_UTF8
stored
);
let _ = std::fs::remove_file(&archive);
}