From 98cacd2682cfd4dd6450eb8095eb77a3d5b443ea Mon Sep 17 00:00:00 2001 From: Retro_Guy Date: Thu, 28 Dec 2023 13:31:43 -0700 Subject: [PATCH] Finish improving multiline header handling. --- .../rslight/scripts/rslight-lib.php | 28 +++++++++++-------- Rocksolid_Light/rslight/scripts/spoolnews.php | 21 +++++++++----- 2 files changed, 30 insertions(+), 19 deletions(-) diff --git a/Rocksolid_Light/rslight/scripts/rslight-lib.php b/Rocksolid_Light/rslight/scripts/rslight-lib.php index 0cf6006..089578d 100644 --- a/Rocksolid_Light/rslight/scripts/rslight-lib.php +++ b/Rocksolid_Light/rslight/scripts/rslight-lib.php @@ -337,6 +337,7 @@ function process_post($message, $group) $is_header = 1; $body = ""; $ref = 0; + $sub = 0; $response = ""; $bytes = 0; $lines = 0; @@ -350,6 +351,10 @@ function process_post($message, $group) if ($is_header == 0) { $body .= $line . "\n"; } else { + if (strpos($line, ': ') !== false) { + $ref = 0; + $sub = 0; + } if (stripos($line, "Date: ") === 0) { $finddate = explode(': ', $line); $article_date = strtotime($finddate[1]); @@ -359,31 +364,30 @@ function process_post($message, $group) $no_org = 0; } if (stripos($line, "Subject: ") !== false) { - $subject = explode('Subject: ', $line, 2); - $ref = 0; + $this_subject = explode('Subject: ', $line, 2); + $subject = $this_subject[1]; + $sub = 1; } if (stripos($line, "From: ") === 0) { $from = explode(': ', $line); - $ref = 0; } if (stripos($line, "Xref: ") === 0) { $xref = $line; - $ref = 0; } if (stripos($line, "Newsgroups: ") === 0) { $ngroups = explode(': ', $line); $newsgroups = $ngroups[1]; - $ref = 0; } if (stripos($line, "References: ") === 0) { $references_line = explode(': ', $line); $references = $references_line[1]; $ref = 1; } - if ((stripos($line, ':') === false) && (strpos($line, '>'))) { - if ($ref == 1) { - $references = $references . " " . trim($line); - } + if (preg_match('/^\s/', $line) && $ref == 1) { + $references = $references . $line; + } + if (preg_match('/^\s/', $line) && $sub == 1) { + $subject = $subject . $line; } if (stripos($line, "Message-ID: ") !== false) { $mid = explode(': ', $line); @@ -395,7 +399,7 @@ function process_post($message, $group) * SPAM CHECK */ if (isset($CONFIG['spamassassin']) && ($CONFIG['spamassassin'] == true)) { - $spam_result_array = check_spam($subject[1], $from[1], $newsgroups, $references, $body, $msgid, true); + $spam_result_array = check_spam($subject, $from[1], $newsgroups, $references, $body, $msgid, true); $res = $spam_result_array['res']; $spamresult = $spam_result_array['spamresult']; $spamcheckerversion = $spam_result_array['spamcheckerversion']; @@ -422,7 +426,7 @@ function process_post($message, $group) $date_rep = $finddate[1]; } if ($no_mid == 1) { - $identity = $subject[1] . "," . $from[1] . "," . $ngroups[1] . "," . $references . "," . $body; + $identity = $subject . "," . $from[1] . "," . $ngroups[1] . "," . $references . "," . $body; $msgid = '<' . md5($identity) . '$1@' . trim($CONFIG['email_tail'], '@') . '>'; fputs($postfilehandle, "Message-ID: " . $msgid . "\r\n"); } else { @@ -455,7 +459,7 @@ function process_post($message, $group) if ($section == "") { $response = "441 Posting failed (section not found)\r\n"; } else { - $response = insert_article($section, $group, $postfilename, $subject[1], $from[1], $article_date, $date_rep, $msgid, $references, $bytes, $lines, $xref, $body); + $response = insert_article($section, $group, $postfilename, $subject, $from[1], $article_date, $date_rep, $msgid, $references, $bytes, $lines, $xref, $body); } return $response; } diff --git a/Rocksolid_Light/rslight/scripts/spoolnews.php b/Rocksolid_Light/rslight/scripts/spoolnews.php index 199d4b6..3cb98ce 100644 --- a/Rocksolid_Light/rslight/scripts/spoolnews.php +++ b/Rocksolid_Light/rslight/scripts/spoolnews.php @@ -261,6 +261,7 @@ function get_articles($ns, $group) $lines = 0; $bytes = 0; $ref = 0; + $sub = 0; $banned = false; $is_header = 1; $body = ""; @@ -277,6 +278,7 @@ function get_articles($ns, $group) $response = str_replace("\t", " ", $response); if (strpos($response, ': ') !== false) { $ref = 0; + $sub = 0; } // Find article date if (stripos($response, "Date: ") === 0) { @@ -303,8 +305,10 @@ function get_articles($ns, $group) } } if (stripos($response, "Subject: ") === 0) { - $subject = explode('Subject: ', $response, 2); - if (preg_match($subject_filter, $subject[1])) { + $this_subject = explode('Subject: ', $response, 2); + $subject = $this_subject[1]; + $sub = 1; + if (preg_match($subject_filter, $subject)) { $banned = "subject_filter"; } } @@ -348,6 +352,9 @@ function get_articles($ns, $group) if (preg_match('/^\s/', $response) && $ref == 1) { $references = $references . $response; } + if (preg_match('/^\s/', $response) && $sub == 1) { + $subject = $subject . $response; + } } else { $body .= $response . "\n"; } @@ -375,7 +382,7 @@ function get_articles($ns, $group) $article ++; } else { if ((strpos($CONFIG['nocem_groups'], $group) !== false) && ($CONFIG['enable_nocem'] == true)) { - if (strpos($subject[1], $nocem_check) !== false) { + if (strpos($subject, $nocem_check) !== false) { $is_from = address_decode($from[1], 'nowhere'); $nocem_file = tempnam($spooldir . "/nocem", $is_from[0]['mailbox'] . "@" . $is_from[0]['host'] . "[" . date("Y.m.d.H.i.s") . "]"); copy($articleHandle, $nocem_file); @@ -387,8 +394,8 @@ function get_articles($ns, $group) } } if ((strpos($rslight_gpg['nntp_group'], $group) !== false) && ($rslight_gpg['enable'] == '1')) { - if (strpos($subject[1], $bbsmail_check) !== false) { - $bbsmail_file = preg_replace('/@@RSL /', '', $subject[1]); + if (strpos($subject, $bbsmail_check) !== false) { + $bbsmail_file = preg_replace('/@@RSL /', '', $subject); $bbsmail_filename = $spooldir . "/bbsmail/in/bbsmail-" . $bbsmail_file; copy($articleHandle, $bbsmail_filename); } @@ -408,7 +415,7 @@ function get_articles($ns, $group) $current_article['epochdate'] = $article_date; $current_article['stringdate'] = $finddate[1]; $current_article['from'] = $from[1]; - $current_article['subject'] = $subject[1]; + $current_article['subject'] = $subject; $current_article['references'] = $references; $current_article['bytes'] = $bytes; $current_article['lines'] = $lines; @@ -418,7 +425,7 @@ function get_articles($ns, $group) // Check Spam $res = 0; if (isset($CONFIG['spamassassin']) && ($CONFIG['spamassassin'] == true) && ($OVERRIDES['disable_spamassassin_spooling'] !== true)) { - $spam_result_array = check_spam($subject[1], $from[1], $groupnames[1], $references, $this_article, $mid[1]); + $spam_result_array = check_spam($subject, $from[1], $groupnames[1], $references, $this_article, $mid[1]); $res = $spam_result_array['res']; $spamresult = $spam_result_array['spamresult']; $spamcheckerversion = $spam_result_array['spamcheckerversion'];