Skip to content

Commit

Permalink
(js) Fix mail filters with flags prefixed with $
Browse files Browse the repository at this point in the history
Fixes #4461
  • Loading branch information
cgx committed May 15, 2018
1 parent 31d7926 commit 6581242
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 18 deletions.
7 changes: 4 additions & 3 deletions UI/Templates/MailerUI/UIxMailViewTemplate.wox
Expand Up @@ -78,7 +78,7 @@
<md-menu-content width="4">
<md-menu-item ng-hide="viewer.showFlags">
<md-button label:aria-label="Add a tag"
ng-click="viewer.addFlags()">
ng-click="viewer.addFlags($event)">
<var:string label:value="Add a tag"/>
</md-button>
</md-menu-item>
Expand Down Expand Up @@ -179,10 +179,11 @@
</div>
</div>
</div>
<div class="sg-padded hide-xs" ng-show="viewer.showFlags">
<div class="sg-padded" ng-show="viewer.showFlags">
<md-chips class="sg-readonly"
sg-focus-on="flags"
ng-model="viewer.message.flags">
ng-model="viewer.message.flags"
md-transform-chip="$chip.name">
<md-chip-template>
<span class="sg-chip-color">
<span ng-style="{ 'background-color': viewer.service.$tags[$chip][1] }"><!-- color --></span>
Expand Down
18 changes: 10 additions & 8 deletions UI/WebServerResources/js/Mailer/Mailbox.service.js
Expand Up @@ -321,10 +321,10 @@
* @function $filter
* @memberof Mailbox.prototype
* @desc Fetch the messages metadata of the mailbox
* @param {object} [sort] - sort preferences. Defaults to descendent by date.
* @param {string} sort.match - either AND or OR
* @param {string} sort.sort - either arrival, subject, from, to, date, or size
* @param {boolean} sort.asc - sort is ascendant if true
* @param {object} [sortsortingAttributes] - sort preferences. Defaults to descendent by date.
* @param {string} sortingAttributes.match - either AND or OR
* @param {string} sortingAttributes.sort - either arrival, subject, from, to, date, or size
* @param {boolean} sortingAttributes.asc - sort is ascendant if true
* @param {object[]} [filters] - list of filters for the query
* @param {string} filters.searchBy - either subject, from, to, cc, or body
* @param {string} filters.searchInput - the search string to match
Expand Down Expand Up @@ -573,6 +573,7 @@
// Update inbox quota
if (data.quotas)
_this.$account.updateQuota(data.quotas);
return true;
});
};

Expand Down Expand Up @@ -917,10 +918,11 @@
// Instanciate Message objects
_.reduce(_this.uids, function(msgs, msg, i) {
var data, msgObject;
if (_this.threaded)
if (_this.threaded) {
data = _.zipObject(uids, msg);
else
} else {
data = {uid: msg.toString()};
}

// Build map of UID <=> index
_this.uidsMap[data.uid] = i;
Expand All @@ -939,7 +941,7 @@
_.forEach(_this.headers, function(data) {
var msg = _.zipObject(headers, data),
i = _this.uidsMap[msg.uid.toString()];
_.extend(_this.$messages[i], msg);
_this.$messages[i].init(msg);
});
}
Mailbox.$log.debug('mailbox ' + _this.id + ' ready');
Expand Down Expand Up @@ -976,7 +978,7 @@
messageHeaders = _.zipObject(headers, messageHeaders);
j = _this.uidsMap[messageHeaders.uid.toString()];
if (angular.isDefined(j)) {
_.extend(_this.$messages[j], messageHeaders);
_this.$messages[j].init(messageHeaders);
}
});
}
Expand Down
27 changes: 21 additions & 6 deletions UI/WebServerResources/js/Mailer/Message.service.js
Expand Up @@ -23,8 +23,7 @@
if (typeof futureMessageData.then !== 'function') {
//console.debug(JSON.stringify(futureMessageData, undefined, 2));
if (angular.isUndefined(lazy) || !lazy) {
angular.extend(this, futureMessageData);
this.$formatFullAddresses();
this.init(futureMessageData);
}
this.uid = parseInt(futureMessageData.uid);
}
Expand Down Expand Up @@ -104,6 +103,24 @@
return results;
};

/**
* @function init
* @memberof Message.prototype
* @desc Extend instance with new data and massage some attributes.
* @param {object} data - attributes of message
*/
Message.prototype.init = function(data) {
var _this = this;
angular.extend(this, data);
this.$formatFullAddresses();
this.$loadUnsafeContent = false;
_.forEach(this.flags, function(flag, i) {
if (flag.charAt(0) == '$') {
_this.flags.splice(i, 1,'_' + flag);
}
});
};

/**
* @function $absolutePath
* @memberof Message.prototype
Expand Down Expand Up @@ -458,7 +475,7 @@
var data = {
operation: operation,
msgUIDs: [this.uid],
flags: tag
flags: tag.replace(/^_\$/, '$')
};

if (tag)
Expand Down Expand Up @@ -746,10 +763,8 @@
}
return Message.$timeout(function() {
delete _this.$parts;
angular.extend(_this, data);
_this.$formatFullAddresses();
_this.$loadUnsafeContent = false;
_this.$loaded = Message.STATUS.LOADED;
_this.init(data);
return _this;
});
});
Expand Down
2 changes: 2 additions & 0 deletions UI/WebServerResources/js/Mailer/MessageController.js
Expand Up @@ -177,6 +177,8 @@
}

this.addFlags = function($event) {
$event.stopPropagation();
$event.preventDefault();
this.showFlags = true;
focus("flags");
};
Expand Down
Expand Up @@ -17,7 +17,7 @@
this.timeZonesList = $window.timeZonesList;
this.timeZonesSearchText = '';
this.sieveVariablesCapability = ($window.sieveCapabilities.indexOf('variables') >= 0);
this.mailLabelKeyRE = new RegExp("^[^(){} %*\"\\\\]*$");
this.mailLabelKeyRE = new RegExp(/^(?!^_\$)[^(){} %*\"\\\\]*?$/);


if (sgSettings.activeUser('path').mail) {
Expand Down

0 comments on commit 6581242

Please sign in to comment.