看板初始化提交
This commit is contained in:
@@ -0,0 +1,138 @@
|
||||
<?php
|
||||
|
||||
namespace Kanboard\Core\Mail;
|
||||
|
||||
use Kanboard\Job\EmailJob;
|
||||
use Pimple\Container;
|
||||
use Kanboard\Core\Base;
|
||||
|
||||
/**
|
||||
* Mail Client
|
||||
*
|
||||
* @package Kanboard\Core\Mail
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class Client extends Base
|
||||
{
|
||||
/**
|
||||
* Mail transport instances
|
||||
*
|
||||
* @access private
|
||||
* @var \Pimple\Container
|
||||
*/
|
||||
private $transports;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @access public
|
||||
* @param \Pimple\Container $container
|
||||
*/
|
||||
public function __construct(Container $container)
|
||||
{
|
||||
parent::__construct($container);
|
||||
$this->transports = new Container;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a HTML email
|
||||
*
|
||||
* @access public
|
||||
* @param string $recipientEmail
|
||||
* @param string $recipientName
|
||||
* @param string $subject
|
||||
* @param string $html
|
||||
* @return Client
|
||||
*/
|
||||
public function send($recipientEmail, $recipientName, $subject, $html, $authorName = null, $authorEmail = null)
|
||||
{
|
||||
if (! empty($recipientEmail)) {
|
||||
$this->queueManager->push(EmailJob::getInstance($this->container)->withParams(
|
||||
$recipientEmail,
|
||||
$recipientName,
|
||||
$subject,
|
||||
$html,
|
||||
is_null($authorName) ? $this->getAuthorName() : $authorName,
|
||||
is_null($authorEmail) ? $this->getAuthorEmail() : $authorEmail
|
||||
));
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get author name
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function getAuthorName()
|
||||
{
|
||||
$author = 'Kanboard';
|
||||
|
||||
if ($this->userSession->isLogged()) {
|
||||
$author = e('%s via Kanboard', $this->helper->user->getFullname());
|
||||
}
|
||||
|
||||
return $author;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get author email
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function getAuthorEmail()
|
||||
{
|
||||
if ($this->userSession->isLogged()) {
|
||||
$userData = $this->userSession->getAll();
|
||||
return ! empty($userData['email']) ? $userData['email'] : '';
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get mail transport instance
|
||||
*
|
||||
* @access public
|
||||
* @param string $transport
|
||||
* @return ClientInterface
|
||||
*/
|
||||
public function getTransport($transport)
|
||||
{
|
||||
return $this->transports[$transport];
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new mail transport
|
||||
*
|
||||
* @access public
|
||||
* @param string $transport
|
||||
* @param string $class
|
||||
* @return Client
|
||||
*/
|
||||
public function setTransport($transport, $class)
|
||||
{
|
||||
$container = $this->container;
|
||||
|
||||
$this->transports[$transport] = function () use ($class, $container) {
|
||||
return new $class($container);
|
||||
};
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the list of registered transports
|
||||
*
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getAvailableTransports()
|
||||
{
|
||||
$availableTransports = $this->transports->keys();
|
||||
return array_combine($availableTransports, $availableTransports);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace Kanboard\Core\Mail;
|
||||
|
||||
/**
|
||||
* Mail Client Interface
|
||||
*
|
||||
* @package Kanboard\Core\Mail
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
interface ClientInterface
|
||||
{
|
||||
/**
|
||||
* Send a HTML email
|
||||
*
|
||||
* @access public
|
||||
* @param string $recipientEmail
|
||||
* @param string $recipientName
|
||||
* @param string $subject
|
||||
* @param string $html
|
||||
* @param string $authorName
|
||||
* @param string $authorEmail
|
||||
*/
|
||||
public function sendEmail($recipientEmail, $recipientName, $subject, $html, $authorName, $authorEmail = '');
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace Kanboard\Core\Mail\Transport;
|
||||
|
||||
use Swift_Message;
|
||||
use Swift_Mailer;
|
||||
use Swift_MailTransport;
|
||||
use Swift_TransportException;
|
||||
use Kanboard\Core\Base;
|
||||
use Kanboard\Core\Mail\ClientInterface;
|
||||
|
||||
/**
|
||||
* PHP Mail Handler
|
||||
*
|
||||
* @package Kanboard\Core\Mail\Transport
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class Mail extends Base implements ClientInterface
|
||||
{
|
||||
/**
|
||||
* Send a HTML email
|
||||
*
|
||||
* @access public
|
||||
* @param string $recipientEmail
|
||||
* @param string $recipientName
|
||||
* @param string $subject
|
||||
* @param string $html
|
||||
* @param string $authorName
|
||||
* @param string $authorEmail
|
||||
*/
|
||||
public function sendEmail($recipientEmail, $recipientName, $subject, $html, $authorName, $authorEmail = '')
|
||||
{
|
||||
try {
|
||||
$message = Swift_Message::newInstance()
|
||||
->setSubject($subject)
|
||||
->setFrom($this->helper->mail->getMailSenderAddress(), $authorName)
|
||||
->setTo(array($recipientEmail => $recipientName));
|
||||
|
||||
if (! empty(MAIL_BCC)) {
|
||||
$message->setBcc(MAIL_BCC);
|
||||
}
|
||||
|
||||
$headers = $message->getHeaders();
|
||||
|
||||
// See https://tools.ietf.org/html/rfc3834#section-5
|
||||
$headers->addTextHeader('Auto-Submitted', 'auto-generated');
|
||||
|
||||
if (! empty($authorEmail)) {
|
||||
$message->setReplyTo($authorEmail);
|
||||
}
|
||||
|
||||
$message->setBody($html, 'text/html');
|
||||
|
||||
Swift_Mailer::newInstance($this->getTransport())->send($message);
|
||||
} catch (Swift_TransportException $e) {
|
||||
$this->logger->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get SwiftMailer transport
|
||||
*
|
||||
* @access protected
|
||||
* @return \Swift_Transport
|
||||
*/
|
||||
protected function getTransport()
|
||||
{
|
||||
return Swift_MailTransport::newInstance();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace Kanboard\Core\Mail\Transport;
|
||||
|
||||
use Swift_SendmailTransport;
|
||||
|
||||
/**
|
||||
* PHP Mail Handler
|
||||
*
|
||||
* @package Kanboard\Core\Mail\Transport
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class Sendmail extends Mail
|
||||
{
|
||||
/**
|
||||
* Get SwiftMailer transport
|
||||
*
|
||||
* @access protected
|
||||
* @return \Swift_Transport
|
||||
*/
|
||||
protected function getTransport()
|
||||
{
|
||||
return Swift_SendmailTransport::newInstance(MAIL_SENDMAIL_COMMAND);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace Kanboard\Core\Mail\Transport;
|
||||
|
||||
use Swift_SmtpTransport;
|
||||
|
||||
/**
|
||||
* PHP Mail Handler
|
||||
*
|
||||
* @package Kanboard\Core\Mail\Transport
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class Smtp extends Mail
|
||||
{
|
||||
/**
|
||||
* Get SwiftMailer transport
|
||||
*
|
||||
* @access protected
|
||||
* @return \Swift_Transport
|
||||
*/
|
||||
protected function getTransport()
|
||||
{
|
||||
$transport = Swift_SmtpTransport::newInstance(MAIL_SMTP_HOSTNAME, MAIL_SMTP_PORT);
|
||||
$transport->setUsername(MAIL_SMTP_USERNAME);
|
||||
$transport->setPassword(MAIL_SMTP_PASSWORD);
|
||||
if (!is_null(MAIL_SMTP_HELO_NAME)) {
|
||||
$transport->setLocalDomain(MAIL_SMTP_HELO_NAME);
|
||||
}
|
||||
$transport->setEncryption(MAIL_SMTP_ENCRYPTION);
|
||||
|
||||
if (HTTP_VERIFY_SSL_CERTIFICATE === false) {
|
||||
$transport->setStreamOptions(array(
|
||||
'ssl' => array(
|
||||
'allow_self_signed' => true,
|
||||
'verify_peer' => false,
|
||||
'verify_peer_name' => false,
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
return $transport;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user