diff --git a/README.md b/README.md index ef2a328..276e266 100644 --- a/README.md +++ b/README.md @@ -67,10 +67,14 @@ If you have a hierarchy of folders, you can search recursively within the childr # Specifying the password -If you don't wish to specify a password via a command-line argument, where it could be seen by other users of the system, and you don't want to type it in each time, you have two options: +If you don't wish to specify a password via a command-line argument, where it could be seen by other users of the system, and you don't want to type it in each time, you have three options: * You can put it in an environment variable called IMAPDEDUP_PASSWORD, or -* You can specify it in a wrapper script as described below. +* You can specify it in a wrapper script as described below, or +* You can put it into [keyring](https://pypi.org/project/keyring/). + +The last option required to install [keyring](https://pypi.org/project/keyring/) library and allows to use option `-K` that is specified your system keyring name that will be used to get password for specified account via option `-u`. + # Use with a config file (a wrapper script) diff --git a/imapdedup.py b/imapdedup.py index 4c55c9e..0d74a8f 100755 --- a/imapdedup.py +++ b/imapdedup.py @@ -72,6 +72,7 @@ def get_arguments(args: List[str]) -> Tuple[optparse.Values, List[str]]: parser.add_option("-x", "--ssl", dest="ssl", action="store_true", help="Use SSL") parser.add_option("-X", "--starttls", dest="starttls", action="store_true", help="Require STARTTLS") parser.add_option("-u", "--user", dest="user", help="IMAP user name") + parser.add_option("-K", "--keyring", dest="keyring", help="Keyring name to get password") parser.add_option( "-w", "--password", @@ -158,6 +159,10 @@ def get_arguments(args: List[str]) -> Tuple[optparse.Values, List[str]]: sys.stderr.write("\nError: If you use -m you must also use -c.\n") sys.exit(1) + if options.keyring: + import keyring + options.password = keyring.get_password(options.keyring, options.user) + if not options.password and not options.process: # Read from IMAPDEDUP_PASSWORD env variable, or prompt for one. options.password = os.getenv("IMAPDEDUP_PASSWORD") or getpass.getpass()