Imap.fetch results in segfault (Ubuntu Dapper LTS, amd64)

Hi all, I have a Dapper LTS box (amd64) and since I’ve applied this
update (USN-596-1: Ruby vulnerabilities | Ubuntu security notices | Ubuntu) a mail script I have that
has worked for a while now pauses for a minute or two while talking to a
Dovecot IMAP server, then segfaults. Basically the code is this:

…stuff snipped…

loop do
imap = Net::IMAP.new(server, 993, true)
imap.login(user, pass)
imap.select(folder)
imap.search([“NOT”, “SEEN”]).each do |msg_id|
env = imap.fetch(msg_id, “ENVELOPE”)[0].attr[“ENVELOPE”]

…stuff snipped…

With some debugging output it freezes on the above imap.fetch line for
the very first email (of usually many). If I drop down to non-TLS
logins, it does the same thing. For kicks I’ve even tried using a
version of the /usr/lib/ruby/1.8/net/imap.rb file from a Debian Etch
box, and still the same thing. strace output doesn’t show anything
useful to me, though my low level chops are very rusty these days.

The thing is, the fetch appears to at least partially work from the mail
server’s POV since Dovecot moves the messages from “new” to “cur”, so at
least part of it is working.

Has anyone else run across this (and better yet, anyone got a
workaround?)

Thanks.