def _handle_part(self, part, part_index, tmp_dir, extract_attach, parsed_mail):
    bodies = parsed_mail[PROC_EMAIL_JSON_BODIES]
    files = parsed_mail[PROC_EMAIL_JSON_FILES]
    file_name = part.get_filename()
    content_disp = part.get('Content-Disposition')
    content_type = part.get('Content-Type')
    content_id = part.get('Content-ID')
    if (file_name is None):
        name = 'part_{0}'.format(part_index)
        extension = '.{0}'.format(part_index)
        if (content_type is not None):
            extension = mimetypes.guess_extension(re.sub(';.*', '', content_type))
        if (content_id is not None):
            name = content_id
        file_name = '{0}{1}'.format(name, extension)
    else:
        try:
            file_name = str(make_header(decode_header(file_name)))
        except Exception:
            file_name = self._decode_uni_string(file_name, file_name)
    file_path = '{0}/{1}_{2}'.format(tmp_dir, part_index, file_name.translate(str.maketrans('', '', ''.join(['<', '>', ' ']))))
    self._base_connector.debug_print('file_path: {0}'.format(file_path))
    (status, process_further) = self._handle_if_body(content_disp, content_type, part, bodies, file_path, parsed_mail)
    if (not process_further):
        return phantom.APP_SUCCESS
    if ((content_type is not None) and (content_type.find(PROC_EMAIL_CONTENT_TYPE_MESSAGE) != (- 1))):
        return phantom.APP_SUCCESS
    if extract_attach:
        (_, file_extension) = os.path.splitext(file_name)
        part_payload = part.get_payload(decode=True)
        if (not part_payload):
            return phantom.APP_SUCCESS
        try:
            with open(file_path, 'wb') as f:
                f.write(part_payload)
            files.append({'file_name': file_name, 'file_path': file_path})
        except IOError as e:
            error_msg = str(e)
            if ('File name too long' in error_msg):
                self.write_with_new_filename(tmp_dir, part_payload, file_extension, files, as_byte=False)
            else:
                self._base_connector.debug_print('Failed to write file: {}'.format(e))
    return phantom.APP_SUCCESS
def _handle_part(self, part, part_index, tmp_dir, extract_attach, parsed_mail):
    bodies = parsed_mail[PROC_EMAIL_JSON_BODIES]
    files = parsed_mail[PROC_EMAIL_JSON_FILES]
    file_name = part.get_filename()
    content_disp = part.get('Content-Disposition')
    content_type = part.get('Content-Type')
    content_id = part.get('Content-ID')
    if (file_name is None):
        name = 'part_{0}'.format(part_index)
        extension = '.{0}'.format(part_index)
        if (content_type is not None):
            extension = mimetypes.guess_extension(re.sub(';.*', , content_type))
        if (content_id is not None):
            name = content_id
        file_name = '{0}{1}'.format(name, extension)
    else:
        try:
            file_name = str(make_header(decode_header(file_name)))
        except Exception:
            file_name = self._decode_uni_string(file_name, file_name)
    file_path = '{0}/{1}_{2}'.format(tmp_dir, part_index, file_name.translate(str.maketrans(, , .join(['<', '>', ' ']))))
    self._base_connector.debug_print('file_path: {0}'.format(file_path))
    (status, process_further) = self._handle_if_body(content_disp, content_type, part, bodies, file_path, parsed_mail)
    if (not process_further):
        return phantom.APP_SUCCESS
    if ((content_type is not None) and (content_type.find(PROC_EMAIL_CONTENT_TYPE_MESSAGE) != (- 1))):
        return phantom.APP_SUCCESS
    if extract_attach:
        (_, file_extension) = os.path.splitext(file_name)
        part_payload = part.get_payload(decode=True)
        if (not part_payload):
            return phantom.APP_SUCCESS
        try:
            with open(file_path, 'wb') as f:
                f.write(part_payload)
            files.append({'file_name': file_name, 'file_path': file_path})
        except IOError as e:
            error_msg = str(e)
            if ('File name too long' in error_msg):
                self.write_with_new_filename(tmp_dir, part_payload, file_extension, files, as_byte=False)
            else:
                self._base_connector.debug_print('Failed to write file: {}'.format(e))
    return phantom.APP_SUCCESS