Пример #1
0
     continue;
 }
 $url = str_replace('${EMAIL}', urlencode($row[1]), $url);
 $url = str_replace('${ID}', urlencode($row[2]), $url);
 // fwrite(STDOUT, "$row[1] $fetchscript " . escapeshellarg($url) . " ");
 fwrite(STDOUT, "{$row['1']} ");
 $handle = popen($fetchscript . " " . escapeshellarg($url), "r");
 $data = stream_get_contents($handle);
 $status = pclose($handle);
 $content_type = "";
 if ($data && ($nl = strpos($data, "\n")) !== false) {
     $content_type = substr($data, 0, $nl);
     $data = substr($data, $nl + 1);
 }
 $worked = false;
 if (pcntl_wifexitedsuccess($status) && preg_match(',\\Aimage/,', $content_type)) {
     $sresult = Dbl::fetch_first_object(Dbl::qe("select ContactImage.* from ContactImage join ContactInfo using (contactImageId) where ContactInfo.contactId=?", $row[0]));
     if ($sresult && $sresult->mimetype === $content_type && $sresult->data === $data) {
         $worked = "unchanged";
     } else {
         $iresult = Dbl::qe("insert into ContactImage set contactId=?, mimetype=?, data=?", $row[0], $content_type, $data);
         if ($iresult) {
             Dbl::qe("update ContactInfo set contactImageId=? where contactId=?", $iresult->insert_id, $row[0]);
             $worked = true;
         }
     }
 }
 if ($worked === "unchanged") {
     fwrite(STDERR, strlen($data) . "B " . $content_type . " (unchanged)\n");
 } else {
     if ($worked) {
Пример #2
0
 static function send_preparation($prep)
 {
     global $Conf;
     if ($Conf->opt("internalMailer", null) === null) {
         $Conf->set_opt("internalMailer", strncasecmp(PHP_OS, "WIN", 3) != 0);
     }
     $headers = $prep->headers;
     $eol = self::eol();
     // create valid To: header
     $to = $prep->to;
     if (is_array($to)) {
         $to = join(", ", $to);
     }
     $to = MimeText::encode_email_header("To: ", $to);
     $headers["to"] = $to . $eol;
     // set sendmail parameters
     $extra = $Conf->opt("sendmailParam");
     if (($sender = $Conf->opt("emailSender", null)) !== null) {
         @ini_set("sendmail_from", $sender);
         if ($extra === null) {
             $extra = "-f" . escapeshellarg($sender);
         }
     }
     if ($prep->sendable && $Conf->opt("internalMailer") && ($sendmail = ini_get("sendmail_path"))) {
         $htext = join("", $headers);
         $f = popen($extra ? "{$sendmail} {$extra}" : $sendmail, "wb");
         fwrite($f, $htext . $eol . $prep->body);
         $status = pclose($f);
         if (pcntl_wifexitedsuccess($status)) {
             return true;
         } else {
             $Conf->set_opt("internalMailer", false);
             error_log("Mail " . $headers["to"] . " failed to send, falling back (status {$status})");
         }
     }
     if ($prep->sendable) {
         if (strpos($to, $eol) === false) {
             unset($headers["to"]);
             $to = substr($to, 4);
             // skip "To: "
         } else {
             $to = "";
         }
         unset($headers["subject"]);
         $htext = substr(join("", $headers), 0, -2);
         return mail($to, $prep->subject, $prep->body, $htext, $extra);
     } else {
         if (!$Conf->opt("sendEmail") && !preg_match('/\\Aanonymous\\d*\\z/', $to)) {
             unset($headers["mime-version"], $headers["content-type"]);
             $text = join("", $headers) . $eol . $prep->body;
             if (PHP_SAPI != "cli") {
                 $Conf->infoMsg("<pre>" . htmlspecialchars($text) . "</pre>");
             } else {
                 if (!$Conf->opt("disablePrintEmail")) {
                     fwrite(STDERR, "========================================\n" . str_replace("\r\n", "\n", $text) . "========================================\n");
                 }
             }
             return null;
         }
     }
 }