# - Subject: namespace App\Presenters; use App; use Nette; class Cli\MailhandlerPresenter extends App\Presenters\BasePresenter { public function run(Nette\Application\Request $request) { try { $extension = $request->parameters['extension']; if(empty($extension)) throw new \ErrorException("no address extension"); $database = $this->database; $final_address = $database->get_finaldestination_by_verp($extension); if(is_null($final_address)) throw new \ErrorException("no sent mail found for '$extension'"); $chunks = []; for(;;) { $chunk = fread(STDIN, 65536); if($chunk === false) throw new \ErrorException(error_get_last()); if($chunk === '') break; $chunks[] = $chunk; } $mail = implode($chunks); $final_address->last_bounce = $mail; if(false) { $res = ""; $header = ""; $headers = []; $key = ""; $line = fgets(STDIN, 4096); while(!feof(STDIN) && trim($line) != '') { if (preg_match("/^([^:]+): (.*)/", $line, $matches)) { $key = $matches[1]; $value = $matches[2]; #if (array_key_exists($key, $headers)) { # # Multiple headers like "Received:" # $v = $headers[$key]; # $headers[$key] = [$v, $value]; #} else { $headers[$key] = $value; #} } else { # line continued if ($key != '') { $headers[$key] .= " ".ltrim($line); } } $header .= $line; $line = fgets(STDIN, 4096); } # $hdr = imap_rfc822_parse_headers($mailheader); if (preg_match("/mailmindev\+([^@]+)@uvt.nl/", $headers["To"], $matches)) { // FIXME: mailmindev is afhankelijk van instance # It's a bounce $verp = $matches[1]; $database = $this->database; $context = $database->context; $context->beginTransaction(); # x="select emailaddress from finaldestinations where verp=$verp" # "update emailaddresses set laststatus=f where emailaddress=$x" $context->commit(); # Voor nu even loggen naar een filetje... $fp = fopen("/tmp/mailmin-bounces.txt", "a"); fputs($fp, "bounce-received $verp\n"); fclose($fp); } } } catch(\Exception $e) { error_log($e); } return new Nette\Application\Responses\TextResponse(''); } }