Moving e-mails between accounts via AppleScript

I’ve just finished listening to episode 3 of Automators and immediately came up with an idea for an AppleScript to move e-mails. Unfortunately, I have never used AppleScript before and was unable to figure it out.

I have two Mail accounts:

  1. iCloud
  2. Work

I want to do the following: If an e-mail is in my iCloud mailbox “Move” and flagged, move it to my “Work” inbox.

My thinking behind this is the following: On my Mac, I can move e-mails from my “Work” account to my “iCloud” Account and vice versa. On my iPhone, however, it works only from “Work” to “iCloud”. My Idea is to create a Workflow/Shortcut that creates a file in an iCloud folder which Hazel monitors. Hazel could then trigger the Script. This way, I’d have a possibility to move e-mails to my “Work” inbox. But maybe this is way to complicated and there is a far easier solution, which means I’m open for suggestions… :wink:

I tried adjusting the Script John Gruber created here but I struggled to understand even the first two lines of the actual script (“set _acct_name to name of _acct” and “set _inbox to _acct’s mailbox “INBOX””).

Any help or suggestion is greatly appreciated! :smiley: