Clean up rslight-lib a little. Fix finding msg by msgid
This commit is contained in:
parent
f90fcbded2
commit
ee86c8209c
|
@ -459,28 +459,18 @@ function get_last($nntp_group) {
|
||||||
|
|
||||||
function get_xhdr($header, $articles) {
|
function get_xhdr($header, $articles) {
|
||||||
global $config_dir,$spooldir,$nntp_group,$workpath,$path;
|
global $config_dir,$spooldir,$nntp_group,$workpath,$path;
|
||||||
// By Message-ID
|
|
||||||
$tmpgroup=$nntp_group;
|
$tmpgroup=$nntp_group;
|
||||||
$mid=false;
|
$mid=false;
|
||||||
|
// By Message-ID
|
||||||
if(!is_numeric($articles)) {
|
if(!is_numeric($articles)) {
|
||||||
$database = $spooldir.'/articles-overview.db3';
|
$found = find_article_by_msgid($articles);
|
||||||
$table = 'overview';
|
$tmpgroup = $found['newsgroup'];
|
||||||
$dbh = rslight_db_open($database, $table);
|
$articles = $found['number'];
|
||||||
$stmt = $dbh->prepare("SELECT * FROM $table WHERE msgid like :terms");
|
|
||||||
$stmt->bindParam(':terms', $article);
|
|
||||||
$stmt->execute();
|
|
||||||
while($found = $stmt->fetch()) {
|
|
||||||
$nntp_group = $found['newsgroup'];
|
|
||||||
$article = $found['number'];
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
$dbh = null;
|
if($tmpgroup == '') {
|
||||||
} else {
|
|
||||||
if($nntp_group == '') {
|
|
||||||
$msg="412 no newsgroup selected\r\n";
|
$msg="412 no newsgroup selected\r\n";
|
||||||
return $msg;
|
return $msg;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
$thisgroup = $path."/".preg_replace('/\./', '/', $tmpgroup);
|
$thisgroup = $path."/".preg_replace('/\./', '/', $tmpgroup);
|
||||||
$article_num = explode('-', $articles);
|
$article_num = explode('-', $articles);
|
||||||
$first = $article_num[0];
|
$first = $article_num[0];
|
||||||
|
@ -501,7 +491,7 @@ function get_xhdr($header, $articles) {
|
||||||
$msg="221 Header information for ".$header." follows (from articles)\r\n";
|
$msg="221 Header information for ".$header." follows (from articles)\r\n";
|
||||||
for($i=$first; $i<=$last; $i++) {
|
for($i=$first; $i<=$last; $i++) {
|
||||||
$article_full_path=$thisgroup.'/'.strval($i);
|
$article_full_path=$thisgroup.'/'.strval($i);
|
||||||
$data=extract_header_line($article_full_path, $header, $thisgroup, $i);
|
$data=extract_header_line($article_full_path, $header, $tmpgroup, $i);
|
||||||
if($data !== false) {
|
if($data !== false) {
|
||||||
if($mid !== false) {
|
if($mid !== false) {
|
||||||
$msg.=$mid." ".$data;
|
$msg.=$mid." ".$data;
|
||||||
|
@ -517,7 +507,7 @@ function get_xhdr($header, $articles) {
|
||||||
function extract_header_line($article_full_path, $header, $thisgroup, $article) {
|
function extract_header_line($article_full_path, $header, $thisgroup, $article) {
|
||||||
global $CONFIG;
|
global $CONFIG;
|
||||||
if($CONFIG['article_database'] == '1') {
|
if($CONFIG['article_database'] == '1') {
|
||||||
$thisarticle=get_db_article($article, $thisgroup);
|
$thisarticle=np_get_db_article($article, $thisgroup);
|
||||||
} else {
|
} else {
|
||||||
$thisarticle=file($article_full_path, FILE_IGNORE_NEW_LINES);
|
$thisarticle=file($article_full_path, FILE_IGNORE_NEW_LINES);
|
||||||
}
|
}
|
||||||
|
@ -638,19 +628,10 @@ function get_article($article, $nntp_group) {
|
||||||
}
|
}
|
||||||
// By Message-ID
|
// By Message-ID
|
||||||
if(!is_numeric($article)) {
|
if(!is_numeric($article)) {
|
||||||
$database = $spooldir.'/articles-overview.db3';
|
$found = find_article_by_msgid($article);
|
||||||
$table = 'overview';
|
|
||||||
$dbh = rslight_db_open($database, $table);
|
|
||||||
$stmt = $dbh->prepare("SELECT * FROM $table WHERE msgid like :terms");
|
|
||||||
$stmt->bindParam(':terms', $article);
|
|
||||||
$stmt->execute();
|
|
||||||
while($found = $stmt->fetch()) {
|
|
||||||
$nntp_group = $found['newsgroup'];
|
$nntp_group = $found['newsgroup'];
|
||||||
$article = $found['number'];
|
$article = $found['number'];
|
||||||
$this_id = $found['msgid'];
|
$this_id = $found['msgid'];
|
||||||
break;
|
|
||||||
}
|
|
||||||
$dbh = null;
|
|
||||||
} else {
|
} else {
|
||||||
// By article number
|
// By article number
|
||||||
if($nntp_group === "") {
|
if($nntp_group === "") {
|
||||||
|
@ -663,11 +644,12 @@ function get_article($article, $nntp_group) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if($CONFIG['article_database'] == '1') {
|
if($CONFIG['article_database'] == '1') {
|
||||||
$thisarticle=get_db_article($article, $nntp_group);
|
$thisarticle=np_get_db_article($article, $nntp_group);
|
||||||
if($thisarticle === FALSE) {
|
if($thisarticle === FALSE) {
|
||||||
$msg.="430 no such article found\r\n";
|
$msg.="430 no such article found\r\n";
|
||||||
return $msg;
|
return $msg;
|
||||||
}
|
}
|
||||||
|
$thisarticle[] = ".";
|
||||||
} else {
|
} else {
|
||||||
$thisgroup = $path."/".preg_replace('/\./', '/', $nntp_group);
|
$thisgroup = $path."/".preg_replace('/\./', '/', $nntp_group);
|
||||||
if(!file_exists($thisgroup."/".$article)) {
|
if(!file_exists($thisgroup."/".$article)) {
|
||||||
|
@ -687,45 +669,6 @@ function get_article($article, $nntp_group) {
|
||||||
return $msg.$msg2;
|
return $msg.$msg2;
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_db_article($article, $group) {
|
|
||||||
global $nntp_article,$nntp_group,$config_dir,$path,$groupconfig,$config_name,$spooldir;
|
|
||||||
$msg2="";
|
|
||||||
$ok_article = 0;
|
|
||||||
$database = $spooldir.'/'.$nntp_group.'-articles.db3';
|
|
||||||
$dbh = rslight_db_open($database);
|
|
||||||
// Use article pointer
|
|
||||||
if(!isset($article) && is_numeric($nntp_article)) {
|
|
||||||
$article = $nntp_article;
|
|
||||||
}
|
|
||||||
// By Message-ID
|
|
||||||
if(!is_numeric($article)) {
|
|
||||||
$stmt = $dbh->prepare("SELECT * FROM articles WHERE msgid like :terms");
|
|
||||||
$stmt->bindParam(':terms', $article);
|
|
||||||
$stmt->execute();
|
|
||||||
while($found = $stmt->fetch()) {
|
|
||||||
$msg2 = $found['article'];
|
|
||||||
$ok_article = 1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$stmt = $dbh->prepare("SELECT * FROM articles WHERE number = :terms");
|
|
||||||
$stmt->bindParam(':terms', $article);
|
|
||||||
$stmt->execute();
|
|
||||||
while($found = $stmt->fetch()) {
|
|
||||||
$msg2 = $found['article'];
|
|
||||||
$ok_article = 1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$dbh = null;
|
|
||||||
if($ok_article !== 1) {
|
|
||||||
return FALSE;
|
|
||||||
} else {
|
|
||||||
$thisarticle = preg_split("/\r\n|\n|\r/", trim($msg2));
|
|
||||||
return $thisarticle;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function get_header($article, $nntp_group) {
|
function get_header($article, $nntp_group) {
|
||||||
global $CONFIG,$nntp_article,$config_dir,$path,$groupconfig,$config_name,$spooldir;
|
global $CONFIG,$nntp_article,$config_dir,$path,$groupconfig,$config_name,$spooldir;
|
||||||
$msg2="";
|
$msg2="";
|
||||||
|
@ -733,27 +676,12 @@ function get_header($article, $nntp_group) {
|
||||||
if(!isset($article) && is_numeric($nntp_article)) {
|
if(!isset($article) && is_numeric($nntp_article)) {
|
||||||
$article = $nntp_article;
|
$article = $nntp_article;
|
||||||
}
|
}
|
||||||
if($CONFIG['article_database'] == '1') {
|
|
||||||
$thisarticle=get_db_article($article, $nntp_group);
|
|
||||||
if($thisarticle === FALSE) {
|
|
||||||
$msg.="430 no such article found\r\n";
|
|
||||||
return $msg;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// By Message-ID
|
// By Message-ID
|
||||||
if(!is_numeric($article)) {
|
if(!is_numeric($article)) {
|
||||||
$database = $spooldir.'/articles-overview.db3';
|
$found = find_article_by_msgid($article);
|
||||||
$table = 'overview';
|
|
||||||
$dbh = rslight_db_open($database, $table);
|
|
||||||
$stmt = $dbh->prepare("SELECT * FROM $table WHERE msgid like :terms");
|
|
||||||
$stmt->bindParam(':terms', $article);
|
|
||||||
$stmt->execute();
|
|
||||||
while($found = $stmt->fetch()) {
|
|
||||||
$nntp_group = $found['newsgroup'];
|
$nntp_group = $found['newsgroup'];
|
||||||
$article = $found['number'];
|
$article = $found['number'];
|
||||||
break;
|
$this_id = $found['msgid'];
|
||||||
}
|
|
||||||
$dbh = null;
|
|
||||||
} else {
|
} else {
|
||||||
// By article number
|
// By article number
|
||||||
if($nntp_group === "") {
|
if($nntp_group === "") {
|
||||||
|
@ -765,6 +693,13 @@ function get_header($article, $nntp_group) {
|
||||||
return $msg;
|
return $msg;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if($CONFIG['article_database'] == '1') {
|
||||||
|
$thisarticle=np_get_db_article($article, $nntp_group);
|
||||||
|
if($thisarticle === FALSE) {
|
||||||
|
$msg.="430 no such article found\r\n";
|
||||||
|
return $msg;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
$thisgroup = $path."/".preg_replace('/\./', '/', $nntp_group);
|
$thisgroup = $path."/".preg_replace('/\./', '/', $nntp_group);
|
||||||
if(!file_exists($thisgroup."/".$article)) {
|
if(!file_exists($thisgroup."/".$article)) {
|
||||||
$msg.="430 no such article found\r\n";
|
$msg.="430 no such article found\r\n";
|
||||||
|
@ -793,32 +728,12 @@ function get_body($article, $nntp_group) {
|
||||||
if(!isset($article) && is_numeric($nntp_article)) {
|
if(!isset($article) && is_numeric($nntp_article)) {
|
||||||
$article = $nntp_article;
|
$article = $nntp_article;
|
||||||
}
|
}
|
||||||
if($CONFIG['article_database'] == '1') {
|
|
||||||
$thisarticle=get_db_article($article, $nntp_group);
|
|
||||||
if($thisarticle === FALSE) {
|
|
||||||
$msg.="430 no such article found\r\n";
|
|
||||||
return $msg;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// By Message-ID
|
// By Message-ID
|
||||||
if(!is_numeric($article)) {
|
if(!is_numeric($article)) {
|
||||||
$menulist = file($config_dir."menu.conf", FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
|
$found = find_article_by_msgid($article);
|
||||||
foreach($menulist as $menu) {
|
$nntp_group = $found['newsgroup'];
|
||||||
if(($menu[0] == '#') || (trim($menu) == "")) {
|
$article = $found['number'];
|
||||||
continue;
|
$this_id = $found['msgid'];
|
||||||
}
|
|
||||||
$name=explode(":", $menu);
|
|
||||||
$overviewdata = file($spooldir."/".$name[0]."-overview", FILE_IGNORE_NEW_LINES);
|
|
||||||
foreach($overviewdata as $overviewline) {
|
|
||||||
// Remove :#rsl#: in 0.6.6 and only use tab
|
|
||||||
$articledata = preg_split("/(:#rsl#:|\t)/", $overviewline);
|
|
||||||
if(!strcasecmp($articledata[2], $article)) {
|
|
||||||
$nntp_group=$articledata[0];
|
|
||||||
$article=$articledata[1];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// By article number
|
// By article number
|
||||||
if($nntp_group === "") {
|
if($nntp_group === "") {
|
||||||
|
@ -830,6 +745,14 @@ function get_body($article, $nntp_group) {
|
||||||
return $msg;
|
return $msg;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if($CONFIG['article_database'] == '1') {
|
||||||
|
$thisarticle=np_get_db_article($article, $nntp_group);
|
||||||
|
if($thisarticle === FALSE) {
|
||||||
|
$msg.="430 no such article found\r\n";
|
||||||
|
return $msg;
|
||||||
|
}
|
||||||
|
$thisarticle[] = ".";
|
||||||
|
} else {
|
||||||
$thisgroup = $path."/".preg_replace('/\./', '/', $nntp_group);
|
$thisgroup = $path."/".preg_replace('/\./', '/', $nntp_group);
|
||||||
if(!file_exists($thisgroup."/".$article)) {
|
if(!file_exists($thisgroup."/".$article)) {
|
||||||
$msg.="430 no such article found\r\n";
|
$msg.="430 no such article found\r\n";
|
||||||
|
@ -837,7 +760,6 @@ function get_body($article, $nntp_group) {
|
||||||
}
|
}
|
||||||
$thisarticle=file($thisgroup."/".$article, FILE_IGNORE_NEW_LINES);
|
$thisarticle=file($thisgroup."/".$article, FILE_IGNORE_NEW_LINES);
|
||||||
}
|
}
|
||||||
$body=0;
|
|
||||||
foreach($thisarticle as $thisline) {
|
foreach($thisarticle as $thisline) {
|
||||||
if(($thisline == "") && ($body == 0)) {
|
if(($thisline == "") && ($body == 0)) {
|
||||||
$body=1;
|
$body=1;
|
||||||
|
@ -1155,6 +1077,24 @@ $date_i,$mid_i,$references_i,$bytes_i,$lines_i,$xref_i,$body) {
|
||||||
unlink($sn_lockfile);
|
unlink($sn_lockfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function find_article_by_msgid($msgid) {
|
||||||
|
global $spooldir;
|
||||||
|
$database = $spooldir.'/articles-overview.db3';
|
||||||
|
$table = 'overview';
|
||||||
|
$dbh = rslight_db_open($database, $table);
|
||||||
|
$stmt = $dbh->prepare("SELECT * FROM $table WHERE msgid like :terms");
|
||||||
|
$stmt->bindParam(':terms', $msgid);
|
||||||
|
$stmt->execute();
|
||||||
|
while($found = $stmt->fetch()) {
|
||||||
|
$return['newsgroup'] = $found['newsgroup'];
|
||||||
|
$return['number'] = $found['number'];
|
||||||
|
$return['msgid'] = $found['msgid'];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
$dbh = null;
|
||||||
|
return $return;
|
||||||
|
}
|
||||||
|
|
||||||
function get_article_list($thisgroup) {
|
function get_article_list($thisgroup) {
|
||||||
global $spooldir;
|
global $spooldir;
|
||||||
$database = $spooldir."/articles-overview.db3";
|
$database = $spooldir."/articles-overview.db3";
|
||||||
|
|
Loading…
Reference in New Issue