<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>El Tramo &#187; IMAP</title>
	<atom:link href="http://el-tramo.be/blog/tag/imap/feed" rel="self" type="application/rss+xml" />
	<link>http://el-tramo.be</link>
	<description>Remko Tronçon&#039;s Homepage</description>
	<lastBuildDate>Fri, 11 Jun 2010 19:08:15 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Mirroring GMail locally with MBSync</title>
		<link>http://el-tramo.be/blog/gmail-mbsync</link>
		<comments>http://el-tramo.be/blog/gmail-mbsync#comments</comments>
		<pubDate>Sun, 31 Aug 2008 20:51:35 +0000</pubDate>
		<dc:creator>Remko Tronçon</dc:creator>
				<category><![CDATA[Nerdy]]></category>
		<category><![CDATA[E-Mail]]></category>
		<category><![CDATA[GMail]]></category>
		<category><![CDATA[IMAP]]></category>
		<category><![CDATA[MBSync]]></category>

		<guid isPermaLink="false">http://el-tramo.be/?p=196</guid>
		<description><![CDATA[Ever since I started using GMail as my mail client, I wanted to have an automatically synchronized local (off-line) copy of my GMail account. Such a copy would not only serve as a backup, but would also come in handy when I needed to consult messages when I&#8217;m without internet connection. It would also allow [...]]]></description>
			<content:encoded><![CDATA[<p>Ever since I started using GMail as my mail client, I wanted to have an automatically synchronized local (off-line) copy of my GMail account. Such a copy would not only serve as a backup, but would also come in handy when I needed to consult messages when I&#8217;m without internet connection. It would also allow me to efficiently check my e-mail when I only have very limited (and expensive) bandwidth, or simply to find out  which messages take up most space on my account.</p>
<p>With the arrival of IMAP support for GMail, it has become possible to efficiently synchronize your mailboxes, without having to jump through loops or downloading your whole history over POP3 every time you synchronize. While looking for an IMAP synchronization tool, I stumbled upon <a href="http://blog.rectalogic.com/2007/11/automated-gmail-backup-via-imap.html">a post</a> referring to <a href="http://isync.sourceforge.net/">mbsync</a>, a tool which did exactly what I wanted. The post itself only talked about synchronizing your messages as a flat list, and did not talk about synchronizing labels. When trying to synchronizing all my mail, including labels, I bumped into some caveats of mbsync. Luckily, these problems can easily be fixed.</p>
<p><span id="more-196"></span></p>
<p>My first problem was the fact that I use ‘/’ in my GMail labels to create a label hierarchy. It turns out that GMail&#8217;s IMAP service uses ‘/’ as its hierarchy delimiter as well, which makes the IMAP mailbox hierarchy the same as my label hierarchy. Moreover, GMail&#8217;s internal mail folders (e.g. ‘All Mail’, ‘Sent Mail’, ‘Starred Mail’, &#8230;) also reside in a hierarchy under a toplevel mailbox called ‘[Gmail]’. The problem is that mbsync only checks the toplevel mailboxes, despite the fact that it allows you to write mailbox matching patterns based on delimiters. Changing mbsync to check the whole hierarchy of IMAP mailboxes was just a one-character patch.</p>
<p>However, then came the second problem: mailboxes with &#8216;/&#8217; in their name cannot be written to the filesystem directly: you either have to make sure that all the parent directories of the mailbox exist, or you have to replace the &#8216;/&#8217; by another character (sequence) that <em>is</em> valid, thus flattening your mailbox hierarchy. Since mbsync uses maildir as its local storage format, and since hierarchical maildirs are not really supported by mail clients, I chose for the latter solution: a flat list of maildir mailboxes for mirroring my hierarchical IMAP mailboxes.</p>
<p>After these changes, it is possible to synchronize a complete GMail account using the following mbsync configuration file:</p>
<blockquote>
<pre>IMAPAccount gmail
Host imap.gmail.com
User MY.NAME@gmail.com
UseIMAPS yes
CertificateFile ~/GMail/gmail.pem

IMAPStore gmail-remote
Account gmail

MaildirStore gmail-local
Path ~/GMail/
Inbox ~/GMail/Inbox

Channel gmail
Master :gmail-remote:
Slave :gmail-local:
# Exclude everything under the internal [Gmail] folder, except the interesting folders
Patterns * ![Gmail]* "[Gmail]/All Mail"
Create Slave
Expunge Slave
Sync Pull</pre>
</blockquote>
<p>After putting this in <code>~/.mbsyncrc</code>, you can synchronize your account by running</p>
<blockquote>
<pre>mbsync gmail</pre>
</blockquote>
<p>You can also add the following to your configuration file:</p>
<blockquote>
<pre>Channel gmail-inbox
Master :gmail-remote:
Slave :gmail-local:
Create Slave
Expunge Slave
Sync Pull</pre>
</blockquote>
<p>This allows you to only synchronize your inbox (e.g. when on GPRS), by calling</p>
<blockquote>
<pre>mbsync gmail-inbox</pre>
</blockquote>
<p>My patch against mbsync CVS can be found <a href="/files/mbsync/recursive_imap.diff">here</a> (together with <a href="/files/mbsync/imap_compilation_fix.diff">a fix</a> to make it compile on Mac OS X).</p>
]]></content:encoded>
			<wfw:commentRss>http://el-tramo.be/blog/gmail-mbsync/feed</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>
