interpolating account names
nicolas.s-dev at laposte.net
Sat Jan 20 13:47:10 GMT 2018
On Sat, Jan 20, 2018 at 04:04:25PM +0800, Mathias Korber wrote:
> I am trying to set up offlineimap (7.1.5) for severa;gmail accounts.
> I was hoping to use
> # Path to file with arbitrary Python code to be loaded
> pythonfile = ~/.offlineimap/offlineimap.py
> remotepasseval = get_pass(%(account))
> (with the pass tool to look up the password)
> but with that, OI always asks for the password.
> So I am not sure what variable I should interpolate
> (I tried account and accountname)
> I also tried adding some debug code to the python function
> in ~/.offlineimap/offlineimap.py
> #! /usr/bin/env python2
> from subprocess import check_output
> def get_pass(account):
> f.write("acocunt name = %s"%account)
> return check_output("pass Mail/" + account,
> But that does not even result in the file being opened.
Interpolation just provide variables. The declared variable must be
used later in the config file.
Here is what might worth the try:
call_pass = get_pass(%(account_name))
account_name = ACCOUNT_NAME
remotepasseval = call_pass
IOW, it's not possible to trash the remotepasseval in the remote
What I'm not 100% sure is that interpolation can work for variables
defined after they are used.
> So this raises two (3?) questions:
> a) which variable should I use to pass the account name
> in the [default] section (so I don't have to specify
> a separate one in each account
You have to define all the variables yourself. Since we can't remove the
remotepasseval lines in the Repository sections, it's easier to not use
interpolation like this:
remotepasseval = get_pass('ACCOUNT_NAME')
> b) is there a list of all variable/fields that I can interpolate
AFAIK, there are no predefined variables. The interpolation comes from
the configparser module. The official doc is:
> c) how to add debugging into the python script?
I would just print() the values instead of writing them to a file.
If you have a lot of accounts, you might like to build the config file
with a script of your own and use a template system. For a script
written in python there is jinja2 (usually used for the web but this can
be used in a script).
Also, you might like to split your config file and have one config file
per account. Then, call offlineimap with
offlineimap -c CONFIG_FILE_PATH
More information about the OfflineIMAP-project