def _build_filedata_tag(self, sb, item): name = mod_comm.xml_filter_cdata( mod_comm.xml_filter_encoding(item.file_name()), '\t\t') extension = mod_comm.xml_filter_cdata( mod_comm.xml_filter_encoding(item.file_extension()), '\t\t') mimetype = mod_comm.xml_filter_cdata( mod_comm.xml_filter_encoding(item.file_mimetype_name()), '\t\t') mimesubtype = mod_comm.xml_filter_cdata( mod_comm.xml_filter_encoding(item.file_mimesubtype_name()), '\t\t') sb.append( '\n\t\t\t<file-data size="{0}" extracted-chars="{1}">'.format( item.file_size(), item.extracted_chars())) if name != '': sb.append('\n\t\t\t\t<name>{0}</name>'.format(name)) if extension != '': sb.append('\n\t\t\t\t<extension>{0}</extension>'.format(extension)) if mimetype != '': sb.append('\n\t\t\t\t<mime-type>{0}</mime-type>'.format(mimetype)) if mimesubtype != '': sb.append('\n\t\t\t\t<mime-subtype>{0}</mime-subtype>'.format( mimesubtype)) sb.append('\n\t\t\t</file-data>')
def _build_metadata_tag(self, sb, item): sb.append('\n\t\t\t<metadata>') for key in item.metadata(): prop_id = key prop_value = item.metadata()[key] prop_name = self._property.get_name(prop_id) criteria1 = item.is_email( ) and prop_id != mod_prop.PST_BODY_ID and prop_id != mod_prop.PST_HEADER_ID criteria2 = not item.is_email( ) and prop_id != mod_prop.EXTRACTED_TEXT_ID if criteria1 or criteria2: name = mod_comm.xml_filter_element_name( mod_comm.xml_filter_encoding(prop_name)) value = mod_comm.xml_filter_cdata( mod_comm.xml_filter_encoding(prop_value), '\t\t\t\t') if item.redacttype_id() == mod_comm.REDACTTYPE_CONTENT: value = self._redact_text(value) if len(value) > 0: sb.append('\n\t\t\t\t<field name="{0}">{1}</field>'.format( name, value)) sb.append('\n\t\t\t</metadata>')
def _build_pstdata_tag(self, sb, item): pstfolder_name = mod_comm.xml_filter_cdata( mod_comm.xml_filter_encoding(item.pstfolder_name()), '\t\t') sb.append('\n\t\t\t<pst-data type="{0}" '.format(item.psttype_name())) if item.psttype_id( ) != mod_comm.PSTTYPE_ATTACHMENT: #attachments cannot have attachments, any other pstitem can. sb.append('attachments="{0}"'.format(len(item.children()))) sb.append('>') sb.append('\n\t\t\t\t<pst-folder id="{0}">{1}</pst-folder>'.format( item.pstfolder_id(), pstfolder_name)) if item.is_email(): to = mod_comm.xml_filter_cdata( mod_comm.xml_filter_encoding(item.email_to()), '\t\t\t') cc = mod_comm.xml_filter_cdata( mod_comm.xml_filter_encoding(item.email_cc()), '\t\t\t') bcc = mod_comm.xml_filter_cdata( mod_comm.xml_filter_encoding(item.email_bcc()), '\t\t\t') date = mod_comm.xml_filter_cdata( mod_comm.xml_filter_encoding(item.email_date()), '\t\t\t') subject = mod_comm.xml_filter_cdata( mod_comm.xml_filter_encoding(item.pst_subject()), '\t\t\t') if item.redacttype_id() == mod_comm.REDACTTYPE_CONTENT: to = self._redact_text(to) cc = self._redact_text(cc) bcc = self._redact_text(bcc) date = self._redact_text(date) subject = self._redact_text(subject) sb.append('\n\t\t\t\t<email-data ') if item.has_replies(): sb.append('replies="{0}" '.format(len(item.replies()))) if item.is_email_header_generated(): sb.append('header-generated="true" ') sb.append('>') if to != '': sb.append('\n\t\t\t\t\t<email-to>{0}</email-to>'.format(to)) if cc != '': sb.append('\n\t\t\t\t\t<email-cc>{0}</email-cc>'.format(cc)) if bcc != '': sb.append('\n\t\t\t\t\t<email-bcc>{0}</email-bcc>'.format(bcc)) if date != '': sb.append( '\n\t\t\t\t\t<email-date>{0}</email-date>'.format(date)) if subject != '': sb.append( '\n\t\t\t\t\t<email-subject>{0}</email-subject>'.format( subject)) sb.append('\n\t\t\t\t</email-data>') sb.append('\n\t\t\t</pst-data>')
def _build_pstfolder_node(self, sb, src_id, id, children, names, level): tabs = mod_comm.get_tabs(level, '\t') foldername = mod_comm.xml_filter_cdata( mod_comm.xml_filter_encoding(names[id]), '\t\t') itemcount = 0 if id in self._folderitems: itemcount = len(self._folderitems[id]) subfoldercount = 0 if id in children: subfoldercount = len(children[id]) sb.append( '\n{0}<pst_folder id="{1}" items="{2}" subfolders="{3}">'.format( tabs, str(id), itemcount, subfoldercount)) sb.append('\n\t{0}<name>{1}</name>'.format(tabs, foldername)) if subfoldercount > 0: for child_id in children[id]: self._build_pstfolder_node(sb, src_id, child_id, children, names, level + 2) sb.append('\n{0}</pst_folder>'.format(tabs))
def _build_pst_node(self, sb, src_id, id, children, names, level): tabs = mod_comm.get_tabs(level, '\t') foldername = mod_comm.xml_filter_cdata(mod_comm.xml_filter_encoding(names[id]), '\t\t') itemcount = 0 if id in self._folderitems: itemcount = len(self._folderitems[id]) subfoldercount = 0 if id in children: subfoldercount = len(children[id]) sb.append('\n{0}<pst_folder id="{1}" items="{2}" subfolders="{3}">'.format(tabs, str(id), itemcount, subfoldercount)) sb.append('\n\t{0}<name>{1}</name>'.format(tabs, foldername)) if itemcount > 0: sb.append('\n\t{0}<items>'.format(tabs)) items = self._folderitems[id] src_id_str = mod_comm.get_source_dir(src_id) for public_id in items: type = get_type_by_publicid(public_id) sb.append('\n\t\t{0}<!-- id="{1}" type="{2}" -->'.format(tabs, public_id, type)) sb.append('\n\t\t{0}<xi:include href="../meta/{1}/{2}.xml" />'.format(tabs, src_id_str, public_id)) sb.append('\n\t{0}</items>'.format(tabs)) if subfoldercount > 0: sb.append('\n\t{0}<pst_folders>'.format(tabs)) for child_id in children[id]: self._build_pst_node(sb, src_id, child_id, children, names, level + 2) sb.append('\n\t{0}</pst_folders>'.format(tabs)) sb.append('\n{0}</pst_folder>'.format(tabs))