/// <summary> /// Add name to the block list if it is not already present. /// </summary> /// <param name="name">Name of user to block</param> public void Block(string name) { // ReSharper disable once LoopCanBeConvertedToQuery foreach (RuleGroup ruleGroup in ruleGroups) { if (ruleGroup.rule.Any(rule => rule.property == "Author" && rule.value.ToString() == name)) { return; } } RuleGroup newRuleGroup = new RuleGroup { type = RuleGroupType.Any, title = string.Format(Resources.BlockFrom, name), active = true, actionCode = RuleActionCodes.Unread | RuleActionCodes.Clear, rule = new[] { new Rule { property = "Author", value = name, op = PredicateBuilder.Op.Equals } } }; AddRule(newRuleGroup); FolderCollection.ApplyRules(newRuleGroup); }