Move id format check from server into notmuch
This commit is contained in:
parent
c703be2ca5
commit
4da888b240
@ -598,6 +598,11 @@ impl Notmuch {
|
|||||||
|
|
||||||
#[instrument(skip_all, fields(id=id,part=part))]
|
#[instrument(skip_all, fields(id=id,part=part))]
|
||||||
pub fn show_original_part(&self, id: &MessageId, part: usize) -> Result<Vec<u8>, NotmuchError> {
|
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])?;
|
let res = self.run_notmuch(["show", "--part", &part.to_string(), id])?;
|
||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -29,7 +29,7 @@ use serde::Deserialize;
|
|||||||
use sqlx::postgres::PgPool;
|
use sqlx::postgres::PgPool;
|
||||||
use tokio::{net::TcpListener, sync::Mutex};
|
use tokio::{net::TcpListener, sync::Mutex};
|
||||||
use tower_http::trace::{DefaultMakeSpan, TraceLayer};
|
use tower_http::trace::{DefaultMakeSpan, TraceLayer};
|
||||||
use tracing::{info, warn};
|
use tracing::info;
|
||||||
|
|
||||||
// Make our own error that wraps `anyhow::Error`.
|
// Make our own error that wraps `anyhow::Error`.
|
||||||
struct AppError(letterbox_server::ServerError);
|
struct AppError(letterbox_server::ServerError);
|
||||||
@ -148,12 +148,7 @@ async fn view_original(
|
|||||||
extract::Path(id): extract::Path<String>,
|
extract::Path(id): extract::Path<String>,
|
||||||
) -> Result<impl IntoResponse, AppError> {
|
) -> Result<impl IntoResponse, AppError> {
|
||||||
info!("view_original {id}");
|
info!("view_original {id}");
|
||||||
let mid = if id.starts_with("id:") {
|
let bytes = nm.show_original(&id)?;
|
||||||
id
|
|
||||||
} else {
|
|
||||||
format!("id:{id}")
|
|
||||||
};
|
|
||||||
let bytes = nm.show_original(&mid)?;
|
|
||||||
let s = String::from_utf8_lossy(&bytes).to_string();
|
let s = String::from_utf8_lossy(&bytes).to_string();
|
||||||
Ok(s.into_response())
|
Ok(s.into_response())
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user