}
                     $language_emails[$data['language_id']][] = $data['email'];
                 }
                 unset($users);
                 foreach ($language_emails as $language_id => $emails) {
                     if (true !== $l->setLanguage($language_id) && (empty($session->_conf_all['default_language']) || true !== $l->setLanguage($session->_conf_all['default_language']))) {
                         $l->setLanguage($old_language_id);
                     }
                     foreach ($emails as $email) {
                         $email_body = $l->g('email_new_user_notification');
                         $email_body = str_replace('[CHAT_NAME]', $session->_conf_all['chat_name'], $email_body);
                         $email_body = str_replace('[EMAIL_ADDRESS]', $user->email, $email_body);
                         $email_body = str_replace('[USERNAME]', $user->login, $email_body);
                         $email_body = str_replace('[REMOTE_IP]', PCPIN_CLIENT_IP, $email_body);
                         $email_body = str_replace('[SENDER]', $session->_conf_all['chat_email_sender_name'], $email_body);
                         PCPIN_Email::send('"' . $session->_conf_all['chat_email_sender_name'] . '"' . ' <' . $session->_conf_all['chat_email_sender_address'] . '>', $email, $session->_conf_all['chat_name'] . ': ' . $l->g('new_account_created'), null, null, $email_body);
                     }
                 }
                 // Restore original language
                 if ($l->id != $old_language_id) {
                     $l->setLanguage($old_language_id);
                 }
             }
         }
     } else {
         // Activation failed (should not happen)
         $message = $l->g('invalid_activation_code');
     }
 } else {
     // Invalid activation code
     $message = $l->g('invalid_activation_code');
 /**
  * Convert email address into RFC-Compatible format
  * @param   string    $email    Email address
  * @param   boolean   $rfc821   Optional. Use strict RFC821 envelope format. Default is FALSE.
  * @return  string
  */
 function convertEmailAddressRFC($email = '', $rfc821 = false)
 {
     $out = trim($email);
     if ($out != '') {
         if (false !== strpos($out, ' ')) {
             $tmp = explode(' ', $out);
             $address = array_pop($tmp);
             $name = implode(' ', $tmp);
         } else {
             $name = '';
             $address = $out;
         }
         if (substr($name, 0, 1) == '"' && substr($name, strlen($name) - 1, 1) == '"') {
             $name = substr($name, 1, strlen($name) - 2);
         }
         if (false !== strpos($name, '<')) {
             $name = '"' . str_replace('"', '\\"', $name) . '"';
         }
         $address = '<' . trim(ltrim(rtrim(trim($address), '>'), '<')) . '>';
         if ($rfc821 || $name == '' || $name == '""') {
             // Strict mode
             $out = $address;
         } else {
             // "Violative" mode, not RFC821-comform, but accepted by mosts servers :/
             $out = PCPIN_Email::encodeHeaderValue($name) . ' ' . $address;
         }
     }
     return $out;
 }
                    break;
                case 2:
                    $violation_category = $l->g('insult');
                    break;
                case 3:
                    $violation_category = $l->g('adult_content');
                    break;
                case 4:
                    $violation_category = $l->g('illegal_content');
                    break;
                case 5:
                    $violation_category = $l->g('harassment');
                    break;
                case 6:
                    $violation_category = $l->g('fraud');
                    break;
                case 7:
                default:
                    $violation_category = $l->g('other');
                    break;
            }
            // Send an email
            $email_body = $l->g('date') . ":\n\t" . $tmp_user->makeDate(time()) . "\n" . $l->g('room_name') . ":\n\t" . $current_room_name . "\n" . $l->g('author') . ":\n\t" . $nickname->coloredToPlain($current_nickname, false) . "\n" . $l->g('violation_category') . ":\n\t" . $violation_category . "\n" . $l->g('abuser_nickname') . ":\n\t" . $abuse_nickname . "\n" . $l->g('violation_description') . ":\n\n" . $abuse_description . "\n";
            PCPIN_Email::send('"' . $session->_conf_all['chat_email_sender_name'] . '"' . ' <' . $session->_conf_all['chat_email_sender_address'] . '>', $tmp_user->email, $session->_conf_all['chat_name'] . ': ' . $l->g('abuse_arrived'), null, null, $email_body);
        }
        if ($old_language_id != $l->id) {
            // Restore original language
            $l->setLanguage($old_language_id);
        }
    }
}
 } else {
     // Email address is free
     if ($current_user->is_admin !== 'y' && !empty($session->_conf_all['activate_new_emails'])) {
         // Email address needs to be activated
         $activation_required = 1;
         $email_new_activation_code = PCPIN_Common::randomString(18, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789');
         $profile_user->email_new = $email;
         $profile_user->email_new_date = date('Y-m-d H:i:s');
         $profile_user->email_new_activation_code = md5($email_new_activation_code);
         $profile_user->_db_updateObj($profile_user->id);
         $email_body = $l->g('email_email_address_activation');
         $email_body = str_replace('[HOURS]', $session->_conf_all['new_email_activation_timeout'], $email_body);
         $email_body = str_replace('[SENDER]', $session->_conf_all['chat_email_sender_name'], $email_body);
         $email_body = str_replace('[ACTIVATION_URL]', str_replace(' ', '%20', $session->_conf_all['base_url']) . '?activate_email&activation_code=' . urlencode($email_new_activation_code), $email_body);
         $email_body = str_replace('[CHAT_NAME]', $session->_conf_all['chat_name'], $email_body);
         PCPIN_Email::send('"' . $session->_conf_all['chat_email_sender_name'] . '"' . ' <' . $session->_conf_all['chat_email_sender_address'] . '>', $email, $l->g('email_address_activation'), null, null, $email_body);
         $xmlwriter->setHeaderStatus(0);
         $xmlwriter->setHeaderMessage(str_replace('[EMAIL]', $email, $l->g('email_address_activation_sent')));
     } else {
         // Save new email address
         $activation_required = 0;
         $profile_user->email = $email;
         $profile_user->email_new = '';
         $profile_user->email_new_date = '';
         $profile_user->email_new_activation_code = '';
         $profile_user->_db_updateObj($profile_user->id);
         $xmlwriter->setHeaderStatus(0);
         $xmlwriter->setHeaderMessage($l->g('email_address_changed'));
         $msg->addMessage(1010, 'n', 0, '', $session->_s_room_id, 0, $profile_user_id);
     }
 }
}
if (empty($errortext)) {
    // Check data
    if ($current_user->_db_getList('id,login', 'email = ' . $email, 'activated = y', 'is_guest = n', 1)) {
        // Email address found
        $user_id = $current_user->_db_list[0]['id'];
        $login = $current_user->_db_list[0]['login'];
        $current_user->_db_freeList();
    } else {
        // Wrong Email
        $errortext[] = $l->g('email_not_found');
    }
}
if (!empty($errortext)) {
    $xmlwriter->setHeaderStatus(1);
    $xmlwriter->setHeaderMessage('- ' . implode("\n- ", $errortext));
} else {
    // Reset password
    $password_new = PCPIN_Common::randomString(mt_rand(6, 8), 'abcdefghijklmnopqrstuvwxyz0123456789');
    $current_user->_db_updateRow($user_id, 'id', array('password_new' => md5($password_new)));
    // Send "password reset" email
    $email_body = $l->g('email_password_reset');
    $email_body = str_replace('[CHAT_NAME]', $session->_conf_all['chat_name'], $email_body);
    $email_body = str_replace('[USERNAME]', $login, $email_body);
    $email_body = str_replace('[PASSWORD]', $password_new, $email_body);
    $email_body = str_replace('[URL]', str_replace(' ', '%20', $session->_conf_all['base_url']), $email_body);
    $email_body = str_replace('[SENDER]', $session->_conf_all['chat_email_sender_name'], $email_body);
    PCPIN_Email::send('"' . $session->_conf_all['chat_email_sender_name'] . '"' . ' <' . $session->_conf_all['chat_email_sender_address'] . '>', $email, $l->g('password_reset'), null, null, $email_body);
    $xmlwriter->setHeaderStatus(0);
    $xmlwriter->setHeaderMessage(str_replace('[EMAIL]', $email, $l->g('new_password_sent')));
}