From 61ad5c86543ac9d73f50d5d5b03ab12ef28b6304 Mon Sep 17 00:00:00 2001 From: Zach DeCook Date: Sat, 21 Nov 2020 22:02:07 +0000 Subject: * Gemini: Provide mechanism to edit songs over email --- laravel/applyedit.php | 26 ++++++++++++++++++++++++++ laravel/public/song.gmi.php | 2 ++ 2 files changed, 28 insertions(+) create mode 100644 laravel/applyedit.php 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 @@ +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%20id ?>&body=text) ?> Edit song + limit(5)->pluck('title','id') as $id => $title): ?> => -- cgit 1.4.1