% Mail
Mail>
Mail> s 1,1000 filename
Mail> x
%
This saves all messages from the first to the one-thousandth in one file. Change the numbers accordingly for your mailbox size. Then, on your Mac, do this in the Terminal:
% cd Library/Mail/Mailboxes/
% mkdir unixmails
% cd unixmails
% scp servername:filename .
Where servername:filename is replaced with the Linux server info. Type in password as requested. After the file is copied, just launch Mail.app, and then you can find all the mails under "On My Mac" in the folder "unixmails."
Now you can even copy all the emails to your IMAP server just by selecting them all and dragging them.

