Check for new mail (Simpler way)

Is there a simpler way to do this? I have the unreadCount and messageSubs returned to a growl notification.

tell application "Mail"
	set unreadCount to 0
	set messageSubs to ""
	set allMessages to every message of inbox
	repeat with aMessage in allMessages
		if read status of aMessage is false then
			set messageSubject to the subject of aMessage
			set unreadCount to unreadCount + 1
			if messageSubject's ((text items of messageSubject)'s item count) ≥ 20 then
				set shortenedSub to ""
				set itemCount to 0
				repeat with aLetter in (text items of messageSubject)
					set itemCount to itemCount + 1
					if itemCount ≤ 20 then
						set shortenedSub to shortenedSub & aLetter
					end if
				end repeat
				set messageSubject to shortenedSub & "..."
			end if
			if not messageSubs = "" then
				set messageSubs to messageSubs & ", "
			end if
			set messageSubs to messageSubs & messageSubject
		end if
	end repeat
end tell

Thanks! That is much simpler. I don’t fully understand it though, what does the “it” refer to? And how does the (count) work?

Thanks, that explains why when I tested “it” without the tell block it returned “<>”, but I see how it works now.
Anyway, thanks for your help, I owe you one!


I’m curious, how does everyone learn this? Looking around the site I found the begginner’s guide, but nothing else as useful for the more advanced stuff.