Move id format check from server into notmuch

This commit is contained in:
Bill Thiede 2025-04-20 10:47:40 -07:00
parent c703be2ca5
commit 4da888b240
2 changed files with 7 additions and 7 deletions

View File

@ -598,6 +598,11 @@ impl Notmuch {
#[instrument(skip_all, fields(id=id,part=part))]
pub fn show_original_part(&self, id: &MessageId, part: usize) -> Result<Vec<u8>, NotmuchError> {
let id = if id.starts_with("id:") {
id
} else {
&format!("id:{id}")
};
let res = self.run_notmuch(["show", "--part", &part.to_string(), id])?;
Ok(res)
}

View File

@ -29,7 +29,7 @@ use serde::Deserialize;
use sqlx::postgres::PgPool;
use tokio::{net::TcpListener, sync::Mutex};
use tower_http::trace::{DefaultMakeSpan, TraceLayer};
use tracing::{info, warn};
use tracing::info;
// Make our own error that wraps `anyhow::Error`.
struct AppError(letterbox_server::ServerError);
@ -148,12 +148,7 @@ async fn view_original(
extract::Path(id): extract::Path<String>,
) -> Result<impl IntoResponse, AppError> {
info!("view_original {id}");
let mid = if id.starts_with("id:") {
id
} else {
format!("id:{id}")
};
let bytes = nm.show_original(&mid)?;
let bytes = nm.show_original(&id)?;
let s = String::from_utf8_lossy(&bytes).to_string();
Ok(s.into_response())
}