//! Patch inbound email: message-ID → MT thread mapping for multi-part patch threading.
use sqlx::PgPool;
use super::{MtThreadId, ProjectId};
use crate::error::Result;
/// Store a mapping from an email Message-ID to an MT thread.
#[tracing::instrument(skip_all)]
pub async fn insert_patch_message_id(
pool: &PgPool,
message_id: &str,
project_id: ProjectId,
thread_id: MtThreadId,
) -> Result<()> {
sqlx::query(
"INSERT INTO patch_message_ids (message_id, project_id, thread_id)
VALUES ($1, $2, $3)
ON CONFLICT (message_id) DO NOTHING",
)
.bind(message_id)
.bind(project_id)
.bind(thread_id)
.execute(pool)
.await?;
Ok(())
}
/// Look up a thread by a single email Message-ID.
#[tracing::instrument(skip_all)]
#[allow(dead_code)]
pub async fn get_thread_id_by_message_id(
pool: &PgPool,
message_id: &str,
) -> Result