Skip to content

Commit

Permalink
Merge pull request #127 from soup-bowl/release
Browse files Browse the repository at this point in the history
Release version 1.3.2
  • Loading branch information
soup-bowl authored Oct 1, 2022
2 parents c3d844b + 0d13824 commit 870692f
Show file tree
Hide file tree
Showing 18 changed files with 243 additions and 22 deletions.
14 changes: 14 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.233.0/containers/ubuntu
{
"name": "Ubuntu",
"image" : "mcr.microsoft.com/vscode/devcontainers/base:0-jammy",
"settings": {},
"extensions": [],
"forwardPorts": [ 8080, 8081, 8082, 8083 ],
"postCreateCommand": "./.devcontainer/postCreateCommand.sh",
"postStartCommand": "./.devcontainer/postStartCommand.sh",
"features": {
"docker-in-docker": "latest"
}
}
15 changes: 15 additions & 0 deletions .devcontainer/postCreateCommand.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash
if [ ! -z ${GITPOD_HOST+x} ]; then
WP_SITE_URL="https://8080-${GITPOD_WORKSPACE_ID}.${GITPOD_WORKSPACE_CLUSTER_HOST}"
elif [ ! -z ${CODESPACE_NAME+x} ]; then
WP_SITE_URL="https://${CODESPACE_NAME}-8080.githubpreview.dev"
else
WP_SITE_URL="http://localhost:8080"
fi

docker run --rm --tty --volume $PWD:/app --user $(id -u):$(id -g) composer install --ignore-platform-reqs
docker-compose up -d
echo "Pausing for MySQL to complete..." && sleep 30
docker-compose exec www wp core install --url="${WP_SITE_URL}" --title="SMTP Dummy" --admin_user="admin" --admin_password="password" --admin_email="[email protected]" --allow-root
docker-compose exec www wp plugin activate simple-smtp --allow-root
cp .env.example .env
2 changes: 2 additions & 0 deletions .devcontainer/postStartCommand.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
docker-compose up -d
1 change: 1 addition & 0 deletions .distignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/.devcontainer
/.docker
/.git
/.github
Expand Down
4 changes: 3 additions & 1 deletion .docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
FROM docker.io/wordpress:php7.4-apache

RUN apt-get update && apt-get install less
RUN apt-get -y update && apt-get -y --no-install-recommends install less \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

RUN curl https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar --output /usr/bin/wp \
&& chmod +X /usr/bin/wp \
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/smtp_report.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
name: Report missing/incorrect SMTP settings
name: Report new, missing or incorrect SMTP settings
about: Report issues with the Quick Config SMTP chooser.
title: ''
labels: smtp-setting
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ jobs:
dev: no
args: --profile --ignore-platform-reqs
- name: WordPress Plugin Deploy
id: deploy
uses: 10up/action-wordpress-plugin-deploy@stable
with:
generate-zip: true
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ on:
branches:
- main
- develop
paths-ignore:
- '.devcontainer/**'
- '.docker/**'
- '.github/**'
- '.vscode/**'
pull_request:
branches:
- develop
Expand All @@ -26,7 +31,7 @@ jobs:

steps:
- uses: actions/checkout@v2

- name: Composer Dependencies
uses: php-actions/composer@v2
with:
Expand Down
23 changes: 16 additions & 7 deletions .gitpod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,23 @@ tasks:
docker pull composer
docker-compose pull
docker-compose build www
command: |
docker run --rm --tty --volume $PWD:/app --user $(id -u):$(id -g) composer install --ignore-platform-reqs
docker-compose up -d
echo "Pausing for MySQL to complete..."&& sleep 15
docker-compose exec www wp core install --url="https://8080-${GITPOD_WORKSPACE_ID}.${GITPOD_WORKSPACE_CLUSTER_HOST}" --title="SMTP Dummy" --admin_user="admin" --admin_password="password" --admin_email="[email protected]" --allow-root
docker-compose exec www wp plugin activate simple-smtp --allow-root
cp .env.example .env
command: sh ./.devcontainer/postCreateCommand.sh
vscode:
extensions:
- ms-azuretools.vscode-docker
- johnbillion.vscode-wordpress-hooks

ports:
- port: 8080
name: WordPress
description: Main WordPress instance.
- port: 8081
name: MailHog
description: Access GUI for the MailHog interface.
- port: 8082
name: phpMyAdmin
description: Access GUI for the MariaDB instance.
- port: 8083
description: SMTP port for MailHog.
- port: 4443
description: Unused in GitPod.
2 changes: 1 addition & 1 deletion assets/smtp-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @license MIT
*/

const { __, _x, _n, _nx } = wp.i18n;
const { __ } = wp.i18n;

/**
* Grabs the sources file. If it loads, we continue. If not, we do not display this feature.
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: '3.6'
services:
db:
image: docker.io/library/mariadb:latest
image: docker.io/library/mariadb:10.5.15 # Changed due to MariaDB Docker build issues.
environment:
MYSQL_ROOT_PASSWORD: s9f6sd759r32r7f0dsf5673894956
MYSQL_DATABASE: wordpress
Expand Down
8 changes: 7 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Tags: mail,email,smtp,dispatch,sender
Requires at least: 4.9
Tested up to: 6.0
Requires PHP: 7.0
Stable tag: 1.3.1.1
Stable tag: 1.3.2
License: MIT

Adds a simple mail configuration panel into your WordPress installation. Supports temporary logging and config variables.
Expand Down Expand Up @@ -95,7 +95,13 @@ To help diagnose disabled input boxes, when the WordPress site is in [debugging
= Can I report an issue, or contribute to development? =
Yes! [Please see our GitHub repository here](https://github.com/soup-bowl/wp-simple-smtp) for writing issues and/or making pull requests.

One of the easiest aspects to contribute to is the SMTP quick configuration segment. If you wish to maintain this aspect, suggest a new setting, or report broken entries, see the [SMTP quick config wiki page](https://github.com/soup-bowl/wp-simple-smtp/wiki/SMTP-Quick-Config).

== Changelog ==
= 1.3.2 =
* Added: Mail view now displays from, cc, bcc & the headers stored when logging is enabled.
* Fix: Infinite loop when a plugin hooks into the mail routine functions and sends an email ([#116](https://github.com/soup-bowl/wp-simple-smtp/pull/116)).

= 1.3.1.1 =
* Verified working with WordPress 6.0.

Expand Down
83 changes: 83 additions & 0 deletions src/log/class-log.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,33 @@ public function get_recipients() {
return $this->recipients;
}

/**
* Gets the from details.
*
* @return string|null
*/
public function get_from() {
return $this->find_in_headers( 'from' );
}

/**
* Gets the cc recipients.
*
* @return string|null
*/
public function get_cc() {
return $this->find_in_headers( 'cc' );
}

/**
* Gets the bcc recipients.
*
* @return string|null
*/
public function get_bcc() {
return $this->find_in_headers( 'bcc' );
}

/**
* Gets the server dispatch headers.
*
Expand All @@ -130,6 +157,28 @@ public function get_headers() {
return $this->headers;
}

/**
* Same as get_headers, but the header strings are split.
*
* @param bool $exclude_recipients Remove CC from the list.
* @return array[]
*/
public function get_headers_as_array( $exclude_recipients = true ) {
$collection = [];
if ( ! empty( $this->get_headers() ) ) {
foreach ( $this->get_headers() as $header ) {
$expd = explode( ':', $header );
if ( $exclude_recipients && in_array( strtolower( $expd[0] ), [ 'cc', 'bcc', 'from' ], true ) ) {
continue;
} else {
$collection[] = $expd;
}
}
}

return $collection;
}

/**
* The dispatch headers, unsplit.
*
Expand Down Expand Up @@ -273,4 +322,38 @@ public function set_timestamp( $timestamp ) {

return $this;
}

/**
* Searches the header array for a particular header.
*
* @param string $needle Header to look for.
* @return string[]
*/
private function find_in_headers( $needle ) {
$collection = [];
foreach ( $this->get_headers_as_array( false ) as $header ) {
if ( strtolower( $header[0] ) === strtolower( $needle ) ) {
$collection[] = $header[1];
}
}

return $collection;
}

/**
* Extracts the email from angled brackets, if the syntax is so.
*
* @param string $input The subject to be inspected.
* @return string Either the extracted email address, or the input is returned untouched.
*/
private function strip_email( $input ) {
$stripped = '';
$rc = preg_match( '/(?<=\<).+?(?=\>)/', $input, $stripped );

if ( 1 === $rc ) {
return $stripped;
} else {
return $input;
}
}
}
7 changes: 7 additions & 0 deletions src/log/class-logservice.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public function register_log_storage() {
'delete_post' => 'manage_options',
'read_post' => 'manage_options',
],
'label' => _x( 'E-mail log entries', 'Post Type General Name', 'simple-smtp' ),
]
);
}
Expand All @@ -60,6 +61,12 @@ public function register_log_storage() {
* @return integer ID of the newly-inserted entry.
*/
public function new_log_entry( $log ) {
// Patch fix to stop Sucuri from spamming the log. Should be investigated more.
$dup_check = post_exists( $log->get_subject(), '', current_time( 'mysql' ), $this->post_type );
if ( 0 !== $dup_check ) {
return $dup_check;
}

$post_id = wp_insert_post(
[
'post_title' => $log->get_subject(),
Expand Down
31 changes: 29 additions & 2 deletions src/log/class-logtable.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace wpsimplesmtp;

use wpsimplesmtp\Log;
use wpsimplesmtp\LogService;

/**
Expand Down Expand Up @@ -68,13 +69,12 @@ public function display( $page, $maximum_per_page = 20 ) {

if ( ! empty( $entries ) ) {
foreach ( $entries as $entry ) {
$recipients = implode( ', ', $entry->get_recipients() );
$actions = $this->render_log_entry_buttons( $entry );
$date = gmdate( get_option( 'time_format' ) . ', ' . get_option( 'date_format' ), strtotime( $entry->get_timestamp() ) );
$row_classes = ( ! empty( $entry->get_error() ) ) ? 'site-archived log-row' : 'log-row';
echo wp_kses(
'<tr class="' . esc_attr( $row_classes ) . '">
<td data-colname="' . $labels[0] . '" class="has-row-actions">' . $recipients . $actions . '</td>
<td data-colname="' . $labels[0] . '" class="has-row-actions">' . $this->display_recipients( $entry ) . $actions . '</td>
<td data-colname="' . $labels[1] . '">' . $entry->get_subject() . '</td>
<td data-colname="' . $labels[2] . '"><abbr title="' . $entry->get_timestamp() . '">' . $date . '</abbr></td>
<td data-colname="' . $labels[3] . '">' . $entry->get_error() . '</td>
Expand Down Expand Up @@ -221,6 +221,33 @@ private function render_log_entry_buttons( $entry ) {
return $row_actions;
}

/**
* Compiles a list of recipients (to and cc) into a single string.
*
* @param Log $log_item Log entry item.
* @return string
*/
private function display_recipients( $log_item ) {
$recipients = [];

if ( ! empty( $log_item->get_recipients() ) ) {
$recipients[] = esc_html__( 'To', 'simple-smtp' ) . ': ' . implode( ', ', $log_item->get_recipients() );
}

if ( ! empty( $log_item->get_cc() ) ) {
$recipients[] = esc_html__( 'CC', 'simple-smtp' ) . ': ' . implode( ', ', $log_item->get_cc() );
}

if ( ! empty( $log_item->get_bcc() ) ) {
$recipients[] = esc_html__( 'BCC', 'simple-smtp' ) . ': ' . implode( ', ', $log_item->get_bcc() );
}

return wp_kses(
implode( ', ', $recipients ),
$this->allowed_table_html()
);
}

/**
* Array for kses that allows table-related HTML only.
*
Expand Down
Loading

0 comments on commit 870692f

Please sign in to comment.