Webmail: normalize format of addresses in JSON

This commit is contained in:
Francis Lachapelle
2015-06-11 15:40:26 -04:00
parent 5a106e1613
commit df019f515f
6 changed files with 67 additions and 65 deletions
@@ -64,6 +64,21 @@
return path.join('/');
};
/**
* @function $shortAddress
* @memberof Message.prototype
* @desc Format the first address of a specific type with a short description.
* @returns a string of the name or the email of the envelope address type
*/
Message.prototype.$shortAddress = function(type) {
var address = '';
if (this[type] && this[type].length > 0) {
address = this[type][0].name || this[type][0].email || '';
}
return address;
};
/**
* @function $content
* @memberof Message.prototype
@@ -102,9 +117,9 @@
angular.extend(_this, data);
_this.id = _this.$absolutePath();
// Build long representation of email addresses
_.each(['from', 'to', 'cc', 'bcc', 'replyTo'], function(type) {
_.each(_this[type + 'Addresses'], function(data, i) {
if (data.name != data.address)
_.each(['from', 'to', 'cc', 'bcc', 'reply-to'], function(type) {
_.each(_this[type], function(data, i) {
if (data.name && data.name != data.address)
data.full = data.name + ' <' + data.address + '>';
else
data.full = '<' + data.address + '>';