def dmarc_find_organizational_domain(domain, public_suffix_list):
    """
    Find the organizational domain of the given domain.

    Uses mainly the algorithm found at https://publicsuffix.org/list/ to get
    the organizational domain. Could return "" if none is found.

    """
    # The algorithm could be more elaborate but this is simple and fast enough.
    organizational_domain = ""
    matching_rule = []
    matching_count = 0
    matching_exception = False
    labels = domain.split(".")[::-1]
    for rule, exception in public_suffix_list:
        if matching_exception and not exception:
            continue

        # We always need to have the whole rule available. zip (later) will
        # truncate to the shortest list.
        if len(rule) > len(labels):
            continue

        matched = 0
        for a, b in zip(rule, labels):
            if a in ("*", b):
                matched += 1
            else:
                break

        # The whole rule needs to match.
        if matched == len(rule):
            if exception:
                matching_rule = rule
                matching_count = matched
                matching_exception = exception
            elif matched > matching_count:
                matching_rule = rule
                matching_count = matched

    if matching_rule:
        if matching_exception:
            organizational_domain = ".".join(labels[:len(matching_rule)][::-1])
        elif len(labels) > len(matching_rule):
            organizational_domain = ".".join(labels[:matching_count+1][::-1])
    # Default matching rule is "*"
    elif len(labels) > 1:
        organizational_domain = ".".join(labels[:2][::-1])

    return organizational_domain