<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

  <title><![CDATA[Foobacca]]></title>
  <link href="https://foobacca.co.uk/atom.xml" rel="self"/>
  <link href="https://foobacca.co.uk/"/>
  <updated>2017-06-13T20:59:55+01:00</updated>
  <id>https://foobacca.co.uk/</id>
  <author>
    <name><![CDATA[Hamish Downer]]></name>
    
  </author>
  <generator uri="http://octopress.org/">Octopress</generator>

  
  <entry>
    <title type="html"><![CDATA[Books read in 2015]]></title>
    <link href="https://foobacca.co.uk/blog/2016/01/books-read-in-2015/"/>
    <updated>2016-01-29T21:51:00+00:00</updated>
    <id>https://foobacca.co.uk/blog/2016/01/books-read-in-2015</id>
    <content type="html"><![CDATA[<p>Inspired by <a href="http://markos.gaivo.net/articles/books-i-read-in-2015.html">my friend&rsquo;s regular year of books posts</a> I thought I might write down what I read in 2015.</p>

<p>I&rsquo;ve got back into reading books a bit more this year, and one of the key things I&rsquo;ve done is decide not to read the internet at certain times &ndash; over breakfast being one of the key times.  And I had a 2 week holiday in Scotland doing a litle light walking and a lot of reading :)</p>

<p>Anyway, here are the books by theme:</p>

<h2>Pregnancy</h2>

<p>My partner became pregnant in 2015 so we of course read quite a bit about the process.</p>

<p>&ldquo;<a href="http://www.cartoonkate.co.uk/bump-how-to-make-grow-and-birth-a-baby/">Bump &ndash; How to make, grow and birth a baby</a>&rdquo; and &ldquo;<a href="http://www.cartoonkate.co.uk/the-food-of-love/">The Food of Love</a>&rdquo; (about breastfeeding) &ndash; both by the awesome Kate Evans.  She has a lot of sound advice (mostly backed up by evidence), a lovely voice and some very funny cartoons.  It&rsquo;s the only book I&rsquo;ve seen that explicitly acknowledges lesbian couples throughout the book.  And the voice is by turns caring, witty and always supportive.  Highly recommended if you&rsquo;re heading that way or thinking about heading that way.</p>

<p><a href="http://www.lindageddes.com/books">Bumpology</a> is the book when you&rsquo;re getting tired or bewildered by all the conflicting advice you&rsquo;ll read, be told etc.  Written by a journalist for the New Scientist, this book is all about the evidence.  And refreshingly she presents the numbers involved in studies and translates risk into phrases like &ldquo;so it would require 5000 woman to stop doing X to prevent one still birth&rdquo;.  Very nice.</p>

<h2>Politics, History etc</h2>

<p><a href="http://www.amazon.co.uk/The-Joy-Tax-Richard-Murphy/dp/059307517X">The Joy of Tax</a> by Richard Murphy takes a fairly radical look at taxation and the part it makes in the modern state and economy. He explains that governments start by spending money and putting it into the economy, and tax is then used to regulate the money supply, enourage or discourage behaviour and a few other broad purposes.  Once you take on that view, it changes a lot of how you look at government, deficits and the rest.  A lot of his ideas have been used to make Corbynomics and I&rsquo;m very happy to see the terms of the economic debate being greatly widened.  Well worth a read for a very different perspective to the usual neoliberal one.</p>

<p>The Great War for Civilisation by Robert Fisk is an epic history of the Middle East.  Fisk pulls no punches, and consequently the read borders on the traumatic for periods.  I put it down after one section detailing how one state had tortured various dissidents over time.  I&rsquo;ll pick it up again, but it&rsquo;s a hard read at times.</p>

<h2>Science, Tech, Work</h2>

<p>Irrationality by Stuart Sutherland is a classic about the many ways the brain makes shortcuts that often serve as well, but in the modern world often lead us astray.  It&rsquo;s a fascinating read, but you&rsquo;ll probably remain just as irrational after reading it.</p>

<p><a href="http://www.poodr.com/book/">Practical Object Oriented Design in Ruby</a> by Sandi Metz is a great book.  She is a wonderful communicator and a great programmer &ndash; look up <a href="https://www.youtube.com/results?search_query=sandi+metz">her talks on youtube</a> sometime, they&rsquo;re excellent.  The book has really made me look afresh at the code I write, highly recommended.</p>

<p><a href="https://www.twoscoopspress.com/products/two-scoops-of-django-1-8">2 Scoops of Django 1.8</a> is a collection of best practices for using the Django web framework, written by a couple who have been in the core of the Django community for many years.  Nothing earth shattering in there, but lots of solid stuff.  Generally, I&rsquo;d start with their recommendations and only change if there is a good reason.</p>

<p>Refactoring by Martin Fowler is one of those classics where the word has become part of the lexicon and then used and abused by all and sundry.  It is interesting to read the definition as &ldquo;changing the internals of the code without changing the external behaviour&rdquo;.  So the idea is to get all the tests passing, and <strong>then</strong> refactor the code to improve it.  You may well improve it in a way that will make the next feature easy, but you&rsquo;re not making the change at that point.  As Kent Beck puts it &ldquo;<a href="https://twitter.com/kentbeck/status/250733358307500032">for each desired change, make the change easy (warning: this may be hard), then make the easy change</a>&rdquo;.  The refactorings presented are generally pretty low level, leading to a fine grained style of refactoring.</p>

<p>SMACSS is a way to organise your CSS.  God knows I need a better way to do this, though since reading it I&rsquo;ve not done much CSS.  I shall try to pick it up again when I do get back there.</p>

<p>Rolling Rocks Downhill and The Phoenix Project are both novels about project management in an IT setting &ndash; the first more focussed on software development, the second more on Ops and DevOps.  I&rsquo;m not sure they&rsquo;re the highest forms of literature, but they&rsquo;re surprisingly good page turners, and have plenty of good ideas for making projects run smoother.</p>

<p>Never Check Email in the Morning was recommended on a blog I respect.  The style is relentlessly positive American business which can be a bit much.  But the content is generally sound, so if you&rsquo;re struggling to manage to keep on top of your work, you may well get some value out of this book.</p>

<h2>Fiction</h2>

<p>This year I read the first 3 of the Enders series &ndash; Enders Game, Speaker for the Dead, Xenocide.  Fantastic sci-fi that gets beyond the initial premise into deep relationships, well formed characters and difficult quandaries.  The first book has less of that, but it&rsquo;s really the kicking off point for some sudden changes of gear.  I won&rsquo;t spoil things by talking about the plot.</p>

<p>The Endless War is another classic sci-fi, looking at long wars and adapting back to society afterwards.  I enjoyed it but it&rsquo;s not one of the greatest I&rsquo;ve read.  Ancillary Justice is a more recent sci-fi that has a different take on the world with a fairly amoral society producing a remnant of a warship looking for revenge.  It feels pretty fresh.</p>

<p>The Circle by Dave Eggers is a near future distopia involving some sort of combination of Google and Facebook called The Circle.  Quite disturbing, if a little heavy handed in places.  &ldquo;Sharing is Caring.&rdquo;</p>

<p>I also came back (again) to Neil Gaiman, re-reading the lovely American Gods, really enjoying the prequel &ldquo;Sandman Overture&rdquo; &ndash; fantastic artwork and ideas &ndash; and also the beautifully illustrated &ldquo;Sleeper and the Spindle&rdquo;.</p>

<p>Nothing buddhist in 2015, which is unusual for me.  We&rsquo;ll see how I feel in 2016, though with a baby arriving imminently I may end up with less reading time &hellip;</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Dell XPS 15]]></title>
    <link href="https://foobacca.co.uk/blog/2015/03/dell-xps-15/"/>
    <updated>2015-03-28T10:48:00+00:00</updated>
    <id>https://foobacca.co.uk/blog/2015/03/dell-xps-15</id>
    <content type="html"><![CDATA[<h1>Getting Ubuntu 15.04 set up on a Dell XPS 15 (9530)</h1>

<h2>HiDPI</h2>

<p>The Dell XPS 15 has a gorgeous screen, 15&#8221;, 3200x1800.  This means that things can appear very small.  Here are the things I did to make it usable.</p>

<ul>
<li>the <a href="http://askubuntu.com/a/462023/150">display settings have a scaling slider</a> &ndash; from 1.5 to 2 should work OK.</li>
<li>firefox &ndash; you need to open <code>about:config</code> and change the value of <code>layout.css.devPixelsPerPx</code> to between 1.5 and 2.</li>
<li>chrome &ndash; todo</li>
</ul>


<p>Then there are the parts outside of the X display &ndash; grub and the console, which I like to be usable:</p>

<h3>grub</h3>

<p>Stealing from <a href="http://www.obeythetestinggoat.com/ot-hidpi-on-ubuntu-with-a-samsung-ativ-9.html">the testing goat HiDPI post</a>:</p>

<blockquote><p>You&rsquo;ll have noticed that the GRUB boot menu is in a ridiculously small font because of all our teeny-tiny pixels. Fix it by generating a new font in 30-point:</p>

<pre><code>sudo grub-mkfont -s 30 -o /boot/grub/DejaVuSansMono.pf2 /usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf
</code></pre>

<p>DejaVu works well because it has all the glyphs for the line art, others may not work so well.</p>

<p>Edit <code>/etc/default/grub</code> and add a line saying <code>GRUB_FONT=/boot/grub/DejaVuSansMono.pf2</code>, and run <code>update-grub</code> to commit.</p></blockquote>

<h3>TTY console</h3>

<p>Stealing more from <a href="http://www.obeythetestinggoat.com/ot-hidpi-on-ubuntu-with-a-samsung-ativ-9.html">the testing goat HiDPI post</a>:</p>

<blockquote><p>One final thing that&rsquo;s pretty much unusable out of the box are the TTY consoles you get from pressing, eg, CTRL+ALT+F1. To change their font, you&rsquo;ll want to do a:</p>

<pre><code>sudo dpkg-reconfigure console-setup
</code></pre>

<p>I picked the VGA font in 32x16, and it looks fine, if somewhat retro.</p></blockquote>

<h2>Touchpad Middle Button</h2>

<p>The touchpad worked pretty well out of the box.  Two finger scrolling was smooth, but &hellip;</p>

<p>I really like using the middle button in Linux, for pasting selected text, opening links in a new browser tab, closing browser tabs &hellip;  But I couldn&rsquo;t find a way to make it work.  Various people mentioned that the top right corner of the touchpad/clickpad should work, but it didn&rsquo;t for me.  Eventually I worked out how to do it with synclient.  First I had to look up all the sizes of stuff.  It&rsquo;s a long list, but here are the relevant results:</p>

<pre><code>$ synclient -l
Parameter settings:
    LeftEdge                = 1765
    RightEdge               = 5367
    TopEdge                 = 1634
    BottomEdge              = 4420
# lots of stuff
    RightButtonAreaLeft     = 3566
    RightButtonAreaRight    = 0
    RightButtonAreaTop      = 4063
    RightButtonAreaBottom   = 0
    MiddleButtonAreaLeft    = 0
    MiddleButtonAreaRight   = 0
    MiddleButtonAreaTop     = 0
    MiddleButtonAreaBottom  = 0
</code></pre>

<p>And realised I might be able to set the <code>MiddleButtonArea*</code> settings, and it did indeed work.  I created a file, <code>~/bin/touchpad_settings.sh</code> with the following contents:</p>

<pre><code>#!/bin/sh
# set up the top right corner as middle button
synclient MiddleButtonAreaBottom=2000
synclient MiddleButtonAreaLeft=3566
</code></pre>

<p>Then in the shell:</p>

<pre><code>$ chmod +x ~/bin/touchpad_settings.sh
$ gsettings set org.gnome.settings-daemon.peripherals.input-devices hotplug-command "/home/hamish/bin/touchpad_settings.sh"
</code></pre>

<p>The second command means that it should be <a href="http://askubuntu.com/a/156545">re-applied on boot and when waking from sleep</a>.</p>

<h2>Swapping Caps Lock and Escape</h2>

<p>The easy way of doing this through the standard keyboard settings has been removed, sadly.  So I installed <code>gnome-tweak-tool</code> and found the settings in there.  <a href="http://askubuntu.com/a/446725/150">See screenshots of keyboard settings</a>.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Custom reports with notmuch]]></title>
    <link href="https://foobacca.co.uk/blog/2013/07/custom-reports-with-notmuch/"/>
    <updated>2013-07-20T15:23:00+01:00</updated>
    <id>https://foobacca.co.uk/blog/2013/07/custom-reports-with-notmuch</id>
    <content type="html"><![CDATA[<p>It&rsquo;s just a little thing, but I like to see counts of messages in certain categories.  As notmuch provides a count command, it is simple to write a script that will provide you with the counts you want.  Here&rsquo;s one I prepared earlier:</p>

<pre><code>#!/bin/sh

# I'm interested in the thread count rather than individual messages
NMC="/usr/bin/notmuch count --output=threads"

# I break it down by total, how many are flagged and how many are unread
# This function produces a single line
function tag_report(){
  TAG=$1
  TOTAL_COUNT=$($NMC tag:$TAG)
  FLAGGED_COUNT=$($NMC tag:$TAG AND tag:flagged)
  UNREAD_COUNT=$($NMC tag:$TAG AND tag:unread)

  echo "$TAG: total $TOTAL_COUNT flagged $FLAGGED_COUNT unread $UNREAD_COUNT"
}

# then these are the tags I'm interested in, so print the reports
# one line per tag
function full_report(){
  tag_report inbox
  tag_report action
  tag_report waiting
  tag_report readlater
}

# finally, pipe through column to make the results line up nicely
full_report | column -t
</code></pre>

<p>I&rsquo;ve chosen to do this by having a small tmux window above my mail client, using <code>watch</code> to refresh.  The command I use is:</p>

<pre><code>watch -t -n 300 bin/mailreport
</code></pre>

<p>The <code>-t</code> means don&rsquo;t bother showing the time (saving a line of output) and the <code>-n 300</code> means only run the report once every 5 minutes.  The output (currently) looks like:</p>

<pre><code>inbox:      total  28  flagged  4  unread  0
action:     total  55  flagged  4  unread  11
waiting:    total  13  flagged  2  unread  1
readlater:  total  60  flagged  2  unread  3
</code></pre>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Matching headers with regular expressions using afew]]></title>
    <link href="https://foobacca.co.uk/blog/2013/07/matching-headers-with-regular-expressions-using-afew/"/>
    <updated>2013-07-15T22:43:00+01:00</updated>
    <id>https://foobacca.co.uk/blog/2013/07/matching-headers-with-regular-expressions-using-afew</id>
    <content type="html"><![CDATA[<p><em>This post is part of my <a href="https://foobacca.co.uk/blog/2013/03/notmuch/">notmuch of a journey series</a></em>.</p>

<p>notmuch is somewhat limited in the choice of headers it processes, despite that being <a href="http://notmuchmail.org/pipermail/notmuch/2012/012501.html">an oft requested feature</a>.  However afew parses the entire email itself so it can do what it likes.</p>

<p>The recently added HeaderMatchingFilter will match a regular expression you provide against an arbitrary header you specify.  The text matched can be used as the tag.  A simple version of the <a href="https://afew.readthedocs.org/en/latest/filters.html#listmailsfilter">ListMailsFilter</a> could be implemented as:</p>

<pre><code>[HeaderMatchingFilter.1]
header = List-Id
pattern = &lt;(?P&lt;list_id&gt;.*)&gt;
tags = +lists +{list_id}
</code></pre>

<p>So if the <code>List-Id</code> header field is found, and it starts and ends with <code>&lt;&gt;</code> then the contents will be used as a tag, and in addition the tag <code>list_id</code> will be added to the message.</p>

<p>My initial motivation was that we use email addresses of the form:</p>

<pre><code>&lt;projectname&gt;-team@aptivate.org
</code></pre>

<p>for various projects, so I wanted to use the <code>projectname</code> as the tag without having to write a filter for every project.  With HeaderMatchingFilter I can do:</p>

<pre><code>[HeaderMatchingFilter.1]
header = To
pattern = (?P&lt;team_name&gt;[a-z0-9]+)-team@aptivate.org
tags = +{team_name}

[HeaderMatchingFilter.2]
header = Cc
pattern = (?P&lt;team_name&gt;[a-z0-9]+)-team@aptivate.org
tags = +{team_name}
</code></pre>

<p>Also, we use redmine heavily.  It adds a header saying what project the email is associated with.  I can use that by doing:</p>

<pre><code>[HeaderMatchingFilter.3]
header = X-Redmine-Project
pattern = (?P&lt;project&gt;.*)
tags = +{project}
</code></pre>

<p>On a related note, I have now written more <a href="https://afew.readthedocs.org/en/latest/manual.html">documentation for afew</a>, so hopefully the path after me will be smoother.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[initial tagging and afew]]></title>
    <link href="https://foobacca.co.uk/blog/2013/04/initial-tagging-and-afew/"/>
    <updated>2013-04-01T09:00:00+01:00</updated>
    <id>https://foobacca.co.uk/blog/2013/04/initial-tagging-and-afew</id>
    <content type="html"><![CDATA[<p><em>This post is part of my <a href="https://foobacca.co.uk/blog/2013/03/notmuch/">notmuch of a journey series</a></em>.</p>

<p>I love the way gmail uses labels and I loved using them in sup.  notmuch has tags for the same purpose so I want to use them extensively, and to have most tags added automatically for me.</p>

<h2>notmuch new mail workflow</h2>

<p>There are several ways to do this, but the way I&rsquo;ve done it is:</p>

<ul>
<li>offlineimap runs every X minutes</li>
<li>the offlineimap <code>postsynchook</code> is set to <code>notmuch new</code> &ndash; so when the IMAP run is complete, notmuch is called</li>
<li>notmuch new processes all the email it doesn&rsquo;t know about, adding a set of tags to every new message</li>
<li>notmuch then checks for the file <code>&lt;maildir&gt;/.notmuch/hooks/post-new</code> and if it exists then it will run it</li>
<li>in my case, the hook file calls <code>afew --new --tag</code></li>
</ul>


<p>The tags added by <code>notmuch new</code> are set in the notmuch config file, in the part that looks like:</p>

<pre><code>[new]
tags=new
</code></pre>

<p>So all new messages will have those tags added.  Your <code>post-new</code> hook can then run only against mail that is tagged &ldquo;new&rdquo;, making it nice and fast.  And as the final step, the <code>post-new</code> hooks should remove the &ldquo;new&rdquo; tag from all messages that have it, so that you don&rsquo;t have to re-process them next time.  A common idea is also to remove the &ldquo;new&rdquo; tag from messages that match filters you want to archive, and at the end of your filter list you replace the &ldquo;new&rdquo; tag with the &ldquo;inbox&rdquo; tag for any messages still tagged &ldquo;new&rdquo;.</p>

<p>You can do this with a basic shell script that calls the notmuch command line binary, as shown on the <a href="http://notmuchmail.org/initial_tagging/">notmuch initial tagging page</a>.  However the command line binary only looks at a few headers (From, To, Cc, Subject, Date and message ID as far as I can tell).  So I thought I&rsquo;d look into:</p>

<h2>afew</h2>

<p><a href="https://github.com/teythoon/afew">afew</a> is a python command that will run filters against a set of messages and generate tags.  I can install it using pip.  However, at the time of writing the <a href="https://afew.readthedocs.org/en/latest/manual.html">documentation</a> is not as useful as it could be.  I ended up reading the code to work out what was going on.</p>

<p>One key bit of information is that the config files are stored in <code>~/.config/afew/config</code> which meant I could search github for <a href="https://github.com/search?q=path%3Aafew%2Fconfig&amp;type=Code&amp;ref=advsearch&amp;l=">path:afew/config</a> &ndash; which only brought up two hits when I just tried it, but that&rsquo;s a start to see what others do.  The most useful one I found was by <a href="https://github.com/pazz/configs/blob/master/.config/afew/config">pazz</a> and you might also want to look at <a href="https://github.com/foobacca/dotfiles/blob/master/afew/config">my afew config</a>.</p>

<p>When you&rsquo;re playing with afew, running <code>afew --help</code> will get you started reasonably.  And the command you want for the <code>post-new</code> hook is:</p>

<pre><code>afew --tag --new
</code></pre>

<p>Which will run against the new messages and run the tag filters.</p>

<h2>afew filters</h2>

<p>I had to read the code to work out what some of the filters were, so here are my findings as a first stab at documenting them.  Later I intend to improve the docs.</p>

<h3>afew&rsquo;s built in filters</h3>

<p>The default filter set (if you don&rsquo;t specify anything in the config) is:</p>

<pre><code>[SpamFilter]
[ClassifyingFilter]
[KillThreadsFilter]
[ListMailsFilter]
[ArchiveSentMailsFilter]
[InboxFilter]
</code></pre>

<p>These can be customised by specifying settings beneath them.  The standard settings are:</p>

<ul>
<li><code>message</code> &ndash; text that will be displayed while running this filter if the verbosity is high enough.</li>
<li><code>query</code> &ndash; the query to use against the messages, specified in standard notmuch format</li>
<li><code>tags</code> &ndash; the tags to add to messages that match the query</li>
<li><code>tag_blacklist</code> &ndash; if the message has one of these tags, don&rsquo;t add <code>tags</code> to it</li>
</ul>


<p>Note that most of the filters below set their own value for message, query and/or tags, and some ignore some of the above settings.</p>

<h4>SpamFilter</h4>

<p>This looks for the header <code>X-Spam-Flag</code> &ndash; if it finds it, the <code>spam</code> tag is set.  You can override the tag used for spam if you want.</p>

<p>The settings you can use are:</p>

<ul>
<li><code>spam_tag</code> is the tag used to identify spam. It defaults to &ldquo;spam&rdquo;</li>
</ul>


<h4>ClassifyingFilter</h4>

<p>This is to do with learning what tags match what without explicit rules.  I haven&rsquo;t worked this one out fully, but the project README has some details on how to use it.  If I work out more I&rsquo;ll blog about and link to that from here.</p>

<h4>KillThreadsFilter</h4>

<p>If the new message has been added to a thread that has already been tagged &ldquo;killed&rdquo; then add the &ldquo;killed&rdquo; tag to this message.  This allows for ignoring all replies to a particular thread.</p>

<h4>ListMailsFilter</h4>

<p>This filter looks for the <code>List-Id</code> header, and if it finds it, adds the list name as a tag, together with the tag &ldquo;lists&rdquo;.</p>

<h4>ArchiveSentMailsFilter</h4>

<p>Basically does what says it on the tin.  Though more accurately, it looks for emails that are from one of your addresses <em>and not</em> to any of your addresses.  It then adds the sent tag and removes the inbox tag.</p>

<h4>InboxFilter</h4>

<p>This removes the new tags, and adds the &ldquo;inbox&rdquo; tag to any message that isn&rsquo;t killed or spam.</p>

<h4>FolderNameFilter</h4>

<p>This looks at which folder each email is in and uses that name as a tag for the email.  So if you have a procmail or seive set up that puts emails in folders for you, this might be useful.</p>

<h3>Adding your own filters to afew</h3>

<p>You can modify filters, and define your own versions of the base Filter that allow you to tag messages in a similar way to the <code>notmuch tag</code> command, using the settings above.  Showing some sample configs is the easiest way to understand.  The <a href="http://notmuchmail.org/initial_tagging/">notmuch initial tagging page</a> shows a sample config:</p>

<pre><code># immediately archive all messages from "me"
notmuch tag -new -- tag:new and from:me@example.com

# delete all messages from a spammer:
notmuch tag +deleted -- tag:new and from:spam@spam.com

# tag all message from notmuch mailing list
notmuch tag +notmuch -- tag:new and to:notmuch@notmuchmail.org

# finally, retag all "new" messages "inbox" and "unread"
notmuch tag +inbox +unread -new -- tag:new
</code></pre>

<p>The equivalent in afew would be:</p>

<pre><code>[ArchiveSentMailsFilter]

[Filter.spamcom]
message = Delete all messages from spammer
query = from:spam@spam.com
tags = deleted;-new

[Filter.notmuch]
message = Tag all messages from the notmuch mailing list
query = to:notmuch@notmuchmail.org
tags = notmuch

[Filter.myinbox]
message = My version of the inbox filter
query = tag:new
tags = inbox;unread;-new
</code></pre>

<p>Not that the queries do not include <code>tag:new</code> because this is implied when afew is run with the <code>--new</code> flag.</p>

<p>Here are a few more example filters from github dotfiles:</p>

<pre><code>[Filter.1]
query = 'sicsa-students@sicsa.ac.uk'
tags = +sicsa
message = sicsa

[Filter.2]
query = 'from:foosoc.ed@gmail.com OR from:GT Silber OR from:lizzie.brough@eusa.ed.ac.uk'
tags = +soc;+foo
message = foosoc

[Filter.3]
query = 'folder:gmail/G+'
tags = +G+
message = gmail spam

# skip inbox
[Filter.6]
query = 'to:notmuch@notmuchmail.org AND (subject:emacs OR subject:elisp OR "(defun" OR "(setq" OR PATCH)'
tags = -inbox;-new
message = notmuch emacs stuff
</code></pre>

<p>If you need more powerful processing you can write filters that match regular expressions against any header in the email with the HeaderMatchingFilter, but more on that in a future blog post.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[python 2.7 on debian squeeze]]></title>
    <link href="https://foobacca.co.uk/blog/2013/03/python-2-dot-7-on-debian-squeeze/"/>
    <updated>2013-03-31T18:35:00+01:00</updated>
    <id>https://foobacca.co.uk/blog/2013/03/python-2-dot-7-on-debian-squeeze</id>
    <content type="html"><![CDATA[<p><em>This post is part of my <a href="https://foobacca.co.uk/blog/2013/03/notmuch/">notmuch of a journey series</a></em>.</p>

<p>There were various python libraries and apps I wanted to use, and <a href="https://github.com/teythoon/afew">afew</a> and <a href="https://github.com/pazz/alot/">alot</a> in particular requires python 2.7</p>

<p>I am running all this on a machine that is running Debian Squeeze which ships with python 2.6 and a little research reveals that it would be unwise to grab python 2.7 from testing/Wheezy as it will then become the system python and break lots of things.</p>

<p>But then I came across <a href="https://github.com/utahta/pythonbrew">pythonbrew</a> which is inspired by the ruby rvm &ndash; it allows you to install different versions of python inside your home directory.  However, doing this straight off might lead you to be missing some vital functionality related to compression or unicode (as I did the first couple of attempts).  So the debian packages to install (covering all the packages I need for my notmuch journey) are:</p>

<pre><code>sudo apt-get install build-essential libbz2-dev libc6-dev libexpat1-dev \
    libgcrypt11-dev libglib2.0-dev libgmime-2.4-dev libgpg-error-dev \
    libgpgme11-dev libncurses5-dev libncursesw5-dev libreadline-dev \
    libsqlite3-dev libssl-dev zlib1g-dev python-pip
sudo apt-get install -t testing libnotmuch-dev notmuch libnotmuch3
</code></pre>

<p>Then you can do:</p>

<pre><code>pip install pythonbrew
pythonbrew install 2.7.3
pythonbrew use 2.7.3   # this starts using python 2.7 in the current shell
</code></pre>

<p>I also wanted to have the notmuch python bindings, so I did:</p>

<pre><code>git clone git://notmuchmail.org/git/notmuch
cd notmuch/bindings/python
python setup.py install
</code></pre>

<p>At this point I was pretty much good to go, although I should also mention that you can save having to remember which version of python you are currently using by having wrapper scripts with contents like:</p>

<pre><code>#!/bin/sh
$HOME/.pythonbrew/pythons/Python-2.7.3/bin/alot $@
</code></pre>

<p>Finally, I also came across a fork of pythonbrew called <a href="https://github.com/saghul/pythonz">pythonz</a> that I may look into further at some point.  It support PyPy and Jython amongst others, but as it says in the README &ldquo;[pythonbrew] has some extra features which I don&rsquo;t really need, so I made this for to make something a bit simpler that works for me&rdquo; so some things might be broken &hellip;</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[offlineimap and msmtp]]></title>
    <link href="https://foobacca.co.uk/blog/2013/03/offlineimap-and-msmtp/"/>
    <updated>2013-03-31T16:52:00+01:00</updated>
    <id>https://foobacca.co.uk/blog/2013/03/offlineimap-and-msmtp</id>
    <content type="html"><![CDATA[<p><em>This post is part of my <a href="https://foobacca.co.uk/blog/2013/03/notmuch/">notmuch of a journey series</a></em>.</p>

<p>notmuch doesn&rsquo;t get my email or send it, so I&rsquo;m turning to two commonly used tools to help me with this.</p>

<ul>
<li><a href="http://docs.offlineimap.org/en/latest/MANUAL.html">offlineimap</a> fetches the email over IMAP (and syncs it back)</li>
<li><a href="http://msmtp.sourceforge.net/">msmtp</a> sends the email for me</li>
</ul>


<p>The set up I had is fairly standard, though a key issue was</p>

<h2>Password Storage</h2>

<p>I&rsquo;m running on a server and connecting over ssh, as I want the same set of tags to be available everywhere.  I don&rsquo;t want my password sitting on disk in clear text (particularly as it is my LDAP password, so used for <code>sudo</code>, <code>ssh</code> and various other logins).  There are various solutions to this if you are running a desktop &ndash; <a href="https://bitbucket.org/kang/python-keyring-lib">python-keyring-lib</a> will link to Gnome, KDE and OS X keyrings.  But it took a bit more searching to work out how to do this on a server.</p>

<p>I considered a number of options</p>

<h3>GPG encrypted file</h3>

<p>I found <a href="http://unix.stackexchange.com/a/48355/668">this unix stackexchage post</a> about having a python script that could decrypt a GPG encrypted file (one file per password).  gpg-agent would run on the server so you didn&rsquo;t have to enter your passphrase every time you need to run it.  I got this running, generating a GPG key that I wasn&rsquo;t actually going to use for email.  That meant I was OK setting a long time out for gpg-agent &ndash; I set it to 24 hours by putting the following in <code>~/.gnupg/gpg-agent.conf</code></p>

<pre><code>pinentry-program /usr/bin/pinentry-curses
default-cache-ttl 86400
max-cache-ttl 86400
</code></pre>

<p>However I wanted to be able to leave offlineimap running and at some point gpg-agent would expire, so this wasn&rsquo;t really what I wanted.</p>

<p>That said I did leave this system in place for msmtp, as that will only run when I send an email &ndash; so I will be logged in at that point and can enter my GPG passphrase into gpg-agent.  The relevant line for the <code>.msmtprc</code> file is:</p>

<pre><code>passwordeval gpg --use-agent --quiet --batch -d ~/.passwd/account.gpg
</code></pre>

<h3>Environment variables</h3>

<p>I found a <a href="https://blog.erroneousthoughts.org/461-2/">blog post describing caching the decrypted password in environment variables</a> which seemed quite cunning.  That would only survive for the session, but then I leave tmux running all the time, so as long as tmux survived, the environment variables would.  But then I thought, why not just:</p>

<h3>Leave offlineimap running in tmux</h3>

<p>When you run offlineimap, if there is no password or passwordeval in the <code>.offlineimaprc</code> file, then offlineimap will ask for your password (provided the ui isn&rsquo;t set to be Noninteractive).  offlineimap can also be told to run repeatedly, without exiting, by putting <code>autorefresh = 5</code> to re-run every 5 minutes.  In between runs, offlineimap will just sit at the terminal waiting, but it remembers your password, keeping it in memory.  Using this I could leave offlineimap running for months inside tmux on the server I use.</p>

<p>(Note that offlineimap will not ask for your password if the <code>ui</code> is set to be Noninteractive.  And the <code>autorefresh</code> setting must be in the <code>[Account X]</code> section &ndash; I put it in the Repository section originally which didn&rsquo;t work).</p>

<h3>ssh keys and offlineimap preauthtunnel</h3>

<p>Finally I worked out that I could talk directly to an imap command line utility on the remote server over ssh &ndash; using a passwordless ssh key to avoid any passwords.  offlineimap is instructed to use it by the <code>preauthtunnel</code> option.</p>

<p>There are two main IMAP servers in the linux world, courier and dovecot.  The relevant commands are:</p>

<pre><code># Courier IMAP (Debian - you should check the path on CentOS)
preauthtunnel = ssh -o Compression=yes -q IMAPHOST '/usr/bin/imapd ./Maildir'

# Dovecot IMAP (CentOS)
preauthtunnel = ssh -o Compression=yes -q IMAPHOST 'MAIL=maildir:~/Maildir exec /usr/libexec/dovecot/imap'
# Dovecot IMAP (Debian)
preauthtunnel = ssh -o Compression=yes -q IMAPHOST 'MAIL=maildir:~/Maildir exec /usr/lib/dovecot/imap'
</code></pre>

<p>Replace <code>IMAPHOST</code> and <code>~/Maildir</code> with your own values.</p>

<p>There are two ways to do this so that you don&rsquo;t have to enter the ssh key passphrase all the time.  You could set up a password-less ssh key to do this, or you could leave an ssh session running so that offlineimap can <a href="http://protempore.net/~calvins/howto/ssh-connection-sharing/">multiplex its connections</a> on to it.</p>

<p>A password-less ssh key leads to the possibility of abuse, but you can generate a new ssh key just for imap and specify it&rsquo;s use by modifying the above command to look like:</p>

<pre><code>preauthtunnel = ssh -q -i /home/hamish/.ssh/id_mail_imap -o Compression=yes IMAPHOST '/usr/libexec/dovecot/imap'
</code></pre>

<p>On the mail server side you can then lock down this key by configuring what command can be run in the <code>.ssh/authorized_keys</code> file.  Mine looks like:</p>

<pre><code>command="/usr/libexec/dovecot/imap",no-X11-forwarding,no-agent-forwarding,no-port-forwarding,no-pty ssh-dss AAAAB3Nza...
</code></pre>

<p>Obviously this will only work for you if you have ssh access to your mail server, so it won&rsquo;t be an option for all.  But I&rsquo;ve given some other options above, so I hope you can find something that works for you.</p>

<h2>Other notes</h2>

<h3>sendmail over ssh</h3>

<p>Another option for sending email to a remote server is to use the sendmail command over ssh (assuming you have ssh access to the server in question).  First you need to generate a passwordless ssh key and copy it to the mail server:</p>

<pre><code>ssh-keygen -t dsa -f ~/.ssh/id_mail_smtp
scp ~/.ssh/id_mail_smtp.pub smtpserver.example.org:.ssh/
</code></pre>

<p>Then, on the mail server, put the key in the authorized_keys file:</p>

<pre><code>cat ~/.ssh/id_mail_smtp.pub &gt;&gt; ~/.ssh/authorized_keys
</code></pre>

<p>Next we edit the authorized keys file, adding the command to run to the beginning of the last line (which is currently our smtp key):</p>

<pre><code>command="/usr/sbin/sendmail -bm -t -oem -oi",no-X11-forwarding,no-agent-forwarding,no-port-forwarding,no-pty ssh-dss AAA...
</code></pre>

<p>In this case the <code>command</code> is the sendmail command for exim &ndash; I&rsquo;m afraid you&rsquo;ll have to work out what your own sendmail command is.  Finally, in your mail client, tell it to use ssh as the sendmail command.  The following works for both mutt and alot:</p>

<pre><code>ssh -q -i /home/hamish/.ssh/id_mail_smtp smtpserver.example.org
</code></pre>

<p>Now whenever your mail client wants to send email, it will start up the ssh connection and print the email to it.  This will be picked up by the sendmail command on the far end and off the email will go.</p>

<h3>ssh ControlMaster</h3>

<p><code>ControlMaster</code> is an ssh option that means you can leave an ssh connection open with a master session, so that future ssh connections reuse the master session rather than having to start an entirely new connection.  This should mean quicker send and receive.  One way to specify it in your <code>~/.ssh/config</code> file is:</p>

<pre><code>ControlMaster auto
ControlPersist 4h
ControlPath /home/username/.ssh/muxcontrol/%r@%h:%p
</code></pre>

<p>This means that connections will be automatically started, will stick around for up to 4 hours, and the socket for your connection to <code>mail.example.com</code> on port 22 with username <code>user</code> would be at <code>/home/username/.ssh/muxcontrol/name@mail.example.com:22</code> (don&rsquo;t forget to create the directory).  (And the default directory is the global <code>/tmp</code> directory).</p>

<p>However a gotcha here is that the connection to the host will use whatever ssh key was used for the initial connection, not the one specified at the command line.  So if offlineimap runs first, using your ssh key tied to the imap command, then when you try to send an email using sendmail over ssh, then your ssh command will run imap rather than sendmail &ndash; and your email will go nowhere.</p>

<p>The solution is to specify a different <code>ControlPath</code> for these commands.  So for offlineimap you could use:</p>

<pre><code>preauthtunnel = ssh -o Compression=yes -o ControlPath=/home/username/.ssh/muxcontrol/IMAP_%r@%h:%p -q IMAPHOST 'MAIL=maildir:~/Maildir exec /usr/libexec/dovecot/imap'
</code></pre>

<p>and for sending:</p>

<pre><code>ssh -q -o ControlPath=/home/username/.ssh/muxcontrol/SMTP_%r@%h:%p -i /home/hamish/.ssh/id_mail_smtp smtpserver.example.org
</code></pre>

<p>This will keep more ssh connections active, but the right action will be done using your different ssh keys.</p>

<h3>Checking IMAP mailboxes</h3>

<p>I was moving folders around and was having trouble working out whether the folders were available but offlineimap was failing to find them, or if dovecot wasn&rsquo;t showing me the folders.  Eventually I found <a href="http://wiki.dovecot.org/MissingMailboxes">how to ask for a folder list over telnet</a>. In short:</p>

<pre><code>telnet imap.example.org 143
A login username password
B list "" *
C logout
</code></pre>

<p>(include the A, B, C).  Or to do this over ssl you could connect with:</p>

<pre><code>openssl s_client -connect mail.aptivate.org:993
</code></pre>

<p>and then run the above commands.</p>

<h3>Other ways of sending to multiple accounts</h3>

<p>In my research, I also found that you can set up <a href="http://paul.frields.org/2009/07/12/best-in-show/">postfix to use different servers for different accounts</a> (though I&rsquo;m not sure how well it would handle encrypted passwords) and I may improve my msmtp set up by using <a href="https://wiki.archlinux.org/index.php/Msmtp#Using_msmtp_offline">msmtp queue</a> at some point, and see how well it deals with encrypted passwords.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Notmuch of a journey]]></title>
    <link href="https://foobacca.co.uk/blog/2013/03/notmuch/"/>
    <updated>2013-03-31T15:26:00+01:00</updated>
    <id>https://foobacca.co.uk/blog/2013/03/notmuch</id>
    <content type="html"><![CDATA[<p>I recently decided to switch to using notmuch as a mail indexer.  I&rsquo;ve been a long time user of <a href="https://github.com/sup-heliotrope/sup">sup</a> and love the command line interface, gmail-like threads and awesome search.  However it can often be a bit cranky and slow, and it &ldquo;doesn&rsquo;t play well with others&rdquo; &ndash; if the mbox files it uses are modified (say by a second imap client) then it needs to rebuild it&rsquo;s index.  I could live with all those and used it for my work email for about three years.</p>

<p>The real nail in the coffin is that it has mostly died as a project (though there have been a few new people stepping up recently).  I have made quite a few commits to it over the years, and it gets the occasional bug fix, but the mailing list has dropped off to nothing over the years.  There was some excitement when the original author of sup, William Morgan, announced <a href="https://github.com/sup-heliotrope/heliotrope">heliotrope</a> and <a href="https://github.com/sup-heliotrope/turnsole">turnsole</a> as a client server version, but it never really gained traction.</p>

<p>So I decided to investigate <a href="http://notmuchmail.org/">notmuch</a> &ndash; which is basically a C program and library which takes your email and gives it to Xapian (a full text search database &ndash; also used by sup under the hood) and then runs queries against it.  But notmuch does &hellip; not much else, so I also need to fetch email, add the new emails to notmuch, run a mail client, send email and look up email addresses.</p>

<p>It&rsquo;s taken a lot of research and playing with various tools.  Some of those tools were great, but poorly documented, so part of the point of these blog posts is to give some info for other people to find.  And I might even get round to adding to the documentation for some of these projects.</p>

<p>So here are the parts &ndash; I&rsquo;ve put up a post about each major part, and all the small bits and links are part of this post.</p>

<ul>
<li>two copies of notmuch</li>
<li><a href="https://foobacca.co.uk/blog/2013/03/offlineimap-and-msmtp/">offlineimap and msmtp</a> &ndash; including the thorny issue of password storage on a headless server (hint: use single purpose password-less ssh keys).</li>
<li><a href="https://foobacca.co.uk/blog/2013/03/python-2-dot-7-on-debian-squeeze/">python 2.7 on debian squeeze</a> &ndash; pythonbrew, all dev libraries, pythonz (bit out of date now that wheezy is stable).</li>
<li><a href="https://foobacca.co.uk/blog/2013/03/initial-tagging-and-afew/">initial tagging and afew</a> &ndash; how to automatically add tags to new email.</li>
<li><a href="https://foobacca.co.uk/blog/2013/07/matching-headers-with-regular-expressions-using-afew/">adding a HeaderMatchingFilter to afew</a> &ndash; so you can use regular expression matches against any header for adding tags.</li>
<li><a href="https://foobacca.co.uk/blog/2013/07/custom-reports-with-notmuch/">custom reports</a> &ndash; showing thread counts in various tags.</li>
<li>address book</li>
<li>the mail client &ndash; alot</li>
<li>future projects</li>
</ul>


<h2>Two copies of notmuch</h2>

<p>I run two copies of notmuch &ndash; one for my gmail account and one for my work one.  I want to keep them separate, so I have set up a parallel config.  The default file is <code>~/.notmuch-config</code> and I have added <code>~/.notmuch-config-work</code>  You can tell notmuch to use it via an enviroment variable &ndash; <code>$NOTMUCH_CONFIG</code> &ndash; but I don&rsquo;t want to set that all the time, so I have a file <code>~/bin/notmuchwork</code> with the contents:</p>

<pre><code>NOTMUCH_CONFIG=~/.notmuch-config-work notmuch $@
</code></pre>

<p>and then have an alias set up in my <code>.bashrc</code>:</p>

<pre><code>alias nmw=$HOME/bin/notmuchwork
</code></pre>

<p>I have similar set up for alot and afew &ndash; although for those you can define the config path on the command line rather than through an environment variable.  This is necessary as they access notmuch through the python library rather than through the command line.</p>

<h2>My dotfiles</h2>

<p>My <a href="https://github.com/foobacca/dotfiles.git">dotfiles are on github</a> have all of my config &ndash; have fun poking around.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Buddhist Audio]]></title>
    <link href="https://foobacca.co.uk/blog/2013/03/buddhist-audio/"/>
    <updated>2013-03-24T12:01:00+00:00</updated>
    <id>https://foobacca.co.uk/blog/2013/03/buddhist-audio</id>
    <content type="html"><![CDATA[<p>Here are some sources of buddhist audio:</p>

<ul>
<li><a href="http://www.dharmaseed.org/talks/">london insight</a> (recordings of teachers who John Teesdale also brings to Cambridge)</li>
<li><a href="http://www.audiodharma.org/talks/">audio dharma</a> (US centre)</li>
<li><a href="http://www.freebuddhistaudio.com/audio/">free buddhist audio</a> (Triratna, aka FWBO)</li>
<li><a href="http://www.buddhistgeeks.com/">buddhist geeks</a> (I used them last Wednesday)</li>
<li><a href="http://www.dharmaseed.org/talks/">dharma seed</a></li>
</ul>

]]></content>
  </entry>
  
</feed>
