That was full of bugs. I forgot to specify the forum in the query. Oops. Here's the updated code
Code:
// hide email addresses
$mailmessage = preg_replace("/[a-zA-Z0-9\-_]+@[a-zA-Z0-9\-_]+.[a-z]{2,4}/", 'xxx@xxx.xxx', $mailmessage);
// find thread with matching title 'Post'
// make reply if match
$baseTitle = preg_replace("/re: /", "", $title);
$baseTitle = preg_replace("/Re: /", "", $baseTitle);
$baseTitle = preg_replace("/RE: /", "", $baseTitle);
$forumid = $foruminfo['forumid'];
$queryResult = $vbulletin->db->query_first("
SELECT threadid
FROM " . TABLE_PREFIX . "thread
WHERE forumid = $forumid AND (title = '$title' OR title = '$baseTitle') ORDER BY threadid DESC LIMIT 1
");
if ($queryResult['threadid']) {
$threadid = $queryResult['threadid'];
$type = "reply";
$cronlog .= "Found reply for thread $threadid";
}
// ##### Time To Post The Reply #####
if ($type == "reply")
{
// Building post info