from bs4 import BeautifulSoup


def search_html_part(message):
    """
    Parses the html message using BeautifulSoup and searches for all href
    references. Any links that contain the word 'unsubscribe' are added
    to a list of unsubscribe_links along with sender names and returned

    :param PyzMessage message: email message in html
    """
    html = message.html_part.get_payload().decode(message.html_part.charset)
    soup = BeautifulSoup(html, 'html.parser')

    link_elems = soup.select('a')
    unsubscribe_links = []

    for link in link_elems:
        if 'unsubscribe' in link.text.lower():
            unsubscribe_links.append((link.get('href'),
                                      message.get_address('from')[0]))

    return unsubscribe_links