Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 10 additions & 18 deletions apps/server/src/lib/email-verification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ async function validateSPF(domain: string, ip: string): Promise<boolean> {
if (await checkMechanism(includeMech, includeDomain)) return true;
}
}
} catch (e) {
} catch {
// Include domain lookup failed
}
}
Expand All @@ -161,7 +161,7 @@ async function validateSPF(domain: string, ip: string): Promise<boolean> {
}

return false;
} catch (error) {
} catch {
return false;
}
}
Expand Down Expand Up @@ -216,7 +216,7 @@ async function validateDKIM(rawEmail: string): Promise<boolean> {
const pemKey = `-----BEGIN PUBLIC KEY-----\n${pubKey}\n-----END PUBLIC KEY-----`;
return verifier.verify(pemKey, signature, 'base64');

} catch (error) {
} catch {
return false;
}
}
Expand All @@ -235,7 +235,7 @@ async function validateDMARC(domain: string): Promise<boolean> {
// Require strict policy (quarantine or reject)
return policy === 'quarantine' || policy === 'reject';

} catch (error) {
} catch {
return false;
}
}
Expand Down Expand Up @@ -432,7 +432,7 @@ async function getBIMILogo(domain: string): Promise<string | undefined> {

return undefined;

} catch (error) {
} catch {
return undefined;
}
}
Expand All @@ -454,18 +454,10 @@ export async function verify(rawEmail: string): Promise<{isVerified: boolean; lo

// Run validations in parallel
const [spfValid, dkimValid, dmarcValid, bimiValid] = await Promise.all([
senderIP ? validateSPF(domain, senderIP).catch(error => {
return false;
}) : Promise.resolve(false),
validateDKIM(rawEmail).catch(error => {
return false;
}),
validateDMARC(domain).catch(error => {
return false;
}),
validateBIMI(domain).catch(error => {
return false;
}),
senderIP ? validateSPF(domain, senderIP).catch(() => false) : Promise.resolve(false),
validateDKIM(rawEmail).catch(() => false),
validateDMARC(domain).catch(() => false),
validateBIMI(domain).catch(() => false),
]);

const authValid = dkimValid || spfValid || dmarcValid;
Expand All @@ -488,4 +480,4 @@ export async function verify(rawEmail: string): Promise<{isVerified: boolean; lo
console.error('Email verification error:', error);
return { isVerified: false };
}
}
}
34 changes: 8 additions & 26 deletions apps/server/src/routes/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@ import {
GmailSearchAssistantSystemPrompt,
AiChatPrompt,
} from '../lib/prompts';
import { type Connection, type ConnectionContext, type WSMessage } from 'agents';
import { type Connection, type WSMessage } from 'agents';
import { EPrompts, type IOutgoingMessage, type ParsedMessage } from '../types';
import type { IGetThreadResponse, MailManager } from '../lib/driver/types';
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
import { createSimpleAuth, type SimpleAuth } from '../lib/auth';
import { connectionToDriver } from '../lib/server-utils';
import type { CreateDraftData } from '../lib/schemas';
import { FOLDERS, parseHeaders } from '../lib/utils';
import { FOLDERS } from '../lib/utils';
import { env, RpcTarget } from 'cloudflare:workers';
import { AIChatAgent } from 'agents/ai-chat-agent';
import { tools as authTools } from './agent/tools';
Expand All @@ -31,25 +30,11 @@ import { getPrompt } from '../lib/brain';
import { openai } from '@ai-sdk/openai';
import { and, eq } from 'drizzle-orm';
import { McpAgent } from 'agents/mcp';
import { groq } from '@ai-sdk/groq';
import { createDb } from '../db';
import { z } from 'zod';

const decoder = new TextDecoder();

interface ThreadRow {
id: string;
thread_id: string;
provider_id: string;
messages: string;
latest_sender: string;
latest_received_on: string;
latest_subject: string;
latest_label_ids: string;
created_at: string;
updated_at: string;
}

export enum IncomingMessageType {
UseChatRequest = 'cf_agent_use_chat_request',
ChatClear = 'cf_agent_chat_clear',
Expand Down Expand Up @@ -341,7 +326,7 @@ export class ZeroAgent extends AIChatAgent<typeof env> {

private getDataStreamResponse(
onFinish: StreamTextOnFinishCallback<{}>,
options?: {
_options?: {
abortSignal: AbortSignal | undefined;
},
) {
Expand Down Expand Up @@ -443,7 +428,7 @@ export class ZeroAgent extends AIChatAgent<typeof env> {
let data: IncomingMessage;
try {
data = JSON.parse(message) as IncomingMessage;
} catch (error) {
} catch {
// silently ignore invalid messages for now
// TODO: log errors with log levels
return;
Expand Down Expand Up @@ -919,11 +904,8 @@ export class ZeroAgent extends AIChatAgent<typeof env> {
let totalSynced = 0;
let pageToken: string | null = null;
let hasMore = true;
let pageCount = 0;

while (hasMore) {
pageCount++;

const result = await this.driver.list({
folder,
maxResults: maxCount,
Expand Down Expand Up @@ -960,7 +942,7 @@ export class ZeroAgent extends AIChatAgent<typeof env> {
max?: number;
cursor?: string;
}) {
const { labelIds = [], folder, q, max = 50, cursor } = params;
const { labelIds = [], folder, max = 50, cursor } = params;

try {
// Build WHERE conditions
Expand Down Expand Up @@ -1511,7 +1493,7 @@ export class ZeroMCP extends McpAgent<typeof env, {}, { userId: string }> {
},
],
};
} catch (e) {
} catch {
return {
content: [
{
Expand Down Expand Up @@ -1543,7 +1525,7 @@ export class ZeroMCP extends McpAgent<typeof env, {}, { userId: string }> {
},
],
};
} catch (e) {
} catch {
return {
content: [
{
Expand Down Expand Up @@ -1575,7 +1557,7 @@ export class ZeroMCP extends McpAgent<typeof env, {}, { userId: string }> {
},
],
};
} catch (e) {
} catch {
return {
content: [
{
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.db.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ services:

valkey:
container_name: zerodotemail-redis
image: docker.io/bitnami/valkey:8.0
image: bitnami/valkey:latest
environment:
- ALLOW_EMPTY_PASSWORD=yes
- VALKEY_DISABLE_COMMANDS=FLUSHDB,FLUSHALL
Expand All @@ -36,4 +36,4 @@ services:

volumes:
valkey-data:
postgres-data:
postgres-data: