rp

simple email tools
git clone https://git.parazyd.org/rp
Log | Files | Refs | README | LICENSE

commit 7feca628c98dada673754d76376ccbb88cf46892
parent f2a21cb47f96678dbebf158b3f602ff75aa933dc
Author: parazyd <parazyd@dyne.org>
Date:   Tue,  5 May 2020 13:02:15 +0200

Allow rpsync to sync specific mailboxes.

Diffstat:
Mbin/rpsync | 33+++++++++++++++------------------
1 file changed, 15 insertions(+), 18 deletions(-)

diff --git a/bin/rpsync b/bin/rpsync @@ -5,12 +5,13 @@ # """ rp module for syncing from a remote IMAP server. """ +from argparse import ArgumentParser from os import getenv from os.path import join -from sys import argv from imaplib import IMAP4, IMAP4_SSL from subprocess import Popen, PIPE from time import time +from sys import exit as die PROFILE = getenv('RPPROFILE') @@ -18,13 +19,6 @@ if not PROFILE: PROFILE = join(getenv('HOME'), '.rp/default') -def usage(): - """ Usage function """ - print('* Usage: %s [-n]' % argv[0]) - print(' -n: dry run') - exit(1) - - def parsecfg(): """ Function for parsing the config file """ cfgmap = {} @@ -69,27 +63,30 @@ def fetchmail(imapctx, mailbox): def main(): """ Main routine """ - if len(argv) > 1 and argv[1] != '-n': - usage() + parser = ArgumentParser(description='rpsync') + parser.add_argument('mbox', type=str, nargs='+', help='Mailbox to sync') + parser.add_argument('-n', action='store_true', help='Dry run') - dryrun = False - if '-n' in argv: - dryrun = True + args = parser.parse_args() + dryrun = args.n config = parsecfg() rhost = config['rnet'].split('!')[1] rport = config['rnet'].split('!')[2] imap = imapconnect(rhost, rport) if not imap: - exit(1) + die(1) - data = imap.login(config['ruser'], config['rpass']) - data = imap.list() + imap.login(config['ruser'], config['rpass']) boxes = [] - for mbox in data[1]: - boxes.append(mbox.split()[2]) + if args.mbox[0] == 'all': + for i in imap.list()[1]: + boxes.append(i.split()[2]) + else: + for i in args.mbox: + boxes.append(i.encode()) hasmail = [] for i in boxes: