def main(): args = docopt.docopt('\n'.join(__doc__.split('\n')[2:]), version=const.VERSION) logging.basicConfig( level=logging.DEBUG if args['--verbose'] else logging.INFO, stream=sys.stdout, ) conf = config.new_context_from_file(args['--config-file'], section='imap') delete_conf = config.new_context_from_file(args['--config-file'], section='trash') if conf is None: return 1 try: imap_account = imap_cli.connect(**conf) imap_cli.change_dir(imap_account, args['--directory'] or const.DEFAULT_DIRECTORY, read_only=False) if delete_conf['delete_method'] == 'MOVE_TO_TRASH': copy.copy(imap_account, args['<mail_id>'], delete_conf['trash_directory']) flag.flag(imap_account, args['<mail_id>'], [const.FLAG_DELETED]) if delete_conf['delete_method'] in ['MOVE_TO_TRASH', 'EXPUNGE']: imap_account.expunge() imap_cli.disconnect(imap_account) except KeyboardInterrupt: log.info('Interrupt by user, exiting') return 0
def main(): args = docopt.docopt('\n'.join(__doc__.split('\n')[2:]), version=const.VERSION) logging.basicConfig( level=logging.DEBUG if args['--verbose'] else logging.INFO, stream=sys.stdout, ) conf = config.new_context_from_file(args['--config-file'], section='imap') if conf is None: return 1 try: imap_account = imap_cli.connect(**conf) imap_cli.change_dir(imap_account, args['--from'] or const.DEFAULT_DIRECTORY, read_only=False) copy(imap_account, args['<mail_id>'], args['<dest>']) if args['--delete']: flag.flag(imap_account, args['<mail_id>'], [const.FLAG_DELETED]) imap_account.expunge() imap_cli.disconnect(imap_account) except KeyboardInterrupt: log.info('Interrupt by user, exiting') return 0
def do_mv(self, arg): '''Move mail from one mailbox to another.''' try: args = docopt.docopt('Usage: cp <dest> <mail_id>...', arg) except SystemExit: return copy.copy(self.imap_account, args['<mail_id>'], args['<dest>']) flag.flag(self.imap_account, args['<mail_id>'], [const.FLAG_DELETED]) self.imap_account.expunge()
def do_rm(self, arg): '''Remove mail from one mailbox.''' try: args = docopt.docopt('Usage: rm <mail_id>...', arg) except SystemExit: return if self.delete_conf['delete_method'] == 'MOVE_TO_TRASH': copy.copy(self.imap_account, args['<mail_id>'], self.delete_conf['trash_directory']) flag.flag(self.imap_account, args['<mail_id>'], [const.FLAG_DELETED]) if self.delete_conf['delete_method'] in ['MOVE_TO_TRASH', 'EXPUNGE']: self.imap_account.expunge()
def do_flag(self, arg): '''Set or Unset flag on mails.''' try: args = docopt.docopt('\n'.join([ 'Usage: flag [options] <mail_id> <flag>', '', 'Options:', ' -u, --unset Remove flag instead of setting them', ' -h, --help Show help options', ]), argv=arg) except SystemExit: return flag.flag(self.imap_account, [args['<mail_id>']], args['<flag>'], unset=args['--unset'])
def main(): args = docopt.docopt("\n".join(__doc__.split("\n")[2:]), version=const.VERSION) logging.basicConfig(level=logging.DEBUG if args["--verbose"] else logging.INFO, stream=sys.stdout) conf = config.new_context_from_file(args["--config-file"], section="imap") delete_conf = config.new_context_from_file(args["--config-file"], section="trash") if conf is None: return 1 try: imap_account = imap_cli.connect(**conf) imap_cli.change_dir(imap_account, args["--directory"] or const.DEFAULT_DIRECTORY, read_only=False) if delete_conf["delete_method"] == "MOVE_TO_TRASH": copy.copy(imap_account, args["<mail_id>"], delete_conf["trash_directory"]) flag.flag(imap_account, args["<mail_id>"], [const.FLAG_DELETED]) if delete_conf["delete_method"] in ["MOVE_TO_TRASH", "EXPUNGE"]: imap_account.expunge() imap_cli.disconnect(imap_account) except KeyboardInterrupt: log.info("Interrupt by user, exiting") return 0