Skip to content

Commit

Permalink
Merge branch 'keyring' of https://github.com/catap/IMAPdedup into cat…
Browse files Browse the repository at this point in the history
…ap-keyring
  • Loading branch information
quentinsf committed Dec 21, 2020
2 parents 6ce0039 + bd1b3e5 commit 53014e5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
5 changes: 5 additions & 0 deletions imapdedup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 53014e5

Please sign in to comment.