Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

feat(email): store & sanitize signature in settings, drop Gmail fetch (#4318)

Evan Hutnika78d9f07c797
diff --git a/js/app/packages/service-clients/service-email/generated/client.ts b/js/app/packages/service-clients/service-email/generated/client.ts
index 57644faecc..268626628e 100644
--- a/js/app/packages/service-clients/service-email/generated/client.ts
+++ b/js/app/packages/service-clients/service-email/generated/client.ts
@@ -35,7 +35,6 @@ import type {
ListContactsResponse,
ListEmailFiltersResponse,
ListLabelsResponse,
- ListLinksParams,
ListLinksResponse,
ParsedMessage,
PatchSettingsRequest,
@@ -1777,27 +1776,14 @@ export type listLinksResponse =
| listLinksResponseSuccess
| listLinksResponseError;
-export const getListLinksUrl = (params?: ListLinksParams) => {
- const normalizedParams = new URLSearchParams();
-
- Object.entries(params || {}).forEach(([key, value]) => {
- if (value !== undefined) {
- normalizedParams.append(key, value === null ? 'null' : value.toString());
- }
- });
-
- const stringifiedParams = normalizedParams.toString();
-
- return stringifiedParams.length > 0
- ? `/email/links?${stringifiedParams}`
- : `/email/links`;
+export const getListLinksUrl = () => {
+ return `/email/links`;
};
export const listLinks = async (
- params?: ListLinksParams,
options?: RequestInit
): Promise<listLinksResponse> => {
- const res = await fetch(getListLinksUrl(params), {
+ const res = await fetch(getListLinksUrl(), {
...options,
method: 'GET',
});
diff --git a/js/app/packages/service-clients/service-email/generated/schemas/index.ts b/js/app/packages/service-clients/service-email/generated/schemas/index.ts
index 07e074dd0c..da7bf90bab 100644
--- a/js/app/packages/service-clients/service-email/generated/schemas/index.ts
+++ b/js/app/packages/service-clients/service-email/generated/schemas/index.ts
@@ -188,14 +188,12 @@ export * from './labelType';
export * from './labelTypeProperty';
export * from './link';
export * from './linkPhotoUrl';
-export * from './linkSignature';
export * from './listBackfillJobsResponse';
export * from './listBlockedResponse';
export * from './listContactsResponse';
export * from './listContactsResponseContacts';
export * from './listEmailFiltersResponse';
export * from './listLabelsResponse';
-export * from './listLinksParams';
export * from './listLinksResponse';
export * from './message';
export * from './messageBodyHtmlSanitized';
@@ -244,6 +242,7 @@ export * from './resyncResponse';
export * from './sendMessageRequest';
export * from './sendMessageResponse';
export * from './settings';
+export * from './settingsSignature';
export * from './settingsSignatureOnRepliesForwards';
export * from './sharedInboxConflictResponse';
export * from './syncStatus';
diff --git a/js/app/packages/service-clients/service-email/generated/schemas/link.ts b/js/app/packages/service-clients/service-email/generated/schemas/link.ts
index 525d0e8375..3d4bc721be 100644
--- a/js/app/packages/service-clients/service-email/generated/schemas/link.ts
+++ b/js/app/packages/service-clients/service-email/generated/schemas/link.ts
@@ -5,7 +5,6 @@
* OpenAPI spec version: 0.1.0
*/
import type { LinkPhotoUrl } from './linkPhotoUrl';
-import type { LinkSignature } from './linkSignature';
import type { Settings } from './settings';
import type { SyncStatus } from './syncStatus';
import type { UserProvider } from './userProvider';
@@ -25,7 +24,6 @@ per-inbox reconnect prompt independently of the sync-status badge. */
photo_url?: LinkPhotoUrl;
provider: UserProvider;
settings: Settings;
- signature?: LinkSignature;
sync_status: SyncStatus;
updated_at: string;
}
diff --git a/js/app/packages/service-clients/service-email/generated/schemas/linkSignature.ts b/js/app/packages/service-clients/service-email/generated/schemas/linkSignature.ts
deleted file mode 100644
index ebd9215789..0000000000
--- a/js/app/packages/service-clients/service-email/generated/schemas/linkSignature.ts
+++ /dev/null
@@ -1,8 +0,0 @@
-/**
- * Generated by orval v7.21.0 🍺
- * Do not edit manually.
- * email_service
- * OpenAPI spec version: 0.1.0
- */
-
-export type LinkSignature = string | null;
diff --git a/js/app/packages/service-clients/service-email/generated/schemas/listLinksParams.ts b/js/app/packages/service-clients/service-email/generated/schemas/listLinksParams.ts
deleted file mode 100644
index 605559cc98..0000000000
--- a/js/app/packages/service-clients/service-email/generated/schemas/listLinksParams.ts
+++ /dev/null
@@ -1,13 +0,0 @@
-/**
- * Generated by orval v7.21.0 🍺
- * Do not edit manually.
- * email_service
- * OpenAPI spec version: 0.1.0
- */
-
-export type ListLinksParams = {
- /**
- * If the user's gmail signature should be included in the response. Defaults to false.
- */
- include_signature?: boolean;
-};
diff --git a/js/app/packages/service-clients/service-email/generated/schemas/settings.ts b/js/app/packages/service-clients/service-email/generated/schemas/settings.ts
index 05937d078a..51570cc794 100644
--- a/js/app/packages/service-clients/service-email/generated/schemas/settings.ts
+++ b/js/app/packages/service-clients/service-email/generated/schemas/settings.ts
@@ -4,8 +4,13 @@
* email_service
* OpenAPI spec version: 0.1.0
*/
+import type { SettingsSignature } from './settingsSignature';
import type { SettingsSignatureOnRepliesForwards } from './settingsSignatureOnRepliesForwards';
export interface Settings {
+ /** The user's email signature content (HTML). On a patch, omit or send
+`null` to leave unchanged (both deserialize to `None`); pass an empty
+string to clear it. The column cannot be set to SQL NULL via patch. */
+ signature?: SettingsSignature;
signature_on_replies_forwards?: SettingsSignatureOnRepliesForwards;
}
diff --git a/js/app/packages/service-clients/service-email/generated/schemas/settingsSignature.ts b/js/app/packages/service-clients/service-email/generated/schemas/settingsSignature.ts
new file mode 100644
index 0000000000..98d3f81a8e
--- /dev/null
+++ b/js/app/packages/service-clients/service-email/generated/schemas/settingsSignature.ts
@@ -0,0 +1,13 @@
+/**
+ * Generated by orval v7.21.0 🍺
+ * Do not edit manually.
+ * email_service
+ * OpenAPI spec version: 0.1.0
+ */
+
+/**
+ * The user's email signature content (HTML). On a patch, omit or send
+`null` to leave unchanged (both deserialize to `None`); pass an empty
+string to clear it. The column cannot be set to SQL NULL via patch.
+ */
+export type SettingsSignature = string | null;
diff --git a/js/app/packages/service-clients/service-email/openapi.json b/js/app/packages/service-clients/service-email/openapi.json
index dc5a1f19db..0070a203f6 100644
--- a/js/app/packages/service-clients/service-email/openapi.json
+++ b/js/app/packages/service-clients/service-email/openapi.json
@@ -1577,17 +1577,6 @@
"tags": ["Links"],
"summary": "List all links belonging to the user.",
"operationId": "list_links",
- "parameters": [
- {
- "name": "include_signature",
- "in": "query",
- "description": "If the user's gmail signature should be included in the response. Defaults to false.",
- "required": false,
- "schema": {
- "type": "boolean"
- }
- }
- ],
"responses": {
"200": {
"description": "",
@@ -4278,9 +4267,6 @@
"settings": {
"$ref": "#/components/schemas/Settings"
},
- "signature": {
- "type": ["string", "null"]
- },
"sync_status": {
"$ref": "#/components/schemas/SyncStatus"
},
@@ -4844,6 +4830,10 @@
"Settings": {
"type": "object",
"properties": {
+ "signature": {
+ "type": ["string", "null"],
+ "description": "The user's email signature content (HTML). On a patch, omit or send\n`null` to leave unchanged (both deserialize to `None`); pass an empty\nstring to clear it. The column cannot be set to SQL NULL via patch."
+ },
"signature_on_replies_forwards": {
"type": ["boolean", "null"]
}
diff --git a/local_stack.just b/local_stack.just
index bb32b2a156..effc4afbb7 100644
--- a/local_stack.just
+++ b/local_stack.just
@@ -49,6 +49,25 @@ create_local_queues:
aws --endpoint-url=http://localhost:4566 sqs create-queue --queue-name static-file-s3-event-notification-queue || true
@echo "SQS queues created"
+# Purge all messages from every SQS queue in LocalStack
+purge_queues:
+ #!/usr/bin/env bash
+ set -euo pipefail
+ queues=$(aws --endpoint-url=http://localhost:4566 sqs list-queues --query 'QueueUrls[]' --output text)
+ # `--output text` emits the literal "None" (not empty) when there are no queues.
+ if [ -z "$queues" ] || [ "$queues" = "None" ]; then
+ echo "No SQS queues found"
+ exit 0
+ fi
+ for queue_url in $queues; do
+ if aws --endpoint-url=http://localhost:4566 sqs purge-queue --queue-url "$queue_url"; then
+ echo "Purged $queue_url"
+ else
+ echo "Failed to purge $queue_url" >&2
+ fi
+ done
+ echo "All SQS queues purged"
+
# Create DynamoDB tables in LocalStack
create_local_tables:
# bulk-upload table (PK + SK with GSI)
diff --git a/rust/cloud-storage/.sqlx/query-d728d837465a8c930ea6fd8d69117d216c66bf5fa08d07a44b9f4b5503280111.json b/rust/cloud-storage/.sqlx/query-d728d837465a8c930ea6fd8d69117d216c66bf5fa08d07a44b9f4b5503280111.json
new file mode 100644
index 0000000000..19f2172a05
--- /dev/null
+++ b/rust/cloud-storage/.sqlx/query-d728d837465a8c930ea6fd8d69117d216c66bf5fa08d07a44b9f4b5503280111.json
@@ -0,0 +1,36 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO email_settings (link_id, signature_on_replies_forwards, signature)\n VALUES ($1, COALESCE($2, FALSE), $3)\n ON CONFLICT (link_id)\n DO UPDATE SET\n signature_on_replies_forwards = COALESCE($2, email_settings.signature_on_replies_forwards),\n signature = COALESCE($3, email_settings.signature),\n updated_at = NOW()\n RETURNING link_id, signature_on_replies_forwards, signature\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "link_id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 1,
+ "name": "signature_on_replies_forwards",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 2,
+ "name": "signature",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Bool",
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ true
+ ]
+ },
+ "hash": "d728d837465a8c930ea6fd8d69117d216c66bf5fa08d07a44b9f4b5503280111"
+}
diff --git a/rust/cloud-storage/.sqlx/query-d84f480cd90b929670bdbe24b839126ad17975d9f7490e8a5d521e2c1eb752c5.json b/rust/cloud-storage/.sqlx/query-d84f480cd90b929670bdbe24b839126ad17975d9f7490e8a5d521e2c1eb752c5.json
deleted file mode 100644
index b146805915..0000000000
--- a/rust/cloud-storage/.sqlx/query-d84f480cd90b929670bdbe24b839126ad17975d9f7490e8a5d521e2c1eb752c5.json
+++ /dev/null
@@ -1,29 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n INSERT INTO email_settings (link_id, signature_on_replies_forwards)\n VALUES ($1, $2)\n ON CONFLICT (link_id)\n DO UPDATE SET\n signature_on_replies_forwards = EXCLUDED.signature_on_replies_forwards,\n updated_at = NOW()\n RETURNING link_id, signature_on_replies_forwards\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "link_id",
- "type_info": "Uuid"
- },
- {
- "ordinal": 1,
- "name": "signature_on_replies_forwards",
- "type_info": "Bool"
- }
- ],
- "parameters": {
- "Left": [
- "Uuid",
- "Bool"
- ]
- },
- "nullable": [
- false,
- false
- ]
- },
- "hash": "d84f480cd90b929670bdbe24b839126ad17975d9f7490e8a5d521e2c1eb752c5"
-}
diff --git a/rust/cloud-storage/.sqlx/query-26ab5fa9630526b99a3937baff648f056a532178864f1f62ce55d107d1702f7f.json b/rust/cloud-storage/.sqlx/query-f69d2ac9d0be422ed1b42f04ce1d903d3f19a8bb85f19c40563ef812746cea51.json
similarity index 61%
rename from rust/cloud-storage/.sqlx/query-26ab5fa9630526b99a3937baff648f056a532178864f1f62ce55d107d1702f7f.json
rename to rust/cloud-storage/.sqlx/query-f69d2ac9d0be422ed1b42f04ce1d903d3f19a8bb85f19c40563ef812746cea51.json
index 204ec15fdc..627475f42b 100644
--- a/rust/cloud-storage/.sqlx/query-26ab5fa9630526b99a3937baff648f056a532178864f1f62ce55d107d1702f7f.json
+++ b/rust/cloud-storage/.sqlx/query-f69d2ac9d0be422ed1b42f04ce1d903d3f19a8bb85f19c40563ef812746cea51.json
@@ -1,6 +1,6 @@
{
"db_name": "PostgreSQL",
- "query": "\n SELECT link_id, signature_on_replies_forwards\n FROM email_settings\n WHERE link_id = $1\n ",
+ "query": "\n SELECT link_id, signature_on_replies_forwards, signature\n FROM email_settings\n WHERE link_id = $1\n ",
"describe": {
"columns": [
{
@@ -12,6 +12,11 @@
"ordinal": 1,
"name": "signature_on_replies_forwards",
"type_info": "Bool"
+ },
+ {
+ "ordinal": 2,
+ "name": "signature",
+ "type_info": "Text"
}
],
"parameters": {
@@ -21,8 +26,9 @@
},
"nullable": [
false,
- false
+ false,
+ true
]
},
- "hash": "26ab5fa9630526b99a3937baff648f056a532178864f1f62ce55d107d1702f7f"
+ "hash": "f69d2ac9d0be422ed1b42f04ce1d903d3f19a8bb85f19c40563ef812746cea51"
}
diff --git a/rust/cloud-storage/email_db_client/src/settings/mod.rs b/rust/cloud-storage/email_db_client/src/settings/mod.rs
index fa5500c8d7..5b456939a6 100644
--- a/rust/cloud-storage/email_db_client/src/settings/mod.rs
+++ b/rust/cloud-storage/email_db_client/src/settings/mod.rs
@@ -2,27 +2,30 @@ use models_email::{db, service};
use sqlx::PgPool;
use sqlx::types::Uuid;
-/// Updates a user's settings.
-#[tracing::instrument(skip(pool), err)]
+/// Applies a partial update to a user's settings. Fields left `None` in the
+/// patch keep their existing value (COALESCE); on a fresh insert, an omitted
+/// `signature_on_replies_forwards` is written as FALSE and `signature` as NULL.
+// skip `patch` — it carries the user's signature HTML, which shouldn't hit traces.
+#[tracing::instrument(skip(pool, patch), err)]
pub async fn patch_settings(
pool: &PgPool,
- service_settings: service::settings::Settings,
+ patch: service::settings::SettingsPatch,
) -> anyhow::Result<service::settings::Settings> {
- let db_settings = db::settings::Settings::from(service_settings);
-
let result = sqlx::query_as!(
db::settings::Settings,
r#"
- INSERT INTO email_settings (link_id, signature_on_replies_forwards)
- VALUES ($1, $2)
+ INSERT INTO email_settings (link_id, signature_on_replies_forwards, signature)
+ VALUES ($1, COALESCE($2, FALSE), $3)
ON CONFLICT (link_id)
DO UPDATE SET
- signature_on_replies_forwards = EXCLUDED.signature_on_replies_forwards,
+ signature_on_replies_forwards = COALESCE($2, email_settings.signature_on_replies_forwards),
+ signature = COALESCE($3, email_settings.signature),
updated_at = NOW()
- RETURNING link_id, signature_on_replies_forwards
+ RETURNING link_id, signature_on_replies_forwards, signature
"#,
- db_settings.link_id,
- db_settings.signature_on_replies_forwards,
+ patch.link_id,
+ patch.signature_on_replies_forwards,
+ patch.signature,
)
.fetch_one(pool)
.await?;
@@ -39,7 +42,7 @@ pub async fn fetch_settings(
let result = sqlx::query_as!(
db::settings::Settings,
r#"
- SELECT link_id, signature_on_replies_forwards
+ SELECT link_id, signature_on_replies_forwards, signature
FROM email_settings
WHERE link_id = $1
"#,
diff --git a/rust/cloud-storage/email_service/src/api/email/links/list.rs b/rust/cloud-storage/email_service/src/api/email/links/list.rs
index b54e22e5dc..759d5f445e 100644
--- a/rust/cloud-storage/email_service/src/api/email/links/list.rs
+++ b/rust/cloud-storage/email_service/src/api/email/links/list.rs
@@ -1,9 +1,8 @@
use crate::api::context::ApiContext;
-use axum::extract::{Query, State};
+use axum::extract::State;
use axum::http::StatusCode;
use axum::response::{IntoResponse, Response};
use axum::{Extension, Json};
-use email_service::util::gmail::auth::fetch_gmail_access_token_from_link;
use futures::future::join_all;
use model::response::ErrorResponse;
use model::user::UserContext;
@@ -17,17 +16,12 @@ use thiserror::Error;
pub enum ListLinksError {
#[error("Database error")]
DatabaseError(anyhow::Error),
-
- #[error("Failed to fetch Gmail access token")]
- AuthError(anyhow::Error),
}
impl IntoResponse for ListLinksError {
fn into_response(self) -> Response {
let status_code = match &self {
- ListLinksError::DatabaseError(_) | ListLinksError::AuthError(_) => {
- StatusCode::INTERNAL_SERVER_ERROR
- }
+ ListLinksError::DatabaseError(_) => StatusCode::INTERNAL_SERVER_ERROR,
};
(status_code, self.to_string()).into_response()
@@ -41,21 +35,11 @@ pub struct ListLinksResponse {
pub links: Vec<api::link::Link>,
}
-#[derive(serde::Deserialize, Debug, ToSchema)]
-pub struct QueryParams {
- /// if we should include the user's gmail signature in the response. hits gmail api
- #[serde(default)]
- pub include_signature: bool,
-}
-
/// List all links belonging to the user.
#[utoipa::path(
get,
tag = "Links",
path = "/email/links",
- params(
- ("include_signature" = Option<bool>, Query, description = "If the user's gmail signature should be included in the response. Defaults to false."),
- ),
operation_id = "list_links",
responses(
(status = 200, body=ListLinksResponse),
@@ -68,7 +52,6 @@ pub struct QueryParams {
pub async fn list_links_handler(
State(ctx): State<ApiContext>,
user_context: Extension<UserContext>,
- Query(query_params): Query<QueryParams>,
) -> Result<Response, ListLinksError> {
let links =
email_db_client::links::get::fetch_inboxes_for_macro_id(&ctx.db, &user_context.user_id)
@@ -104,26 +87,8 @@ pub async fn list_links_handler(
.map_err(ListLinksError::DatabaseError)?
.and_then(|contact| contact.photo_url);
- let signature = if query_params.include_signature {
- let access_token = fetch_gmail_access_token_from_link(
- &link,
- &ctx.redis_client,
- &ctx.auth_service_client,
- )
- .await
- .map_err(ListLinksError::AuthError)?;
-
- ctx.gmail_client
- .get_email_signature(&access_token, link.email_address.0.as_ref())
- .await
- .unwrap_or(None)
- } else {
- None
- };
-
Ok(api::link::Link::new(
link,
- signature,
api::settings::Settings::from(settings),
sync_status,
photo_url,
diff --git a/rust/cloud-storage/email_service/src/api/email/settings/patch.rs b/rust/cloud-storage/email_service/src/api/email/settings/patch.rs
index 1be91c758c..60f31c83ab 100644
--- a/rust/cloud-storage/email_service/src/api/email/settings/patch.rs
+++ b/rust/cloud-storage/email_service/src/api/email/settings/patch.rs
@@ -3,6 +3,7 @@ use axum::extract::State;
use axum::http::StatusCode;
use axum::response::{IntoResponse, Response};
use axum::{Extension, Json};
+use email_service::util::sanitizer::sanitize_html_fragment;
use model::response::ErrorResponse;
use models_email::service::link::Link;
use models_email::{api, service};
@@ -56,10 +57,14 @@ pub async fn patch_settings_handler(
link: Extension<Link>,
Json(api_settings): Json<PatchSettingsRequest>,
) -> Result<Json<PatchSettingsResponse>, PatchSettingsError> {
- let service_settings = service::settings::Settings::new(api_settings.settings, link.id);
+ // The signature is user-supplied HTML; sanitize at this trust boundary
+ // before it is persisted (and later rendered into compose bodies).
+ let mut settings = api_settings.settings;
+ settings.signature = settings.signature.map(|html| sanitize_html_fragment(&html));
- let updated_settings =
- email_db_client::settings::patch_settings(&ctx.db, service_settings).await?;
+ let patch = service::settings::SettingsPatch::new(settings, link.id);
+
+ let updated_settings = email_db_client::settings::patch_settings(&ctx.db, patch).await?;
let response_settings = api::settings::Settings::from(updated_settings);
diff --git a/rust/cloud-storage/email_service/src/convert/mod.rs b/rust/cloud-storage/email_service/src/convert/mod.rs
index bc0c9322da..d962905be1 100644
--- a/rust/cloud-storage/email_service/src/convert/mod.rs
+++ b/rust/cloud-storage/email_service/src/convert/mod.rs
@@ -1,7 +1,6 @@
//! Conversion utilities for mapping Gmail API responses to service layer models.
mod payload;
-mod sanitizer;
pub mod contact;
pub mod history;
diff --git a/rust/cloud-storage/email_service/src/convert/payload.rs b/rust/cloud-storage/email_service/src/convert/payload.rs
index 3d6c25a7cf..b1c87b08c3 100644
--- a/rust/cloud-storage/email_service/src/convert/payload.rs
+++ b/rust/cloud-storage/email_service/src/convert/payload.rs
@@ -6,7 +6,7 @@ use models_email::gmail::{Header, MessagePart};
use crate::convert::message::find_header;
use crate::convert::message::parse_address_header;
-use crate::convert::sanitizer::sanitize_email_html;
+use crate::util::sanitizer::sanitize_email_html;
#[derive(Debug, Default)]
pub struct ParsedGmailPayload {
diff --git a/rust/cloud-storage/email_service/src/util/mod.rs b/rust/cloud-storage/email_service/src/util/mod.rs
index 3e3aff2840..6ae6ebe3e1 100644
--- a/rust/cloud-storage/email_service/src/util/mod.rs
+++ b/rust/cloud-storage/email_service/src/util/mod.rs
@@ -1,5 +1,6 @@
pub mod gmail;
pub mod process_pre_insert;
pub mod redis;
+pub mod sanitizer;
pub mod sync_contacts;
pub mod upload_attachment;
diff --git a/rust/cloud-storage/email_service/src/convert/sanitizer.rs b/rust/cloud-storage/email_service/src/util/sanitizer.rs
similarity index 95%
rename from rust/cloud-storage/email_service/src/convert/sanitizer.rs
rename to rust/cloud-storage/email_service/src/util/sanitizer.rs
index 213a3c83cf..bd6ab4811a 100644
--- a/rust/cloud-storage/email_service/src/convert/sanitizer.rs
+++ b/rust/cloud-storage/email_service/src/util/sanitizer.rs
@@ -24,6 +24,14 @@ pub fn sanitize_email_html(raw_html: &str) -> String {
CLEANER.clean(&content_to_clean).to_string()
}
+/// Sanitizes a user-supplied HTML fragment (e.g. an email signature) with the
+/// same allowlist as full email bodies, but without the document/body
+/// reconstruction `sanitize_email_html` applies to whole messages — a fragment
+/// has no `<head>`/`<body>` to extract, so we just clean it in place.
+pub fn sanitize_html_fragment(raw_html: &str) -> String {
+ CLEANER.clean(raw_html).to_string()
+}
+
/// Extracts all <style> tags and the <body> tag from a parsed document,
/// wherever they might be, and reconstructs a clean HTML string.
fn find_and_reconstruct(document: &Html) -> Option<String> {
diff --git a/rust/cloud-storage/gmail_client/src/lib.rs b/rust/cloud-storage/gmail_client/src/lib.rs
index 8f2f197391..2f36b37e8e 100644
--- a/rust/cloud-storage/gmail_client/src/lib.rs
+++ b/rust/cloud-storage/gmail_client/src/lib.rs
@@ -6,7 +6,6 @@ pub(crate) mod history;
pub(crate) mod labels;
pub(crate) mod messages;
pub(crate) mod profile;
-mod settings;
pub(crate) mod threads;
pub(crate) mod watch;
@@ -313,16 +312,6 @@ impl GmailClient {
contacts::list_other_contacts(self, access_token, sync_token).await
}
- /// Gets the email signature for a specific email address
- #[tracing::instrument(skip(self, access_token), err)]
- pub async fn get_email_signature(
- &self,
- access_token: &str,
- email_address: &str,
- ) -> Result<Option<String>, GmailError> {
- settings::get_email_signature(self, access_token, email_address).await
- }
-
/// Blocks a sender by creating a filter that sends their emails to SPAM.
/// This replicates the "Block Sender" functionality in the Gmail UI.
#[tracing::instrument(skip(self, access_token), err)]
diff --git a/rust/cloud-storage/gmail_client/src/settings.rs b/rust/cloud-storage/gmail_client/src/settings.rs
deleted file mode 100644
index da2034bd9f..0000000000
--- a/rust/cloud-storage/gmail_client/src/settings.rs
+++ /dev/null
@@ -1,41 +0,0 @@
-use crate::GmailClient;
-use models_email::gmail::EmailSignature;
-use models_email::gmail::error::GmailError;
-
-#[tracing::instrument(skip(client, access_token), err)]
-pub(crate) async fn get_email_signature(
- client: &GmailClient,
- access_token: &str,
- email_address: &str,
-) -> Result<Option<String>, GmailError> {
- let url = format!(
- "{}/users/me/settings/sendAs/{}",
- client.base_url, email_address
- );
-
- let http_client = client.inner.clone();
-
- let response = http_client
- .get(&url)
- .bearer_auth(access_token)
- .send()
- .await
- .map_err(|e| GmailError::HttpRequest(e.to_string()))?;
-
- let response = response.error_for_status().map_err(|e| match e.status() {
- Some(status) if status.as_u16() == 401 => GmailError::Unauthorized,
- Some(status) if status.as_u16() == 429 => GmailError::RateLimitExceeded,
- Some(status) if status.as_u16() == 404 => GmailError::NotFound(format!(
- "Gmail API returned 404 for email_address: {}",
- email_address
- )),
- _ => GmailError::ApiError(e.to_string()),
- })?;
-
- let email_signature = response
- .json::<EmailSignature>()
- .await
- .map_err(|e| GmailError::BodyReadError(e.to_string()))?;
-
- Ok((!email_signature.signature.is_empty()).then_some(email_signature.signature))
-}
diff --git a/rust/cloud-storage/macro_db_client/migrations/20260624185611_add_signature_to_email_settings.sql b/rust/cloud-storage/macro_db_client/migrations/20260624185611_add_signature_to_email_settings.sql
new file mode 100644
index 0000000000..e7cae0f331
--- /dev/null
+++ b/rust/cloud-storage/macro_db_client/migrations/20260624185611_add_signature_to_email_settings.sql
@@ -0,0 +1,3 @@
+-- store the user's email signature content (HTML) per link
+ALTER TABLE "email_settings"
+ ADD COLUMN IF NOT EXISTS signature TEXT;
diff --git a/rust/cloud-storage/models_email/src/email/api/link.rs b/rust/cloud-storage/models_email/src/email/api/link.rs
index 46c1ea2a39..9221d8965a 100644
--- a/rust/cloud-storage/models_email/src/email/api/link.rs
+++ b/rust/cloud-storage/models_email/src/email/api/link.rs
@@ -98,7 +98,6 @@ pub struct Link {
/// Whether the link's Google grant needs to be reconnected. Drives the
/// per-inbox reconnect prompt independently of the sync-status badge.
pub needs_reauth: bool,
- pub signature: Option<String>,
pub settings: Settings,
pub is_primary: bool,
pub created_at: DateTime<Utc>,
@@ -108,7 +107,6 @@ pub struct Link {
impl Link {
pub fn new(
source: service::link::Link,
- signature: Option<String>,
settings: Settings,
sync_status: SyncStatus,
photo_url: Option<String>,
@@ -123,7 +121,6 @@ impl Link {
is_sync_active: source.is_sync_active,
sync_status,
needs_reauth: source.needs_reauth,
- signature,
settings,
is_primary: source.is_primary,
created_at: source.created_at,
diff --git a/rust/cloud-storage/models_email/src/email/api/settings.rs b/rust/cloud-storage/models_email/src/email/api/settings.rs
index a7f06dc450..230c638d37 100644
--- a/rust/cloud-storage/models_email/src/email/api/settings.rs
+++ b/rust/cloud-storage/models_email/src/email/api/settings.rs
@@ -4,12 +4,17 @@ use utoipa::ToSchema;
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
pub struct Settings {
pub signature_on_replies_forwards: Option<bool>,
+ /// The user's email signature content (HTML). On a patch, omit or send
+ /// `null` to leave unchanged (both deserialize to `None`); pass an empty
+ /// string to clear it. The column cannot be set to SQL NULL via patch.
+ pub signature: Option<String>,
}
impl From<crate::email::service::settings::Settings> for Settings {
fn from(service_settings: crate::email::service::settings::Settings) -> Self {
Settings {
signature_on_replies_forwards: Some(service_settings.signature_on_replies_forwards),
+ signature: service_settings.signature,
}
}
}
diff --git a/rust/cloud-storage/models_email/src/email/db/settings.rs b/rust/cloud-storage/models_email/src/email/db/settings.rs
index 6986ba3f13..1d995336df 100644
--- a/rust/cloud-storage/models_email/src/email/db/settings.rs
+++ b/rust/cloud-storage/models_email/src/email/db/settings.rs
@@ -6,13 +6,5 @@ use uuid::Uuid;
pub struct Settings {
pub link_id: Uuid,
pub signature_on_replies_forwards: bool,
-}
-
-impl From<crate::email::service::settings::Settings> for Settings {
- fn from(service_settings: crate::email::service::settings::Settings) -> Self {
- Settings {
- link_id: service_settings.link_id,
- signature_on_replies_forwards: service_settings.signature_on_replies_forwards,
- }
- }
+ pub signature: Option<String>,
}
diff --git a/rust/cloud-storage/models_email/src/email/service/settings.rs b/rust/cloud-storage/models_email/src/email/service/settings.rs
index 9d2ad54a37..555163dde0 100644
--- a/rust/cloud-storage/models_email/src/email/service/settings.rs
+++ b/rust/cloud-storage/models_email/src/email/service/settings.rs
@@ -6,17 +6,7 @@ use uuid::Uuid;
pub struct Settings {
pub link_id: Uuid,
pub signature_on_replies_forwards: bool,
-}
-
-impl Settings {
- pub fn new(api_settings: crate::email::api::settings::Settings, link_id: Uuid) -> Self {
- Settings {
- link_id,
- signature_on_replies_forwards: api_settings
- .signature_on_replies_forwards
- .unwrap_or(false),
- }
- }
+ pub signature: Option<String>,
}
impl From<crate::email::db::settings::Settings> for Settings {
@@ -24,6 +14,25 @@ impl From<crate::email::db::settings::Settings> for Settings {
Settings {
link_id: db_settings.link_id,
signature_on_replies_forwards: db_settings.signature_on_replies_forwards,
+ signature: db_settings.signature,
+ }
+ }
+}
+
+/// A partial update to a link's settings. `None` fields are left unchanged.
+#[derive(Debug, Clone)]
+pub struct SettingsPatch {
+ pub link_id: Uuid,
+ pub signature_on_replies_forwards: Option<bool>,
+ pub signature: Option<String>,
+}
+
+impl SettingsPatch {
+ pub fn new(api_settings: crate::email::api::settings::Settings, link_id: Uuid) -> Self {
+ SettingsPatch {
+ link_id,
+ signature_on_replies_forwards: api_settings.signature_on_replies_forwards,
+ signature: api_settings.signature,
}
}
}
diff --git a/rust/cloud-storage/models_email/src/gmail/mod.rs b/rust/cloud-storage/models_email/src/gmail/mod.rs
index 205926c8c5..fd0635da48 100644
--- a/rust/cloud-storage/models_email/src/gmail/mod.rs
+++ b/rust/cloud-storage/models_email/src/gmail/mod.rs
@@ -226,10 +226,3 @@ pub struct GmailUserProfile {
pub threads_total: i32,
pub history_id: String,
}
-
-/// Response structure for Gmail send-as settings
-#[derive(Debug, Serialize, Deserialize)]
-#[serde(rename_all = "camelCase")]
-pub struct EmailSignature {
- pub signature: String,
-}