using terms from application "Mail" on perform mail action with messages theMessages for rule theRule tell application "Mail" repeat with thisMessage in theMessages set msgDate to date received of thisMessage set msgMonth to month of msgDate as integer set msgYear to year of msgDate as integer set msgQuarter to ((round ((msgMonth - 1) / 3) rounding down) + 1) set msgAccount to name of account of mailbox of thisMessage set msgMailbox to name of mailbox of thisMessage set mboxName to "Personal/" & msgYear & "/Q" & msgQuarter tell account "Home" try set mbox to mailbox named mboxName get name of mbox on error make new mailbox with properties {name:mboxName} set mbox to mailbox named mboxName end try move thisMessage to mbox end tell end repeat end tell end perform mail action with messages end using terms from