def _handle_mail_object(self, mail, email_id, rfc822_email, tmp_dir, start_time_epoch):
    parsed_mail = OrderedDict()
    tmp_dir = tmp_dir
    if (not os.path.exists(tmp_dir)):
        os.makedirs(tmp_dir)
    extract_attach = self._config[PROC_EMAIL_JSON_EXTRACT_ATTACHMENTS]
    charset = mail.get_content_charset()
    if (charset is None):
        charset = 'utf-8'
    parsed_mail[PROC_EMAIL_JSON_SUBJECT] = mail.get('Subject', '')
    parsed_mail[PROC_EMAIL_JSON_FROM] = mail.get('From', '')
    parsed_mail[PROC_EMAIL_JSON_TO] = mail.get('To', '')
    parsed_mail[PROC_EMAIL_JSON_DATE] = mail.get('Date', '')
    parsed_mail[PROC_EMAIL_JSON_MSG_ID] = mail.get('Message-ID', '')
    parsed_mail[PROC_EMAIL_JSON_FILES] = files = []
    parsed_mail[PROC_EMAIL_JSON_BODIES] = bodies = []
    parsed_mail[PROC_EMAIL_JSON_START_TIME] = start_time_epoch
    parsed_mail[PROC_EMAIL_JSON_EMAIL_HEADERS] = []
    if mail.is_multipart():
        for (i, part) in enumerate(mail.walk()):
            add_email_id = None
            if (i == 0):
                add_email_id = email_id
            self._parse_email_headers(parsed_mail, part, add_email_id=add_email_id)
            self._base_connector.debug_print('part: {0}'.format(part.__dict__))
            self._base_connector.debug_print('part type', type(part))
            if part.is_multipart():
                self.check_and_update_eml(part)
                continue
            try:
                ret_val = self._handle_part(part, i, tmp_dir, extract_attach, parsed_mail)
            except Exception as e:
                self._base_connector.debug_print('ErrorExp in _handle_part # {0}'.format(i), e)
                continue
            if phantom.is_fail(ret_val):
                continue
    else:
        self._parse_email_headers(parsed_mail, mail, add_email_id=email_id)
        file_path = '{0}/part_1.text'.format(tmp_dir)
        with open(file_path, 'wb') as f:
            f.write(mail.get_payload(decode=True))
        bodies.append({'file_path': file_path, 'charset': charset})
        self._add_body_in_email_headers(parsed_mail, file_path, mail.get_content_charset(), 'text/plain')
    container_name = self._get_container_name(parsed_mail, email_id)
    if (container_name is None):
        return phantom.APP_ERROR
    container = {}
    container_data = dict(parsed_mail)
    del container_data[PROC_EMAIL_JSON_EMAIL_HEADERS]
    container.update(_container_common)
    self._container['source_data_identifier'] = email_id
    self._container['name'] = container_name
    self._container['data'] = {'raw_email': rfc822_email}
    parsed_mail[PROC_EMAIL_JSON_IPS] = set()
    parsed_mail[PROC_EMAIL_JSON_HASHES] = set()
    parsed_mail[PROC_EMAIL_JSON_URLS] = set()
    parsed_mail[PROC_EMAIL_JSON_DOMAINS] = set()
    for (i, body) in enumerate(bodies):
        if (not body):
            continue
        try:
            self._handle_body(body, parsed_mail, email_id)
        except Exception as e:
            self._base_connector.debug_print_debug_print('ErrorExp in _handle_body # {0}: {1}'.format(i, str(e)))
            continue
    self._attachments.extend(files)
    self._create_artifacts(parsed_mail)
    return phantom.APP_SUCCESS
def _handle_mail_object(self, mail, email_id, rfc822_email, tmp_dir, start_time_epoch):
    parsed_mail = OrderedDict()
    tmp_dir = tmp_dir
    if (not os.path.exists(tmp_dir)):
        os.makedirs(tmp_dir)
    extract_attach = self._config[PROC_EMAIL_JSON_EXTRACT_ATTACHMENTS]
    charset = mail.get_content_charset()
    if (charset is None):
        charset = 'utf-8'
    parsed_mail[PROC_EMAIL_JSON_SUBJECT] = mail.get('Subject', )
    parsed_mail[PROC_EMAIL_JSON_FROM] = mail.get('From', )
    parsed_mail[PROC_EMAIL_JSON_TO] = mail.get('To', )
    parsed_mail[PROC_EMAIL_JSON_DATE] = mail.get('Date', )
    parsed_mail[PROC_EMAIL_JSON_MSG_ID] = mail.get('Message-ID', )
    parsed_mail[PROC_EMAIL_JSON_FILES] = files = []
    parsed_mail[PROC_EMAIL_JSON_BODIES] = bodies = []
    parsed_mail[PROC_EMAIL_JSON_START_TIME] = start_time_epoch
    parsed_mail[PROC_EMAIL_JSON_EMAIL_HEADERS] = []
    if mail.is_multipart():
        for (i, part) in enumerate(mail.walk()):
            add_email_id = None
            if (i == 0):
                add_email_id = email_id
            self._parse_email_headers(parsed_mail, part, add_email_id=add_email_id)
            self._base_connector.debug_print('part: {0}'.format(part.__dict__))
            self._base_connector.debug_print('part type', type(part))
            if part.is_multipart():
                self.check_and_update_eml(part)
                continue
            try:
                ret_val = self._handle_part(part, i, tmp_dir, extract_attach, parsed_mail)
            except Exception as e:
                self._base_connector.debug_print('ErrorExp in _handle_part # {0}'.format(i), e)
                continue
            if phantom.is_fail(ret_val):
                continue
    else:
        self._parse_email_headers(parsed_mail, mail, add_email_id=email_id)
        file_path = '{0}/part_1.text'.format(tmp_dir)
        with open(file_path, 'wb') as f:
            f.write(mail.get_payload(decode=True))
        bodies.append({'file_path': file_path, 'charset': charset})
        self._add_body_in_email_headers(parsed_mail, file_path, mail.get_content_charset(), 'text/plain')
    container_name = self._get_container_name(parsed_mail, email_id)
    if (container_name is None):
        return phantom.APP_ERROR
    container = {}
    container_data = dict(parsed_mail)
    del container_data[PROC_EMAIL_JSON_EMAIL_HEADERS]
    container.update(_container_common)
    self._container['source_data_identifier'] = email_id
    self._container['name'] = container_name
    self._container['data'] = {'raw_email': rfc822_email}
    parsed_mail[PROC_EMAIL_JSON_IPS] = set()
    parsed_mail[PROC_EMAIL_JSON_HASHES] = set()
    parsed_mail[PROC_EMAIL_JSON_URLS] = set()
    parsed_mail[PROC_EMAIL_JSON_DOMAINS] = set()
    for (i, body) in enumerate(bodies):
        if (not body):
            continue
        try:
            self._handle_body(body, parsed_mail, email_id)
        except Exception as e:
            self._base_connector.debug_print_debug_print('ErrorExp in _handle_body # {0}: {1}'.format(i, str(e)))
            continue
    self._attachments.extend(files)
    self._create_artifacts(parsed_mail)
    return phantom.APP_SUCCESS