<h1 id="setting-up-a-local-imap-server">Setting up a local imap server</h1>
<p>To install a local imap daemon that will only listen to localhost connections, made via ssh tunneling. This is for use as a local backup of your imap files, or for keeping a remote backup somewhere.</p>
<p>This is not a mail delivery solution but rather a way to keep a backup of your email using to a <code>MailDir</code> directory that you can access using your email client. As each message is stored in its own file, you can also use normal tools like <code>find|sed|awk|grep</code> to find messages.</p>
<p>This setup can be installed locally or remotely on, for example, a raspberry pi. In that case you can enable a portforwarding rule in <code>~/.ssh/config</code> to include something like <code>LocalForward 127.0.0.1:2143 127.0.0.1:143</code></p>
<p>Install using <code>aptitude install courier-imap courier-authdaemon</code></p>
<p>You can check the status using <code>systemctl status courier-imap.service courier-authdaemon.service</code></p>
<p>Edit the file <code>/etc/courier/imapd</code> and modify the following settings:</p>
<p>Address to listen on, can be set to a single IP address.</p>
<pre><code>    &lt; ADDRESS=0
    &gt; ADDRESS=127.0.0.1
</code></pre>
<p>Maximum number of IMAP servers started</p>
<pre><code>    &lt; MAXDAEMONS=40
    &gt; MAXDAEMONS=80
</code></pre>
<p>Maximum number of connections to accept from the same IP address</p>
<pre><code>    &lt; MAXPERIP=20
    &gt; MAXPERIP=40
</code></pre>
<p>The following setting is optional, and causes messages from the given folder to be automatically deleted after the given number of days.</p>
<pre><code>    &lt; IMAP_EMPTYTRASH=Trash:7
    &gt; #IMAP_EMPTYTRASH=Trash:7
</code></pre>
<p>Change the directory name of the maildir directory.</p>
<pre><code>    &lt; MAILDIRPATH=Maildir
    &gt; MAILDIRPATH=/home/pi/MailDir
</code></pre>
<p>Then restart the service using <code>systemctl restart courier-imap.service courier-authdaemon.service</code>.</p>
<p>When I did this I got a strange error about but installing the package <code>gamin</code> fixed it. Which is a <em>Library providing the FAM File Alteration Monitor API</em>.</p>
<pre><code>  Filesystem notification initialization error -- contact your mail
  administrator (check for configuration errors with the FAM/Gamin library)
</code></pre>
<h3 id="links">Links</h3>
<ul>
<li><a href="https://www.courier-mta.org/imap/documentation.html">https://www.courier-mta.org/imap/documentation.html</a></li>
<li><a href="https://www.faqforge.com/linux/fix-for-courier-imap-error-check-for-configuration-errors-with-the-famgamin-library/">https://www.faqforge.com/linux/fix-for-courier-imap-error-check-for-configuration-errors-with-the-famgamin-library/</a></li>
</ul>
