These three patches fix and clean up mutt_buffy. The first patch fixes the call to mutt_expand_path() to use the string length passed into the function instead of assuming _POSIX_PATH_MAX.
The second patch fixes http://dev.mutt.org/trac/ticket/3208 (imap and mutt does not display new message count) and http://dev.mutt.org/trac/ticket/3218 (<space> doesn't cycle through mailboxes). The third patch rewrites mutt_buffy to be readable and maintainable. The sum total is the same as what I have posted at http://dev.mutt.org/trac/attachment/ticket/3218/fix-3218.patch
