'List email addresses on file for this package, classified by their
relevance to the participant in question. Returns a list of
``(address, classification)`` string tuples, sorted by
classification as follows:
- primary
- verified
- unverified
- unlinked
- other
Emails are alphabetical within each classification.'

def classify_emails_for_participant(self, participant):

    package_emails_by_group = OrderedDict(((PRIMARY, []), (VERIFIED, []), (UNVERIFIED, []), (UNLINKED, []), (OTHER, [])))
    group_by_participant_email = {}
    for email in participant.get_emails():
        if (email.address == participant.email_address):
            group = PRIMARY
        elif email.verified:
            group = VERIFIED
        else:
            group = UNVERIFIED
        group_by_participant_email[email.address] = group
    other_verified = self.db.all(u'\n\n                                                SELECT    address\n                                                        FROM    emails\n                                                    WHERE    verified    is    true\n                                                            AND    participant_id    !=    %s\n                                                            AND    address    =    ANY((SELECT    emails    FROM    packages    WHERE    id=%s)::text[])\n                                        ORDER    BY    address    ASC\n\n                                ', (participant.id, self.id))
    for email in sorted(self.emails):
        group = group_by_participant_email.get(email)
        if (not group):
            group = (OTHER if (email in other_verified) else UNLINKED)
        package_emails_by_group[group].append(email)
    out = []
    for group in package_emails_by_group:
        for email in package_emails_by_group[group]:
            out.append((email, group))
    return out
