about summary refs log tree commit diff
path: root/laravel
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
parent8c8f804e3624b58da3a94937e533e3aef6763058 (diff)
downloadprosongsa-61ad5c86543ac9d73f50d5d5b03ab12ef28b6304.tar.gz
* Gemini: Provide mechanism to edit songs over email
Diffstat (limited to 'laravel')
-rw-r--r--laravel/applyedit.php26
-rwxr-xr-xlaravel/public/song.gmi.php2
2 files changed, 28 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);
diff --git a/laravel/public/song.gmi.php b/laravel/public/song.gmi.php
index 4bf424d..8e3c43b 100755
--- a/laravel/public/song.gmi.php
+++ b/laravel/public/song.gmi.php
@@ -30,6 +30,8 @@ printf("30 " . Song::inRandomOrder()->first()->id . "\r\n");return;
 
 ```
 
+=> mailto:zachdecook+songs@gmail.com?subject=Edit%20Song%20<?= $song->id ?>&body=<?= rawurlencode($song->text) ?> Edit song
+
 <?php foreach(Song::inRandomOrder()->limit(5)->pluck('title','id') as $id => $title): ?>
 => <?= $id ?> <?= $title ?>