def _add_body_in_email_headers(self, parsed_mail, file_path, charset, content_type):
    email_headers = parsed_mail[PROC_EMAIL_JSON_EMAIL_HEADERS]
    try:
        with open(file_path, 'r') as f:
            body_content = f.read()
    except Exception:
        with open(file_path, 'rb') as f:
            body_content = f.read()
        self._base_connector.debug_print('Reading file data using binary mode')
    body_content = UnicodeDammit(body_content).unicode_markup.encode('utf-8').decode('utf-8')
    if ('text/plain' in content_type):
        try:
            email_headers[(- 1)]['cef']['bodyText'] = self._get_string(body_content, charset)
        except Exception as e:
            try:
                email_headers[(- 1)]['cef']['bodyText'] = str(make_header(decode_header(body_content)))
            except Exception:
                email_headers[(- 1)]['cef']['bodyText'] = self._decode_uni_string(body_content, body_content)
            (error_code, error_msg) = self._get_error_message_from_exception(e)
            err = 'Error occurred while parsing text/plain body content for creating artifacts'
            self._base_connector.debug_print('{}. {}. {}'.format(err, error_code, error_msg))
    elif ('text/html' in content_type):
        try:
            email_headers[(- 1)]['cef']['bodyHtml'] = self._get_string(body_content, charset)
        except Exception as e:
            try:
                email_headers[(- 1)]['cef']['bodyHtml'] = str(make_header(decode_header(body_content)))
            except Exception:
                email_headers[(- 1)]['cef']['bodyHtml'] = self._decode_uni_string(body_content, body_content)
            (error_code, error_msg) = self._get_error_message_from_exception(e)
            err = 'Error occurred while parsing text/html body content for creating artifacts'
            self._base_connector.debug_print('{}. {}. {}'.format(err, error_code, error_msg))
    else:
        if (not email_headers[(- 1)]['cef'].get('bodyOther')):
            email_headers[(- 1)]['cef']['bodyOther'] = {}
        try:
            email_headers[(- 1)]['cef']['bodyOther'][content_type] = self._get_string(body_content, charset)
        except Exception as e:
            try:
                email_headers[(- 1)]['cef']['bodyOther'][content_type] = str(make_header(decode_header(body_content)))
            except Exception:
                email_headers[(- 1)]['cef']['bodyOther'][content_type] = self._decode_uni_string(body_content, body_content)
            (error_code, error_msg) = self._get_error_message_from_exception(e)
            err = 'Error occurred while parsing bodyOther content for creating artifacts'
            self._base_connector.debug_print('{}. {}. {}'.format(err, error_code, error_msg))
def _add_body_in_email_headers(self, parsed_mail, file_path, charset, content_type):
    email_headers = parsed_mail[PROC_EMAIL_JSON_EMAIL_HEADERS]
    try:
        with open(file_path, 'r') as f:
            body_content = f.read()
    except Exception:
        with open(file_path, 'rb') as f:
            body_content = f.read()
        self._base_connector.debug_print('Reading file data using binary mode')
    body_content = UnicodeDammit(body_content).unicode_markup.encode('utf-8').decode('utf-8')
    if ('text/plain' in content_type):
        try:
            email_headers[(- 1)]['cef']['bodyText'] = self._get_string(body_content, charset)
        except Exception as e:
            try:
                email_headers[(- 1)]['cef']['bodyText'] = str(make_header(decode_header(body_content)))
            except Exception:
                email_headers[(- 1)]['cef']['bodyText'] = self._decode_uni_string(body_content, body_content)
            (error_code, error_msg) = self._get_error_message_from_exception(e)
            err = 'Error occurred while parsing text/plain body content for creating artifacts'
            self._base_connector.debug_print('{}. {}. {}'.format(err, error_code, error_msg))
    elif ('text/html' in content_type):
        try:
            email_headers[(- 1)]['cef']['bodyHtml'] = self._get_string(body_content, charset)
        except Exception as e:
            try:
                email_headers[(- 1)]['cef']['bodyHtml'] = str(make_header(decode_header(body_content)))
            except Exception:
                email_headers[(- 1)]['cef']['bodyHtml'] = self._decode_uni_string(body_content, body_content)
            (error_code, error_msg) = self._get_error_message_from_exception(e)
            err = 'Error occurred while parsing text/html body content for creating artifacts'
            self._base_connector.debug_print('{}. {}. {}'.format(err, error_code, error_msg))
    else:
        if (not email_headers[(- 1)]['cef'].get('bodyOther')):
            email_headers[(- 1)]['cef']['bodyOther'] = {}
        try:
            email_headers[(- 1)]['cef']['bodyOther'][content_type] = self._get_string(body_content, charset)
        except Exception as e:
            try:
                email_headers[(- 1)]['cef']['bodyOther'][content_type] = str(make_header(decode_header(body_content)))
            except Exception:
                email_headers[(- 1)]['cef']['bodyOther'][content_type] = self._decode_uni_string(body_content, body_content)
            (error_code, error_msg) = self._get_error_message_from_exception(e)
            err = 'Error occurred while parsing bodyOther content for creating artifacts'
            self._base_connector.debug_print('{}. {}. {}'.format(err, error_code, error_msg))