com web/wiki: Add new SMTP plugin: dokuwiki/lib/plugins/smtp/.travis.yml dokuwiki/lib/plugins/smtp/README dokuwiki/lib/plugins/smtp/_t
est/general.test.php dokuwiki/lib/plugins/smtp/_test/me ssage.test.php dokuwiki/lib/plugins/smtp/action.php d okuwiki/lib/plugins/smtp/admin.php
dokuwiki/lib/plugins/smt p/admin.svg dokuwiki/lib/plugins/smtp/classes/Logger.php dokuwiki/lib/plugins/smtp/classes/Message.php dokuwiki/l
ib/plugins/smtp/conf/default.php dok

From: Date: Tue, 05 Dec 2017 14:11:11 +0000
Subject: com web/wiki: Add new SMTP plugin: dokuwiki/lib/plugins/smtp/.travis.yml dokuwiki/lib/plugins/smtp/README dokuwiki/lib/plugins/smtp/_t
est/general.test.php dokuwiki/lib/plugins/smtp/_test/me ssage.test.php dokuwiki/lib/plugins/smtp/action.php d okuwiki/lib/plugins/smtp/admin.php
dokuwiki/lib/plugins/smt p/admin.svg dokuwiki/lib/plugins/smtp/classes/Logger.php dokuwiki/lib/plugins/smtp/classes/Message.php dokuwiki/l
ib/plugins/smtp/conf/default.php dok
Groups: php.webmaster 
Request: Send a blank email to php-webmaster+get-26625@lists.php.net to get a copy of this message
Commit: 4821c89e7ba7d6c39a71d487f96d8ac03edf2d69 Author: Niklas Keller <me@kelunik.com> Tue, 5 Dec 2017 15:11:11 +0100 Parents: 5229a4e9d6b8ed04c2b11caa3d751eb34e215fab Branches: master Link: http://git.php.net/?p=web/wiki.git;a=commitdiff;h=4821c89e7ba7d6c39a71d487f96d8ac03edf2d69 Log: Add new SMTP plugin Previously simply mail() was used on the old server. The new server doesn't have a valid configuration currently. Changed paths: A dokuwiki/lib/plugins/smtp/.travis.yml A dokuwiki/lib/plugins/smtp/README A dokuwiki/lib/plugins/smtp/_test/general.test.php A dokuwiki/lib/plugins/smtp/_test/message.test.php A dokuwiki/lib/plugins/smtp/action.php A dokuwiki/lib/plugins/smtp/admin.php A dokuwiki/lib/plugins/smtp/admin.svg A dokuwiki/lib/plugins/smtp/classes/Logger.php A dokuwiki/lib/plugins/smtp/classes/Message.php A dokuwiki/lib/plugins/smtp/conf/default.php A dokuwiki/lib/plugins/smtp/conf/metadata.php A dokuwiki/lib/plugins/smtp/helper.php A dokuwiki/lib/plugins/smtp/lang/ar/intro.txt A dokuwiki/lib/plugins/smtp/lang/ar/lang.php A dokuwiki/lib/plugins/smtp/lang/ar/settings.php A dokuwiki/lib/plugins/smtp/lang/cs/intro.txt A dokuwiki/lib/plugins/smtp/lang/cs/lang.php A dokuwiki/lib/plugins/smtp/lang/cs/settings.php A dokuwiki/lib/plugins/smtp/lang/da/intro.txt A dokuwiki/lib/plugins/smtp/lang/da/lang.php A dokuwiki/lib/plugins/smtp/lang/da/settings.php A dokuwiki/lib/plugins/smtp/lang/de/intro.txt A dokuwiki/lib/plugins/smtp/lang/de/lang.php A dokuwiki/lib/plugins/smtp/lang/de/settings.php A dokuwiki/lib/plugins/smtp/lang/en/intro.txt A dokuwiki/lib/plugins/smtp/lang/en/lang.php A dokuwiki/lib/plugins/smtp/lang/en/settings.php A dokuwiki/lib/plugins/smtp/lang/eo/intro.txt A dokuwiki/lib/plugins/smtp/lang/eo/lang.php A dokuwiki/lib/plugins/smtp/lang/eo/settings.php A dokuwiki/lib/plugins/smtp/lang/fr/intro.txt A dokuwiki/lib/plugins/smtp/lang/fr/lang.php A dokuwiki/lib/plugins/smtp/lang/fr/settings.php A dokuwiki/lib/plugins/smtp/lang/ja/intro.txt A dokuwiki/lib/plugins/smtp/lang/ja/lang.php A dokuwiki/lib/plugins/smtp/lang/ja/settings.php A dokuwiki/lib/plugins/smtp/lang/ko/intro.txt A dokuwiki/lib/plugins/smtp/lang/ko/lang.php A dokuwiki/lib/plugins/smtp/lang/ko/settings.php A dokuwiki/lib/plugins/smtp/lang/nl/intro.txt A dokuwiki/lib/plugins/smtp/lang/nl/lang.php A dokuwiki/lib/plugins/smtp/lang/nl/settings.php A dokuwiki/lib/plugins/smtp/lang/no/intro.txt A dokuwiki/lib/plugins/smtp/lang/no/lang.php A dokuwiki/lib/plugins/smtp/lang/no/settings.php A dokuwiki/lib/plugins/smtp/lang/ru/intro.txt A dokuwiki/lib/plugins/smtp/lang/ru/lang.php A dokuwiki/lib/plugins/smtp/lang/ru/settings.php A dokuwiki/lib/plugins/smtp/lang/sk/settings.php A dokuwiki/lib/plugins/smtp/lang/sv/intro.txt A dokuwiki/lib/plugins/smtp/lang/sv/lang.php A dokuwiki/lib/plugins/smtp/lang/sv/settings.php A dokuwiki/lib/plugins/smtp/lang/zh/intro.txt A dokuwiki/lib/plugins/smtp/lang/zh/lang.php A dokuwiki/lib/plugins/smtp/lang/zh/settings.php A dokuwiki/lib/plugins/smtp/loader.php A dokuwiki/lib/plugins/smtp/plugin.info.txt A dokuwiki/lib/plugins/smtp/subtree/php-fig/log/.gitignore A dokuwiki/lib/plugins/smtp/subtree/php-fig/log/LICENSE A dokuwiki/lib/plugins/smtp/subtree/php-fig/log/Psr/Log/AbstractLogger.php A dokuwiki/lib/plugins/smtp/subtree/php-fig/log/Psr/Log/InvalidArgumentException.php A dokuwiki/lib/plugins/smtp/subtree/php-fig/log/Psr/Log/LogLevel.php A dokuwiki/lib/plugins/smtp/subtree/php-fig/log/Psr/Log/LoggerAwareInterface.php A dokuwiki/lib/plugins/smtp/subtree/php-fig/log/Psr/Log/LoggerAwareTrait.php A dokuwiki/lib/plugins/smtp/subtree/php-fig/log/Psr/Log/LoggerInterface.php A dokuwiki/lib/plugins/smtp/subtree/php-fig/log/Psr/Log/LoggerTrait.php A dokuwiki/lib/plugins/smtp/subtree/php-fig/log/Psr/Log/NullLogger.php A dokuwiki/lib/plugins/smtp/subtree/php-fig/log/Psr/Log/Test/LoggerInterfaceTest.php A dokuwiki/lib/plugins/smtp/subtree/php-fig/log/README.md A dokuwiki/lib/plugins/smtp/subtree/php-fig/log/composer.json A dokuwiki/lib/plugins/smtp/subtree/txtthinking/Mailer/.gitignore A dokuwiki/lib/plugins/smtp/subtree/txtthinking/Mailer/LICENSE A dokuwiki/lib/plugins/smtp/subtree/txtthinking/Mailer/README.md A dokuwiki/lib/plugins/smtp/subtree/txtthinking/Mailer/composer.json A dokuwiki/lib/plugins/smtp/subtree/txtthinking/Mailer/phpunit.xml A dokuwiki/lib/plugins/smtp/subtree/txtthinking/Mailer/src/Mailer.php A dokuwiki/lib/plugins/smtp/subtree/txtthinking/Mailer/src/Mailer/Exceptions/CodeException.php A dokuwiki/lib/plugins/smtp/subtree/txtthinking/Mailer/src/Mailer/Exceptions/CryptoException.php A dokuwiki/lib/plugins/smtp/subtree/txtthinking/Mailer/src/Mailer/Exceptions/SMTPException.php A dokuwiki/lib/plugins/smtp/subtree/txtthinking/Mailer/src/Mailer/Exceptions/SendException.php A dokuwiki/lib/plugins/smtp/subtree/txtthinking/Mailer/src/Mailer/Message.php A dokuwiki/lib/plugins/smtp/subtree/txtthinking/Mailer/src/Mailer/SMTP.php A dokuwiki/lib/plugins/smtp/subtree/txtthinking/Mailer/tests/MailerTest.php A dokuwiki/lib/plugins/smtp/subtree/txtthinking/Mailer/tests/SMTPTest.php A dokuwiki/lib/plugins/smtp/subtree/txtthinking/Mailer/tests/TestCase.php

diff --git a/dokuwiki/lib/plugins/smtp/.travis.yml b/dokuwiki/lib/plugins/smtp/.travis.yml new file mode 100644 index 0000000..03fce1e --- /dev/null +++ b/dokuwiki/lib/plugins/smtp/.travis.yml @@ -0,0 +1,15 @@ +# Config file for travis-ci.org + +language: php +php: + - "7.0" + - "5.6" + - "5.5" + - "5.4" + - "5.3" +env: + - DOKUWIKI=master + - DOKUWIKI=stable +before_install: wget https://raw.github.com/splitbrain/dokuwiki-travis/master/travis.sh +install: sh travis.sh +script: cd _test && phpunit --stderr --group plugin_smtp diff --git a/dokuwiki/lib/plugins/smtp/README b/dokuwiki/lib/plugins/smtp/README new file mode 100644 index 0000000..040ff1b --- /dev/null +++ b/dokuwiki/lib/plugins/smtp/README @@ -0,0 +1,27 @@ +smtp Plugin for DokuWiki + +Send mails via a configured SMTP server + +All documentation for this plugin can be found at +https://www.dokuwiki.org/plugin:smtp + +If you install this plugin manually, make sure it is installed in +lib/plugins/smtp/ - if the folder is called different it +will not work! + +Please refer to http://www.dokuwiki.org/plugins for additional info +on how to install plugins in DokuWiki. + +---- +Copyright (C) Andreas Gohr <andi@splitbrain.org> + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; version 2 of the License + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +See the COPYING file in your DokuWiki folder for details diff --git a/dokuwiki/lib/plugins/smtp/_test/general.test.php b/dokuwiki/lib/plugins/smtp/_test/general.test.php new file mode 100644 index 0000000..84c1ac6 --- /dev/null +++ b/dokuwiki/lib/plugins/smtp/_test/general.test.php @@ -0,0 +1,33 @@ +<?php +/** + * General tests for the smtp plugin + * + * @group plugin_smtp + * @group plugins + */ +class general_plugin_smtp_test extends DokuWikiTest { + + /** + * Simple test to make sure the plugin.info.txt is in correct format + */ + public function test_plugininfo() { + $file = __DIR__.'/../plugin.info.txt'; + $this->assertFileExists($file); + + $info = confToHash($file); + + $this->assertArrayHasKey('base', $info); + $this->assertArrayHasKey('author', $info); + $this->assertArrayHasKey('email', $info); + $this->assertArrayHasKey('date', $info); + $this->assertArrayHasKey('name', $info); + $this->assertArrayHasKey('desc', $info); + $this->assertArrayHasKey('url', $info); + + $this->assertEquals('smtp', $info['base']); + $this->assertRegExp('/^https?:\/\//', $info['url']); + $this->assertTrue(mail_isvalid($info['email'])); + $this->assertRegExp('/^\d\d\d\d-\d\d-\d\d$/', $info['date']); + $this->assertTrue(false !== strtotime($info['date'])); + } +} diff --git a/dokuwiki/lib/plugins/smtp/_test/message.test.php b/dokuwiki/lib/plugins/smtp/_test/message.test.php new file mode 100644 index 0000000..de69c2b --- /dev/null +++ b/dokuwiki/lib/plugins/smtp/_test/message.test.php @@ -0,0 +1,51 @@ +<?php +/** + * General tests for the smtp plugin + * + * @group plugin_smtp + * @group plugins + */ +class message_plugin_smtp_test extends DokuWikiTest { + public function setUp() { + parent::setUp(); + require_once __DIR__ . '/../loader.php'; + } + + public function test_body() { + $input = trim(' +X-Mailer: DokuWiki +X-Dokuwiki-User: admin +X-Dokuwiki-Title: Test Wiki +X-Dokuwiki-Server: localhost.localhost +From: a@example.com +To: b@example.com +Bcc: c@example.com, d@example.com, + d@example.com +Subject: A test + +This is the body of the mail +Bcc: this is not a header line +end of message +'); + + $expect = trim(' +X-Mailer: DokuWiki +X-Dokuwiki-User: admin +X-Dokuwiki-Title: Test Wiki +X-Dokuwiki-Server: localhost.localhost +From: a@example.com +To: b@example.com +Subject: A test + +This is the body of the mail +Bcc: this is not a header line +end of message +'); + $expect .= "\r\n\r\n.\r\n"; + + $message = new \splitbrain\dokuwiki\plugin\smtp\Message('','',$input); + + $this->assertEquals($expect, $message->toString()); + + } +} diff --git a/dokuwiki/lib/plugins/smtp/action.php b/dokuwiki/lib/plugins/smtp/action.php new file mode 100644 index 0000000..d206954 --- /dev/null +++ b/dokuwiki/lib/plugins/smtp/action.php @@ -0,0 +1,99 @@ +<?php +/** + * DokuWiki Plugin smtp (Action Component) + * + * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html + * @author Andreas Gohr <andi@splitbrain.org> + */ + +// must be run within Dokuwiki +if(!defined('DOKU_INC')) die(); + +class action_plugin_smtp extends DokuWiki_Action_Plugin { + + /** + * Registers a callback function for a given event + * + * @param Doku_Event_Handler $controller DokuWiki's event controller object + * @return void + */ + public function register(Doku_Event_Handler $controller) { + + $controller->register_hook('MAIL_MESSAGE_SEND', 'BEFORE', $this, 'handle_mail_message_send'); + + } + + /** + * [Custom event handler which performs action] + * + * @param Doku_Event $event event object by reference + * @param mixed $param [the parameters passed as fifth argument to register_hook() when this + * handler was registered] + * @return void + */ + + public function handle_mail_message_send(Doku_Event &$event, $param) { + require_once __DIR__ . '/loader.php'; + + // prepare the message + /** @var Mailer $mailer Our Mailer with all the data */ + $mailer = $event->data['mail']; + $body = $mailer->dump(); // this also prepares all internal variables of the mailer + $rcpt = $event->data['to'] . ',' . + $event->data['cc'] . ',' . + $event->data['bcc']; + $from = $event->data['from']; + $message = new \splitbrain\dokuwiki\plugin\smtp\Message( + $from, + $rcpt, + $body + ); + + // prepare the SMTP communication lib + $logger = new \splitbrain\dokuwiki\plugin\smtp\Logger(); + $smtp = new \Tx\Mailer\SMTP($logger); + $smtp->setServer( + $this->getConf('smtp_host'), + $this->getConf('smtp_port'), + $this->getConf('smtp_ssl') + ); + if($this->getConf('auth_user')){ + $smtp->setAuth( + $this->getConf('auth_user'), + $this->getConf('auth_pass') + ); + } + $smtp->setEhlo( + helper_plugin_smtp::getEHLO($this->getConf('localdomain')) + ); + + + // send the message + try { + $smtp->send($message); + $ok = true; + } catch (Exception $e) { + msg('There was an unexpected problem communicating with SMTP: '.$e->getMessage(), -1); + $ok = false; + } + + // give debugging help on error + if(!$ok && $this->getConf('debug')) { + $log = array(); + foreach($logger->getLog() as $line) { + $log[] = trim($line[1]); + } + $log = trim(join("\n", $log)); + msg('SMTP log:<br /><pre>'.hsc($log).'</pre><b>Above may contain passwords - do not post online!</b>',-1); + } + + // finish event handling + $event->preventDefault(); + $event->stopPropagation(); + $event->result = $ok; + $event->data['success'] = $ok; + } + +} + +// vim:ts=4:sw=4:et: diff --git a/dokuwiki/lib/plugins/smtp/admin.php b/dokuwiki/lib/plugins/smtp/admin.php new file mode 100644 index 0000000..853e9b3 --- /dev/null +++ b/dokuwiki/lib/plugins/smtp/admin.php @@ -0,0 +1,71 @@ +<?php +/** + * Swiftmail Plugin + * + * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) + * @author Andreas Gohr <andi@splitbrain.org> + */ +// must be run within Dokuwiki +if(!defined('DOKU_INC')) die(); + +class admin_plugin_smtp extends DokuWiki_Admin_Plugin { + + /** + * return sort order for position in admin menu + */ + function getMenuSort() { + return 200; + } + + /** + * handle user request + */ + function handle() { + global $INPUT; + global $conf; + if(!$INPUT->bool('send')) return; + + // make sure debugging is on; + $conf['plugin']['smtp']['debug'] = 1; + + // send a mail + $mail = new Mailer(); + if($INPUT->str('to')) $mail->to($INPUT->str('to')); + if($INPUT->str('cc')) $mail->cc($INPUT->str('cc')); + if($INPUT->str('bcc')) $mail->bcc($INPUT->str('bcc')); + $mail->subject('DokuWiki says hello'); + $mail->setBody("Hi @USER@\n\nThis is a test from @DOKUWIKIURL@"); + $ok = $mail->send(); + + // check result + if($ok){ + msg('Message was sent. SMTP seems to work.',1); + }else{ + msg('Message wasn\'t sent. SMTP seems not to work properly.',-1); + } + } + + /** + * Output HTML form + */ + function html() { + global $INPUT; + global $conf; + + echo $this->locale_xhtml('intro'); + + if(!$conf['mailfrom']) msg($this->getLang('nofrom'),-1); + + + $form = new Doku_Form(array()); + $form->startFieldset('Testmail'); + $form->addHidden('send', 1); + $form->addElement(form_makeField('text', 'to', $INPUT->str('to'), 'To:', '', 'block')); + $form->addElement(form_makeField('text', 'cc', $INPUT->str('cc'), 'Cc:', '', 'block')); + $form->addElement(form_makeField('text', 'bcc', $INPUT->str('bcc'), 'Bcc:', '', 'block')); + $form->addElement(form_makeButton('submit', '', 'Send Email')); + + $form->printForm(); + } + +} diff --git a/dokuwiki/lib/plugins/smtp/admin.svg b/dokuwiki/lib/plugins/smtp/admin.svg new file mode 100644 index 0000000..6e58030 --- /dev/null +++ b/dokuwiki/lib/plugins/smtp/admin.svg @@ -0,0 +1 @@ +<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M15.45 11.91c-.11-2.21-1.75-3.54-3.73-3.54h-.08c-2.29 0-3.55 1.8-3.55 3.84 0 2.29 1.53 3.74 3.54 3.74 2.25 0 3.72-1.65 3.83-3.59m-3.81-5.97c1.53 0 2.97.68 4.02 1.74 0-.51.33-.89.83-.89h.11c.74 0 .89.7.89.92v7.9c-.04.52.54.78.87.44 1.27-1.29 2.78-6.69-.79-9.81-3.33-2.92-7.8-2.44-10.18-.8-2.52 1.74-4.14 5.61-2.57 9.22 1.71 3.95 6.61 5.13 9.52 3.95 1.48-.59 2.15 1.4.65 2.05-2.34.99-8.77.89-11.78-4.32-2.03-3.52-1.93-9.71 3.46-12.92C10.81 1.42 16.24 2.1 19.5 5.5c3.45 3.6 3.25 10.3-.1 12.91-1.51 1.18-3.76.03-3.74-1.7l-.02-.56a5.611 5.611 0 0 1-3.99 1.66C8.63 17.81 6 15.15 6 12.13c0-3.05 2.63-5.74 5.65-5.74z"/></svg> \ No newline at end of file diff --git a/dokuwiki/lib/plugins/smtp/classes/Logger.php b/dokuwiki/lib/plugins/smtp/classes/Logger.php new file mode 100644 index 0000000..ade5e5c --- /dev/null +++ b/dokuwiki/lib/plugins/smtp/classes/Logger.php @@ -0,0 +1,155 @@ +<?php + +namespace splitbrain\dokuwiki\plugin\smtp; + +use Psr\Log\LoggerInterface; + +/** + * Simple PSR-3 logger + * + * Simply logs to an internal variable + * + * @package splitbrain\dokuwiki\plugin\smtp + */ +class Logger implements LoggerInterface { + + protected $log = array(); + + /** + * Get all log messages + * + * @return array + */ + public function getLog() { + return $this->log; + } + + /** + * System is unusable. + * + * @param string $message + * @param array $context + * + * @return null + */ + public function emergency($message, array $context = array()) + { + $this->log('emergency', $message, $context); + } + + /** + * Action must be taken immediately. + * + * Example: Entire website down, database unavailable, etc. This should + * trigger the SMS alerts and wake you up. + * + * @param string $message + * @param array $context + * + * @return null + */ + public function alert($message, array $context = array()) + { + $this->log('alert', $message, $context); + } + + /** + * Critical conditions. + * + * Example: Application component unavailable, unexpected exception. + * + * @param string $message + * @param array $context + * + * @return null + */ + public function critical($message, array $context = array()) + { + $this->log('critical', $message, $context); + } + + /** + * Runtime errors that do not require immediate action but should typically + * be logged and monitored. + * + * @param string $message + * @param array $context + * + * @return null + */ + public function error($message, array $context = array()) + { + $this->log('error', $message, $context); + } + + /** + * Exceptional occurrences that are not errors. + * + * Example: Use of deprecated APIs, poor use of an API, undesirable things + * that are not necessarily wrong. + * + * @param string $message + * @param array $context + * + * @return null + */ + public function warning($message, array $context = array()) + { + $this->log('warning', $message, $context); + } + + /** + * Normal but significant events. + * + * @param string $message + * @param array $context + * + * @return null + */ + public function notice($message, array $context = array()) + { + $this->log('notice', $message, $context); + } + + /** + * Interesting events. + * + * Example: User logs in, SQL logs. + * + * @param string $message + * @param array $context + * + * @return null + */ + public function info($message, array $context = array()) + { + $this->log('info', $message, $context); + } + + /** + * Detailed debug information. + * + * @param string $message + * @param array $context + * + * @return null + */ + public function debug($message, array $context = array()) + { + $this->log('debug', $message, $context); + } + + /** + * Logs with an arbitrary level. + * + * @param mixed $level + * @param string $message + * @param array $context + * + * @return null + */ + public function log($level, $message, array $context = array()) + { + $this->log[] = array($level, $message, $context); + } +} diff --git a/dokuwiki/lib/plugins/smtp/classes/Message.php b/dokuwiki/lib/plugins/smtp/classes/Message.php new file mode 100644 index 0000000..ee8e9fb --- /dev/null +++ b/dokuwiki/lib/plugins/smtp/classes/Message.php @@ -0,0 +1,93 @@ +<?php + +namespace splitbrain\dokuwiki\plugin\smtp; + +/** + * Class Message + * + * Overrides the Message class with what we need to reuse the SMTP mailer without using + * their message composer + * + * @package splitbrain\dokuwiki\plugin\smtp + */ +class Message extends \Tx\Mailer\Message { + + protected $from; + protected $rcpt; + protected $body; + + /** + * @param string $from Sender Address + * @param string $rcpt all recipients (TO, CC, BCC) + * @param string $body the full message body including headers + */ + public function __construct($from, $rcpt, $body) { + $this->from = $from; + $this->rcpt = $rcpt; + $this->body = $body; + } + + /** + * Return the mail only part of the from address + * + * @return string + */ + public function getFromEmail() { + if(preg_match('#(.*?)<(.*?)>#', $this->from, $matches)) { + return $matches[2]; + } + + return $this->from; + } + + /** + * Get a list of all recipients (mail only part) + * + * @return array + */ + public function getTo() { + $rcpt = array(); + + // We need the mail only part of all recipients + $addresses = explode(',', $this->rcpt); + foreach($addresses as $addr) { + // parse address + if(preg_match('#(.*?)<(.*?)>#', $addr, $matches)) { + $rcpt[] = trim($matches[2]); + } else { + $rcpt[] = trim($addr); + } + } + + $rcpt = array_filter($rcpt); + $rcpt = array_unique($rcpt); + return $rcpt; + } + + /** + * Return the whole message body ready to be send by DATA + * + * Includes end of data signature and strips the BCC header + * + * @return string + */ + public function toString() { + // we need to remove the BCC header here + $lines = explode("\n", $this->body); + $count = count($lines); + for($i=0; $i<$count; $i++) { + if(trim($lines[$i]) === '') break; // end of headers, we're done + if(substr($lines[$i],0, 4) == 'Bcc:') { + unset($lines[$i]); // we found the Bcc: header and remove it + while(substr($lines[++$i],0, 1) === ' ') { + unset($lines[$i]); // indented lines are header continuiation + } + break; // header removed, we're done + } + } + $body = join("\n", $lines); + + return $body . $this->CRLF . $this->CRLF . "." . $this->CRLF; + } + +} diff --git a/dokuwiki/lib/plugins/smtp/conf/default.php b/dokuwiki/lib/plugins/smtp/conf/default.php new file mode 100644 index 0000000..165475c --- /dev/null +++ b/dokuwiki/lib/plugins/smtp/conf/default.php @@ -0,0 +1,13 @@ +<?php + +$conf['smtp_host'] = 'localhost'; +$conf['smtp_port'] = 25; +$conf['smtp_ssl'] = ''; + +$conf['localdomain'] = ''; + +$conf['auth_user'] = ''; +$conf['auth_pass'] = ''; + + +$conf['debug'] = 0; diff --git a/dokuwiki/lib/plugins/smtp/conf/metadata.php b/dokuwiki/lib/plugins/smtp/conf/metadata.php new file mode 100644 index 0000000..884f908 --- /dev/null +++ b/dokuwiki/lib/plugins/smtp/conf/metadata.php @@ -0,0 +1,13 @@ +<?php + +$meta['smtp_host'] = array('string'); +$meta['smtp_port'] = array('numeric'); +$meta['smtp_ssl'] = array('multichoice','_choices' => array('','ssl','tls')); + +$meta['auth_user'] = array('string'); +$meta['auth_pass'] = array('password'); + +$meta['localdomain'] = array('string'); + +$meta['debug'] = array('onoff'); + diff --git a/dokuwiki/lib/plugins/smtp/helper.php b/dokuwiki/lib/plugins/smtp/helper.php new file mode 100644 index 0000000..d85fbd1 --- /dev/null +++ b/dokuwiki/lib/plugins/smtp/helper.php @@ -0,0 +1,29 @@ +<?php +/** + * DokuWiki Plugin smtp (Helper Component) + * + * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html + * @author Andreas Gohr <andi@splitbrain.org> + */ + +// must be run within Dokuwiki +if(!defined('DOKU_INC')) die(); + +class helper_plugin_smtp extends DokuWiki_Plugin { + + /** + * Return a string usable as EHLO message + * + * @param string $ehlo configured EHLO (ovverrides automatic detection) + * @return string + */ + static public function getEHLO($ehlo='') { + if(empty($ehlo)) { + $ehlo = !empty($_SERVER["SERVER_ADDR"]) ? "[" . $_SERVER["SERVER_ADDR"] . "]" : "localhost.localdomain"; + } + return $ehlo; + } + +} + +// vim:ts=4:sw=4:et: diff --git a/dokuwiki/lib/plugins/smtp/lang/ar/intro.txt b/dokuwiki/lib/plugins/smtp/lang/ar/intro.txt new file mode 100644 index 0000000..639a43d --- /dev/null +++ b/dokuwiki/lib/plugins/smtp/lang/ar/intro.txt @@ -0,0 +1 @@ += = = اختبار سويفتميل = = = هذه الصفحة يسمح لك بتشغيل إرسال بريد اختبار في دوكي ويكي. يمكنك استخدامه للتحقق إذا قمت بتكوين البرنامج المساعد سويفتميل بشكل صحيح. إعطاء عناوين البريد الإلكتروني الخاص بالمستلم في النموذج أدناه. \ No newline at end of file diff --git a/dokuwiki/lib/plugins/smtp/lang/ar/lang.php b/dokuwiki/lib/plugins/smtp/lang/ar/lang.php new file mode 100644 index 0000000..4ee925b --- /dev/null +++ b/dokuwiki/lib/plugins/smtp/lang/ar/lang.php @@ -0,0 +1,9 @@ +<?php + +/** + * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) + * + * @author alhajr <alhajr300@gmail.com> + */ +$lang['menu'] = 'تحقق من تكوين سويفتميل'; +$lang['nofrom'] = 'أنت لم تكوين الخيار \'mailfrom\'. إرسال الرسائل ستفشل على الأرجح.'; diff --git a/dokuwiki/lib/plugins/smtp/lang/ar/settings.php b/dokuwiki/lib/plugins/smtp/lang/ar/settings.php new file mode 100644 index 0000000..7102c0f --- /dev/null +++ b/dokuwiki/lib/plugins/smtp/lang/ar/settings.php @@ -0,0 +1,13 @@ +<?php + +/** + * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) + * + * @author alhajr <alhajr300@gmail.com> + */ +$lang['smtp_host'] = 'خادم البريد الصادر SMTP.'; +$lang['smtp_ssl'] = 'ما هو نوع التشفير المستخدم عند الاتصال مع ملقم SMTP الخاص بك؟'; +$lang['smtp_ssl_o_'] = 'لا شيء'; +$lang['auth_user'] = 'إذا كانت المصادقة مطلوبة، ضع اسم المستخدم الخاص بك هنا.'; +$lang['auth_pass'] = 'كلمة المرور للمستخدم أعلاه.'; +$lang['debug'] = 'طباعة سجل كامل للاخطأ عند فشل الإرسال؟ تعطيل عندما يعمل كل شيء!'; diff --git a/dokuwiki/lib/plugins/smtp/lang/cs/intro.txt b/dokuwiki/lib/plugins/smtp/lang/cs/intro.txt new file mode 100644 index 0000000..9c6d146 --- /dev/null +++ b/dokuwiki/lib/plugins/smtp/lang/cs/intro.txt @@ -0,0 +1,5 @@ +====== Zkouška SMTP ====== + +Na této stránce můžete vyzkoušet posílání e-mailu v DokuWiki. Můžete ji využít pro ověření správnosti nastavení rozšíření SMTP. + +Do formuláře níže zadejte e-mailové adresy adresátů. \ No newline at end of file diff --git a/dokuwiki/lib/plugins/smtp/lang/cs/lang.php b/dokuwiki/lib/plugins/smtp/lang/cs/lang.php new file mode 100644 index 0000000..9ee070c --- /dev/null +++ b/dokuwiki/lib/plugins/smtp/lang/cs/lang.php @@ -0,0 +1,9 @@ +<?php + +/** + * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) + * + * @author Pavel Krupička <pajdacz@gmail.com> + */ +$lang['menu'] = 'Zkouška nastavení SMTP'; +$lang['nofrom'] = 'Nenastavili jste možnost \'mailfrom\'. Odesílání e-mailů pravděpodobně selže.'; diff --git a/dokuwiki/lib/plugins/smtp/lang/cs/settings.php b/dokuwiki/lib/plugins/smtp/lang/cs/settings.php new file mode 100644 index 0000000..dd69515 --- /dev/null +++ b/dokuwiki/lib/plugins/smtp/lang/cs/settings.php @@ -0,0 +1,17 @@ +<?php + +/** + * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) + * + * @author Pavel Krupička <pajdacz@gmail.com> + */ +$lang['smtp_host'] = 'Váš odchozí SMTP server.'; +$lang['smtp_port'] = 'Port, na kterém SMTP server naslouchá. Obvykle 25. 465 pro SSL.'; +$lang['smtp_ssl'] = 'Jaký typ šifrování se využívá pro komunikaci s vaším SMTP serverem?'; +$lang['smtp_ssl_o_'] = 'žádný'; +$lang['smtp_ssl_o_ssl'] = 'SSL'; +$lang['smtp_ssl_o_tls'] = 'TLS'; +$lang['auth_user'] = 'Pokud je vyžadováno ověření, zadejte sem uživatelské jméno.'; +$lang['auth_pass'] = 'Heslo pro výše uvedeného uživatele.'; +$lang['localdomain'] = 'Jméno, které má být použito během HELO fáze SMTP. Mělo by být FQDN webového serveru, na kterém běží DokuWiki. Pro automatické zjištění ponechte prázdné.'; +$lang['debug'] = 'Vypsat kompletní výpis chyb, pokud odesílání selže? Zrušte, pokud vše funguje!'; diff --git a/dokuwiki/lib/plugins/smtp/lang/da/intro.txt b/dokuwiki/lib/plugins/smtp/lang/da/intro.txt new file mode 100644 index 0000000..79ef62b --- /dev/null +++ b/dokuwiki/lib/plugins/smtp/lang/da/intro.txt @@ -0,0 +1,5 @@ +====== SMTP Test ====== + +Denne side tillader dig at udløse sending af en test-mail i DokuWiki. Du kan bruge den til at kontrollere om du har konfigureret SMTP plugin korrekt. + +Angiv modtagers email-adresse i formularen herunder. diff --git a/dokuwiki/lib/plugins/smtp/lang/da/lang.php b/dokuwiki/lib/plugins/smtp/lang/da/lang.php new file mode 100644 index 0000000..d495836 --- /dev/null +++ b/dokuwiki/lib/plugins/smtp/lang/da/lang.php @@ -0,0 +1,9 @@ +<?php + +/** + * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) + * + * @author Søren Birk <soer9648@eucl.dk> + */ +$lang['menu'] = 'Kontrollér SMTP konfiguration'; +$lang['nofrom'] = 'Du konfigurerede ikke \'mailfrom\'-indstillingen. Sending af mails vil højst sandsynligt fejle.'; diff --git a/dokuwiki/lib/plugins/smtp/lang/da/settings.php b/dokuwiki/lib/plugins/smtp/lang/da/settings.php new file mode 100644 index 0000000..54ed724 --- /dev/null +++ b/dokuwiki/lib/plugins/smtp/lang/da/settings.php @@ -0,0 +1,17 @@ +<?php + +/** + * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) + * + * @author Søren Birk <soer9648@eucl.dk> + */ +$lang['smtp_host'] = 'Din udgående SMTP-server.'; +$lang['smtp_port'] = 'Porten, hvor din SMTP-server lytter. Som regel 25. 465 for SSL.'; +$lang['smtp_ssl'] = 'Hvilken kryptering benyttes under kommunikation med din SMTP-Server?'; +$lang['smtp_ssl_o_'] = 'ingen'; +$lang['smtp_ssl_o_ssl'] = 'SSL'; +$lang['smtp_ssl_o_tls'] = 'TLS'; +$lang['auth_user'] = 'Hvis autentificering er nødvendigt, skriv dit brugernavn her.'; +$lang['auth_pass'] = 'Adgangskode for brugeren herover.'; +$lang['localdomain'] = 'Navnet der skal benyttes under HELP-fasen for SMTP. Bør være FQDN for webserveren som DokuWiki kører på. Efterlad feltet tomt for autogenkendelse.'; +$lang['debug'] = 'Udskriv en fuld fejllog når mails sendes? Deaktivér dette, når alt virker!'; diff --git a/dokuwiki/lib/plugins/smtp/lang/de/intro.txt b/dokuwiki/lib/plugins/smtp/lang/de/intro.txt new file mode 100644 index 0000000..f6ae0c7 --- /dev/null +++ b/dokuwiki/lib/plugins/smtp/lang/de/intro.txt @@ -0,0 +1,5 @@ +====== SMTP Test ====== + +Auf dieser Seite kannst du eine Testmail von DokuWiki versenden. Diese kannst du verwenden um deine SMTP Konfiguration zu überprüfen. + +Füge die E-Mailaddressen der Empfänger in das Formular ein. diff --git a/dokuwiki/lib/plugins/smtp/lang/de/lang.php b/dokuwiki/lib/plugins/smtp/lang/de/lang.php new file mode 100644 index 0000000..4970adc --- /dev/null +++ b/dokuwiki/lib/plugins/smtp/lang/de/lang.php @@ -0,0 +1,9 @@ +<?php + +/** + * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) + * + * @author Dominik Eckelmann <deckelmann@gmail.com> + */ +$lang['menu'] = 'Überprüfe SMTP Konfiguration'; +$lang['nofrom'] = 'Sie haben die "mailfrom" Option nicht gesetzt. Der E-Mail Versand wird deshalb vermutlich fehlschlagen.'; diff --git a/dokuwiki/lib/plugins/smtp/lang/de/settings.php b/dokuwiki/lib/plugins/smtp/lang/de/settings.php new file mode 100644 index 0000000..1c3e5b6 --- /dev/null +++ b/dokuwiki/lib/plugins/smtp/lang/de/settings.php @@ -0,0 +1,17 @@ +<?php + +/** + * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) + * + * @author Dominik Eckelmann <deckelmann@gmail.com> + */ +$lang['smtp_host'] = 'Dein ausgehender SMTP Server'; +$lang['smtp_port'] = 'Der Port deines SMTP Servers (Standard 25 oder 465 für SSL)'; +$lang['smtp_ssl'] = 'Welche Verschlüsslung wird bei der Kommunikation mit deinem SMTP Server verwendet.'; +$lang['smtp_ssl_o_'] = 'Keine'; +$lang['smtp_ssl_o_ssl'] = 'SSL'; +$lang['smtp_ssl_o_tls'] = 'TLS'; +$lang['auth_user'] = 'Trage hier den Benutzernamen ein, falls eine Anmeldung am STMP Server erforderlich ist.'; +$lang['auth_pass'] = 'Passwort für den Benutzer darüber.'; +$lang['localdomain'] = 'Füge hier den namen, welcher während des HELO Aufrufes von SMTP verwendet werden soll. Dies sollte der FQDN deines DokuWiki Webservers sein. Wenn du es Leer lässt wird DokuWiki versuchen es selbst zu ermitteln.'; +$lang['debug'] = 'Kompletten Fehlerbericht ausgeben wenn das Versenden fehlschlägt. Deaktiviere es wenn das Versenden Funktioniert.'; diff --git a/dokuwiki/lib/plugins/smtp/lang/en/intro.txt b/dokuwiki/lib/plugins/smtp/lang/en/intro.txt new file mode 100644 index 0000000..c5d9dfd --- /dev/null +++ b/dokuwiki/lib/plugins/smtp/lang/en/intro.txt @@ -0,0 +1,5 @@ +====== SMTP Testing ====== + +This page allows you to trigger sending a test mail in DokuWiki. You can use it to check if you configured the SMTP plugin correctly. + +Give recipient's email addresses in the form below. diff --git a/dokuwiki/lib/plugins/smtp/lang/en/lang.php b/dokuwiki/lib/plugins/smtp/lang/en/lang.php new file mode 100644 index 0000000..11647e3 --- /dev/null +++ b/dokuwiki/lib/plugins/smtp/lang/en/lang.php @@ -0,0 +1,4 @@ +<?php + +$lang['menu'] = 'Check SMTP configuration'; +$lang['nofrom'] = 'You did not configure the \'mailfrom\' option. Sending mails will probably fail.'; diff --git a/dokuwiki/lib/plugins/smtp/lang/en/settings.php b/dokuwiki/lib/plugins/smtp/lang/en/settings.php new file mode 100644 index 0000000..9042c43 --- /dev/null +++ b/dokuwiki/lib/plugins/smtp/lang/en/settings.php @@ -0,0 +1,16 @@ +<?php + +$lang['smtp_host'] = 'Your outgoing SMTP server.'; +$lang['smtp_port'] = 'The port your SMTP server listens on. Usually 25. 465 for SSL.'; +$lang['smtp_ssl'] = 'What kind of encryption is used when communicating with your SMTP Server?'; // off, ssl, tls + +$lang['smtp_ssl_o_'] = 'none'; +$lang['smtp_ssl_o_ssl'] = 'SSL'; +$lang['smtp_ssl_o_tls'] = 'TLS'; + +$lang['auth_user'] = 'If authentication is required, put your user name here.'; +$lang['auth_pass'] = 'Password for the above user.'; + +$lang['localdomain'] = 'The name to be used during HELO phase of SMTP. Should be the FQDN of the webserver DokuWiki is running on. Leave empty for autodetection.'; + +$lang['debug'] = 'Print a full error log when sending fails? Disable when everything works!'; diff --git a/dokuwiki/lib/plugins/smtp/lang/eo/intro.txt b/dokuwiki/lib/plugins/smtp/lang/eo/intro.txt new file mode 100644 index 0000000..f01b1ec --- /dev/null +++ b/dokuwiki/lib/plugins/smtp/lang/eo/intro.txt @@ -0,0 +1,5 @@ +====== Testi SMTP ====== + +Tiu paĝo eksendas test-retpoŝton en DokuWiki. Tiel vi povas testi, ĉu la kromaĵo SMTP ĝuste agordiĝis. + +Indiku la retpoŝtadreson de ricevanto(j) en la formularo. diff --git a/dokuwiki/lib/plugins/smtp/lang/eo/lang.php b/dokuwiki/lib/plugins/smtp/lang/eo/lang.php new file mode 100644 index 0000000..413ee0d --- /dev/null +++ b/dokuwiki/lib/plugins/smtp/lang/eo/lang.php @@ -0,0 +1,9 @@ +<?php + +/** + * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) + * + * @author Robert Bogenschneider <bogi@uea.org> + */ +$lang['menu'] = 'Testi la agordojn de SMTP'; +$lang['nofrom'] = 'Vi ne indikis la \'mailfrom\'-opcion. Sendi retpoŝtaĵojn verŝajne malsukcesos.'; diff --git a/dokuwiki/lib/plugins/smtp/lang/eo/settings.php b/dokuwiki/lib/plugins/smtp/lang/eo/settings.php new file mode 100644 index 0000000..5108025 --- /dev/null +++ b/dokuwiki/lib/plugins/smtp/lang/eo/settings.php @@ -0,0 +1,17 @@ +<?php + +/** + * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) + * + * @author Robert Bogenschneider <bogi@uea.org> + */ +$lang['smtp_host'] = 'Via SMTP-servilo por eliranta poŝto.'; +$lang['smtp_port'] = 'La SMTP-pordego de via servilo. Kutime 25, 465 por SSL.'; +$lang['smtp_ssl'] = 'Kia ĉifrado estas uzata dum komunikado kun via SMTP-servilo?'; +$lang['smtp_ssl_o_'] = 'neniu'; +$lang['smtp_ssl_o_ssl'] = 'SSL'; +$lang['smtp_ssl_o_tls'] = 'TLS'; +$lang['auth_user'] = 'Se aŭtentikado necesas, indiku vian nomon tie.'; +$lang['auth_pass'] = 'Pasvorto por la supra uzanto.'; +$lang['localdomain'] = 'Nomo dum la HELO-fazo de SMTP. Devus esti la FQDN de la retservilo, kiun uzas DokuWiki. Lasu malplena por aŭtomata detekto.'; +$lang['debug'] = 'Ĉu presi plenan erar-logon, kiam sendado malsukcesas? Malŝaltu, kiam ĉio funkcias!'; diff --git a/dokuwiki/lib/plugins/smtp/lang/fr/intro.txt b/dokuwiki/lib/plugins/smtp/lang/fr/intro.txt new file mode 100644 index 0000000..585af8a --- /dev/null +++ b/dokuwiki/lib/plugins/smtp/lang/fr/intro.txt @@ -0,0 +1,5 @@ +====== Test de SMTP ====== + +Cette page vous permet de déclencher l'envoi d'un courriel de test depuis DokuWiki. Vous pouvez l'utiliser pour vérifier si SMTP est correctement configuré. + +Indiquez l'adresse email du destinataire dans le formulaire ci dessous. diff --git a/dokuwiki/lib/plugins/smtp/lang/fr/lang.php b/dokuwiki/lib/plugins/smtp/lang/fr/lang.php new file mode 100644 index 0000000..08d410b --- /dev/null +++ b/dokuwiki/lib/plugins/smtp/lang/fr/lang.php @@ -0,0 +1,10 @@ +<?php + +/** + * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) + * + * @author Schplurtz le Dévoulonné <Schplurtz@laposte.net> + * @author Schplurtz le Déboulonné <Schplurtz@laposte.net> + */ +$lang['menu'] = 'Vérifier la configuration de SMTP'; +$lang['nofrom'] = 'Vous n\'avez pas configuré l\'option \'De\'. L\'envoi de courriel va probablement échouer.'; diff --git a/dokuwiki/lib/plugins/smtp/lang/fr/settings.php b/dokuwiki/lib/plugins/smtp/lang/fr/settings.php new file mode 100644 index 0000000..1d68d5d --- /dev/null +++ b/dokuwiki/lib/plugins/smtp/lang/fr/settings.php @@ -0,0 +1,17 @@ +<?php + +/** + * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) + * + * @author Schplurtz le Dévoulonné <Schplurtz@laposte.net> + */ +$lang['smtp_host'] = 'Votre serveur SMTP sortant.'; +$lang['smtp_port'] = 'Port d\'écoute du serveur SMTP. Habituellement 25. 465 pour SSL'; +$lang['smtp_ssl'] = 'Type de chiffrement utilisé lors des communications avec votre serveur SMTP.'; +$lang['smtp_ssl_o_'] = 'aucun'; +$lang['smtp_ssl_o_ssl'] = 'SSL'; +$lang['smtp_ssl_o_tls'] = 'TLS'; +$lang['auth_user'] = 'SI une authentification est nécessaire, indiquez ici le nom d\'utilisateur.'; +$lang['auth_pass'] = 'Mot de passe du compte ci dessus.'; +$lang['localdomain'] = 'Nom à utiliser durant la phase HELO du protocole SMTP. Devrait être le FQDN du serveur web sur lequel DokuWiki fonctionne. Laisser vide pour une détection automatique.'; +$lang['debug'] = 'Afficher un journal d\'erreur complet en cas d\'échec d\'envoi. Désactiver lorsque tout fonctionne.'; diff --git a/dokuwiki/lib/plugins/smtp/lang/ja/intro.txt b/dokuwiki/lib/plugins/smtp/lang/ja/intro.txt new file mode 100644 index 0000000..5e627a3 --- /dev/null +++ b/dokuwiki/lib/plugins/smtp/lang/ja/intro.txt @@ -0,0 +1,6 @@ +====== SMTP 設定の確認 ====== + +このページは、DokuWiki からのテストメール送信ができます。 +SMTP プラグインの設定が正しいかどうかの確認に使用してください。 + +宛先の電子メールアドレスを下のフォームに入力して下さい。 diff --git a/dokuwiki/lib/plugins/smtp/lang/ja/lang.php b/dokuwiki/lib/plugins/smtp/lang/ja/lang.php new file mode 100644 index 0000000..9ba9c7c --- /dev/null +++ b/dokuwiki/lib/plugins/smtp/lang/ja/lang.php @@ -0,0 +1,9 @@ +<?php + +/** + * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) + * + * @author Hideaki SAWADA <chuno@live.jp> + */ +$lang['menu'] = 'SMTP 設定の確認'; +$lang['nofrom'] = '\'mailfrom\' オプションを設定していません。メール送信は、おそらく失敗します。'; diff --git a/dokuwiki/lib/plugins/smtp/lang/ja/settings.php b/dokuwiki/lib/plugins/smtp/lang/ja/settings.php new file mode 100644 index 0000000..f2596b1 --- /dev/null +++ b/dokuwiki/lib/plugins/smtp/lang/ja/settings.php @@ -0,0 +1,18 @@ +<?php + +/** + * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) + * + * @author Hideaki SAWADA <chuno@live.jp> + * @author hideaki SAWADA <chuno@live.jp> + */ +$lang['smtp_host'] = '送信 SMTP サーバー'; +$lang['smtp_port'] = 'SMTP サーバーのポート。通常は 25。SSL の場合は 465。'; +$lang['smtp_ssl'] = 'SMTP サーバーと通信する時、使用される暗号化は?'; +$lang['smtp_ssl_o_'] = 'なし'; +$lang['smtp_ssl_o_ssl'] = 'SSL'; +$lang['smtp_ssl_o_tls'] = 'TLS'; +$lang['auth_user'] = '認証が必要な場合のユーザー名'; +$lang['auth_pass'] = '上記ユーザーのパスワード'; +$lang['localdomain'] = 'SMTP の HELO フェーズ中に使用される名前。DokuWiki が稼働している Web サーバーの FQDN です。自動検出させる場合、空のままにします。'; +$lang['debug'] = '送信が失敗した場合、完全なエラーログを印刷しますか?稼働確認後、無効にして下さい!'; diff --git a/dokuwiki/lib/plugins/smtp/lang/ko/intro.txt b/dokuwiki/lib/plugins/smtp/lang/ko/intro.txt new file mode 100644 index 0000000..b70eeb7 --- /dev/null +++ b/dokuwiki/lib/plugins/smtp/lang/ko/intro.txt @@ -0,0 +1,5 @@ +====== SMTP 테스트 ====== + +이 페이지는 도쿠위키에서 테스트 메일을 보낼 수 있습니다. 올바르게 SMTP 플러그인을 설정했는지 확인하는 데 사용할 수 있습니다. + +아래 양식에서 받는 사람의 이메일 주소를 주세요. diff --git a/dokuwiki/lib/plugins/smtp/lang/ko/lang.php b/dokuwiki/lib/plugins/smtp/lang/ko/lang.php new file mode 100644 index 0000000..043e00f --- /dev/null +++ b/dokuwiki/lib/plugins/smtp/lang/ko/lang.php @@ -0,0 +1,9 @@ +<?php + +/** + * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) + * + * @author Myeongjin <aranet100@gmail.com> + */ +$lang['menu'] = 'SMTP 설정 확인'; +$lang['nofrom'] = '\'mailfrom\' 옵션이 설정되지 않았습니다. 메일 보내기는 아마 실패할 것입니다.'; diff --git a/dokuwiki/lib/plugins/smtp/lang/ko/settings.php b/dokuwiki/lib/plugins/smtp/lang/ko/settings.php new file mode 100644 index 0000000..0900665 --- /dev/null +++ b/dokuwiki/lib/plugins/smtp/lang/ko/settings.php @@ -0,0 +1,17 @@ +<?php + +/** + * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) + * + * @author Myeongjin <aranet100@gmail.com> + */ +$lang['smtp_host'] = '보내는 SMTP 서버.'; +$lang['smtp_port'] = '수신 대기하는 SMTP 서버 포트. 일반적으로 25. SSL은 465.'; +$lang['smtp_ssl'] = 'SMTP 서버와 통신할 때 어떤 종류의 암호화를 사용합니까?'; +$lang['smtp_ssl_o_'] = '없음'; +$lang['smtp_ssl_o_ssl'] = 'SSL'; +$lang['smtp_ssl_o_tls'] = 'TLS'; +$lang['auth_user'] = '인증이 필요하면, 여기에 사용자 이름을 넣으세요.'; +$lang['auth_pass'] = '위 사용자에 대한 비밀번호.'; +$lang['localdomain'] = 'SMTP의 HELO 단계에서 사용될 이름. 도쿠위키를 실행하고 있는 웹 서버가 정규화된 도메인 이름(HELO)이어야 합니다. 자동 감지를 하려면 비워 두세요.'; +$lang['debug'] = '보내기를 실패할 때 전체 오류 기록을 인쇄하겠습니까? 모든 작동이 정상이면 비활성화하세요!'; diff --git a/dokuwiki/lib/plugins/smtp/lang/nl/intro.txt b/dokuwiki/lib/plugins/smtp/lang/nl/intro.txt new file mode 100644 index 0000000..3a8aecb --- /dev/null +++ b/dokuwiki/lib/plugins/smtp/lang/nl/intro.txt @@ -0,0 +1,5 @@ +====== SMTP Test ====== + +Deze pagina laat je een test e-mail versturen in DokuWiki. Je kunt het gebruiken om te controleren of je de SMTP plugin correct hebt geconfigureerd. + +Geef een e-mailadres waarop u het bericht wilt ontvangen in het formulier hieronder. diff --git a/dokuwiki/lib/plugins/smtp/lang/nl/lang.php b/dokuwiki/lib/plugins/smtp/lang/nl/lang.php new file mode 100644 index 0000000..6d3a641 --- /dev/null +++ b/dokuwiki/lib/plugins/smtp/lang/nl/lang.php @@ -0,0 +1,9 @@ +<?php + +/** + * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) + * + * @author Gerrit Uitslag <Klapinklapin@gmail.com> + */ +$lang['menu'] = 'SMTP configuratie controleren'; +$lang['nofrom'] = 'Je hebt niet de \'mailfrom\' optie geconfigureerd. Het versturen van e-mail zal waarschijnlijk mislukken.'; diff --git a/dokuwiki/lib/plugins/smtp/lang/nl/settings.php b/dokuwiki/lib/plugins/smtp/lang/nl/settings.php new file mode 100644 index 0000000..590b40c --- /dev/null +++ b/dokuwiki/lib/plugins/smtp/lang/nl/settings.php @@ -0,0 +1,17 @@ +<?php + +/** + * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) + * + * @author Gerrit Uitslag <Klapinklapin@gmail.com> + */ +$lang['smtp_host'] = 'Je uitgaande SMTP server.'; +$lang['smtp_port'] = 'De poort waarop je SMTP server luistert. Vaak 25. 465 voor SSL.'; +$lang['smtp_ssl'] = 'Welke soort encryptie is gebruikt om te communiceren met je SMTP server?'; +$lang['smtp_ssl_o_'] = 'geen'; +$lang['smtp_ssl_o_ssl'] = 'SSL'; +$lang['smtp_ssl_o_tls'] = 'TLS'; +$lang['auth_user'] = 'Als authenticatie nodig is, moet je hier je gebruikersnaam geven.'; +$lang['auth_pass'] = 'Wachtwoord van bovenstaande gebruiker.'; +$lang['localdomain'] = 'De naam die gebruikt wordt tijdens de HELO fase van SMTP. Moet de FQDN van de webserver zijn waarop DokuWiki draait. Leeglaten voor zelfdetectie.'; +$lang['debug'] = 'Een complete foutlog weergeven als het versturen mislukt? Schakel deze optie uit als alles werkt!'; diff --git a/dokuwiki/lib/plugins/smtp/lang/no/intro.txt b/dokuwiki/lib/plugins/smtp/lang/no/intro.txt new file mode 100644 index 0000000..73c07df --- /dev/null +++ b/dokuwiki/lib/plugins/smtp/lang/no/intro.txt @@ -0,0 +1,5 @@ +====== SMTP-testing ====== + +På denne siden kan du sende ut en test-e-post fra DokuWiki. Bruk denne for å sjekke om du har installert din SMTP-utvidelse riktig. + +Sett inn mottakers e-postadresse i skjemaet nedenfor. diff --git a/dokuwiki/lib/plugins/smtp/lang/no/lang.php b/dokuwiki/lib/plugins/smtp/lang/no/lang.php new file mode 100644 index 0000000..4974dcf --- /dev/null +++ b/dokuwiki/lib/plugins/smtp/lang/no/lang.php @@ -0,0 +1,10 @@ +<?php + +/** + * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) + * + * @author Daniel Raknes <rada@jbv.no> + * @author Arne Hanssen <arne.hanssen@getmail.no> + */ +$lang['menu'] = 'Sjekk SMTP-konfigurasjonen'; +$lang['nofrom'] = 'Du har ikke konfigurerte «Avsenderadresse for automatiske e-poster». Sending av e-post vil sannsynligvis ikke virke.'; diff --git a/dokuwiki/lib/plugins/smtp/lang/no/settings.php b/dokuwiki/lib/plugins/smtp/lang/no/settings.php new file mode 100644 index 0000000..df55fdf --- /dev/null +++ b/dokuwiki/lib/plugins/smtp/lang/no/settings.php @@ -0,0 +1,18 @@ +<?php + +/** + * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) + * + * @author Daniel Raknes <rada@jbv.no> + * @author Arne Hanssen <arne.hanssen@getmail.no> + */ +$lang['smtp_host'] = 'Utgående SMTP-server.'; +$lang['smtp_port'] = 'Porten din SMTP-server lytter til. Vanligvis port 25. Port 465 brukes ved SSL.'; +$lang['smtp_ssl'] = 'Hvilken type kryptering brukes ved kommunikasjon med SMTP-serveren?'; +$lang['smtp_ssl_o_'] = 'ingen'; +$lang['smtp_ssl_o_ssl'] = 'SSL'; +$lang['smtp_ssl_o_tls'] = 'TLS'; +$lang['auth_user'] = 'Hvis autentisering er påkrevd, skriv inn brukernavnet ditt her.'; +$lang['auth_pass'] = 'Passord for brukeren over.'; +$lang['localdomain'] = 'Navnet som vil bli brukt HELO fasen av SMTP. Bør være kjørende DokuWiki-serverens FQDN (komplette domenenavn) . La feltet være blankt for autodeteksjon. '; +$lang['debug'] = 'Vise full feillogg når sending av e-post feiler? Deaktiver når alt fungerer!'; diff --git a/dokuwiki/lib/plugins/smtp/lang/ru/intro.txt b/dokuwiki/lib/plugins/smtp/lang/ru/intro.txt new file mode 100644 index 0000000..3efa6b2 --- /dev/null +++ b/dokuwiki/lib/plugins/smtp/lang/ru/intro.txt @@ -0,0 +1,5 @@ +====== Проверка протокола SMTP ====== + +На этой странице вы можете отправить тестовое сообщение из "DokuWiki". SMTP плагин покажет, где ты закосячил. + +Напишите адреса получателей электронной почты в форме ниже. \ No newline at end of file diff --git a/dokuwiki/lib/plugins/smtp/lang/ru/lang.php b/dokuwiki/lib/plugins/smtp/lang/ru/lang.php new file mode 100644 index 0000000..d77e91b --- /dev/null +++ b/dokuwiki/lib/plugins/smtp/lang/ru/lang.php @@ -0,0 +1,9 @@ +<?php + +/** + * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) + * + * @author Artem Trutko <trutko@facebook.com> + */ +$lang['menu'] = 'Проверка SMTP конфигурации'; +$lang['nofrom'] = 'Вы не указали получателя. Отправка письма вряд ли получится.'; diff --git a/dokuwiki/lib/plugins/smtp/lang/ru/settings.php b/dokuwiki/lib/plugins/smtp/lang/ru/settings.php new file mode 100644 index 0000000..fbffc5f --- /dev/null +++ b/dokuwiki/lib/plugins/smtp/lang/ru/settings.php @@ -0,0 +1,17 @@ +<?php + +/** + * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) + * + * @author Artem Trutko <trutko@facebook.com> + */ +$lang['smtp_host'] = 'Ваш SMTP-сервер исходящей почты.'; +$lang['smtp_port'] = 'Порт SMTP-сервера. Обычно 25. 465 для SSL.'; +$lang['smtp_ssl'] = 'Какой тип шифрования используется при связи с SMTP-сервером?'; +$lang['smtp_ssl_o_'] = 'ничего'; +$lang['smtp_ssl_o_ssl'] = 'SSL'; +$lang['smtp_ssl_o_tls'] = 'TLS'; +$lang['auth_user'] = 'Если требуется проверка подлинности, укажите свое имя пользователя здесь.'; +$lang['auth_pass'] = 'Пароль для указанного пользователя.'; +$lang['localdomain'] = 'Имя, которое будет использоваться во время фазы запрос helo протокола SMTP. Должно быть полное доменное имя веб-сервера "Докувики". Оставьте пустым для автоопределения.'; +$lang['debug'] = 'Отобразить полный лог ошибок при отправке сбой? Отключить, когда все работает!'; diff --git a/dokuwiki/lib/plugins/smtp/lang/sk/settings.php b/dokuwiki/lib/plugins/smtp/lang/sk/settings.php new file mode 100644 index 0000000..3631ec0 --- /dev/null +++ b/dokuwiki/lib/plugins/smtp/lang/sk/settings.php @@ -0,0 +1,22 @@ +<?php +/** + * Slovak language for the "SMTP" DokuWiki plugin + * + * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) + * @author Martin Hanula <mh.ikar@gmail.com> + */ + +$lang['smtp_host'] = 'Meno/adresa SMTP servera pre odosielanie pošty'; // eng: 'Your outgoing SMTP server.'; +$lang['smtp_port'] = 'Číslo portu, na ktorom počúva SMTP server. Väčšinou 25, resp. 465 pre SSL.'; // eng: 'The port your SMTP server listens on. Usually 25. 465 for SSL.'; +$lang['smtp_ssl'] = 'Typ šifrovania, ktorý sa používa pri komunikácii s SMTP serverom'; // eng: 'What kind of encryption is used when communicating with your SMTP Server?'; // off, ssl, tls + +$lang['smtp_ssl_o_'] = 'žiadne'; // eng: 'none'; +$lang['smtp_ssl_o_ssl'] = 'SSL'; // eng: 'SSL'; +$lang['smtp_ssl_o_tls'] = 'TLS'; // eng: 'TLS'; + +$lang['auth_user'] = 'Ak SMTP server vyžaduje autentifikáciu, použiť nasledovné meno používateľa'; // eng: 'If authentication is required, put your user name here.'; +$lang['auth_pass'] = 'Ak SMTP server vyžaduje autentifikáciu, použiť nasledovné heslo používateľa'; // eng: 'Password for the above user.'; + +$lang['localdomain'] = 'Meno použité v HELO fáze SMTP. Malo by to byť FQDN webservera, na ktorom beží DokuWiki. Pre autodetekciu nechať pole prázdne.'; // eng: 'The name to be used during HELO phase of SMTP. Should be the FQDN of the webserver DokuWiki is running on. Leave empty for autodetection.'; + +$lang['debug'] = 'Zobraziť celý chybový log keď odosielanie zlyhá? <b>Deaktivovať, ak všetko funguje!</b>'; // eng: 'Print a full error log when sending fails? Disable when everything works!'; diff --git a/dokuwiki/lib/plugins/smtp/lang/sv/intro.txt b/dokuwiki/lib/plugins/smtp/lang/sv/intro.txt new file mode 100644 index 0000000..e9c9db5 --- /dev/null +++ b/dokuwiki/lib/plugins/smtp/lang/sv/intro.txt @@ -0,0 +1,5 @@ +====== Test av SMTP ====== + +Denna sida tillåter dig att skicka ett test-e-brev via DokuWiki. Du kan använda sidan för att kontrollera om du konfigurerat SMTP korrekt. + +Fyll i mottagarens e-postadress i formuläret nedan. \ No newline at end of file diff --git a/dokuwiki/lib/plugins/smtp/lang/sv/lang.php b/dokuwiki/lib/plugins/smtp/lang/sv/lang.php new file mode 100644 index 0000000..7695baa --- /dev/null +++ b/dokuwiki/lib/plugins/smtp/lang/sv/lang.php @@ -0,0 +1,9 @@ +<?php + +/** + * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) + * + * @author Tor Härnqvist <tor@harnqvist.se> + */ +$lang['menu'] = 'Kontrollera SMTP-konfiguration'; +$lang['nofrom'] = 'Du konfigurerade inte \'mailform\'-alternativet. E-postutskick kommer troligen inte fungera.'; diff --git a/dokuwiki/lib/plugins/smtp/lang/sv/settings.php b/dokuwiki/lib/plugins/smtp/lang/sv/settings.php new file mode 100644 index 0000000..9c555a4 --- /dev/null +++ b/dokuwiki/lib/plugins/smtp/lang/sv/settings.php @@ -0,0 +1,17 @@ +<?php + +/** + * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) + * + * @author Tor Härnqvist <tor@harnqvist.se> + */ +$lang['smtp_host'] = 'Din utgående SMTP-server'; +$lang['smtp_port'] = 'Porten som din SMTP-server lyssnar på. Vanligtvis 25. 465 för SSL.'; +$lang['smtp_ssl'] = 'Vilken typ av kryptering används vid kommunikation med din SMTP-server?'; +$lang['smtp_ssl_o_'] = 'ingen'; +$lang['smtp_ssl_o_ssl'] = 'SSL'; +$lang['smtp_ssl_o_tls'] = 'TLS'; +$lang['auth_user'] = 'Om autentisering krävs, fyll i ditt användarnamn här'; +$lang['auth_pass'] = 'Lösenord för ovanstående användare.'; +$lang['localdomain'] = 'Namnet att använda för HELO-fasen av SMTP. Skall vara FQDN för webbservern som DokuWiki körs på. Lämna tomt för automatisk detektion.'; +$lang['debug'] = 'Skriv en fullständig fellogg när utskick ej fungerar. Avaktivera när allt fungerar!'; diff --git a/dokuwiki/lib/plugins/smtp/lang/zh/intro.txt b/dokuwiki/lib/plugins/smtp/lang/zh/intro.txt new file mode 100644 index 0000000..5582555 --- /dev/null +++ b/dokuwiki/lib/plugins/smtp/lang/zh/intro.txt @@ -0,0 +1,5 @@ +====== SMTP 测试 ====== + +本页面允许您从 Dokuwiki 发送测试邮件。您可以用它来检查 SMTP 插件是否已正确配置。 + +在下面的表格中填入收件人的电子邮箱。 diff --git a/dokuwiki/lib/plugins/smtp/lang/zh/lang.php b/dokuwiki/lib/plugins/smtp/lang/zh/lang.php new file mode 100644 index 0000000..e014522 --- /dev/null +++ b/dokuwiki/lib/plugins/smtp/lang/zh/lang.php @@ -0,0 +1,4 @@ +<?php + +$lang['menu'] = '检查 SMTP 配置'; +$lang['nofrom'] = '您没有配置“mailfrom”选项。邮件发送可能会失败。'; diff --git a/dokuwiki/lib/plugins/smtp/lang/zh/settings.php b/dokuwiki/lib/plugins/smtp/lang/zh/settings.php new file mode 100644 index 0000000..ac9ce47 --- /dev/null +++ b/dokuwiki/lib/plugins/smtp/lang/zh/settings.php @@ -0,0 +1,16 @@ +<?php + +$lang['smtp_host'] = '您的 SMTP 发送服务器。'; +$lang['smtp_port'] = '您的 SMTP 服务器监听端口。通常是 25,对于 SSL常是 465。'; +$lang['smtp_ssl'] = '您的 SMTP 服务器所用的加密类型?'; // off, ssl, tls + +$lang['smtp_ssl_o_'] = '无'; +$lang['smtp_ssl_o_ssl'] = 'SSL'; +$lang['smtp_ssl_o_tls'] = 'TLS'; + +$lang['auth_user'] = '如果需要认证,在这里输入您的用户名。'; +$lang['auth_pass'] = '对应上面用户名的密码。'; + +$lang['localdomain'] = '在 SMTP 握手阶段所使用的名称。应为运行 Dokuwiki 服务器的完全资格域名。留空则自动检测。'; + +$lang['debug'] = '在发送失败时显示完整的错误信息?在一切正常时请关闭!'; diff --git a/dokuwiki/lib/plugins/smtp/loader.php b/dokuwiki/lib/plugins/smtp/loader.php new file mode 100644 index 0000000..f992546 --- /dev/null +++ b/dokuwiki/lib/plugins/smtp/loader.php @@ -0,0 +1,40 @@ +<?php + +/** + * Simple PSR-4 autoloader + * + * Based on PSR-4 example code + * + * @link http://www.php-fig.org/psr/psr-4/examples/ + * @param string $class The fully-qualified class name. + * @return void + */ +spl_autoload_register(function($class) { + $namespaces = array( + 'Psr\\Log\\' => __DIR__ . '/subtree/php-fig/log/Psr/Log/', + 'Tx\\' => __DIR__ . '/subtree/txtthinking/Mailer/src/', + 'splitbrain\\dokuwiki\\plugin\\smtp\\' => __DIR__ . '/classes/' + ); + + foreach($namespaces as $prefix => $base_dir) { + // does the class use the namespace prefix? + $len = strlen($prefix); + if (strncmp($prefix, $class, $len) !== 0) { + // no, move to the next + continue; + } + + // get the relative class name + $relative_class = substr($class, $len); + + // replace the namespace prefix with the base directory, replace namespace + // separators with directory separators in the relative class name, append + // with .php + $file = $base_dir . str_replace('\\', '/', $relative_class) . '.php'; + + // if the file exists, require it + if (file_exists($file)) { + require $file; + } + } +}); diff --git a/dokuwiki/lib/plugins/smtp/plugin.info.txt b/dokuwiki/lib/plugins/smtp/plugin.info.txt new file mode 100644 index 0000000..5d1ab1f --- /dev/null +++ b/dokuwiki/lib/plugins/smtp/plugin.info.txt @@ -0,0 +1,7 @@ +base smtp +author Andreas Gohr +email andi@splitbrain.org +date 2017-08-03 +name smtp plugin +desc Send mails via a configured SMTP server +url https://www.dokuwiki.org/plugin:smtp diff --git a/dokuwiki/lib/plugins/smtp/subtree/php-fig/log/.gitignore b/dokuwiki/lib/plugins/smtp/subtree/php-fig/log/.gitignore new file mode 100644 index 0000000..22d0d82 --- /dev/null +++ b/dokuwiki/lib/plugins/smtp/subtree/php-fig/log/.gitignore @@ -0,0 +1 @@ +vendor diff --git a/dokuwiki/lib/plugins/smtp/subtree/php-fig/log/LICENSE b/dokuwiki/lib/plugins/smtp/subtree/php-fig/log/LICENSE new file mode 100644 index 0000000..474c952 --- /dev/null +++ b/dokuwiki/lib/plugins/smtp/subtree/php-fig/log/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2012 PHP Framework Interoperability Group + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/dokuwiki/lib/plugins/smtp/subtree/php-fig/log/Psr/Log/AbstractLogger.php b/dokuwiki/lib/plugins/smtp/subtree/php-fig/log/Psr/Log/AbstractLogger.php new file mode 100644 index 0000000..5a68a23 --- /dev/null +++ b/dokuwiki/lib/plugins/smtp/subtree/php-fig/log/Psr/Log/AbstractLogger.php @@ -0,0 +1,128 @@ +<?php + +namespace Psr\Log; + +/** + * This is a simple Logger implementation that other Loggers can inherit from. + * + * It simply delegates all log-level-specific methods to the `log` method to + * reduce boilerplate code that a simple Logger that does the same thing with + * messages regardless of the error level has to implement. + */ +abstract class AbstractLogger implements LoggerInterface +{ + /** + * System is unusable. + * + * @param string $message + * @param array $context + * + * @return null + */ + public function emergency($message, array $context = array()) + { + $this->log(LogLevel::EMERGENCY, $message, $context); + } + + /** + * Action must be taken immediately. + * + * Example: Entire website down, database unavailable, etc. This should + * trigger the SMS alerts and wake you up. + * + * @param string $message + * @param array $context + * + * @return null + */ + public function alert($message, array $context = array()) + { + $this->log(LogLevel::ALERT, $message, $context); + } + + /** + * Critical conditions. + * + * Example: Application component unavailable, unexpected exception. + * + * @param string $message + * @param array $context + * + * @return null + */ + public function critical($message, array $context = array()) + { + $this->log(LogLevel::CRITICAL, $message, $context); + } + + /** + * Runtime errors that do not require immediate action but should typically + * be logged and monitored. + * + * @param string $message + * @param array $context + * + * @return null + */ + public function error($message, array $context = array()) + { + $this->log(LogLevel::ERROR, $message, $context); + } + + /** + * Exceptional occurrences that are not errors. + * + * Example: Use of deprecated APIs, poor use of an API, undesirable things + * that are not necessarily wrong. + * + * @param string $message + * @param array $context + * + * @return null + */ + public function warning($message, array $context = array()) + { + $this->log(LogLevel::WARNING, $message, $context); + } + + /** + * Normal but significant events. + * + * @param string $message + * @param array $context + * + * @return null + */ + public function notice($message, array $context = array()) + { + $this->log(LogLevel::NOTICE, $message, $context); + } + + /** + * Interesting events. + * + * Example: User logs in, SQL logs. + * + * @param string $message + * @param array $context + * + * @return null + */ + public function info($message, array $context = array()) + { + $this->log(LogLevel::INFO, $message, $context); + } + + /** + * Detailed debug information. + * + * @param string $message + * @param array $context + * + * @return null + */ + public function debug($message, array $context = array()) + { + $this->log(LogLevel::DEBUG, $message, $context); + } +} diff --git a/dokuwiki/lib/plugins/smtp/subtree/php-fig/log/Psr/Log/InvalidArgumentException.php b/dokuwiki/lib/plugins/smtp/subtree/php-fig/log/Psr/Log/InvalidArgumentException.php new file mode 100644 index 0000000..67f852d --- /dev/null +++ b/dokuwiki/lib/plugins/smtp/subtree/php-fig/log/Psr/Log/InvalidArgumentException.php @@ -0,0 +1,7 @@ +<?php + +namespace Psr\Log; + +class InvalidArgumentException extends \InvalidArgumentException +{ +} diff --git a/dokuwiki/lib/plugins/smtp/subtree/php-fig/log/Psr/Log/LogLevel.php b/dokuwiki/lib/plugins/smtp/subtree/php-fig/log/Psr/Log/LogLevel.php new file mode 100644 index 0000000..9cebcac --- /dev/null +++ b/dokuwiki/lib/plugins/smtp/subtree/php-fig/log/Psr/Log/LogLevel.php @@ -0,0 +1,18 @@ +<?php + +namespace Psr\Log; + +/** + * Describes log levels. + */ +class LogLevel +{ + const EMERGENCY = 'emergency'; + const ALERT = 'alert'; + const CRITICAL = 'critical'; + const ERROR = 'error'; + const WARNING = 'warning'; + const NOTICE = 'notice'; + const INFO = 'info'; + const DEBUG = 'debug'; +} diff --git a/dokuwiki/lib/plugins/smtp/subtree/php-fig/log/Psr/Log/LoggerAwareInterface.php b/dokuwiki/lib/plugins/smtp/subtree/php-fig/log/Psr/Log/LoggerAwareInterface.php new file mode 100644 index 0000000..e84191b --- /dev/null +++ b/dokuwiki/lib/plugins/smtp/subtree/php-fig/log/Psr/Log/LoggerAwareInterface.php @@ -0,0 +1,18 @@ +<?php + +namespace Psr\Log; + +/** + * Describes a logger-aware instance. + */ +interface LoggerAwareInterface +{ + /** + * Sets a logger instance on the object. + * + * @param LoggerInterface $logger + * + * @return null + */ + public function setLogger(LoggerInterface $logger); +} diff --git a/dokuwiki/lib/plugins/smtp/subtree/php-fig/log/Psr/Log/LoggerAwareTrait.php b/dokuwiki/lib/plugins/smtp/subtree/php-fig/log/Psr/Log/LoggerAwareTrait.php new file mode 100644 index 0000000..639f79b --- /dev/null +++ b/dokuwiki/lib/plugins/smtp/subtree/php-fig/log/Psr/Log/LoggerAwareTrait.php @@ -0,0 +1,26 @@ +<?php + +namespace Psr\Log; + +/** + * Basic Implementation of LoggerAwareInterface. + */ +trait LoggerAwareTrait +{ + /** + * The logger instance. + * + * @var LoggerInterface + */ + protected $logger; + + /** + * Sets a logger. + * + * @param LoggerInterface $logger + */ + public function setLogger(LoggerInterface $logger) + { + $this->logger = $logger; + } +} diff --git a/dokuwiki/lib/plugins/smtp/subtree/php-fig/log/Psr/Log/LoggerInterface.php b/dokuwiki/lib/plugins/smtp/subtree/php-fig/log/Psr/Log/LoggerInterface.php new file mode 100644 index 0000000..16c04ad --- /dev/null +++ b/dokuwiki/lib/plugins/smtp/subtree/php-fig/log/Psr/Log/LoggerInterface.php @@ -0,0 +1,123 @@ +<?php + +namespace Psr\Log; + +/** + * Describes a logger instance. + * + * The message MUST be a string or object implementing __toString(). + * + * The message MAY contain placeholders in the form: {foo} where foo + * will be replaced by the context data in key "foo". + * + * The context array can contain arbitrary data. The only assumption that + * can be made by implementors is that if an Exception instance is given + * to produce a stack trace, it MUST be in a key named "exception". + * + * See https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md + * for the full interface specification. + */ +interface LoggerInterface +{ + /** + * System is unusable. + * + * @param string $message + * @param array $context + * + * @return null + */ + public function emergency($message, array $context = array()); + + /** + * Action must be taken immediately. + * + * Example: Entire website down, database unavailable, etc. This should + * trigger the SMS alerts and wake you up. + * + * @param string $message + * @param array $context + * + * @return null + */ + public function alert($message, array $context = array()); + + /** + * Critical conditions. + * + * Example: Application component unavailable, unexpected exception. + * + * @param string $message + * @param array $context + * + * @return null + */ + public function critical($message, array $context = array()); + + /** + * Runtime errors that do not require immediate action but should typically + * be logged and monitored. + * + * @param string $message + * @param array $context + * + * @return null + */ + public function error($message, array $context = array()); + + /** + * Exceptional occurrences that are not errors. + * + * Example: Use of deprecated APIs, poor use of an API, undesirable things + * that are not necessarily wrong. + * + * @param string $message + * @param array $context + * + * @return null + */ + public function warning($message, array $context = array()); + + /** + * Normal but significant events. + * + * @param string $message + * @param array $context + * + * @return null + */ + public function notice($message, array $context = array()); + + /** + * Interesting events. + * + * Example: User logs in, SQL logs. + * + * @param string $message + * @param array $context + * + * @return null + */ + public function info($message, array $context = array()); + + /** + * Detailed debug information. + * + * @param string $message + * @param array $context + * + * @return null + */ + public function debug($message, array $context = array()); + + /** + * Logs with an arbitrary level. + * + * @param mixed $level + * @param string $message + * @param array $context + * + * @return null + */ + public function log($level, $message, array $context = array()); +} diff --git a/dokuwiki/lib/plugins/smtp/subtree/php-fig/log/Psr/Log/LoggerTrait.php b/dokuwiki/lib/plugins/smtp/subtree/php-fig/log/Psr/Log/LoggerTrait.php new file mode 100644 index 0000000..d8c611b --- /dev/null +++ b/dokuwiki/lib/plugins/smtp/subtree/php-fig/log/Psr/Log/LoggerTrait.php @@ -0,0 +1,140 @@ +<?php + +namespace Psr\Log; + +/** + * This is a simple Logger trait that classes unable to extend AbstractLogger + * (because they extend another class, etc) can include. + * + * It simply delegates all log-level-specific methods to the `log` method to + * reduce boilerplate code that a simple Logger that does the same thing with + * messages regardless of the error level has to implement. + */ +trait LoggerTrait +{ + /** + * System is unusable. + * + * @param string $message + * @param array $context + * + * @return null + */ + public function emergency($message, array $context = array()) + { + $this->log(LogLevel::EMERGENCY, $message, $context); + } + + /** + * Action must be taken immediately. + * + * Example: Entire website down, database unavailable, etc. This should + * trigger the SMS alerts and wake you up. + * + * @param string $message + * @param array $context + * + * @return null + */ + public function alert($message, array $context = array()) + { + $this->log(LogLevel::ALERT, $message, $context); + } + + /** + * Critical conditions. + * + * Example: Application component unavailable, unexpected exception. + * + * @param string $message + * @param array $context + * + * @return null + */ + public function critical($message, array $context = array()) + { + $this->log(LogLevel::CRITICAL, $message, $context); + } + + /** + * Runtime errors that do not require immediate action but should typically + * be logged and monitored. + * + * @param string $message + * @param array $context + * + * @return null + */ + public function error($message, array $context = array()) + { + $this->log(LogLevel::ERROR, $message, $context); + } + + /** + * Exceptional occurrences that are not errors. + * + * Example: Use of deprecated APIs, poor use of an API, undesirable things + * that are not necessarily wrong. + * + * @param string $message + * @param array $context + * + * @return null + */ + public function warning($message, array $context = array()) + { + $this->log(LogLevel::WARNING, $message, $context); + } + + /** + * Normal but significant events. + * + * @param string $message + * @param array $context + * + * @return null + */ + public function notice($message, array $context = array()) + { + $this->log(LogLevel::NOTICE, $message, $context); + } + + /** + * Interesting events. + * + * Example: User logs in, SQL logs. + * + * @param string $message + * @param array $context + * + * @return null + */ + public function info($message, array $context = array()) + { + $this->log(LogLevel::INFO, $message, $context); + } + + /** + * Detailed debug information. + * + * @param string $message + * @param array $context + * + * @return null + */ + public function debug($message, array $context = array()) + { + $this->log(LogLevel::DEBUG, $message, $context); + } + + /** + * Logs with an arbitrary level. + * + * @param mixed $level + * @param string $message + * @param array $context + * + * @return null + */ + abstract public function log($level, $message, array $context = array()); +} diff --git a/dokuwiki/lib/plugins/smtp/subtree/php-fig/log/Psr/Log/NullLogger.php b/dokuwiki/lib/plugins/smtp/subtree/php-fig/log/Psr/Log/NullLogger.php new file mode 100644 index 0000000..3fc5100 --- /dev/null +++ b/dokuwiki/lib/plugins/smtp/subtree/php-fig/log/Psr/Log/NullLogger.php @@ -0,0 +1,28 @@ +<?php + +namespace Psr\Log; + +/** + * This Logger can be used to avoid conditional log calls. + * + * Logging should always be optional, and if no logger is provided to your + * library creating a NullLogger instance to have something to throw logs at + * is a good way to avoid littering your code with `if ($this->logger) { }` + * blocks. + */ +class NullLogger extends AbstractLogger +{ + /** + * Logs with an arbitrary level. + * + * @param mixed $level + * @param string $message + * @param array $context + * + * @return null + */ + public function log($level, $message, array $context = array()) + { + // noop + } +} diff --git a/dokuwiki/lib/plugins/smtp/subtree/php-fig/log/Psr/Log/Test/LoggerInterfaceTest.php b/dokuwiki/lib/plugins/smtp/subtree/php-fig/log/Psr/Log/Test/LoggerInterfaceTest.php new file mode 100644 index 0000000..06f250d --- /dev/null +++ b/dokuwiki/lib/plugins/smtp/subtree/php-fig/log/Psr/Log/Test/LoggerInterfaceTest.php @@ -0,0 +1,133 @@ +<?php + +namespace Psr\Log\Test; + +use Psr\Log\LoggerInterface; +use Psr\Log\LogLevel; + +/** + * Provides a base test class for ensuring compliance with the LoggerInterface. + * + * Implementors can extend the class and implement abstract methods to run this + * as part of their test suite. + */ +abstract class LoggerInterfaceTest extends \PHPUnit_Framework_TestCase +{ + /** + * @return LoggerInterface + */ + abstract public function getLogger(); + + /** + * This must return the log messages in order. + * + * The simple formatting of the messages is: "<LOG LEVEL> <MESSAGE>". + * + * Example ->error('Foo') would yield "error Foo". + * + * @return string[] + */ + abstract public function getLogs(); + + public function testImplements() + { + $this->assertInstanceOf('Psr\Log\LoggerInterface', $this->getLogger()); + } + + /** + * @dataProvider provideLevelsAndMessages + */ + public function testLogsAtAllLevels($level, $message) + { + $logger = $this->getLogger(); + $logger->{$level}($message, array('user' => 'Bob')); + $logger->log($level, $message, array('user' => 'Bob')); + + $expected = array( + $level.' message of level '.$level.' with context: Bob', + $level.' message of level '.$level.' with context: Bob', + ); + $this->assertEquals($expected, $this->getLogs()); + } + + public function provideLevelsAndMessages() + { + return array( + LogLevel::EMERGENCY => array(LogLevel::EMERGENCY, 'message of level emergency with context: {user}'), + LogLevel::ALERT => array(LogLevel::ALERT, 'message of level alert with context: {user}'), + LogLevel::CRITICAL => array(LogLevel::CRITICAL, 'message of level critical with context: {user}'), + LogLevel::ERROR => array(LogLevel::ERROR, 'message of level error with context: {user}'), + LogLevel::WARNING => array(LogLevel::WARNING, 'message of level warning with context: {user}'), + LogLevel::NOTICE => array(LogLevel::NOTICE, 'message of level notice with context: {user}'), + LogLevel::INFO => array(LogLevel::INFO, 'message of level info with context: {user}'), + LogLevel::DEBUG => array(LogLevel::DEBUG, 'message of level debug with context: {user}'), + ); + } + + /** + * @expectedException \Psr\Log\InvalidArgumentException + */ + public function testThrowsOnInvalidLevel() + { + $logger = $this->getLogger(); + $logger->log('invalid level', 'Foo'); + } + + public function testContextReplacement() + { + $logger = $this->getLogger(); + $logger->info('{Message {nothing} {user} {foo.bar} a}', array('user' => 'Bob', 'foo.bar' => 'Bar')); + + $expected = array('info {Message {nothing} Bob Bar a}'); + $this->assertEquals($expected, $this->getLogs()); + } + + public function testObjectCastToString() + { + $dummy = $this->getMock('Psr\Log\Test\DummyTest', array('__toString')); + $dummy->expects($this->once()) + ->method('__toString') + ->will($this->returnValue('DUMMY')); + + $this->getLogger()->warning($dummy); + + $expected = array('warning DUMMY'); + $this->assertEquals($expected, $this->getLogs()); + } + + public function testContextCanContainAnything() + { + $context = array( + 'bool' => true, + 'null' => null, + 'string' => 'Foo', + 'int' => 0, + 'float' => 0.5, + 'nested' => array('with object' => new DummyTest), + 'object' => new \DateTime, + 'resource' => fopen('php://memory', 'r'), + ); + + $this->getLogger()->warning('Crazy context data', $context); + + $expected = array('warning Crazy context data'); + $this->assertEquals($expected, $this->getLogs()); + } + + public function testContextExceptionKeyCanBeExceptionOrOtherValues() + { + $logger = $this->getLogger(); + $logger->warning('Random message', array('exception' => 'oops')); + $logger->critical('Uncaught Exception!', array('exception' => new \LogicException('Fail'))); + + $expected = array( + 'warning Random message', + 'critical Uncaught Exception!' + ); + $this->assertEquals($expected, $this->getLogs()); + } +} + +class DummyTest +{ +} diff --git a/dokuwiki/lib/plugins/smtp/subtree/php-fig/log/README.md b/dokuwiki/lib/plugins/smtp/subtree/php-fig/log/README.md new file mode 100644 index 0000000..574bc1c --- /dev/null +++ b/dokuwiki/lib/plugins/smtp/subtree/php-fig/log/README.md @@ -0,0 +1,45 @@ +PSR Log +======= + +This repository holds all interfaces/classes/traits related to +[PSR-3](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md). + +Note that this is not a logger of its own. It is merely an interface that +describes a logger. See the specification for more details. + +Usage +----- + +If you need a logger, you can use the interface like this: + +```php +<?php + +use Psr\Log\LoggerInterface; + +class Foo +{ + private $logger; + + public function __construct(LoggerInterface $logger = null) + { + $this->logger = $logger; + } + + public function doSomething() + { + if ($this->logger) { + $this->logger->info('Doing work'); + } + + // do something useful + } +} +``` + +You can then pick one of the implementations of the interface to get a logger. + +If you want to implement the interface, you can require this package and +implement `Psr\Log\LoggerInterface` in your code. Please read the +[specification text](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md) +for details. diff --git a/dokuwiki/lib/plugins/smtp/subtree/php-fig/log/composer.json b/dokuwiki/lib/plugins/smtp/subtree/php-fig/log/composer.json new file mode 100644 index 0000000..6a51765 --- /dev/null +++ b/dokuwiki/lib/plugins/smtp/subtree/php-fig/log/composer.json @@ -0,0 +1,25 @@ +{ + "name": "psr/log", + "description": "Common interface for logging libraries", + "keywords": ["psr", "psr-3", "log"], + "license": "MIT", + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "require": { + "php": ">=5.3.0" + }, + "autoload": { + "psr-4": { + "Psr\\Log\\": "Psr/Log/" + } + }, + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + } +} diff --git a/dokuwiki/lib/plugins/smtp/subtree/txtthinking/Mailer/.gitignore b/dokuwiki/lib/plugins/smtp/subtree/txtthinking/Mailer/.gitignore new file mode 100644 index 0000000..c70cc03 --- /dev/null +++ b/dokuwiki/lib/plugins/smtp/subtree/txtthinking/Mailer/.gitignore @@ -0,0 +1,4 @@ +vendor/ +composer.lock +.idea/ +docs/ diff --git a/dokuwiki/lib/plugins/smtp/subtree/txtthinking/Mailer/LICENSE b/dokuwiki/lib/plugins/smtp/subtree/txtthinking/Mailer/LICENSE new file mode 100644 index 0000000..41cb9c4 --- /dev/null +++ b/dokuwiki/lib/plugins/smtp/subtree/txtthinking/Mailer/LICENSE @@ -0,0 +1,20 @@ +The MIT License (MIT) + +Copyright (c) 2013 + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/dokuwiki/lib/plugins/smtp/subtree/txtthinking/Mailer/README.md b/dokuwiki/lib/plugins/smtp/subtree/txtthinking/Mailer/README.md new file mode 100644 index 0000000..682535f --- /dev/null +++ b/dokuwiki/lib/plugins/smtp/subtree/txtthinking/Mailer/README.md @@ -0,0 +1,51 @@ +Mailer +======= + +A lightweight SMTP mail sender + +### Install + +``` +$ composer require txthinking/mailer +``` + +### Usage + +``` +<?php +use Tx\Mailer; + +$ok = (new Mailer()) + ->setServer('smtp.ym.163.com', 25) + ->setAuth('', '') // email, password + ->setFrom('You', '') //your name, your email + ->setFakeFrom('heelo', 'bot@fake.com') // if u want, a fake name, a fake email + ->addTo('Cloud', 'cloud@txthinking.com') + ->setSubject('Test Mailer') + ->setBody('Hi, I <strong>love</strong> you.') + ->addAttachment('host', '/etc/hosts') + ->send(); +var_dump($ok); +``` +OR +``` +<?php +use \Tx\Mailer\SMTP; +use \Tx\Mailer\Message; +use \Monolog\Logger; + +$smtp = new SMTP(); // new SMTP(new Logger('Mailer')); # set logger to receive debug log +$smtp->setServer('smtp.ym.163.com', 25) + ->setAuth('bot@ym.txthinking.com', ''); // email, password + +$message = new Message(); +$message->setFrom('Tom', 'your@mail.com') // your name, your email + ->setFakeFrom('heelo', 'bot@fake.com') // if u want, a fake name, a fake email + ->addTo('Cloud', 'cloud@txthinking.com') + ->setSubject('Test Mailer') + ->setBody('<h1>For test</h1>') + ->addAttachment('host', '/etc/hosts'); + +$ok = $smtp->send($message); +var_dump($ok); +``` diff --git a/dokuwiki/lib/plugins/smtp/subtree/txtthinking/Mailer/composer.json b/dokuwiki/lib/plugins/smtp/subtree/txtthinking/Mailer/composer.json new file mode 100644 index 0000000..34390bb --- /dev/null +++ b/dokuwiki/lib/plugins/smtp/subtree/txtthinking/Mailer/composer.json @@ -0,0 +1,39 @@ +{ + "name": "txthinking/mailer", + "type": "library", + "keywords": ["mail", "smtp"], + "description": "A very lightweight PHP SMTP mail sender", + "license": "MIT", + "homepage": "http://github.com/txthinking/Mailer", + "authors": [ + { + "name": "Cloud", + "email": "cloud@txthinking.com", + "homepage": "http://www.txthinking.com", + "role": "Thinker" + }, + { + "name": "Matt Sowers", + "email": "msowers@erblearn.org" + } + ], + "require": { + "php": ">=5.3.2", + "psr/log": "~1.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.0", + "erb/testing-tools": "dev-master", + "monolog/monolog": "~1.13" + }, + "autoload": { + "psr-4": { + "Tx\\": "src/" + } + }, + "autoload-dev": { + "classmap": [ + "tests/TestCase.php" + ] + } +} diff --git a/dokuwiki/lib/plugins/smtp/subtree/txtthinking/Mailer/phpunit.xml b/dokuwiki/lib/plugins/smtp/subtree/txtthinking/Mailer/phpunit.xml new file mode 100644 index 0000000..3732559 --- /dev/null +++ b/dokuwiki/lib/plugins/smtp/subtree/txtthinking/Mailer/phpunit.xml @@ -0,0 +1,33 @@ +<?xml version="1.0" encoding="UTF-8"?> +<phpunit + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.5/phpunit.xsd" + backupGlobals="false" + backupStaticAttributes="false" + bootstrap="./vendor/autoload.php" + colors="true" + convertErrorsToExceptions="true" + convertNoticesToExceptions="true" + convertWarningsToExceptions="true" + processIsolation="false" + stopOnFailure="false" + > + <testsuites> + <testsuite name="Mailer Test Suite"> + <directory>./tests/</directory> + </testsuite> + </testsuites> + <filter> + <blacklist> + <directory suffix=".php">vendor</directory> + </blacklist> + </filter> + <logging> + <log + type="coverage-html" + target="docs/report" + lowUpperBound="35" + highLowerBound="70" + /> + </logging> +</phpunit> diff --git a/dokuwiki/lib/plugins/smtp/subtree/txtthinking/Mailer/src/Mailer.php b/dokuwiki/lib/plugins/smtp/subtree/txtthinking/Mailer/src/Mailer.php new file mode 100644 index 0000000..9226041 --- /dev/null +++ b/dokuwiki/lib/plugins/smtp/subtree/txtthinking/Mailer/src/Mailer.php @@ -0,0 +1,173 @@ +<?php namespace Tx; +/***************************************************\ + * + * Mailer (https://github.com/txthinking/Mailer) + * + * A lightweight PHP SMTP mail sender. + * Implement RFC0821, RFC0822, RFC1869, RFC2045, RFC2821 + * + * Support html body, don't worry that the receiver's + * mail client can't support html, because Mailer will + * send both text/plain and text/html body, so if the + * mail client can't support html, it will display the + * text/plain body. + * + * Create Date 2012-07-25. + * Under the MIT license. + * + \***************************************************/ + +use Psr\Log\LoggerInterface; +use \Tx\Mailer\Message; +use \Tx\Mailer\SMTP; + +/** + * Class Mailer + * + * This class provides the Mailer public methods for backwards compatibility, but it is recommended + * that you use the Tx\Mailer\SMTP and Tx\Mailer\Message classes going forward + * + * @package Tx + */ +class Mailer{ + /** + * SMTP Class + * @var SMTP + */ + protected $smtp; + + /** + * Mail Message + * @var Message + */ + protected $message; + + /** + * construct function + */ + public function __construct(LoggerInterface $logger=null){ + $this->smtp = new SMTP($logger); + $this->message = new Message(); + } + + /** + * set server and port + * @param string $host server + * @param int $port port + * @param string $secure ssl tls + * @return $this + */ + public function setServer($host, $port, $secure=null){ + $this->smtp->setServer($host, $port, $secure); + return $this; + } + + /** + * auth with server + * @param string $username + * @param string $password + * @return $this + */ + public function setAuth($username, $password){ + $this->smtp->setAuth($username, $password); + return $this; + } + + /** + * set mail from + * @param string $name + * @param string $email + * @return $this + */ + public function setFrom($name, $email){ + $this->message->setFrom($name, $email); + return $this; + } + + /** + * set fake mail from + * @param string $name + * @param string $email + * @return $this + */ + public function setFakeFrom($name, $email){ + $this->message->setFakeFrom($name, $email); + return $this; + } + + /** + * set mail receiver + * @param string $name + * @param string $email + * @return $this + */ + public function setTo($name, $email){ + $this->message->addTo($name, $email); + return $this; + } + + /** + * add mail receiver + * @param string $name + * @param string $email + * @return $this + */ + public function addTo($name, $email){ + $this->message->addTo($name, $email); + return $this; + } + + /** + * set mail subject + * @param string $subject + * @return $this + */ + public function setSubject($subject){ + $this->message->setSubject($subject); + return $this; + } + + /** + * set mail body + * @param string $body + * @return $this + */ + public function setBody($body){ + $this->message->setBody($body); + return $this; + } + + /** + * set mail attachment + * @param $name + * @param $path + * @return $this + * @internal param string $attachment + */ + public function setAttachment($name, $path){ + $this->message->addAttachment($name, $path); + return $this; + } + + /** + * add mail attachment + * @param $name + * @param $path + * @return $this + * @internal param string $attachment + */ + public function addAttachment($name, $path){ + $this->message->addAttachment($name, $path); + return $this; + } + + /** + * Send the message... + * @return boolean + */ + public function send(){ + return $this->smtp->send($this->message); + } + +} + diff --git a/dokuwiki/lib/plugins/smtp/subtree/txtthinking/Mailer/src/Mailer/Exceptions/CodeException.php b/dokuwiki/lib/plugins/smtp/subtree/txtthinking/Mailer/src/Mailer/Exceptions/CodeException.php new file mode 100644 index 0000000..4cbb792 --- /dev/null +++ b/dokuwiki/lib/plugins/smtp/subtree/txtthinking/Mailer/src/Mailer/Exceptions/CodeException.php @@ -0,0 +1,40 @@ +<?php +/***************************************************\ + * + * Mailer (https://github.com/txthinking/Mailer) + * + * A lightweight PHP SMTP mail sender. + * Implement RFC0821, RFC0822, RFC1869, RFC2045, RFC2821 + * + * Support html body, don't worry that the receiver's + * mail client can't support html, because Mailer will + * send both text/plain and text/html body, so if the + * mail client can't support html, it will display the + * text/plain body. + * + * Create Date 2012-07-25. + * Under the MIT license. + * + \***************************************************/ +/** + * Created by PhpStorm. + * User: msowers + * Date: 3/30/15 + * Time: 2:42 PM + */ + +namespace Tx\Mailer\Exceptions; + + +class CodeException extends SMTPException +{ + public function __construct($expected, $received, $serverMessage = null) + { + $message = "Unexpected return code - Expected: {$expected}, Got: {$received}"; + if (isset($serverMessage)) { + $message .= " | " . $serverMessage; + } + parent::__construct($message); + } + +} diff --git a/dokuwiki/lib/plugins/smtp/subtree/txtthinking/Mailer/src/Mailer/Exceptions/CryptoException.php b/dokuwiki/lib/plugins/smtp/subtree/txtthinking/Mailer/src/Mailer/Exceptions/CryptoException.php new file mode 100644 index 0000000..35e177d --- /dev/null +++ b/dokuwiki/lib/plugins/smtp/subtree/txtthinking/Mailer/src/Mailer/Exceptions/CryptoException.php @@ -0,0 +1,32 @@ +<?php +/***************************************************\ + * + * Mailer (https://github.com/txthinking/Mailer) + * + * A lightweight PHP SMTP mail sender. + * Implement RFC0821, RFC0822, RFC1869, RFC2045, RFC2821 + * + * Support html body, don't worry that the receiver's + * mail client can't support html, because Mailer will + * send both text/plain and text/html body, so if the + * mail client can't support html, it will display the + * text/plain body. + * + * Create Date 2012-07-25. + * Under the MIT license. + * + \***************************************************/ +/** + * Created by PhpStorm. + * User: msowers + * Date: 3/30/15 + * Time: 2:48 PM + */ + +namespace Tx\Mailer\Exceptions; + + +class CryptoException extends SMTPException +{ + +} diff --git a/dokuwiki/lib/plugins/smtp/subtree/txtthinking/Mailer/src/Mailer/Exceptions/SMTPException.php b/dokuwiki/lib/plugins/smtp/subtree/txtthinking/Mailer/src/Mailer/Exceptions/SMTPException.php new file mode 100644 index 0000000..8c3228f --- /dev/null +++ b/dokuwiki/lib/plugins/smtp/subtree/txtthinking/Mailer/src/Mailer/Exceptions/SMTPException.php @@ -0,0 +1,35 @@ +<?php +/***************************************************\ + * + * Mailer (https://github.com/txthinking/Mailer) + * + * A lightweight PHP SMTP mail sender. + * Implement RFC0821, RFC0822, RFC1869, RFC2045, RFC2821 + * + * Support html body, don't worry that the receiver's + * mail client can't support html, because Mailer will + * send both text/plain and text/html body, so if the + * mail client can't support html, it will display the + * text/plain body. + * + * Create Date 2012-07-25. + * Under the MIT license. + * + \***************************************************/ +/** + * Created by PhpStorm. + * User: msowers + * Date: 3/30/15 + * Time: 1:51 PM + */ + +namespace Tx\Mailer\Exceptions; + +class SMTPException extends \Exception +{ + public function __construct($message) + { + parent::__construct($message); + } + +} diff --git a/dokuwiki/lib/plugins/smtp/subtree/txtthinking/Mailer/src/Mailer/Exceptions/SendException.php b/dokuwiki/lib/plugins/smtp/subtree/txtthinking/Mailer/src/Mailer/Exceptions/SendException.php new file mode 100644 index 0000000..6c3aa87 --- /dev/null +++ b/dokuwiki/lib/plugins/smtp/subtree/txtthinking/Mailer/src/Mailer/Exceptions/SendException.php @@ -0,0 +1,31 @@ +<?php +/***************************************************\ + * + * Mailer (https://github.com/txthinking/Mailer) + * + * A lightweight PHP SMTP mail sender. + * Implement RFC0821, RFC0822, RFC1869, RFC2045, RFC2821 + * + * Support html body, don't worry that the receiver's + * mail client can't support html, because Mailer will + * send both text/plain and text/html body, so if the + * mail client can't support html, it will display the + * text/plain body. + * + * Create Date 2012-07-25. + * Under the MIT license. + * + \***************************************************/ +/** + * Created by PhpStorm. + * User: msowers + * Date: 3/30/15 + * Time: 1:47 PM + */ + +namespace Tx\Mailer\Exceptions; + +class SendException extends SMTPException +{ + +} diff --git a/dokuwiki/lib/plugins/smtp/subtree/txtthinking/Mailer/src/Mailer/Message.php b/dokuwiki/lib/plugins/smtp/subtree/txtthinking/Mailer/src/Mailer/Message.php new file mode 100644 index 0000000..379c458 --- /dev/null +++ b/dokuwiki/lib/plugins/smtp/subtree/txtthinking/Mailer/src/Mailer/Message.php @@ -0,0 +1,356 @@ +<?php namespace Tx\Mailer; +/***************************************************\ + * + * Mailer (https://github.com/txthinking/Mailer) + * + * A lightweight PHP SMTP mail sender. + * Implement RFC0821, RFC0822, RFC1869, RFC2045, RFC2821 + * + * Support html body, don't worry that the receiver's + * mail client can't support html, because Mailer will + * send both text/plain and text/html body, so if the + * mail client can't support html, it will display the + * text/plain body. + * + * Create Date 2012-07-25. + * Under the MIT license. + * + \***************************************************/ +class Message +{ + /** + * from name + */ + protected $fromName; + + /** + * from email + */ + protected $fromEmail; + + /** + * fake from name + */ + protected $fakeFromName; + + /** + * fake from email + */ + protected $fakeFromEmail; + + /** + * to email + */ + protected $to = array(); + + /** + * mail subject + */ + protected $subject; + + /** + * mail body + */ + protected $body; + + /** + *mail attachment + */ + protected $attachment = array(); + + /** + * message header + */ + protected $header = array(); + + /** + * charset + */ + protected $charset = "UTF-8"; + + /** + * header multipart boundaryMixed + */ + protected $boundaryMixed; + + /** + * header multipart alternative + */ + protected $boundaryAlternative; + + /** + * $this->CRLF + * @var string + */ + protected $CRLF = "\r\n"; + + /** + * set mail from + * @param string $name + * @param string $email + * @return $this + */ + public function setFrom($name, $email) + { + $this->fromName = $name; + $this->fromEmail = $email; + return $this; + } + + + /** + * set mail fake from + * @param string $name + * @param string $email + * @return $this + */ + public function setFakeFrom($name, $email) + { + $this->fakeFromName = $name; + $this->fakeFromEmail = $email; + return $this; + } + + /** + * set mail receiver + * @param string $name + * @param string $email + * @return $this + */ + public function setTo($name, $email){ + $this->to[$name] = $email; + return $this; + } + + /** + * add mail receiver + * @param string $name + * @param string $email + * @return $this + */ + public function addTo($name, $email){ + $this->to[$name] = $email; + return $this; + } + + /** + * set mail subject + * @param string $subject + * @return $this + */ + public function setSubject($subject){ + $this->subject = $subject; + return $this; + } + + /** + * set mail body + * @param string $body + * @return $this + */ + public function setBody($body){ + $this->body = $body; + return $this; + } + + /** + * add mail attachment + * @param $name + * @param $path + * @return $this + */ + public function setAttachment($name, $path){ + $this->attachment[$name] = $path; + return $this; + } + + /** + * add mail attachment + * @param $name + * @param $path + * @return $this + */ + public function addAttachment($name, $path){ + $this->attachment[$name] = $path; + return $this; + } + + /** + * @return string + */ + public function getFromName() + { + return $this->fromName; + } + + /** + * @return string + */ + public function getFromEmail() + { + return $this->fromEmail; + } + + + /** + * @return string + */ + public function getFakeFromName() + { + return $this->fakeFromName; + } + + /** + * @return string + */ + public function getFakeFromEmail() + { + return $this->fakeFromEmail; + } + + /** + * @return mixed + */ + public function getTo() + { + return $this->to; + } + + /** + * @return mixed + */ + public function getSubject() + { + return $this->subject; + } + + /** + * @return mixed + */ + public function getBody() + { + return $this->body; + } + + /** + * @return array + */ + public function getAttachment() + { + return $this->attachment; + } + + /** + * Create mail header + * @return $this + */ + protected function createHeader(){ + $this->header['Date'] = date('r'); + + if(!empty($this->fakeFromEmail)){ + $this->header['Return-Path'] = $this->fakeFromEmail; + $this->header['From'] = $this->fakeFromName . " <" . $this->fakeFromEmail . ">"; + } else{ + $this->header['Return-Path'] = $this->fromEmail; + $this->header['From'] = $this->fromName . " <" . $this->fromEmail .">"; + } + + $this->header['To'] = ''; + foreach ($this->to as $toName => $toEmail) { + $this->header['To'] .= $toName . " <" . $toEmail . ">, "; + } + $this->header['To'] = substr($this->header['To'], 0, -2); + $this->header['Subject'] = $this->subject; + $this->header['Message-ID'] = '<' . md5('TX'.md5(time()).uniqid()) . '@' . $this->fromEmail . '>'; + $this->header['X-Priority'] = '3'; + $this->header['X-Mailer'] = 'Mailer (https://github.com/txthinking/Mailer)'; + $this->header['MIME-Version'] = '1.0'; + if (!empty($this->attachment)){ + $this->boundaryMixed = md5(md5(time().'TxMailer').uniqid()); + $this->header['Content-Type'] = "multipart/mixed; \r\n\tboundary=\"" . $this->boundaryMixed . "\""; + } + $this->boundaryAlternative = md5(md5(time().'TXMailer').uniqid()); + return $this; + } + + /** + * @brief createBody create body + * + * @return string + */ + protected function createBody(){ + $in = ""; + $in .= "Content-Type: multipart/alternative; boundary=\"$this->boundaryAlternative\"" . $this->CRLF; + $in .= $this->CRLF; + $in .= "--" . $this->boundaryAlternative . $this->CRLF; + $in .= "Content-Type: text/plain; charset=\"" . $this->charset . "\"" . $this->CRLF; + $in .= "Content-Transfer-Encoding: base64" . $this->CRLF; + $in .= $this->CRLF; + $in .= chunk_split(base64_encode($this->body)) . $this->CRLF; + $in .= $this->CRLF; + $in .= "--" . $this->boundaryAlternative . $this->CRLF; + $in .= "Content-Type: text/html; charset=\"" . $this->charset ."\"" . $this->CRLF; + $in .= "Content-Transfer-Encoding: base64" . $this->CRLF; + $in .= $this->CRLF; + $in .= chunk_split(base64_encode($this->body)) . $this->CRLF; + $in .= $this->CRLF; + $in .= "--" . $this->boundaryAlternative . "--" . $this->CRLF; + return $in; + } + + /** + * @brief createBodyWithAttachment create body with attachment + * + * @return string + */ + protected function createBodyWithAttachment(){ + $in = ""; + $in .= $this->CRLF; + $in .= $this->CRLF; + $in .= '--' . $this->boundaryMixed . $this->CRLF; + $in .= "Content-Type: multipart/alternative; boundary=\"$this->boundaryAlternative\"" . $this->CRLF; + $in .= $this->CRLF; + $in .= "--" . $this->boundaryAlternative . $this->CRLF; + $in .= "Content-Type: text/plain; charset=\"" . $this->charset . "\"" . $this->CRLF; + $in .= "Content-Transfer-Encoding: base64" . $this->CRLF; + $in .= $this->CRLF; + $in .= chunk_split(base64_encode($this->body)) . $this->CRLF; + $in .= $this->CRLF; + $in .= "--" . $this->boundaryAlternative . $this->CRLF; + $in .= "Content-Type: text/html; charset=\"" . $this->charset ."\"" . $this->CRLF; + $in .= "Content-Transfer-Encoding: base64" . $this->CRLF; + $in .= $this->CRLF; + $in .= chunk_split(base64_encode($this->body)) . $this->CRLF; + $in .= $this->CRLF; + $in .= "--" . $this->boundaryAlternative . "--" . $this->CRLF; + foreach ($this->attachment as $name => $path){ + $in .= $this->CRLF; + $in .= '--' . $this->boundaryMixed . $this->CRLF; + $in .= "Content-Type: application/octet-stream; name=\"". $name ."\"" . $this->CRLF; + $in .= "Content-Transfer-Encoding: base64" . $this->CRLF; + $in .= "Content-Disposition: attachment; filename=\"" . $name . "\"" . $this->CRLF; + $in .= $this->CRLF; + $in .= chunk_split(base64_encode(file_get_contents($path))) . $this->CRLF; + } + $in .= $this->CRLF; + $in .= $this->CRLF; + $in .= '--' . $this->boundaryMixed . '--' . $this->CRLF; + return $in; + } + + public function toString(){ + $in = ''; + $this->createHeader(); + foreach ($this->header as $key => $value) { + $in .= $key . ': ' . $value . $this->CRLF; + } + if (empty($this->attachment)) { + $in .= $this->createBody(); + } else { + $in .= $this->createBodyWithAttachment(); + } + $in .= $this->CRLF . $this->CRLF . "." . $this->CRLF; + return $in; + } + +} diff --git a/dokuwiki/lib/plugins/smtp/subtree/txtthinking/Mailer/src/Mailer/SMTP.php b/dokuwiki/lib/plugins/smtp/subtree/txtthinking/Mailer/src/Mailer/SMTP.php new file mode 100644 index 0000000..e4347af --- /dev/null +++ b/dokuwiki/lib/plugins/smtp/subtree/txtthinking/Mailer/src/Mailer/SMTP.php @@ -0,0 +1,357 @@ +<?php +/***************************************************\ + * + * Mailer (https://github.com/txthinking/Mailer) + * + * A lightweight PHP SMTP mail sender. + * Implement RFC0821, RFC0822, RFC1869, RFC2045, RFC2821 + * + * Support html body, don't worry that the receiver's + * mail client can't support html, because Mailer will + * send both text/plain and text/html body, so if the + * mail client can't support html, it will display the + * text/plain body. + * + * Create Date 2012-07-25. + * Under the MIT license. + * + \***************************************************/ + +namespace Tx\Mailer; + +use Psr\Log\LoggerInterface; +use Tx\Mailer\Exceptions\CodeException; +use Tx\Mailer\Exceptions\CryptoException; +use Tx\Mailer\Exceptions\SMTPException; + +class SMTP +{ + /** + * smtp socket + */ + protected $smtp; + + /** + * smtp server + */ + protected $host; + + /** + * smtp server port + */ + protected $port; + + /** + * smtp secure ssl tls + */ + protected $secure; + + /** + * EHLO message + */ + protected $ehlo; + + /** + * smtp username + */ + protected $username; + + /** + * smtp password + */ + protected $password; + + /** + * $this->CRLF + * @var string + */ + protected $CRLF = "\r\n"; + + /** + * @var Message + */ + protected $message; + + /** + * @var LoggerInterface - Used to make things prettier than self::$logger + */ + protected $logger; + + /** + * Stack of all commands issued to SMTP + * @var array + */ + protected $commandStack = array(); + + /** + * Stack of all results issued to SMTP + * @var array + */ + protected $resultStack = array(); + + public function __construct(LoggerInterface $logger=null) + { + $this->logger = $logger; + } + + /** + * set server and port + * @param string $host server + * @param int $port port + * @param string $secure ssl tls + * @return $this + */ + public function setServer($host, $port, $secure=null) + { + $this->host = $host; + $this->port = $port; + $this->secure = $secure; + if(!$this->ehlo) $this->ehlo = $host; + $this->logger && $this->logger->debug("Set: the server"); + return $this; + } + + /** + * auth with server + * @param string $username + * @param string $password + * @return $this + */ + public function setAuth($username, $password){ + $this->username = $username; + $this->password = $password; + $this->logger && $this->logger->debug("Set: the auth"); + return $this; + } + + /** + * set the EHLO message + * @param $ehlo + * @return $this + */ + public function setEhlo($ehlo){ + $this->ehlo = $ehlo; + return $this; + } + + /** + * Send the message + * + * @param Message $message + * @return $this + * @throws CodeException + * @throws CryptoException + * @throws SMTPException + */ + public function send(Message $message){ + $this->logger && $this->logger->debug('Set: a message will be sent'); + $this->message = $message; + $this->connect() + ->ehlo(); + + if ($this->secure === 'tls'){ + $this->starttls() + ->ehlo(); + } + $this->authLogin() + ->mailFrom() + ->rcptTo() + ->data() + ->quit(); + return fclose($this->smtp); + } + + /** + * connect the server + * SUCCESS 220 + * @return $this + * @throws CodeException + * @throws SMTPException + */ + protected function connect(){ + $this->logger && $this->logger->debug("Connecting to {$this->host} at {$this->port}"); + $host = ($this->secure == 'ssl') ? 'ssl://' . $this->host : $this->host; + $this->smtp = @fsockopen($host, $this->port); + //set block mode + // stream_set_blocking($this->smtp, 1); + if (!$this->smtp){ + throw new SMTPException("Could not open SMTP Port."); + } + $code = $this->getCode(); + if ($code !== '220'){ + throw new CodeException('220', $code, array_pop($this->resultStack)); + } + return $this; + } + + /** + * SMTP STARTTLS + * SUCCESS 220 + * @return $this + * @throws CodeException + * @throws CryptoException + * @throws SMTPException + */ + protected function starttls(){ + $in = "STARTTLS" . $this->CRLF; + $code = $this->pushStack($in); + if ($code !== '220'){ + throw new CodeException('220', $code, array_pop($this->resultStack)); + } + if(!stream_socket_enable_crypto($this->smtp, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) { + throw new CryptoException("Start TLS failed to enable crypto"); + } + return $this; + } + + /** + * SMTP EHLO + * SUCCESS 250 + * @return $this + * @throws CodeException + * @throws SMTPException + */ + protected function ehlo(){ + $in = "EHLO " . $this->ehlo . $this->CRLF; + $code = $this->pushStack($in); + if ($code !== '250'){ + throw new CodeException('250', $code, array_pop($this->resultStack)); + } + return $this; + } + + /** + * SMTP AUTH LOGIN + * SUCCESS 334 + * SUCCESS 334 + * SUCCESS 235 + * @return $this + * @throws CodeException + * @throws SMTPException + */ + protected function authLogin() + { + if ($this->username === null && $this->password === null) { + // Unless the user has specifically set a username/password + // Do not try to authorize. + return $this; + } + + $in = "AUTH LOGIN" . $this->CRLF; + $code = $this->pushStack($in); + if ($code !== '334'){ + throw new CodeException('334', $code, array_pop($this->resultStack)); + } + $in = base64_encode($this->username) . $this->CRLF; + $code = $this->pushStack($in); + if ($code !== '334'){ + throw new CodeException('334', $code, array_pop($this->resultStack)); + } + $in = base64_encode($this->password) . $this->CRLF; + $code = $this->pushStack($in); + if ($code !== '235'){ + throw new CodeException('235', $code, array_pop($this->resultStack)); + } + return $this; + } + + /** + * SMTP MAIL FROM + * SUCCESS 250 + * @return $this + * @throws CodeException + * @throws SMTPException + */ + protected function mailFrom(){ + $in = "MAIL FROM:<{$this->message->getFromEmail()}>" . $this->CRLF; + $code = $this->pushStack($in); + if ($code !== '250') { + throw new CodeException('250', $code, array_pop($this->resultStack)); + } + return $this; + } + + /** + * SMTP RCPT TO + * SUCCESS 250 + * @return $this + * @throws CodeException + * @throws SMTPException + */ + protected function rcptTo(){ + foreach ($this->message->getTo() as $toEmail) { + $in = "RCPT TO:<" . $toEmail . ">" . $this->CRLF; + $code = $this->pushStack($in); + if ($code !== '250') { + throw new CodeException('250', $code, array_pop($this->resultStack)); + } + } + return $this; + } + + /** + * SMTP DATA + * SUCCESS 354 + * SUCCESS 250 + * @return $this + * @throws CodeException + * @throws SMTPException + */ + protected function data(){ + $in = "DATA" . $this->CRLF; + $code = $this->pushStack($in); + if ($code !== '354') { + throw new CodeException('354', $code, array_pop($this->resultStack)); + } + $in = $this->message->toString(); + $code = $this->pushStack($in); + if ($code !== '250'){ + throw new CodeException('250', $code, array_pop($this->resultStack)); + } + return $this; + } + + /** + * SMTP QUIT + * SUCCESS 221 + * @return $this + * @throws CodeException + * @throws SMTPException + */ + protected function quit(){ + $in = "QUIT" . $this->CRLF; + $code = $this->pushStack($in); + if ($code !== '221'){ + throw new CodeException('221', $code, array_pop($this->resultStack)); + } + return $this; + } + + protected function pushStack($string) + { + $this->commandStack[] = $string; + fputs($this->smtp, $string, strlen($string)); + $this->logger && $this->logger->debug('Sent: '. $string); + return $this->getCode(); + } + + /** + * get smtp response code + * once time has three digital and a space + * @return string + * @throws SMTPException + */ + protected function getCode() { + while ($str = fgets($this->smtp, 515)) { + $this->logger && $this->logger->debug("Got: ". $str); + $this->resultStack[] = $str; + if(substr($str,3,1) == " ") { + $code = substr($str,0,3); + return $code; + } + } + throw new SMTPException("SMTP Server did not respond with anything I recognized"); + } + +} + diff --git a/dokuwiki/lib/plugins/smtp/subtree/txtthinking/Mailer/tests/MailerTest.php b/dokuwiki/lib/plugins/smtp/subtree/txtthinking/Mailer/tests/MailerTest.php new file mode 100644 index 0000000..e2bbd75 --- /dev/null +++ b/dokuwiki/lib/plugins/smtp/subtree/txtthinking/Mailer/tests/MailerTest.php @@ -0,0 +1,51 @@ +<?php + +use \Tx\Mailer; +use \Tx\Mailer\SMTP; +use \Tx\Mailer\Message; +use \Tx\Mailer\Exceptions\SMTPException; +use \Monolog\Logger; + +class MailerTest extends TestCase { + + protected $smtp; + protected $message; + + public function setup(){ + $this->smtp = new SMTP(new Logger('SMTP')); + $this->message = new Message(); + } + + public function testSMTP(){ + $this->smtp + ->setServer('smtp.ym.163.com', 25) + ->setAuth('bot@ym.txthinking.com', ''); // email, password + + $this->message + ->setFrom('Tom', 'bot@ym.txthinking.com') // your name, your email + ->setFakeFrom('heelo', 'bot@hello.com') // a fake name, a fake email + ->addTo('Cloud', 'cloud@txthinking.com') + ->setSubject('Test SMTP ' . time()) + ->setBody('<h1>for test</h1>') + ->addAttachment('host', '/etc/hosts'); + + $status = $this->smtp->send($this->message); + $this->assertTrue($status); + } + + public function testSend(){ + $status = (new Mailer(new Logger('Mailer'))) + ->setServer('smtp.ym.163.com', 25) + ->setAuth('bot@ym.txthinking.com', '') // email, password + ->setFrom('Tom', 'bot@ym.txthinking.com') // your name, your email + ->setFakeFrom('张全蛋', 'zhangquandan@hello.com') // a fake name, a fake email + ->addTo('Cloud', 'cloud@txthinking.com') + ->setSubject('hello '. time()) + ->setBody('Hi, boy') + ->addAttachment('host', '/etc/hosts') + ->send(); + $this->assertTrue($status); + } + +} + diff --git a/dokuwiki/lib/plugins/smtp/subtree/txtthinking/Mailer/tests/SMTPTest.php b/dokuwiki/lib/plugins/smtp/subtree/txtthinking/Mailer/tests/SMTPTest.php new file mode 100644 index 0000000..de257ac --- /dev/null +++ b/dokuwiki/lib/plugins/smtp/subtree/txtthinking/Mailer/tests/SMTPTest.php @@ -0,0 +1,90 @@ +<?php +/** + * Created by PhpStorm. + * User: msowers + * Date: 3/31/15 + * Time: 10:57 AM + */ + +use Tx\Mailer\SMTP; +use Tx\Mailer\Message; +use ERB\Testing\Tools\TestHelper; + +/** + * Class SMTPTest + * @package Tests + * + * This test set requires the use of an open SMTP server mock. Currently, I'm using FakeSMTPServer + * + */ +class SMTPTest extends TestCase { + + /** + * @var SMTP + */ + protected $smtp; + + /** + * @var TestHelper + */ + protected $testHelper; + + public function setup() + { + $this->smtp = new SMTP(); + $this->testHelper = new TestHelper(); + + } + + public function testSetServer() + { + $result = $this->smtp->setServer("localhost", "25", null); + $this->assertEquals('localhost', $this->testHelper->getPropertyValue($this->smtp, 'host')); + $this->assertEquals('25', $this->testHelper->getPropertyValue($this->smtp, 'port')); + $this->assertSame($this->smtp, $result); + } + + public function testSetAuth() + { + $result = $this->smtp->setAuth('none', 'none'); + + $this->assertEquals('none', $this->testHelper->getPropertyValue($this->smtp, 'username')); + $this->assertEquals('none', $this->testHelper->getPropertyValue($this->smtp, 'password')); + $this->assertSame($this->smtp, $result); + } + + public function testMessage() + { + $this->smtp->setServer("localhost", "25", null) + ->setAuth('none', 'none'); + + $message = new Message(); + $message->setFrom('You', 'nobody@nowhere.no') + ->setTo('Them', 'them@nowhere.no') + ->setSubject('This is a test') + ->setBody('This is a test part two'); + + $status = $this->smtp->send($message); + $this->assertTrue($status); + } + + + /** + * @expectedException \Tx\Mailer\Exceptions\SMTPException + */ + public function testConnectSMTPException() + { + $this->smtp->setServer("localhost", "99999", null) + ->setAuth('none', 'none'); + $message = new Message(); + $message->setFrom('You', 'nobody@nowhere.no') + ->setTo('Them', 'them@nowhere.no') + ->setSubject('This is a test') + ->setBody('This is a test part two'); + + $this->smtp->send($message); + + } + + +} diff --git a/dokuwiki/lib/plugins/smtp/subtree/txtthinking/Mailer/tests/TestCase.php b/dokuwiki/lib/plugins/smtp/subtree/txtthinking/Mailer/tests/TestCase.php new file mode 100644 index 0000000..d3479f4 --- /dev/null +++ b/dokuwiki/lib/plugins/smtp/subtree/txtthinking/Mailer/tests/TestCase.php @@ -0,0 +1,5 @@ +<?php +// someday if you want do init action before testing +class TestCase extends \PHPUnit_Framework_TestCase{ +} +
« previous php.webmaster (#26625) next »