Backend for songs.zachdecook.com
Diffstat (limited to 'laravel/applyedit.php')
| -rwxr-xr-x | laravel/applyedit.php | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/laravel/applyedit.php b/laravel/applyedit.php index b9aa619..bd9f296 100755 --- a/laravel/applyedit.php +++ b/laravel/applyedit.php @@ -8,12 +8,20 @@ $kernel = $app->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 < 10; $i++) { +for($i = 0; $i < 30; $i++) { // TODO: Process these in order? $header = imap_header($imap, $number - $i); - if (strpos($header->to[0]->mailbox, "+songs")){ + 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)); @@ -25,7 +33,6 @@ for($i = 0; $i < 10; $i++) { $song->save(); imap_delete($imap, $number - $i); printf("updated song {$song->id}"); - exit(0); } } exit(0); |