about summary refs log tree commit diff
path: root/laravel/applyedit.php
diff options
context:
space:
mode:
authorZach DeCook <zachdecook@librem.one>2020-11-21 22:02:07 +0000
committerZach DeCook <zachdecook@librem.one>2020-11-21 22:02:07 +0000
commit61ad5c86543ac9d73f50d5d5b03ab12ef28b6304 (patch)
treeecb11b5483c3fd775ae1cfa93c9a6d280d660010 /laravel/applyedit.php
parent8c8f804e3624b58da3a94937e533e3aef6763058 (diff)
downloadprosongsa-61ad5c86543ac9d73f50d5d5b03ab12ef28b6304.tar.gz
* Gemini: Provide mechanism to edit songs over email
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);