mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-29 03:59:21 +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,5 +1,6 @@
|
|||
import { AbstractCollectionModel } from 'Model/AbstractCollection';
|
||||
import { EmailModel } from 'Model/Email';
|
||||
import { EmailModel, addressparser } from 'Model/Email';
|
||||
import { forEachObjectValue } from 'Common/Utils';
|
||||
|
||||
'use strict';
|
||||
|
||||
|
|
@ -13,6 +14,16 @@ export class EmailCollectionModel extends AbstractCollectionModel
|
|||
return super.reviveFromJson(items, email => EmailModel.reviveFromJson(email));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} text
|
||||
* @returns {EmailCollectionModel}
|
||||
*/
|
||||
static fromString(str) {
|
||||
let list = new this();
|
||||
list.fromString(str);
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {boolean=} friendlyView = false
|
||||
* @param {boolean=} wrapWithLink = false
|
||||
|
|
@ -21,4 +32,23 @@ export class EmailCollectionModel extends AbstractCollectionModel
|
|||
toString(friendlyView, wrapWithLink) {
|
||||
return this.map(email => email.toLine(friendlyView, wrapWithLink)).join(', ');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} text
|
||||
*/
|
||||
fromString(str) {
|
||||
if (str) {
|
||||
let items = {}, key;
|
||||
addressparser(str).forEach(item => {
|
||||
item = new EmailModel(item.address, item.name);
|
||||
// Make them unique
|
||||
key = item.email || item.name;
|
||||
if (key && (item.name || !items[key])) {
|
||||
items[key] = item;
|
||||
}
|
||||
});
|
||||
forEachObjectValue(items, item => this.push(item));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue