Yesterday, I decided I would sit down and finally get my copy of Kontact connected up properly via IMAP, so I could not only use it for mail, but also for notes, calendering and other crap.
The first step was EMail. I guess this would be bloody simple, as that’s the main use that people subscribe to IMAP for.
I was wrong…
Problem One – connecting
I tried connecting, using the same details I use in work and in webmail, but the client (KMail) would hang and finally timeout.
I tried connecting via telnet, which would start like this:
[kae@kae share]$ telnet verens.com 143 Trying 126.96.36.199... Connected to verens.com (188.8.131.52). Escape character is '^]'.
Followed by a pause of three minutes, then finally:
* OK [CAPABILITY IMAP4rev1 UIDPLUS CHILDREN NAMESPACE THREAD=ORDEREDSUBJECT THREAD=REFERENCES SORT QUOTA IDLE ACL ACL2=UNION STARTTLS] Courier-IMAP ready. Copyright 1998-2005 Double Precision, Inc. See COPYING for distribution information. Connection closed by foreign host. [kae@kae share]$
After tests involving a few different machines, it became clear that it was local to my own machine. All other machines connected fine. Beyond that, I was flummoxed.
A few hours later, it occurred to me to examine the differences between a tcpdump of a successful telnet session (from a different machine) and an unsuccessful telnet session (from this machine).
It was suddenly clear that it was something to do with the first tcp header in the tcpdump:
[root@webworks run]# tcpdump host kae.verens.com and port 143 -A tcpdump: verbose output suppressed, use -v or -vv for full protocol decode listening on eth0, link-type EN10MB (Ethernet), capture size 96 bytes 21:15:31.501878 IP kae.verens.com.60451 > 192.168.1.9.imap: S 1688597885:1688597885(0) win 5840 <mss 1408,sackOK,timestamp 10763308 0,nop,wscale 7>
I had no clue what “wscale” was, but a quick search online brought me to this page which described exactly the same problem I was experiencing.
Unfortunately, the solution there was not correct for my own kernel (2.6.17), but a quick test showed that the following command solved the problem instantly:
echo 0 > /proc/sys/net/ipv4/tcp_window_scaling
I put that in
/etc/rc.local so it would be run on boot.
I still don’t understand the problem completely, but from what I understand,
wscale has something to do with the size of a TCP packet that a machine is capable of handling. At some point between my own machine and my IMAP server, one of the routers couldn’t handle the requested
wscale, and didn’t have a backup plan for that eventuality. By changing the local value to 0, I essentially simplified my own network, so my machine would only connect with the most default TCP size. If I’m wrong, I’m sorry – I’m no TCP/IP guru.
update: Marcus Furlong pointed me to this post which has a further explanation.
Problem 2 – Kontact
Right, so I then had a successful IMAP connection. I needed to set up KOrganizer, KJournal and KNotes to use it.
The method described by various online resources, is to add IMAP as the default resource through the KDE Control Panel (KDE Components > KDE Resources).
This is not enough. You must then open your Kontact, click Settings > Configure Kontact, then open Mail > Misc > Groupware, and set an IMAP folder as the parent folder of the resources.
Unfortunately, the notes I found didn’t tell me that this only works with Cached Imap (which they also call Disconnected Imap for some reason). So, you must remove your IMAP connection and start all over again using Disconnected Imap. Then download all of your mail (which took me half an hour or so), and restart Kontact. Bloody annoying.
A ridiculous comment in the bug notes:
The imap resource is not designed to be used with online IMAP, only with
cached IMAP. The real bug is that it’s possible to configure it to use online
I totally disagree with the above. Why not allow it to work with proper IMAP??