feature/compose-send: отправка писем через SMTP
Типы: - ComposeData в message.ts (to/cc/bcc/subject/body + reply-headers) - smtpHost/smtpPort/smtpSecure в ImapCredentials (опциональные) - messages:send в IpcChannelMap - sendMessage() в IEmailProvider Main-process: - ImapProvider.sendMessage() — nodemailer SMTP + IMAP APPEND в Sent - AccountManager.sendMessage() с авто-переподключением - IPC-handler messages:send Renderer: - compose.store: draft, openNew/openReply/openForward/send - ComposeWindow.vue — glass-модал с token-адресами, Cc/Bcc, textarea, Ctrl+Enter - AppShell: кнопка "Написать" в sidebar + Ctrl+N - MessageHeader: кнопки Ответить / Ответить всем / Переслать - AddAccountDialog: секция SMTP-настроек (авто-подстановка из IMAP-хоста) - AppIcon: иконки compose, reply, forward, send Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
823f6e5b8d
commit
05e5c8c5d2
17 changed files with 1106 additions and 11 deletions
12
package-lock.json
generated
12
package-lock.json
generated
|
|
@ -21,6 +21,7 @@
|
|||
"imapflow": "^1.0.171",
|
||||
"jsdom": "^29.0.1",
|
||||
"mailparser": "^3.9.6",
|
||||
"nodemailer": "^8.0.4",
|
||||
"pinia": "^3.0.2",
|
||||
"sanitize-html": "^2.17.2",
|
||||
"vue": "^3.5.13",
|
||||
|
|
@ -28,6 +29,7 @@
|
|||
},
|
||||
"devDependencies": {
|
||||
"@types/dompurify": "^3.2.0",
|
||||
"@types/nodemailer": "^8.0.0",
|
||||
"@vitejs/plugin-vue": "^5.2.3",
|
||||
"electron": "^35.1.2",
|
||||
"electron-builder": "^25.1.8",
|
||||
|
|
@ -2161,6 +2163,16 @@
|
|||
"undici-types": "~6.21.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/nodemailer": {
|
||||
"version": "8.0.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/nodemailer/-/nodemailer-8.0.0.tgz",
|
||||
"integrity": "sha512-fyf8jWULsCo0d0BuoQ75i6IeoHs47qcqxWc7yUdUcV0pOZGjUTTOvwdG1PRXUDqN/8A64yQdQdnA2pZgcdi+cA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@types/node": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/plist": {
|
||||
"version": "3.0.5",
|
||||
"resolved": "https://registry.npmjs.org/@types/plist/-/plist-3.0.5.tgz",
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@
|
|||
"imapflow": "^1.0.171",
|
||||
"jsdom": "^29.0.1",
|
||||
"mailparser": "^3.9.6",
|
||||
"nodemailer": "^8.0.4",
|
||||
"pinia": "^3.0.2",
|
||||
"sanitize-html": "^2.17.2",
|
||||
"vue": "^3.5.13",
|
||||
|
|
@ -40,6 +41,7 @@
|
|||
},
|
||||
"devDependencies": {
|
||||
"@types/dompurify": "^3.2.0",
|
||||
"@types/nodemailer": "^8.0.0",
|
||||
"@vitejs/plugin-vue": "^5.2.3",
|
||||
"electron": "^35.1.2",
|
||||
"electron-builder": "^25.1.8",
|
||||
|
|
|
|||
|
|
@ -37,6 +37,15 @@ export function registerMessageHandlers(manager: AccountManager): void {
|
|||
await manager.pollNewMessages(accountId)
|
||||
})
|
||||
|
||||
registerHandler('messages:send', async ({ accountId, compose }) => {
|
||||
try {
|
||||
await manager.sendMessage(accountId, compose)
|
||||
return { success: true }
|
||||
} catch (e) {
|
||||
return { success: false, error: (e as Error).message }
|
||||
}
|
||||
})
|
||||
|
||||
registerHandler('messages:search', async ({ accountId, query, limit }) => {
|
||||
return manager.searchMessages(accountId, query, limit)
|
||||
})
|
||||
|
|
|
|||
|
|
@ -189,6 +189,7 @@ export class ExchangeProvider implements IEmailProvider {
|
|||
|
||||
async pollNewMessages(): Promise<void> { /* Exchange использует свой polling через onNewMail */ }
|
||||
async searchMessages(_query: string, _limit: number): Promise<import('@shared/types/message').MessageEnvelope[]> { return [] }
|
||||
async sendMessage(_compose: import('@shared/types/message').ComposeData): Promise<void> { throw new Error('Send not implemented for Exchange') }
|
||||
|
||||
private detectRole(name: string): SpecialFolderRole {
|
||||
const n = name.toLowerCase()
|
||||
|
|
|
|||
|
|
@ -305,4 +305,8 @@ export class GmailProvider implements IEmailProvider {
|
|||
|
||||
return { html, text, inlineImages, attachments }
|
||||
}
|
||||
|
||||
async sendMessage(_compose: import('@shared/types/message').ComposeData): Promise<void> {
|
||||
throw new Error('Отправка для Gmail не реализована')
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
import { ImapFlow } from 'imapflow'
|
||||
import { simpleParser } from 'mailparser'
|
||||
import nodemailer from 'nodemailer'
|
||||
import type { IEmailProvider, FolderListResult, MessageListOptions, MessageListResult } from '@shared/types/provider'
|
||||
import type { MessageBody, MessageFlags, MessageEnvelope, Address } from '@shared/types/message'
|
||||
import type { MessageBody, MessageFlags, MessageEnvelope, Address, ComposeData } from '@shared/types/message'
|
||||
import { SpecialFolderRole } from '@shared/types/folder'
|
||||
import type { Folder } from '@shared/types/folder'
|
||||
import type { AccountConfig, ImapCredentials } from '@shared/types/account'
|
||||
|
|
@ -250,6 +251,95 @@ export class ImapProvider implements IEmailProvider {
|
|||
}
|
||||
}
|
||||
|
||||
async sendMessage(compose: ComposeData): Promise<void> {
|
||||
const creds = this.config.credentials as ImapCredentials
|
||||
|
||||
// SMTP-настройки: явные или авто-вывод из IMAP-хоста
|
||||
const smtpHost = creds.smtpHost ?? creds.host.replace(/^imap\./i, 'smtp.')
|
||||
const smtpPort = creds.smtpPort ?? 587
|
||||
const smtpSecure = creds.smtpSecure ?? smtpPort === 465
|
||||
|
||||
const transporter = nodemailer.createTransport({
|
||||
host: smtpHost,
|
||||
port: smtpPort,
|
||||
secure: smtpSecure,
|
||||
auth: { user: creds.username, pass: creds.password },
|
||||
tls: { rejectUnauthorized: false } // самоподписанные сертификаты корпоративных серверов
|
||||
})
|
||||
|
||||
const from = this.config.label
|
||||
? `"${this.config.label}" <${this.config.email}>`
|
||||
: this.config.email
|
||||
|
||||
const info = await transporter.sendMail({
|
||||
from,
|
||||
to: compose.to.join(', '),
|
||||
cc: compose.cc.length ? compose.cc.join(', ') : undefined,
|
||||
bcc: compose.bcc.length ? compose.bcc.join(', ') : undefined,
|
||||
subject: compose.subject,
|
||||
text: compose.body,
|
||||
inReplyTo: compose.inReplyTo,
|
||||
references: compose.references
|
||||
})
|
||||
|
||||
// Сохраняем в папку Sent (best-effort)
|
||||
try {
|
||||
const raw = await this.buildRawMessage(info.messageId ?? '', compose, from)
|
||||
const sentFolder = await this.findSentFolder()
|
||||
if (sentFolder && raw) {
|
||||
await this.client.append(sentFolder, raw, ['\\Seen'])
|
||||
}
|
||||
} catch { /* не критично — письмо уже отправлено */ }
|
||||
}
|
||||
|
||||
private async findSentFolder(): Promise<string | null> {
|
||||
try {
|
||||
const tree = await this.client.listTree() as { folders?: ImapMailbox[] }
|
||||
return this.findFolderByRole(tree.folders ?? [], SpecialFolderRole.Sent)
|
||||
} catch { return null }
|
||||
}
|
||||
|
||||
private findFolderByRole(folders: ImapMailbox[], role: SpecialFolderRole): string | null {
|
||||
for (const f of folders) {
|
||||
const detected = this.detectFolderRole(f.specialUse, f.name)
|
||||
if (detected === role) return f.path
|
||||
if (f.folders?.length) {
|
||||
const found = this.findFolderByRole(f.folders, role)
|
||||
if (found) return found
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
private async buildRawMessage(
|
||||
messageId: string,
|
||||
compose: ComposeData,
|
||||
from: string
|
||||
): Promise<Buffer | null> {
|
||||
try {
|
||||
const transporter = nodemailer.createTransport({ streamTransport: true, newline: 'unix' })
|
||||
const mail = await transporter.sendMail({
|
||||
from,
|
||||
to: compose.to.join(', '),
|
||||
cc: compose.cc.length ? compose.cc.join(', ') : undefined,
|
||||
bcc: compose.bcc.length ? compose.bcc.join(', ') : undefined,
|
||||
subject: compose.subject,
|
||||
text: compose.body,
|
||||
messageId,
|
||||
inReplyTo: compose.inReplyTo,
|
||||
references: compose.references,
|
||||
date: new Date()
|
||||
})
|
||||
const chunks: Buffer[] = []
|
||||
await new Promise<void>((res, rej) => {
|
||||
;(mail.message as NodeJS.ReadableStream).on('data', (c: Buffer) => chunks.push(c))
|
||||
;(mail.message as NodeJS.ReadableStream).on('end', res)
|
||||
;(mail.message as NodeJS.ReadableStream).on('error', rej)
|
||||
})
|
||||
return Buffer.concat(chunks)
|
||||
} catch { return null }
|
||||
}
|
||||
|
||||
onNewMail(callback: (folderId: string, envelope: MessageEnvelope) => void): void {
|
||||
this.newMailCallback = callback
|
||||
this.client.on('exists', (data: { path: string; count: number; prevCount: number }) => {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import { join } from 'node:path'
|
|||
import type { AccountConfig } from '@shared/types/account'
|
||||
import { AccountType } from '@shared/types/account'
|
||||
import type { IEmailProvider, FolderListResult, MessageListResult } from '@shared/types/provider'
|
||||
import type { MessageBody, MessageFlags, MessageEnvelope } from '@shared/types/message'
|
||||
import type { MessageBody, MessageFlags, MessageEnvelope, ComposeData } from '@shared/types/message'
|
||||
import { ImapProvider } from '../providers/imap.provider'
|
||||
import { ExchangeProvider } from '../providers/exchange.provider'
|
||||
import { GmailProvider } from '../providers/gmail.provider'
|
||||
|
|
@ -131,6 +131,12 @@ export class AccountManager {
|
|||
if (provider) await provider.pollNewMessages().catch(() => {})
|
||||
}
|
||||
|
||||
async sendMessage(accountId: string, compose: ComposeData): Promise<void> {
|
||||
return this.withAutoReconnect(accountId, () =>
|
||||
this.getProvider(accountId).sendMessage(compose)
|
||||
)
|
||||
}
|
||||
|
||||
async searchMessages(accountId: string, query: string, limit: number): Promise<MessageEnvelope[]> {
|
||||
return this.withAutoReconnect(accountId, () => {
|
||||
const provider = this.providers.get(accountId)
|
||||
|
|
|
|||
|
|
@ -17,6 +17,10 @@ export type IconName =
|
|||
| 'threads'
|
||||
| 'search'
|
||||
| 'close'
|
||||
| 'compose'
|
||||
| 'reply'
|
||||
| 'forward'
|
||||
| 'send'
|
||||
|
||||
const props = defineProps<{
|
||||
name: IconName
|
||||
|
|
@ -99,6 +103,22 @@ const paths: Record<IconName, string> = {
|
|||
<line x1="18" y1="6" x2="6" y2="18"/>
|
||||
<line x1="6" y1="6" x2="18" y2="18"/>
|
||||
`,
|
||||
compose: `
|
||||
<path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"/>
|
||||
<path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"/>
|
||||
`,
|
||||
reply: `
|
||||
<polyline points="9 17 4 12 9 7"/>
|
||||
<path d="M20 18v-2a4 4 0 0 0-4-4H4"/>
|
||||
`,
|
||||
forward: `
|
||||
<polyline points="15 17 20 12 15 7"/>
|
||||
<path d="M4 18v-2a4 4 0 0 1 4-4h12"/>
|
||||
`,
|
||||
send: `
|
||||
<line x1="22" y1="2" x2="11" y2="13"/>
|
||||
<polygon points="22 2 15 22 11 13 2 9 22 2"/>
|
||||
`,
|
||||
}
|
||||
</script>
|
||||
|
||||
|
|
|
|||
|
|
@ -21,6 +21,11 @@ const imapUsername = ref('')
|
|||
const imapPassword = ref('')
|
||||
const imapLabel = ref('')
|
||||
|
||||
const smtpHost = ref('')
|
||||
const smtpPort = ref(587)
|
||||
const smtpSecure = ref(false)
|
||||
const showSmtp = ref(false)
|
||||
|
||||
function generateId(): string {
|
||||
return `${Date.now()}-${Math.random().toString(36).slice(2, 9)}`
|
||||
}
|
||||
|
|
@ -36,7 +41,10 @@ async function handleSubmit(): Promise<void> {
|
|||
port: imapPort.value,
|
||||
secure: imapSecure.value,
|
||||
username: imapUsername.value,
|
||||
password: imapPassword.value
|
||||
password: imapPassword.value,
|
||||
...(showSmtp.value && smtpHost.value
|
||||
? { smtpHost: smtpHost.value, smtpPort: smtpPort.value, smtpSecure: smtpSecure.value }
|
||||
: {})
|
||||
}
|
||||
const config: AccountConfig = {
|
||||
id: generateId(),
|
||||
|
|
@ -112,6 +120,37 @@ const isFormValid = computed(() => imapHost.value && imapUsername.value && imapP
|
|||
<label>Пароль</label>
|
||||
<input v-model="imapPassword" type="password" required />
|
||||
</div>
|
||||
<!-- SMTP (опционально) -->
|
||||
<div class="smtp-section">
|
||||
<button type="button" class="smtp-toggle" @click="showSmtp = !showSmtp">
|
||||
<svg :style="{ transform: showSmtp ? 'rotate(90deg)' : 'none', transition: 'transform 0.18s' }"
|
||||
width="12" height="12" viewBox="0 0 24 24" fill="none"
|
||||
stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
|
||||
<polyline points="9 18 15 12 9 6"/>
|
||||
</svg>
|
||||
Настройки SMTP (для отправки)
|
||||
</button>
|
||||
|
||||
<div v-if="showSmtp" class="smtp-fields">
|
||||
<div class="form-row">
|
||||
<div class="form-group flex-1">
|
||||
<label>SMTP сервер</label>
|
||||
<input v-model="smtpHost" type="text" :placeholder="imapHost ? imapHost.replace(/^imap\./i, 'smtp.') : 'smtp.example.com'" />
|
||||
</div>
|
||||
<div class="form-group" style="width: 80px">
|
||||
<label>Порт</label>
|
||||
<input v-model.number="smtpPort" type="number" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="checkbox-label">
|
||||
<input v-model="smtpSecure" type="checkbox" />
|
||||
SSL/TLS (порт 465)
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="submit-btn" :disabled="!isFormValid || testing">
|
||||
{{ testing ? 'Подключение...' : 'Добавить аккаунт' }}
|
||||
</button>
|
||||
|
|
@ -491,4 +530,38 @@ const isFormValid = computed(() => imapHost.value && imapUsername.value && imapP
|
|||
@keyframes spin {
|
||||
to { transform: rotate(360deg); }
|
||||
}
|
||||
|
||||
.smtp-section {
|
||||
margin-top: 4px;
|
||||
margin-bottom: 8px;
|
||||
border-radius: 10px;
|
||||
border: 1px solid rgba(255, 255, 255, 0.10);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.smtp-toggle {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 10px 14px;
|
||||
font-size: 12px;
|
||||
font-weight: 500;
|
||||
color: var(--text-muted);
|
||||
background: rgba(255, 255, 255, 0.03);
|
||||
cursor: pointer;
|
||||
text-align: left;
|
||||
transition: background var(--transition-fast), color var(--transition-fast);
|
||||
}
|
||||
|
||||
.smtp-toggle:hover {
|
||||
background: rgba(255, 255, 255, 0.07);
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.smtp-fields {
|
||||
padding: 8px 14px 12px;
|
||||
border-top: 1px solid rgba(255, 255, 255, 0.07);
|
||||
background: rgba(255, 255, 255, 0.02);
|
||||
}
|
||||
</style>
|
||||
|
|
|
|||
600
src/renderer/src/components/compose/ComposeWindow.vue
Normal file
600
src/renderer/src/components/compose/ComposeWindow.vue
Normal file
|
|
@ -0,0 +1,600 @@
|
|||
<script setup lang="ts">
|
||||
import { ref, computed, watch, nextTick, onMounted, onUnmounted } from 'vue'
|
||||
import { useComposeStore } from '../../stores/compose.store'
|
||||
import AppIcon from '../AppIcon.vue'
|
||||
|
||||
const composeStore = useComposeStore()
|
||||
|
||||
// ── Адресные поля (token-input) ───────────────────────────
|
||||
|
||||
type Field = 'to' | 'cc' | 'bcc'
|
||||
|
||||
const toInput = ref('')
|
||||
const ccInput = ref('')
|
||||
const bccInput = ref('')
|
||||
const showCc = ref(false)
|
||||
const showBcc = ref(false)
|
||||
|
||||
const toInputEl = ref<HTMLInputElement | null>(null)
|
||||
const bodyEl = ref<HTMLTextAreaElement | null>(null)
|
||||
|
||||
watch(() => composeStore.draft, (d) => {
|
||||
if (!d) return
|
||||
toInput.value = ''
|
||||
ccInput.value = ''
|
||||
bccInput.value = ''
|
||||
showCc.value = d.cc.length > 0
|
||||
showBcc.value = d.bcc.length > 0
|
||||
nextTick(() => {
|
||||
if (d.mode === 'new') {
|
||||
toInputEl.value?.focus()
|
||||
} else {
|
||||
bodyEl.value?.focus()
|
||||
// Ставим курсор в начало (перед цитатой)
|
||||
bodyEl.value?.setSelectionRange(0, 0)
|
||||
}
|
||||
})
|
||||
}, { immediate: true })
|
||||
|
||||
function inputModel(field: Field): { value: string; update: (v: string) => void } {
|
||||
if (field === 'to') return { value: toInput.value, update: (v) => { toInput.value = v } }
|
||||
if (field === 'cc') return { value: ccInput.value, update: (v) => { ccInput.value = v } }
|
||||
return { value: bccInput.value, update: (v) => { bccInput.value = v } }
|
||||
}
|
||||
|
||||
function parseEmails(raw: string): string[] {
|
||||
return raw.split(/[,;\s]+/)
|
||||
.map((s) => s.trim())
|
||||
.filter((s) => s.includes('@'))
|
||||
}
|
||||
|
||||
function commitInput(field: Field): void {
|
||||
if (!composeStore.draft) return
|
||||
const raw = field === 'to' ? toInput.value : field === 'cc' ? ccInput.value : bccInput.value
|
||||
const emails = parseEmails(raw)
|
||||
if (!emails.length) return
|
||||
composeStore.draft[field] = [...composeStore.draft[field], ...emails]
|
||||
if (field === 'to') toInput.value = ''
|
||||
if (field === 'cc') ccInput.value = ''
|
||||
if (field === 'bcc') bccInput.value = ''
|
||||
}
|
||||
|
||||
function onAddressKeydown(e: KeyboardEvent, field: Field): void {
|
||||
if (e.key === 'Enter' || e.key === 'Tab' || e.key === ',') {
|
||||
e.preventDefault()
|
||||
commitInput(field)
|
||||
}
|
||||
if (e.key === 'Backspace') {
|
||||
const raw = field === 'to' ? toInput.value : field === 'cc' ? ccInput.value : bccInput.value
|
||||
if (raw === '' && composeStore.draft) {
|
||||
composeStore.draft[field].pop()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function removeAddr(field: Field, idx: number): void {
|
||||
composeStore.draft?.[field].splice(idx, 1)
|
||||
}
|
||||
|
||||
function onAddressBlur(field: Field): void {
|
||||
commitInput(field)
|
||||
}
|
||||
|
||||
// ── Отправка ──────────────────────────────────────────────
|
||||
|
||||
async function handleSend(): Promise<void> {
|
||||
if (!composeStore.draft) return
|
||||
// Сначала коммитим незаконченный ввод адресов
|
||||
commitInput('to')
|
||||
commitInput('cc')
|
||||
commitInput('bcc')
|
||||
await nextTick()
|
||||
await composeStore.send()
|
||||
}
|
||||
|
||||
// ── Keyboard shortcut Ctrl/Cmd+Enter ─────────────────────
|
||||
|
||||
function onKeydown(e: KeyboardEvent): void {
|
||||
if ((e.ctrlKey || e.metaKey) && e.key === 'Enter') {
|
||||
e.preventDefault()
|
||||
handleSend()
|
||||
}
|
||||
if (e.key === 'Escape') {
|
||||
composeStore.close()
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => document.addEventListener('keydown', onKeydown))
|
||||
onUnmounted(() => document.removeEventListener('keydown', onKeydown))
|
||||
|
||||
// ── Title ─────────────────────────────────────────────────
|
||||
|
||||
const title = computed(() => {
|
||||
switch (composeStore.draft?.mode) {
|
||||
case 'reply': return 'Ответить'
|
||||
case 'replyAll': return 'Ответить всем'
|
||||
case 'forward': return 'Переслать'
|
||||
default: return 'Новое письмо'
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Transition name="compose">
|
||||
<div v-if="composeStore.isOpen" class="compose-overlay" @mousedown.self="composeStore.close()">
|
||||
<div class="compose-window" @keydown.stop>
|
||||
<!-- Header -->
|
||||
<div class="compose-header">
|
||||
<span class="compose-title">{{ title }}</span>
|
||||
<button class="compose-close" @click="composeStore.close()">
|
||||
<AppIcon name="close" :size="11" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- Fields -->
|
||||
<div class="compose-fields" v-if="composeStore.draft">
|
||||
<!-- To -->
|
||||
<div class="field-row">
|
||||
<span class="field-label">Кому</span>
|
||||
<div class="addr-input-wrap">
|
||||
<span
|
||||
v-for="(addr, i) in composeStore.draft.to"
|
||||
:key="i"
|
||||
class="addr-token"
|
||||
>
|
||||
{{ addr }}
|
||||
<button class="token-remove" @click="removeAddr('to', i)">×</button>
|
||||
</span>
|
||||
<input
|
||||
ref="toInputEl"
|
||||
class="addr-input"
|
||||
:value="toInput"
|
||||
placeholder="email@example.com"
|
||||
@input="toInput = ($event.target as HTMLInputElement).value"
|
||||
@keydown="onAddressKeydown($event, 'to')"
|
||||
@blur="onAddressBlur('to')"
|
||||
/>
|
||||
</div>
|
||||
<div class="field-actions">
|
||||
<button v-if="!showCc" class="toggle-field" @click="showCc = true">Копия</button>
|
||||
<button v-if="!showBcc" class="toggle-field" @click="showBcc = true">Скрытая</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Cc -->
|
||||
<div v-if="showCc" class="field-row">
|
||||
<span class="field-label">Копия</span>
|
||||
<div class="addr-input-wrap">
|
||||
<span
|
||||
v-for="(addr, i) in composeStore.draft.cc"
|
||||
:key="i"
|
||||
class="addr-token"
|
||||
>
|
||||
{{ addr }}
|
||||
<button class="token-remove" @click="removeAddr('cc', i)">×</button>
|
||||
</span>
|
||||
<input
|
||||
class="addr-input"
|
||||
:value="ccInput"
|
||||
placeholder="email@example.com"
|
||||
@input="ccInput = ($event.target as HTMLInputElement).value"
|
||||
@keydown="onAddressKeydown($event, 'cc')"
|
||||
@blur="onAddressBlur('cc')"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Bcc -->
|
||||
<div v-if="showBcc" class="field-row">
|
||||
<span class="field-label">Скрытая</span>
|
||||
<div class="addr-input-wrap">
|
||||
<span
|
||||
v-for="(addr, i) in composeStore.draft.bcc"
|
||||
:key="i"
|
||||
class="addr-token"
|
||||
>
|
||||
{{ addr }}
|
||||
<button class="token-remove" @click="removeAddr('bcc', i)">×</button>
|
||||
</span>
|
||||
<input
|
||||
class="addr-input"
|
||||
:value="bccInput"
|
||||
placeholder="email@example.com"
|
||||
@input="bccInput = ($event.target as HTMLInputElement).value"
|
||||
@keydown="onAddressKeydown($event, 'bcc')"
|
||||
@blur="onAddressBlur('bcc')"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Subject -->
|
||||
<div class="field-row">
|
||||
<span class="field-label">Тема</span>
|
||||
<input
|
||||
class="subject-input"
|
||||
v-model="composeStore.draft.subject"
|
||||
placeholder="Тема письма"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Divider -->
|
||||
<div class="compose-divider" />
|
||||
|
||||
<!-- Body -->
|
||||
<textarea
|
||||
ref="bodyEl"
|
||||
class="compose-body"
|
||||
v-model="composeStore.draft!.body"
|
||||
placeholder="Напишите сообщение..."
|
||||
/>
|
||||
|
||||
<!-- Footer -->
|
||||
<div class="compose-footer">
|
||||
<div v-if="composeStore.sendError" class="send-error">
|
||||
{{ composeStore.sendError }}
|
||||
</div>
|
||||
<div class="footer-actions">
|
||||
<button class="btn-cancel" @click="composeStore.close()">Отмена</button>
|
||||
<button
|
||||
class="btn-send"
|
||||
:disabled="composeStore.sending || !composeStore.draft?.to.length && !toInput"
|
||||
@click="handleSend"
|
||||
>
|
||||
<span v-if="composeStore.sending" class="spinner-sm" />
|
||||
<span class="send-icon" v-else><AppIcon name="send" :size="13" /></span>
|
||||
{{ composeStore.sending ? 'Отправка...' : 'Отправить' }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Transition>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
/* ── Overlay ─────────────────────────────────────────────── */
|
||||
.compose-overlay {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: 200;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: rgba(0, 0, 0, 0.45);
|
||||
backdrop-filter: blur(4px);
|
||||
-webkit-backdrop-filter: blur(4px);
|
||||
}
|
||||
|
||||
/* ── Window ──────────────────────────────────────────────── */
|
||||
.compose-window {
|
||||
width: 660px;
|
||||
max-width: calc(100vw - 48px);
|
||||
max-height: calc(100vh - 80px);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
border-radius: 16px;
|
||||
border: 1px solid rgba(255, 255, 255, 0.13);
|
||||
background:
|
||||
linear-gradient(160deg, rgba(255, 255, 255, 0.09) 0%, rgba(255, 255, 255, 0.02) 100%),
|
||||
rgba(12, 12, 22, 0.92);
|
||||
backdrop-filter: blur(56px) saturate(2.2);
|
||||
-webkit-backdrop-filter: blur(56px) saturate(2.2);
|
||||
box-shadow:
|
||||
inset 0 1px 0 rgba(255, 255, 255, 0.18),
|
||||
inset 0 0 0 1px rgba(255, 255, 255, 0.04),
|
||||
0 24px 80px rgba(0, 0, 0, 0.65),
|
||||
0 8px 24px rgba(0, 0, 0, 0.40);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
/* ── Header ──────────────────────────────────────────────── */
|
||||
.compose-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 14px 16px 12px;
|
||||
border-bottom: 1px solid rgba(255, 255, 255, 0.07);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.compose-title {
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
color: var(--text-primary);
|
||||
letter-spacing: 0.01em;
|
||||
}
|
||||
|
||||
.compose-close {
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border-radius: 50%;
|
||||
color: var(--text-muted);
|
||||
transition: background var(--transition-fast), color var(--transition-fast);
|
||||
}
|
||||
|
||||
.compose-close:hover {
|
||||
background: rgba(255, 255, 255, 0.10);
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
/* ── Fields ──────────────────────────────────────────────── */
|
||||
.compose-fields {
|
||||
flex-shrink: 0;
|
||||
padding: 4px 0;
|
||||
border-bottom: 1px solid rgba(255, 255, 255, 0.07);
|
||||
}
|
||||
|
||||
.field-row {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 0;
|
||||
padding: 6px 16px;
|
||||
border-bottom: 1px solid rgba(255, 255, 255, 0.04);
|
||||
min-height: 36px;
|
||||
}
|
||||
|
||||
.field-row:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.field-label {
|
||||
flex-shrink: 0;
|
||||
width: 60px;
|
||||
font-size: 11px;
|
||||
font-weight: 600;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.5px;
|
||||
color: var(--text-muted);
|
||||
padding-top: 8px;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
/* ── Address token input ─────────────────────────────────── */
|
||||
.addr-input-wrap {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 4px;
|
||||
align-items: center;
|
||||
padding: 4px 0;
|
||||
min-height: 28px;
|
||||
}
|
||||
|
||||
.addr-token {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
padding: 2px 8px 2px 9px;
|
||||
border-radius: 99px;
|
||||
font-size: 12px;
|
||||
color: var(--text-secondary);
|
||||
background: rgba(255, 255, 255, 0.08);
|
||||
border: 1px solid rgba(255, 255, 255, 0.12);
|
||||
white-space: nowrap;
|
||||
max-width: 260px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.token-remove {
|
||||
flex-shrink: 0;
|
||||
font-size: 13px;
|
||||
line-height: 1;
|
||||
color: var(--text-muted);
|
||||
padding: 0 1px;
|
||||
transition: color var(--transition-fast);
|
||||
}
|
||||
|
||||
.token-remove:hover {
|
||||
color: var(--danger);
|
||||
}
|
||||
|
||||
.addr-input {
|
||||
flex: 1;
|
||||
min-width: 140px;
|
||||
background: none;
|
||||
border: none;
|
||||
outline: none;
|
||||
color: var(--text-primary);
|
||||
font-size: 13px;
|
||||
padding: 3px 0;
|
||||
caret-color: var(--accent);
|
||||
}
|
||||
|
||||
.addr-input::placeholder {
|
||||
color: rgba(255, 255, 255, 0.20);
|
||||
}
|
||||
|
||||
.field-actions {
|
||||
flex-shrink: 0;
|
||||
display: flex;
|
||||
gap: 4px;
|
||||
padding-top: 7px;
|
||||
}
|
||||
|
||||
.toggle-field {
|
||||
font-size: 11px;
|
||||
color: var(--text-muted);
|
||||
padding: 1px 6px;
|
||||
border-radius: 4px;
|
||||
transition: color var(--transition-fast), background var(--transition-fast);
|
||||
}
|
||||
|
||||
.toggle-field:hover {
|
||||
color: var(--text-secondary);
|
||||
background: rgba(255, 255, 255, 0.06);
|
||||
}
|
||||
|
||||
/* Subject input */
|
||||
.subject-input {
|
||||
flex: 1;
|
||||
background: none;
|
||||
border: none;
|
||||
outline: none;
|
||||
color: var(--text-primary);
|
||||
font-size: 13px;
|
||||
font-weight: 500;
|
||||
padding: 7px 0;
|
||||
caret-color: var(--accent);
|
||||
}
|
||||
|
||||
.subject-input::placeholder {
|
||||
color: rgba(255, 255, 255, 0.20);
|
||||
font-weight: 400;
|
||||
}
|
||||
|
||||
/* ── Divider ─────────────────────────────────────────────── */
|
||||
.compose-divider {
|
||||
height: 1px;
|
||||
background: rgba(255, 255, 255, 0.06);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
/* ── Body ────────────────────────────────────────────────── */
|
||||
.compose-body {
|
||||
flex: 1;
|
||||
background: none;
|
||||
border: none;
|
||||
outline: none;
|
||||
resize: none;
|
||||
color: var(--text-primary);
|
||||
font-size: 13px;
|
||||
line-height: 1.65;
|
||||
padding: 14px 16px;
|
||||
min-height: 220px;
|
||||
caret-color: var(--accent);
|
||||
font-family: inherit;
|
||||
}
|
||||
|
||||
.compose-body::placeholder {
|
||||
color: rgba(255, 255, 255, 0.18);
|
||||
}
|
||||
|
||||
/* ── Footer ──────────────────────────────────────────────── */
|
||||
.compose-footer {
|
||||
flex-shrink: 0;
|
||||
padding: 10px 16px 14px;
|
||||
border-top: 1px solid rgba(255, 255, 255, 0.07);
|
||||
background: rgba(0, 0, 0, 0.12);
|
||||
}
|
||||
|
||||
.send-error {
|
||||
font-size: 12px;
|
||||
color: var(--danger);
|
||||
margin-bottom: 8px;
|
||||
padding: 6px 10px;
|
||||
background: rgba(255, 60, 60, 0.10);
|
||||
border: 1px solid rgba(255, 60, 60, 0.20);
|
||||
border-radius: 7px;
|
||||
}
|
||||
|
||||
.footer-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: flex-end;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.btn-cancel {
|
||||
padding: 7px 16px;
|
||||
border-radius: var(--radius-full);
|
||||
font-size: 13px;
|
||||
color: var(--text-muted);
|
||||
background: rgba(255, 255, 255, 0.05);
|
||||
border: 1px solid rgba(255, 255, 255, 0.09);
|
||||
transition: background var(--transition-fast), color var(--transition-fast);
|
||||
}
|
||||
|
||||
.btn-cancel:hover {
|
||||
background: rgba(255, 255, 255, 0.09);
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.btn-send {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 7px;
|
||||
padding: 7px 20px;
|
||||
border-radius: var(--radius-full);
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
color: var(--accent-text);
|
||||
background: linear-gradient(
|
||||
to bottom,
|
||||
color-mix(in srgb, var(--accent) 88%, white 12%) 0%,
|
||||
var(--accent) 100%
|
||||
);
|
||||
border: none;
|
||||
box-shadow:
|
||||
inset 0 1px 0 rgba(255, 255, 255, 0.35),
|
||||
0 2px 10px color-mix(in srgb, var(--accent) 35%, transparent);
|
||||
cursor: pointer;
|
||||
transition:
|
||||
background var(--transition-fast),
|
||||
box-shadow var(--transition-fast),
|
||||
transform var(--transition-fast),
|
||||
opacity var(--transition-fast);
|
||||
}
|
||||
|
||||
.btn-send:hover:not(:disabled) {
|
||||
background: linear-gradient(
|
||||
to bottom,
|
||||
color-mix(in srgb, var(--accent-hover) 88%, white 12%) 0%,
|
||||
var(--accent-hover) 100%
|
||||
);
|
||||
box-shadow:
|
||||
inset 0 1px 0 rgba(255, 255, 255, 0.40),
|
||||
0 4px 18px color-mix(in srgb, var(--accent) 45%, transparent);
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
|
||||
.btn-send:active:not(:disabled) {
|
||||
transform: translateY(0);
|
||||
box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.20);
|
||||
}
|
||||
|
||||
.btn-send:disabled {
|
||||
opacity: 0.45;
|
||||
cursor: not-allowed;
|
||||
transform: none;
|
||||
}
|
||||
|
||||
.send-icon {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.spinner-sm {
|
||||
width: 13px;
|
||||
height: 13px;
|
||||
border: 2px solid rgba(255, 255, 255, 0.3);
|
||||
border-top-color: #fff;
|
||||
border-radius: 50%;
|
||||
animation: spin 0.7s linear infinite;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
to { transform: rotate(360deg); }
|
||||
}
|
||||
|
||||
/* ── Transitions ─────────────────────────────────────────── */
|
||||
.compose-enter-active {
|
||||
transition: opacity 180ms ease, transform 220ms cubic-bezier(0.34, 1.1, 0.64, 1);
|
||||
}
|
||||
.compose-leave-active {
|
||||
transition: opacity 140ms ease, transform 160ms ease;
|
||||
}
|
||||
.compose-enter-from {
|
||||
opacity: 0;
|
||||
transform: scale(0.96) translateY(12px);
|
||||
}
|
||||
.compose-leave-to {
|
||||
opacity: 0;
|
||||
transform: scale(0.97) translateY(6px);
|
||||
}
|
||||
</style>
|
||||
|
|
@ -1,15 +1,18 @@
|
|||
<script setup lang="ts">
|
||||
import { ref } from 'vue'
|
||||
import { ref, onMounted, onUnmounted } from 'vue'
|
||||
import AccountSwitcher from '../sidebar/AccountSwitcher.vue'
|
||||
import FolderTree from '../sidebar/FolderTree.vue'
|
||||
import MessageList from '../messages/MessageList.vue'
|
||||
import MessagePreview from '../preview/MessagePreview.vue'
|
||||
import AddAccountDialog from '../accounts/AddAccountDialog.vue'
|
||||
import NotificationContainer from '../notifications/NotificationContainer.vue'
|
||||
import ComposeWindow from '../compose/ComposeWindow.vue'
|
||||
import AppIcon from '../AppIcon.vue'
|
||||
import { useAccountsStore } from '../../stores/accounts.store'
|
||||
import { useComposeStore } from '../../stores/compose.store'
|
||||
|
||||
const accountsStore = useAccountsStore()
|
||||
const composeStore = useComposeStore()
|
||||
const showAddAccount = ref(false)
|
||||
const folderPaneWidth = ref(240)
|
||||
const messagePaneWidth = ref(360)
|
||||
|
|
@ -49,6 +52,16 @@ function stopResize(): void {
|
|||
document.body.style.cursor = ''
|
||||
document.body.style.userSelect = ''
|
||||
}
|
||||
|
||||
function onGlobalKeydown(e: KeyboardEvent): void {
|
||||
if ((e.ctrlKey || e.metaKey) && e.key === 'n' && accountsStore.accounts.length > 0) {
|
||||
e.preventDefault()
|
||||
composeStore.openNew()
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => document.addEventListener('keydown', onGlobalKeydown))
|
||||
onUnmounted(() => document.removeEventListener('keydown', onGlobalKeydown))
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
|
@ -56,6 +69,14 @@ function stopResize(): void {
|
|||
<div class="content-area">
|
||||
<div class="account-bar">
|
||||
<AccountSwitcher @add-account="onAddAccount" />
|
||||
<button
|
||||
v-if="accountsStore.accounts.length > 0"
|
||||
class="compose-btn"
|
||||
v-tooltip="'Новое письмо (Ctrl+N)'"
|
||||
@click="composeStore.openNew()"
|
||||
>
|
||||
<AppIcon name="compose" :size="16" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="folder-pane" :style="{ width: folderPaneWidth + 'px' }">
|
||||
|
|
@ -81,6 +102,7 @@ function stopResize(): void {
|
|||
/>
|
||||
|
||||
<NotificationContainer />
|
||||
<ComposeWindow />
|
||||
|
||||
<!-- Пустое состояние: нет аккаунтов -->
|
||||
<div v-if="accountsStore.accounts.length === 0 && !accountsStore.loading && !showAddAccount" class="empty-state">
|
||||
|
|
@ -132,6 +154,48 @@ function stopResize(): void {
|
|||
box-shadow:
|
||||
inset 0 1px 0 rgba(255, 255, 255, 0.12),
|
||||
0 8px 32px rgba(0, 0, 0, 0.50);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.compose-btn {
|
||||
margin: 0 8px 10px;
|
||||
padding: 9px 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border-radius: 10px;
|
||||
color: var(--text-secondary);
|
||||
background: rgba(255, 255, 255, 0.06);
|
||||
border: 1px solid rgba(255, 255, 255, 0.10);
|
||||
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.09);
|
||||
cursor: pointer;
|
||||
transition:
|
||||
background var(--transition-fast),
|
||||
color var(--transition-fast),
|
||||
border-color var(--transition-fast),
|
||||
box-shadow var(--transition-fast),
|
||||
transform var(--transition-fast);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.compose-btn:hover {
|
||||
background: linear-gradient(
|
||||
to bottom,
|
||||
color-mix(in srgb, var(--accent) 88%, white 12%) 0%,
|
||||
var(--accent) 100%
|
||||
);
|
||||
border-color: transparent;
|
||||
color: var(--accent-text);
|
||||
box-shadow:
|
||||
inset 0 1px 0 rgba(255, 255, 255, 0.35),
|
||||
0 3px 12px color-mix(in srgb, var(--accent) 35%, transparent);
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
|
||||
.compose-btn:active {
|
||||
transform: translateY(0);
|
||||
}
|
||||
|
||||
.folder-pane {
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import AppIcon from '../AppIcon.vue'
|
|||
import { useMessagesStore } from '../../stores/messages.store'
|
||||
import { useFoldersStore } from '../../stores/folders.store'
|
||||
import { useAccountsStore } from '../../stores/accounts.store'
|
||||
import { useComposeStore } from '../../stores/compose.store'
|
||||
|
||||
const props = defineProps<{
|
||||
message: MessageEnvelope
|
||||
|
|
@ -14,6 +15,7 @@ const props = defineProps<{
|
|||
const messagesStore = useMessagesStore()
|
||||
const foldersStore = useFoldersStore()
|
||||
const accountsStore = useAccountsStore()
|
||||
const composeStore = useComposeStore()
|
||||
|
||||
const isUnread = computed(() => !props.message.flags.seen)
|
||||
const isFlagged = computed(() => props.message.flags.flagged)
|
||||
|
|
@ -31,6 +33,18 @@ async function handleDelete(): Promise<void> {
|
|||
await messagesStore.deleteOne(props.message.id)
|
||||
}
|
||||
|
||||
function handleReply(): void {
|
||||
composeStore.openReply(props.message, messagesStore.messageBody)
|
||||
}
|
||||
|
||||
function handleReplyAll(): void {
|
||||
composeStore.openReply(props.message, messagesStore.messageBody, true)
|
||||
}
|
||||
|
||||
function handleForward(): void {
|
||||
composeStore.openForward(props.message, messagesStore.messageBody)
|
||||
}
|
||||
|
||||
const dateDisplay = computed(() => formatFullDate(props.message.date))
|
||||
|
||||
// ── Contact popup ──────────────────────────────────────────
|
||||
|
|
@ -182,6 +196,23 @@ onUnmounted(() => {
|
|||
|
||||
<!-- Строка действий -->
|
||||
<div class="action-bar">
|
||||
<button class="action-btn primary" v-tooltip="'Ответить'" @click="handleReply">
|
||||
<AppIcon name="reply" :size="13" />
|
||||
<span>Ответить</span>
|
||||
</button>
|
||||
|
||||
<button class="action-btn" v-tooltip="'Ответить всем'" @click="handleReplyAll">
|
||||
<AppIcon name="reply" :size="13" />
|
||||
<span>Всем</span>
|
||||
</button>
|
||||
|
||||
<button class="action-btn" v-tooltip="'Переслать'" @click="handleForward">
|
||||
<AppIcon name="forward" :size="13" />
|
||||
<span>Переслать</span>
|
||||
</button>
|
||||
|
||||
<div class="action-spacer" />
|
||||
|
||||
<button
|
||||
class="action-btn"
|
||||
:class="{ active: isFlagged, 'flag-active': isFlagged }"
|
||||
|
|
@ -189,7 +220,6 @@ onUnmounted(() => {
|
|||
@click="handleToggleFlag"
|
||||
>
|
||||
<AppIcon name="flag" :size="13" />
|
||||
<span>{{ isFlagged ? 'Отмечено' : 'Флажок' }}</span>
|
||||
</button>
|
||||
|
||||
<button
|
||||
|
|
@ -199,18 +229,14 @@ onUnmounted(() => {
|
|||
@click="handleToggleRead"
|
||||
>
|
||||
<AppIcon name="envelope" :size="13" />
|
||||
<span>{{ isUnread ? 'Прочитано' : 'Непрочитано' }}</span>
|
||||
</button>
|
||||
|
||||
<div class="action-spacer" />
|
||||
|
||||
<button
|
||||
class="action-btn danger"
|
||||
v-tooltip="'Удалить письмо'"
|
||||
@click="handleDelete"
|
||||
>
|
||||
<AppIcon name="trash" :size="13" />
|
||||
<span>Удалить</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -504,6 +530,32 @@ onUnmounted(() => {
|
|||
border-color: rgba(240, 165, 0, 0.42);
|
||||
}
|
||||
|
||||
.action-btn.primary {
|
||||
background: linear-gradient(
|
||||
to bottom,
|
||||
color-mix(in srgb, var(--accent) 88%, white 12%) 0%,
|
||||
var(--accent) 100%
|
||||
);
|
||||
border-color: transparent;
|
||||
color: var(--accent-text);
|
||||
box-shadow:
|
||||
inset 0 1px 0 rgba(255, 255, 255, 0.30),
|
||||
0 2px 8px color-mix(in srgb, var(--accent) 30%, transparent);
|
||||
}
|
||||
|
||||
.action-btn.primary:hover {
|
||||
background: linear-gradient(
|
||||
to bottom,
|
||||
color-mix(in srgb, var(--accent-hover) 88%, white 12%) 0%,
|
||||
var(--accent-hover) 100%
|
||||
);
|
||||
border-color: transparent;
|
||||
color: var(--accent-text);
|
||||
box-shadow:
|
||||
inset 0 1px 0 rgba(255, 255, 255, 0.35),
|
||||
0 4px 14px color-mix(in srgb, var(--accent) 40%, transparent);
|
||||
}
|
||||
|
||||
.action-btn.danger:hover {
|
||||
color: var(--danger);
|
||||
background: rgba(255, 60, 60, 0.12);
|
||||
|
|
|
|||
144
src/renderer/src/stores/compose.store.ts
Normal file
144
src/renderer/src/stores/compose.store.ts
Normal file
|
|
@ -0,0 +1,144 @@
|
|||
import { ref, computed } from 'vue'
|
||||
import { defineStore } from 'pinia'
|
||||
import type { ComposeData } from '@shared/types/message'
|
||||
import type { MessageEnvelope, MessageBody } from '@shared/types/message'
|
||||
import { useAccountsStore } from './accounts.store'
|
||||
import { useIpc } from '../composables/useIpc'
|
||||
|
||||
export type ComposeMode = 'new' | 'reply' | 'replyAll' | 'forward'
|
||||
|
||||
export interface ComposeDraft {
|
||||
mode: ComposeMode
|
||||
to: string[]
|
||||
cc: string[]
|
||||
bcc: string[]
|
||||
subject: string
|
||||
body: string
|
||||
inReplyTo?: string
|
||||
references?: string
|
||||
replyToMessageId?: string
|
||||
replyToFolderId?: string
|
||||
}
|
||||
|
||||
function quoteBody(envelope: MessageEnvelope, body: MessageBody | null): string {
|
||||
const date = envelope.date ? new Date(envelope.date).toLocaleString('ru') : ''
|
||||
const from = envelope.from.name
|
||||
? `${envelope.from.name} <${envelope.from.email}>`
|
||||
: envelope.from.email
|
||||
const text = body?.text ?? ''
|
||||
const lines = text.split('\n').map((l) => `> ${l}`).join('\n')
|
||||
return `\n\n--- Оригинальное письмо ---\nОт: ${from}\nДата: ${date}\nТема: ${envelope.subject}\n\n${lines}`
|
||||
}
|
||||
|
||||
export const useComposeStore = defineStore('compose', () => {
|
||||
const { invoke } = useIpc()
|
||||
const accountsStore = useAccountsStore()
|
||||
|
||||
const draft = ref<ComposeDraft | null>(null)
|
||||
const sending = ref(false)
|
||||
const sendError = ref<string | null>(null)
|
||||
|
||||
const isOpen = computed(() => draft.value !== null)
|
||||
|
||||
function openNew(): void {
|
||||
sendError.value = null
|
||||
draft.value = { mode: 'new', to: [], cc: [], bcc: [], subject: '', body: '' }
|
||||
}
|
||||
|
||||
function openReply(envelope: MessageEnvelope, body: MessageBody | null, replyAll = false): void {
|
||||
sendError.value = null
|
||||
const to = replyAll
|
||||
? [envelope.from.email, ...envelope.to.map((a) => a.email)].filter(
|
||||
(e) => e !== accountsStore.activeAccount?.email
|
||||
)
|
||||
: [envelope.from.email]
|
||||
const cc = replyAll ? envelope.cc.map((a) => a.email) : []
|
||||
draft.value = {
|
||||
mode: replyAll ? 'replyAll' : 'reply',
|
||||
to,
|
||||
cc,
|
||||
bcc: [],
|
||||
subject: envelope.subject.startsWith('Re:') ? envelope.subject : `Re: ${envelope.subject}`,
|
||||
body: quoteBody(envelope, body),
|
||||
inReplyTo: envelope.messageId,
|
||||
references: envelope.messageId
|
||||
? [envelope.inReplyTo, envelope.messageId].filter(Boolean).join(' ')
|
||||
: undefined,
|
||||
replyToMessageId: envelope.id,
|
||||
replyToFolderId: envelope.folderId
|
||||
}
|
||||
}
|
||||
|
||||
function openForward(envelope: MessageEnvelope, body: MessageBody | null): void {
|
||||
sendError.value = null
|
||||
draft.value = {
|
||||
mode: 'forward',
|
||||
to: [],
|
||||
cc: [],
|
||||
bcc: [],
|
||||
subject: envelope.subject.startsWith('Fwd:') ? envelope.subject : `Fwd: ${envelope.subject}`,
|
||||
body: quoteBody(envelope, body)
|
||||
}
|
||||
}
|
||||
|
||||
function close(): void {
|
||||
draft.value = null
|
||||
sendError.value = null
|
||||
}
|
||||
|
||||
async function send(): Promise<boolean> {
|
||||
if (!draft.value) return false
|
||||
if (!accountsStore.activeAccountId) {
|
||||
sendError.value = 'Нет активного аккаунта'
|
||||
return false
|
||||
}
|
||||
if (!draft.value.to.length) {
|
||||
sendError.value = 'Укажите получателя'
|
||||
return false
|
||||
}
|
||||
|
||||
const compose: ComposeData = {
|
||||
to: draft.value.to,
|
||||
cc: draft.value.cc,
|
||||
bcc: draft.value.bcc,
|
||||
subject: draft.value.subject,
|
||||
body: draft.value.body,
|
||||
inReplyTo: draft.value.inReplyTo,
|
||||
references: draft.value.references,
|
||||
replyToMessageId: draft.value.replyToMessageId,
|
||||
replyToFolderId: draft.value.replyToFolderId
|
||||
}
|
||||
|
||||
sending.value = true
|
||||
sendError.value = null
|
||||
try {
|
||||
const result = await invoke('messages:send', {
|
||||
accountId: accountsStore.activeAccountId,
|
||||
compose
|
||||
})
|
||||
if (!result.success) {
|
||||
sendError.value = result.error ?? 'Ошибка отправки'
|
||||
return false
|
||||
}
|
||||
close()
|
||||
return true
|
||||
} catch (e) {
|
||||
sendError.value = (e as Error).message
|
||||
return false
|
||||
} finally {
|
||||
sending.value = false
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
draft,
|
||||
isOpen,
|
||||
sending,
|
||||
sendError,
|
||||
openNew,
|
||||
openReply,
|
||||
openForward,
|
||||
close,
|
||||
send
|
||||
}
|
||||
})
|
||||
|
|
@ -10,6 +10,10 @@ export interface ImapCredentials {
|
|||
secure: boolean
|
||||
username: string
|
||||
password: string
|
||||
// SMTP — опционально; если не указано, выводится из IMAP-хоста
|
||||
smtpHost?: string
|
||||
smtpPort?: number
|
||||
smtpSecure?: boolean
|
||||
}
|
||||
|
||||
export interface ExchangeCredentials {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import type { AccountConfig } from './account'
|
||||
import type { FolderListResult, MessageListResult } from './provider'
|
||||
import type { MessageBody, MessageFlags, MessageEnvelope } from './message'
|
||||
import type { MessageBody, MessageFlags, MessageEnvelope, ComposeData } from './message'
|
||||
|
||||
export interface IpcChannelMap {
|
||||
'accounts:list': [void, AccountConfig[]]
|
||||
|
|
@ -40,6 +40,7 @@ export interface IpcChannelMap {
|
|||
|
||||
'messages:poll': [{ accountId: string }, void]
|
||||
'messages:search': [{ accountId: string; query: string; limit: number }, MessageEnvelope[]]
|
||||
'messages:send': [{ accountId: string; compose: ComposeData }, { success: boolean; error?: string }]
|
||||
'app:setZoom': [{ factor: number }, void]
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -45,3 +45,15 @@ export interface MessageBody {
|
|||
inlineImages: InlineImage[]
|
||||
attachments: Attachment[]
|
||||
}
|
||||
|
||||
export interface ComposeData {
|
||||
to: string[]
|
||||
cc: string[]
|
||||
bcc: string[]
|
||||
subject: string
|
||||
body: string // plain text
|
||||
inReplyTo?: string // Message-ID оригинала (для ответа)
|
||||
references?: string // References header
|
||||
replyToMessageId?: string // ID письма в store (чтобы поставить \Answered)
|
||||
replyToFolderId?: string
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import type { Folder } from './folder'
|
||||
import type { MessageEnvelope, MessageBody, MessageFlags } from './message'
|
||||
import type { MessageEnvelope, MessageBody, MessageFlags, ComposeData } from './message'
|
||||
|
||||
export interface FolderListResult {
|
||||
folders: Folder[]
|
||||
|
|
@ -32,4 +32,5 @@ export interface IEmailProvider {
|
|||
offNewMail(): void
|
||||
pollNewMessages(): Promise<void>
|
||||
searchMessages(query: string, limit: number): Promise<MessageEnvelope[]>
|
||||
sendMessage(compose: ComposeData): Promise<void>
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue