Skip to content

Commit

Permalink
feat(mail): filter messages by tags (labels)
Browse files Browse the repository at this point in the history
Fixes #3323
Fixes #3835
Fixes #5338
  • Loading branch information
cgx committed Oct 21, 2021
1 parent 175e380 commit 800e21b
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 9 deletions.
3 changes: 3 additions & 0 deletions UI/MailerUI/English.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@
/* Filter option in messages list */
"Show flagged messages only" = "Show flagged messages only";

/* Aria label for icon of labels */
"Filtered by label" = "Filtered by label";

/* Tree */
"SentFolderName" = "Sent";
"TrashFolderName" = "Trash";
Expand Down
38 changes: 29 additions & 9 deletions UI/MailerUI/UIxMailListActions.m
Original file line number Diff line number Diff line change
Expand Up @@ -424,29 +424,29 @@ - (EOQualifier *) searchQualifier
EOQualifier *qualifier, *notDeleted, *searchQualifier;
WORequest *request;
NSDictionary *sortingAttributes, *content, *filter;
NSArray *filters;
NSString *searchBy, *searchInput, *searchString, *match;
NSMutableArray *qualifiers, *searchArray;
NSArray *filters, *labels;
NSString *searchBy, *searchInput, *searchString, *match, *label;
NSMutableArray *qualifiers, *searchArray, *labelQualifiers;
BOOL unseenOnly, flaggedOnly;
int nbFilters, i;
int max, i;

request = [context request];
content = [[request contentAsString] objectFromJSONString];
notDeleted = [EOQualifier qualifierWithQualifierFormat: @"(not (flags = %@))", @"deleted"];
qualifier = nil;
qualifiers = [NSMutableArray arrayWithObject: notDeleted];
searchString = nil;
match = nil;
filters = [content objectForKey: @"filters"];
labels = [content objectForKey: @"labels"];
unseenOnly = [[content objectForKey: @"unseenOnly"] boolValue];
flaggedOnly = [[content objectForKey: @"flaggedOnly"] boolValue];

if (filters)
{
nbFilters = [filters count];
if (nbFilters > 0) {
searchArray = [NSMutableArray arrayWithCapacity: nbFilters];
for (i = 0; i < nbFilters; i++)
max = [filters count];
if (max > 0) {
searchArray = [NSMutableArray arrayWithCapacity: max];
for (i = 0; i < max; i++)
{
filter = [filters objectAtIndex:i];
searchBy = [filter objectForKey: @"searchBy"];
Expand Down Expand Up @@ -489,6 +489,26 @@ - (EOQualifier *) searchQualifier
searchQualifier = [EOQualifier qualifierWithQualifierFormat: @"(flags = %@)", @"flagged"];
[qualifiers addObject: searchQualifier];
}
if (labels)
{
max = [labels count];
if (max > 0)
{
labelQualifiers = [NSMutableArray arrayWithCapacity: max];
for (i = 0; i < max; i++)
{
label = [labels objectAtIndex: i];
qualifier = [EOQualifier qualifierWithQualifierFormat: @"(flags = %@)", label];
[labelQualifiers addObject: qualifier];
}
if (max > 1)
{
qualifier = [[EOOrQualifier alloc] initWithQualifierArray: labelQualifiers];
[qualifier autorelease];
}
[qualifiers addObject: qualifier];
}
}

if ([qualifiers count] > 1)
{
Expand Down
15 changes: 15 additions & 0 deletions UI/Templates/MailerUI/UIxMailFolderTemplate.wox
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,20 @@
sg-true-value="1"
sg-false-value="0"> <var:string label:value="Show flagged messages only"/></sg-checkmark>
</md-menu-item>
<md-menu-divider> <!-- divider --></md-menu-divider>
<md-menu-item ng-repeat="label in ::mailbox.selectedFolder.$labels track by label.imapName">
<sg-checkmark
ng-change="mailbox.selectedFolder.$filter(mailbox.service.$query)"
ng-model="mailbox.selectedFolder.$filteredLabels[label.imapName]"
sg-true-value="1"
sg-false-value="0">
<div layout="row" layout-align="start center">
<div class="sg-color-chip"
ng-style="{ backgroundColor: label.color || '#333' }"><!-- color --></div>
{{ label.name || label.imapName }}
</div>
</sg-checkmark>
</md-menu-item>
</md-menu-content>
</md-menu>
<md-menu>
Expand Down Expand Up @@ -302,6 +316,7 @@
<span ng-switch-default="true"><span ng-bind="mailbox.service.selectedFolder.getLength()"><!-- count --></span> <var:string label:value="messages"/></span>
</div>
<div class="md-truncate">
<md-icon label:aria-label="Filtered by label" ng-show="mailbox.selectedFolder.filteredByLabel()">label_outline</md-icon>
<span ng-show="mailbox.selectedFolder.$unseenOnly"><var:string label:value="Unread"/></span>
<span ng-show="mailbox.selectedFolder.$flaggedOnly"><var:string label:value="Flagged"/></span>
<md-icon ng-class="{ 'md-flip': mailbox.ascending() }">sort</md-icon>
Expand Down
29 changes: 29 additions & 0 deletions UI/WebServerResources/js/Mailer/Mailbox.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,12 @@
if (this.$flaggedOnly)
options.flaggedOnly = 1;

var labels = _.filter(_.keys(this.$filteredLabels), function (k) {
return !!_this.$filteredLabels[k];
});
if (labels.length)
options.labels = labels;

// Restart the refresh timer, if needed
if (!Mailbox.$virtualMode) {
var refreshViewCheck = Mailbox.$Preferences.defaults.SOGoRefreshViewCheck;
Expand Down Expand Up @@ -675,6 +681,29 @@
});
};

/**
* @function getLabels
* @memberof Mailbox.prototype
* @desc Fetch the list of labels associated to the mailbox. Use the cached value if available.
* @returns a promise of the HTTP operation
*/
Mailbox.prototype.getLabels = function() {
var _this = this;

if (this.$labels)
return this.$labels;

this.$filteredLabels = {};
return Mailbox.$$resource.fetch(this.id, 'labels').then(function(data) {
_this.$labels = data;
return _this.$labels;
});
};

Mailbox.prototype.filteredByLabel = function() {
return _.includes(this.$filteredLabels, 1);
};

/**
* @function $flagMessages
* @memberof Mailbox.prototype
Expand Down
3 changes: 3 additions & 0 deletions UI/WebServerResources/js/Mailer/MailboxController.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
this.messageDialog = null; // also access from Message controller
this.mode = { search: false, multiple: 0 };

if (!Mailbox.$virtualMode)
this.selectedFolder.getLabels(); // fetch labels from server

_registerHotkeys(hotkeys);

// Expunge mailbox when leaving the Mail module
Expand Down

0 comments on commit 800e21b

Please sign in to comment.