def oleMetaData(file_path, save=True): now = dt.now() file_name = getFileName(file_path) metadata = "Time: %d/%d/%d %d : %d : %d. Found the following metadata for file %s:\n\n" % ( now.year, now.month, now.day, now.hour, now.minute, now.second, file_name[:-4]) try: ole = OleFileIO(file_path) meta = ole.get_metadata() ole.close() author = meta.author.decode("latin-1") creation_time = meta.create_time.ctime() last_author = meta.last_saved_by.decode("latin-1") last_edit_time = meta.last_saved_time.ctime() last_printed = meta.last_printed.ctime() revisions = meta.revision_number.decode("latin-1") company = meta.company.decode("latin-1") creating_app = meta.creating_application.decode("latin-1") metadata += "Original Author: %s\nCreation Time: %s\nLast Author: %s\n" % (author, creation_time, last_author) \ + "Last Modification Time: %s\nLast Printed at: %s\Total Revisions: %s\n" % (last_edit_time, last_printed, revisions) \ + "Created with: %s\nCompany: %s" % (creating_app, company) try: print(metadata) except UnicodeEncodeError: print( "Console encoding can't decode the result. Enter chcp 65001 in the console and rerun the script." ) if save: file_name = getFileName(file_path) tgt = file_name + ".txt" saveResult(tgt, metadata) except OSError as e1: print("File not supported: %s" % e1) except FileNotFoundError: print("Specified file could not be found")
def __init__( self, path, prefix="", ole=None, filename=None, encoding=None, lazy=False, ): """ :param path: path to the msg file in the system or is the raw msg file. :param prefix: used for extracting embeded msg files inside the main one. Do not set manually unless you know what you are doing. :param filename: optional, the filename to be used by default when saving. :param: extract_attachments: extract data from attachments to message :param lazy: continue with extraction even if an attachment fails """ self.path = path self.filename = filename if ole is None: ole = OleFileIO(path) self.ole = ole self.lazy = lazy # Parse the main props self.prefix = prefix prop_type = constants.TYPE_MESSAGE_EMBED if self.prefix == "": prop_type = constants.TYPE_MESSAGE propdata = self._getStream("__properties_version1.0") self.mainProperties = Properties(propdata, prop_type) # Determine if the message is unicode-style: # PidTagStoreSupportMask self.is_unicode = False if "340D0003" in self.mainProperties: value = self.mainProperties["340D0003"].value self.is_unicode = (value & 0x40000) != 0 self.encoding = encoding # if "66C30003" in self.mainProperties: # # PidTagCodePageId # codepage = self.mainProperties["66C30003"].value # self.encoding = get_encoding(codepage, self.encoding) if self.encoding is None: metadata = ole.get_metadata() self.encoding = get_encoding(metadata.codepage) if "3FFD0003" in self.mainProperties: # PidTagMessageCodepage codepage = self.mainProperties["3FFD0003"].value self.encoding = get_encoding(codepage, self.encoding) if self.encoding is None: self.encoding = self.guessEncoding() log.debug("Message encoding: %s", self.encoding) self.subject = self.getStringField("0037") self.date = self.mainProperties.date