Merge pull request #10723 from frederic34/swiftmailer-autoloader

autoloader for egulias lib needed by swiftmailer
This commit is contained in:
Laurent Destailleur 2019-03-02 18:21:31 +01:00 committed by GitHub
commit 4288a09101
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 133 additions and 56 deletions

View File

@ -352,71 +352,55 @@ class CMailFile
elseif ($this->sendmode == 'swiftmailer') elseif ($this->sendmode == 'swiftmailer')
{ {
// Use Swift Mailer library // Use Swift Mailer library
// ------------------------------------------
$host = dol_getprefix('email'); $host = dol_getprefix('email');
require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/lexer/lib/Doctrine/Common/Lexer/AbstractLexer.php'; require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/lexer/lib/Doctrine/Common/Lexer/AbstractLexer.php';
require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/egulias/email-validator/EmailValidator/Exception/InvalidEmail.php'; // egulias autoloader lib
require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/egulias/email-validator/EmailValidator/Exception/NoDomainPart.php'; require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/autoload.php';
require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/egulias/email-validator/EmailValidator/EmailParser.php';
require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/egulias/email-validator/EmailValidator/EmailLexer.php';
require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/egulias/email-validator/EmailValidator/EmailValidator.php';
require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/egulias/email-validator/EmailValidator/Warning/Warning.php';
require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/egulias/email-validator/EmailValidator/Warning/LocalTooLong.php';
require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/egulias/email-validator/EmailValidator/Parser/Parser.php';
require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/egulias/email-validator/EmailValidator/Parser/DomainPart.php';
require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/egulias/email-validator/EmailValidator/Parser/LocalPart.php';
require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/egulias/email-validator/EmailValidator/Validation/EmailValidation.php';
require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/egulias/email-validator/EmailValidator/Validation/RFCValidation.php';
require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/lib/classes/Swift/InputByteStream.php'; require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/lib/swift_required.php';
require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/lib/classes/Swift/Signer.php';
require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/lib/classes/Swift/Signers/HeaderSigner.php'; // Create the message
require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/lib/classes/Swift/Signers/DKIMSigner.php'; //$this->message = Swift_Message::newInstance();
//require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/lib/classes/Swift/SignedMessage.php'; $this->message = new Swift_Message();
require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/lib/swift_required.php';
// Create the message
//$this->message = Swift_Message::newInstance();
$this->message = new Swift_Message();
//$this->message = new Swift_SignedMessage(); //$this->message = new Swift_SignedMessage();
// Adding a trackid header to a message // Adding a trackid header to a message
$headers = $this->message->getHeaders(); $headers = $this->message->getHeaders();
$headers->addTextHeader('X-Dolibarr-TRACKID', $trackid . '@' . $host); $headers->addTextHeader('X-Dolibarr-TRACKID', $trackid . '@' . $host);
$headerID = time() . '.swiftmailer-dolibarr-' . $trackid . '@' . $host; $headerID = time() . '.swiftmailer-dolibarr-' . $trackid . '@' . $host;
$msgid = $headers->get('Message-ID'); $msgid = $headers->get('Message-ID');
$msgid->setId($headerID); $msgid->setId($headerID);
$headers->addIdHeader('References', $headerID); $headers->addIdHeader('References', $headerID);
// TODO if (! empty($moreinheader)) ... // TODO if (! empty($moreinheader)) ...
// Give the message a subject // Give the message a subject
try { try {
$result = $this->message->setSubject($subject); $result = $this->message->setSubject($subject);
} catch (Exception $e) { } catch (Exception $e) {
$this->errors[] = $e->getMessage(); $this->errors[] = $e->getMessage();
} }
// Set the From address with an associative array // Set the From address with an associative array
//$this->message->setFrom(array('john@doe.com' => 'John Doe')); //$this->message->setFrom(array('john@doe.com' => 'John Doe'));
if (! empty($from)) { if (! empty($from)) {
try { try {
$result = $this->message->setFrom($this->getArrayAddress($from)); $result = $this->message->setFrom($this->getArrayAddress($from));
} catch (Exception $e) { } catch (Exception $e) {
$this->errors[] = $e->getMessage(); $this->errors[] = $e->getMessage();
} }
} }
// Set the To addresses with an associative array // Set the To addresses with an associative array
if (! empty($to)) { if (! empty($to)) {
try { try {
$result = $this->message->setTo($this->getArrayAddress($to)); $result = $this->message->setTo($this->getArrayAddress($to));
} catch (Exception $e) { } catch (Exception $e) {
$this->errors[] = $e->getMessage(); $this->errors[] = $e->getMessage();
} }
} }
if (! empty($replyto)) { if (! empty($replyto)) {
try { try {
$result = $this->message->SetReplyTo($this->getArrayAddress($replyto)); $result = $this->message->SetReplyTo($this->getArrayAddress($replyto));
} catch (Exception $e) { } catch (Exception $e) {
@ -424,16 +408,14 @@ class CMailFile
} }
} }
try { try {
$result = $this->message->setCharSet($conf->file->character_set_client); $result = $this->message->setCharSet($conf->file->character_set_client);
} catch (Exception $e) { } catch (Exception $e) {
$this->errors[] = $e->getMessage(); $this->errors[] = $e->getMessage();
} }
if (! empty($this->html)) if (! empty($this->html)) {
{ if (!empty($css)) {
if (!empty($css))
{
$this->css = $css; $this->css = $css;
$this->buildCSS(); $this->buildCSS();
} }

View File

@ -187,7 +187,7 @@ class FormFile
$out .= '<tr>'; $out .= '<tr>';
if (! empty($options)) $out .= '<td>'.$options.'</td>'; if (! empty($options)) $out .= '<td>'.$options.'</td>';
$out .= '<td valign="middle" class="nowrap">'; $out .= '<td valign="middle" class="nowrap">';
$out .= '<input type="checkbox" '.$rename.' class="savingdocmask" name="savingdocmask" value="'.dol_escape_js($savingdocmask).'"> '.$langs->trans("SaveUploadedFileWithMask", preg_replace('/__file__/',$langs->transnoentitiesnoconv("OriginFileName"),$savingdocmask), $langs->transnoentitiesnoconv("OriginFileName")); $out .= '<input type="checkbox" '.$rename.' class="savingdocmask" name="savingdocmask" value="'.dol_escape_js($savingdocmask).'"> '.$langs->trans("SaveUploadedFileWithMask", preg_replace('/__file__/', $langs->transnoentitiesnoconv("OriginFileName"), $savingdocmask), $langs->transnoentitiesnoconv("OriginFileName"));
$out .= '</td>'; $out .= '</td>';
$out .= '</tr>'; $out .= '</tr>';
} }

View File

@ -0,0 +1,13 @@
<?php
/*
* Bootstrap the library.
*/
namespace Egulias;
require_once __DIR__ . '/egulias/email-validator/AutoLoader.php';
$autoloader = new EguliasAutoLoader(__NAMESPACE__, dirname(__DIR__));
$autoloader->register();

View File

@ -0,0 +1,82 @@
<?php
namespace Egulias;
/**
* PSR-0 Autoloader
*
* @author ieter Hordijk <info@pieterhordijk.com>
*/
class EguliasAutoLoader
{
/**
* @var string The namespace prefix for this instance.
*/
protected $namespace = '';
/**
* @var string The filesystem prefix to use for this instance
*/
protected $path = '';
/**
* Build the instance of the autoloader
*
* @param string $namespace The prefixed namespace this instance will load
* @param string $path The filesystem path to the root of the namespace
*/
public function __construct($namespace, $path)
{
$this->namespace = ltrim($namespace, '\\');
$this->path = rtrim($path, '/\\') . DIRECTORY_SEPARATOR;
}
/**
* Try to load a class
*
* @param string $class The class name to load
*
* @return boolean If the loading was successful
*/
public function load($class)
{
$class = ltrim($class, '\\');
if (strpos($class, $this->namespace) === 0) {
$nsparts = explode('\\', $class);
$class = array_pop($nsparts);
$path = $this->path . 'swiftmailer/egulias/email-validator/EmailValidator/';
$max=count($nsparts);
for ($i=2; $i<$max;$i++) {
$path .= $nsparts[$i].'/';
}
$nsparts = array();
$path .= str_replace('_', DIRECTORY_SEPARATOR, $class) . '.php';
if (file_exists($path)) {
require $path;
return true;
}
}
return false;
}
/**
* Register the autoloader to PHP
*
* @return boolean The status of the registration
*/
public function register()
{
return spl_autoload_register(array($this, 'load'));
}
/**
* Unregister the autoloader to PHP
*
* @return boolean The status of the unregistration
*/
public function unregister()
{
return spl_autoload_unregister(array($this, 'load'));
}
}