odant-work 1.0.72 → 1.0.74
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/#system/package-manifest.json +29 -27
- package/$server/$folder/$class/$structure/handlers/pages/explorer/$handler/explorer.js +1 -1
- package/$server/$folder/$class/$structure/handlers/pages/form/calendar/$handler/calendar.js +1004 -1011
- package/$server/$folder/$class/$structure/handlers/pages/form/email/$handler/class.js +7 -90
- package/$server/$folder/$class/$structure/handlers/pages/form/email/$handler/email.js +913 -705
- package/$server/$folder/$class/$structure/handlers/pages/form/email/$handler/methods/refresh/$method/class.js +30 -1
- package/$server/$folder/$class/$structure/handlers/pages/form/search/$handler/class.js +1 -1
- package/$server/$folder/$class/$structure/handlers/pages/form/system/$handler/tabs/staff.js +78 -5
- package/$server/$folder/$class/ai/skills/email-mailbox.md +10 -7
- package/$server/$folder/$class/ai/skills/meeting-minutes.md +1 -1
- package/$server/$folder/$file/$eml/triggers/on_save/$trigger/class.js +17 -1
- package/$server/$folder/lib/calendar-form/calendar-form.js +482 -296
- package/$server/$folder/lib/icon/icon.js +50 -0
- package/$server/$folder/lib/tree/tree.js +9 -7
- package/USERS/$users/class.js +4 -3
- package/oda/components/icon/icon.js +6 -1
- package/package.json +1 -1
- package/sources/host/email-utils.js +25 -1
- package/sources/modules/agent/index.js +3 -1
- package/sources/modules/agent/node-rules.js +51 -0
- package/sources/modules/agent/scheduler.js +7 -0
- package/sources/modules/agent/tools/calendar-mail.js +273 -0
- package/sources/server/access/gateway.js +3 -0
- package/sources/server/class/feed.js +46 -0
- package/sources/server/class/mail-calendar.js +867 -0
- package/sources/server/class/security.js +44 -0
- package/sources/server/folder.js +1 -1
|
@@ -1,46 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
icon: 'enterprise:email',
|
|
3
|
-
imports: 'oda//button, oda//icon',
|
|
4
|
-
template: /* html */`
|
|
5
|
-
<style>
|
|
6
|
-
:host {
|
|
7
|
-
@apply --vertical;
|
|
8
|
-
@apply --flex;
|
|
9
|
-
}
|
|
10
|
-
.email-top-panel {
|
|
11
|
-
gap: 4px;
|
|
12
|
-
align-items: center;
|
|
13
|
-
}
|
|
14
|
-
</style>
|
|
15
|
-
<div class="email-top-panel" slot="top-panel" horizontal>
|
|
16
|
-
<oda-button icon="icons:add" @tap="odaFormEmail?.createEmail?.()" title="Написать"></oda-button>
|
|
17
|
-
<oda-button icon="icons:refresh" @tap="odaFormEmail?.fetchRefresh?.()" title="Обновить"></oda-button>
|
|
18
|
-
</div>
|
|
19
|
-
<oda-form-email flex :$item></oda-form-email>
|
|
20
|
-
`,
|
|
21
|
-
get odaFormEmail() {
|
|
22
|
-
return this.$('oda-form-email');
|
|
23
|
-
},
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const NO_MAILBOX = 'Сначала настройте почтовый ящик в настройках формы';
|
|
27
|
-
const EMPTY_DRAFT = () => ({ from: '', to: '', subject: '', body: '', inReplyTo: '' });
|
|
28
|
-
|
|
29
|
-
function accountAddresses(mailboxes = {}) {
|
|
30
|
-
const result = [];
|
|
31
|
-
for (const [key, box] of Object.entries(mailboxes || {})) {
|
|
32
|
-
const address = String(box?.auth?.user || box?.address || key || '').trim();
|
|
33
|
-
if (address && !result.includes(address))
|
|
34
|
-
result.push(address);
|
|
35
|
-
}
|
|
36
|
-
return result;
|
|
37
|
-
}
|
|
1
|
+
const EMPTY_DRAFT = () => ({ uid: '', origTime: 0, from: '', to: '', cc: '', subject: '', body: '', inReplyTo: '', attachments: [] });
|
|
38
2
|
|
|
39
3
|
function parseJson(value) {
|
|
40
|
-
if (value && typeof value === 'object')
|
|
41
|
-
|
|
42
|
-
if (typeof value !== 'string' || !value)
|
|
43
|
-
return null;
|
|
4
|
+
if (value && typeof value === 'object') return value;
|
|
5
|
+
if (typeof value !== 'string' || !value) return null;
|
|
44
6
|
try {
|
|
45
7
|
const parsed = JSON.parse(value);
|
|
46
8
|
return parsed && typeof parsed === 'object' ? parsed : null;
|
|
@@ -50,42 +12,25 @@ function parseJson(value) {
|
|
|
50
12
|
}
|
|
51
13
|
}
|
|
52
14
|
|
|
53
|
-
function
|
|
54
|
-
if (!value)
|
|
55
|
-
return '';
|
|
15
|
+
function formatMailShortDate(value) {
|
|
16
|
+
if (!value) return '';
|
|
56
17
|
const d = new Date(value);
|
|
57
|
-
if (
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
minute: '2-digit',
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
function newUid() {
|
|
68
|
-
if (globalThis.crypto?.randomUUID)
|
|
69
|
-
return crypto.randomUUID();
|
|
70
|
-
return Date.now().toString(36) + '-' + Math.random().toString(36).slice(2, 10);
|
|
18
|
+
if (isNaN(d.getTime())) return String(value);
|
|
19
|
+
const now = new Date();
|
|
20
|
+
const sameDay = d.getFullYear() === now.getFullYear() && d.getMonth() === now.getMonth() && d.getDate() === now.getDate();
|
|
21
|
+
if (sameDay)
|
|
22
|
+
return d.toLocaleTimeString('ru-RU', { hour: '2-digit', minute: '2-digit' });
|
|
23
|
+
return d.toLocaleDateString('ru-RU', { day: '2-digit', month: '2-digit' });
|
|
71
24
|
}
|
|
72
25
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
return (
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
function validateRecipients(to) {
|
|
82
|
-
const list = String(to || '').split(/[,;]/).map(s => s.trim()).filter(Boolean);
|
|
83
|
-
if (!list.length)
|
|
84
|
-
throw new Error('Укажите получателя');
|
|
85
|
-
const bad = list.filter(a => !/^[^\s@<>]+@[^\s@<>]+\.[^\s@<>]+$/.test(bareAddress(a)));
|
|
86
|
-
if (bad.length)
|
|
87
|
-
throw new Error('Некорректный адрес: ' + bad.join(', '));
|
|
88
|
-
return list.join(', ');
|
|
26
|
+
function formatMailFullDate(value) {
|
|
27
|
+
if (!value) return '';
|
|
28
|
+
const d = new Date(value);
|
|
29
|
+
if (isNaN(d.getTime())) return String(value);
|
|
30
|
+
return d.toLocaleString('ru-RU', {
|
|
31
|
+
day: '2-digit', month: 'short', year: 'numeric',
|
|
32
|
+
hour: '2-digit', minute: '2-digit',
|
|
33
|
+
});
|
|
89
34
|
}
|
|
90
35
|
|
|
91
36
|
function htmlToText(html) {
|
|
@@ -100,90 +45,79 @@ function htmlToText(html) {
|
|
|
100
45
|
function quoteBody(msg) {
|
|
101
46
|
const text = msg.body || htmlToText(msg.html || '');
|
|
102
47
|
const quoted = String(text).split(/\r?\n/).map(line => '> ' + line).join('\n');
|
|
103
|
-
return `\n\n${msg.
|
|
48
|
+
return `\n\n${formatMailFullDate(msg.date)}, ${msg.from || ''} пишет:\n${quoted}`;
|
|
104
49
|
}
|
|
105
50
|
|
|
106
|
-
/** Документ для iframe sandbox: без скриптов, ссылки — в новой вкладке. */
|
|
107
51
|
function htmlDocument(html) {
|
|
108
52
|
return '<!doctype html><html><head><meta charset="utf-8"><base target="_blank">'
|
|
109
|
-
+ '<style>body{margin:0;font-family:sans-serif;word-wrap:break-word;}img{max-width:100%;height:auto;}</style>'
|
|
53
|
+
+ '<style>body{margin:0;padding:8px;font-family:sans-serif;font-size:13.5px;line-height:1.45;word-wrap:break-word;}img{max-width:100%;height:auto;}</style>'
|
|
110
54
|
+ '</head><body>' + String(html || '') + '</body></html>';
|
|
111
55
|
}
|
|
112
56
|
|
|
113
|
-
function
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
body: body || '',
|
|
121
|
-
html: '',
|
|
122
|
-
status,
|
|
123
|
-
box: 'outbox',
|
|
124
|
-
mailbox: address || '',
|
|
125
|
-
};
|
|
126
|
-
if (inReplyTo)
|
|
127
|
-
json.inReplyTo = inReplyTo;
|
|
128
|
-
return json;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
/** Метаданные письма для message лога (список строится без чтения тел). */
|
|
132
|
-
function emlMeta(json) {
|
|
133
|
-
return {
|
|
134
|
-
uid: json.uid || '',
|
|
135
|
-
subject: json.subject || '',
|
|
136
|
-
from: json.from || '',
|
|
137
|
-
to: json.to || '',
|
|
138
|
-
date: json.date || '',
|
|
139
|
-
box: json.box || '',
|
|
140
|
-
mailbox: json.mailbox || '',
|
|
141
|
-
status: json.status || '',
|
|
142
|
-
};
|
|
57
|
+
function mailboxesToAccounts(mailboxes = {}) {
|
|
58
|
+
return Object.entries(mailboxes).map(([address, box]) => ({
|
|
59
|
+
address,
|
|
60
|
+
smtp: { host: '', port: 465, secure: true, ...box.smtp },
|
|
61
|
+
imap: { host: '', port: 993, secure: true, ...box.imap },
|
|
62
|
+
auth: { user: address, pass: '', ...box.auth },
|
|
63
|
+
}));
|
|
143
64
|
}
|
|
144
65
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
return null;
|
|
158
|
-
}
|
|
66
|
+
function accountsToMailboxes(accounts = [], previousMailboxes = {}) {
|
|
67
|
+
const mailboxes = Object.create(null);
|
|
68
|
+
for (const acc of accounts) {
|
|
69
|
+
const address = String(acc.auth?.user || '').trim();
|
|
70
|
+
if (!address) continue;
|
|
71
|
+
const prev = previousMailboxes?.[address] || {};
|
|
72
|
+
mailboxes[address] = {
|
|
73
|
+
...prev,
|
|
74
|
+
smtp: { host: acc.smtp?.host || '', port: Number(acc.smtp?.port) || 465, secure: acc.smtp?.secure !== false },
|
|
75
|
+
imap: { host: acc.imap?.host || '', port: Number(acc.imap?.port) || 993, secure: acc.imap?.secure !== false },
|
|
76
|
+
auth: { user: address, pass: acc.auth?.pass || '' },
|
|
77
|
+
};
|
|
159
78
|
}
|
|
160
|
-
|
|
161
|
-
return {
|
|
162
|
-
path: row.path,
|
|
163
|
-
uid: meta.uid || '',
|
|
164
|
-
subject: meta.subject || '(без темы)',
|
|
165
|
-
from: meta.from || '',
|
|
166
|
-
to: meta.to || '',
|
|
167
|
-
date,
|
|
168
|
-
status: meta.status || '',
|
|
169
|
-
error: meta.error || '',
|
|
170
|
-
box: meta.box,
|
|
171
|
-
address: meta.mailbox || '',
|
|
172
|
-
messageId: meta.messageId || '',
|
|
173
|
-
body: null,
|
|
174
|
-
html: null,
|
|
175
|
-
dateLabel: formatMailDate(date),
|
|
176
|
-
sortTime: date ? new Date(date).getTime() : (row.time || 0),
|
|
177
|
-
};
|
|
79
|
+
return mailboxes;
|
|
178
80
|
}
|
|
179
81
|
|
|
180
|
-
function
|
|
181
|
-
return
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
82
|
+
async function openEmailSettingsDialog($context) {
|
|
83
|
+
if (openEmailSettingsDialog.opening || !$context) return null;
|
|
84
|
+
openEmailSettingsDialog.opening = true;
|
|
85
|
+
let el, settings;
|
|
86
|
+
try {
|
|
87
|
+
settings = await $context.fetch('read_secret', { filename: 'email.json' });
|
|
88
|
+
el = ODA.createElement('oda-email-settings', {
|
|
89
|
+
accounts: mailboxesToAccounts(settings?.mailboxes),
|
|
90
|
+
});
|
|
91
|
+
if (!el.accounts.length) el.addAccount();
|
|
92
|
+
else el.index = 0;
|
|
93
|
+
}
|
|
94
|
+
catch (e) {
|
|
95
|
+
ODA.showMessage?.(e.message || String(e));
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
finally {
|
|
99
|
+
openEmailSettingsDialog.opening = false;
|
|
100
|
+
}
|
|
101
|
+
try {
|
|
102
|
+
await WORK.showDialog(el, {
|
|
103
|
+
TITLE: { label: 'Почтовые ящики', icon: 'enterprise:email' },
|
|
104
|
+
OK: { label: 'Сохранить', icon: 'icons:save' },
|
|
105
|
+
CANCEL: { label: 'Отмена', icon: 'icons:close' },
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
catch {
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
try {
|
|
112
|
+
el.validate();
|
|
113
|
+
const mailboxes = accountsToMailboxes(el.accounts, settings?.mailboxes);
|
|
114
|
+
await $context.fetch('save_secret', { filename: 'email.json' }, JSON.stringify({ mailboxes }));
|
|
115
|
+
return mailboxes;
|
|
116
|
+
}
|
|
117
|
+
catch (e) {
|
|
118
|
+
ODA.showMessage?.(e.message || String(e));
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
187
121
|
}
|
|
188
122
|
|
|
189
123
|
ODA({
|
|
@@ -215,25 +149,15 @@ ODA({
|
|
|
215
149
|
cursor: pointer;
|
|
216
150
|
border-bottom: 1px solid var(--subtle-border);
|
|
217
151
|
}
|
|
218
|
-
.account-item:not([info-invert]):hover {
|
|
219
|
-
@apply --hover;
|
|
220
|
-
}
|
|
152
|
+
.account-item:not([info-invert]):hover { @apply --hover; }
|
|
221
153
|
.account-title {
|
|
222
154
|
font-weight: 500;
|
|
223
155
|
overflow: hidden;
|
|
224
156
|
text-overflow: ellipsis;
|
|
225
157
|
white-space: nowrap;
|
|
226
158
|
}
|
|
227
|
-
.account-sub {
|
|
228
|
-
|
|
229
|
-
@apply --muted;
|
|
230
|
-
}
|
|
231
|
-
/* на инвертированной плашке приглушённый цвет темы нечитаем — следуем цвету плашки */
|
|
232
|
-
[info-invert] .account-sub {
|
|
233
|
-
color: inherit;
|
|
234
|
-
fill: inherit;
|
|
235
|
-
opacity: .75;
|
|
236
|
-
}
|
|
159
|
+
.account-sub { font-size: x-small; @apply --muted; }
|
|
160
|
+
[info-invert] .account-sub { color: inherit; fill: inherit; opacity: .75; }
|
|
237
161
|
.editor {
|
|
238
162
|
padding: 12px var(--space-l);
|
|
239
163
|
gap: var(--space-m);
|
|
@@ -245,10 +169,7 @@ ODA({
|
|
|
245
169
|
padding: var(--space-s) var(--space-m);
|
|
246
170
|
margin: 0;
|
|
247
171
|
}
|
|
248
|
-
legend {
|
|
249
|
-
font-size: x-small;
|
|
250
|
-
padding: 0 var(--space-s);
|
|
251
|
-
}
|
|
172
|
+
legend { font-size: x-small; padding: 0 var(--space-s); }
|
|
252
173
|
input {
|
|
253
174
|
border: none;
|
|
254
175
|
outline: none;
|
|
@@ -259,635 +180,922 @@ ODA({
|
|
|
259
180
|
box-sizing: border-box;
|
|
260
181
|
font: inherit;
|
|
261
182
|
}
|
|
262
|
-
.row {
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
}
|
|
266
|
-
.port {
|
|
267
|
-
max-width: 72px;
|
|
268
|
-
}
|
|
269
|
-
.empty {
|
|
270
|
-
padding: 24px;
|
|
271
|
-
@apply --muted;
|
|
272
|
-
text-align: center;
|
|
273
|
-
}
|
|
183
|
+
.row { gap: 12px; align-items: center; }
|
|
184
|
+
.port { max-width: 72px; }
|
|
185
|
+
.empty { padding: var(--space-l); @apply --muted; }
|
|
274
186
|
</style>
|
|
275
187
|
<div class="accounts" vertical>
|
|
276
188
|
<div class="accounts-toolbar" horizontal>
|
|
277
|
-
<
|
|
278
|
-
<oda-button icon="icons:add" title="Добавить ящик"
|
|
189
|
+
<span flex>Ящики</span>
|
|
190
|
+
<oda-button icon="icons:add" @tap="addAccount" title="Добавить ящик"></oda-button>
|
|
191
|
+
<oda-button icon="icons:delete" :disabled="!current" @tap="removeAccount" title="Удалить ящик"></oda-button>
|
|
279
192
|
</div>
|
|
280
|
-
<div
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
<div class="account-title">{{$for.item.auth?.user || '(новый)'}}</div>
|
|
286
|
-
<div class="account-sub">{{$for.item.smtp?.host || 'SMTP не задан'}}</div>
|
|
287
|
-
</div>
|
|
288
|
-
<oda-button ~if="index === $for.index" icon="icons:delete" title="Удалить ящик" @tap="removeAccount($for.index)"></oda-button>
|
|
289
|
-
</div>
|
|
290
|
-
<div ~if="!accounts.length" class="empty">Нет ящиков</div>
|
|
193
|
+
<div class="account-item" ~for="accounts"
|
|
194
|
+
:info-invert="index === $for.index"
|
|
195
|
+
@tap="index = $for.index">
|
|
196
|
+
<div class="account-title">{{$for.item.auth.user || 'Новый ящик'}}</div>
|
|
197
|
+
<div class="account-sub">{{$for.item.smtp.host || 'SMTP не задан'}}</div>
|
|
291
198
|
</div>
|
|
199
|
+
<div ~if="!accounts.length" class="empty">Нажмите «+» чтобы добавить ящик</div>
|
|
292
200
|
</div>
|
|
293
|
-
<div class="editor" vertical flex>
|
|
294
|
-
<
|
|
201
|
+
<div class="editor" vertical flex ~if="current">
|
|
202
|
+
<fieldset>
|
|
203
|
+
<legend>Учётная запись</legend>
|
|
204
|
+
<input placeholder="user@example.com" ::value="current.auth.user">
|
|
205
|
+
<input type="password" placeholder="Пароль или пароль приложения" ::value="current.auth.pass">
|
|
206
|
+
</fieldset>
|
|
207
|
+
<fieldset>
|
|
208
|
+
<legend>Исходящая почта (SMTP)</legend>
|
|
295
209
|
<div class="row" horizontal>
|
|
296
|
-
<
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
</fieldset>
|
|
300
|
-
<fieldset flex>
|
|
301
|
-
<legend>Пароль</legend>
|
|
302
|
-
<input type="password" placeholder="••••••••" ::value="accounts[index].auth.pass">
|
|
303
|
-
</fieldset>
|
|
210
|
+
<input flex placeholder="smtp.yandex.ru" ::value="current.smtp.host">
|
|
211
|
+
<input class="port" type="number" placeholder="465" ::value="current.smtp.port">
|
|
212
|
+
<oda-checkbox ::value="current.smtp.secure"></oda-checkbox><span>TLS</span>
|
|
304
213
|
</div>
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
<oda-checkbox ::value="accounts[index].imap.secure"></oda-checkbox>
|
|
315
|
-
<span>SSL/TLS</span>
|
|
316
|
-
</label>
|
|
317
|
-
</div>
|
|
318
|
-
</fieldset>
|
|
319
|
-
<fieldset>
|
|
320
|
-
<legend>Исходящая (SMTP)</legend>
|
|
321
|
-
<input placeholder="smtp.example.com" ::value="accounts[index].smtp.host">
|
|
322
|
-
<div class="row" horizontal>
|
|
323
|
-
<fieldset class="port">
|
|
324
|
-
<legend>Порт</legend>
|
|
325
|
-
<input type="number" ::value="accounts[index].smtp.port">
|
|
326
|
-
</fieldset>
|
|
327
|
-
<label horizontal style="gap:4px; align-items:center;">
|
|
328
|
-
<oda-checkbox ::value="accounts[index].smtp.secure"></oda-checkbox>
|
|
329
|
-
<span>SSL/TLS</span>
|
|
330
|
-
</label>
|
|
331
|
-
</div>
|
|
332
|
-
</fieldset>
|
|
333
|
-
</div>
|
|
334
|
-
<div ~if="!accounts[index]" class="empty" flex>Выберите ящик или нажмите «+»</div>
|
|
214
|
+
</fieldset>
|
|
215
|
+
<fieldset>
|
|
216
|
+
<legend>Входящая почта (IMAP)</legend>
|
|
217
|
+
<div class="row" horizontal>
|
|
218
|
+
<input flex placeholder="imap.yandex.ru" ::value="current.imap.host">
|
|
219
|
+
<input class="port" type="number" placeholder="993" ::value="current.imap.port">
|
|
220
|
+
<oda-checkbox ::value="current.imap.secure"></oda-checkbox><span>TLS</span>
|
|
221
|
+
</div>
|
|
222
|
+
</fieldset>
|
|
335
223
|
</div>
|
|
224
|
+
<div ~if="!current" class="empty" flex>Выберите или добавьте ящик</div>
|
|
336
225
|
`,
|
|
337
226
|
accounts: [],
|
|
338
227
|
index: -1,
|
|
228
|
+
get current() { return this.accounts[this.index] ?? null; },
|
|
339
229
|
addAccount() {
|
|
340
|
-
this.accounts.
|
|
230
|
+
this.accounts = [...this.accounts, {
|
|
231
|
+
address: '',
|
|
232
|
+
smtp: { host: '', port: 465, secure: true },
|
|
233
|
+
imap: { host: '', port: 993, secure: true },
|
|
234
|
+
auth: { user: '', pass: '' },
|
|
235
|
+
}];
|
|
341
236
|
this.index = this.accounts.length - 1;
|
|
342
|
-
this.render();
|
|
343
237
|
},
|
|
344
|
-
removeAccount(
|
|
345
|
-
if (index < 0)
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
this.
|
|
349
|
-
|
|
350
|
-
this.index = Math.min(this.index, this.accounts.length - 1);
|
|
351
|
-
}
|
|
352
|
-
this.render();
|
|
353
|
-
})
|
|
238
|
+
removeAccount() {
|
|
239
|
+
if (this.index < 0) return;
|
|
240
|
+
const next = [...this.accounts];
|
|
241
|
+
next.splice(this.index, 1);
|
|
242
|
+
this.accounts = next;
|
|
243
|
+
this.index = next.length ? Math.min(this.index, next.length - 1) : -1;
|
|
354
244
|
},
|
|
355
245
|
validate() {
|
|
356
|
-
const
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
throw new Error('
|
|
246
|
+
const seen = new Set();
|
|
247
|
+
for (const acc of this.accounts) {
|
|
248
|
+
const addr = String(acc.auth?.user || '').trim();
|
|
249
|
+
if (!addr) throw new Error('Укажите адрес (логин) для каждого ящика');
|
|
250
|
+
if (seen.has(addr)) throw new Error('Повторяющийся ящик: ' + addr);
|
|
251
|
+
seen.add(addr);
|
|
252
|
+
}
|
|
361
253
|
},
|
|
362
254
|
});
|
|
363
255
|
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
imports: 'oda//button, oda//icon
|
|
367
|
-
|
|
368
|
-
template: /* html */ `
|
|
256
|
+
export default {
|
|
257
|
+
icon: 'enterprise:email',
|
|
258
|
+
imports: 'oda//button, oda//icon',
|
|
259
|
+
template: /* html */`
|
|
369
260
|
<style>
|
|
370
261
|
:host {
|
|
262
|
+
@apply --horizontal;
|
|
263
|
+
@apply --flex;
|
|
371
264
|
overflow: hidden;
|
|
265
|
+
background: var(--content-background, #ffffff);
|
|
266
|
+
color: var(--content-color, #1e293b);
|
|
267
|
+
font-size: 13px;
|
|
268
|
+
}
|
|
269
|
+
.mail-sidebar {
|
|
270
|
+
@apply --vertical;
|
|
271
|
+
width: 212px;
|
|
272
|
+
flex-shrink: 0;
|
|
273
|
+
padding: 12px 10px;
|
|
274
|
+
gap: 6px;
|
|
275
|
+
border-right: 1px solid var(--subtle-border, #e2e8f0);
|
|
276
|
+
background: var(--subtle-background, #f8fafc);
|
|
277
|
+
overflow-y: auto;
|
|
278
|
+
}
|
|
279
|
+
.compose-btn {
|
|
280
|
+
@apply --horizontal;
|
|
281
|
+
align-items: center;
|
|
282
|
+
justify-content: center;
|
|
283
|
+
gap: 7px;
|
|
284
|
+
padding: 9px 14px;
|
|
285
|
+
border-radius: 9px;
|
|
286
|
+
border: none;
|
|
287
|
+
background: var(--accent-color, #2563eb);
|
|
288
|
+
color: var(--accent-back, #ffffff);
|
|
289
|
+
font: inherit;
|
|
290
|
+
font-size: 13.5px;
|
|
291
|
+
font-weight: 600;
|
|
292
|
+
cursor: pointer;
|
|
293
|
+
margin-bottom: 6px;
|
|
294
|
+
box-shadow: 0 2px 6px rgba(37, 99, 235, 0.22);
|
|
295
|
+
}
|
|
296
|
+
.compose-btn:hover { filter: brightness(1.06); }
|
|
297
|
+
.nav-btn {
|
|
298
|
+
@apply --horizontal;
|
|
299
|
+
align-items: center;
|
|
300
|
+
gap: 9px;
|
|
301
|
+
width: 100%;
|
|
302
|
+
padding: 8px 11px;
|
|
303
|
+
border-radius: 8px;
|
|
304
|
+
border: 1px solid transparent;
|
|
305
|
+
background: transparent;
|
|
306
|
+
color: inherit;
|
|
307
|
+
font: inherit;
|
|
308
|
+
font-size: 13.5px;
|
|
309
|
+
font-weight: 500;
|
|
310
|
+
text-align: left;
|
|
311
|
+
cursor: pointer;
|
|
312
|
+
user-select: none;
|
|
313
|
+
}
|
|
314
|
+
.nav-btn:hover {
|
|
315
|
+
background: color-mix(in srgb, var(--accent-color, #2563eb) 6%, transparent);
|
|
316
|
+
}
|
|
317
|
+
.nav-btn.active {
|
|
318
|
+
background: color-mix(in srgb, var(--accent-color, #2563eb) 10%, var(--content-background, #ffffff));
|
|
319
|
+
border-color: color-mix(in srgb, var(--accent-color, #2563eb) 50%, transparent);
|
|
320
|
+
color: var(--accent-color, #2563eb);
|
|
321
|
+
font-weight: 600;
|
|
322
|
+
}
|
|
323
|
+
.nav-badge {
|
|
324
|
+
margin-left: auto;
|
|
325
|
+
padding: 1px 7px;
|
|
326
|
+
border-radius: 999px;
|
|
327
|
+
font-size: 11px;
|
|
328
|
+
font-weight: 700;
|
|
329
|
+
background: var(--accent-color, #2563eb);
|
|
330
|
+
color: #ffffff;
|
|
331
|
+
}
|
|
332
|
+
.nav-count {
|
|
333
|
+
margin-left: auto;
|
|
334
|
+
font-size: 11.5px;
|
|
335
|
+
color: var(--muted-color, #64748b);
|
|
336
|
+
}
|
|
337
|
+
.side-sep {
|
|
338
|
+
height: 1px;
|
|
339
|
+
margin: 4px 6px;
|
|
340
|
+
background: var(--subtle-border, #e2e8f0);
|
|
341
|
+
}
|
|
342
|
+
.side-label {
|
|
343
|
+
padding: 2px 10px;
|
|
344
|
+
font-size: 11px;
|
|
345
|
+
font-weight: 700;
|
|
346
|
+
text-transform: uppercase;
|
|
347
|
+
letter-spacing: 0.04em;
|
|
348
|
+
color: var(--muted-color, #64748b);
|
|
349
|
+
}
|
|
350
|
+
.acc-pill {
|
|
351
|
+
font-size: 12.5px;
|
|
352
|
+
padding: 6px 10px;
|
|
353
|
+
overflow: hidden;
|
|
354
|
+
text-overflow: ellipsis;
|
|
355
|
+
white-space: nowrap;
|
|
356
|
+
}
|
|
357
|
+
.mail-list-pane {
|
|
358
|
+
@apply --vertical;
|
|
359
|
+
width: 335px;
|
|
360
|
+
min-width: 260px;
|
|
361
|
+
flex-shrink: 0;
|
|
362
|
+
border-right: 1px solid var(--subtle-border, #e2e8f0);
|
|
363
|
+
background: var(--content-background, #ffffff);
|
|
364
|
+
overflow: hidden;
|
|
365
|
+
}
|
|
366
|
+
.list-toolbar {
|
|
367
|
+
@apply --horizontal;
|
|
368
|
+
align-items: center;
|
|
369
|
+
gap: 6px;
|
|
370
|
+
padding: 10px 10px 8px;
|
|
371
|
+
border-bottom: 1px solid var(--subtle-border, #e2e8f0);
|
|
372
|
+
background: var(--content-background, #ffffff);
|
|
373
|
+
}
|
|
374
|
+
.search-input {
|
|
375
|
+
@apply --flex;
|
|
376
|
+
min-width: 0;
|
|
377
|
+
padding: 6px 10px;
|
|
378
|
+
border-radius: 7px;
|
|
379
|
+
border: 1px solid var(--subtle-border, #cbd5e1);
|
|
380
|
+
background: var(--subtle-background, #f8fafc);
|
|
381
|
+
color: inherit;
|
|
382
|
+
font: inherit;
|
|
383
|
+
font-size: 12.5px;
|
|
384
|
+
outline: none;
|
|
385
|
+
}
|
|
386
|
+
.search-input:focus {
|
|
387
|
+
border-color: var(--accent-color, #2563eb);
|
|
388
|
+
background: var(--content-background, #ffffff);
|
|
389
|
+
}
|
|
390
|
+
.icon-btn {
|
|
391
|
+
@apply --horizontal;
|
|
392
|
+
align-items: center;
|
|
393
|
+
justify-content: center;
|
|
394
|
+
padding: 6px 8px;
|
|
395
|
+
border-radius: 7px;
|
|
396
|
+
border: 1px solid var(--subtle-border, #cbd5e1);
|
|
397
|
+
background: var(--content-background, #ffffff);
|
|
398
|
+
color: inherit;
|
|
399
|
+
cursor: pointer;
|
|
400
|
+
font-size: 12px;
|
|
401
|
+
}
|
|
402
|
+
.icon-btn:hover { background: var(--accent-soft); }
|
|
403
|
+
.icon-btn.active {
|
|
404
|
+
border-color: var(--accent-color, #2563eb);
|
|
405
|
+
color: var(--accent-color, #2563eb);
|
|
406
|
+
background: color-mix(in srgb, var(--accent-color, #2563eb) 10%, var(--content-background, #ffffff));
|
|
407
|
+
font-weight: 600;
|
|
408
|
+
}
|
|
409
|
+
.msg-scroll {
|
|
410
|
+
@apply --vertical;
|
|
411
|
+
@apply --flex;
|
|
412
|
+
overflow-y: auto;
|
|
413
|
+
}
|
|
414
|
+
.msg-row {
|
|
415
|
+
display: flex;
|
|
416
|
+
flex-direction: column;
|
|
417
|
+
gap: 3px;
|
|
418
|
+
padding: 10px 12px;
|
|
419
|
+
border-bottom: 1px solid var(--subtle-border, #f1f5f9);
|
|
420
|
+
cursor: pointer;
|
|
421
|
+
position: relative;
|
|
422
|
+
transition: background 0.1s ease;
|
|
423
|
+
}
|
|
424
|
+
.msg-row:hover {
|
|
425
|
+
background: var(--subtle-background, #f8fafc);
|
|
426
|
+
}
|
|
427
|
+
.msg-row.selected {
|
|
428
|
+
background: color-mix(in srgb, var(--accent-color, #2563eb) 10%, var(--content-background, #ffffff));
|
|
429
|
+
border-left: 3px solid var(--accent-color, #2563eb);
|
|
430
|
+
padding-left: 9px;
|
|
431
|
+
}
|
|
432
|
+
.msg-row.unread .msg-peer,
|
|
433
|
+
.msg-row.unread .msg-subj {
|
|
434
|
+
font-weight: 700;
|
|
435
|
+
}
|
|
436
|
+
.msg-top {
|
|
437
|
+
display: flex;
|
|
438
|
+
align-items: center;
|
|
439
|
+
gap: 6px;
|
|
440
|
+
min-width: 0;
|
|
441
|
+
}
|
|
442
|
+
.unread-dot {
|
|
443
|
+
width: 7px;
|
|
444
|
+
height: 7px;
|
|
445
|
+
border-radius: 50%;
|
|
446
|
+
background: var(--accent-color, #2563eb);
|
|
447
|
+
flex-shrink: 0;
|
|
448
|
+
}
|
|
449
|
+
.msg-peer {
|
|
450
|
+
flex: 1;
|
|
451
|
+
min-width: 0;
|
|
452
|
+
overflow: hidden;
|
|
453
|
+
text-overflow: ellipsis;
|
|
454
|
+
white-space: nowrap;
|
|
455
|
+
font-size: 13px;
|
|
456
|
+
font-weight: 500;
|
|
457
|
+
}
|
|
458
|
+
.msg-time {
|
|
459
|
+
font-size: 11px;
|
|
460
|
+
color: var(--muted-color, #64748b);
|
|
461
|
+
white-space: nowrap;
|
|
462
|
+
}
|
|
463
|
+
.msg-subj {
|
|
464
|
+
font-size: 12.5px;
|
|
465
|
+
overflow: hidden;
|
|
466
|
+
text-overflow: ellipsis;
|
|
467
|
+
white-space: nowrap;
|
|
468
|
+
display: flex;
|
|
469
|
+
align-items: center;
|
|
470
|
+
gap: 5px;
|
|
471
|
+
}
|
|
472
|
+
.msg-snip {
|
|
473
|
+
font-size: 11.5px;
|
|
474
|
+
color: var(--muted-color, #64748b);
|
|
475
|
+
overflow: hidden;
|
|
476
|
+
text-overflow: ellipsis;
|
|
477
|
+
white-space: nowrap;
|
|
478
|
+
}
|
|
479
|
+
.status-tag {
|
|
480
|
+
font-size: 10.5px;
|
|
481
|
+
padding: 1px 6px;
|
|
482
|
+
border-radius: 999px;
|
|
483
|
+
background: var(--subtle-background, #f1f5f9);
|
|
484
|
+
color: var(--muted-color, #64748b);
|
|
485
|
+
}
|
|
486
|
+
.status-tag.err { background: #fef2f2; color: #dc2626; }
|
|
487
|
+
.status-tag.draft { background: #fffbeb; color: #b45309; }
|
|
488
|
+
.mail-view-pane {
|
|
489
|
+
@apply --vertical;
|
|
490
|
+
@apply --flex;
|
|
491
|
+
min-width: 0;
|
|
492
|
+
overflow: hidden;
|
|
493
|
+
background: var(--content-background, #ffffff);
|
|
494
|
+
}
|
|
495
|
+
.empty-pane {
|
|
496
|
+
@apply --vertical;
|
|
497
|
+
@apply --flex;
|
|
498
|
+
align-items: center;
|
|
499
|
+
justify-content: center;
|
|
500
|
+
gap: 10px;
|
|
501
|
+
color: var(--muted-color, #64748b);
|
|
502
|
+
padding: 24px;
|
|
503
|
+
text-align: center;
|
|
504
|
+
}
|
|
505
|
+
.view-actions {
|
|
506
|
+
@apply --horizontal;
|
|
507
|
+
align-items: center;
|
|
508
|
+
gap: 6px;
|
|
509
|
+
padding: 10px 16px;
|
|
510
|
+
border-bottom: 1px solid var(--subtle-border, #e2e8f0);
|
|
511
|
+
background: var(--subtle-background, #f8fafc);
|
|
512
|
+
flex-wrap: wrap;
|
|
513
|
+
}
|
|
514
|
+
.view-head {
|
|
515
|
+
@apply --vertical;
|
|
516
|
+
gap: 4px;
|
|
517
|
+
padding: 14px 18px 10px;
|
|
518
|
+
border-bottom: 1px solid var(--subtle-border, #e2e8f0);
|
|
519
|
+
}
|
|
520
|
+
.view-subject {
|
|
521
|
+
font-size: 17px;
|
|
522
|
+
font-weight: 700;
|
|
523
|
+
}
|
|
524
|
+
.view-meta {
|
|
525
|
+
font-size: 12.5px;
|
|
526
|
+
color: var(--muted-color, #475569);
|
|
527
|
+
}
|
|
528
|
+
.att-bar {
|
|
529
|
+
display: flex;
|
|
530
|
+
flex-wrap: wrap;
|
|
531
|
+
gap: 6px;
|
|
532
|
+
padding: 8px 18px;
|
|
533
|
+
border-bottom: 1px solid var(--subtle-border, #e2e8f0);
|
|
534
|
+
background: var(--subtle-background, #f8fafc);
|
|
535
|
+
}
|
|
536
|
+
.att-chip {
|
|
537
|
+
@apply --horizontal;
|
|
538
|
+
align-items: center;
|
|
539
|
+
gap: 5px;
|
|
540
|
+
padding: 4px 10px;
|
|
541
|
+
border-radius: 6px;
|
|
542
|
+
border: 1px solid var(--subtle-border, #cbd5e1);
|
|
543
|
+
background: var(--content-background, #ffffff);
|
|
544
|
+
font-size: 12px;
|
|
545
|
+
cursor: pointer;
|
|
546
|
+
}
|
|
547
|
+
.view-body {
|
|
548
|
+
@apply --flex;
|
|
549
|
+
overflow: auto;
|
|
550
|
+
padding: 16px 18px;
|
|
551
|
+
white-space: pre-wrap;
|
|
552
|
+
line-height: 1.5;
|
|
553
|
+
user-select: text;
|
|
554
|
+
}
|
|
555
|
+
.view-iframe {
|
|
556
|
+
@apply --flex;
|
|
557
|
+
width: 100%;
|
|
558
|
+
border: none;
|
|
559
|
+
background: #ffffff;
|
|
560
|
+
}
|
|
561
|
+
.compose-wrap {
|
|
562
|
+
@apply --vertical;
|
|
563
|
+
@apply --flex;
|
|
564
|
+
padding: 14px 18px;
|
|
565
|
+
gap: 10px;
|
|
566
|
+
overflow-y: auto;
|
|
567
|
+
}
|
|
568
|
+
.compose-field {
|
|
569
|
+
display: flex;
|
|
570
|
+
align-items: center;
|
|
571
|
+
gap: 8px;
|
|
572
|
+
border-bottom: 1px solid var(--subtle-border, #e2e8f0);
|
|
573
|
+
padding: 4px 0;
|
|
574
|
+
}
|
|
575
|
+
.compose-field label {
|
|
576
|
+
width: 68px;
|
|
577
|
+
font-size: 12.5px;
|
|
578
|
+
color: var(--muted-color, #64748b);
|
|
579
|
+
flex-shrink: 0;
|
|
580
|
+
}
|
|
581
|
+
.compose-field input,
|
|
582
|
+
.compose-field select {
|
|
583
|
+
flex: 1;
|
|
584
|
+
border: none;
|
|
585
|
+
outline: none;
|
|
586
|
+
background: transparent;
|
|
587
|
+
color: inherit;
|
|
588
|
+
font: inherit;
|
|
589
|
+
padding: 4px 0;
|
|
590
|
+
}
|
|
591
|
+
.compose-body {
|
|
592
|
+
@apply --flex;
|
|
593
|
+
min-height: 180px;
|
|
594
|
+
border: 1px solid var(--subtle-border, #e2e8f0);
|
|
595
|
+
border-radius: 8px;
|
|
596
|
+
padding: 10px 12px;
|
|
597
|
+
outline: none;
|
|
598
|
+
background: var(--content-background, #ffffff);
|
|
599
|
+
color: inherit;
|
|
600
|
+
font: inherit;
|
|
601
|
+
line-height: 1.5;
|
|
602
|
+
resize: none;
|
|
603
|
+
}
|
|
604
|
+
.compose-footer {
|
|
605
|
+
@apply --horizontal;
|
|
606
|
+
align-items: center;
|
|
607
|
+
gap: 8px;
|
|
608
|
+
padding-top: 4px;
|
|
372
609
|
}
|
|
373
610
|
</style>
|
|
374
|
-
|
|
375
|
-
<
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
611
|
+
|
|
612
|
+
<aside class="mail-sidebar">
|
|
613
|
+
<button type="button" class="compose-btn" @tap="createEmail()">
|
|
614
|
+
<oda-icon icon="icons:add" icon-size="16"></oda-icon>
|
|
615
|
+
<span>Написать</span>
|
|
616
|
+
</button>
|
|
617
|
+
|
|
618
|
+
<button type="button" class="nav-btn" ~for="folders"
|
|
619
|
+
~class="{ active: activeBox === $for.item.id }"
|
|
620
|
+
@tap="selectBox($for.item.id)">
|
|
621
|
+
<oda-icon :icon="$for.item.icon" icon-size="16"></oda-icon>
|
|
622
|
+
<span>{{$for.item.label}}</span>
|
|
623
|
+
<span ~if="badgeOf($for.item.id) > 0" class="nav-badge">{{badgeOf($for.item.id)}}</span>
|
|
624
|
+
<span ~if="badgeOf($for.item.id) === 0 && countOf($for.item.id) > 0" class="nav-count">{{countOf($for.item.id)}}</span>
|
|
625
|
+
</button>
|
|
626
|
+
|
|
627
|
+
<div class="side-sep" ~if="accounts.length"></div>
|
|
628
|
+
<div class="side-label" ~if="accounts.length">Ящики</div>
|
|
629
|
+
<button type="button" class="nav-btn acc-pill" ~if="accounts.length > 1"
|
|
630
|
+
~class="{ active: !selectedAccount }"
|
|
631
|
+
@tap="selectAccount('')">Все ящики</button>
|
|
632
|
+
<button type="button" class="nav-btn acc-pill" ~for="accounts"
|
|
633
|
+
~class="{ active: selectedAccount === $for.item.address }"
|
|
634
|
+
@tap="selectAccount($for.item.address)"
|
|
635
|
+
:title="$for.item.address">
|
|
636
|
+
<span>{{$for.item.address}}</span>
|
|
637
|
+
</button>
|
|
638
|
+
|
|
639
|
+
<div style="flex: 1;"></div>
|
|
640
|
+
<div class="side-sep" ~if="canConfigure"></div>
|
|
641
|
+
<label ~if="canConfigure && accounts.length" style="display:flex;align-items:center;gap:6px;padding:4px 8px;font-size:12px;cursor:pointer;">
|
|
642
|
+
<input type="checkbox" :checked="autoRefresh" @change="toggleAutoRefresh($event.target.checked)">
|
|
643
|
+
<span>Автопроверка почты</span>
|
|
644
|
+
</label>
|
|
645
|
+
<button type="button" class="nav-btn" ~if="canConfigure" @tap="openSettings()">
|
|
646
|
+
<oda-icon icon="icons:settings" icon-size="16"></oda-icon>
|
|
647
|
+
<span>Настройка ящиков</span>
|
|
648
|
+
</button>
|
|
649
|
+
</aside>
|
|
650
|
+
|
|
651
|
+
<section class="mail-list-pane">
|
|
652
|
+
<div class="list-toolbar">
|
|
653
|
+
<input class="search-input" type="search" placeholder="Поиск писем…" :value="searchQuery" @input="onSearchInput($event)">
|
|
654
|
+
<button type="button" class="icon-btn" ~class="{ active: unreadOnly }" @tap="toggleUnreadOnly()" title="Только непрочитанные">●</button>
|
|
655
|
+
<button type="button" class="icon-btn" @tap="fetchRefresh()" :disabled="refreshing" title="Проверить почту с сервера">
|
|
656
|
+
<oda-icon :icon="refreshing ? 'spinners:8-dots-rotate' : 'icons:refresh'" icon-size="15"></oda-icon>
|
|
657
|
+
</button>
|
|
658
|
+
</div>
|
|
659
|
+
|
|
660
|
+
<div class="msg-scroll">
|
|
661
|
+
<div ~if="loading && !messages.length" class="empty-pane">Загрузка писем…</div>
|
|
662
|
+
<div ~if="!loading && !messages.length" class="empty-pane">
|
|
663
|
+
<span>В папке «{{activeBoxLabel}}» писем нет</span>
|
|
664
|
+
</div>
|
|
665
|
+
<div ~for="messages" class="msg-row"
|
|
666
|
+
~class="{ selected: selected?.path === $for.item.path, unread: !$for.item.read }"
|
|
667
|
+
@tap="selectMessage($for.item)">
|
|
668
|
+
<div class="msg-top">
|
|
669
|
+
<span ~if="!$for.item.read" class="unread-dot"></span>
|
|
670
|
+
<span class="msg-peer">{{peerLabel($for.item)}}</span>
|
|
671
|
+
<span class="msg-time">{{shortDate($for.item.date || $for.item.sortTime)}}</span>
|
|
672
|
+
</div>
|
|
673
|
+
<div class="msg-subj">
|
|
674
|
+
<span style="flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;">{{$for.item.subject || '(без темы)'}}</span>
|
|
675
|
+
<oda-icon ~if="$for.item.attachmentsCount > 0" icon="editor:attach-file" icon-size="13"></oda-icon>
|
|
676
|
+
<span ~if="$for.item.status === 'failed'" class="status-tag err">ошибка</span>
|
|
677
|
+
<span ~if="$for.item.status === 'draft'" class="status-tag draft">черновик</span>
|
|
678
|
+
</div>
|
|
679
|
+
<div ~if="$for.item.snippet" class="msg-snip">{{$for.item.snippet}}</div>
|
|
680
|
+
</div>
|
|
681
|
+
</div>
|
|
682
|
+
</section>
|
|
683
|
+
|
|
684
|
+
<main class="mail-view-pane">
|
|
685
|
+
<div ~if="mode === 'idle'" class="empty-pane">
|
|
686
|
+
<oda-icon icon="enterprise:email" icon-size="40" style="opacity:0.35;"></oda-icon>
|
|
687
|
+
<div style="font-size:14px;font-weight:600;">Выберите письмо для просмотра</div>
|
|
688
|
+
<div ~if="!accounts.length && canConfigure" style="font-size:12.5px;">
|
|
689
|
+
Почтовый ящик для этого узла ещё не настроен.
|
|
690
|
+
<div style="margin-top:8px;">
|
|
691
|
+
<button type="button" class="compose-btn" @tap="openSettings()">Подключить ящик</button>
|
|
692
|
+
</div>
|
|
693
|
+
</div>
|
|
694
|
+
</div>
|
|
695
|
+
|
|
696
|
+
<div ~if="mode === 'view' && selected" style="display:flex;flex-direction:column;flex:1;min-height:0;">
|
|
697
|
+
<div class="view-actions">
|
|
698
|
+
<oda-button ~if="selected.box === 'drafts'" icon="editor:mode-edit" info-invert @tap="editDraft(selected)">Продолжить черновик</oda-button>
|
|
699
|
+
<oda-button ~if="selected.box !== 'drafts'" icon="icons:reply" @tap="reply(false)">Ответить</oda-button>
|
|
700
|
+
<oda-button ~if="selected.box !== 'drafts' && (selected.cc || (selected.to || '').includes(','))" icon="icons:reply-all" @tap="reply(true)">Ответить всем</oda-button>
|
|
701
|
+
<oda-button icon="icons:forward" @tap="forward()">Переслать</oda-button>
|
|
702
|
+
<oda-button ~if="selected.box === 'inbox'" :icon="selected.read ? 'icons:markunread' : 'icons:drafts'" @tap="toggleRead(selected)">
|
|
703
|
+
{{selected.read ? 'Непрочитано' : 'Прочитано'}}
|
|
704
|
+
</oda-button>
|
|
705
|
+
<div style="flex:1;"></div>
|
|
706
|
+
<oda-button ~if="selected.box !== 'trash'" icon="icons:delete" @tap="moveToTrash(selected)">В корзину</oda-button>
|
|
707
|
+
<oda-button ~if="selected.box === 'trash'" icon="icons:restore" @tap="restoreFromTrash(selected)">Восстановить</oda-button>
|
|
708
|
+
<oda-button ~if="selected.box === 'trash'" icon="icons:delete-forever" error @tap="deleteForever(selected)">Удалить навсегда</oda-button>
|
|
709
|
+
</div>
|
|
710
|
+
|
|
711
|
+
<div class="view-head">
|
|
712
|
+
<div class="view-subject">{{selected.subject || '(без темы)'}}</div>
|
|
713
|
+
<div class="view-meta"><b>От:</b> {{selected.from || '—'}} · <b>Дата:</b> {{fullDate(selected.date)}}</div>
|
|
714
|
+
<div class="view-meta"><b>Кому:</b> {{selected.to || '—'}} <span ~if="selected.cc">· <b>Копия:</b> {{selected.cc}}</span></div>
|
|
715
|
+
<div ~if="selected.error" style="font-size:12.5px;color:#dc2626;font-weight:600;">Ошибка доставки: {{selected.error}}</div>
|
|
716
|
+
</div>
|
|
717
|
+
|
|
718
|
+
<div ~if="selected.attachments?.length" class="att-bar">
|
|
719
|
+
<div ~for="selected.attachments" class="att-chip" @tap="openAttachment($for.item)">
|
|
720
|
+
<oda-icon icon="editor:attach-file" icon-size="14"></oda-icon>
|
|
721
|
+
<span>{{$for.item.name || 'Вложение'}}</span>
|
|
722
|
+
</div>
|
|
723
|
+
</div>
|
|
724
|
+
|
|
725
|
+
<iframe ~if="selected.html" class="view-iframe" sandbox="allow-popups allow-popups-to-escape-sandbox" :srcdoc="htmlDoc"></iframe>
|
|
726
|
+
<div ~if="!selected.html" class="view-body">{{selected.body || ''}}</div>
|
|
727
|
+
</div>
|
|
728
|
+
|
|
729
|
+
<div ~if="mode === 'compose'" class="compose-wrap">
|
|
730
|
+
<div style="display:flex;align-items:center;justify-content:space-between;">
|
|
731
|
+
<span style="font-size:15px;font-weight:700;">{{draft.uid ? 'Редактирование черновика' : 'Новое письмо'}}</span>
|
|
732
|
+
</div>
|
|
733
|
+
|
|
734
|
+
<div class="compose-field">
|
|
735
|
+
<label>От:</label>
|
|
736
|
+
<select @change="draft.from = $event.target.value">
|
|
737
|
+
<option ~for="accounts" :value="$for.item.address" :selected="$for.item.address === draft.from">{{$for.item.address}}</option>
|
|
738
|
+
</select>
|
|
739
|
+
</div>
|
|
740
|
+
<div class="compose-field">
|
|
741
|
+
<label>Кому:</label>
|
|
742
|
+
<input placeholder="recipient@example.com" :value="draft.to" @input="draft.to = $event.target.value">
|
|
743
|
+
</div>
|
|
744
|
+
<div class="compose-field">
|
|
745
|
+
<label>Копия:</label>
|
|
746
|
+
<input placeholder="cc@example.com (необязательно)" :value="draft.cc" @input="draft.cc = $event.target.value">
|
|
747
|
+
</div>
|
|
748
|
+
<div class="compose-field">
|
|
749
|
+
<label>Тема:</label>
|
|
750
|
+
<input placeholder="Тема письма" :value="draft.subject" @input="draft.subject = $event.target.value">
|
|
751
|
+
</div>
|
|
752
|
+
|
|
753
|
+
<div class="att-bar" style="padding:6px 0;border:none;background:transparent;" ~if="draft.attachments?.length">
|
|
754
|
+
<div ~for="draft.attachments" class="att-chip">
|
|
755
|
+
<oda-icon icon="editor:attach-file" icon-size="14"></oda-icon>
|
|
756
|
+
<span>{{$for.item.name}}</span>
|
|
757
|
+
<oda-icon icon="icons:close" icon-size="13" style="cursor:pointer;" @tap.stop="removeDraftAttachment($for.index)"></oda-icon>
|
|
758
|
+
</div>
|
|
759
|
+
</div>
|
|
760
|
+
|
|
761
|
+
<textarea class="compose-body" placeholder="Текст письма…" :value="draft.body" @input="draft.body = $event.target.value"></textarea>
|
|
762
|
+
|
|
763
|
+
<div class="compose-footer">
|
|
764
|
+
<oda-button icon="icons:send" info-invert @tap="sendDraft()">Отправить</oda-button>
|
|
765
|
+
<oda-button icon="icons:save" @tap="saveDraft()">Сохранить черновик</oda-button>
|
|
766
|
+
<label class="icon-btn" style="cursor:pointer;">
|
|
767
|
+
<oda-icon icon="editor:attach-file" icon-size="15"></oda-icon>
|
|
768
|
+
<span>Прикрепить</span>
|
|
769
|
+
<input type="file" multiple hidden @change="onAttachFiles($event)">
|
|
770
|
+
</label>
|
|
771
|
+
<div style="flex:1;"></div>
|
|
772
|
+
<oda-button icon="icons:close" @tap="mode = selected ? 'view' : 'idle'">Отмена</oda-button>
|
|
773
|
+
</div>
|
|
774
|
+
</div>
|
|
775
|
+
</main>
|
|
379
776
|
`,
|
|
380
|
-
$item:
|
|
381
|
-
|
|
777
|
+
$item: {
|
|
778
|
+
$def: null,
|
|
779
|
+
set(n, o) {
|
|
780
|
+
if (o && this._onChanged)
|
|
781
|
+
o.unlisten?.('changed', this._onChanged);
|
|
782
|
+
if (n) {
|
|
783
|
+
this._onChanged ??= () => this.debounce('mail-reload', () => this.reload(), 200);
|
|
784
|
+
n.listen?.('changed', this._onChanged);
|
|
785
|
+
this.initLoad();
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
},
|
|
789
|
+
folders: [
|
|
382
790
|
{ id: 'inbox', label: 'Входящие', icon: 'icons:inbox' },
|
|
791
|
+
{ id: 'drafts', label: 'Черновики', icon: 'editor:insert-drive-file' },
|
|
383
792
|
{ id: 'outbox', label: 'Исходящие', icon: 'iconoir:send-mail' },
|
|
384
793
|
{ id: 'trash', label: 'Корзина', icon: 'icons:delete' },
|
|
385
794
|
],
|
|
795
|
+
activeBox: 'inbox',
|
|
796
|
+
selectedAccount: '',
|
|
797
|
+
searchQuery: '',
|
|
798
|
+
unreadOnly: false,
|
|
799
|
+
loading: false,
|
|
800
|
+
refreshing: false,
|
|
801
|
+
accounts: [],
|
|
802
|
+
canConfigure: false,
|
|
803
|
+
autoRefresh: true,
|
|
804
|
+
messages: [],
|
|
805
|
+
countsByBox: { inbox: 0, drafts: 0, outbox: 0, trash: 0 },
|
|
806
|
+
unreadByBox: { inbox: 0, drafts: 0, outbox: 0, trash: 0 },
|
|
386
807
|
selected: null,
|
|
387
808
|
mode: 'idle',
|
|
388
809
|
draft: EMPTY_DRAFT(),
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
return this.
|
|
810
|
+
get activeBoxLabel() {
|
|
811
|
+
return this.folders.find(f => f.id === this.activeBox)?.label || 'Входящие';
|
|
812
|
+
},
|
|
813
|
+
get htmlDoc() {
|
|
814
|
+
return htmlDocument(this.selected?.html);
|
|
394
815
|
},
|
|
395
816
|
attached() {
|
|
396
|
-
this.
|
|
397
|
-
|
|
398
|
-
this._watch();
|
|
817
|
+
if (this.$item && this._loadedFor !== this.$item)
|
|
818
|
+
this.initLoad();
|
|
399
819
|
},
|
|
400
820
|
detached() {
|
|
401
|
-
|
|
402
|
-
src?.unlisten?.('changed', this._onChanged);
|
|
403
|
-
this._watched = null;
|
|
821
|
+
this.$item?.unlisten?.('changed', this._onChanged);
|
|
404
822
|
},
|
|
405
|
-
async
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
this.
|
|
409
|
-
|
|
410
|
-
|
|
823
|
+
async initLoad() {
|
|
824
|
+
const cur = this.$item;
|
|
825
|
+
if (!cur) return;
|
|
826
|
+
this._loadedFor = cur;
|
|
827
|
+
this.selected = null;
|
|
828
|
+
this.mode = 'idle';
|
|
829
|
+
await this.loadAccounts();
|
|
830
|
+
await this.reload();
|
|
411
831
|
},
|
|
412
|
-
async
|
|
832
|
+
async loadAccounts() {
|
|
833
|
+
if (!this.$item?.fetch) return;
|
|
413
834
|
try {
|
|
414
|
-
|
|
835
|
+
const res = await this.$item.fetch('mail_accounts');
|
|
836
|
+
this.accounts = Array.isArray(res?.accounts) ? res.accounts : [];
|
|
837
|
+
this.canConfigure = Boolean(res?.canConfigure);
|
|
838
|
+
this.autoRefresh = res?.autoRefresh !== false;
|
|
415
839
|
}
|
|
416
840
|
catch {
|
|
417
|
-
this.
|
|
841
|
+
this.accounts = [];
|
|
842
|
+
this.canConfigure = false;
|
|
418
843
|
}
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
.
|
|
427
|
-
.
|
|
428
|
-
.
|
|
429
|
-
|
|
430
|
-
},
|
|
431
|
-
/** Письма дня (все ящики), одна загрузка на форму; исходящие — последняя версия по uid. */
|
|
432
|
-
dayMessages(day) {
|
|
433
|
-
const cache = this._dayCache ??= new Map();
|
|
434
|
-
if (!cache.has(day)) {
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
cache.set(day, (async () => {
|
|
439
|
-
const rows = await this.$item.logs({ mode: 'bodies', day, ext: 'eml' });
|
|
440
|
-
const seen = new Set();
|
|
441
|
-
const list = [];
|
|
442
|
-
// rows — по убыванию time: первая строка uid — актуальная версия
|
|
443
|
-
for (const row of rows || []) {
|
|
444
|
-
const msg = await rowToMessage(row);
|
|
445
|
-
if (!msg)
|
|
446
|
-
continue;
|
|
447
|
-
const key = msg.uid ? 'uid:' + msg.uid : 'path:' + msg.path;
|
|
448
|
-
if (seen.has(key))
|
|
449
|
-
continue;
|
|
450
|
-
seen.add(key);
|
|
451
|
-
list.push(msg);
|
|
452
|
-
}
|
|
453
|
-
list.sort((a, b) => (b.sortTime || 0) - (a.sortTime || 0));
|
|
454
|
-
return list;
|
|
455
|
-
})().catch(e => {
|
|
456
|
-
console.warn('[email] day', day, e);
|
|
457
|
-
cache.delete(day);
|
|
458
|
-
return [];
|
|
844
|
+
},
|
|
845
|
+
async reload() {
|
|
846
|
+
if (!this.$item?.fetch) return;
|
|
847
|
+
this.loading = true;
|
|
848
|
+
try {
|
|
849
|
+
const res = await this.$item.fetch('mail_list', {}, JSON.stringify({
|
|
850
|
+
box: this.activeBox,
|
|
851
|
+
address: this.selectedAccount,
|
|
852
|
+
q: this.searchQuery,
|
|
853
|
+
unreadOnly: this.unreadOnly,
|
|
854
|
+
limit: 200,
|
|
459
855
|
}));
|
|
856
|
+
this.messages = Array.isArray(res?.messages) ? res.messages : [];
|
|
857
|
+
if (res?.countsByBox) this.countsByBox = res.countsByBox;
|
|
858
|
+
if (res?.unreadByBox) this.unreadByBox = res.unreadByBox;
|
|
859
|
+
}
|
|
860
|
+
catch (e) {
|
|
861
|
+
this.messages = [];
|
|
862
|
+
}
|
|
863
|
+
finally {
|
|
864
|
+
this.loading = false;
|
|
460
865
|
}
|
|
461
|
-
return cache.get(day);
|
|
462
866
|
},
|
|
463
|
-
|
|
464
|
-
this.
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
867
|
+
badgeOf(boxId) {
|
|
868
|
+
return boxId === 'inbox' ? (Number(this.unreadByBox?.[boxId]) || 0) : 0;
|
|
869
|
+
},
|
|
870
|
+
countOf(boxId) {
|
|
871
|
+
return boxId === 'drafts' ? (Number(this.countsByBox?.[boxId]) || 0) : 0;
|
|
872
|
+
},
|
|
873
|
+
peerLabel(msg) {
|
|
874
|
+
if (this.activeBox === 'outbox' || this.activeBox === 'drafts')
|
|
875
|
+
return msg.to || '(без получателя)';
|
|
876
|
+
return msg.from || '(неизвестный отправитель)';
|
|
877
|
+
},
|
|
878
|
+
shortDate(v) { return formatMailShortDate(v); },
|
|
879
|
+
fullDate(v) { return formatMailFullDate(v); },
|
|
880
|
+
selectBox(boxId) {
|
|
881
|
+
this.activeBox = boxId;
|
|
882
|
+
this.selected = null;
|
|
883
|
+
if (this.mode === 'view') this.mode = 'idle';
|
|
884
|
+
this.reload();
|
|
885
|
+
},
|
|
886
|
+
selectAccount(addr) {
|
|
887
|
+
this.selectedAccount = addr || '';
|
|
888
|
+
this.reload();
|
|
889
|
+
},
|
|
890
|
+
onSearchInput(e) {
|
|
891
|
+
this.searchQuery = e.target.value || '';
|
|
892
|
+
this.debounce('mail-search', () => this.reload(), 200);
|
|
893
|
+
},
|
|
894
|
+
toggleUnreadOnly() {
|
|
895
|
+
this.unreadOnly = !this.unreadOnly;
|
|
896
|
+
this.reload();
|
|
468
897
|
},
|
|
469
898
|
async fetchRefresh() {
|
|
899
|
+
if (!this.$item?.fetch || this.refreshing) return;
|
|
900
|
+
this.refreshing = true;
|
|
470
901
|
try {
|
|
471
|
-
await this.$
|
|
902
|
+
await this.$item.fetch('mail_refresh');
|
|
472
903
|
}
|
|
473
904
|
catch (e) {
|
|
474
|
-
ODA.showMessage(e
|
|
905
|
+
ODA.showMessage?.(e?.message || String(e));
|
|
475
906
|
}
|
|
476
|
-
|
|
477
|
-
|
|
907
|
+
finally {
|
|
908
|
+
this.refreshing = false;
|
|
909
|
+
}
|
|
910
|
+
await this.loadAccounts();
|
|
911
|
+
await this.reload();
|
|
478
912
|
},
|
|
479
913
|
async selectMessage(msg) {
|
|
914
|
+
if (!msg?.path || !this.$item?.fetch) return;
|
|
480
915
|
this.selected = msg;
|
|
481
916
|
this.mode = 'view';
|
|
482
|
-
if (msg.body != null)
|
|
483
|
-
return;
|
|
484
917
|
try {
|
|
485
|
-
const
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
}
|
|
918
|
+
const full = await this.$item.fetch('mail_read', {}, JSON.stringify({ path: msg.path, uid: msg.uid, markRead: true }));
|
|
919
|
+
this.selected = full;
|
|
920
|
+
if (!msg.read && full.read) {
|
|
921
|
+
msg.read = true;
|
|
922
|
+
this.messages = [...this.messages];
|
|
923
|
+
if (this.unreadByBox.inbox > 0) {
|
|
924
|
+
this.unreadByBox = { ...this.unreadByBox, inbox: this.unreadByBox.inbox - 1 };
|
|
925
|
+
}
|
|
926
|
+
}
|
|
494
927
|
}
|
|
495
928
|
catch (e) {
|
|
496
|
-
|
|
497
|
-
ODA.showMessage(e.message);
|
|
498
|
-
this.selected = { ...msg, body: e.message, html: '' };
|
|
929
|
+
ODA.showMessage?.(e?.message || String(e));
|
|
499
930
|
}
|
|
500
931
|
},
|
|
501
|
-
async
|
|
932
|
+
async toggleRead(msg) {
|
|
933
|
+
if (!msg?.path || !this.$item?.fetch) return;
|
|
934
|
+
try {
|
|
935
|
+
await this.$item.fetch('mail_state', {}, JSON.stringify({ path: msg.path, uid: msg.uid, read: !msg.read }));
|
|
936
|
+
await this.reload();
|
|
937
|
+
if (this.selected?.path === msg.path)
|
|
938
|
+
this.selected = { ...this.selected, read: !msg.read };
|
|
939
|
+
}
|
|
940
|
+
catch (e) { ODA.showMessage?.(e?.message || String(e)); }
|
|
941
|
+
},
|
|
942
|
+
async moveToTrash(msg) {
|
|
943
|
+
if (!msg?.path || !this.$item?.fetch) return;
|
|
944
|
+
try {
|
|
945
|
+
await this.$item.fetch('mail_state', {}, JSON.stringify({ path: msg.path, uid: msg.uid, box: 'trash' }));
|
|
946
|
+
this.selected = null;
|
|
947
|
+
this.mode = 'idle';
|
|
948
|
+
await this.reload();
|
|
949
|
+
}
|
|
950
|
+
catch (e) { ODA.showMessage?.(e?.message || String(e)); }
|
|
951
|
+
},
|
|
952
|
+
async restoreFromTrash(msg) {
|
|
953
|
+
if (!msg?.path || !this.$item?.fetch) return;
|
|
954
|
+
try {
|
|
955
|
+
await this.$item.fetch('mail_state', {}, JSON.stringify({ path: msg.path, uid: msg.uid, restore: true }));
|
|
956
|
+
this.selected = null;
|
|
957
|
+
this.mode = 'idle';
|
|
958
|
+
await this.reload();
|
|
959
|
+
}
|
|
960
|
+
catch (e) { ODA.showMessage?.(e?.message || String(e)); }
|
|
961
|
+
},
|
|
962
|
+
async deleteForever(msg) {
|
|
963
|
+
if (!msg?.path || !this.$item?.fetch) return;
|
|
964
|
+
try {
|
|
965
|
+
await this.$item.fetch('mail_state', {}, JSON.stringify({ path: msg.path, uid: msg.uid, deletePermanent: true }));
|
|
966
|
+
this.selected = null;
|
|
967
|
+
this.mode = 'idle';
|
|
968
|
+
await this.reload();
|
|
969
|
+
}
|
|
970
|
+
catch (e) { ODA.showMessage?.(e?.message || String(e)); }
|
|
971
|
+
},
|
|
972
|
+
async createEmail(init = {}) {
|
|
502
973
|
if (!this.accounts.length)
|
|
503
|
-
await this.
|
|
974
|
+
await this.loadAccounts();
|
|
504
975
|
if (!this.accounts.length) {
|
|
505
|
-
ODA.showMessage(
|
|
976
|
+
ODA.showMessage?.('Сначала настройте почтовый ящик');
|
|
506
977
|
return;
|
|
507
978
|
}
|
|
508
|
-
this.draft = {
|
|
509
|
-
|
|
979
|
+
this.draft = {
|
|
980
|
+
...EMPTY_DRAFT(),
|
|
981
|
+
from: this.selectedAccount || this.accounts[0]?.address || '',
|
|
982
|
+
...init,
|
|
983
|
+
};
|
|
510
984
|
this.mode = 'compose';
|
|
511
985
|
},
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
986
|
+
editDraft(msg) {
|
|
987
|
+
this.createEmail({
|
|
988
|
+
uid: msg.uid || '',
|
|
989
|
+
origTime: msg.origTime || 0,
|
|
990
|
+
from: msg.address || msg.from || this.accounts[0]?.address || '',
|
|
991
|
+
to: msg.to || '',
|
|
992
|
+
cc: msg.cc || '',
|
|
993
|
+
subject: msg.subject === '(без темы)' ? '' : (msg.subject || ''),
|
|
994
|
+
body: msg.body || '',
|
|
995
|
+
attachments: Array.isArray(msg.attachments) ? [...msg.attachments] : [],
|
|
996
|
+
});
|
|
997
|
+
},
|
|
998
|
+
reply(replyAll = false) {
|
|
518
999
|
const src = this.selected;
|
|
1000
|
+
if (!src) return;
|
|
519
1001
|
const subject = /^re:/i.test(src.subject || '') ? src.subject : 'Re: ' + (src.subject || '');
|
|
520
1002
|
const to = src.box === 'outbox' ? src.to : src.from;
|
|
521
|
-
const from = this.accounts.
|
|
522
|
-
|
|
1003
|
+
const from = this.accounts.some(a => a.address === src.address) ? src.address : undefined;
|
|
1004
|
+
this.createEmail({
|
|
523
1005
|
to,
|
|
1006
|
+
cc: replyAll ? (src.cc || '') : '',
|
|
524
1007
|
subject,
|
|
525
1008
|
body: quoteBody(src),
|
|
526
1009
|
inReplyTo: src.messageId || '',
|
|
527
1010
|
...(from ? { from } : {}),
|
|
528
1011
|
});
|
|
529
1012
|
},
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
const
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
to = validateRecipients(this.draft.to);
|
|
542
|
-
}
|
|
543
|
-
catch (e) {
|
|
544
|
-
ODA.showMessage(e.message);
|
|
545
|
-
return;
|
|
546
|
-
}
|
|
547
|
-
const settings = this._settings || await this.loadSettings();
|
|
548
|
-
const box = settings?.mailboxes?.[address];
|
|
549
|
-
const eml = defaultEmlJson({
|
|
550
|
-
uid: newUid(),
|
|
551
|
-
from: box?.auth?.user || address,
|
|
552
|
-
to,
|
|
553
|
-
subject: this.draft.subject,
|
|
554
|
-
body: this.draft.body,
|
|
555
|
-
address,
|
|
556
|
-
inReplyTo: this.draft.inReplyTo,
|
|
557
|
-
status: 'pending',
|
|
1013
|
+
forward() {
|
|
1014
|
+
const src = this.selected;
|
|
1015
|
+
if (!src) return;
|
|
1016
|
+
const subject = /^fwd?:/i.test(src.subject || '') ? src.subject : 'Fwd: ' + (src.subject || '');
|
|
1017
|
+
const from = this.accounts.some(a => a.address === src.address) ? src.address : undefined;
|
|
1018
|
+
this.createEmail({
|
|
1019
|
+
to: '',
|
|
1020
|
+
subject,
|
|
1021
|
+
body: `\n\n---------- Пересылаемое сообщение ----------\nОт: ${src.from}\nКому: ${src.to}\nТема: ${src.subject}\n\n${src.body || htmlToText(src.html || '')}`,
|
|
1022
|
+
attachments: Array.isArray(src.attachments) ? src.attachments.filter(a => a.path) : [],
|
|
1023
|
+
...(from ? { from } : {}),
|
|
558
1024
|
});
|
|
1025
|
+
},
|
|
1026
|
+
async onAttachFiles(e) {
|
|
1027
|
+
const files = [...(e.target?.files || [])];
|
|
1028
|
+
e.target.value = '';
|
|
1029
|
+
if (!files.length || !this.$item?.save_files) return;
|
|
559
1030
|
try {
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
this.
|
|
566
|
-
|
|
567
|
-
|
|
1031
|
+
const fd = new FormData();
|
|
1032
|
+
for (const f of files)
|
|
1033
|
+
fd.append('file', f, f.name);
|
|
1034
|
+
const saved = await this.$item.save_files(fd, { ignore_save_logs: true });
|
|
1035
|
+
const arr = Array.isArray(saved) ? saved : (saved ? [saved] : []);
|
|
1036
|
+
const nextAtts = [...(this.draft.attachments || [])];
|
|
1037
|
+
for (let i = 0; i < arr.length; i++) {
|
|
1038
|
+
const s = arr[i];
|
|
1039
|
+
const p = s?.path || s?.logFullPath || '';
|
|
1040
|
+
if (p)
|
|
1041
|
+
nextAtts.push({ name: files[i]?.name || p.split('/').pop(), path: p });
|
|
1042
|
+
}
|
|
1043
|
+
this.draft = { ...this.draft, attachments: nextAtts };
|
|
568
1044
|
}
|
|
569
|
-
catch (
|
|
570
|
-
ODA.showMessage(
|
|
1045
|
+
catch (err) {
|
|
1046
|
+
ODA.showMessage?.(err?.message || String(err));
|
|
571
1047
|
}
|
|
572
1048
|
},
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
template: /* html */ `
|
|
578
|
-
<style>
|
|
579
|
-
:host {
|
|
580
|
-
min-width: 240px;
|
|
581
|
-
overflow: hidden;
|
|
582
|
-
border-bottom: 1px solid var(--subtle-border);
|
|
583
|
-
}
|
|
584
|
-
.box-title {
|
|
585
|
-
@apply --header;
|
|
586
|
-
padding: var(--space-m) 12px;
|
|
587
|
-
font-weight: 600;
|
|
588
|
-
font-size: small;
|
|
589
|
-
text-transform: uppercase;
|
|
590
|
-
letter-spacing: .04em;
|
|
591
|
-
}
|
|
592
|
-
.days {
|
|
593
|
-
overflow-y: auto;
|
|
594
|
-
}
|
|
595
|
-
.empty {
|
|
596
|
-
padding: 12px;
|
|
597
|
-
@apply --muted;
|
|
598
|
-
font-size: small;
|
|
599
|
-
}
|
|
600
|
-
</style>
|
|
601
|
-
<div class="box-title">{{box?.label || box?.id}}</div>
|
|
602
|
-
<div class="days" vertical flex>
|
|
603
|
-
<email-day ~for="dates" :day="$for.item" :box-id="box?.id" :first="$for.index === 0"></email-day>
|
|
604
|
-
<div ~if="!dates.length" class="empty">Нет писем</div>
|
|
605
|
-
</div>
|
|
606
|
-
`,
|
|
607
|
-
box: null,
|
|
608
|
-
dates: [],
|
|
609
|
-
// имена реестров разные: $pdp сначала ищет свойство на самом узле
|
|
610
|
-
_dayRegistry() {
|
|
611
|
-
return this._days ??= new Set();
|
|
612
|
-
},
|
|
613
|
-
attached() {
|
|
614
|
-
this.$pdp?._mailboxRegistry?.().add(this);
|
|
615
|
-
this.reload();
|
|
616
|
-
},
|
|
617
|
-
detached() {
|
|
618
|
-
this.$pdp?._mailboxRegistry?.().delete(this);
|
|
619
|
-
},
|
|
620
|
-
async reload() {
|
|
621
|
-
this.dates = await this.$pdp.loadDates();
|
|
622
|
-
for (const day of this._dayRegistry())
|
|
623
|
-
day.reload();
|
|
1049
|
+
removeDraftAttachment(idx) {
|
|
1050
|
+
const next = [...(this.draft.attachments || [])];
|
|
1051
|
+
next.splice(idx, 1);
|
|
1052
|
+
this.draft = { ...this.draft, attachments: next };
|
|
624
1053
|
},
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
:host {
|
|
633
|
-
@apply --vertical;
|
|
634
|
-
@apply --no-flex;
|
|
635
|
-
}
|
|
636
|
-
:host([hidden-day]) {
|
|
637
|
-
display: none;
|
|
638
|
-
}
|
|
639
|
-
.day-header {
|
|
640
|
-
cursor: pointer;
|
|
641
|
-
padding: 6px 10px;
|
|
642
|
-
align-items: center;
|
|
643
|
-
gap: var(--space-s);
|
|
644
|
-
font-size: small;
|
|
645
|
-
}
|
|
646
|
-
/* раскрытый день — цвета плашки --accent-invert, приглушаем только свёрнутые */
|
|
647
|
-
.day-header:not([accent-invert]) {
|
|
648
|
-
@apply --muted;
|
|
649
|
-
}
|
|
650
|
-
.msg-list {
|
|
651
|
-
gap: 2px;
|
|
652
|
-
padding: 0 var(--space-s) 6px;
|
|
653
|
-
}
|
|
654
|
-
.msg-item {
|
|
655
|
-
display: grid;
|
|
656
|
-
grid-template-columns: 1fr auto;
|
|
657
|
-
grid-template-rows: auto auto;
|
|
658
|
-
gap: 2px var(--space-m);
|
|
659
|
-
padding: var(--space-m) 10px;
|
|
660
|
-
cursor: pointer;
|
|
661
|
-
border-radius: var(--radius-s);
|
|
662
|
-
margin: 0 2px;
|
|
663
|
-
}
|
|
664
|
-
.msg-item:not([info-invert]):hover {
|
|
665
|
-
@apply --hover;
|
|
666
|
-
}
|
|
667
|
-
.msg-subject {
|
|
668
|
-
font-weight: 500;
|
|
669
|
-
font-size: small;
|
|
670
|
-
overflow: hidden;
|
|
671
|
-
text-overflow: ellipsis;
|
|
672
|
-
white-space: nowrap;
|
|
673
|
-
min-width: 0;
|
|
674
|
-
}
|
|
675
|
-
.msg-date {
|
|
676
|
-
font-size: x-small;
|
|
677
|
-
@apply --muted;
|
|
678
|
-
white-space: nowrap;
|
|
679
|
-
justify-self: end;
|
|
680
|
-
}
|
|
681
|
-
.msg-from, .msg-to {
|
|
682
|
-
font-size: x-small;
|
|
683
|
-
@apply --muted;
|
|
684
|
-
overflow: hidden;
|
|
685
|
-
text-overflow: ellipsis;
|
|
686
|
-
white-space: nowrap;
|
|
687
|
-
min-width: 0;
|
|
688
|
-
}
|
|
689
|
-
.msg-to {
|
|
690
|
-
justify-self: end;
|
|
691
|
-
text-align: right;
|
|
692
|
-
}
|
|
693
|
-
/* на инвертированной плашке приглушённый цвет темы нечитаем — следуем цвету плашки */
|
|
694
|
-
[info-invert] .msg-date,
|
|
695
|
-
[info-invert] .msg-from,
|
|
696
|
-
[info-invert] .msg-to {
|
|
697
|
-
color: inherit;
|
|
698
|
-
fill: inherit;
|
|
699
|
-
opacity: .75;
|
|
700
|
-
}
|
|
701
|
-
.empty {
|
|
702
|
-
padding: var(--space-s) 12px var(--space-m);
|
|
703
|
-
@apply --muted;
|
|
704
|
-
font-size: x-small;
|
|
705
|
-
}
|
|
706
|
-
</style>
|
|
707
|
-
<div class="day-header" horizontal :accent-invert="expanded" @tap="expanded = !expanded">
|
|
708
|
-
<span flex>{{label}}</span>
|
|
709
|
-
<oda-button icon-size="16" :icon="expanderIcon"></oda-button>
|
|
710
|
-
</div>
|
|
711
|
-
<div class="msg-list" vertical ~if="expanded">
|
|
712
|
-
<div ~for="messages" class="msg-item"
|
|
713
|
-
:info-invert="selectedPath === $for.item.path"
|
|
714
|
-
@tap="$pdp.selectMessage($for.item)">
|
|
715
|
-
<div class="msg-subject">{{$for.item.subject}}</div>
|
|
716
|
-
<div class="msg-date">{{$for.item.status === 'failed' ? 'ошибка' : $for.item.dateLabel}}</div>
|
|
717
|
-
<div class="msg-from">От: {{$for.item.from}}</div>
|
|
718
|
-
<div class="msg-to">Кому: {{$for.item.to}}</div>
|
|
719
|
-
</div>
|
|
720
|
-
<div ~if="loaded && !messages.length" class="empty">Нет писем</div>
|
|
721
|
-
</div>
|
|
722
|
-
`,
|
|
723
|
-
day: '',
|
|
724
|
-
boxId: '',
|
|
725
|
-
messages: [],
|
|
726
|
-
loaded: false,
|
|
727
|
-
first: {
|
|
728
|
-
$def: false,
|
|
729
|
-
set(n) {
|
|
730
|
-
if (n)
|
|
731
|
-
this.expanded = true;
|
|
1054
|
+
async saveDraft() {
|
|
1055
|
+
if (!this.$item?.fetch) return;
|
|
1056
|
+
try {
|
|
1057
|
+
const res = await this.$item.fetch('mail_draft_save', {}, JSON.stringify(this.draft));
|
|
1058
|
+
this.draft = { ...this.draft, uid: res?.uid || this.draft.uid };
|
|
1059
|
+
ODA.showMessage?.('Черновик сохранён');
|
|
1060
|
+
await this.reload();
|
|
732
1061
|
}
|
|
1062
|
+
catch (e) { ODA.showMessage?.(e?.message || String(e)); }
|
|
733
1063
|
},
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
this.
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
},
|
|
748
|
-
get label() {
|
|
749
|
-
const date = new Date(this.day + 'T12:00:00');
|
|
750
|
-
if (Number.isNaN(date.getTime()))
|
|
751
|
-
return this.day;
|
|
752
|
-
return date.toLocaleDateString('ru-RU', {
|
|
753
|
-
weekday: 'short',
|
|
754
|
-
year: 'numeric',
|
|
755
|
-
month: 'long',
|
|
756
|
-
day: 'numeric',
|
|
757
|
-
});
|
|
758
|
-
},
|
|
759
|
-
attached() {
|
|
760
|
-
this.$pdp?._dayRegistry?.().add(this);
|
|
761
|
-
if (this.expanded)
|
|
762
|
-
this.reload();
|
|
763
|
-
},
|
|
764
|
-
detached() {
|
|
765
|
-
this.$pdp?._dayRegistry?.().delete(this);
|
|
1064
|
+
async sendDraft() {
|
|
1065
|
+
if (!this.$item?.fetch) return;
|
|
1066
|
+
try {
|
|
1067
|
+
await this.$item.fetch('mail_send', {}, JSON.stringify({
|
|
1068
|
+
...this.draft,
|
|
1069
|
+
draftUid: this.draft.uid || undefined,
|
|
1070
|
+
}));
|
|
1071
|
+
this.draft = EMPTY_DRAFT();
|
|
1072
|
+
this.mode = 'idle';
|
|
1073
|
+
this.activeBox = 'outbox';
|
|
1074
|
+
await this.reload();
|
|
1075
|
+
}
|
|
1076
|
+
catch (e) { ODA.showMessage?.(e?.message || String(e)); }
|
|
766
1077
|
},
|
|
767
|
-
async
|
|
768
|
-
if (!
|
|
769
|
-
|
|
770
|
-
const day = this.day, boxId = this.boxId;
|
|
771
|
-
const list = await this.$pdp.dayMessages(day);
|
|
772
|
-
if (day !== this.day || boxId !== this.boxId)
|
|
1078
|
+
async openAttachment(att) {
|
|
1079
|
+
if (!att?.path) {
|
|
1080
|
+
ODA.showMessage?.(`Вложение «${att?.name || 'файл'}»`);
|
|
773
1081
|
return;
|
|
774
|
-
|
|
775
|
-
|
|
1082
|
+
}
|
|
1083
|
+
const item = await globalThis.WORK?.get_item?.(att.path).catch(() => null);
|
|
1084
|
+
if (item && typeof window?.execute === 'function')
|
|
1085
|
+
window.execute(item);
|
|
776
1086
|
},
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
<style>
|
|
784
|
-
:host {
|
|
785
|
-
@apply --vertical;
|
|
786
|
-
@apply --flex;
|
|
787
|
-
overflow: hidden;
|
|
788
|
-
padding: 12px var(--space-l);
|
|
789
|
-
gap: var(--space-m);
|
|
790
|
-
}
|
|
791
|
-
fieldset {
|
|
792
|
-
border: 1px solid var(--subtle-border);
|
|
793
|
-
border-radius: var(--radius-s);
|
|
794
|
-
padding: var(--space-s) var(--space-m);
|
|
795
|
-
margin: 0;
|
|
796
|
-
}
|
|
797
|
-
legend {
|
|
798
|
-
font-size: x-small;
|
|
799
|
-
padding: 0 var(--space-s);
|
|
800
|
-
}
|
|
801
|
-
input, textarea, select {
|
|
802
|
-
border: none;
|
|
803
|
-
outline: none;
|
|
804
|
-
background: transparent;
|
|
805
|
-
color: inherit;
|
|
806
|
-
width: 100%;
|
|
807
|
-
box-sizing: border-box;
|
|
808
|
-
font: inherit;
|
|
809
|
-
}
|
|
810
|
-
textarea {
|
|
811
|
-
min-height: 160px;
|
|
812
|
-
resize: vertical;
|
|
813
|
-
}
|
|
814
|
-
.idle {
|
|
815
|
-
align-items: center;
|
|
816
|
-
justify-content: center;
|
|
817
|
-
@apply --muted;
|
|
818
|
-
padding: 24px;
|
|
819
|
-
}
|
|
820
|
-
.msg-meta {
|
|
821
|
-
font-size: small;
|
|
822
|
-
@apply --muted;
|
|
823
|
-
}
|
|
824
|
-
.msg-error {
|
|
825
|
-
font-size: small;
|
|
826
|
-
color: var(--error-color);
|
|
827
|
-
}
|
|
828
|
-
.toolbar {
|
|
829
|
-
gap: var(--space-m);
|
|
830
|
-
align-items: center;
|
|
831
|
-
justify-content: flex-end;
|
|
832
|
-
}
|
|
833
|
-
.view-body {
|
|
834
|
-
white-space: pre-wrap;
|
|
835
|
-
overflow: auto;
|
|
836
|
-
padding: var(--space-m) 0;
|
|
837
|
-
}
|
|
838
|
-
.view-html {
|
|
839
|
-
border: 1px solid var(--subtle-border);
|
|
840
|
-
border-radius: var(--radius-s);
|
|
841
|
-
box-sizing: border-box;
|
|
842
|
-
width: 100%;
|
|
843
|
-
/* намеренно белый в обеих темах: чужая вёрстка писем рассчитана на светлый фон */
|
|
844
|
-
background: white;
|
|
845
|
-
}
|
|
846
|
-
</style>
|
|
847
|
-
<div ~if="mode === 'idle'" class="idle" flex>Выберите письмо</div>
|
|
848
|
-
<div ~if="mode === 'compose'" vertical flex style="gap: 8px;">
|
|
849
|
-
<fieldset>
|
|
850
|
-
<legend>От</legend>
|
|
851
|
-
<select @change="(e) => $pdp.setFrom(e.target.value)">
|
|
852
|
-
<option ~for="accounts" :value="$for.item" :selected="$for.item === draft.from">{{$for.item}}</option>
|
|
853
|
-
</select>
|
|
854
|
-
</fieldset>
|
|
855
|
-
<fieldset>
|
|
856
|
-
<legend>Кому</legend>
|
|
857
|
-
<input placeholder="recipient@example.com" ::value="draft.to">
|
|
858
|
-
</fieldset>
|
|
859
|
-
<fieldset>
|
|
860
|
-
<legend>Тема</legend>
|
|
861
|
-
<input placeholder="Тема письма" ::value="draft.subject">
|
|
862
|
-
</fieldset>
|
|
863
|
-
<fieldset flex vertical>
|
|
864
|
-
<legend>Текст</legend>
|
|
865
|
-
<textarea ::value="draft.body" flex></textarea>
|
|
866
|
-
</fieldset>
|
|
867
|
-
<div class="toolbar" horizontal>
|
|
868
|
-
<oda-button icon="icons:send" @tap="$pdp.sendDraft()" title="Отправить">Отправить</oda-button>
|
|
869
|
-
</div>
|
|
870
|
-
</div>
|
|
871
|
-
<div ~if="mode === 'view' && selected" vertical flex style="gap: 4px;">
|
|
872
|
-
<div horizontal class="toolbar">
|
|
873
|
-
<strong flex>{{selected.subject}}</strong>
|
|
874
|
-
<oda-button icon="icons:reply" @tap="$pdp.reply()" title="Ответить">Ответить</oda-button>
|
|
875
|
-
</div>
|
|
876
|
-
<span class="msg-meta">От: {{selected.from}}</span>
|
|
877
|
-
<span class="msg-meta">Кому: {{selected.to}}</span>
|
|
878
|
-
<span ~if="selected.status" class="msg-meta">Статус: {{statusLabel}}</span>
|
|
879
|
-
<span ~if="selected.error" class="msg-error">{{selected.error}}</span>
|
|
880
|
-
<iframe ~if="selected.html" class="view-html" flex sandbox="allow-popups allow-popups-to-escape-sandbox" :srcdoc="htmlDoc"></iframe>
|
|
881
|
-
<div class="view-body" flex ~if="!selected.html">{{selected.body ?? 'Загрузка…'}}</div>
|
|
882
|
-
</div>
|
|
883
|
-
`,
|
|
884
|
-
// selected / draft / accounts — у формы (через $pdp); свои одноимённые свойства перекрыли бы их
|
|
885
|
-
mode: 'idle',
|
|
886
|
-
get statusLabel() {
|
|
887
|
-
const s = this.$pdp.selected?.status || '';
|
|
888
|
-
return { pending: 'отправляется', sent: 'отправлено', failed: 'ошибка отправки' }[s] || s;
|
|
1087
|
+
async openSettings() {
|
|
1088
|
+
const res = await openEmailSettingsDialog(this.$item);
|
|
1089
|
+
if (res) {
|
|
1090
|
+
await this.loadAccounts();
|
|
1091
|
+
await this.reload();
|
|
1092
|
+
}
|
|
889
1093
|
},
|
|
890
|
-
|
|
891
|
-
|
|
1094
|
+
async toggleAutoRefresh(val) {
|
|
1095
|
+
this.autoRefresh = Boolean(val);
|
|
1096
|
+
try {
|
|
1097
|
+
await this.$item?.save?.({ mailAutoRefresh: this.autoRefresh });
|
|
1098
|
+
}
|
|
1099
|
+
catch { /* ignore */ }
|
|
892
1100
|
},
|
|
893
|
-
}
|
|
1101
|
+
};
|