* [PATCH pit 1/3] lib: Remove unnecessary var_dump
2022-02-26 16:52 [PATCH pit 0/3] Add Telegram Notification Support Alviro Iskandar Setiawan
@ 2022-02-26 16:52 ` Alviro Iskandar Setiawan
2022-02-26 16:57 ` Ammar Faizi
2022-02-26 16:52 ` [PATCH pit 2/3] bin/public-inbox-tg: Add Telegram CC notification support Alviro Iskandar Setiawan
` (3 subsequent siblings)
4 siblings, 1 reply; 7+ messages in thread
From: Alviro Iskandar Setiawan @ 2022-02-26 16:52 UTC (permalink / raw)
To: Ammar Faizi
Cc: Nugra, Arthur Lapz, Alviro Iskandar Setiawan,
GNU/Weeb Mailing List, Alviro Iskandar Setiawan
The var_dump() in sendFile() is not needed. Maybe sir Ammar forgot
to remove it when debugging :v
Signed-off-by: Alviro Iskandar Setiawan <[email protected]>
---
lib.php | 1 -
1 file changed, 1 deletion(-)
diff --git a/lib.php b/lib.php
index 771d24f..b35abbd 100644
--- a/lib.php
+++ b/lib.php
@@ -63,6 +63,5 @@ function sendFile(array $post): ?array
if (!$out)
return NULL;
- var_dump($out);
return json_decode($out, true);
}
--
2.32.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH pit 2/3] bin/public-inbox-tg: Add Telegram CC notification support
2022-02-26 16:52 [PATCH pit 0/3] Add Telegram Notification Support Alviro Iskandar Setiawan
2022-02-26 16:52 ` [PATCH pit 1/3] lib: Remove unnecessary var_dump Alviro Iskandar Setiawan
@ 2022-02-26 16:52 ` Alviro Iskandar Setiawan
2022-02-26 16:52 ` [PATCH pit 3/3] data: Add GNU/Weeb friends Alviro Iskandar Setiawan
` (2 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Alviro Iskandar Setiawan @ 2022-02-26 16:52 UTC (permalink / raw)
To: Ammar Faizi
Cc: Nugra, Arthur Lapz, Alviro Iskandar Setiawan,
GNU/Weeb Mailing List, Alviro Iskandar Setiawan
This adds "Telegram-Cc:" header when a registered Telegram user is in
the "To:" or "Cc:" list. Use simple file lookup as the database. No
SQL database is involved.
Signed-off-by: Alviro Iskandar Setiawan <[email protected]>
---
bin/public-inbox-tg.php | 75 +++++++++++++++++++++++++++++++----------
1 file changed, 58 insertions(+), 17 deletions(-)
diff --git a/bin/public-inbox-tg.php b/bin/public-inbox-tg.php
index a09a690..dea2de6 100644
--- a/bin/public-inbox-tg.php
+++ b/bin/public-inbox-tg.php
@@ -10,21 +10,52 @@ const TARGET_CHAT_ID = -1001483770714;
// // Private Cloud
// const TARGET_CHAT_ID = -1001226735471;
+const DATA_DIR = __DIR__."/../data";
+
require __DIR__."/../lib.php";
-function buildList(string $cc, string $name): string
+function listTelegramLookup(array $list): array
{
- if (empty($cc))
- return "";
+ $ret = [];
- $ret = "";
- $ccs = explode(",", $cc);
- foreach ($ccs as $cc)
- $ret .= "{$name}: ".trim($cc)."\n";
+ if (!is_dir(DATA_DIR))
+ mkdir(DATA_DIR);
+
+ if (!is_dir(DATA_DIR."/tg"))
+ mkdir(DATA_DIR."/tg");
+
+ foreach ($list as $c) {
+ if (preg_match("/.+\<(.+?)\>/", $c, $m))
+ $c = $m[1];
+
+ $u = DATA_DIR."/tg/".$c;
+ if (!file_exists($u))
+ continue;
+
+ $ret[] = trim(file_get_contents($u));
+ }
return $ret;
}
+function extractList(string $str): array
+{
+ $str = explode(",", $str);
+ foreach ($str as &$c)
+ $c = trim($c);
+
+ return $str;
+}
+
+function buildList(array $list, string $name): string
+{
+ $ret = "";
+ foreach ($list as $c)
+ $ret .= "{$name}: ".trim($c)."\n";
+
+ return trim($ret);
+}
+
// Thanks to https://stackoverflow.com/a/2955878/7275114
function slugify($text, string $divider = '-'): string
{
@@ -104,27 +135,37 @@ function fx(string $input): int
$err = "";
if (preg_match("/(?:^|\\n)to:\s+?(.+?)(?:\\n\S+\:|\\n\\n)/si", $hdr, $m)) {
- $to = clean_header_val($m[1]);
- $toList = trim(buildList($to, "To"));
+ $toList = extractList(clean_header_val($m[1]));
+ $toListStr = buildList($toList, "To");
} else {
- $toList = "";
+ $toListStr = "";
}
if (preg_match("/(?:^|\\n)cc:\s+?(.+?)(\\n\S+\:|\\n\\n)/si", $hdr, $m)) {
- $cc = clean_header_val($m[1]);
- $ccList = trim(buildList($cc, "Cc"));
+ $ccList = extractList(clean_header_val($m[1]));
+ $ccListStr = buildList($toList, "Cc");
} else {
- $ccList = "";
+ $ccListStr = "";
}
$content = trim(substr($body, 0, MAX_BODYLEN));
$msg = "#ml\nFrom: {$from}\n";
- if ($toList)
- $msg .= "{$toList}\n";
+ if ($toListStr)
+ $msg .= "{$toListStr}\n";
+
+ if ($ccListStr)
+ $msg .= "{$ccListStr}\n";
- if ($ccList)
- $msg .= "{$ccList}\n";
+ $tgCCs = array_merge(...[listTelegramLookup($toList), listTelegramLookup($ccList)]);
+ $tgCCs = array_unique($tgCCs);
+
+ if (count($tgCCs) > 0) {
+ $msg .= "Telegram-Cc: ";
+ foreach ($tgCCs as $tgCC)
+ $msg .= $tgCC;
+ $msg .= "\n";
+ }
$msg .= "Date: {$date}\n";
$msg .= "Subject: {$subject}";
--
2.32.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH pit 3/3] data: Add GNU/Weeb friends
2022-02-26 16:52 [PATCH pit 0/3] Add Telegram Notification Support Alviro Iskandar Setiawan
2022-02-26 16:52 ` [PATCH pit 1/3] lib: Remove unnecessary var_dump Alviro Iskandar Setiawan
2022-02-26 16:52 ` [PATCH pit 2/3] bin/public-inbox-tg: Add Telegram CC notification support Alviro Iskandar Setiawan
@ 2022-02-26 16:52 ` Alviro Iskandar Setiawan
2022-02-26 17:02 ` [PATCH pit 0/3] Add Telegram Notification Support Ammar Faizi
2022-02-26 17:11 ` Ammar Faizi
4 siblings, 0 replies; 7+ messages in thread
From: Alviro Iskandar Setiawan @ 2022-02-26 16:52 UTC (permalink / raw)
To: Ammar Faizi
Cc: Nugra, Arthur Lapz, Alviro Iskandar Setiawan,
GNU/Weeb Mailing List, Alviro Iskandar Setiawan
Add GNU/Weeb friends to file database. This is important to generate
notification in the "Telegram-Cc:" header.
Signed-off-by: Alviro Iskandar Setiawan <[email protected]>
---
data/tg/[email protected] | 1 +
data/tg/[email protected] | 1 +
data/tg/[email protected] | 1 +
data/tg/[email protected] | 1 +
data/tg/[email protected] | 1 +
5 files changed, 5 insertions(+)
create mode 100644 data/tg/[email protected]
create mode 100644 data/tg/[email protected]
create mode 100644 data/tg/[email protected]
create mode 100644 data/tg/[email protected]
create mode 100644 data/tg/[email protected]
diff --git a/data/tg/[email protected] b/data/tg/[email protected]
new file mode 100644
index 0000000..f6d03bc
--- /dev/null
+++ b/data/tg/[email protected]
@@ -0,0 +1 @@
+@Viro_SSFS
diff --git a/data/tg/[email protected] b/data/tg/[email protected]
new file mode 100644
index 0000000..f6d03bc
--- /dev/null
+++ b/data/tg/[email protected]
@@ -0,0 +1 @@
+@Viro_SSFS
diff --git a/data/tg/[email protected] b/data/tg/[email protected]
new file mode 100644
index 0000000..8b94cbe
--- /dev/null
+++ b/data/tg/[email protected]
@@ -0,0 +1 @@
+@ammarfaizi2
diff --git a/data/tg/[email protected] b/data/tg/[email protected]
new file mode 100644
index 0000000..8b1e614
--- /dev/null
+++ b/data/tg/[email protected]
@@ -0,0 +1 @@
+@LoliOverflow
diff --git a/data/tg/[email protected] b/data/tg/[email protected]
new file mode 100644
index 0000000..e0ccae1
--- /dev/null
+++ b/data/tg/[email protected]
@@ -0,0 +1 @@
+@rlapz
--
2.32.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH pit 0/3] Add Telegram Notification Support
2022-02-26 16:52 [PATCH pit 0/3] Add Telegram Notification Support Alviro Iskandar Setiawan
` (2 preceding siblings ...)
2022-02-26 16:52 ` [PATCH pit 3/3] data: Add GNU/Weeb friends Alviro Iskandar Setiawan
@ 2022-02-26 17:02 ` Ammar Faizi
2022-02-26 17:11 ` Ammar Faizi
4 siblings, 0 replies; 7+ messages in thread
From: Ammar Faizi @ 2022-02-26 17:02 UTC (permalink / raw)
To: Alviro Iskandar Setiawan
Cc: Nugra, Arthur Lapz, Alviro Iskandar Setiawan,
GNU/Weeb Mailing List
On 2/26/22 11:52 PM, Alviro Iskandar Setiawan wrote:
> Hi sir,
>
> This series contains 3 patches to add Telegram notification support.
> When someone is in the "To:" or "Cc:" list, they will be mentioned
> in Telegram.
The code looks good. I am going to test this in my private group. If
it works. I will give it a go. Wait for it...
--
Ammar Faizi
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH pit 0/3] Add Telegram Notification Support
2022-02-26 16:52 [PATCH pit 0/3] Add Telegram Notification Support Alviro Iskandar Setiawan
` (3 preceding siblings ...)
2022-02-26 17:02 ` [PATCH pit 0/3] Add Telegram Notification Support Ammar Faizi
@ 2022-02-26 17:11 ` Ammar Faizi
4 siblings, 0 replies; 7+ messages in thread
From: Ammar Faizi @ 2022-02-26 17:11 UTC (permalink / raw)
To: Alviro Iskandar Setiawan
Cc: Nugra, Arthur Lapz, Alviro Iskandar Setiawan,
GNU/Weeb Mailing List
On 2/26/22 11:52 PM, Alviro Iskandar Setiawan wrote:
> Hi sir,
>
> This series contains 3 patches to add Telegram notification support.
> When someone is in the "To:" or "Cc:" list, they will be mentioned
> in Telegram.
>
> [PATCH 1/3]
> lib: Remove unnecessary var_dump. The var_dump() in sendFile() is not
> needed. Maybe sir Ammar forgot to remove it when debugging :v
>
> [PATCH 2/3]
> bin/public-inbox-tg: Add Telegram CC notification support. This adds
> "Telegram-Cc:" header when a registered Telegram user is in the "To:"
> or "Cc:" list. Use simple file lookup as the database. No SQL database
> is involved.
>
> [PATCH 3/3]
> data: Add GNU/Weeb friends: Add GNU/Weeb friends to file database.
> This is important to generate notification in the "Telegram-Cc:"
> header.
> [...]
Applied, thanks!
[1/3] lib: Remove unnecessary var_dump
commit: f0cab3bceef216612a8072b8d80a3389e60a3651
[2/3] bin/public-inbox-tg: Add Telegram CC notification support
commit: b7a968b53f42f7392ac2fb3450524bb4a949baab
[3/3] data: Add GNU/Weeb friends
commit: f28aa882e6dbe164095a1a0fceacc6e72cf0991f
Best regards,
--
Ammar Faizi
^ permalink raw reply [flat|nested] 7+ messages in thread