Beispiel #1
0
function NextMailFile()
{
    $dir = scandir(substr(BOUNCEBACK_PATH, 0, -1), SCANDIR_SORT_ASCENDING);
    $lockFail = false;
    $gotFile = false;
    foreach ($dir as $fileName) {
        if (preg_match('/^(\\d+)\\./', $fileName, $res)) {
            if (($handle = fopen(BOUNCEBACK_PATH . $fileName, 'rb')) === false) {
                continue;
            }
            if (!flock($handle, LOCK_EX | LOCK_NB)) {
                $lockFail = true;
                fclose($handle);
                continue;
            }
            if (feof($handle)) {
                fclose($handle);
                unlink(BOUNCEBACK_PATH . $fileName);
                continue;
            }
            $ts = intval($res[1], 10);
            $gotFile = $fileName;
            break;
        }
    }
    unset($dir);
    if (!$gotFile) {
        if ($lockFail) {
            sleep(3);
            return true;
        }
        return false;
    }
    DebugMessage('Found message received at ' . date('Y-m-d H:i:s', $ts) . ', ' . TimeDiff($ts));
    $message = fread($handle, min(filesize(BOUNCEBACK_PATH . $fileName), 4194304));
    ftruncate($handle, 0);
    fclose($handle);
    unlink(BOUNCEBACK_PATH . $fileName);
    $mailId = false;
    if (preg_match('/X-Undermine-MailID:\\s*([a-zA-Z0-9_-]{27})/', $message, $res)) {
        $mailId = $res[1];
    } elseif (preg_match('/[Mm]essage ID: ([a-zA-Z0-9_-]{27})/', $message, $res)) {
        $mailId = $res[1];
    }
    if (!$mailId) {
        DebugMessage('Could not find message ID, forwarding to editor');
        NewsstandMail('*****@*****.**', 'The Editor', 'Unparsed notification reply', $message);
    } else {
        $address = GetAddressByMailID($mailId);
        if (!$address) {
            DebugMessage('Could not find address for mail ID ' . $mailId);
        } else {
            $cnt = DisableEmailAddress($address['address']);
            DebugMessage('Address ' . $address['address'] . ' removed from ' . $cnt . ' account' . ($cnt == 1 ? '' : 's') . '.');
        }
    }
    return true;
}
Beispiel #2
0
function BlockMailId($mailId)
{
    $db = DBConnect();
    if (!$db) {
        return 'Could not connect to database, please try again later.';
    }
    $address = GetAddressByMailID($mailId);
    if ($address === false) {
        return 'Could not find an email by that ID, please try again later.';
    }
    if (!is_null($address['blocked'])) {
        return $address['address'] . ' was removed on ' . date('Y-m-d H:i:s', $address['blocked']);
    }
    $stmt = $db->prepare('insert into tblEmailBlocked (address, added) values (?, now())');
    $stmt->bind_param('s', $address['address']);
    $stmt->execute();
    $stmt->close();
    $rowCount = $db->affected_rows;
    if ($rowCount == 0) {
        return 'Error adding row to blocked table, please try again later.';
    }
    DisableEmailAddress($address['address']);
    return $address['address'] . ' will no longer receive any mail from The Undermine Journal.';
}