/**
 * Insert/Update the data of email address into DB
 *
 * @param array Data of returned email:
 *               'address'
 *               'errormsg'
 *               'message'
 *               'headers'
 *               'errtype'
 */
function dre_save_email_address_data($email_returned)
{
    global $DB;
    if (empty($email_returned['address'])) {
        // No emails, Exit here
        return;
    }
    $EmailAddressCache =& get_EmailAddressCache();
    // Get an existing email address to update if it exist
    $EmailAddress =& $EmailAddressCache->get_by_name($email_returned['address'], false);
    if (!$EmailAddress) {
        // Insert new email address
        $EmailAddress = new EmailAddress();
        $EmailAddress->set('address', $email_returned['address']);
    }
    switch ($email_returned['errtype']) {
        // Error type of the returned email:
        case 'P':
            // Permanent error
            $EmailAddress->increase_counter('prmerror');
            // Update only the adresses with NOT spammer statuses
            $EmailAddress->set_status('prmerror');
            break;
        case 'T':
            // Temporary error
            if (in_array($EmailAddress->get('status'), array('suspicious1', 'suspicious2', 'suspicious3'))) {
                // If current status already is defined as 'suspicious1', 'suspicious2' or 'suspicious3'
                if ($EmailAddress->get('sent_last_returnerror') <= 1) {
                    if ($EmailAddress->get('status') == 'suspicious1') {
                        // Increase status from suspicious1 to suspicious2
                        $EmailAddress->set('status', 'suspicious2');
                    } elseif ($EmailAddress->get('status') == 'suspicious2') {
                        // Increase status from suspicious2 to suspicious3
                        $EmailAddress->set('status', 'suspicious3');
                    }
                }
            } elseif ($EmailAddress->get('status') == 'redemption') {
                // IF current status is 'redemption' we should set it as 'suspicious3'
                $EmailAddress->set_status('suspicious3');
            } else {
                // Update only the email addresses with level status less then Suspicious 1
                $EmailAddress->set_status('suspicious1');
            }
            $EmailAddress->increase_counter('tmperror');
            break;
        case 'S':
            // Spam suspicion
            $EmailAddress->increase_counter('spamerror');
            // Update only the email addresses with 'unknown' status
            $EmailAddress->set_status('warning');
            break;
        default:
            // Other errors
            $EmailAddress->increase_counter('othererror');
            // Update only the email addresses with 'unknown' status
            $EmailAddress->set_status('warning');
            break;
    }
    // Insert/Update an email address
    $EmailAddress->dbsave();
}
예제 #2
0
    /**
     * Delete user and dependencies from database
     *
     * Includes WAY TOO MANY requests because we try to be compatible with MySQL 3.23, bleh!
     *
     * @param Log Log object where output gets added (by reference).
     */
    function dbdelete(&$Log)
    {
        global $DB, $Plugins;
        if ($this->ID == 0) {
            debug_die('Non persistant object cannot be deleted!');
        }
        $deltype = param('deltype', 'string', '');
        // spammer
        $DB->begin();
        if ($deltype == 'spammer') {
            // If we delete user as spammer we should delete private messaged of this user
            $this->init_relations(true);
        } else {
            // If we delete user as not spammer we keep his comments as from anonymous user
            // Transform registered user comments to unregistered:
            $ret = $DB->query('UPDATE T_comments
													SET comment_author_user_ID = NULL,
															comment_author = ' . $DB->quote($this->get('preferredname')) . ',
															comment_author_email = ' . $DB->quote($this->get('email')) . ',
															comment_author_url = ' . $DB->quote($this->get('url')) . '
													WHERE comment_author_user_ID = ' . $this->ID);
            if (is_a($Log, 'log')) {
                $Log->add('Transforming user\'s comments to unregistered comments... ' . sprintf('(%d rows)', $ret), 'note');
            }
        }
        // remember ID, because parent method resets it to 0
        $old_ID = $this->ID;
        $old_email = $this->get('email');
        // Delete main object:
        if (!parent::dbdelete()) {
            $DB->rollback();
            $Log->add('User has not been deleted.', 'error');
            return false;
        }
        if ($deltype == 'spammer') {
            // User was deleted as spammer, we should mark email of this user as 'Spammer'
            $EmailAddressCache =& get_EmailAddressCache();
            $EmailAddress =& $EmailAddressCache->get_by_name($old_email, false, false);
            if (!$EmailAddress) {
                // Create new record in the T_email_address table
                $EmailAddress = new EmailAddress();
                $EmailAddress->set('address', $old_email);
            }
            if (!empty($EmailAddress)) {
                // Save status of an email address
                $EmailAddress->set('status', 'spammer');
                $EmailAddress->dbsave();
            }
        }
        $DB->commit();
        if (is_a($Log, 'log')) {
            $Log->add('Deleted User.', 'note');
        }
        // Notify plugins:
        $this->ID = $old_ID;
        $Plugins->trigger_event('AfterUserDelete', $params = array('User' => &$this));
        $this->ID = 0;
        // BLOCK CACHE INVALIDATION:
        // This User has been modified, cached content depending on it should be invalidated:
        BlockCache::invalidate_key('user_ID', $old_ID);
        return true;
    }
예제 #3
0
     break;
 case 'blocked_save':
     // Update Email Address...
     // Check that this action request is not a CSRF hacked request:
     $Session->assert_received_crumb('email_blocked');
     $action = 'blocked_edit';
     if (!isset($edited_EmailAddress)) {
         // Create a new address
         $edited_EmailAddress = new EmailAddress();
         $action = 'blocked_new';
     }
     // load data from request
     if ($edited_EmailAddress->load_from_Request()) {
         // We could load data from form without errors:
         // Save Email Address in DB:
         $edited_EmailAddress->dbsave();
         $Messages->add(T_('The email address was updated.'), 'success');
         // Redirect so that a reload doesn't write to the DB twice:
         header_redirect('?ctrl=email&tab=blocked', 303);
         // Will EXIT
         // We have EXITed already at this point!!
     }
     break;
 case 'blocked_delete':
     // Delete Email Address...
     // Check that this action request is not a CSRF hacked request:
     $Session->assert_received_crumb('email_blocked');
     // Make sure we got an emadr_ID:
     param('emadr_ID', 'integer', true);
     if ($edited_EmailAddress->dbdelete()) {
         $Messages->add(T_('The email address was deleted.'), 'success');