import gpg from serenitas.utils.exchange import ExchangeMessage import datetime em = ExchangeMessage() for msg in em.get_msgs( path=["SeleneOps", "Passport"], filters={"last_modification_time": datetime.date.today()}, ): print(msg) for attach in msg.attachments: if attach.name == "Attachment1.pgp": try: with attach.fp as fp: plaintext, result, verify_result = gpg.Context().decrypt( fp.read(), passphrase="Serenitas1" ) with open( f"/home/serenitas/flint/{attach.last_modified_time.strftime('%Y%m%d')}_ISOSEL.csv", "w", ) as csvFile: text = plaintext.decode("utf-8").replace("\t", ",") csvFile.write(text) break except gpg.errors.GPGMEError as e: print(e)