Note that Mail.app needs to be running for all of this to work. In your .zshrc, create a function that calls the AppleScript:

function mail_count {
osascript ~/Scripts/mail_count.scpt
}

Finally, redefine your prompt based on the new function. The following would be the most basic approach – but feel free to add your own variables as needed:

PROMPT='$(mail_count) '

If you don't want to mess with your prompt or use one of the oh-my-zsh styles, or even the promptinit module, you could also just use the precmd() function, in which you define anything that should be run before another command is executed. In that case, you wouldn't need the PROMPT_SUBST option.

precmd() {
mail_count
}

Whichever method you use, your unread mail count will be output in plain text. If you want to change the messages, take a look at the source of the .scpt file and modify it accordingly.

This is O(n) where n is number of messages in my inbox, right? I have too many messages. Wouldn't it be too slow?
–
snihalaniAug 27 '12 at 20:18

Yes, correct. It could be a little slow. I just tested it with dummy values, obviously, on a rather fast machine – near instantaneous. Your mileage may vary. You might be able to count differently – using unread count of every mailbox as explained here.
–
slhck♦Aug 27 '12 at 20:24

I posted the better script as an answer. Check it out.
–
snihalaniAug 27 '12 at 21:04

set output_string to ""
tell application "Mail"
set Unread_Count to unread count of inbox
if Unread_Count is 0 then
set output_string to ""
else if Unread_Count is 1 then
set output_string to "1 message"
else
set output_string to ("" & (get Unread_Count) & " messages")
end if
end tell
return output_string