Skip to content

Commit

Permalink
fix(mail(js)): expect the recipient to become a string when saving a …
Browse files Browse the repository at this point in the history
…message
  • Loading branch information
cgx committed Feb 11, 2022
1 parent 10076be commit b252aeb
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions UI/WebServerResources/js/Mailer/Message.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,22 @@
*/
Message.prototype.$shortAddress = function(type) {
var address = '';
if (this[type] && this[type].length > 0) {
address = this[type][0].name || this[type][0].email || '';
if (this[type]) {
if (angular.isString(this[type])) {
// The recipient is a string; try to extract the name
var emailRE = /<?(([\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*[\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+@((((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?))/i;
var match = this[type].match(emailRE);
if (match) {
address = this[type].substring(0, match.index);
address = address.replace(/^\"? *(.+?)\"? *$/, "$1");
}
if (!address.length)
address = this[type];
}
else if (this[type].length > 0) {
// We have an array of objects; pick the first one
address = this[type][0].name || this[type][0].email || '';
}
}

return address;
Expand Down

0 comments on commit b252aeb

Please sign in to comment.