frosch03.de/posts/2016-06-02-offlineimap-cygwin
Install offlineimap
Offlineimap is easy to install since it is a simple package to select from within cygwin's setup.exe.
- offlineimap (6.5.5-1)
Test via offlineimap --version
if you installed it correctly. This
should reveal just the version number.
Configure offlineimap
To configure offlineimap, you must create a .offlineimaprc
file within
your home directory. Within that file you configure your email accounts,
settings and so on.
The easiest way would be, to put your login credentials right into that file. But I rather disadvice you to do so. I therefore will present you an example, where your password is stored encrypted with GnuPG on your disc.
The following configuration is my gmail config:
{% highlight ini %} [general] accounts = gmail maxsyncaccounts = 1 ui = ttyui pythonfile = ~/bin/offlineimap-helper.py socktimeout = 90 expunge = yes
[Account gmail] localrepository = gmaillocal remoterepository = gmailremote
[Repository gmaillocal] type = Maildir localfolders = ~/Mail/gmail
[Repository gmailremote] type = Gmail remoteuser = frosch03@gmail.com remotepasseval = mailpasswd("gmail") ssl = yes sslcacertfile = /usr/ssl/certs/ca-bundle.crt auth\_mechanisms = GSSAPI, CRAM-MD5, PLAIN, LOGIN maxconnections = 2 idlefolders = ['INBOX'] {% endhighlight %}
As you could see, there is one account configured within the general section, called gmail. Then there is a Account gmail section, that further defines the the names for a local and a remote section. The local section then defines the type to be of maildir and where the maildir is located.
Within the Repository gmailremote section, all parameters for
accessing your gmail repository are defined. Your mails will be stored
with the ~/Mail/gmail
folder. If it isn't existing yet, create it via
mkdir -p ~/Mail/gmail
.
As you could see, instead of a password, the function mailpasswd
is
called. It is called with the parameter "gmail", which corresponds to
the filename (omitting the ending), that contains the encrypted
password.
The function itself is defined within offlineimap-helper.py
and that
file is loaded by the general sections pythonfile
variable.
If you don't have a ~/bin/
folder, create it with mkdir ~/bin
. Now
go ahead and create the offlineimap-helper.py
file within ~/bin/
with the following content:
{% highlight python %} import os import subprocess
def mailpasswd(acct): acct = os.path.basename(acct) path = "home/frosch03.passwd/%s.gpg" % acct args = ["gpg", "–use-agent", "–quiet", "–batch", "-d", path] try: return subprocess.check\_output(args).strip() except subprocess.Multiprocessors: return ""
def prime\_gpg\_agent(): ret = False i = 1 while not ret: ret =
(mailpasswd("prime") = "prime") if i > 2: from offlineimap.ui import
getglobalui sys.stderr.write("Error reading in passwords.
Terminating.\n") getglobalui().terminate() i +
1 return ret
prime\_gpg\_agent() {% endhighlight %}
This file contains the short python function, that retrieves the
password from the .gpg file. It contains another function
prime_gpg_agent
. The function is called at the end of the file, so
once offlineimap-helper.py
is parsed, a dummy retrieve run is
performed. The priming function should retrieve the string "prime" from
prime.gpg
, if everything is setup correctly.
Create an encrypted file with your password
GnuPG is simply installed via cygwin's setup.exe. Just select
- gnupg (1.4.20-1)
If it is installed correctly, gpg --version
should return the correct
version information.
If you have no gpg key pair yet, you need to create a new one. This is
done by gpg --gen-key
. Select your desired settings - I tend to select
the highest possible - and then enter your data.
ATTENTION: Until now we only have GnuPG 1.4.x within cgywin, which comes without a GnuPG Agent. The only way is to use a gpg key without a passphrase. In any case, this is not recomendet, as your private key is not secured and therefore could be used by any user that has local access to it. If you are willing to take the risk, in going ahead with a gpg-key without a passphrase, follow the next steps.
Once the key is generated, you are able to create the encrypted files.
You should store the password files within a folder at your home
directory, named .passwd
. Create that folder with mkdir ~/.passwd
.
Now create the file ~/.passwd/prime.gpg
within emacs, enter the string
"prime" (without the quotes) and store the file again. A dialog should
ask you for the recipients for the encryption. Mark your own key and
confirm the dialog.
After that, you have to provide your password file, so open the
~/.passwd/gmail.gpg
file within emacs and immediately store it (do not
enter your password right now). Again, a dialog should ask you for the
recipients for the encryption. Mark your own key again and confirm the
dialog.
Check if the created file is encrypted. If so, open the
~/.passwd/gmail.gpg
file once again, enter now your password and store
it. You might again enter the key.
Try out your setup
If all the previous steps are done correctly, a call of offlineimap
should start downloading your mails into the configured maildir. This
might initially take a longer time.
Read on: how to compile mu/mu4e within cygwin