@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator

Use ExecFuture to raise sendmail error codes out of PHPMailer

Summary:
Ref T2843. We currently drop any stdout/stderr emitted by sendmail. Instead, use `ExecFuture` so we'll throw an exception with debugging information preserved.

@tido, can you apply this and restart the daemons?

Test Plan: Rests on @tido

Reviewers: tido, btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T2843

Differential Revision: https://secure.phabricator.com/D5464

+18 -50
+9 -25
externals/phpmailer/class.phpmailer-lite.php
··· 532 532 } else { 533 533 $sendmail = sprintf("%s -oi -t", escapeshellcmd($this->Sendmail)); 534 534 } 535 + 535 536 if ($this->SingleTo === true) { 536 537 foreach ($this->SingleToArray as $key => $val) { 537 - if(!@$mail = popen($sendmail, 'w')) { 538 - throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL); 539 - } 540 - fputs($mail, "To: " . $val . "\n"); 541 - fputs($mail, $header); 542 - fputs($mail, $body); 543 - $result = pclose($mail); 544 - // implement call back function if it exists 545 - $isSent = ($result == 0) ? 1 : 0; 546 - $this->doCallback($isSent,$val,$this->cc,$this->bcc,$this->Subject,$body); 547 - if($result != 0) { 548 - throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL); 549 - } 538 + $mail = new ExecFuture('%C', $sendmail); 539 + $mail->write("To: {$val}\n", true); 540 + $mail->write($header.$body); 541 + $mail->resolvex(); 550 542 } 551 543 } else { 552 - if(!@$mail = popen($sendmail, 'w')) { 553 - throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL); 554 - } 555 - fputs($mail, $header); 556 - fputs($mail, $body); 557 - $result = pclose($mail); 558 - // implement call back function if it exists 559 - $isSent = ($result == 0) ? 1 : 0; 560 - $this->doCallback($isSent,$this->to,$this->cc,$this->bcc,$this->Subject,$body); 561 - if($result != 0) { 562 - throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL); 563 - } 544 + $mail = new ExecFuture('%C', $sendmail); 545 + $mail->write($header.$body); 546 + $mail->resolvex(); 564 547 } 548 + 565 549 return true; 566 550 } 567 551
+9 -25
externals/phpmailer/class.phpmailer.php
··· 601 601 } else { 602 602 $sendmail = sprintf("%s -oi -t", escapeshellcmd($this->Sendmail)); 603 603 } 604 + 604 605 if ($this->SingleTo === true) { 605 606 foreach ($this->SingleToArray as $key => $val) { 606 - if(!@$mail = popen($sendmail, 'w')) { 607 - throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL); 608 - } 609 - fputs($mail, "To: " . $val . "\n"); 610 - fputs($mail, $header); 611 - fputs($mail, $body); 612 - $result = pclose($mail); 613 - // implement call back function if it exists 614 - $isSent = ($result == 0) ? 1 : 0; 615 - $this->doCallback($isSent,$val,$this->cc,$this->bcc,$this->Subject,$body); 616 - if($result != 0) { 617 - throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL); 618 - } 607 + $mail = new ExecFuture('%C', $sendmail); 608 + $mail->write("To: {$val}\n", true); 609 + $mail->write($header.$body); 610 + $mail->resolvex(); 619 611 } 620 612 } else { 621 - if(!@$mail = popen($sendmail, 'w')) { 622 - throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL); 623 - } 624 - fputs($mail, $header); 625 - fputs($mail, $body); 626 - $result = pclose($mail); 627 - // implement call back function if it exists 628 - $isSent = ($result == 0) ? 1 : 0; 629 - $this->doCallback($isSent,$this->to,$this->cc,$this->bcc,$this->Subject,$body); 630 - if($result != 0) { 631 - throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL); 632 - } 613 + $mail = new ExecFuture('%C', $sendmail); 614 + $mail->write($header.$body); 615 + $mail->resolvex(); 633 616 } 617 + 634 618 return true; 635 619 } 636 620