Ejemplo n.º 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;
}
Ejemplo n.º 2
0
function SetSubEmail($loginState, $address)
{
    $userId = $loginState['id'];
    $lang = GetLang($loginState['locale']);
    $address = trim($address);
    if ($address) {
        $filtered = filter_var($address, FILTER_VALIDATE_EMAIL);
        if ($filtered === false) {
            return ['status' => 'invalid'];
        }
        $address = $filtered;
    }
    $db = DBConnect();
    $cnt = 0;
    $stmt = $db->prepare('select count(*) from tblEmailBlocked where address=?');
    $stmt->bind_param('s', $address);
    $stmt->execute();
    $stmt->bind_result($cnt);
    $stmt->fetch();
    $stmt->close();
    if ($cnt != 0) {
        return ['status' => 'invalid'];
    }
    $stmt = $db->prepare('SELECT ifnull(email,\'\') address, unix_timestamp(emailset) emailset, emailverification from tblUser where id = ?');
    $stmt->bind_param('i', $userId);
    $stmt->execute();
    $result = $stmt->get_result();
    $row = $result->fetch_assoc();
    $result->close();
    $stmt->close();
    if ($row === false) {
        // could not find user
        return ['status' => 'unknown'];
    }
    if ($address && !is_null($row['emailverification']) && $row['emailset'] > time() - 15 * 60) {
        // setting a new address when we recently sent a notification email to another address
        return ['status' => 'verify', 'address' => $row['address']];
    }
    if ($address == $row['address']) {
        // setting address we already have saved
        if (!is_null($row['emailverification'])) {
            // resend notification email
            NewsstandMail($address, $loginState['name'], $lang['emailAddressUpdated'], sprintf($lang['emailVerificationMessage'], implode(' ', str_split($row['emailverification'], 3))), $loginState['locale']);
            SendUserMessage($userId, 'Email', $lang['emailVerificationResent'], sprintf($lang['emailVerificationResentMessage'], htmlspecialchars($address, ENT_COMPAT | ENT_HTML5)));
        }
        return ['status' => is_null($row['emailverification']) ? 'success' : 'verify', 'address' => $row['address']];
    }
    if (!$address) {
        // removing the address
        $stmt = $db->prepare('update tblUser set email=null, emailverification=null where id = ?');
        $stmt->bind_param('i', $userId);
        $stmt->execute();
        $stmt->close();
        if ($db->affected_rows == 0) {
            return ['status' => 'unknown'];
        }
        SendUserMessage($userId, 'Email', $lang['emailAddressRemoved'], $lang['emailAddressRemovedMessage']);
        return ['status' => 'success', 'address' => $address];
    }
    // setting a new address
    $stmt = $db->prepare('update tblUser set email=null, emailverification=null where id = ?');
    $stmt->bind_param('i', $userId);
    $stmt->execute();
    $stmt->close();
    if ($db->affected_rows == 0) {
        return ['status' => 'unknown'];
    }
    $verification = str_pad(mt_rand(1, 999999999), 9, '0', STR_PAD_BOTH);
    NewsstandMail($address, $loginState['name'], $lang['emailAddressUpdated'], sprintf($lang['emailVerificationMessage'], implode(' ', str_split($verification, 3))), $loginState['locale']);
    SendUserMessage($userId, 'Email', $lang['emailAddressUpdated'], sprintf($lang['emailAddressUpdatedMessage'], htmlspecialchars($address, ENT_COMPAT | ENT_HTML5)));
    $stmt = $db->prepare('update tblUser set email=?, emailverification=?, emailset=NOW() where id = ?');
    $stmt->bind_param('ssi', $address, $verification, $userId);
    $stmt->execute();
    $stmt->close();
    if ($db->affected_rows == 0) {
        SendUserMessage($userId, 'Email', $lang['emailAddressRemoved'], $lang['emailAddressRemovedError']);
        return ['status' => 'unknown'];
    }
    return ['status' => 'verify', 'address' => $address];
}
Ejemplo n.º 3
0
function LogPaypalError($message, $subject = 'Paypal IPN Issue')
{
    global $argv;
    $pth = __DIR__ . '/../logs/paypalerrors.log';
    if ($pth) {
        $me = PHP_SAPI == 'cli' ? 'CLI:' . realpath($argv[0]) : 'Web:' . $_SERVER['REQUEST_URI'];
        file_put_contents($pth, date('Y-m-d H:i:s') . " {$me} {$message}\n" . ($subject === false ? '' : print_r($_POST, true)), FILE_APPEND | LOCK_EX);
    }
    if ($subject !== false) {
        NewsstandMail(SUBSCRIPTION_ERRORS_EMAIL_ADDRESS, 'Paypal Manager', $subject, $message . "<br><br>" . str_replace("\n", '<br>', print_r($_POST, true)));
    }
}