snappymail/dev/Helper/Message.js

84 lines
1.8 KiB
JavaScript
Raw Normal View History

2019-07-05 03:19:24 +08:00
import { isNonEmptyArray, isUnd } from 'Common/Utils';
import { EmailModel } from 'Model/Email';
2016-07-07 05:03:30 +08:00
/**
* @param {Array.<EmailModel>} emails
* @param {boolean=} friendlyView = false
* @param {boolean=} wrapWithLink = false
* @returns {string}
*/
export function emailArrayToString(emails, friendlyView = false, wrapWithLink = false) {
2019-07-05 03:19:24 +08:00
let index = 0,
2016-07-16 05:29:42 +08:00
len = 0;
2016-07-07 05:03:30 +08:00
const result = [];
2019-07-05 03:19:24 +08:00
if (isNonEmptyArray(emails)) {
for (len = emails.length; index < len; index++) {
2016-07-07 05:03:30 +08:00
result.push(emails[index].toLine(friendlyView, wrapWithLink));
2016-05-23 01:35:09 +08:00
}
}
2016-07-07 05:03:30 +08:00
return result.join(', ');
}
2016-05-23 01:35:09 +08:00
2016-07-07 05:03:30 +08:00
/**
* @param {Array.<EmailModel>} emails
* @returns {string}
*/
export function emailArrayToStringClear(emails) {
2019-07-05 03:19:24 +08:00
let index = 0,
2016-07-16 05:29:42 +08:00
len = 0;
2016-05-23 01:35:09 +08:00
2016-07-07 05:03:30 +08:00
const result = [];
2019-07-05 03:19:24 +08:00
if (isNonEmptyArray(emails)) {
for (len = emails.length; index < len; index++) {
if (emails[index] && emails[index].email && '' !== emails[index].name) {
2016-07-07 05:03:30 +08:00
result.push(emails[index].email);
2016-05-23 01:35:09 +08:00
}
}
}
2016-07-07 05:03:30 +08:00
return result.join(', ');
}
/**
* @param {?Array} json
* @returns {Array.<EmailModel>}
*/
export function emailArrayFromJson(json) {
2019-07-05 03:19:24 +08:00
let index = 0,
2016-07-16 05:29:42 +08:00
len = 0,
email = null;
2016-05-23 01:35:09 +08:00
2016-07-07 05:03:30 +08:00
const result = [];
2019-07-05 03:19:24 +08:00
if (isNonEmptyArray(json)) {
for (index = 0, len = json.length; index < len; index++) {
2016-07-07 05:03:30 +08:00
email = EmailModel.newInstanceFromJson(json[index]);
2019-07-05 03:19:24 +08:00
if (email) {
2016-07-07 05:03:30 +08:00
result.push(email);
2016-05-23 01:35:09 +08:00
}
}
}
2016-07-07 05:03:30 +08:00
return result;
}
2016-05-23 01:35:09 +08:00
2016-07-07 05:03:30 +08:00
/**
* @param {Array.<EmailModel>} inputEmails
* @param {Object} unic
* @param {Array} localEmails
*/
export function replyHelper(inputEmails, unic, localEmails) {
2019-07-05 03:19:24 +08:00
if (inputEmails && 0 < inputEmails.length) {
2016-07-07 05:03:30 +08:00
let index = 0;
const len = inputEmails.length;
2019-07-05 03:19:24 +08:00
for (; index < len; index++) {
if (isUnd(unic[inputEmails[index].email])) {
2016-07-07 05:03:30 +08:00
unic[inputEmails[index].email] = true;
localEmails.push(inputEmails[index]);
2016-05-23 01:35:09 +08:00
}
}
}
}