comparison 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
comparison
equal deleted inserted replaced
0:d7ab68b71c74 1:61fac319ca3e
44 $line = nntp_readline($socket); 44 $line = nntp_readline($socket);
45 $code = strtok($line, " \t"); 45 $code = strtok($line, " \t");
46 if ($code != 221) die("Error code $code from $peer[address]\n"); 46 if ($code != 221) die("Error code $code from $peer[address]\n");
47 strtok(" \t"); //article number 47 strtok(" \t"); //article number
48 $lines = nntp_readlines($socket); 48 $lines = nntp_readlines($socket);
49 nntp_removeheader(&$lines, 'Xref');
50 nntp_updatepath(&$lines, 'pNewss.Core.UCIS.nl');
49 $header = implode("\r\n", $lines); 51 $header = implode("\r\n", $lines);
50 52
51 nntp_writeline($socket, 'BODY '.$i); 53 nntp_writeline($socket, 'BODY '.$i);
52 $line = nntp_readline($socket); 54 $line = nntp_readline($socket);
53 $code = strtok($line, " \t"); 55 $code = strtok($line, " \t");
65 } 67 }
66 nntp_writeline($socket, 'QUIT'); 68 nntp_writeline($socket, 'QUIT');
67 fclose($socket); 69 fclose($socket);
68 } 70 }
69 71
72 function nntp_removeheader(&$lines, $header) {
73 $header = strtoupper($header).':';
74 $hlen = strlen($header);
75 foreach ($lines as $key => $line) if (strtoupper(substr($line, 0, $hlen)) == $header) unset($lines[$key]);
76 }
77 function nntp_updatepath(&$lines, $value) {
78 $header = strtoupper('Path').':';
79 $hlen = strlen($header);
80 $found = FALSE;
81 foreach ($lines as &$line) if (strtoupper(substr($line, 0, $hlen)) == $header) {
82 $parts = explode(': ', $line, 2);
83 $parts[1] = $value.'!'.$parts[1];
84 $line = implode(': ', $parts);
85 $found = TRUE;
86 break;
87 }
88 if (!$found) $lines[] = 'Path: '.$value;
89 }
90
70 function nntp_readline($socket) { 91 function nntp_readline($socket) {
71 $line = rtrim(fgets($socket, 512), "\r\n"); 92 $line = rtrim(fgets($socket, 512), "\r\n");
72 print('R: '.$line."\n"); 93 print('R: '.$line."\n");
73 return $line; 94 return $line;
74 } 95 }