<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Wojno: Tag imap</title>
    <link>http://christopher.wojno.com/articles/tag/imap</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>Exploration through Code</description>
    <item>
      <title>Thunderbird Copy to Sent IMAP Connection Error</title>
      <description>&lt;p&gt;This article applies to: &lt;a href="http://www.mozilla.com/en-US/thunderbird/"&gt;Thunderbird&lt;/a&gt; v.2.0.0.9 and a few previous versions and may very well be applicable in the future.&lt;/p&gt;


	&lt;h1&gt;The Solution&lt;/h1&gt;


	&lt;p&gt;I&amp;#8217;m assuming you want the solution and not the explanation. If you really do want the explanation, scroll down and come back!&lt;/p&gt;


	&lt;p&gt;After I set up my own &lt;span class="caps"&gt;IMAP&lt;/span&gt; server for my e-mail, I began to get error messages from Thunderbird: &amp;#8220;Error copying message to sent folder. Retry? OK.&amp;#8221; Rather than change my Postfix server (which was advised against by the documentation), I looked for a client-side solution. Retrying is a crap-shoot. Sometimes it copies, but most of the time it just sits there after informing you that:&lt;/p&gt;


&lt;blockquote&gt;Unable to connect to your &lt;span class="caps"&gt;IMAP&lt;/span&gt; server. You may have exceeded the maximum number of connections to this server. If so, use the Advanced &lt;span class="caps"&gt;IMAP&lt;/span&gt; Server Settings Dialog to reduce the number of cached connections.&lt;/blockquote&gt;

	&lt;p&gt;Advanced &lt;span class="caps"&gt;IMAP&lt;/span&gt; Server Settings Dialog? I&amp;#8217;ve never heard of that before. Let&amp;#8217;s see what about:config has to say. You can find it in Tools-&amp;gt;Options&amp;#8230; on Windows, or Edit-&amp;gt;Options&amp;#8230; on other platforms. Once you see the dialog, hit the &amp;#8220;Advanced&amp;#8221; icon at the top right, then hit the &amp;#8220;General&amp;#8221; tab in the area below it. You&amp;#8217;ll see &amp;#8220;Config Editor&amp;#8230;&amp;#8221;.&lt;/p&gt;


	&lt;p&gt;I tried setting: mail.imap.max_cached_connections from 5, to 1, to 0. No value fixes it.&lt;/p&gt;


	&lt;p&gt;I then noticed: mail.server.server2.max_cached_connections And not just that one (I have several &lt;span class="caps"&gt;IMAP&lt;/span&gt; accounts). There were a few others as well. Setting these to 1 &lt;span class="caps"&gt;HAS&lt;/span&gt; solved my problem.&lt;/p&gt;


	&lt;p&gt;Just make sure all your: mail.server.server&lt;strong&gt;N&lt;/strong&gt;.max_cached_connections = 1&lt;/p&gt;


	&lt;p&gt;Now, had I listened to the error message from the start, I would have gone to the account settings for each. Right click on the &lt;span class="caps"&gt;IMAP&lt;/span&gt; account and select properties. Then goes to server settings. You&amp;#8217;ll notice an &amp;#8220;Advanced&amp;#8221; button. Sure enough, you see the text field for the number of cached connections. Of course, if you want to change them all at once, you can use the Config Editor.&lt;/p&gt;


	&lt;p&gt;Remember, restart Thunderbird for the changes to take effect. Don&amp;#8217;t expect miracles until after you&amp;#8217;ve relaunched.&lt;/p&gt;


	&lt;h1&gt;The Explanation&lt;/h1&gt;


	&lt;p&gt;&lt;span class="caps"&gt;IMAP&lt;/span&gt; connection caching? Yes, when Thunderbird checks your e-mail over &lt;span class="caps"&gt;IMAP&lt;/span&gt;, it starts up a &lt;span class="caps"&gt;TCP&lt;/span&gt; connection. That&amp;#8217;s a 3-way handshake.&lt;/p&gt;


	&lt;ol&gt;
	&lt;li&gt;Hello Server!&lt;/li&gt;
		&lt;li&gt;Hello Client!&lt;/li&gt;
		&lt;li&gt;Hello again Server! (I got your hello)&lt;/li&gt;
	&lt;/ol&gt;


	&lt;p&gt;3 Hello&amp;#8217;s = 3 way handshake. &lt;span class="caps"&gt;OK OK&lt;/span&gt;, yes, this is a gross oversimplification. None-the-less, this handshake sequence is considered slow and &amp;#8220;expensive.&amp;#8221; So instead of saying good-bye after getting your mail, the client will say, &amp;#8220;I&amp;#8217;ll be back, so leave the line open.&amp;#8221; Sounds good, but most servers have limited resources. Once the maximum number of connections is reached, it won&amp;#8217;t accept any more. That&amp;#8217;s what is happening with Thunderbird here. It&amp;#8217;s being told that there is no more room.&lt;/p&gt;


	&lt;p&gt;So, what limited resource am I talking about? Well, those connections take up memory, especially the secure ones. &lt;span class="caps"&gt;SSL&lt;/span&gt; adds the overhead of a new shared secret (passphrase). That&amp;#8217;s not too bad, but it&amp;#8217;s more than storing the usual, unencrypted nothing. Even if you don&amp;#8217;t use &lt;span class="caps"&gt;SSL&lt;/span&gt;, each connection uses a new port. Every computer has 65535 ports. Depending on the system, approximately 1000 of them are reserved for system calls. The other 64,000 and change are shared among all the services provided by the server. And, yup, you guessed it, each connection uses up a port.&lt;/p&gt;


	&lt;p&gt;May not seem like a big deal. But say, you have an account. Thunderbird caches 5 connections by default. If you have 5 folders, it will use all 5 connections and cache them. If your e-mail is on a dedicated machine: 64,535/5 = 12,907. Only 13 thousand users can check their mail (if they all have 5 or more folders). If you have a big company, this would be bad if the &lt;span class="caps"&gt;CEO&lt;/span&gt; or &lt;span class="caps"&gt;POB&lt;/span&gt; (pointy haired boss) can&amp;#8217;t check his or her e-mail. Most servers will limit you (as did mine and probably yours if you&amp;#8217;re reading this article to solve your problem) to 4 connections from the same IP address. While it helps solve the connection volume problem, Thunderbird gets confused.&lt;/p&gt;


	&lt;p&gt;See, if you need a new connection on the same account, thunderbird will use any active ones. But if you have multiple accounts, Thunderbird assumes the connections are independent. Apparently, this is a mistake.&lt;/p&gt;


	&lt;h2&gt;An Expert Fix&lt;/h2&gt;


	&lt;p&gt;I suggest that Thunderbird take note of refused connections and give up active connections from &lt;em&gt;other&lt;/em&gt; accounts if they resolve to the same server. That will expand the already automatic connection cycling feature among connections on the same account to connections on the same client.&lt;/p&gt;</description>
      <pubDate>Thu, 20 Dec 2007 21:46:00 -0800</pubDate>
      <guid isPermaLink="false">urn:uuid:a5e3237a-f6ab-4a62-9064-c50cb15600f3</guid>
      <author>Christopher Wojno</author>
      <link>http://christopher.wojno.com/articles/2007/12/20/thunderbird-copy-to-sent-imap-connection-error</link>
      <category>How-Tos</category>
      <category>thunderbird</category>
      <category>imap</category>
      <category>cached</category>
      <category>connection</category>
      <category>exceed</category>
      <category>fix</category>
    </item>
  </channel>
</rss>
