├── backend ├── database │ └── migrations │ │ ├── 000009_create_drafts_table.down.sql │ │ ├── 000015_create_send_queue_table.down.sql │ │ ├── 000008_create_email_templates_table.down.sql │ │ ├── 000010_create_oauth2_states_table.down.sql │ │ ├── 000007_add_folder_sync_fields.down.sql │ │ ├── 000007_add_folder_sync_fields.up.sql │ │ ├── 000014_add_user_id_to_attachments.down.sql │ │ ├── 000006_create_email_unique_constraints.down.sql │ │ ├── 000001_create_users_table.down.sql │ │ ├── 000017_add_part_id_to_attachments.up.sql │ │ ├── 000005_create_attachments_table.down.sql │ │ ├── 000003_create_folders_table.down.sql │ │ ├── 000002_create_email_accounts_table.down.sql │ │ ├── 000014_add_user_id_to_attachments.up.sql │ │ ├── 000006_create_email_unique_constraints.up.sql │ │ ├── 000013_fix_attachment_fields_mapping.up.sql │ │ ├── 000010_create_oauth2_states_table.up.sql │ │ ├── 000004_create_emails_table.down.sql │ │ ├── 000001_create_users_table.up.sql │ │ ├── 000008_create_email_templates_table.up.sql │ │ ├── 000016_add_encoding_to_attachments.up.sql │ │ ├── 000009_create_drafts_table.up.sql │ │ ├── 000015_create_send_queue_table.up.sql │ │ ├── 000005_create_attachments_table.up.sql │ │ ├── 000003_create_folders_table.up.sql │ │ ├── 000011_optimize_database_indexes.down.sql │ │ ├── 000012_modify_attachments_email_id_nullable.up.sql │ │ ├── 000002_create_email_accounts_table.up.sql │ │ ├── 000012_modify_attachments_email_id_nullable.down.sql │ │ ├── 000013_fix_attachment_fields_mapping.down.sql │ │ ├── 000016_add_encoding_to_attachments.down.sql │ │ ├── 000017_add_part_id_to_attachments.down.sql │ │ ├── 000004_create_emails_table.up.sql │ │ └── 000011_optimize_database_indexes.up.sql ├── internal │ ├── models │ │ ├── base.go │ │ ├── user.go │ │ ├── folder.go │ │ ├── attachment.go │ │ ├── draft.go │ │ └── email_account.go │ ├── services │ │ └── utils.go │ ├── database │ │ └── migration │ │ │ ├── interface.go │ │ │ └── golang_migrator.go │ ├── middleware │ │ └── cors.go │ ├── handlers │ │ ├── soft_delete.go │ │ ├── sse.go │ │ └── backup.go │ └── auth │ │ └── jwt.go ├── .dockerignore ├── go.mod ├── cmd │ └── debug │ │ └── main.go ├── .env.example └── .env.local ├── frontend ├── src │ ├── app │ │ ├── favicon.ico │ │ ├── mailbox │ │ │ ├── page.tsx │ │ │ ├── search │ │ │ │ └── page.tsx │ │ │ └── mobile │ │ │ │ ├── page.tsx │ │ │ │ ├── compose │ │ │ │ └── page.tsx │ │ │ │ ├── account │ │ │ │ └── [id] │ │ │ │ │ ├── settings │ │ │ │ │ └── page.tsx │ │ │ │ │ └── page.tsx │ │ │ │ ├── folder │ │ │ │ └── [id] │ │ │ │ │ └── page.tsx │ │ │ │ └── email │ │ │ │ └── [id] │ │ │ │ └── page.tsx │ │ ├── layout.tsx │ │ └── page.tsx │ ├── lib │ │ ├── utils.ts │ │ └── providers.tsx │ ├── components │ │ ├── ui │ │ │ ├── skeleton.tsx │ │ │ ├── hydration-loader.tsx │ │ │ ├── sonner.tsx │ │ │ ├── label.tsx │ │ │ ├── separator.tsx │ │ │ ├── textarea.tsx │ │ │ ├── collapsible.tsx │ │ │ ├── progress.tsx │ │ │ ├── input.tsx │ │ │ ├── avatar.tsx │ │ │ ├── switch.tsx │ │ │ ├── checkbox.tsx │ │ │ ├── radio-group.tsx │ │ │ ├── badge.tsx │ │ │ ├── popover.tsx │ │ │ ├── scroll-area.tsx │ │ │ ├── tooltip.tsx │ │ │ ├── tabs.tsx │ │ │ ├── slider.tsx │ │ │ ├── card.tsx │ │ │ ├── button.tsx │ │ │ ├── table.tsx │ │ │ └── breadcrumb.tsx │ │ ├── auth │ │ │ ├── auth-guard.tsx │ │ │ └── auth-debug.tsx │ │ ├── mailbox │ │ │ ├── sidebar-header.tsx │ │ │ ├── loading-skeleton.tsx │ │ │ ├── account-settings-modal.tsx │ │ │ ├── translation-bar.tsx │ │ │ ├── folder-tree.tsx │ │ │ ├── bulk-actions.tsx │ │ │ └── folder-item.tsx │ │ ├── account-edit │ │ │ ├── account-edit-form.tsx │ │ │ ├── README.md │ │ │ └── account-edit-config.ts │ │ └── mobile │ │ │ ├── mobile-account-settings-page.tsx │ │ │ └── mobile-layout.tsx │ ├── hooks │ │ ├── use-mobile.ts │ │ ├── use-hydration.ts │ │ ├── use-email-accounts.ts │ │ └── use-mobile-navigation.ts │ └── types │ │ └── sse.ts ├── postcss.config.mjs ├── public │ ├── vercel.svg │ ├── window.svg │ ├── file.svg │ ├── globe.svg │ └── next.svg ├── .prettierignore ├── .prettierrc ├── components.json ├── next.config.ts ├── .gitignore ├── tsconfig.json ├── eslint.config.mjs ├── README.md └── package.json ├── docker-compose.dev.yml ├── scripts ├── docker-build.sh └── docker-deploy.sh ├── .github └── workflows │ └── docker-build.yml ├── .dockerignore ├── docker-compose.yml ├── .env.docker.example └── Makefile /backend/database/migrations/000009_create_drafts_table.down.sql: -------------------------------------------------------------------------------- 1 | -- 删除草稿表 2 | DROP TABLE IF EXISTS drafts; 3 | -------------------------------------------------------------------------------- /frontend/src/app/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fengyuanluo/firemailplus/HEAD/frontend/src/app/favicon.ico -------------------------------------------------------------------------------- /backend/database/migrations/000015_create_send_queue_table.down.sql: -------------------------------------------------------------------------------- 1 | -- 删除发送队列表 2 | DROP TABLE IF EXISTS send_queue; 3 | -------------------------------------------------------------------------------- /frontend/postcss.config.mjs: -------------------------------------------------------------------------------- 1 | const config = { 2 | plugins: ['@tailwindcss/postcss'], 3 | }; 4 | 5 | export default config; 6 | -------------------------------------------------------------------------------- /backend/database/migrations/000008_create_email_templates_table.down.sql: -------------------------------------------------------------------------------- 1 | -- 删除邮件模板表 2 | DROP TABLE IF EXISTS email_templates; 3 | -------------------------------------------------------------------------------- /backend/database/migrations/000010_create_oauth2_states_table.down.sql: -------------------------------------------------------------------------------- 1 | -- 删除OAuth2状态表 2 | DROP TABLE IF EXISTS oauth2_states; 3 | -------------------------------------------------------------------------------- /frontend/public/vercel.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /frontend/.prettierignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .next 3 | .vercel 4 | .env* 5 | dist 6 | build 7 | coverage 8 | *.log 9 | .DS_Store 10 | public 11 | *.md 12 | -------------------------------------------------------------------------------- /backend/database/migrations/000007_add_folder_sync_fields.down.sql: -------------------------------------------------------------------------------- 1 | -- 移除文件夹同步字段 2 | ALTER TABLE folders DROP COLUMN uid_validity; 3 | ALTER TABLE folders DROP COLUMN uid_next; 4 | -------------------------------------------------------------------------------- /backend/database/migrations/000007_add_folder_sync_fields.up.sql: -------------------------------------------------------------------------------- 1 | -- 添加文件夹同步字段 2 | ALTER TABLE folders ADD COLUMN uid_validity INTEGER DEFAULT 0; 3 | ALTER TABLE folders ADD COLUMN uid_next INTEGER DEFAULT 0; 4 | -------------------------------------------------------------------------------- /frontend/src/lib/utils.ts: -------------------------------------------------------------------------------- 1 | import { clsx, type ClassValue } from 'clsx'; 2 | import { twMerge } from 'tailwind-merge'; 3 | 4 | export function cn(...inputs: ClassValue[]) { 5 | return twMerge(clsx(inputs)); 6 | } 7 | -------------------------------------------------------------------------------- /backend/database/migrations/000014_add_user_id_to_attachments.down.sql: -------------------------------------------------------------------------------- 1 | -- 回滚:移除附件表的user_id字段 2 | 3 | -- 1. 删除相关索引 4 | DROP INDEX IF EXISTS idx_attachments_temp_permission; 5 | DROP INDEX IF EXISTS idx_attachments_user_id; 6 | 7 | -- 2. 删除user_id列 8 | ALTER TABLE attachments DROP COLUMN user_id; 9 | -------------------------------------------------------------------------------- /frontend/.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "semi": true, 3 | "trailingComma": "es5", 4 | "singleQuote": true, 5 | "printWidth": 100, 6 | "tabWidth": 2, 7 | "useTabs": false, 8 | "endOfLine": "lf", 9 | "arrowParens": "always", 10 | "bracketSpacing": true, 11 | "bracketSameLine": false, 12 | "quoteProps": "as-needed" 13 | } 14 | -------------------------------------------------------------------------------- /backend/database/migrations/000006_create_email_unique_constraints.down.sql: -------------------------------------------------------------------------------- 1 | -- 删除邮件唯一约束 2 | 3 | -- 删除内容相似性约束 4 | DROP INDEX IF EXISTS idx_emails_content_similarity; 5 | 6 | -- 删除文件夹内UID唯一约束 7 | DROP INDEX IF EXISTS idx_emails_account_folder_uid_unique; 8 | 9 | -- 删除账户内MessageID唯一约束 10 | DROP INDEX IF EXISTS idx_emails_account_message_id_unique; 11 | -------------------------------------------------------------------------------- /frontend/src/app/mailbox/page.tsx: -------------------------------------------------------------------------------- 1 | 'use client'; 2 | 3 | import { DesktopOnlyRoute } from '@/components/auth/route-guard'; 4 | import { MailboxLayout } from '@/components/mailbox/mailbox-layout'; 5 | 6 | export default function MailboxPage() { 7 | return ( 8 | 9 | 10 | 11 | ); 12 | } 13 | -------------------------------------------------------------------------------- /frontend/src/components/ui/skeleton.tsx: -------------------------------------------------------------------------------- 1 | import { cn } from '@/lib/utils'; 2 | 3 | function Skeleton({ className, ...props }: React.ComponentProps<'div'>) { 4 | return ( 5 |
10 | ); 11 | } 12 | 13 | export { Skeleton }; 14 | -------------------------------------------------------------------------------- /backend/database/migrations/000001_create_users_table.down.sql: -------------------------------------------------------------------------------- 1 | -- 删除用户表触发器 2 | DROP TRIGGER IF EXISTS update_users_updated_at; 3 | 4 | -- 删除用户表索引 5 | DROP INDEX IF EXISTS idx_users_username; 6 | DROP INDEX IF EXISTS idx_users_deleted_at; 7 | DROP INDEX IF EXISTS idx_users_role; 8 | DROP INDEX IF EXISTS idx_users_is_active; 9 | 10 | -- 删除用户表 11 | DROP TABLE IF EXISTS users; 12 | -------------------------------------------------------------------------------- /frontend/public/window.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /frontend/public/file.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /backend/internal/models/base.go: -------------------------------------------------------------------------------- 1 | package models 2 | 3 | import ( 4 | "time" 5 | 6 | "gorm.io/gorm" 7 | ) 8 | 9 | // BaseModel 基础模型,包含通用字段 10 | type BaseModel struct { 11 | ID uint `gorm:"primarykey" json:"id"` 12 | CreatedAt time.Time `json:"created_at"` 13 | UpdatedAt time.Time `json:"updated_at"` 14 | DeletedAt gorm.DeletedAt `gorm:"index" json:"deleted_at,omitempty"` 15 | } 16 | 17 | // TableName 接口,用于自定义表名 18 | type TableNamer interface { 19 | TableName() string 20 | } 21 | -------------------------------------------------------------------------------- /backend/database/migrations/000017_add_part_id_to_attachments.up.sql: -------------------------------------------------------------------------------- 1 | -- 为附件表添加part_id字段,用于存储IMAP PartID信息 2 | -- 这是修复附件下载失败的关键字段 3 | 4 | -- 1. 添加part_id列 5 | ALTER TABLE attachments ADD COLUMN part_id VARCHAR(50); 6 | 7 | -- 2. 为part_id字段创建索引 8 | CREATE INDEX IF NOT EXISTS idx_attachments_part_id ON attachments(part_id); 9 | 10 | -- 3. 为email_id和part_id创建复合索引(用于IMAP查询优化) 11 | CREATE INDEX IF NOT EXISTS idx_attachments_email_part ON attachments(email_id, part_id); 12 | 13 | -- 注意:现有记录的part_id将为NULL,需要重新同步邮件来获取正确的PartID 14 | -------------------------------------------------------------------------------- /backend/database/migrations/000005_create_attachments_table.down.sql: -------------------------------------------------------------------------------- 1 | -- 删除附件表触发器 2 | DROP TRIGGER IF EXISTS update_attachments_updated_at; 3 | 4 | -- 删除附件表索引 5 | DROP INDEX IF EXISTS idx_attachments_email_id; 6 | DROP INDEX IF EXISTS idx_attachments_email_type; 7 | DROP INDEX IF EXISTS idx_attachments_content_id; 8 | DROP INDEX IF EXISTS idx_attachments_deleted_at; 9 | DROP INDEX IF EXISTS idx_attachments_filename; 10 | DROP INDEX IF EXISTS idx_attachments_is_inline; 11 | 12 | -- 删除附件表 13 | DROP TABLE IF EXISTS attachments; 14 | -------------------------------------------------------------------------------- /frontend/src/app/mailbox/search/page.tsx: -------------------------------------------------------------------------------- 1 | import { Suspense } from 'react'; 2 | import { SearchResultsPage } from '@/components/mailbox/search-results-page'; 3 | import { LoadingSkeleton } from '@/components/mailbox/loading-skeleton'; 4 | import { ProtectedRoute } from '@/components/auth/route-guard'; 5 | 6 | export default function SearchPage() { 7 | return ( 8 | 9 | }> 10 | 11 | 12 | 13 | ); 14 | } 15 | -------------------------------------------------------------------------------- /backend/database/migrations/000003_create_folders_table.down.sql: -------------------------------------------------------------------------------- 1 | -- 删除文件夹表触发器 2 | DROP TRIGGER IF EXISTS update_folders_updated_at; 3 | 4 | -- 删除文件夹表索引 5 | DROP INDEX IF EXISTS idx_folders_account_id; 6 | DROP INDEX IF EXISTS idx_folders_account_type; 7 | DROP INDEX IF EXISTS idx_folders_account_parent; 8 | DROP INDEX IF EXISTS idx_folders_parent_id; 9 | DROP INDEX IF EXISTS idx_folders_deleted_at; 10 | DROP INDEX IF EXISTS idx_folders_type; 11 | DROP INDEX IF EXISTS idx_folders_path; 12 | 13 | -- 删除文件夹表 14 | DROP TABLE IF EXISTS folders; 15 | -------------------------------------------------------------------------------- /frontend/components.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://ui.shadcn.com/schema.json", 3 | "style": "new-york", 4 | "rsc": true, 5 | "tsx": true, 6 | "tailwind": { 7 | "config": "", 8 | "css": "src/app/globals.css", 9 | "baseColor": "neutral", 10 | "cssVariables": true, 11 | "prefix": "" 12 | }, 13 | "aliases": { 14 | "components": "@/components", 15 | "utils": "@/lib/utils", 16 | "ui": "@/components/ui", 17 | "lib": "@/lib", 18 | "hooks": "@/hooks" 19 | }, 20 | "iconLibrary": "lucide" 21 | } 22 | -------------------------------------------------------------------------------- /frontend/next.config.ts: -------------------------------------------------------------------------------- 1 | import type { NextConfig } from 'next'; 2 | 3 | const nextConfig: NextConfig = { 4 | // 启用standalone模式以优化Docker镜像大小 5 | output: 'standalone', 6 | 7 | // 优化配置 8 | experimental: { 9 | // 启用服务器组件优化 10 | serverComponentsExternalPackages: [], 11 | }, 12 | 13 | // 压缩配置 14 | compress: true, 15 | 16 | // 静态文件优化 17 | assetPrefix: process.env.NODE_ENV === 'production' ? '' : '', 18 | 19 | // 图片优化 20 | images: { 21 | unoptimized: false, 22 | }, 23 | }; 24 | 25 | export default nextConfig; 26 | -------------------------------------------------------------------------------- /backend/database/migrations/000002_create_email_accounts_table.down.sql: -------------------------------------------------------------------------------- 1 | -- 删除邮件账户表触发器 2 | DROP TRIGGER IF EXISTS update_email_accounts_updated_at; 3 | 4 | -- 删除邮件账户表索引 5 | DROP INDEX IF EXISTS idx_email_accounts_user_id; 6 | DROP INDEX IF EXISTS idx_email_accounts_user_provider; 7 | DROP INDEX IF EXISTS idx_email_accounts_email; 8 | DROP INDEX IF EXISTS idx_email_accounts_deleted_at; 9 | DROP INDEX IF EXISTS idx_email_accounts_is_active; 10 | DROP INDEX IF EXISTS idx_email_accounts_sync_status; 11 | 12 | -- 删除邮件账户表 13 | DROP TABLE IF EXISTS email_accounts; 14 | -------------------------------------------------------------------------------- /frontend/src/app/mailbox/mobile/page.tsx: -------------------------------------------------------------------------------- 1 | import { Suspense } from 'react'; 2 | import { MobileOnlyRoute } from '@/components/auth/route-guard'; 3 | import { MobileAccountsPage } from '@/components/mobile/mobile-accounts-page'; 4 | import { MobileLoading } from '@/components/mobile/mobile-layout'; 5 | 6 | export default function MobileMailboxPage() { 7 | return ( 8 | 9 | }> 10 | 11 | 12 | 13 | ); 14 | } 15 | -------------------------------------------------------------------------------- /backend/database/migrations/000014_add_user_id_to_attachments.up.sql: -------------------------------------------------------------------------------- 1 | -- 为附件表添加user_id字段,用于临时附件的权限检查 2 | -- 临时附件(email_id为NULL)需要通过user_id来确定所有者 3 | 4 | -- 1. 添加user_id列 5 | ALTER TABLE attachments ADD COLUMN user_id INTEGER; 6 | 7 | -- 2. 为user_id字段创建索引 8 | CREATE INDEX IF NOT EXISTS idx_attachments_user_id ON attachments(user_id); 9 | 10 | -- 3. 为临时附件权限检查创建复合索引 11 | CREATE INDEX IF NOT EXISTS idx_attachments_temp_permission ON attachments(user_id, email_id) WHERE email_id IS NULL; 12 | 13 | -- 4. 添加外键约束(如果需要的话,SQLite默认不强制外键) 14 | -- 注意:在生产环境中可能需要根据实际情况决定是否添加外键约束 15 | -------------------------------------------------------------------------------- /frontend/src/app/mailbox/mobile/compose/page.tsx: -------------------------------------------------------------------------------- 1 | import { Suspense } from 'react'; 2 | import { MobileComposePage } from '@/components/mobile/mobile-compose-page'; 3 | import { MobileLoading } from '@/components/mobile/mobile-layout'; 4 | import { MobileOnlyRoute } from '@/components/auth/route-guard'; 5 | 6 | export default function MobileComposeRoute() { 7 | return ( 8 | 9 | }> 10 | 11 | 12 | 13 | ); 14 | } 15 | -------------------------------------------------------------------------------- /frontend/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.* 7 | .yarn/* 8 | !.yarn/patches 9 | !.yarn/plugins 10 | !.yarn/releases 11 | !.yarn/versions 12 | 13 | # testing 14 | /coverage 15 | 16 | # next.js 17 | /.next/ 18 | /out/ 19 | 20 | # production 21 | /build 22 | 23 | # misc 24 | .DS_Store 25 | *.pem 26 | 27 | # debug 28 | npm-debug.log* 29 | yarn-debug.log* 30 | yarn-error.log* 31 | .pnpm-debug.log* 32 | 33 | # env files (can opt-in for committing if needed) 34 | .env* 35 | 36 | # vercel 37 | .vercel 38 | 39 | # typescript 40 | *.tsbuildinfo 41 | next-env.d.ts 42 | -------------------------------------------------------------------------------- /frontend/src/hooks/use-mobile.ts: -------------------------------------------------------------------------------- 1 | import * as React from 'react'; 2 | 3 | const MOBILE_BREAKPOINT = 768; 4 | 5 | export function useIsMobile() { 6 | const [isMobile, setIsMobile] = React.useState(undefined); 7 | 8 | React.useEffect(() => { 9 | const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`); 10 | const onChange = () => { 11 | setIsMobile(window.innerWidth < MOBILE_BREAKPOINT); 12 | }; 13 | mql.addEventListener('change', onChange); 14 | setIsMobile(window.innerWidth < MOBILE_BREAKPOINT); 15 | return () => mql.removeEventListener('change', onChange); 16 | }, []); 17 | 18 | return !!isMobile; 19 | } 20 | -------------------------------------------------------------------------------- /frontend/src/app/mailbox/mobile/account/[id]/settings/page.tsx: -------------------------------------------------------------------------------- 1 | 'use client'; 2 | 3 | import { use } from 'react'; 4 | import { MobileAccountSettingsPage } from '@/components/mobile/mobile-account-settings-page'; 5 | import { MobileOnlyRoute } from '@/components/auth/route-guard'; 6 | 7 | interface PageProps { 8 | params: Promise<{ 9 | id: string; 10 | }>; 11 | } 12 | 13 | export default function AccountSettingsPage({ params }: PageProps) { 14 | const resolvedParams = use(params); 15 | const accountId = parseInt(resolvedParams.id); 16 | 17 | return ( 18 | 19 | 20 | 21 | ); 22 | } 23 | -------------------------------------------------------------------------------- /frontend/src/components/ui/hydration-loader.tsx: -------------------------------------------------------------------------------- 1 | /** 2 | * 水合加载组件 3 | * 在水合过程中显示的加载界面 4 | */ 5 | 6 | interface HydrationLoaderProps { 7 | message?: string; 8 | className?: string; 9 | } 10 | 11 | export function HydrationLoader({ 12 | message = '正在初始化应用...', 13 | className = '', 14 | }: HydrationLoaderProps) { 15 | return ( 16 |
17 |
18 |
19 |

{message}

20 |
21 |
22 | ); 23 | } 24 | -------------------------------------------------------------------------------- /frontend/src/components/ui/sonner.tsx: -------------------------------------------------------------------------------- 1 | 'use client'; 2 | 3 | import { useTheme } from 'next-themes'; 4 | import { Toaster as Sonner, ToasterProps } from 'sonner'; 5 | 6 | const Toaster = ({ ...props }: ToasterProps) => { 7 | const { theme = 'system' } = useTheme(); 8 | 9 | return ( 10 | 22 | ); 23 | }; 24 | 25 | export { Toaster }; 26 | -------------------------------------------------------------------------------- /frontend/src/app/layout.tsx: -------------------------------------------------------------------------------- 1 | import type { Metadata } from 'next'; 2 | import { Inter } from 'next/font/google'; 3 | import './globals.css'; 4 | import { Providers } from '@/lib/providers'; 5 | 6 | const inter = Inter({ subsets: ['latin'] }); 7 | 8 | export const metadata: Metadata = { 9 | title: '花火邮箱 - 现代化邮件客户端', 10 | description: '一个基于 Next.js 15 和 React 19 的现代化邮件客户端', 11 | }; 12 | 13 | export default function RootLayout({ 14 | children, 15 | }: Readonly<{ 16 | children: React.ReactNode; 17 | }>) { 18 | return ( 19 | 20 | 21 | {children} 22 | 23 | 24 | ); 25 | } 26 | -------------------------------------------------------------------------------- /frontend/src/components/ui/label.tsx: -------------------------------------------------------------------------------- 1 | 'use client'; 2 | 3 | import * as React from 'react'; 4 | import * as LabelPrimitive from '@radix-ui/react-label'; 5 | 6 | import { cn } from '@/lib/utils'; 7 | 8 | function Label({ className, ...props }: React.ComponentProps) { 9 | return ( 10 | 18 | ); 19 | } 20 | 21 | export { Label }; 22 | -------------------------------------------------------------------------------- /frontend/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ES2017", 4 | "lib": ["dom", "dom.iterable", "esnext"], 5 | "allowJs": true, 6 | "skipLibCheck": true, 7 | "strict": true, 8 | "noEmit": true, 9 | "esModuleInterop": true, 10 | "module": "esnext", 11 | "moduleResolution": "bundler", 12 | "resolveJsonModule": true, 13 | "isolatedModules": true, 14 | "jsx": "preserve", 15 | "incremental": true, 16 | "plugins": [ 17 | { 18 | "name": "next" 19 | } 20 | ], 21 | "paths": { 22 | "@/*": ["./src/*"] 23 | } 24 | }, 25 | "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"], 26 | "exclude": ["node_modules"] 27 | } 28 | -------------------------------------------------------------------------------- /backend/internal/services/utils.go: -------------------------------------------------------------------------------- 1 | package services 2 | 3 | import ( 4 | "strings" 5 | ) 6 | 7 | // isUniqueConstraintError 检查是否为唯一约束错误 8 | func isUniqueConstraintError(err error) bool { 9 | if err == nil { 10 | return false 11 | } 12 | 13 | errStr := err.Error() 14 | errStrLower := strings.ToLower(errStr) 15 | 16 | // 检查常见的唯一约束错误关键词 17 | uniqueKeywords := []string{ 18 | "unique constraint", 19 | "duplicate key", 20 | "duplicate entry", 21 | "unique violation", 22 | "constraint violation", 23 | "unique index", 24 | "duplicate", 25 | "unique", 26 | } 27 | 28 | for _, keyword := range uniqueKeywords { 29 | if strings.Contains(errStrLower, keyword) { 30 | return true 31 | } 32 | } 33 | 34 | return false 35 | } 36 | -------------------------------------------------------------------------------- /backend/database/migrations/000006_create_email_unique_constraints.up.sql: -------------------------------------------------------------------------------- 1 | -- 创建邮件唯一约束,防止重复邮件 2 | 3 | -- 主要约束:账户内MessageID唯一(排除NULL和空字符串) 4 | CREATE UNIQUE INDEX IF NOT EXISTS idx_emails_account_message_id_unique 5 | ON emails(account_id, message_id) 6 | WHERE message_id IS NOT NULL AND message_id != ''; 7 | 8 | -- 辅助约束:文件夹内UID唯一 9 | CREATE UNIQUE INDEX IF NOT EXISTS idx_emails_account_folder_uid_unique 10 | ON emails(account_id, folder_id, uid) 11 | WHERE folder_id IS NOT NULL; 12 | 13 | -- 内容相似性约束:防止相同主题、发件人、日期的邮件重复(用于MessageID为空的情况) 14 | -- 注意:这里使用from_address而不是from,避免SQLite保留字问题 15 | CREATE INDEX IF NOT EXISTS idx_emails_content_similarity 16 | ON emails(account_id, subject, from_address, date) 17 | WHERE message_id IS NULL OR message_id = ''; 18 | -------------------------------------------------------------------------------- /frontend/src/components/auth/auth-guard.tsx: -------------------------------------------------------------------------------- 1 | 'use client'; 2 | 3 | import { useHydrationGuard } from '@/hooks/use-hydration'; 4 | 5 | interface AuthGuardProps { 6 | children: React.ReactNode; 7 | } 8 | 9 | export function AuthGuard({ children }: AuthGuardProps) { 10 | const { isHydrated } = useHydrationGuard(); 11 | 12 | if (!isHydrated) { 13 | return ( 14 |
15 |
16 |
17 |

正在初始化应用...

18 |
19 |
20 | ); 21 | } 22 | 23 | return <>{children}; 24 | } 25 | -------------------------------------------------------------------------------- /frontend/src/app/mailbox/mobile/folder/[id]/page.tsx: -------------------------------------------------------------------------------- 1 | import { Suspense } from 'react'; 2 | import { MobileEmailsPage } from '@/components/mobile/mobile-emails-page'; 3 | import { MobileLoading } from '@/components/mobile/mobile-layout'; 4 | import { MobileOnlyRoute } from '@/components/auth/route-guard'; 5 | 6 | interface MobileEmailsPageProps { 7 | params: Promise<{ 8 | id: string; 9 | }>; 10 | } 11 | 12 | export default async function MobileFolderEmailsPage({ params }: MobileEmailsPageProps) { 13 | const { id } = await params; 14 | 15 | return ( 16 | 17 | }> 18 | 19 | 20 | 21 | ); 22 | } 23 | -------------------------------------------------------------------------------- /frontend/src/app/mailbox/mobile/account/[id]/page.tsx: -------------------------------------------------------------------------------- 1 | import { Suspense } from 'react'; 2 | import { MobileFoldersPage } from '@/components/mobile/mobile-folders-page'; 3 | import { MobileLoading } from '@/components/mobile/mobile-layout'; 4 | import { MobileOnlyRoute } from '@/components/auth/route-guard'; 5 | 6 | interface MobileFoldersPageProps { 7 | params: Promise<{ 8 | id: string; 9 | }>; 10 | } 11 | 12 | export default async function MobileAccountFoldersPage({ params }: MobileFoldersPageProps) { 13 | const { id } = await params; 14 | 15 | return ( 16 | 17 | }> 18 | 19 | 20 | 21 | ); 22 | } 23 | -------------------------------------------------------------------------------- /frontend/src/app/mailbox/mobile/email/[id]/page.tsx: -------------------------------------------------------------------------------- 1 | import { Suspense } from 'react'; 2 | import { MobileEmailDetailPage } from '@/components/mobile/mobile-email-detail-page'; 3 | import { MobileLoading } from '@/components/mobile/mobile-layout'; 4 | import { MobileOnlyRoute } from '@/components/auth/route-guard'; 5 | 6 | interface MobileEmailDetailPageProps { 7 | params: Promise<{ 8 | id: string; 9 | }>; 10 | } 11 | 12 | export default async function MobileEmailDetailRoute({ params }: MobileEmailDetailPageProps) { 13 | const { id } = await params; 14 | 15 | return ( 16 | 17 | }> 18 | 19 | 20 | 21 | ); 22 | } 23 | -------------------------------------------------------------------------------- /backend/database/migrations/000013_fix_attachment_fields_mapping.up.sql: -------------------------------------------------------------------------------- 1 | -- 修复附件表字段映射语义错误 2 | -- 添加正确的is_downloaded字段,修正is_inline字段的语义 3 | 4 | -- 1. 添加新的is_downloaded列 5 | ALTER TABLE attachments ADD COLUMN is_downloaded BOOLEAN NOT NULL DEFAULT false; 6 | 7 | -- 2. 将现有is_inline列的数据迁移到is_downloaded列 8 | -- 因为当前is_inline列实际存储的是"是否已下载"的信息 9 | UPDATE attachments SET is_downloaded = is_inline; 10 | 11 | -- 3. 重新计算is_inline列的正确值 12 | -- is_inline应该表示是否为内联附件,基于disposition和content_id判断 13 | UPDATE attachments SET is_inline = ( 14 | disposition = 'inline' OR 15 | (content_id IS NOT NULL AND content_id != '') 16 | ); 17 | 18 | -- 4. 为新字段创建索引 19 | CREATE INDEX IF NOT EXISTS idx_attachments_is_downloaded ON attachments(is_downloaded); 20 | 21 | -- 5. 更新现有索引的注释(SQLite不支持注释,但保留用于文档) 22 | -- idx_attachments_is_inline 现在正确表示内联附件索引 23 | -------------------------------------------------------------------------------- /frontend/src/components/ui/separator.tsx: -------------------------------------------------------------------------------- 1 | 'use client'; 2 | 3 | import * as React from 'react'; 4 | import * as SeparatorPrimitive from '@radix-ui/react-separator'; 5 | 6 | import { cn } from '@/lib/utils'; 7 | 8 | function Separator({ 9 | className, 10 | orientation = 'horizontal', 11 | decorative = true, 12 | ...props 13 | }: React.ComponentProps) { 14 | return ( 15 | 25 | ); 26 | } 27 | 28 | export { Separator }; 29 | -------------------------------------------------------------------------------- /frontend/src/components/ui/textarea.tsx: -------------------------------------------------------------------------------- 1 | import * as React from 'react'; 2 | 3 | import { cn } from '@/lib/utils'; 4 | 5 | function Textarea({ className, ...props }: React.ComponentProps<'textarea'>) { 6 | return ( 7 |