Skip to content

Commit

Permalink
Final Merge - Version 1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
soup-bowl authored Jan 23, 2022
2 parents a91a6c5 + 936a237 commit 2946c9d
Show file tree
Hide file tree
Showing 16 changed files with 246 additions and 29 deletions.
4 changes: 4 additions & 0 deletions .docker/quickstart.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ fi
if [ "$1" == "beta" ]; then
wp core update --version=nightly --allow-root
fi

wp plugin install wp-crontrol --allow-root

wp plugin activate simple-smtp wp-crontrol --allow-root
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ Steps to reproduce the behavior:
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.
If applicable, add screenshots to help explain your problem.
14 changes: 14 additions & 0 deletions .github/ISSUE_TEMPLATE/smtp_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
name: Report missing/incorrect SMTP settings
about: Report issues with the Quick Config SMTP chooser.
title: ''
labels: smtp-setting
assignees: ''

---

**Is this a new suggestion or an edit to an existing option?**


**What is your update/replacement suggestion?**

4 changes: 3 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
name: Per-commit CI Test
on:
push:
branches: [ main ]
branches:
- main
- develop
workflow_dispatch:

jobs:
Expand Down
23 changes: 9 additions & 14 deletions assets/smtp-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,10 @@ const { __, _x, _n, _nx } = wp.i18n;
*/
function wpss_loadin() {
if ( null !== document.getElementById( 'wpss-conf' ) ) {
jQuery.getJSON(
"https://www.soupbowl.io/wp-json/wprass/v1/sources",
function( data ) {
wpss_load_quicksettings( data );
document.getElementById( 'wpss-quickset' ).onchange = function( stuff ) {
wpss_input_selection( data, stuff.target.value );
};
}
);
wpss_load_quicksettings( wpss_qc_settings );
document.getElementById( 'wpss-quickset' ).onchange = function( stuff ) {
wpss_input_selection( wpss_qc_settings, stuff.target.value );
};
}
}

Expand All @@ -47,10 +42,10 @@ function wpss_load_quicksettings( data ) {
selector_c1.outerHTML = "<th scope=\"row\">" + __( 'Quick Config', 'simple-smtp' ) + "</th>";

// Content cell.
var datacount = data.configurations.length;
var datacount = data.length;
options += '<option>' + __( 'Select', 'simple-smtp' ) + '</option>';
for (i = 0; i < datacount; i++) {
options += '<option>' + data.configurations[i].name + '</option>';
options += '<option>' + data[i].name + '</option>';
}
selector.innerHTML = options;
selector_c2.appendChild( selector );
Expand All @@ -69,10 +64,10 @@ function wpss_load_quicksettings( data ) {
*/
function wpss_input_selection( data, name ) {
var s = null;
var c = data.configurations.length;
var c = data.length;
for (i = 0; i < c; i++) {
if ( data.configurations[i].name == name ) {
s = data.configurations[i];
if ( data[i].name == name ) {
s = data[i];
break;
}
}
Expand Down
1 change: 1 addition & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/squizlabs/PHP_CodeSniffer/master/phpcs.xsd">
<exclude-pattern>/vendor/*</exclude-pattern>
<exclude-pattern>/.docker/*</exclude-pattern>
<rule ref="WordPress" />

<!-- Argh, this... Please let me know if I'm doing something wrong. -->
Expand Down
24 changes: 21 additions & 3 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@
Contributors: soupbowl
Tags: mail,email,smtp,dispatch,sender
Requires at least: 4.9
Tested up to: 5.8
Tested up to: 5.9
Requires PHP: 7.0
Stable tag: 1.2.3
Stable tag: 1.3
License: MIT

Adds a simple mail configuration panel into your WordPress installation. Supports logging and config variables.
Adds a simple mail configuration panel into your WordPress installation. Supports temporary logging and config variables.

== Description ==
Adds a simple, no-fuss SMTP settings to your WordPress installation that lets you define custom settings, which is especially useful for hosts with no control over the php `mail` functionality.

If logging is enabled, a new segment in the settings panel will show up with a 30-day overview of recent emails, and will automatically prune older logs. Please see the FAQ if you want a more permanent solution.

## Environment and constant overriding (optional)
This plugin will prefer environmental and constant-stored values over the plugin-saved equivalent settings, making it easier to use this plugin via deployment.

Expand Down Expand Up @@ -52,6 +54,13 @@ The over-ride hierachy is as follows, with top being the most important.
* Multisite network settings.
* Locally-configured settings.

= How do I stop the logs from automatically purging? =
The logs by default will auto-prune to avoid keeping sensitive details in logs and contributing to database bloat. But if you wish to keep the logs more permanently, then register the following hook (typically in your theme functions.php) to disable the auto-pruning functionality:

```
add_filter( 'simple_smtp_disable_log_prune', '__return_true' );
```

= How is the SMTP password stored? =
If openssl is available to PHP, then the password will be **encrypted** ([not hashed](https://stackoverflow.com/a/4948393)) when stored in the database. If unavailable, the SMTP password will be saved into the database as **plaintext**. The more recommended way of storing the password is to define SMTP_PASS in your wp-config.php file, which should already be locked and inaccessible from the front-end.

Expand Down Expand Up @@ -83,6 +92,15 @@ To help diagnose disabled input boxes, when the WordPress site is in [debugging
Yes! [Please see our GitHub repository here](https://github.com/soup-bowl/wp-simple-smtp) for writing issues and/or making pull requests.

== Changelog ==
= 1.3 =
* Added: Read logged emails via WP-CLI.
* Added: Status message from testing emails ([#81](https://github.com/soup-bowl/wp-simple-smtp/issues/81)).
* Change: Uninstalling the plugin will remove the lingering logs ([#70](https://github.com/soup-bowl/wp-simple-smtp/issues/70)).
* Change: (For new installs) logs purge automatically after a month ([#71](https://github.com/soup-bowl/wp-simple-smtp/issues/71)).
* Change: Quick config settings now contained within plugin ([#78](https://github.com/soup-bowl/wp-simple-smtp/issues/78)).
* Change: Tightened permissions to the log viewer ([#74](https://github.com/soup-bowl/wp-simple-smtp/issues/74)).
* Fix: Incorrect capability type used by the log viewer. Thanks to [Benoît Chantre](https://github.com/benoitchantre) [#74](https://github.com/soup-bowl/wp-simple-smtp/issues/74).

= 1.2.3 =
* Add: [WordPress CLI](https://wp-cli.org/) support. See the FAQ for usage details.
* Change: Password not returned plaintext in settings ([#61](https://github.com/soup-bowl/wp-simple-smtp/issues/61)).
Expand Down
26 changes: 25 additions & 1 deletion src/cli/class-emaillog.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,37 @@ public function load_log( $args, $assoc_args ) {
}
}

/**
* Displays the contents of an email.
*
* <ID>
* : ID of the email you wish to load up.
*
* @when before_wp_load
*
* @param array $args Command-line arguments.
* @param array $assoc_args Associated arguments.
*/
public function view_email( $args, $assoc_args ) {
$email = $this->log_service->get_log_entry_by_id( (int) $args[0] );
if ( ! empty( $email ) ) {
WP_CLI::line( 'Recipient(s): ' . implode( ', ', $email->get_recipients() ) );
WP_CLI::line( 'Subject: ' . $email->get_subject() );
WP_CLI::line( 'Headers: ' . implode( ', ', $email->get_headers() ) );
WP_CLI::line( 'Contents:' );
WP_CLI::line( $email->get_body() );
} else {
WP_CLI::error( __( 'Email not found.', 'simple-smtp' ) );
}
}

/**
* Generates a CLI output list of entries derrived from the input.
*
* @param Log[] $entries Log entry collection.
* @return void Prints the log to the page.
*/
public function list( $entries ) {
private function list( $entries ) {
$list_format = [];
foreach ( $entries as $entry ) {
$list_format[] = [
Expand Down
4 changes: 2 additions & 2 deletions src/cli/class-emailtest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ public function test_email( $args, $assoc_args ) {
$is_sent = wp_mail( $recipient, $email['subject'], $email['message'], $email['headers'] );

if ( $is_sent ) {
WP_CLI::success( __( 'Test email sent!', 'simple-smtp' ) );
WP_CLI::success( __( 'Test email sent successfully.', 'simple-smtp' ) );
} else {
WP_CLI::error( __( 'Email failed to send. Check the logs to see what happened.', 'simple-smtp' ) );
WP_CLI::error( __( 'Test email failed. Please check your configuration and try again.', 'simple-smtp' ) );
}
} else {
WP_CLI::error( __( 'Email address provided is invalid.', 'simple-smtp' ) );
Expand Down
42 changes: 40 additions & 2 deletions src/log/class-logservice.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,21 @@ public function __construct() {
* Register the log storage CPT within WordPress.
*/
public function register_log_storage() {
register_post_type( $this->post_type );
register_post_type(
$this->post_type,
[
'capabilities' => [
'publish_posts' => 'manage_options',
'edit_others_posts' => 'manage_options',
'delete_posts' => 'manage_options',
'delete_others_posts' => 'manage_options',
'read_private_posts' => 'manage_options',
'edit_post' => 'manage_options',
'delete_post' => 'manage_options',
'read_post' => 'manage_options',
],
]
);
}

/**
Expand Down Expand Up @@ -191,6 +205,30 @@ public function delete_all_logs() {
return true;
}

/**
* Prunes the log collection based on the specified time interval.
*
* @param integer $int_time_diff After this UNIX timeframe difference will be removed.
* @return boolean
*/
public function prune_logs( $int_time_diff ) {
$all = get_posts(
array(
'post_type' => $this->post_type,
'numberposts' => -1,
'date_query' => [
'before' => gmdate( 'Y-m-d', ( time() - $int_time_diff ) ),
],
)
);

foreach ( $all as $log ) {
wp_delete_post( $log->ID );
}

return true;
}

/**
* Deletes all log entries relating to a certain email address.
*
Expand Down Expand Up @@ -228,7 +266,7 @@ public function delete_all_logs_to_email( $email ) {
* @return Log
*/
private function wp_to_obj( $post ) {
if ( empty( $post ) ) {
if ( empty( $post ) || $this->post_type !== $post->post_type ) {
return null;
}

Expand Down
13 changes: 10 additions & 3 deletions src/mail/class-mailtest.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,16 @@ public static function test_email_handler() {
$recipients[ $i ] = sanitize_email( trim( $recipients[ $i ] ) );
}

wp_mail( $recipients, $email['subject'], $email['message'], $email['headers'] );

wp_safe_redirect( admin_url( 'options-general.php?page=wpsimplesmtp' ) );
$success = wp_mail( $recipients, $email['subject'], $email['message'], $email['headers'] );

wp_safe_redirect(
add_query_arg(
[
'status' => ( $success ) ? 'pass' : 'fail',
],
admin_url( 'options-general.php?page=wpsimplesmtp' )
)
);
exit;
} else {
wp_die( esc_attr_e( 'You are not permitted to send a test email.', 'simple-smtp' ) );
Expand Down
2 changes: 1 addition & 1 deletion src/settings/class-mailview.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function render_email_view( $id ) {
menu_page_url( 'wpsimplesmtp', false )
) . '&resend';

if ( current_user_can( 'administrator' ) && isset( $log ) ) {
if ( current_user_can( 'manage_options' ) && isset( $log ) ) {
$recipients = implode( ', ', $log->get_recipients() );
$date = gmdate( get_option( 'time_format' ) . ', ' . get_option( 'date_format' ), strtotime( $log->get_timestamp() ) );

Expand Down
66 changes: 66 additions & 0 deletions src/settings/class-quickconfig.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php
/**
* Simple email configuration within WordPress.
*
* @package sb-simple-smtp
* @author soup-bowl <[email protected]>
* @license MIT
*/

namespace wpsimplesmtp;

/**
* Configuration applicable to the quick config segment.
*/
class QuickConfig {
/**
* Returns an array of possible SMTP configuration options.
*
* @return array
*/
public static function settings() {
return [
[
'name' => 'Gmail',
'server' => 'smtp.gmail.com',
'port' => '587',
'authentication' => true,
'encryption' => 'tls',
],
[
'name' => 'Microsoft Exchange',
'server' => 'smtp.office365.com',
'port' => '587',
'authentication' => true,
'encryption' => 'tls',
],
[
'name' => 'SendGrid',
'server' => 'smtp.sendgrid.net',
'port' => '587',
'authentication' => true,
'user' => 'apikey',
'encryption' => 'tls',
],
[
'name' => 'Pepipost',
'server' => 'smtp.pepipost.com',
'port' => '587',
'authentication' => true,
],
[
'name' => 'SendinBlue',
'server' => 'smtp-relay.sendinblue.com',
'port' => '587',
'authentication' => true,
],
[
'name' => 'Amazon SES',
'server' => 'email-smtp.<CHANGE>.amazonaws.com',
'port' => '465',
'authentication' => true,
'encryption' => 'tls',
],
];
}
}
17 changes: 17 additions & 0 deletions src/settings/class-singular.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,23 @@ private function render_settings() {
<?php if ( $this->can_edit_settings( 'wpssmtp_disable_settings' ) ) : ?>
<form id='wpss-conf' action='options.php' method='post'>
<?php
if ( ! empty( $_REQUEST['status'] ) ) {
$has_pass = ( 'pass' === $_REQUEST['status'] ) ? true : false;
$notice_level = ( $has_pass ) ? 'notice-success' : 'notice-error';
$notice = ( $has_pass ) ? __( 'Test email sent successfully.', 'simple-smtp' ) : __( 'Test email failed. Please check your configuration and try again.', 'simple-smtp' );

echo wp_kses(
"<div class='notice is-dismissible {$notice_level}'><p><strong>{$notice}</strong></p></div>",
[
'div' => [
'class' => [],
],
'p' => [],
'strong' => [],
]
);
}

settings_fields( 'wpsimplesmtp_smtp' );
do_settings_sections( 'wpsimplesmtp_smtp' );
submit_button();
Expand Down
7 changes: 7 additions & 0 deletions tests/log/class-logservice-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ class WP_Post {
* @var string
*/
public $post_content = 'Example Content';

/**
* Post Type.
*
* @var string
*/
public $post_type = 'sbss_email_log';
}

/**
Expand Down
Loading

0 comments on commit 2946c9d

Please sign in to comment.