-
Notifications
You must be signed in to change notification settings - Fork 3
/
mutt-gnome-keyring-password.py
executable file
·44 lines (39 loc) · 1.36 KB
/
mutt-gnome-keyring-password.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
#!/usr/bin/env python
#
# Use the IMAP password stored in Gnome Keyring in Mutt
#
# Wouter Bolsterlee <[email protected]>, 2010
#
# This helper script writes out a Mutt config line with your IMAP server
# password stored in Gnome keyring (e.g. as saved by Evolution). The output is
# empty if the password was not available. In this case you will be prompted
# for your password by Mutt instead.
#
# Reference this script in your muttrc like this:
#
# set folder = imaps://your.imap.server/
# set imap_user = "yourusername"
# source "~/bin/mutt-gnome-keyring-password.py yourusername your.imap.server imap"|
#
# Note the trailing | character in the last line!
#
# This script was inspired by a similar hack for offlineimap by Ross Burton:
# http://burtonini.com/blog/computers/offlineimap-2008-11-04-20-00
#
import sys
import gobject
import gnomekeyring
try:
user, server, protocol = sys.argv[1:]
except ValueError as e:
print 'Error parsing arguments: %s' % (e,)
print 'Usage: %s USERNAME SERVERNAME PROTOCOL' % (sys.argv[0],)
sys.exit(1)
gobject.set_application_name('Mutt')
try:
q = dict(user=user, server=server, protocol=protocol)
keys = gnomekeyring.find_network_password_sync(**q)
password = keys[0]["password"].replace('"', r'\"')
print 'set imap_pass = "%s"' % (password,)
except (gnomekeyring.NoMatchError, gnomekeyring.IOError), e:
pass