aboutsummaryrefslogtreecommitdiff
path: root/get-attaches.php
diff options
context:
space:
mode:
Diffstat (limited to 'get-attaches.php')
-rw-r--r--get-attaches.php31
1 files changed, 31 insertions, 0 deletions
diff --git a/get-attaches.php b/get-attaches.php
new file mode 100644
index 0000000..36c12ee
--- /dev/null
+++ b/get-attaches.php
@@ -0,0 +1,31 @@
+<?php
+
+require_once __DIR__.'/common.php';
+
+$str = file_get_contents('php://stdin');
+if (!$str)
+ fatalError("no input");
+
+$message_ids = [];
+$photo_urls = [];
+
+$on_message = function($doc, $message_id) {
+ global $message_ids;
+ $message_ids[] = $message_id;
+};
+$on_photo = function($doc, $href, $link_node) {
+ global $photo_urls;
+ $photo_urls[] = $href;
+};
+
+try {
+ onEachMessageOrAttachment($str, $on_message, $on_photo);
+} catch (Exception $e) {
+ fatalError($e->getMessage());
+}
+
+if (!empty($message_ids))
+ echo implode("\n", $message_ids)."\n";
+
+if (!empty($photo_urls))
+ echo implode("\n", $photo_urls)."\n"; \ No newline at end of file