Observant Usenet user emailed me that some replies going to Usenet from our gateway didn't have "References" header and "Re: " in the subject. I investigated this, and it appears that current code is indeed buggy.
Current code first chooses new forum threads and then new posts to send to news server, but SQL query responsible for new threads gets it all wrong.
It gets not only new threads' posts themselves, but also posts to the same thread by the thread author, if the thread was started from the forum. It means that all subsequent forum posts to the thread by the thread author won't get "References" header and also "Re: " in the subject, and therefore won't be threaded in the newsgroups.
The fix is to use special "firstpostid" field in the thread table for determining the first post in the thread.
Replace this code:
PHP Code:
$get_newthreads=$DB_site->query("SELECT post.*, thread.*,
post.dateline AS postdateline, post.msgid AS postmsgid,
thread.title AS threadtitle
FROM " . TABLE_PREFIX . "post as post LEFT JOIN " .
TABLE_PREFIX . "thread as thread ON (
thread.threadid = post.threadid
AND post.userid = thread.postuserid)
WHERE post.isusenetpost = 0 AND
post.postid > {$nntp_settings['last_postid']} AND
thread.forumid = {$group['forum']}");
with this:
PHP Code:
$get_newthreads=$DB_site->query("SELECT post.*, thread.*,
post.dateline AS postdateline, post.msgid AS postmsgid,
thread.title AS threadtitle
FROM " . TABLE_PREFIX . "thread as thread LEFT JOIN " .
TABLE_PREFIX . "post as post ON
thread.firstpostid = post.postid
WHERE post.isusenetpost = 0 AND
post.postid > {$nntp_settings['last_postid']} AND
thread.forumid = {$group['forum']}");