################################################################################
# Decoder, email subject & attachments
################################################################################
from email.header import decode_header


def decode(text):
    '''
        Decode any email encoded subjects' and attachments' names
    '''
    result = []
    blacklist = ['\r\n', '\\r\\n', '\\\r\\\n', '\\\\r\\\\n']

    parts = decode_header(text)
    # Iterate over the message parts
    for string, encoding in parts:
        try:
            if encoding:
                string = str(string, encoding)
                # decode to UTF-8
                string = string.encode().decode()
                result.append(string)
                print(string)

            # If there is no ecoding used:
            elif not encoding and type(string) != bytes:
                result.append(str(string))
                print(string)

        # If there is an exception, return the input as it is
        except Exception as error:
            print("ERROR -> ", text, error)
            return text

    # Construct Result
    result = ' '.join(result).strip()
    # Removing Bad Chars
    for badchrs in blacklist:
        result = result.replace(badchrs, '')

    return result

2914f92647f28e6a9c6eb58a9907a69546862d61
<mask token>

<mask token>


def decode(text):
    """
        Decode any email encoded subjects' and attachments' names
    """
    result = []
    blacklist = ['\r\n', '\\r\\n', '\\\r\\\n', '\\\\r\\\\n']
    parts = decode_header(text)
    for string, encoding in parts:
        try:
            if encoding:
                string = str(string, encoding)
                string = string.encode().decode()
                result.append(string)
                print(string)
            elif not encoding and type(string) != bytes:
                result.append(str(string))
                print(string)
        except Exception as error:
            print('ERROR -> ', text, error)
            return text
    result = ' '.join(result).strip()
    for badchrs in blacklist:
        result = result.replace(badchrs, '')
    return result

from email.header import decode_header


def decode(text):
    """
        Decode any email encoded subjects' and attachments' names
    """
    result = []
    blacklist = ['\r\n', '\\r\\n', '\\\r\\\n', '\\\\r\\\\n']
    parts = decode_header(text)
    for string, encoding in parts:
        try:
            if encoding:
                string = str(string, encoding)
                string = string.encode().decode()
                result.append(string)
                print(string)
            elif not encoding and type(string) != bytes:
                result.append(str(string))
                print(string)
        except Exception as error:
            print('ERROR -> ', text, error)
            return text
    result = ' '.join(result).strip()
    for badchrs in blacklist:
        result = result.replace(badchrs, '')
    return result

################################################################################
# Decoder, email subject & attachments
################################################################################
from email.header import decode_header


def decode(text):
    '''
        Decode any email encoded subjects' and attachments' names
    '''
    result = []
    blacklist = ['\r\n', '\\r\\n', '\\\r\\\n', '\\\\r\\\\n']

    parts = decode_header(text)
    # Iterate over the message parts
    for string, encoding in parts:
        try:
            if encoding:
                string = str(string, encoding)
                # decode to UTF-8
                string = string.encode().decode()
                result.append(string)
                print(string)

            # If there is no ecoding used:
            elif not encoding and type(string) != bytes:
                result.append(str(string))
                print(string)

        # If there is an exception, return the input as it is
        except Exception as error:
            print("ERROR -> ", text, error)
            return text

    # Construct Result
    result = ' '.join(result).strip()
    # Removing Bad Chars
    for badchrs in blacklist:
        result = result.replace(badchrs, '')

    return result
