Prior to 10.7.x this AppleScript used to work with AppleMail:
tell application "Mail"
activate
check for new mail
repeat until (background activity count) = 0
do shell script "sleep 1"
end repeat
end tell
However, since 10.7.x+ this does not seem to work anymore. It doesn't even go in to the repeat loop. My guess is that AppleMail has changed the way it downloads emails and doesn't use "background activity" anymore.
Anyone know how to wait for all emails to download in AppleMail 5+ with AppleScript?