Gmail IMAP Proxy/Cache – Imapproxy+Perdition

Create an IMAP cache using Imapproxy. Because Gmail uses IMAP4s (port 993) instead of IMAP4 (port143) we will need to add Perdition Mail Retrieval Proxy – Imapproxy on it’s own is incapable of serving to port 993. The resulting chain will be IMAP client –> Imapproxy –> Perdition –> Google. I will just use the distro releases although compiling would net newer software.

sudo aptitude install imapproxy Perdition

On my distro the install of both packages was a bit buggy. Imapproxy hangs when trying to startup as it isn’t configured, and Perdition starts more servers than I want and reports “cannot start, is another server listening?” even when it does in fact start normally. After installing I just quit, Ctrl-Z, kill’d, and stopped the services (service imapproxy stop, service perdition stop) or used the init scripts in /etc/init.d. Once they are under control, you can modify the various .conf files.

nano /etc/perdition/perdition.conf

connection_logging
imap_capability IMAP4 IMAP4REV1 LITERAL+
"\"IMPLEMENTATION\" \"perdition\"  "\
"\"SIEVE\" \"comparator-i;octet "\
"comparator-i;ascii-casemap "\
"fileinto "\
"reject "\
"envelope "\
"encoded-character "\
"vacation "\
"subaddress "\
"comparator-i;ascii-numeric "\
"relational "\
"regex "\
"imap4flags "\
"copy i"\
"nclude "\
"variables "\
"body "\
"enotify "\
"environment "\
"mailbox "\
"date\"  "\
"\"SASL\" \"PLAIN\"  "\
"\"NOTIFY\" \"mailto\"  "\
"\"VERSION\" \"1.18\""
listen_port 1716
protocol IMAP4S
outgoing_port 993
outgoing_server  imap.gmail.com
ssl_mode ssl_outgoing
ssl_ca_file /usr/share/ca-certificates/mozilla/Equifax_Secure_CA.crt

Luckily the SSL Cert file needed from Google's Certificate Authority - Equifax is available with most Debian systems. If you are using perdition to proxy to say your ISP's Imap service, have a look around in /usr/share/ca-certificates you might find the one you need. I will also turn off the unneeded servers before restarting.

nano /etc/default/perdition

RUN_PERDITION=yes
POP3=no
POP3_FLAGS=
POP3S=no
POP3S_FLAGS=
IMAP4=no
IMAP4_FLAGS=
IMAP4S=yes
IMAP4S_FLAGS=
MANAGESIEVE=no
MANAGESIEVE_FLAGS=

nano /etc/immaproxy.conf

server_hostname 127.0.0.1
connect_retries 10
connect_delay 5
cache_size 3072
listen_port 1715
listen_address 127.0.0.1
server_port 1716
cache_expiration_time 300
proc_username nobody
proc_groupname nogroup
stat_filename /var/run/pimpstats
protocol_log_filename /var/log/imapproxy_protocol.log
syslog_facility LOG_MAIL
send_tcp_keepalives no
enable_select_cache no
foreground_mode no
force_tls no
chroot_directory /var/lib/imapproxy/chroot
enable_admin_commands no

I also had to 'touch' a writeable logfile for Imapproxy.

touch /var/log/imapproxy_protocol.log
chown nobody:nogroup imapproxy_protocol.log

Finally start the servers. Point your client software (thunderbird for example) at Imapproxy's listening port. If you have errors, enable debugging (/etc/perdition/perdition.conf), there is quite a bit of useful information on the handshaking going on and you should be able to figure it out with a little Google-fu. Of course...I should have just used used an Nginx/Ximba type solution. But doing things the hard way is my motto 'round here.

One Response to “Gmail IMAP Proxy/Cache – Imapproxy+Perdition”

  1. adrian says:

    Perfect. it works! Thanks a lot. Been trying all day imapproxy until I found out it does not support imaps on 993 :))

Leave a Response

unilinear