def _get_email_headers_from_part(self, part, charset=None):
    email_headers = list(part.items())
    if (charset is None):
        charset = part.get_content_charset()
    if (charset is None):
        charset = 'utf8'
    if (not email_headers):
        return {}
    headers = CaseInsensitiveDict()
    try:
        [headers.update({x[0]: self._get_string(x[1], charset)}) for x in email_headers]
    except Exception as e:
        (error_code, error_msg) = self._get_error_message_from_exception(e)
        err = 'Error occurred while converting the header tuple into a dictionary'
        self._base_connector.debug_print('{}. {}. {}'.format(err, error_code, error_msg))
    try:
        received_headers = [self._get_string(x[1], charset) for x in email_headers if (x[0].lower() == 'received')]
    except Exception as e:
        (error_code, error_msg) = self._get_error_message_from_exception(e)
        err = 'Error occurred while handling the received header tuple separately'
        self._base_connector.debug_print('{}. {}. {}'.format(err, error_code, error_msg))
    if received_headers:
        headers['Received'] = received_headers
    subject = headers.get('Subject')
    if subject:
        try:
            headers['decodedSubject'] = str(make_header(decode_header(subject)))
        except Exception:
            headers['decodedSubject'] = self._decode_uni_string(subject, subject)
    return dict(headers)
def _get_email_headers_from_part(self, part, charset=None):
    email_headers = list(part.items())
    if (charset is None):
        charset = part.get_content_charset()
    if (charset is None):
        charset = 'utf8'
    if (not email_headers):
        return {}
    headers = CaseInsensitiveDict()
    try:
        [headers.update({x[0]: self._get_string(x[1], charset)}) for x in email_headers]
    except Exception as e:
        (error_code, error_msg) = self._get_error_message_from_exception(e)
        err = 'Error occurred while converting the header tuple into a dictionary'
        self._base_connector.debug_print('{}. {}. {}'.format(err, error_code, error_msg))
    try:
        received_headers = [self._get_string(x[1], charset) for x in email_headers if (x[0].lower() == 'received')]
    except Exception as e:
        (error_code, error_msg) = self._get_error_message_from_exception(e)
        err = 'Error occurred while handling the received header tuple separately'
        self._base_connector.debug_print('{}. {}. {}'.format(err, error_code, error_msg))
    if received_headers:
        headers['Received'] = received_headers
    subject = headers.get('Subject')
    if subject:
        try:
            headers['decodedSubject'] = str(make_header(decode_header(subject)))
        except Exception:
            headers['decodedSubject'] = self._decode_uni_string(subject, subject)
    return dict(headers)