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')
{
// Use Swift Mailer library
// ------------------------------------------
$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/egulias/email-validator/EmailValidator/Exception/InvalidEmail.php';
require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/egulias/email-validator/EmailValidator/Exception/NoDomainPart.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';
// egulias autoloader lib
require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/autoload.php';
require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/lib/classes/Swift/InputByteStream.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';
require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/lib/classes/Swift/Signers/DKIMSigner.php';
//require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/lib/classes/Swift/SignedMessage.php';
require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/lib/swift_required.php';
// Create the message
//$this->message = Swift_Message::newInstance();
$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();
// Adding a trackid header to a message
$headers = $this->message->getHeaders();
$headers->addTextHeader('X-Dolibarr-TRACKID', $trackid . '@' . $host);
$headerID = time() . '.swiftmailer-dolibarr-' . $trackid . '@' . $host;
$msgid = $headers->get('Message-ID');
$msgid->setId($headerID);
$headers->addIdHeader('References', $headerID);
// TODO if (! empty($moreinheader)) ...
$headers = $this->message->getHeaders();
$headers->addTextHeader('X-Dolibarr-TRACKID', $trackid . '@' . $host);
$headerID = time() . '.swiftmailer-dolibarr-' . $trackid . '@' . $host;
$msgid = $headers->get('Message-ID');
$msgid->setId($headerID);
$headers->addIdHeader('References', $headerID);
// TODO if (! empty($moreinheader)) ...
// Give the message a subject
try {
$result = $this->message->setSubject($subject);
} catch (Exception $e) {
$this->errors[] = $e->getMessage();
}
// Give the message a subject
try {
$result = $this->message->setSubject($subject);
} catch (Exception $e) {
$this->errors[] = $e->getMessage();
}
// Set the From address with an associative array
//$this->message->setFrom(array('john@doe.com' => 'John Doe'));
if (! empty($from)) {
// Set the From address with an associative array
//$this->message->setFrom(array('john@doe.com' => 'John Doe'));
if (! empty($from)) {
try {
$result = $this->message->setFrom($this->getArrayAddress($from));
$result = $this->message->setFrom($this->getArrayAddress($from));
} catch (Exception $e) {
$this->errors[] = $e->getMessage();
}
}
// Set the To addresses with an associative array
if (! empty($to)) {
// Set the To addresses with an associative array
if (! empty($to)) {
try {
$result = $this->message->setTo($this->getArrayAddress($to));
$result = $this->message->setTo($this->getArrayAddress($to));
} catch (Exception $e) {
$this->errors[] = $e->getMessage();
}
}
if (! empty($replyto)) {
if (! empty($replyto)) {
try {
$result = $this->message->SetReplyTo($this->getArrayAddress($replyto));
} catch (Exception $e) {
@ -424,16 +408,14 @@ class CMailFile
}
}
try {
$result = $this->message->setCharSet($conf->file->character_set_client);
} catch (Exception $e) {
$this->errors[] = $e->getMessage();
}
try {
$result = $this->message->setCharSet($conf->file->character_set_client);
} catch (Exception $e) {
$this->errors[] = $e->getMessage();
}
if (! empty($this->html))
{
if (!empty($css))
{
if (! empty($this->html)) {
if (!empty($css)) {
$this->css = $css;
$this->buildCSS();
}

View File

@ -183,11 +183,11 @@ class FormFile
else {
$rename='checked';
}
$out .= '<tr>';
if (! empty($options)) $out .= '<td>'.$options.'</td>';
$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 .= '</tr>';
}
@ -1571,7 +1571,7 @@ class FormFile
{
preg_match('/(.*)\/[^\/]+$/', $relativefile, $reg); $ref=(isset($reg[1])?$reg[1]:'');
}
if (! $id && ! $ref) continue;
$found=0;
if (! empty($this->cache_objects[$modulepart.'_'.$id.'_'.$ref]))

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'));
}
}