<?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>costela.net &#187; debian</title>
	<atom:link href="http://costela.net/tag/debian/feed/" rel="self" type="application/rss+xml" />
	<link>http://costela.net</link>
	<description>rhetorically impaired, ironically despaired</description>
	<lastBuildDate>Sun, 08 Apr 2012 13:30:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Importing an Outlook PST into IMAP</title>
		<link>http://costela.net/2011/06/importing-an-outlook-pst-into-imap/</link>
		<comments>http://costela.net/2011/06/importing-an-outlook-pst-into-imap/#comments</comments>
		<pubDate>Sun, 19 Jun 2011 16:16:09 +0000</pubDate>
		<dc:creator>Leo Antunes</dc:creator>
				<category><![CDATA[Home]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[debian planet]]></category>
		<category><![CDATA[dovecot]]></category>
		<category><![CDATA[imap]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[libpst]]></category>
		<category><![CDATA[outlook]]></category>
		<category><![CDATA[patch]]></category>
		<category><![CDATA[pst]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[readpst]]></category>
		<category><![CDATA[script]]></category>

		<guid isPermaLink="false">http://costela.net/?p=691</guid>
		<description><![CDATA[Well, every once in a while we&#8217;re forced to do something that isn&#8217;t particularly interesting or pleasant. Last week it happened again: I had to import a few pretty big PSTs (most 2Gig, one 10Gig, with about 100.000 emails) into our dovecot IMAP. Doing this with Outlook itself was out of the question: it took [...]]]></description>
			<content:encoded><![CDATA[<p>Well, every once in a while we&#8217;re forced to do something that isn&#8217;t particularly interesting or pleasant. Last week it happened again: I had to import a few pretty big PSTs (most 2Gig, one 10Gig, with about 100.000 emails) into our dovecot IMAP.</p>
<p>Doing this with Outlook itself was out of the question: it took <em>way</em> too long, even on the local network (many hours for a 1G file) and was prone to hanging and crashes, which were obviously a pain to debug and start over.<br />
Thunderbird was unfortunately not much better, since &#8211; at least in our tests &#8211; it didn&#8217;t import the read status of the emails (they were all marked as unread) and also wasn&#8217;t particularly good at handling folders with strange names, containing &#8220;.&#8221;, &#8220;/&#8221; or some more obscure characters. We had used it before for smaller files, where manually dealing with the problems was acceptable, but this time it required something a bit more elaborate, if we were to keep our sanity.</p>
<p>Enter <a href="http://www.five-ten-sg.com/libpst/">libpst</a>. It includes the handy <em>readpst</em> utility which dumps all emails in usable formats in a directory tree, one directory per folder. Unfortunately the Debian version is somewhat outdated and doesn&#8217;t support the newer Outlook formats, so I did <a href="http://anonscm.debian.org/gitweb/?p=collab-maint/libpst.git">some packaging</a> and even a little bit of <a href="http://anonscm.debian.org/gitweb/?p=collab-maint/libpst.git;a=blob;f=debian/patches/mbox_flags.patch">patching</a>. It seems Thunderbird also uses this library, which would explain why it didn&#8217;t handle the Read-Status (haven&#8217;t confirmed this though; just read it somewhere).</p>
<p>The last step was this not-so-little script, which uses the dumped directories from readpst and imports them in IMAP. It would have probably been a bit more elegant to use libpst directly, but I unfortunately didn&#8217;t have the time to mess around with that. I did have to mess around a lot with encodings though, ergo the unholy chaos with <em>unicode()</em>s and <em>str.encode()</em>s thrown around like rice at a wedding (I could never really wrap my head around charset problems; the subject boggles my mind to this very day).</p>
<p><small>code after the jump</small><br />
<span id="more-691"></span></p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/usr/bin/env python2.7</span>
<span style="color: #808080; font-style: italic;">#-*- encoding: utf-8 -*-</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">os</span>, <span style="color: #dc143c;">sys</span>, <span style="color: #dc143c;">time</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">re</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">from</span> argparse <span style="color: #ff7700;font-weight:bold;">import</span> ArgumentParser
<span style="color: #ff7700;font-weight:bold;">from</span> <span style="color: #dc143c;">getpass</span> <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">getpass</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">imaplib</span>
<span style="color: #ff7700;font-weight:bold;">from</span> <span style="color: #dc143c;">email</span>.<span style="color: black;">header</span> <span style="color: #ff7700;font-weight:bold;">import</span> decode_header
<span style="color: #ff7700;font-weight:bold;">from</span> <span style="color: #dc143c;">mailbox</span> <span style="color: #ff7700;font-weight:bold;">import</span> mbox
&nbsp;
<span style="color: #ff7700;font-weight:bold;">from</span> twisted.<span style="color: black;">mail</span> <span style="color: #ff7700;font-weight:bold;">import</span> imap4 <span style="color: #808080; font-style: italic;"># for their imap4-utf7 implementation</span>
&nbsp;
<span style="color: #dc143c;">parser</span> = ArgumentParser<span style="color: black;">&#40;</span>description=<span style="color: #483d8b;">&quot;&quot;&quot;Recursively import mbox files in a directory
                                        structure to an IMAP server.<span style="color: #000099; font-weight: bold;">\n</span>
                                        The expected structure is that generated by
                                        'readpst -r'.&quot;&quot;&quot;</span><span style="color: black;">&#41;</span>
<span style="color: #dc143c;">parser</span>.<span style="color: black;">add_argument</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'-s'</span>, dest=<span style="color: #483d8b;">'imap_server'</span>, default=<span style="color: #483d8b;">'localhost'</span>, <span style="color: #008000;">help</span>=<span style="color: #483d8b;">'IMAP server to import emails to'</span><span style="color: black;">&#41;</span>
<span style="color: #dc143c;">parser</span>.<span style="color: black;">add_argument</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'-u'</span>, dest=<span style="color: #483d8b;">'imap_user'</span>, required=<span style="color: #008000;">True</span>, <span style="color: #008000;">help</span>=<span style="color: #483d8b;">'user for logging in to IMAP'</span><span style="color: black;">&#41;</span>
<span style="color: #dc143c;">parser</span>.<span style="color: black;">add_argument</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'-p'</span>, dest=<span style="color: #483d8b;">'imap_passwd'</span>, <span style="color: #008000;">help</span>=<span style="color: #483d8b;">&quot;will be prompted for if not provided&quot;</span><span style="color: black;">&#41;</span>
<span style="color: #dc143c;">parser</span>.<span style="color: black;">add_argument</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'-c'</span>, dest=<span style="color: #483d8b;">'charset'</span>, default=<span style="color: #483d8b;">'utf8'</span>, <span style="color: #008000;">help</span>=<span style="color: #483d8b;">'charset in which the folders are stored (for versions older than 2003)'</span><span style="color: black;">&#41;</span>
<span style="color: #dc143c;">parser</span>.<span style="color: black;">add_argument</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'-f'</span>, dest=<span style="color: #483d8b;">'force'</span>, action=<span style="color: #483d8b;">'store_true'</span>, <span style="color: #008000;">help</span>=<span style="color: #483d8b;">'import mail even if we think it might be a duplicate'</span><span style="color: black;">&#41;</span>
<span style="color: #dc143c;">parser</span>.<span style="color: black;">add_argument</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'-m'</span>, dest=<span style="color: #483d8b;">'mappings'</span>, <span style="color: #008000;">help</span>=<span style="color: #483d8b;">'a JSON file with mappings between folder names and mailbox names (no slashes or dots)'</span><span style="color: black;">&#41;</span>
<span style="color: #dc143c;">parser</span>.<span style="color: black;">add_argument</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'folder'</span>, nargs=<span style="color: #483d8b;">'+'</span>, <span style="color: #008000;">help</span>=<span style="color: #483d8b;">&quot;the base folders to import&quot;</span><span style="color: black;">&#41;</span>
&nbsp;
args = <span style="color: #dc143c;">parser</span>.<span style="color: black;">parse_args</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #ff7700;font-weight:bold;">not</span> args.<span style="color: black;">imap_passwd</span>:
    args.<span style="color: black;">imap_passwd</span> = <span style="color: #dc143c;">getpass</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">if</span> args.<span style="color: black;">mappings</span>:
    <span style="color: #ff7700;font-weight:bold;">import</span> json
    folderToMailbox = json.<span style="color: black;">load</span><span style="color: black;">&#40;</span><span style="color: #008000;">open</span><span style="color: black;">&#40;</span>args.<span style="color: black;">mappings</span>,<span style="color: #483d8b;">'r'</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">else</span>:
    folderToMailbox = <span style="color: black;">&#123;</span><span style="color: black;">&#125;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> mailboxFromPath<span style="color: black;">&#40;</span>path<span style="color: black;">&#41;</span>:
    paths = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span>
    <span style="color: #ff7700;font-weight:bold;">for</span> p <span style="color: #ff7700;font-weight:bold;">in</span> path.<span style="color: black;">split</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">os</span>.<span style="color: black;">path</span>.<span style="color: black;">sep</span><span style="color: black;">&#41;</span>:
        p = folderToMailbox.<span style="color: black;">get</span><span style="color: black;">&#40;</span>p, p<span style="color: black;">&#41;</span>
&nbsp;
        <span style="color: #808080; font-style: italic;"># only other invalid char besides '/', which can't be created by readpst anyway</span>
        p = p.<span style="color: black;">replace</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'.'</span>,<span style="color: #483d8b;">''</span><span style="color: black;">&#41;</span>
&nbsp;
        paths.<span style="color: black;">append</span><span style="color: black;">&#40;</span>p<span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #483d8b;">'.'</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span>paths<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> imapFlagsFromMbox<span style="color: black;">&#40;</span>flags<span style="color: black;">&#41;</span>:
    <span style="color: #808080; font-style: italic;"># libpst only sets R and O</span>
    f = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span>
    <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #483d8b;">'R'</span> <span style="color: #ff7700;font-weight:bold;">in</span> flags <span style="color: #ff7700;font-weight:bold;">or</span> <span style="color: #483d8b;">'O'</span> <span style="color: #ff7700;font-weight:bold;">in</span> flags:
        f.<span style="color: black;">append</span><span style="color: black;">&#40;</span>r<span style="color: #483d8b;">'<span style="color: #000099; font-weight: bold;">\S</span>een'</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #483d8b;">'D'</span> <span style="color: #ff7700;font-weight:bold;">in</span> flags:
        f.<span style="color: black;">append</span><span style="color: black;">&#40;</span>r<span style="color: #483d8b;">'<span style="color: #000099; font-weight: bold;">\D</span>eleted'</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #483d8b;">'A'</span> <span style="color: #ff7700;font-weight:bold;">in</span> flags:
        f.<span style="color: black;">append</span><span style="color: black;">&#40;</span>r<span style="color: #483d8b;">'<span style="color: #000099; font-weight: bold;">\A</span>nswered'</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #483d8b;">'F'</span> <span style="color: #ff7700;font-weight:bold;">in</span> flags:
        f.<span style="color: black;">append</span><span style="color: black;">&#40;</span>r<span style="color: #483d8b;">'<span style="color: #000099; font-weight: bold;">\F</span>lagged'</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #483d8b;">'('</span>+<span style="color: #483d8b;">' '</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span>f<span style="color: black;">&#41;</span>+<span style="color: #483d8b;">')'</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> utf7encode<span style="color: black;">&#40;</span>s<span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">return</span> imap4.<span style="color: black;">encoder</span><span style="color: black;">&#40;</span>s<span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> headerToUnicode<span style="color: black;">&#40;</span>s<span style="color: black;">&#41;</span>:
    h = decode_header<span style="color: black;">&#40;</span>s<span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>
    <span style="color: #ff7700;font-weight:bold;">try</span>:
        <span style="color: #ff7700;font-weight:bold;">if</span> h<span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>: <span style="color: #808080; font-style: italic;"># charset != None</span>
            <span style="color: #ff7700;font-weight:bold;">try</span>:
                <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">unicode</span><span style="color: black;">&#40;</span><span style="color: #66cc66;">*</span>h<span style="color: black;">&#41;</span>
            <span style="color: #ff7700;font-weight:bold;">except</span> <span style="color: #008000;">LookupError</span>:
                <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">unicode</span><span style="color: black;">&#40;</span>h<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>,<span style="color: #483d8b;">'utf8'</span>,<span style="color: #483d8b;">'replace'</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">else</span>:
            <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">unicode</span><span style="color: black;">&#40;</span>h<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>, <span style="color: #483d8b;">'utf8'</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">except</span> <span style="color: #008000;">UnicodeDecodeError</span>:
        <span style="color: #ff7700;font-weight:bold;">try</span>:
            <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">unicode</span><span style="color: black;">&#40;</span>h<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>, <span style="color: #483d8b;">'cp1252'</span><span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;"># the usual culprits for malformed headers</span>
        <span style="color: #ff7700;font-weight:bold;">except</span> <span style="color: #008000;">UnicodeDecodeError</span>:
            <span style="color: #ff7700;font-weight:bold;">pass</span>
&nbsp;
        <span style="color: #ff7700;font-weight:bold;">try</span>:
            <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">unicode</span><span style="color: black;">&#40;</span>h<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>, <span style="color: #483d8b;">'latin1'</span><span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;"># the usual culprits for malformed headers</span>
        <span style="color: #ff7700;font-weight:bold;">except</span> <span style="color: #008000;">UnicodeDecodeError</span>:
            <span style="color: #ff7700;font-weight:bold;">pass</span>
&nbsp;
        <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">unicode</span><span style="color: black;">&#40;</span>h<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>, <span style="color: #483d8b;">'ascii'</span>, <span style="color: #483d8b;">'ignore'</span><span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;"># give up...</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> main<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
    imap = <span style="color: #dc143c;">imaplib</span>.<span style="color: black;">IMAP4_SSL</span><span style="color: black;">&#40;</span>args.<span style="color: black;">imap_server</span><span style="color: black;">&#41;</span>
    imap.<span style="color: black;">login</span><span style="color: black;">&#40;</span>args.<span style="color: black;">imap_user</span>, args.<span style="color: black;">imap_passwd</span><span style="color: black;">&#41;</span>
&nbsp;
    imap.<span style="color: #dc143c;">select</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">for</span> base <span style="color: #ff7700;font-weight:bold;">in</span> args.<span style="color: black;">folder</span>:
        <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;importing folder &quot;</span>+base
        <span style="color: #ff7700;font-weight:bold;">for</span> root, dirs, files <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #dc143c;">os</span>.<span style="color: black;">walk</span><span style="color: black;">&#40;</span>base<span style="color: black;">&#41;</span>:
            <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #483d8b;">'mbox'</span> <span style="color: #ff7700;font-weight:bold;">in</span> files:
                folder = <span style="color: #008000;">unicode</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">os</span>.<span style="color: black;">path</span>.<span style="color: black;">relpath</span><span style="color: black;">&#40;</span>root, base<span style="color: black;">&#41;</span>, args.<span style="color: black;">charset</span><span style="color: black;">&#41;</span>
                <span style="color: #dc143c;">mailbox</span> = mailboxFromPath<span style="color: black;">&#40;</span>folder<span style="color: black;">&#41;</span>
                <span style="color: #ff7700;font-weight:bold;">print</span> u<span style="color: #483d8b;">'importing mbox in {0} to {1}'</span>.<span style="color: black;">format</span><span style="color: black;">&#40;</span>folder, <span style="color: #dc143c;">mailbox</span><span style="color: black;">&#41;</span>
                mailbox_encoded = utf7encode<span style="color: black;">&#40;</span><span style="color: #dc143c;">mailbox</span><span style="color: black;">&#41;</span>
                m = mbox<span style="color: black;">&#40;</span><span style="color: #dc143c;">os</span>.<span style="color: black;">path</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span>root, <span style="color: #483d8b;">'mbox'</span><span style="color: black;">&#41;</span>, create=<span style="color: #008000;">False</span><span style="color: black;">&#41;</span>
                <span style="color: #ff7700;font-weight:bold;">for</span> msg <span style="color: #ff7700;font-weight:bold;">in</span> m:
                    <span style="color: #ff7700;font-weight:bold;">if</span> imap.<span style="color: #dc143c;">select</span><span style="color: black;">&#40;</span>mailbox_encoded<span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> <span style="color: #66cc66;">!</span>= <span style="color: #483d8b;">'OK'</span>:
                        <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;creating mailbox &quot;</span>+<span style="color: #dc143c;">mailbox</span>
                        r = imap.<span style="color: black;">create</span><span style="color: black;">&#40;</span>mailbox_encoded<span style="color: black;">&#41;</span>
                        <span style="color: #ff7700;font-weight:bold;">if</span> r<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> <span style="color: #66cc66;">!</span>= <span style="color: #483d8b;">'OK'</span>:
                            <span style="color: #dc143c;">sys</span>.<span style="color: black;">stderr</span>.<span style="color: black;">write</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Could not create mailbox: &quot;</span>+<span style="color: #008000;">str</span><span style="color: black;">&#40;</span>r<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
                            <span style="color: #ff7700;font-weight:bold;">continue</span>
                        imap.<span style="color: black;">subscribe</span><span style="color: black;">&#40;</span>mailbox_encoded<span style="color: black;">&#41;</span>
                        imap.<span style="color: #dc143c;">select</span><span style="color: black;">&#40;</span>mailbox_encoded<span style="color: black;">&#41;</span>
&nbsp;
                    <span style="color: #808080; font-style: italic;"># skip possibly duplicated msgs</span>
                    query = <span style="color: #483d8b;">'FROM &quot;{0}&quot; SUBJECT &quot;{1}&quot;'</span>.<span style="color: black;">format</span><span style="color: black;">&#40;</span>
                                utf7encode<span style="color: black;">&#40;</span>headerToUnicode<span style="color: black;">&#40;</span>msg<span style="color: black;">&#91;</span><span style="color: #483d8b;">'from'</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>.<span style="color: black;">replace</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'&quot;'</span>,<span style="color: #483d8b;">''</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>,
                                utf7encode<span style="color: black;">&#40;</span>headerToUnicode<span style="color: black;">&#40;</span>msg<span style="color: black;">&#91;</span><span style="color: #483d8b;">'subject'</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>.<span style="color: black;">replace</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'&quot;'</span>,r<span style="color: #483d8b;">'<span style="color: #000099; font-weight: bold;">\&quot;</span>'</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
                            <span style="color: black;">&#41;</span>
                    <span style="color: #ff7700;font-weight:bold;">if</span> msg.<span style="color: black;">has_key</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'date'</span><span style="color: black;">&#41;</span>:
                        query += <span style="color: #483d8b;">' HEADER DATE &quot;{0}&quot;'</span>.<span style="color: black;">format</span><span style="color: black;">&#40;</span>utf7encode<span style="color: black;">&#40;</span>msg<span style="color: black;">&#91;</span><span style="color: #483d8b;">'date'</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
                    <span style="color: #ff7700;font-weight:bold;">if</span> msg.<span style="color: black;">has_key</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'message-id'</span><span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">and</span> msg<span style="color: black;">&#91;</span><span style="color: #483d8b;">'message-id'</span><span style="color: black;">&#93;</span>:
                        query += <span style="color: #483d8b;">' HEADER MESSAGE-ID &quot;{0}&quot;'</span>.<span style="color: black;">format</span><span style="color: black;">&#40;</span>utf7encode<span style="color: black;">&#40;</span>msg<span style="color: black;">&#91;</span><span style="color: #483d8b;">'message-id'</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
                    r = imap.<span style="color: black;">search</span><span style="color: black;">&#40;</span><span style="color: #008000;">None</span>, <span style="color: #483d8b;">'({0})'</span>.<span style="color: black;">format</span><span style="color: black;">&#40;</span>query<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
                    <span style="color: #ff7700;font-weight:bold;">if</span> r<span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> <span style="color: #ff7700;font-weight:bold;">and</span> <span style="color: #ff7700;font-weight:bold;">not</span> args.<span style="color: black;">force</span>:
                        <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;skipping &quot;</span>+<span style="color: #dc143c;">mailbox</span>+<span style="color: #483d8b;">&quot;: '&quot;</span>+headerToUnicode<span style="color: black;">&#40;</span>msg<span style="color: black;">&#91;</span><span style="color: #483d8b;">'subject'</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span>:<span style="color: #ff4500;">20</span><span style="color: black;">&#93;</span>+<span style="color: #483d8b;">&quot;' (mid: &quot;</span>+<span style="color: #008000;">str</span><span style="color: black;">&#40;</span>msg<span style="color: black;">&#91;</span><span style="color: #483d8b;">'message-id'</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>+<span style="color: #483d8b;">&quot;)&quot;</span>
                        <span style="color: #ff7700;font-weight:bold;">continue</span>
&nbsp;
                    r = imap.<span style="color: black;">append</span><span style="color: black;">&#40;</span>mailbox_encoded, <span style="color: #483d8b;">''</span>, <span style="color: #dc143c;">imaplib</span>.<span style="color: black;">Time2Internaldate</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">time</span>.<span style="color: #dc143c;">time</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>, <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>msg<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
                    <span style="color: #ff7700;font-weight:bold;">if</span> r<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> <span style="color: #66cc66;">!</span>= <span style="color: #483d8b;">'OK'</span>:
                        <span style="color: #dc143c;">sys</span>.<span style="color: black;">stderr</span>.<span style="color: black;">write</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;failed to import {0} ({1}): {2}&quot;</span>.<span style="color: black;">format</span><span style="color: black;">&#40;</span>msg<span style="color: black;">&#91;</span><span style="color: #483d8b;">'message-id'</span><span style="color: black;">&#93;</span>, msg<span style="color: black;">&#91;</span><span style="color: #483d8b;">'date'</span><span style="color: black;">&#93;</span>, r<span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
                        <span style="color: #ff7700;font-weight:bold;">continue</span>
                    num = <span style="color: #dc143c;">re</span>.<span style="color: black;">sub</span><span style="color: black;">&#40;</span>r<span style="color: #483d8b;">'.*APPENDUID <span style="color: #000099; font-weight: bold;">\d</span>+ (<span style="color: #000099; font-weight: bold;">\d</span>+).*'</span>, r<span style="color: #483d8b;">'<span style="color: #000099; font-weight: bold;">\1</span>'</span>, r<span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
                    r = imap.<span style="color: black;">uid</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'STORE'</span>, <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>num<span style="color: black;">&#41;</span>, <span style="color: #483d8b;">&quot;FLAGS&quot;</span>, imapFlagsFromMbox<span style="color: black;">&#40;</span>msg.<span style="color: black;">get_flags</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
                    <span style="color: #ff7700;font-weight:bold;">if</span> r<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> <span style="color: #66cc66;">!</span>= <span style="color: #483d8b;">'OK'</span>:
                        <span style="color: #dc143c;">sys</span>.<span style="color: black;">stderr</span>.<span style="color: black;">write</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;failed to set flags for msg {0} in {1}&quot;</span>.<span style="color: black;">format</span><span style="color: black;">&#40;</span>num, <span style="color: #dc143c;">mailbox</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
    imap.<span style="color: black;">logout</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">if</span> __name__ == <span style="color: #483d8b;">'__main__'</span>:
    main<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>Another useful automation is using the mappings file, which looks something like</p>

<div class="wp_syntax"><div class="code"><pre class="json" style="font-family:monospace;">{
&quot;Deleted items&quot;: &quot;Trash&quot;,
&quot;Sent items&quot;: &quot;Sent&quot;
}</pre></div></div>

<p>to automatically import in the right destinations, in case you have a standardized structure.</p>
]]></content:encoded>
			<wfw:commentRss>http://costela.net/2011/06/importing-an-outlook-pst-into-imap/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Yeah, about that&#8230;</title>
		<link>http://costela.net/2010/02/yeah-about-that/</link>
		<comments>http://costela.net/2010/02/yeah-about-that/#comments</comments>
		<pubDate>Wed, 03 Feb 2010 17:23:56 +0000</pubDate>
		<dc:creator>Leo Antunes</dc:creator>
				<category><![CDATA[Home]]></category>
		<category><![CDATA[complaint]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[debian planet]]></category>
		<category><![CDATA[fosdem]]></category>

		<guid isPermaLink="false">http://costela.net/?p=563</guid>
		<description><![CDATA[I was trying not to complain about it, but now that the number of people asking me about it is getting bigger, my frustration got the best of me. So unfortunately I won&#8217;t see you all there.]]></description>
			<content:encoded><![CDATA[<p>I was trying not to complain about it, but now that the number of people asking me about it is getting bigger, my frustration got the best of me.</p>
<p><img src="/files/not-going-to.png" alt="I'm NOT going to FOSDEM 2010" class="aligncenter size-full wp-image-564" /></p>
<p>So unfortunately I won&#8217;t see you all there.</p>
]]></content:encoded>
			<wfw:commentRss>http://costela.net/2010/02/yeah-about-that/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Re: Making pbuilder just that little bit faster</title>
		<link>http://costela.net/2009/12/re-making-pbuilder-just-that-little-bit-faster/</link>
		<comments>http://costela.net/2009/12/re-making-pbuilder-just-that-little-bit-faster/#comments</comments>
		<pubDate>Tue, 29 Dec 2009 22:45:33 +0000</pubDate>
		<dc:creator>Leo Antunes</dc:creator>
				<category><![CDATA[Home]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[debian planet]]></category>
		<category><![CDATA[pbuilder]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://costela.net/?p=528</guid>
		<description><![CDATA[Absolutely, but there are at least two workarounds: Adding BINDMOUNTS=&#34;/var/cache/apt/archives&#34; APTCACHE=&#34;&#34; to your .pbuilderrc, in case you don&#8217;t need any special separation of local and pbuilder caches (that&#8217;s my case). Using apt-proxy or the like, which has its overhead, but also its other advantages. None of them seem all that bad to me, considering the [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.wgdd.de/?p=74">Absolutely</a>, but there are at least two workarounds:</p>
<ol>
<li>Adding

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">BINDMOUNTS</span>=<span style="color: #ff0000;">&quot;/var/cache/apt/archives&quot;</span>
<span style="color: #007800;">APTCACHE</span>=<span style="color: #ff0000;">&quot;&quot;</span></pre></div></div>

<p> to your .pbuilderrc, in case you don&#8217;t need any special separation of local and pbuilder caches (that&#8217;s my case).</li>
<li>Using apt-proxy or the like, which has its overhead, but also its other advantages.</li>
</ol>
<p>None of them seem all that bad to me, considering the sensible speed improvements to pbuilder, but the ultimate decision probably depends on the amount of disk-access the packages in question need.</p>
]]></content:encoded>
			<wfw:commentRss>http://costela.net/2009/12/re-making-pbuilder-just-that-little-bit-faster/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Notes on the Google Chrome&#8482; Debian package</title>
		<link>http://costela.net/2009/12/notes-on-the-google-chrome-debian-package/</link>
		<comments>http://costela.net/2009/12/notes-on-the-google-chrome-debian-package/#comments</comments>
		<pubDate>Tue, 08 Dec 2009 21:23:41 +0000</pubDate>
		<dc:creator>Leo Antunes</dc:creator>
				<category><![CDATA[Home]]></category>
		<category><![CDATA[chrome]]></category>
		<category><![CDATA[chromium]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[debian planet]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[packaging]]></category>

		<guid isPermaLink="false">http://costela.net/?p=501</guid>
		<description><![CDATA[Just some quick superficial observations on the Debian/Ubuntu package distributed by Google: Most files are installed in /opt/google/. It attempts to patch /usr/share/gnome-control-center/gnome-default-applications.xml on postinst (maybe legacy compatibility? Someone with more gnome-fu than me care to explain?). The postinst also automatically adds a souce for updates to /etc/apt/sources.list.d and an archive key (this is IMHO [...]]]></description>
			<content:encoded><![CDATA[<p>Just some quick superficial observations on the Debian/Ubuntu package <a href="http://www.google.com/chrome?platform=linux">distributed by Google</a>:</p>
<ul>
<li>Most files are installed in <em>/opt/google/</em>.</li>
<li>It attempts to patch <em>/usr/share/gnome-control-center/gnome-default-applications.xml</em> on postinst (maybe legacy compatibility? Someone with more gnome-fu than me care to explain?).</li>
<li>The postinst also automatically adds a souce for updates to <em>/etc/apt/sources.list.d</em> and an archive key (this is IMHO the worst part)</li>
<li>It includes a daily cronjob that &#8211; at least at first glance &#8211; tries to do the same things the postinst did (new apt source, archive key, etc) and some further archive configuration. The cron script is called at the end of postinst.</li>
<li>A casual look at objdump suggests it&#8217;s statically linked to <a href="http://code.google.com/p/v8/">libv8</a></li>
<li>On a slightly more positive note, it at least seems to successfully undo most of the changes once removed, with the exception of the added archive key and the above mentioned patch to gnome&#8217;s default apps list (that is: if there&#8217;s any situation it actually gets applied).</li>
</ul>
<p>I understand it might be too much hassle doing it the right way (from the corporate POV), but then why not simply cooperate a bit more with the community? Hopefully they&#8217;ll accept some criticism and suggestions.<br />
Or even better: they could simply reuse all the <a href="http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=520324">work being done to officially package Chromium</a>.</p>
<p><strong style="color:red;">UPDATE</strong>: forgot to mention that the version string (something like &#8220;4.0.249.43-r34537&#8243;) doesn&#8217;t follow policy. Not a huge deal for a non-distributable package, but in the name of forward-compatibility &#8211; if Chrome ever becomes fully open-source &#8211; it could be smart to adopt something like &#8220;4.0.249.43-0.x&#8221;.</p>
]]></content:encoded>
			<wfw:commentRss>http://costela.net/2009/12/notes-on-the-google-chrome-debian-package/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Nationality wars</title>
		<link>http://costela.net/2009/10/nationality-wars/</link>
		<comments>http://costela.net/2009/10/nationality-wars/#comments</comments>
		<pubDate>Thu, 01 Oct 2009 12:45:25 +0000</pubDate>
		<dc:creator>Leo Antunes</dc:creator>
				<category><![CDATA[Home]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[debian planet]]></category>
		<category><![CDATA[nationality]]></category>
		<category><![CDATA[statistics]]></category>
		<category><![CDATA[useless]]></category>

		<guid isPermaLink="false">http://costela.net/?p=459</guid>
		<description><![CDATA[After seeing bubulle&#8217;s post on the statistics per country in Debian I started wondering about how the statistics were made. They probably take into consideration the Country field in the LDAP, but this seems a bit off since there&#8217;s a considerable number of DDs living abroad. This hit me since I should probably count as [...]]]></description>
			<content:encoded><![CDATA[<p>After seeing <a href="http://www.perrier.eu.org/weblog/2009/10/01#devel-countries">bubulle&#8217;s post on the statistics per country in Debian</a> I started wondering about how the statistics were made. They probably take into consideration the Country field in the LDAP, but this seems a bit off since there&#8217;s a considerable number of DDs living abroad.<br />
This hit me since I should probably count as BR, but live in DE. I&#8217;m personally skewing the statistics!</p>
<p>I know this is totally meaningless, but perhaps we could add a &#8220;nationality&#8221; field to the LDAP, just to make the competition a bit more precise! ;)</p>
]]></content:encoded>
			<wfw:commentRss>http://costela.net/2009/10/nationality-wars/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>

