OK.... Did a bit more debugging... updated script
property secondsIn21Days : 1814400
on run {input, parameters}
try
set dateToday to current date
--
tell application "Mail"
set archiveCount to 0
set theArchiveMailboxName to "CurrentArchive"
if (mailboxtheArchiveMailboxNameexists) = false then
makenewmailboxwith properties {name:theArchiveMailboxName}
end if
repeat with aMessage in input
-- set theMessages to input
-- repeat with aMessage in theMessages
set messageRDate to date received of aMessage
set messageSDate to date sent of aMessage
set messageSubject to subject of aMessage
set messageID to id of aMessage
set timeRDifference to 0
set timeSDifference to 0
-- if messageRDate > 0 then
set timeRDifference to dateToday - messageRDate
-- end if
-- if messageSDate > 0 then
set timeSDifference to dateToday - messageSDate
-- end if
display dialogmessageSubject & " " & messageID & " " & timeRDifference & " " & timeSDifference
if timeRDifference > secondsIn21Days then
display dialog "Move " & messageID & " Received" & messageRDate & " " & messageSDate
moveaMessagetomailboxtheArchiveMailboxName
set archiveCount to archiveCount + 1
else if timeSDifference > secondsIn21Days then
display dialog "Move " & messageID & " Sent" & messageRDate & " " & messageSDate
moveaMessagetomailboxtheArchiveMailboxName
set archiveCount to archiveCount + 1
end if
end repeat
end tell
display notification "emails archived = " & archiveCountwith title "Mail Archive"
-- return -- Successful completion of handler.
on error errStrnumbererrorNumber
-- If our own error number, warn about bad data.
-- if the errorNumber is equal to 750 then
-- display dialog "All items in the list must be integers."
-- return integerSum -- Return the default value (0).
-- else
-- An unknown error occurred. Resignal, so the caller
-- can handle it, or AppleScript can display the number.
error errStrnumbererrorNumber
display notification "emails archived = " & archiveCountwith title "Mail Archive"
-- end if
end try
end run