...
From kb.mozillazine (http://kb.mozillazine.org/Compacting_folders): If the folder is severely corrupted, deleting the .msf file won't help much, and compacting the folder may just make things worse because Thunderbird can't reliably figure out where a message ends anymore. You'll typically run into this only with the Inbox folder. It's much more vulnerable to corruption because it frequently has both lots of messages and a high percentage of deleted (but not visible) messages. That's why it's recommended that you move messages you want to keep to other folders/child folders rather than keep storing them in the Inbox."
Troubleshooting
...
Logging
Sample script to be run in the desktop environment (TODO: $LOGNAME does not have a value ...? The ; after imap:5 is spurious ... ?):
#!/bin/bash
export NSPR_LOG_MODULES=imap:5;
export NSPR_LOG_FILE=/tmp/$LOGNAME.imap.log
/usr/lib/thunderbird/thunderbird &
References
Thunderbird as a Gmail client: http://kb.mozillazine.org/Gmail