# HG changeset patch # User Ivo Smits # Date 1302612866 -7200 # Node ID ae0c67d72670c070fd58a177da7ca17e25d96d94 # Parent 005339a1b2ced56a45c1a2f79029ff9e41766d10 Bugfix in server POST code, add support for client side IHAVE and fall back to STAT-before-POST diff -r 005339a1b2ce -r ae0c67d72670 fetchnews.php --- a/fetchnews.php Tue Apr 12 14:30:56 2011 +0200 +++ b/fetchnews.php Tue Apr 12 14:54:26 2011 +0200 @@ -93,39 +93,42 @@ } if (!count($articles)) break; foreach ($articles as $article) { - nntp_writeline($socket, 'POST'); - $line = nntp_readline($socket); - $code = strtok($line, " \t"); - if ($code != 340) die("Error code $code from $peer[address]\n"); - foreach (explode("\r\n", $article['header']) as $line) { - $parts = explode(': ', $line, 2); - switch (strtoupper($parts[0])) { - case 'PATH': case 'FROM': case 'NEWSGROUPS': case 'SUBJECT': case 'DATE': case 'ORGANIZATION': - case 'LINES': case 'MESSAGE-ID': case 'MIME-VERSION': case 'CONTENT-TYPE': case 'CONTENT-TRANSFER-ENCODING': - case 'USER-AGENT': case 'REFERENCES': case 'REPLY-TO': case 'SENDER': case 'FOLLOWUP-TO': - case 'EXPIRES': case 'CONTROL': case 'DISTRIBUTION': case 'KEYWORDS': case 'SUMMARY': - case 'IN-REPLY-TO': - break; - case 'NNTP-POSTING-HOST': case 'X-TRACE': case 'XREF': case 'X-COMPLAINTS-TO': - case 'NNTP-POSTING-DATE': - $line = NULL; - break; - default: - print("Sending unknown header $parts[0]\n"); + $dopost = FALSE; + if ($peer['post'] == 2) { + nntp_writeline($socket, 'IHAVE <'.$article['messageid'].'>'); + $line = nntp_readline($socket); + $code = strtok($line, " \t"); + if ($code == 335) $dopost = TRUE; + elseif ($code != 435) $peer['post'] = 1; + } + if ($peer['post'] != 2) { + nntp_writeline($socket, 'STAT <'.$article['messageid'].'>'); + $line = nntp_readline($socket); + $code = strtok($line, " \t"); + if ($code == 430) $dopost = TRUE; + elseif ($code != 223) die("Error code $code from $peer[address]\n"); + if ($dopost) { + nntp_writeline($socket, 'POST'); + $line = nntp_readline($socket); + $code = strtok($line, " \t"); + if ($code != 340) die("Error code $code from $peer[address]\n"); } - if ($line !== NULL) nntp_writeline_data($socket, $line); } - nntp_writeline($socket, ''); - foreach (explode("\r\n", $article['body']) as $line) nntp_writeline_data($socket, $line); - nntp_writeline($socket, '.'); - $line = nntp_readline($socket); - $code = strtok($line, " \t"); - if ($code != 240) print("Article $article[messageid] was not accepted ($code)\n"); + if ($dopost) { + foreach (explode("\r\n", $article['header']) as $line) nntp_writeline_data($socket, $line); + nntp_writeline($socket, ''); + foreach (explode("\r\n", $article['body']) as $line) nntp_writeline_data($socket, $line); + nntp_writeline($socket, '.'); + $line = nntp_readline($socket); + $code = strtok($line, " \t"); + if ($code != 240 && $code != 235) print("Article $article[messageid] was not accepted ($code)\n"); + } if ($article['id'] > $peer['lastposted']) $peer['lastposted'] = $article['id']; } $db->update('UPDATE `peers` SET `lastposted` = ? WHERE `id` = ?', array($peer['lastposted'], $peer['id'])); } nntp_writeline($socket, 'QUIT'); + nntp_readline($socket); fclose($socket); } diff -r 005339a1b2ce -r ae0c67d72670 todo.txt --- a/todo.txt Tue Apr 12 14:30:56 2011 +0200 +++ b/todo.txt Tue Apr 12 14:54:26 2011 +0200 @@ -1,4 +1,2 @@ - Make sure that group article numbers are never reused, not even if the last one is deleted (groupmessages table) -- Support IHAVE command to speed up synchronization -- Use STAT before POSTing articles - Allow to store (part of) article data in file