Skip to content

Commit 308abda

Browse files
committed
Initial commit.
(Not finished yet).
0 parents  commit 308abda

File tree

4 files changed

+210
-0
lines changed

4 files changed

+210
-0
lines changed

assets/config.yml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
##\
2+
# This file is a part of the phpMussel\PHPMailer package.
3+
# Homepage: https://phpmussel.github.io/
4+
#
5+
# PHPMUSSEL COPYRIGHT 2013 AND BEYOND BY THE PHPMUSSEL TEAM.
6+
#
7+
# License: GNU/GPLv2
8+
# @see LICENSE.txt
9+
#
10+
# This file: Configuration defaults file (last modified: 2020.06.14).
11+
##/
12+
13+
phpmailer:
14+
event_log:
15+
type: "string"
16+
default: ""
17+
enable_two_factor:
18+
type: "bool"
19+
default: false
20+
enable_notifications:
21+
type: "bool"
22+
default: false
23+
skip_auth_process:
24+
type: "bool"
25+
default: false
26+
host:
27+
type: "string"
28+
default: ""
29+
port:
30+
type: "int"
31+
default: 587
32+
smtp_secure:
33+
type: "string"
34+
default: "default"
35+
choices:
36+
default: "-"
37+
tls: "TLS"
38+
ssl: "SSL"
39+
smtp_auth:
40+
type: "bool"
41+
default: true
42+
username:
43+
type: "string"
44+
default: ""
45+
autocomplete: "username"
46+
password:
47+
type: "string"
48+
default: ""
49+
autocomplete: "current-password"
50+
set_from_address:
51+
type: "email"
52+
default: ""
53+
autocomplete: "email"
54+
set_from_name:
55+
type: "string"
56+
default: ""
57+
autocomplete: "name"
58+
add_reply_to_address:
59+
type: "email"
60+
default: ""
61+
autocomplete: "email"
62+
add_reply_to_name:
63+
type: "string"
64+
default: ""
65+
autocomplete: "name"

composer.json

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"name": "phpmussel/phpmailer",
3+
"description": "Uses PHPMailer to provide 2FA and email notifications support for phpMussel v3+",
4+
"homepage": "https://phpmussel.github.io/",
5+
"license": "GPL-2.0-or-later",
6+
"support": {
7+
"chat": "https://gitter.im/phpMussel2/Lobby",
8+
"issues": "https://github.com/phpMussel/Plugin-PHPMailer/issues",
9+
"source": "https://github.com/phpMussel/Plugin-PHPMailer",
10+
"docs": "https://github.com/phpMussel/Docs"
11+
},
12+
"require": {
13+
"php": ">=7.2.0",
14+
"maikuolan/common": "^2.3",
15+
"phpmussel/core": "^3.0",
16+
"phpmailer/phpmailer": "^3.0"
17+
},
18+
"suggest": {
19+
"phpmussel/frontend": "^3.0",
20+
"phpmussel/web": "^3.0"
21+
},
22+
"require-dev": {
23+
"codeception/codeception": "^2.3",
24+
"symfony/event-dispatcher": "3.4.28"
25+
},
26+
"autoload": {
27+
"psr-4": {
28+
"phpMussel\\PHPMailer\\": "src/"
29+
}
30+
},
31+
"autoload-dev": {
32+
"psr-4": {
33+
"phpMussel\\PHPMailer\\Tests\\": "tests/"
34+
}
35+
}
36+
}

l10n/en.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
##\
2+
# This file is a part of the phpMussel\PHPMailer package.
3+
# Homepage: https://phpmussel.github.io/
4+
#
5+
# PHPMUSSEL COPYRIGHT 2013 AND BEYOND BY THE PHPMUSSEL TEAM.
6+
#
7+
# License: GNU/GPLv2
8+
# @see LICENSE.txt
9+
#
10+
# This file: English language data (last modified: 2020.06.14).
11+
##/
12+
13+
Apples:
14+
- "There is %s apple on the tree."
15+
- "There are %s apples on the tree."
16+
Foo: "Bar"
17+
Hello: "World"

src/PHPMailer.php

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<?php
2+
/**
3+
* This file is a part of the phpMussel\PHPMailer package.
4+
* Homepage: https://phpmussel.github.io/
5+
*
6+
* PHPMUSSEL COPYRIGHT 2013 AND BEYOND BY THE PHPMUSSEL TEAM.
7+
*
8+
* License: GNU/GPLv2
9+
* @see LICENSE.txt
10+
*
11+
* This file: PHPMailer-phpMussel linker (last modified: 2020.06.14).
12+
*/
13+
14+
namespace phpMussel\PHPMailer;
15+
16+
class PHPMailer
17+
{
18+
/**
19+
* @var \phpMussel\Core\Loader The instantiated loader object.
20+
*/
21+
private $Loader;
22+
23+
/**
24+
* @var string The path to the core asset files.
25+
*/
26+
private $AssetsPath = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'assets' . DIRECTORY_SEPARATOR;
27+
28+
/**
29+
* @var string The path to the core L10N files.
30+
*/
31+
private $L10NPath = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'l10n' . DIRECTORY_SEPARATOR;
32+
33+
/**
34+
* Construct the linker instance.
35+
*
36+
* @param \phpMussel\Core\Loader $Loader The instantiated loader object, passed by reference.
37+
*/
38+
public function __construct(\phpMussel\Core\Loader &$Loader)
39+
{
40+
/** Link the loader to this instance. */
41+
$this->Loader = &$Loader;
42+
43+
/** Load configuration defaults and perform fallbacks. */
44+
if (
45+
is_readable($this->AssetsPath . 'config.yml') &&
46+
$Configuration = $this->Loader->readFile($this->AssetsPath . 'config.yml')
47+
) {
48+
$Defaults = [];
49+
$this->Loader->YAML->process($Configuration, $Defaults);
50+
if (isset($Defaults)) {
51+
$this->Loader->fallback($Defaults);
52+
}
53+
}
54+
55+
/** Load L10N data. */
56+
$this->Loader->loadL10N($this->Loader->L10NPath);
57+
58+
/**
59+
* Writes to the PHPMailer event log.
60+
*
61+
* @param string $Data What to write.
62+
* @return bool True on success; False on failure.
63+
*/
64+
$this->Loader->Events->addHandler('writeToPHPMailerEventLog', function (string $Data): bool {
65+
/** Guard. */
66+
if (!$this->Loader->Configuration['phpmailer']['event_log']) {
67+
return false;
68+
}
69+
70+
/** Applies formatting for dynamic log filenames. */
71+
$EventLog = $this->Loader->timeFormat($this->Loader->Time, $this->Loader->Configuration['phpmailer']['event_log']);
72+
73+
$WriteMode = (!file_exists($this->AssetsPath . $EventLog) || (
74+
$this->Loader->Configuration['core']['truncate'] > 0 &&
75+
filesize($this->AssetsPath . $EventLog) >= $this->readBytes($this->Loader->Configuration['core']['truncate'])
76+
)) ? 'w' : 'a';
77+
78+
/** Build the path to the log and write it. */
79+
if ($phpMussel['BuildLogPath']($EventLog)) {
80+
$Handle = fopen($this->AssetsPath . $EventLog, $WriteMode);
81+
fwrite($Handle, $Data);
82+
fclose($Handle);
83+
if ($WriteMode === 'w') {
84+
$phpMussel['LogRotation']($this->Loader->Configuration['phpmailer']['event_log']);
85+
}
86+
return true;
87+
}
88+
89+
return false;
90+
});
91+
}
92+
}

0 commit comments

Comments
 (0)