mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-29 20:19:22 +03:00
Improved email address parsing and handling
This commit is contained in:
parent
e8c93a1d0c
commit
33653eae81
7 changed files with 165 additions and 238 deletions
|
|
@ -1,8 +1,29 @@
|
|||
import { doc, createElement, addEventsListeners } from 'Common/Globals';
|
||||
import { EmailModel } from 'Model/Email';
|
||||
import { EmailModel, addressparser } from 'Model/Email';
|
||||
|
||||
const contentType = 'snappymail/emailaddress',
|
||||
getAddressKey = li => li?.emailaddress?.key;
|
||||
getAddressKey = li => li?.emailaddress?.key,
|
||||
|
||||
parseEmailLine = line => addressparser(line).map(item =>
|
||||
(item.name || item.address)
|
||||
? new EmailModel(item.address, item.name) : null
|
||||
).filter(v => v),
|
||||
splitEmailLine = line => {
|
||||
const result = [];
|
||||
let exists = false;
|
||||
addressparser(line).forEach(item => {
|
||||
const address = (item.name || item.address)
|
||||
? new EmailModel(item.address, item.name)
|
||||
: null;
|
||||
|
||||
if (address?.email) {
|
||||
exists = true;
|
||||
}
|
||||
|
||||
result.push(address ? address.toLine() : item.name);
|
||||
});
|
||||
return exists ? result : null;
|
||||
};
|
||||
|
||||
let dragAddress, datalist;
|
||||
|
||||
|
|
@ -154,8 +175,8 @@ export class EmailAddressesComponent {
|
|||
if (val) {
|
||||
const self = this,
|
||||
v = val.trim(),
|
||||
hook = (v && [',', ';', '\n'].includes(v.slice(-1))) ? EmailModel.splitEmailLine(val) : null,
|
||||
values = (hook || [val]).map(value => EmailModel.parseEmailLine(value))
|
||||
hook = (v && [',', ';', '\n'].includes(v.slice(-1))) ? splitEmailLine(val) : null,
|
||||
values = (hook || [val]).map(value => parseEmailLine(value))
|
||||
.flat(Infinity)
|
||||
.map(item => (item.toLine ? [item.toLine(), item] : [item, null]));
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue