From ceb1c3a1efba6554ce6a4e383959ca13d6098610 Mon Sep 17 00:00:00 2001 From: "r.rasputin" Date: Mon, 16 Nov 2026 11:04:40 +0700 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D1=8B=20=D1=80=D0=B5=D0=B4=D0=B0=D0=BA=D1=82=D0=BE?= =?UTF-8?q?=D1=80=20=D0=BF=D0=B8=D1=81=D1=8C=D0=BC=D0=B0=20=D0=B8=20=D0=BF?= =?UTF-8?q?=D0=BE=D0=BB=D1=83=D1=87=D0=B0=D1=82=D0=B5=D0=BB=D0=B8,=20?= =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=20=D0=BF=D1=80?= =?UTF-8?q?=D0=BE=D1=81=D0=BC=D0=BE=D1=82=D1=80=20=D0=BA=D0=B0=D1=80=D1=82?= =?UTF-8?q?=D0=B8=D0=BD=D0=BE=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/lib/smtp-error.ts | 28 ++++++ src/main/providers/imap.provider.ts | 8 +- src/renderer/src/components/ComposeEditor.vue | 71 ++++++++++++--- .../src/components/ImagePreviewDialog.vue | 87 +++++++++++++++++++ .../src/components/preview/MessageBody.vue | 37 +++++++- src/renderer/src/stores/compose.store.ts | 10 +-- src/renderer/src/utils/reply-recipients.ts | 4 + src/renderer/src/views/ComposeView.vue | 44 ++++------ src/shared/utils/account-email.ts | 8 ++ 9 files changed, 248 insertions(+), 49 deletions(-) create mode 100644 src/main/lib/smtp-error.ts create mode 100644 src/renderer/src/components/ImagePreviewDialog.vue create mode 100644 src/renderer/src/utils/reply-recipients.ts create mode 100644 src/shared/utils/account-email.ts diff --git a/src/main/lib/smtp-error.ts b/src/main/lib/smtp-error.ts new file mode 100644 index 0000000..e5a28df --- /dev/null +++ b/src/main/lib/smtp-error.ts @@ -0,0 +1,28 @@ +import type { ImapCredentials } from '../../shared/types/account' + +export function formatSmtpError(error: unknown, credentials: ImapCredentials): string { + const message: string = error instanceof Error ? error.message : String(error) + const host: string = credentials.smtpHost ?? credentials.host.replace(/^imap\./i, 'smtp.') + const port: number = credentials.smtpPort ?? 587 + const secure: boolean = credentials.smtpSecure ?? port === 465 + const mode: string = secure ? 'SSL/TLS' : 'STARTTLS' + const normalized: string = message.toLowerCase() + let hint: string = '' + if (normalized.includes('wrong version number') || normalized.includes('unknown protocol')) { + hint = 'Проверьте SMTP-порт и режим шифрования: обычно 465 — SSL/TLS, 587 — STARTTLS (переключатель SSL/TLS выключен).' + } else if (normalized.includes('certificate') || normalized.includes('self signed')) { + hint = 'Не удалось проверить сертификат SMTP-сервера. Проверьте имя сервера и доверие к сертификату. Для корпоративного сервера с самоподписанным сертификатом есть отдельная настройка аккаунта.' + } else if (normalized.includes('legacy renegotiation')) { + hint = 'SMTP-сервер использует устаревшее согласование TLS. Требуется обновление TLS на сервере или адрес другого SMTP-сервера у администратора.' + } else if (normalized.includes('ssl') || normalized.includes('tls')) { + hint = 'Не удалось установить защищённое SMTP-соединение. Проверьте порт, режим шифрования и настройки TLS сервера.' + } + return [`SMTP ${host}:${port} (${mode})`, hint, message].filter(Boolean).join('\n') +} + +export class SmtpSendError extends Error { + constructor(error: unknown, credentials: ImapCredentials) { + super(formatSmtpError(error, credentials), { cause: error }) + this.name = 'SmtpSendError' + } +} diff --git a/src/main/providers/imap.provider.ts b/src/main/providers/imap.provider.ts index 0e43ed7..5b3c324 100644 --- a/src/main/providers/imap.provider.ts +++ b/src/main/providers/imap.provider.ts @@ -1,3 +1,5 @@ +import { getAccountEmail } from '@shared/utils/account-email' +import { SmtpSendError } from '../lib/smtp-error' import { buildComposeAttachments } from '../lib/compose-attachments' import { ImapFlow } from 'imapflow' import { simpleParser } from 'mailparser' @@ -407,9 +409,7 @@ export class ImapProvider implements IEmailProvider { }) // Если email хранится без домена (только логин) — достраиваем из IMAP-хоста - const emailAddress = this.config.email.includes('@') - ? this.config.email - : `${this.config.email}@${creds.host.replace(/^[^.]+\./, '')}` + const emailAddress = getAccountEmail(this.config) // Имя отправителя: await-им промис из connect() — гарантирует что имя готово const senderName = await this.senderNamePromise @@ -440,6 +440,8 @@ export class ImapProvider implements IEmailProvider { inReplyTo: compose.inReplyTo, references: compose.references, attachments: buildComposeAttachments(compose) + }).catch((error: unknown): never => { + throw new SmtpSendError(error, creds) }) // Сохраняем в папку Sent (best-effort) diff --git a/src/renderer/src/components/ComposeEditor.vue b/src/renderer/src/components/ComposeEditor.vue index db46f1f..e5e2c3e 100644 --- a/src/renderer/src/components/ComposeEditor.vue +++ b/src/renderer/src/components/ComposeEditor.vue @@ -1,6 +1,7 @@ + + + + diff --git a/src/renderer/src/components/preview/MessageBody.vue b/src/renderer/src/components/preview/MessageBody.vue index a9499ab..6b732e9 100644 --- a/src/renderer/src/components/preview/MessageBody.vue +++ b/src/renderer/src/components/preview/MessageBody.vue @@ -1,5 +1,6 @@