Unflag emails marked as Junk(Spam) by Gmail via IMAP (or other access)

Job ID: 32131050

Budget: $10 – $30 USD

I'd like a script (preferably in PHP but I am flexible) that logs onto my Gmail, reads all messages flagged as Spam (i.e. in my spam folder).

I already have a PHP script ready using this library on Github (ddeboer/imap).

What is missing is the next step.

It then marks all these messages as 'Not Spam'. Once done they finally appear in my Inbox again (were they should been the whole time)!
Related categories: PHP Perl Python