server: set content type when viewing original to prevent download.

This commit is contained in:
Bill Thiede 2021-11-04 19:27:43 -07:00
parent b8a622dba5
commit db0e7c2005

View File

@ -3,7 +3,11 @@ extern crate rocket;
use std::{error::Error, process::Command, str::FromStr};
use rocket::{response::Debug, serde::json::Json, State};
use rocket::{
response::{content::Plain, Debug},
serde::json::Json,
State,
};
use rocket_cors::{AllowedHeaders, AllowedOrigins};
use notmuch::{MessageId, Notmuch, NotmuchError, SearchSummary, ThreadSet};
@ -29,14 +33,14 @@ async fn show(nm: &State<Notmuch>, query: &str) -> Result<Json<ThreadSet>, Debug
}
#[get("/original/<id>")]
async fn original(nm: &State<Notmuch>, id: &str) -> Result<Vec<u8>, Debug<NotmuchError>> {
async fn original(nm: &State<Notmuch>, id: &str) -> Result<Plain<Vec<u8>>, Debug<NotmuchError>> {
let mid = if id.starts_with("id:") {
id.to_string()
} else {
format!("id:{}", id)
};
let res = nm.show_original(&mid)?;
Ok(res)
Ok(Plain(res))
}
#[rocket::main]