Mercurial > hg > pnewss
diff fetchnews.php @ 1:61fac319ca3e
Update Path and Xref header fields while fetching messages, added database schema export
author | Ivo Smits <Ivo@UCIS.nl> |
---|---|
date | Mon, 11 Apr 2011 23:17:27 +0200 |
parents | d7ab68b71c74 |
children | 40e545510a57 |
line wrap: on
line diff
--- a/fetchnews.php Mon Apr 11 22:44:47 2011 +0200 +++ b/fetchnews.php Mon Apr 11 23:17:27 2011 +0200 @@ -46,6 +46,8 @@ if ($code != 221) die("Error code $code from $peer[address]\n"); strtok(" \t"); //article number $lines = nntp_readlines($socket); + nntp_removeheader(&$lines, 'Xref'); + nntp_updatepath(&$lines, 'pNewss.Core.UCIS.nl'); $header = implode("\r\n", $lines); nntp_writeline($socket, 'BODY '.$i); @@ -67,6 +69,25 @@ fclose($socket); } +function nntp_removeheader(&$lines, $header) { + $header = strtoupper($header).':'; + $hlen = strlen($header); + foreach ($lines as $key => $line) if (strtoupper(substr($line, 0, $hlen)) == $header) unset($lines[$key]); +} +function nntp_updatepath(&$lines, $value) { + $header = strtoupper('Path').':'; + $hlen = strlen($header); + $found = FALSE; + foreach ($lines as &$line) if (strtoupper(substr($line, 0, $hlen)) == $header) { + $parts = explode(': ', $line, 2); + $parts[1] = $value.'!'.$parts[1]; + $line = implode(': ', $parts); + $found = TRUE; + break; + } + if (!$found) $lines[] = 'Path: '.$value; +} + function nntp_readline($socket) { $line = rtrim(fgets($socket, 512), "\r\n"); print('R: '.$line."\n");