When I set up the account on my MacBook at home, however, Mail was completely ignoring the IMAP Path Prefix I set, and insisted on listing the entire contents of my home directory, including all the invisible files (.bash_history and so on) and, even worse, the whole public_html tree where my Web site is stored. Looking at a trace of the IMAP communication between Mail and the server, it was clearly a problem on my local machine rather than an error on the server, because Mail was asking for mailbox listings without mentioning the path prefix.
Since everything was still working fine on my work Mac, I thought that there must be some subtle difference in the preferences between the two computers, so I used BBEdit to compare the com.apple.mail.plist files from both machines. In amongst the many arbitrary differences that will always show up when comparing preference files from different computers (such as minor differences in the window sizes or column widths), I noticed the following key:
<key>IMAPServerPrefixesMirrorFilesystem</key>
<true/>
This setting was present in my work preferences file, but absent altogether from my home machine's preferences. Hoping that this key might be the culprit, I added this entry to the preferences file, restarted Mail, and suddenly everything worked properly -- it showed only the mailboxes in the actual mail folder on the server, not all of the other bits and pieces that had been showing up before.
If you are having a similar problem, whereby Mail seems to be ignoring the IMAP Path Prefix no matter how many times you try setting it, running the following command in a Terminal will make the appropriate change to Mail's settings:
defaults write com.apple.mail IMAPServerPrefixesMirrorFilesystem -bool true
[robg adds: I haven't tested this one.]

