-
Notifications
You must be signed in to change notification settings - Fork 1
/
cli.py
63 lines (59 loc) · 1.78 KB
/
cli.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import click
from mailbox import Mailbox
from move import cmd_move
@click.group()
@click.option("--host", "-h", help="IMAP server", required=True)
@click.option("--user", "-u", help="username", required=True)
@click.option("--password", "-p", help="password", required=True, prompt=True, hide_input=True)
@click.option("--debug/--no-debug", default=False)
@click.pass_context
def cli(ctx, host, user, password, debug):
ctx.ensure_object(dict)
ctx.obj["DEBUG"] = debug
mailbox = Mailbox(debug)
mailbox.connect(host, user, password)
ctx.obj["mailbox"] = mailbox
@cli.command()
@click.option(
"--from", "-f", "ffrom",
help="folder from which to move emails",
required=True
)
@click.option("--to", "-t",
help="folder to which to move emails",
required=True
)
@click.pass_context
def move(ctx, ffrom, to):
"""moves emails from one folder to another"""
mailbox = ctx.obj["mailbox"]
cmd_move(mailbox, ffrom, to)
mailbox.disconnect()
@cli.command()
@click.option(
"--source", "-s",
help="folder in which to look for original messages",
default="INBOX",
show_default=True,
)
@click.option(
"--target", "-t",
help="folder in which to look for duplicates (defaults to source)",
default=None,
show_default=False
)
@click.option(
"--dest", "-d",
help="folder into which to dump duplicate messages",
default="Duplicates",
show_default=True
)
def dedup(ctx, source, target, dest):
"""finds and removes duplicate messages"""
if target is None:
target = source
mailbox = ctx.obj["mailbox"]
cmd_dedup(mailbox, source, target, dest)
mailbox.disconnect()
if __name__ == "__main__":
cli(obj={})