Lutin's (sort of) blog

Automatically filter mails using List-Id with imapfilter  --  Sun, 22 Nov 2009 12:07:48

Some time ago, I switched from a pop+fetchmail+procmail setup to using imap+imapfilter+offlineimap, which makes it way easier to sync mails from/to multiple computers. However, one thing I've missed a lot is the ability to do automatic filtering based on list-id with procmail, which is very convenient when you're subscribed to a lot of lists. Recently I found some old code snippets allowing that with imapfilter, and updated them to work with current versions of imapfilter.
First, you need a function that will parse the list-id header to extract the folder name. This one is pretty simple and might not work in some cases, but it appears to work on all the mailing lists I'm subscribed to.
function parseListId(header)
 baseheader = string.sub(header, string.find(header, ':')+1, nil)
 destname = ''
 for i=1,string.len(baseheader) do
  c = string.sub(baseheader, i, i)
  if c == '<' then
   -- reset destname on any < brackets
   destname = ''
  elseif c == '.' then
   -- stop on the first .
   return destname
  elseif c ~= ' ' then
   -- add any non-space character to the destination name
   destname = destname .. c
And then, you need to actually fetch the list-id headers and sort your e-mails accordingly
results = GMAIL['INBOX']:match_field('List-Id', '.*<.*>')
listids = GMAIL['INBOX']:fetch_fields({'List-Id'}, results) or {}

mailboxes = {}
for message, header in pairs(listids) do
 mailbox = parseListId(header)
 if not mailboxes[mailbox] then
  mailboxes[mailbox] = {}
 table.insert(mailboxes[mailbox], message)

for mailbox, messages in pairs(mailboxes) do
 GMAIL['INBOX']:move_messages(GMAIL[mailbox], Set(messages))
That's it, imapfilter now filters your messages according to the List-Id field. Enjoy!

Sbuild list-missing hook  --  Tue, 13 Jan 2009 15:30:08

Time for some random content, as it's been almost a year since I last put something uninteresting here. When I switched from pbuilder to sbuild to build debian packages, what I missed most is the little hook script I used to list missing files - files in debian/tmp that are not part of any package. As some google digging didn't work out so weel to find its sbuild-compatible equivalent, I've finally written a hook script for schroot that does this.
A couple notes on it though:
  • You need to set $purge_build_directory="never"; in your ~/.sbuilrc for this to work, or otherwise the build directory will get deleted, and the script won't work (this doesn't matter much if you're using lvm snapshots, however that might end up eating up a lot of space if you're using the file-based method)
  • You need to put it in /etc/schroot/setup.d, and as it runs fakeroot and uses cdbs' file, you'll need both of those packages installed.
Well, that's pretty much it. You weren't expecting some real content, were you?

Enlightened Boot  --  Fri, 15 Feb 2008 07:45

Some time ago, Rasterman wrote Exquisite, a pretty neat EFL-based, drop-in usplash replacement. After some efforts, I got it working at startup on my computer, and packaged it so that people can enjoy it painlessly.
However, many people don't use packages, and I've been asked several time to write a how-to make it work, so here it is :)
  • Note: All the links below are links to scripts, don't forget to make them executable. A lot of them are based on scripts from the usplash and initramfs-tools debian/ubuntu packages, thanks to their maintainer for the great work :)
  • First off, if you're an ubuntu user you need to work around the framebuffer bug (see the previous post), as exquisites requires vesafb. Basically, if you have a sotck Ubuntu install, you need to:
    • Edit /usr/share/initramfs-tools/hooks/kernelextras, and add the two following lines at the end:
      force_load fbcon
      force_load vesafb
    • Edit /usr/share/initramfs-tools/scripts/init-top/framebuffer and remove the '-b' option passed to the 2 modprobe calls in the middle of the script.
  • As said above, you need to use the framebuffer to have exquisite working. That means you have to append (if not already present) a 'vga=' option in you kernel startup command-line in /boot/grub/menu.lst, and then run sudo update-grub. More information concerning the vga modes can be found on Wikipedia
  • Then, grab exquisite from CVS, compile and install it. I'll assume that the binaries are installed in /sbin (if it's not, adapt the path with the one where you installed exquisite, but keep in mind that exquisite-write has to be installed in a location available at the ealiest stage of the boot, so avoid /usr/* if it's on a different partition)
  • Symlink the binary so that calls to 'upslash' actually call exquisite: sudo ln -s /sbin/exquisite /sbin/usplash
  • You now need to create some wrapper scripts so that it replaces usplash the proper way:
    • Put the following code in /sbin/usplash_write:
      EXQUISITE_IPC="/dev/.initramfs/exquisite" exquisite-write "$@"
      This allows exquisite to survive the root filesystem change that happens when /sbin/init is called from within the initramfs.
    • You also need exquisite-down, which is called from the init scripts at shutdown to launch exquisite. Either save it as /sbin/exquisite-down and symlink /sbin/usplash_down to it, or name it /sbin/usplash_down directly.
  • Next, some initramfs-tools magic:
  • Finally, we need an init script for it. Save it to /etc/init.d/usplash, and run the following command to add it to /etc/rc*.d:
    sudo update-rc.d usplash start 98 2 3 4 5 . stop 01 0 1 6 .
  • Reboot
  • w00t.

Thou Shalt Not Use The Framebuffer  --  Sun, 11 Nov 2007 21:29

I know, I should have written something about the awesomeness of Gutsy. Should have...
...But while I didn't do it, there's a feature among the ton of cool things gutsy brought, that I'd want to share with you: The out-of-the-box non-working framebuffer
So, howto to enjoy that shiny new feature ?
  • Edit /boot/grub/menu.lst with your favorite text editor and put vga= in your default boot options. Don't forget to save.
  • Run 'sudo update-grub'.
  • Reboot your computer.
And here is the best weapon to fight against the 'linux is all about command-line' opinion: You just can't use your console. Don't tell me you're not happy, I know you've been wanting to get rid of it for ages.
I have to say, it's been a pretty good collaboration between users and the kernel development team to bring this feature in:
  A bug about that new function was filed 2 months before the release, set as critical (now, you see how badly users wanted their framebuffer not to work),
  got dozens of answers and about 20 duplicates, and the kernel team did a great job at keeping this feature in gutsy.
Ok, let's stop the sarcasm. Actually they did answer. 'Just remove vga= from you kernel command line'.
Enjoy :)

PS: in case you would be interested in a solution, you might want to look at the Launchpad Bug #129910.

echo 'Hello, World!'  --  Fri, 12 Oct 2007 19:50

Hello, World!
Well, some people have been telling me for a while that I should have a blog....Let's try :)

© 2007-2009 Albin Tonnerre <>