def run(self, func, args=None): if self._file: with open(self._file, "rb") as f: self.eml = message_from_bytes(f.read()) print(bkgrd(white(" File "), "grey_42"), ":", self._file, "\n") if func == self.match_headers: func(args) else: func() else: for entry in scandir(path=self.directory): file_name = entry.name if entry.is_file(): with open(f"{self.directory}{sep}{entry.name}", "rb") as f: self.eml = message_from_bytes(f.read()) print(bkgrd(white(" File "), "grey_42"), ":", file_name, "\n") if func == self.match_headers: func(args) else: func() print()
"--show-receives", action="store_true", help="Show all values for `Received` header") parser.add_argument("-h", "--help", action="store_true", help="Show this help message") args = parser.parse_args() if len(argv) < 2 or args.help: usage() exit(1) if not args.file and not args.directory: print(bkgrd(white("Must provide `-f` or `-d` arguments"), "red")) exit(1) elif args.file: if not exists(args.file) or not isfile(args.file): print( bkgrd( white(f"{args.file} does not exists or is not a file..."), "red")) exit(1) else: email_parser = ParseEmail(_file=args.file) else: if not exists(args.directory) or not isdir(args.directory): print( bkgrd( white(