summaryrefslogtreecommitdiff
path: root/oi.py
blob: 64dce16ecd34cfe64a5a2629b044a2bcbe62c33b (plain)
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
#!/usr/bin/env python2

# Support offlineimap by retrieving login credentials and doing nametrans

import re, os
from subprocess import check_output

def get_pass_pass(account):
    return check_output("pass " + account, shell=True).splitlines()[0]

def get_authinfo_password(machine, login, port):
    s = "machine %s login %s password ([^ ]*) port %s" % (machine, login, port)
    p = re.compile(s)
    authinfo = os.popen("gpg -q --no-tty -d ~/.authinfo.gpg").read()
    return p.search(authinfo).group(1)

def gmail_remote_to_local(folder):
    new = re.sub('^\[Gmail\]/','',folder)
    if folder == "INBOX": return folder
    elif new == "Sent Mail": return "Sent"
    elif new == "All Mail": return "All"
    return new

def gmail_local_to_remote(folder):
    new = "[Gmail]/" + folder
    if folder == "INBOX": return folder
    elif folder in ["Sent", "All"]: return new + " Mail"
    return new

def jhu_remote_to_local(folder):
    if folder == "Sent Items": return "Sent"
    else: return folder

def jhu_local_to_remote(folder):
    if folder == "Sent": return "Sent Items"
    else: return folder