Thunderbird newsgroup list fixer

Tags: python

My thunderbird newsgroup file (something like .thunderbird-3.0/0gahkqdp.default/News/ often contains lines like:

gmane.comp.python.distutils.devel: 1-12428,12431-12446

There’s a two-article “hole” in there that shows up as two unread messages. Yuck. And I got tired of removing those “holes” by hand. So I wrote a script that converts 1-12428,12431-12446 to 1-12446 to remove the holes:

CONFIG_FILE = ('/home/reinout/.thunderbird-3.0/0gahkqdp.default/' +

def fix_thunderbird():
    """Fix the thunderbird newsrc settings

    The settings sometimes contain lines like::

      gmane.comp.python.distutils.devel: 1-12428,12431-12446

    There's a two-article 'hole' in there that shows up as two unread
    messages.  This script removes the holes.


    lines = [line.strip() for line in open(CONFIG_FILE).readlines()]
    print "======= OLD ======="
    for line in lines:
        print line
    print "======= NEW ======="
    outfile = open(CONFIG_FILE, 'w')
    for line in lines:
        if not line:
        newsgroup, messages = line.split(': ')
        parts = messages.split('-')
        new = '%s: %s-%s\n' % (newsgroup,
        print new,

if __name__ == '__main__':

Public domain, do with it what you like :-) logo

About me

My name is Reinout van Rees and I work a lot with Python (programming language) and Django (website framework). I live in The Netherlands and I'm happily married to Annie van Rees-Kooiman.

Weblog feeds

Most of my website content is in my weblog. You can keep up to date by subscribing to the automatic feeds (for instance with Google reader):