def METHOD_NAME(db_session, message, namespace_id):
    with db_session.no_autoflush:
        # First create Contact objects for any email addresses that we haven't
        # seen yet. We want to dedupe by canonicalized address, so this part is
        # a bit finicky.
        all_addresses = []
        for field in (
            message.from_addr,
            message.to_addr,
            message.cc_addr,
            message.bcc_addr,
            message.reply_to,
        ):
            # We generally require these attributes to be non-null, but only
            # set them to the default empty list at flush time. So it's better
            # to be safe here.
            if field is not None:
                all_addresses.extend(field)
        if not all_addresses:
            return
        contact_map = _get_contact_map(db_session, namespace_id, all_addresses)
        # Now associate each contact to the message.
        for field_name in ("from_addr", "to_addr", "cc_addr", "bcc_addr", "reply_to"):
            field = getattr(message, field_name)
            if field is None:
                continue
            for name, email_address in field:
                contact = _get_contact_from_map(contact_map, name, email_address)
                if not contact:
                    continue
                message.contacts.append(
                    MessageContactAssociation(contact=contact, field=field_name)
                )