tell application "Mail"
-- Specify the parent mailbox where the year folders are located
set yearsMailbox to mailbox "Years" of account "iCloud" -- Adjust if the path is different
-- List of sub-mailboxes under 'Years', each named with a four-digit year
set yearFolders to every mailbox of yearsMailbox
-- Specify the source folder where emails are currently located
set sourceFolder to mailbox "Recovered" -- Replace "SourceFolder" with the name of your folder
repeat with eachMessage in (get messages of sourceFolder)
set messageDate to date received of eachMessage
set messageYear to year of messageDate as string
-- Check if a folder for the year exists and move the message
repeat with eachYearFolder in yearFolders
if name of eachYearFolder is messageYear then
move eachMessage to eachYearFolder
Please leave comments below.