Exemple #1
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')
    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
Exemple #2
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')
    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
Exemple #3
0
 def do_cp(self, arg):
     '''Copy 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>'])
Exemple #4
0
 def do_cp(self, arg):
     '''Copy 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>'])
Exemple #5
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()
Exemple #6
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()
Exemple #7
0
    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()
Exemple #8
0
    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()
Exemple #9
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")
    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