LogoKolab Groupware OBS > Projects
Log In

View File 0006-Unbundle-phpmailer.patch of Package phabricator (Project Infrastructure)

From 5c8d1b63da376b2f3e61cae531f5d8f4a637e154 Mon Sep 17 00:00:00 2001
From: "Jeroen van Meeuwen (Kolab Systems)" <vanmeeuwen@kolabsys.com>
Date: Wed, 10 Aug 2016 11:11:06 +0200
Subject: [PATCH 06/15] Unbundle phpmailer

---
 src/__phutil_library_map__.php                     |   1 -
 .../config/check/PhabricatorMailSetupCheck.php     |  20 ----
 .../option/PhabricatorMetaMTAConfigOptions.php     |   2 +-
 ...abricatorMailImplementationPHPMailerAdapter.php |   4 +-
 ...catorMailImplementationPHPMailerLiteAdapter.php | 107 ---------------------
 5 files changed, 2 insertions(+), 132 deletions(-)
 delete mode 100644 src/applications/metamta/adapter/PhabricatorMailImplementationPHPMailerLiteAdapter.php

diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
index 0d65c8f..d9b6844 100644
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -2863,7 +2863,6 @@ phutil_register_library_map(array(
     'PhabricatorMailImplementationAdapter' => 'applications/metamta/adapter/PhabricatorMailImplementationAdapter.php',
     'PhabricatorMailImplementationMailgunAdapter' => 'applications/metamta/adapter/PhabricatorMailImplementationMailgunAdapter.php',
     'PhabricatorMailImplementationPHPMailerAdapter' => 'applications/metamta/adapter/PhabricatorMailImplementationPHPMailerAdapter.php',
-    'PhabricatorMailImplementationPHPMailerLiteAdapter' => 'applications/metamta/adapter/PhabricatorMailImplementationPHPMailerLiteAdapter.php',
     'PhabricatorMailImplementationSendGridAdapter' => 'applications/metamta/adapter/PhabricatorMailImplementationSendGridAdapter.php',
     'PhabricatorMailImplementationTestAdapter' => 'applications/metamta/adapter/PhabricatorMailImplementationTestAdapter.php',
     'PhabricatorMailManagementListInboundWorkflow' => 'applications/metamta/management/PhabricatorMailManagementListInboundWorkflow.php',
diff --git a/src/applications/config/check/PhabricatorMailSetupCheck.php b/src/applications/config/check/PhabricatorMailSetupCheck.php
index 3202f8f..da0ca08 100644
--- a/src/applications/config/check/PhabricatorMailSetupCheck.php
+++ b/src/applications/config/check/PhabricatorMailSetupCheck.php
@@ -7,25 +7,5 @@ final class PhabricatorMailSetupCheck extends PhabricatorSetupCheck {
   }
 
   protected function executeChecks() {
-    $adapter = PhabricatorEnv::getEnvConfig('metamta.mail-adapter');
-
-    switch ($adapter) {
-      case 'PhabricatorMailImplementationPHPMailerLiteAdapter':
-        if (!Filesystem::pathExists('/usr/bin/sendmail') &&
-            !Filesystem::pathExists('/usr/sbin/sendmail')) {
-          $message = pht(
-            'Mail is configured to send via sendmail, but this system has '.
-            'no sendmail binary. Install sendmail or choose a different '.
-            'mail adapter.');
-
-          $this->newIssue('config.metamta.mail-adapter')
-            ->setShortName(pht('Missing Sendmail'))
-            ->setName(pht('No Sendmail Binary Found'))
-            ->setMessage($message)
-            ->addRelatedPhabricatorConfig('metamta.mail-adapter');
-        }
-        break;
-    }
-
   }
 }
diff --git a/src/applications/config/option/PhabricatorMetaMTAConfigOptions.php b/src/applications/config/option/PhabricatorMetaMTAConfigOptions.php
index 45604f6..bf36148 100644
--- a/src/applications/config/option/PhabricatorMetaMTAConfigOptions.php
+++ b/src/applications/config/option/PhabricatorMetaMTAConfigOptions.php
@@ -215,7 +215,7 @@ EODOC
       $this->newOption(
         'metamta.mail-adapter',
         'class',
-        'PhabricatorMailImplementationPHPMailerLiteAdapter')
+        'PhabricatorMailImplementationPHPMailerAdapter')
         ->setBaseClass('PhabricatorMailImplementationAdapter')
         ->setSummary(pht('Control how mail is sent.'))
         ->setDescription($adapter_description),
diff --git a/src/applications/metamta/adapter/PhabricatorMailImplementationPHPMailerAdapter.php b/src/applications/metamta/adapter/PhabricatorMailImplementationPHPMailerAdapter.php
index 8f7e809..13a6209 100644
--- a/src/applications/metamta/adapter/PhabricatorMailImplementationPHPMailerAdapter.php
+++ b/src/applications/metamta/adapter/PhabricatorMailImplementationPHPMailerAdapter.php
@@ -9,9 +9,7 @@ final class PhabricatorMailImplementationPHPMailerAdapter
    * @phutil-external-symbol class PHPMailer
    */
   public function __construct() {
-    $root = phutil_get_library_root('phabricator');
-    $root = dirname($root);
-    require_once $root.'/externals/phpmailer/class.phpmailer.php';
+    require_once '/usr/share/php/PHPMailer/PHPMailerAutoload.php';
     $this->mailer = new PHPMailer($use_exceptions = true);
     $this->mailer->CharSet = 'utf-8';
 
diff --git a/src/applications/metamta/adapter/PhabricatorMailImplementationPHPMailerLiteAdapter.php b/src/applications/metamta/adapter/PhabricatorMailImplementationPHPMailerLiteAdapter.php
deleted file mode 100644
index 2a8b12b..0000000
--- a/src/applications/metamta/adapter/PhabricatorMailImplementationPHPMailerLiteAdapter.php
+++ /dev/null
@@ -1,107 +0,0 @@
-<?php
-
-/**
- * TODO: Should be final, but inherited by SES.
- */
-class PhabricatorMailImplementationPHPMailerLiteAdapter
-  extends PhabricatorMailImplementationAdapter {
-
-  protected $mailer;
-
-  /**
-   * @phutil-external-symbol class PHPMailerLite
-   */
-  public function __construct() {
-    $root = phutil_get_library_root('phabricator');
-    $root = dirname($root);
-    require_once $root.'/externals/phpmailer/class.phpmailer-lite.php';
-    $this->mailer = new PHPMailerLite($use_exceptions = true);
-    $this->mailer->CharSet = 'utf-8';
-
-    $encoding = PhabricatorEnv::getEnvConfig('phpmailer.smtp-encoding', '8bit');
-    $this->mailer->Encoding = $encoding;
-
-    // By default, PHPMailerLite sends one mail per recipient. We handle
-    // multiplexing higher in the stack, so tell it to send mail exactly
-    // like we ask.
-    $this->mailer->SingleTo = false;
-  }
-
-  public function supportsMessageIDHeader() {
-    return true;
-  }
-
-  public function setFrom($email, $name = '') {
-    $this->mailer->SetFrom($email, $name, $crazy_side_effects = false);
-    return $this;
-  }
-
-  public function addReplyTo($email, $name = '') {
-    $this->mailer->AddReplyTo($email, $name);
-    return $this;
-  }
-
-  public function addTos(array $emails) {
-    foreach ($emails as $email) {
-      $this->mailer->AddAddress($email);
-    }
-    return $this;
-  }
-
-  public function addCCs(array $emails) {
-    foreach ($emails as $email) {
-      $this->mailer->AddCC($email);
-    }
-    return $this;
-  }
-
-  public function addAttachment($data, $filename, $mimetype) {
-    $this->mailer->AddStringAttachment(
-      $data,
-      $filename,
-      'base64',
-      $mimetype);
-    return $this;
-  }
-
-  public function addHeader($header_name, $header_value) {
-    if (strtolower($header_name) == 'message-id') {
-      $this->mailer->MessageID = $header_value;
-    } else {
-      $this->mailer->AddCustomHeader($header_name.': '.$header_value);
-    }
-    return $this;
-  }
-
-  public function setBody($body) {
-    $this->mailer->Body = $body;
-    $this->mailer->IsHTML(false);
-    return $this;
-  }
-
-
-  /**
-   * Note: phpmailer-lite does NOT support sending messages with mixed version
-   * (plaintext and html). So for now lets just use HTML if it's available.
-   * @param $html
-   */
-  public function setHTMLBody($html_body) {
-    $this->mailer->Body = $html_body;
-    $this->mailer->IsHTML(true);
-    return $this;
-  }
-
-  public function setSubject($subject) {
-    $this->mailer->Subject = $subject;
-    return $this;
-  }
-
-  public function hasValidRecipients() {
-    return true;
-  }
-
-  public function send() {
-    return $this->mailer->Send();
-  }
-
-}
-- 
2.9.3