snappymail/dev/Helper/Message.js

69 lines
1.4 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) {
const result = [];
2019-07-05 03:19:24 +08:00
if (isNonEmptyArray(emails)) {
emails.forEach(email => result.push(email.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) {
const result = [];
2019-07-05 03:19:24 +08:00
if (isNonEmptyArray(emails)) {
emails.forEach(email => {
if (email && email.email && email.name) {
result.push(email.email);
2016-05-23 01:35:09 +08:00
}
});
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) {
const result = [];
2019-07-05 03:19:24 +08:00
if (isNonEmptyArray(json)) {
json.forEach(email => {
email = EmailModel.newInstanceFromJson(email);
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-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) {
if (inputEmails) {
inputEmails.forEach(email => {
if (isUnd(unic[email.email])) {
unic[email.email] = true;
localEmails.push(email);
2016-05-23 01:35:09 +08:00
}
});
2016-05-23 01:35:09 +08:00
}
}