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
+5 -29
View File
@@ -4,8 +4,7 @@
* SPDX-License-Identifier: Apache-2.0 OR MIT
*/
use base64::Engine;
use base64::engine::general_purpose::STANDARD;
use encodify::base64::LENIENT;
use crate::db::blobs;
use crate::error::Error;
@@ -56,13 +55,12 @@ pub fn fetch_attachments(
let resp = ctx.client.call(ctx.url, "GetAttachment", &body)?;
let inline = parse_get_attachment_inline(&resp.body)?;
for att in inline {
let cleaned = strip_ascii_whitespace(att.content_base64.as_bytes());
if cleaned.is_empty() {
continue;
}
let bytes = STANDARD.decode(&cleaned).map_err(|e| {
let bytes = LENIENT.decode(&att.content_base64).map_err(|e| {
EwsError::Malformed(format!("attachment {}: base64: {e}", att.attachment_id))
})?;
if bytes.is_empty() {
continue;
}
let media_type = att
.content_type
.unwrap_or_else(|| "application/octet-stream".to_owned());
@@ -79,25 +77,3 @@ pub fn fetch_attachments(
pub fn intern_attachment(conn: &rusqlite::Connection, bytes: &[u8]) -> Result<i64, Error> {
blobs::intern_blob(conn, bytes).map_err(|e| Error::Partial(e.to_string()))
}
fn strip_ascii_whitespace(input: &[u8]) -> Vec<u8> {
let mut out = Vec::with_capacity(input.len());
for b in input {
if !matches!(b, b' ' | b'\t' | b'\n' | b'\r') {
out.push(*b);
}
}
out
}
#[cfg(test)]
mod tests {
use super::strip_ascii_whitespace;
#[test]
fn strips_whitespace_efficiently() {
let input = b"AB CD\nEF\tGH\r\nIJ";
let cleaned = strip_ascii_whitespace(input);
assert_eq!(cleaned, b"ABCDEFGHIJ");
}
}