#!/usr/bin/env php make(Illuminate\Contracts\Http\Kernel::class); use App\Song; $imap = imap_open($mailbox, $username, $password); if (!$imap){ printf("no imap :("); exit(1); } $check = imap_check($imap); $number = $check->Nmsgs; if (!$check){ printf("no check :("); exit(1); } // Just check the newest 10 messages. for($i = 0; $i < 30; $i++) { // TODO: Process these in order? $header = imap_header($imap, $number - $i); if (isset($header->to[0]) && strpos($header->to[0]->mailbox, "+songs")){ $json = json_decode($header->subject); $song = Song::findOrFail($json->id); $body = quoted_printable_decode(imap_body($imap, $number - $i)); $song->text = $body; $song->title = $json->title; $song->author = $json->author; $song->key = $json->key; $song->verse = $json->verse; $song->save(); imap_delete($imap, $number - $i); printf("updated song {$song->id}"); } } exit(0);