Fix custom mail labels in Sieve filter editor

pull/17/head
Francis Lachapelle 2014-02-14 21:31:32 -05:00
parent 75c8362df8
commit b34c6324cd
4 changed files with 40 additions and 73 deletions

View File

@ -171,11 +171,6 @@ static NSString *sieveScriptName = @"sogo";
@"Junk", @"junk",
@"NotJunk", @"not_junk",
@"\\Seen", @"seen",
@"$Label1", @"label1",
@"$Label2", @"label2",
@"$Label3", @"label3",
@"$Label4", @"label4",
@"$Label5", @"label5",
nil];
[sieveFlags retain];
}
@ -453,8 +448,8 @@ static NSString *sieveScriptName = @"sogo";
- (NSString *) _extractSieveAction: (NSDictionary *) action
{
NSString *sieveAction, *method, *requirement, *argument,
*flag, *mailbox;
NSString *sieveAction, *method, *requirement, *argument, *flag, *mailbox;
NSDictionary *mailLabels;
SOGoDomainDefaults *dd;
sieveAction = nil;
@ -474,6 +469,12 @@ static NSString *sieveScriptName = @"sogo";
if ([method isEqualToString: @"addflag"])
{
flag = [sieveFlags objectForKey: argument];
if (!flag)
{
mailLabels = [[user userDefaults] mailLabelsColors];
if ([mailLabels objectForKey: argument])
flag = argument;
}
if (flag)
sieveAction = [NSString stringWithFormat: @"%@ %@",
method, [flag asSieveQuotedString]];

View File

@ -265,6 +265,7 @@
"To or Cc" = "To or Cc";
"Size (Kb)" = "Size (Kb)";
"Header" = "Header";
"Body" = "Body";
"Flag the message with:" = "Flag the message with:";
"Discard the message" = "Discard the message";
"File the message in:" = "File the message in:";

View File

@ -1247,7 +1247,7 @@ static NSArray *reminderValues = nil;
{
NSDictionary *v;
v = [[[context activeUser] userDefaults] mailLabelsColors];
v = [[[context activeUser] userDefaults] mailLabelsColors];
ASSIGN(mailLabels, [SOGoMailLabel labelsFromDefaults: v component: self]);
}

View File

@ -92,7 +92,6 @@ function setupConstants() {
"junk": _("Junk"),
"not_junk": _("Not Junk") };
for (var name in mailTags) {
flagLabels[name] = _( mailTags[name][0] );
}
@ -101,46 +100,33 @@ function setupConstants() {
function setupEventHandlers() {
var filterName = $($("mainForm").filterName);
if (filterName) {
var boundCB = onFilterNameChange
.bindAsEventListener(filterName);
filterName.observe("change", boundCB);
filterName.on('change', onFilterNameChange);
}
var matchTypeSelect = $("matchType");
if (matchTypeSelect) {
var boundCB = onMatchTypeChange
.bindAsEventListener(matchTypeSelect);
matchTypeSelect.observe("change", boundCB);
matchTypeSelect.on('change', onMatchTypeChange);
}
var filterRules = $("filterRules");
var boundCB = onFilterRulesDivClick
.bindAsEventListener(filterRules);
filterRules.observe("click", boundCB);
// Filter rules
$("filterRules").on('click', onFilterRulesDivClick);
var ruleAdd = $("ruleAdd");
if (ruleAdd) {
var boundCB = onRuleAddClick.bindAsEventListener(ruleAdd);
ruleAdd.observe("click", boundCB);
ruleAdd.on('click', onRuleAddClick);
}
var ruleDelete = $("ruleDelete");
if (ruleDelete) {
var boundCB = onRuleDeleteClick.bindAsEventListener(ruleDelete);
ruleDelete.observe("click", boundCB);
ruleDelete.on('click', onRuleDeleteClick);
}
var filterActions = $("filterActions");
var boundCB = onFilterActionsDivClick
.bindAsEventListener(filterActions);
filterActions.observe("click", boundCB);
// Filter actions
$('filterActions').on('click', onFilterActionsDivClick);
var actionAdd = $("actionAdd");
if (actionAdd) {
var boundCB = onActionAddClick.bindAsEventListener(actionAdd);
actionAdd.observe("click", boundCB);
actionAdd.on('click', onActionAddClick);
}
var actionDelete = $("actionDelete");
if (actionDelete) {
var boundCB = onActionDeleteClick
.bindAsEventListener(actionDelete);
actionDelete.observe("click", boundCB);
actionDelete.on('click', onActionDeleteClick);
}
}
@ -228,8 +214,7 @@ function appendRule(container, rule) {
var ruleDiv = createElement("div", null, "rule",
{ rule: rule }, null,
container);
var boundCB = onRuleDivClick.bindAsEventListener(ruleDiv);
ruleDiv.observe("click", boundCB);
ruleDiv.on('click', onRuleDivClick);
ensureRuleRepresentation(ruleDiv);
return ruleDiv;
@ -284,14 +269,12 @@ function ensureFieldSelectRepresentation(container, fieldSpan) {
else {
select = createElement("select");
select.rule = container.rule;
var boundCB = onFieldSelectChange.bindAsEventListener(select);
select.observe("change", boundCB);
select.on('change', onFieldSelectChange);
for (var i = 0; i < fields.length; i++) {
var field = fields[i];
var fieldOption = createElement("option", null, null,
{ value: field }, null, select);
fieldOption.appendChild(document
.createTextNode(fieldLabels[field]));
fieldOption.appendChild(document.createTextNode(fieldLabels[field]));
}
fieldSpan.appendChild(select);
}
@ -322,9 +305,7 @@ function ensureFieldCustomHeaderRepresentation(container, fieldSpan) {
if (!container.rule.custom_header)
container.rule.custom_header = "";
headerInput.value = container.rule.custom_header;
var boundCB
= onFieldCustomHeaderChange.bindAsEventListener(headerInput);
headerInput.observe("change", boundCB);
headerInput.on('change', onFieldCustomHeaderChange);
headerInput.focus();
}
} else {
@ -369,8 +350,7 @@ function ensureOperatorSelectRepresentation(container, operatorSpan) {
select = createElement("select");
select.rule = container.rule;
select.sizeOperator = (ruleField == "size");
var boundCB = onOperatorSelectChange.bindAsEventListener(select);
select.observe("change", boundCB);
select.on('change', onOperatorSelectChange);
for (var i = 0; i < operators.length; i++) {
var operator = operators[i];
var operatorOption = createElement("option", null, null,
@ -438,8 +418,7 @@ function ensureValueInputRepresentation(container, valueSpan) {
else {
input = createElement("input", null, "textField");
input.rule = container.rule;
var boundCB = onValueInputChange.bindAsEventListener(input);
input.observe("change", boundCB);
input.on('change', onValueInputChange);
valueSpan.appendChild(input);
}
input.value = container.rule.value;
@ -488,8 +467,7 @@ function appendAction(container, action) {
var actionDiv = createElement("div", null, "action",
{ action: action }, null,
container);
var boundCB = onActionDivClick.bindAsEventListener(actionDiv);
actionDiv.observe("click", boundCB);
actionDiv.on('click', onActionDivClick);
ensureActionRepresentation(actionDiv);
return actionDiv;
@ -557,14 +535,12 @@ function ensureMethodSelectRepresentation(container, methodSpan) {
else {
select = createElement("select");
select.action = container.action;
var boundCB = onMethodSelectChange.bindAsEventListener(select);
select.observe("change", boundCB);
select.on('change', onMethodSelectChange);
for (var i = 0; i < methods.length; i++) {
var method = methods[i];
var methodOption = createElement("option", null, null,
{ value: method }, null, select);
methodOption.appendChild(document
.createTextNode(methodLabels[method]));
methodOption.appendChild(document.createTextNode(methodLabels[method]));
}
methodSpan.appendChild(select);
}
@ -612,12 +588,6 @@ function ensureArgumentRepresentation(container) {
}
function ensureFlagArgRepresentation(container, argumentSpan) {
var flags = [ "seen", "deleted", "answered", "flagged", "junk",
"not_junk" ];
for (var i = 1; i < 6; i++) {
flags.push("label" + i);
}
var selects = argumentSpan.select("SELECT");
var select;
if (selects.length)
@ -625,14 +595,14 @@ function ensureFlagArgRepresentation(container, argumentSpan) {
else {
select = createElement("select");
select.action = container.action;
var boundCB = onFlagArgumentSelectChange.bindAsEventListener(select);
select.observe("change", boundCB);
for (var i = 0; i < flags.length; i++) {
var flag = flags[i];
var flagOption = createElement("option", null, null,
{ value: flag }, null, select);
var label = flagLabels[flag];
flagOption.appendChild(document.createTextNode(label));
select.on('change', onFlagArgumentSelectChange);
for (var flag in flagLabels) {
if (typeof flag != 'undefined') {
var flagOption = createElement("option", null, null,
{ value: flag }, null, select);
var label = flagLabels[flag];
flagOption.appendChild(document.createTextNode(label));
}
}
argumentSpan.appendChild(select);
}
@ -659,8 +629,7 @@ function ensureMailboxArgRepresentation(container, argumentSpan) {
select.action = container.action;
if (!container.action.argument)
container.action.argument = "INBOX";
var boundCB = onMailboxArgumentSelectChange.bindAsEventListener(select);
select.observe("change", boundCB);
select.on('change', onMailboxArgumentSelectChange);
var mailboxes = (window.opener
? window.opener.userMailboxes
: {'displayName': 'INBOX', 'path': 'INBOX' });
@ -692,9 +661,7 @@ function ensureRedirectArgRepresentation(container, argumentSpan) {
emailInput.action = container.action;
if (!container.action.argument)
container.action.argument = "";
var boundCB
= onEmailArgumentChange.bindAsEventListener(emailInput);
emailInput.observe("change", boundCB);
emailInput.on('change', onEmailArgumentChange);
emailInput.focus();
}
emailInput.value = container.action.argument;
@ -716,9 +683,7 @@ function ensureRejectArgRepresentation(container, argumentSpan) {
argumentSpan);
if (!container.action.argument)
container.action.argument = "";
var boundCB
= onMsgArgumentChange.bindAsEventListener(msgArea);
msgArea.observe("change", boundCB);
msgArea.on('change', onMsgArgumentChange);
msgArea.focus();
}
msgArea.value = container.action.argument;