mirror of
https://github.com/the-djmaze/snappymail.git
synced 2025-10-25 21:46:26 +08:00
isUnd(*) to native undefined === *
isFunc to native typeof * === 'function'
isObject to native typeof * === 'object'
microtime() to native Date().getTime();
noop to native ()=>{}
noopFalse to native ()=>false
noopTrue to native ()=>true
boolToAjax to native *?'1':'0'
Underscore.js to native
68 lines
1.4 KiB
JavaScript
68 lines
1.4 KiB
JavaScript
import { isNonEmptyArray } from 'Common/Utils';
|
|
import { EmailModel } from 'Model/Email';
|
|
|
|
/**
|
|
* @param {Array.<EmailModel>} emails
|
|
* @param {boolean=} friendlyView = false
|
|
* @param {boolean=} wrapWithLink = false
|
|
* @returns {string}
|
|
*/
|
|
export function emailArrayToString(emails, friendlyView = false, wrapWithLink = false) {
|
|
const result = [];
|
|
if (isNonEmptyArray(emails)) {
|
|
emails.forEach(email => result.push(email.toLine(friendlyView, wrapWithLink)));
|
|
}
|
|
|
|
return result.join(', ');
|
|
}
|
|
|
|
/**
|
|
* @param {Array.<EmailModel>} emails
|
|
* @returns {string}
|
|
*/
|
|
export function emailArrayToStringClear(emails) {
|
|
const result = [];
|
|
if (isNonEmptyArray(emails)) {
|
|
emails.forEach(email => {
|
|
if (email && email.email && email.name) {
|
|
result.push(email.email);
|
|
}
|
|
});
|
|
}
|
|
|
|
return result.join(', ');
|
|
}
|
|
|
|
/**
|
|
* @param {?Array} json
|
|
* @returns {Array.<EmailModel>}
|
|
*/
|
|
export function emailArrayFromJson(json) {
|
|
const result = [];
|
|
if (isNonEmptyArray(json)) {
|
|
json.forEach(email => {
|
|
email = EmailModel.newInstanceFromJson(email);
|
|
if (email) {
|
|
result.push(email);
|
|
}
|
|
});
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* @param {Array.<EmailModel>} inputEmails
|
|
* @param {Object} unic
|
|
* @param {Array} localEmails
|
|
*/
|
|
export function replyHelper(inputEmails, unic, localEmails) {
|
|
if (inputEmails) {
|
|
inputEmails.forEach(email => {
|
|
if (undefined === unic[email.email]) {
|
|
unic[email.email] = true;
|
|
localEmails.push(email);
|
|
}
|
|
});
|
|
}
|
|
}
|