Backend for songs.zachdecook.com
Diffstat (limited to 'laravel/applyedit.php')
-rw-r--r--laravel/applyedit.php26
1 files changed, 26 insertions, 0 deletions
diff --git a/laravel/applyedit.php b/laravel/applyedit.php
new file mode 100644
index 0000000..034cca1
--- /dev/null
+++ b/laravel/applyedit.php
@@ -0,0 +1,26 @@
+<?php
+define('LARAVEL_START', microtime(true));
+require __DIR__.'/vendor/autoload.php';
+require __DIR__.'/load-eloquent.php';
+$app = require_once __DIR__.'/bootstrap/app.php';
+$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);
+use App\Song;
+
+$imap = imap_open($mailbox, $username, $password);
+$check = imap_check($imap); $number = $check->Nmsgs;
+// Just check the newest 10 messages.
+for($i = 0; $i < 10; $i++) {
+ // TODO: Process these in order?
+ $header = imap_header($imap, $number - $i);
+ if (strpos($header->to[0]->mailbox, "+songs")){
+ $id = explode(" ", $header->subject)[2];
+ $song = Song::findOrFail($id);
+ $body = quoted_printable_decode(imap_body($imap, $number - $i));
+ $song->text = $body;
+ $song->save();
+ imap_delete($imap, $number - $i);
+ printf("updated song $id");
+ exit(0);
+ }
+}
+exit(0);