예제 #1
0
파일: mail.php 프로젝트: kohler/peteramati
 private function run()
 {
     global $Conf, $Opt, $Me, $Error, $subjectPrefix, $mailer_options;
     $subject = trim(defval($_REQUEST, "subject", ""));
     if (substr($subject, 0, strlen($subjectPrefix)) != $subjectPrefix) {
         $subject = $subjectPrefix . $subject;
     }
     $emailBody = $_REQUEST["emailBody"];
     $template = array("subject" => $subject, "body" => $emailBody);
     $rest = array("cc" => $_REQUEST["cc"], "reply-to" => $_REQUEST["replyto"], "pset" => $this->recip->pset, "no_error_quit" => true);
     $rest = array_merge($rest, $mailer_options);
     $mailer = new CS61Mailer($Me, null, $rest);
     $prep = $mailer->make_preparation($template, $rest);
     $paper_sensitive = preg_match('/%[A-Z0-9]+[(%]/', $prep->subject . $prep->body);
     $q = $this->recip->query($paper_sensitive);
     if (!$q) {
         return $Conf->errorMsg("Bad recipients value");
     }
     $result = $Conf->qe_raw($q);
     if (!$result) {
         return;
     }
     $recipients = defval($_REQUEST, "recipients", "");
     if ($this->sending) {
         $q = "recipients='" . sqlq($recipients) . "', cc='" . sqlq($_REQUEST["cc"]) . "', replyto='" . sqlq($_REQUEST["replyto"]) . "', subject='" . sqlq($_REQUEST["subject"]) . "', emailBody='" . sqlq($_REQUEST["emailBody"]) . "'";
         if ($Conf->sversion >= 79) {
             $q .= ", q='" . sqlq($_REQUEST["q"]) . "', t='" . sqlq($_REQUEST["t"]) . "'";
         }
         if ($log_result = Dbl::query_raw("insert into MailLog set {$q}")) {
             $this->mailid_text = " #" . $log_result->insert_id;
         }
         $Me->log_activity("Sending mail{$this->mailid_text} \"{$subject}\"");
     } else {
         $rest["no_send"] = true;
     }
     $mailer = new CS61Mailer();
     $fake_prep = (object) array("subject" => "", "body" => "", "to" => array(), "contactId" => array(), "fake" => 1);
     $last_prep = $fake_prep;
     $nrows_done = 0;
     $nrows_left = edb_nrows($result);
     $nwarnings = 0;
     $preperrors = array();
     while ($row = edb_orow($result)) {
         ++$nrows_done;
         $contact = new Contact($row);
         $mailer->reset($contact, $row, $rest);
         $prep = $mailer->make_preparation($template, $rest);
         if (@$prep->errors) {
             foreach ($prep->errors as $lcfield => $hline) {
                 $reqfield = $lcfield == "reply-to" ? "replyto" : $lcfield;
                 $Error[$reqfield] = true;
                 $emsg = Mailer::$email_fields[$lcfield] . " destination isn’t a valid email list: <blockquote><tt>" . htmlspecialchars($hline) . "</tt></blockquote> Make sure email address are separated by commas; put names in \"quotes\" and email addresses in &lt;angle brackets&gt;.";
                 if (!isset($preperrors[$emsg])) {
                     $Conf->errorMsg($emsg);
                 }
                 $preperrors[$emsg] = true;
             }
         } else {
             if ($this->process_prep($prep, $last_prep, $row)) {
                 if ((!$Me->privChair || @$Opt["chairHidePasswords"]) && !@$last_prep->sensitive) {
                     $srest = array_merge($rest, array("sensitivity" => "display"));
                     $mailer->reset($contact, $row, $srest);
                     $last_prep->sensitive = $mailer->make_preparation($template, $srest);
                 }
             }
         }
         if ($nwarnings != $mailer->nwarnings() || $nrows_done % 5 == 0) {
             $this->echo_mailinfo($nrows_done, $nrows_left);
         }
         if ($nwarnings != $mailer->nwarnings()) {
             $this->echo_prologue();
             $nwarnings = $mailer->nwarnings();
             echo "<div id='foldmailwarn{$nwarnings}' class='hidden'><div class='warning'>", join("<br />", $mailer->warnings()), "</div></div>";
             echo Ht::unstash_script("\$\$('mailwarnings').innerHTML = \$\$('foldmailwarn{$nwarnings}').innerHTML;");
         }
     }
     $this->process_prep($fake_prep, $last_prep, (object) array());
     $this->echo_mailinfo($nrows_done, $nrows_left);
     if (!$this->started && !count($preperrors)) {
         return $Conf->errorMsg("No users match “" . $this->recip->unparse() . "” for that search.");
     } else {
         if (!$this->started) {
             return false;
         } else {
             if (!$this->sending) {
                 $this->echo_actions();
             }
         }
     }
     echo "</div></form>";
     echo Ht::unstash_script("fold('mail', null);");
     $Conf->footer();
     exit;
 }
예제 #2
0
 function sendAccountInfo($sendtype, $sensitive)
 {
     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() && ($this->conf->opt("safePasswords") <= 1 || $sendtype != "forgot")) {
                 $template = "@accountinfo";
             } else {
                 if ($this->contactDbId && $this->prefer_contactdb_password()) {
                     $capmgr = $this->conf->capability_manager("U");
                 } else {
                     $capmgr = $this->conf->capability_manager();
                 }
                 $rest["capability"] = $capmgr->create(CAPTYPE_RESETPASSWORD, array("user" => $this, "timeExpires" => time() + 259200));
                 $this->conf->log("Created password reset " . substr($rest["capability"], 0, 8) . "...", $this);
                 $template = "@resetpassword";
             }
         }
     }
     $mailer = new CS61Mailer($this, null, $rest);
     $prep = $mailer->make_preparation($template, $rest);
     if ($prep->sendable || !$sensitive || $this->conf->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;
     }
 }
예제 #3
0
 static function send_to($recipient, $template, $rest = array())
 {
     if (!defval($recipient, "disabled")) {
         $mailer = new CS61Mailer($recipient, null, $rest);
         if ($prep = $mailer->make_preparation($template, $rest)) {
             self::send_preparation($prep);
         }
     }
 }