import re


def parse_for_encoding(value):
    """
    Helper function called by Message's __init__
    Try to get an encoding in headers. If it's
    not found, set encoding to UTF-8 and hope for
    the best.
    """
    mo = re.search('charset="(.*?)"', value)
    if mo is None:
        emailEncoding = "UTF-8"
    else:
        emailEncoding = mo.group(1)
    return emailEncoding