Mail utility

This is my first approach to script Mail. Somebody knows a faster way to get (same or better) results?
the purpose of my script is to: scan mails with the same subject and trow all shorter answers of a longer discussion.
-ideal to trash alot of similar posts incoming from several mailgroups-

tell application "Mail"
	set {t_lg, t_sub, t_id} to {0, "", {}}
	set mv_ls to {}
	
	set x to mailbox "INBOX" of account "Gmail"
	set att_f to false

	repeat with i from 1 to count of messages in x
		set gt_id to message i of x
		set gt_sub to (subject of gt_id as text)
		set gt_lg to length of (get content of gt_id)
		set gt_att to mail attachments of gt_id

		if t_sub is {} then
			copy {gt_lg, gt_sub, gt_id} to {t_lg, t_sub, t_id}
		else
			if gt_sub contains t_sub then
				if gt_lg > t_lg then
					copy {gt_lg, gt_sub, gt_id} to {t_lg, t_sub, t_id}
					set junk mail status of t_id to true
					move t_id to junk mailbox
				else if gt_lg < t_lg then
					set junk mail status of gt_id to true
					delete gt_id
				end if
			else if gt_sub does not contain t_sub then

				copy {gt_lg, gt_sub, gt_id} to {t_lg, t_sub, t_id}
			else if mail attachments of gt_id is not {} then

				copy {gt_lg, gt_sub, gt_id} to {t_lg, t_sub, t_id}
			end if
		end if
	end repeat
end