Skip to content

Instantly share code, notes, and snippets.

@stephenrjohnson
Created April 18, 2013 16:55
Show Gist options
  • Save stephenrjohnson/5414336 to your computer and use it in GitHub Desktop.
Save stephenrjohnson/5414336 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import re, commands
def get_keychain_pass(account=None, server=None):
params = {
'security': '/usr/bin/security',
'command': 'find-internet-password',
'account': account,
'server': server
}
command = "%(security)s %(command)s -g -a %(account)s -s %(server)s" % params
outtext = commands.getoutput(command)
return re.match(r'password: "(.*)"', outtext).group(1)
mapping = {'INBOX': 'inbox',
'[Gmail]/All Mail': 'all_mail',
'[Gmail]/Bin': 'bin',
'[Gmail]/Drafts': 'drafts',
'[Gmail]/Important': 'important',
'[Gmail]/Sent Mail': 'sent_mail',
'[Gmail]/Spam': 'spam',
'[Gmail]/Starred': 'starred',
'[Gmail]/Trash': 'trash',
'INBOX.Drafts': 'draft',
'INBOX.Junk': 'junk',
'INBOX.Sent': 'sent',
'INBOX.Trash': 'trashcan'}
r_mapping = {val: key for key, val in mapping.items()}
def nt_remote(folder):
try:
return mapping[folder]
except:
return re.sub(' ', '_', folder).lower()
def nt_local(folder):
try:
return r_mapping[folder]
except:
return re.sub('_', ' ', folder).capitalize()
# folderfilter = exclude(['Label', 'Label', ... ])
def exclude(excludes):
def inner(folder):
try:
excludes.index(folder)
return False
except:
return True
return inner
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment