def recipients(preferences, message, valid_paths, config):
rule_cache = dict()<EOL>results = defaultdict(list)<EOL>notified = set()<EOL>for preference in preferences:<EOL><INDENT>user = preference['<STR_LIT:user>']<EOL>context = preference['<STR_LIT>']<EOL>if (user['<STR_LIT>'], context['<STR_LIT:name>']) in notified:<EOL><INDENT>continue<EOL><DEDENT>for filter in preference['<STR_LIT>']:<EOL><INDENT>if matches(filter, message, valid_paths, rule_cache, config):<EOL><INDENT>for detail_value in preference['<STR_LIT>']:<EOL><INDENT>results[context['<STR_LIT:name>']].append({<EOL>'<STR_LIT:user>': user['<STR_LIT>'],<EOL>context['<STR_LIT>']: detail_value,<EOL>'<STR_LIT>': filter['<STR_LIT:name>'],<EOL>'<STR_LIT>': filter['<STR_LIT:id>'],<EOL>'<STR_LIT>': filter['<STR_LIT>'],<EOL>'<STR_LIT>': preference['<STR_LIT>'],<EOL>'<STR_LIT>': preference['<STR_LIT>'],<EOL>'<STR_LIT>': preference['<STR_LIT>'],<EOL>'<STR_LIT>': preference['<STR_LIT>'],<EOL>})<EOL><DEDENT>notified.add((user['<STR_LIT>'], context['<STR_LIT:name>']))<EOL>break<EOL><DEDENT><DEDENT><DEDENT>return results<EOL>
The main API function.

    Accepts a fedmsg message as an argument.

    Returns a dict mapping context names to lists of recipients.