function sendAccountInfo($sendtype, $sensitive)
 {
     global $Conf, $Opt;
     assert(!$this->disabled);
     $rest = array();
     if ($sendtype == "create" && $this->prefer_contactdb_password()) {
         $template = "@activateaccount";
     } else {
         if ($sendtype == "create") {
             $template = "@createaccount";
         } else {
             if ($this->plaintext_password() && ($Opt["safePasswords"] <= 1 || $sendtype != "forgot")) {
                 $template = "@accountinfo";
             } else {
                 if ($this->contactDbId && $this->prefer_contactdb_password()) {
                     $capmgr = $Conf->capability_manager("U");
                 } else {
                     $capmgr = $Conf->capability_manager();
                 }
                 $rest["capability"] = $capmgr->create(CAPTYPE_RESETPASSWORD, array("user" => $this, "timeExpires" => time() + 259200));
                 $Conf->log("Created password reset " . substr($rest["capability"], 0, 8) . "...", $this);
                 $template = "@resetpassword";
             }
         }
     }
     $mailer = new HotCRPMailer($this, null, $rest);
     $prep = $mailer->make_preparation($template, $rest);
     if ($prep->sendable || !$sensitive || get($Opt, "debugShowSensitiveEmail")) {
         Mailer::send_preparation($prep);
         return $template;
     } else {
         Conf::msg_error("Mail cannot be sent to " . htmlspecialchars($this->email) . " at this time.");
         return false;
     }
 }
 private function send_prep($prep)
 {
     global $Conf;
     $cbkey = "c" . join("_", $prep->contacts) . "p" . $prep->paperId;
     if ($this->sending && !defval($_REQUEST, $cbkey)) {
         return;
     }
     set_time_limit(30);
     $this->echo_prologue();
     self::fix_body($prep);
     ++$this->mcount;
     if ($this->sending) {
         Mailer::send_preparation($prep);
         foreach ($prep->contacts as $cid) {
             $Conf->log("Account was sent mail" . $this->mailid_text, $cid, $prep->paperId);
         }
     }
     // hide passwords from non-chair users
     $show_prep = $prep;
     if (get($prep, "sensitive")) {
         $show_prep = $prep->sensitive;
         $show_prep->to = $prep->to;
         self::fix_body($show_prep);
     }
     echo '<div class="mail"><table>';
     $nprintrows = 0;
     foreach (array("To", "cc", "bcc", "reply-to", "Subject") as $k) {
         if ($k == "To") {
             $vh = array();
             foreach ($show_prep->to as $to) {
                 $vh[] = htmlspecialchars(MimeText::decode_header($to));
             }
             $vh = '<div style="max-width:60em"><span class="nw">' . join(',</span> <span class="nw">', $vh) . '</span></div>';
         } else {
             if ($k == "Subject") {
                 $vh = htmlspecialchars(MimeText::decode_header($show_prep->subject));
             } else {
                 if ($line = get($show_prep->headers, $k)) {
                     $k = substr($line, 0, strlen($k));
                     $vh = htmlspecialchars(MimeText::decode_header(substr($line, strlen($k) + 2)));
                 } else {
                     continue;
                 }
             }
         }
         echo " <tr>";
         if (++$nprintrows > 1) {
             echo "<td class='mhpad'></td>";
         } else {
             if ($this->sending) {
                 echo "<td class='mhx'></td>";
             } else {
                 ++$this->cbcount;
                 echo '<td class="mhcb"><input type="checkbox" class="cb" name="', $cbkey, '" value="1" checked="checked" data-range-type="mhcb" id="psel', $this->cbcount, '" onclick="rangeclick(event,this)" /></td>';
             }
         }
         echo '<td class="mhnp nw">', $k, ":</td>", '<td class="mhdp">', $vh, "</td></tr>\n";
     }
     echo " <tr><td></td><td></td><td class='mhb'><pre class='email'>", Ht::link_urls(htmlspecialchars($show_prep->body)), "</pre></td></tr>\n", "<tr><td class='mhpad'></td><td></td><td class='mhpad'></td></tr>", "</table></div>\n";
 }
function save_user($cj, $user_status, $Acct, $allow_modification)
{
    global $Conf, $Me, $Opt, $OK, $newProfile;
    if ($newProfile) {
        $Acct = null;
    }
    // check for missing fields
    UserStatus::normalize_name($cj);
    if ($newProfile && !isset($cj->email)) {
        $user_status->set_error("email", "Email address required.");
        return false;
    }
    // check email
    if ($newProfile || $cj->email != $Acct->email) {
        if ($new_acct = Contact::find_by_email($cj->email)) {
            if ($allow_modification) {
                $cj->id = $new_acct->contactId;
            } else {
                $msg = "Email address “" . htmlspecialchars($cj->email) . "” is already in use.";
                if ($Me->privChair) {
                    $msg = str_replace("an account", "<a href=\"" . hoturl("profile", "u=" . urlencode($cj->email)) . "\">an account</a>", $msg);
                }
                if (!$newProfile) {
                    $msg .= " You may want to <a href=\"" . hoturl("mergeaccounts") . "\">merge these accounts</a>.";
                }
                return $user_status->set_error("email", $msg);
            }
        } else {
            if (Contact::external_login()) {
                if ($cj->email === "") {
                    return $user_status->set_error("email", "Not a valid username.");
                }
            } else {
                if ($cj->email === "") {
                    return $user_status->set_error("email", "You must supply an email address.");
                } else {
                    if (!validate_email($cj->email)) {
                        return $user_status->set_error("email", "“" . htmlspecialchars($cj->email) . "” is not a valid email address.");
                    }
                }
            }
        }
        if (!$newProfile && !$Me->privChair) {
            $old_preferredEmail = $Acct->preferredEmail;
            $Acct->preferredEmail = $cj->email;
            $capmgr = $Conf->capability_manager();
            $rest = array("capability" => $capmgr->create(CAPTYPE_CHANGEEMAIL, array("user" => $Acct, "timeExpires" => time() + 259200, "data" => json_encode(array("uemail" => $cj->email)))));
            $mailer = new HotCRPMailer($Acct, null, $rest);
            $prep = $mailer->make_preparation("@changeemail", $rest);
            if ($prep->sendable) {
                Mailer::send_preparation($prep);
                $Conf->warnMsg("Mail has been sent to " . htmlspecialchars($cj->email) . ". Use the link it contains to confirm your email change request.");
            } else {
                Conf::msg_error("Mail cannot be sent to " . htmlspecialchars($cj->email) . " at this time. Your email address was unchanged.");
            }
            // Save changes *except* for new email, by restoring old email.
            $cj->email = $Acct->email;
            $Acct->preferredEmail = $old_preferredEmail;
        }
    }
    // save account
    return $user_status->save($cj, $Acct, $Me);
}