From a213a6fd1f19722035ab79dc93286e567701bd82 Mon Sep 17 00:00:00 2001
From: Gab <24553253+gabrix73@users.noreply.github.com>
Date: Mon, 21 Apr 2025 15:14:20 +0200
Subject: Update send.php
---
send.php | 152 ++++++++++++++++++++++++++++++++-------------------------------
1 file changed, 77 insertions(+), 75 deletions(-)
(limited to 'send.php')
diff --git a/send.php b/send.php
index b31d3e1..a97f016 100644
--- a/send.php
+++ b/send.php
@@ -1,113 +1,115 @@
$v) $data[$k] = trim($v);
-// Limit to 3 newsgroups
-$groups = array_filter(array_map('trim', explode(',', $newsgroups)));
-if (count($groups) > 3) {
- $groups = array_slice($groups, 0, 3);
+// Check required fields
+$missing = array_filter($required, fn($f) => empty($data[$f] ?? ''));
+if ($missing) {
+ showError(
+ 'Missing required fields: ' . implode(', ', $missing) .
+ '. Remember: you must click Sign Message on the Digital Signature tab before sending.'
+ );
}
-$newsgroups = implode(', ', $groups);
-// Build raw email with dummy To for sendmail -t
-$headers = [];
-$headers[] = "From: $from";
-$headers[] = "To: mail2news@localhost";
-$headers[] = "Newsgroups: $newsgroups";
-$headers[] = "Subject: $subject";
-if ($references) {
- $headers[] = "References: $references";
-}
-// PoW header
-$headers[] = "X-Hashcash: $hashcash";
-// Enforce signature immediately after PoW
-$headers[] = "X-Ed25519-Sig: $sig";
-// Optionally include public key header
-if ($pubkey) {
- $headers[] = "X-Ed25519-Pub: $pubkey";
+// Limit newsgroups to 3
+$groups = array_slice(
+ array_filter(array_map('trim', explode(',', $data['newsgroups']))),
+ 0, 3
+);
+$data['newsgroups'] = implode(', ', $groups);
+
+// Build raw email
+$hdr = [];
+$hdr[] = 'From: ' . $data['from'];
+$hdr[] = 'To: mail2news@localhost'; // dummy for sendmail -t
+$hdr[] = 'Newsgroups: ' . $data['newsgroups'];
+$hdr[] = 'Subject: ' . $data['subject'];
+if (!empty($data['references'])) $hdr[] = 'References: ' . $data['references'];
+$hdr[] = 'X-Hashcash: ' . $data['xhashcash'];
+$hdr[] = 'X-Ed25519-Sig: ' . $data['x-ed25519-sig'];
+if (!empty($data['x-ed25519-pub'])) {
+ $hdr[] = 'X-Ed25519-Pub: ' . $data['x-ed25519-pub'];
}
-$headers[] = "X-No-Archive: Yes";
-$headers[] = "Mime-Version: 1.0";
-$headers[] = "Content-Type: text/plain; charset=UTF-8";
-$headers[] = "Content-Transfer-Encoding: 7bit";
-$headers[] = ""; // end of headers
+$hdr[] = 'X-No-Archive: Yes';
+$hdr[] = 'Mime-Version: 1.0';
+$hdr[] = 'Content-Type: text/plain; charset=UTF-8';
+$hdr[] = 'Content-Transfer-Encoding: 7bit';
+$hdr[] = ''; // blank line before body
-$rawEmail = implode("\r\n", $headers) . "\r\n" . $message . "\r\n";
+$raw = implode("\r\n", $hdr) . "\r\n" . $data['message'] . "\r\n";
-// Send via sendmail using mail2news transport
+// Send via sendmail using the custom transport
$sendmail = '/usr/sbin/sendmail';
$cmd = escapeshellcmd($sendmail) . ' -i -oTransport=mail2news -t';
$descriptors = [
- 0 => ['pipe', 'r'], // stdin
- 1 => ['pipe', 'w'], // stdout
- 2 => ['pipe', 'w'], // stderr
+ 0 => ['pipe', 'r'],
+ 1 => ['pipe', 'w'],
+ 2 => ['pipe', 'w'],
];
-$process = proc_open($cmd, $descriptors, $pipes);
-if (!is_resource($process)) {
- http_response_code(500);
- echo "Failed to invoke sendmail.";
- exit;
-}
+$proc = proc_open($cmd, $descriptors, $pipes);
+if (!is_resource($proc)) showError('Failed to invoke sendmail.');
-// Write the raw email
-fwrite($pipes[0], $rawEmail);
+fwrite($pipes[0], $raw);
fclose($pipes[0]);
-// Capture and close outputs
$stderr = stream_get_contents($pipes[2]);
fclose($pipes[1]);
fclose($pipes[2]);
-$returnCode = proc_close($process);
-if ($returnCode !== 0) {
- http_response_code(500);
- echo "Sendmail error (code {$returnCode}):\n" . nl2br(htmlspecialchars($stderr));
- exit;
+$code = proc_close($proc);
+if ($code !== 0) {
+ showError('Sendmail error (code ' . $code . '):
' . nl2br(htmlspecialchars($stderr)));
}
-// Success page
+// ------------------ success page ------------------
?>
Your post has been handed off to the mail2news transport.
+Your article was handed off to mail2news and should appear in the newsgroups soon.
= $msg ?>
+ + + -- cgit v1.2.3