def BuildFilterRuleStrings(filter_rules, emails_by_id):
  """Builds strings that represent filter rules.

  Args:
    filter_rules: a list of FilterRule PBs.
    emails_by_id: a dict of {user_id: email, ..} of user_ids in the FilterRules.

  Returns:
    A list of strings each representing a FilterRule.
    eg. "if predicate then consequence"
  """
  rule_strs = []
  for rule in filter_rules:
    cons = ""
    if rule.add_labels:
      cons = 'add label(s): %s' % ', '.join(rule.add_labels)
    elif rule.default_status:
      cons = 'set default status: %s' % rule.default_status
    elif rule.default_owner_id:
      cons = 'set default owner: %s' % emails_by_id.get(
          rule.default_owner_id, 'user not found')
    elif rule.add_cc_ids:
      cons = 'add cc(s): %s' % ', '.join(
        [emails_by_id.get(user_id, 'user not found')
         for user_id in rule.add_cc_ids])
    elif rule.add_notify_addrs:
      cons = 'notify: %s' % ', '.join(rule.add_notify_addrs)

    rule_strs.append('if %s then %s' % (rule.predicate, cons))

  return rule_strs