diff --git a/.github/dependabot.yml b/.github/dependabot.yml
new file mode 100644
index 0000000..d4cd657
--- /dev/null
+++ b/.github/dependabot.yml
@@ -0,0 +1,11 @@
+# To get started with Dependabot version updates, you'll need to specify which
+# package ecosystems to update and where the package manifests are located.
+# Please see the documentation for all configuration options:
+# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
+
+version: 2
+updates:
+ - package-ecosystem: "maven" # See documentation for possible values
+ directory: "/" # Location of package manifests
+ schedule:
+ interval: "weekly"
diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml
new file mode 100644
index 0000000..f369e16
--- /dev/null
+++ b/.github/workflows/maven.yml
@@ -0,0 +1,33 @@
+# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
+# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
+
+name: Java CI with Maven
+
+on:
+ push:
+ branches: [ "master" ]
+ pull_request:
+ branches: [ "master" ]
+
+jobs:
+ build:
+
+ runs-on: ubuntu-latest
+
+ steps:
+ - uses: actions/checkout@v3
+ - name: Set up JDK 1.8
+ uses: actions/setup-java@v3
+ with:
+ java-version: '8'
+ distribution: 'temurin'
+ cache: maven
+ - name: Cache local Maven repository
+ uses: actions/cache@v3.0.11
+ with:
+ path: ~/.m2/repository
+ key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
+ restore-keys: |
+ ${{ runner.os }}-maven-
+ - name: Build with Maven
+ run: mvn -B package --file pom.xml
diff --git a/.travis.yml b/.travis.yml
index e1003b4..61998ed 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,4 +1,7 @@
language: java
jdk:
- - oraclejdk7
- - openjdk7
\ No newline at end of file
+ - oraclejdk8
+ - openjdk8
+cache:
+ directories:
+ - $HOME/.m2
diff --git a/README.md b/README.md
index 8b41994..b770218 100644
--- a/README.md
+++ b/README.md
@@ -30,7 +30,7 @@ The easiest way to install and run MockMock is by downloading the jar file [here
`java -jar MockMock.jar`
This will run MockMock on the default ports 25 (for SMTP) and 8282 (the web interface). Please note you might need root permissions on some systems to let it listen on port 25.
-After it started you can use your internet browser to navigate to [http://localhost:8282] (replace host name and web port if necessary). This will now show you the emails it received (which should be none at the moment). You can now send emails using the built in SMTP server running on port 25 by default. The emails should be visible via the web interface. To run MockMock on another port, you can start it with the following parameters:
+After it started you can use your internet browser to navigate to [http://localhost:8282] (replace host name and web port if necessary). This will now show you the emails it received (which should be none at the moment). You can now send emails using the built-in SMTP server running on port 25 by default. The emails should be visible via the web interface. To run MockMock on another port, you can start it with the following parameters:
`java -jar MockMock.jar -p 25000 -h 8080`
This will run MockMock on SMTP port 25000 and http port 8080.
diff --git a/checkstyle.xml b/checkstyle.xml
new file mode 100644
index 0000000..1bcbf91
--- /dev/null
+++ b/checkstyle.xml
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/extra/init.centos b/extra/init.centos
new file mode 100755
index 0000000..6aa1980
--- /dev/null
+++ b/extra/init.centos
@@ -0,0 +1,88 @@
+#! /bin/sh
+### BEGIN INIT INFO
+# Required-Start: $remote_fs $syslog
+# Required-Stop: $remote_fs $syslog
+# Default-Start: 2 3 4 5
+# Default-Stop: 0 1 6
+# Short-Description: MockMock - Mock SMTP Server
+### END INIT INFO
+
+# PATH should only include /usr/* if it runs after the mountnfs.sh script
+PATH=/sbin:/usr/sbin:/bin:/usr/bin
+DESC="MockMock - Mock SMTP Server"
+NAME=mockmock
+DAEMON=/opt/mockmock/MockMock.jar
+DAEMON_ARGS="-p 25000 -h 8282"
+PIDFILE=/var/run/$NAME.pid
+SCRIPTNAME=/etc/init.d/$NAME
+
+# Read configuration variable file if it is present
+[ -r /etc/default/$NAME ] && . /etc/default/$NAME
+
+# Centos daemon functions
+. /etc/init.d/functions
+
+exe="/usr/bin/java -jar ${DAEMON} ${DAEMON_ARGS}"
+
+#
+# Function that starts the daemon/service
+#
+do_start()
+{
+ echo -n "Starting mockmock : ${DAEMON_ARGS}"
+ #daemon ${exe} # Not working ...
+ if [ -s ${PIDFILE} ]; then
+ RETVAL=1
+ echo -n "Already running, check '${PIDFILE}'." && warning
+ echo
+ else
+ nohup ${exe} > /var/log/mockmock.log 2>&1 &
+ RETVAL=$?
+ PID=$!
+ [ $RETVAL -eq 0 ] && success || failure
+ echo
+ echo $PID > ${PIDFILE}
+ fi
+ return "$RETVAL"
+}
+
+#
+# Function that stops the daemon/service
+#
+do_stop()
+{
+ killproc -p ${PIDFILE}
+ RETVAL="$?"
+ if [ "$RETVAL" -ne 0 ]; then
+ echo -n "Could not stop mockmock with pid file ${PIDFILE}." && error
+ return "$RETVAL"
+ fi
+
+ # Many daemons don't delete their pidfiles when they exit.
+ rm -f ${PIDFILE}
+ echo "Stopping mockmock."
+ return "$RETVAL"
+}
+
+case "$1" in
+ start)
+ do_start
+ ;;
+ stop)
+ do_stop
+ ;;
+ status)
+ status -p $PIDFILE
+ ;;
+ restart|force-reload)
+ do_stop
+ do_start
+ ;;
+ *)
+ #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
+ echo "Usage: $SCRIPTNAME {start|stop|status|restart}" >&2
+ exit 3
+ ;;
+esac
+
+:
diff --git a/pom.xml b/pom.xml
index 88cfb5b..627a418 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,117 +1,68 @@
-
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
com.mockmock
MockMock
- 1.4.0
+ 1.4.1-SNAPSHOT
jar
MockMock
Mock SMTP Server
- 2012
https://github.com/tweakers-dev/MockMock
-
-
- 3.0
-
+ 2012
- ISO-8859-15
- ISO-8859-15
- 4.1.2.RELEASE
+ UTF-8
+ UTF-8
+ 2.0.9
-
-
-
- org.apache.maven.plugins
- maven-compiler-plugin
- 2.3.2
-
- 1.7
- 1.7
-
-
-
- org.apache.maven.plugins
- maven-jar-plugin
- 2.3.1
-
-
-
- com.mockmock.AppStarter
-
-
-
-
-
- org.dstovall
- onejar-maven-plugin
- 1.4.4
-
-
-
- 0.97
- true
- onejar
-
- package
-
- one-jar
-
-
-
-
-
-
- org.apache.maven.plugins
- maven-resources-plugin
- 2.4.3
-
-
- copy-resources
- package
-
- copy-resources
-
-
- ${basedir}/target/static
-
-
- src/main/resources
- true
-
-
-
-
-
-
-
-
-
-
-
- onejar-maven-plugin.googlecode.com
- http://onejar-maven-plugin.googlecode.com/svn/mavenrepo
-
-
-
-
-
- repository.springframework.maven.release
- Spring Framework Maven Release Repository
- http://maven.springframework.org/release
-
-
+
+
+
+ org.springframework
+ spring-framework-bom
+ 5.3.23
+ pom
+ import
+
+
+ org.eclipse.jetty
+ jetty-bom
+ 9.4.49.v20220914
+ pom
+ import
+
+
+ javax.mail
+ mail
+ 1.4.7
+
+
+ org.slf4j
+ slf4j-api
+ ${slf4j.version}
+
+
+ com.google.code.findbugs
+ jsr305
+ 3.0.2
+
+
+ javax.activation
+ activation
+ 1.1.1
+
+
+
commons-cli
commons-cli
- 1.2
+ 1.5.0
@@ -120,40 +71,20 @@
2.6
-
- javax.mail
- mail
- 1.4
-
-
-
- org.slf4j
- slf4j-api
- 1.7.2
-
-
org.slf4j
slf4j-simple
- 1.7.2
-
-
-
- javax.activation
- activation
- 1.1
+ ${slf4j.version}
org.eclipse.jetty
jetty-server
- 8.1.8.v20121106
org.eclipse.jetty
jetty-webapp
- 8.1.8.v20121106
@@ -165,60 +96,169 @@
joda-time
joda-time
- 2.1
+ 2.12.5
com.google.guava
guava
- 13.0
+ 32.1.3-jre
org.springframework
spring-core
- ${spring.version}
org.springframework
spring-beans
- ${spring.version}
org.springframework
spring-context
- ${spring.version}
org.springframework
spring-context-support
- ${spring.version}
org.springframework
spring-webmvc
- ${spring.version}
-
junit
junit
- 4.11
+ 4.13.2
test
org.mockito
mockito-core
- 1.8.5
+ 4.11.0
test
-
\ No newline at end of file
+
+
+ repository.springframework.maven.release
+ Spring Framework Maven Release Repository
+ http://maven.springframework.org/release
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-enforcer-plugin
+ 3.4.1
+
+
+ enforce-maven
+
+ enforce
+
+
+
+
+ 3.0.5
+
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-checkstyle-plugin
+ 3.3.0
+
+
+ validate
+ validate
+
+ checkstyle.xml
+ ${project.build.sourceEncoding}
+ true
+ true
+
+
+ check
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.11.0
+
+ 1.7
+ 1.7
+
+
+
+ org.apache.maven.plugins
+ maven-jar-plugin
+ 3.3.0
+
+
+
+ com.mockmock.AppStarter
+
+
+
+
+
+ com.jolira
+ onejar-maven-plugin
+ 1.4.4
+
+
+
+ 0.97
+ true
+ onejar
+
+ package
+
+ one-jar
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-resources-plugin
+ 3.3.1
+
+
+ copy-resources
+ package
+
+ copy-resources
+
+
+ ${basedir}/target/static
+
+
+ src/main/resources
+ true
+
+
+
+
+
+
+
+
+
diff --git a/release/MockMock.jar b/release/MockMock.jar
index 12ed6c2..ca6f98c 100644
Binary files a/release/MockMock.jar and b/release/MockMock.jar differ
diff --git a/src/main/java/com/mockmock/Util.java b/src/main/java/com/mockmock/Util.java
index 2b32188..bcb3d98 100644
--- a/src/main/java/com/mockmock/Util.java
+++ b/src/main/java/com/mockmock/Util.java
@@ -1,12 +1,9 @@
package com.mockmock;
import java.io.BufferedReader;
-import java.io.ByteArrayInputStream;
-import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
-import java.util.Scanner;
public class Util
{
@@ -43,4 +40,4 @@ public String getFile(String fileName)
return sb.toString();
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/com/mockmock/console/Parser.java b/src/main/java/com/mockmock/console/Parser.java
index d836a4e..4246906 100644
--- a/src/main/java/com/mockmock/console/Parser.java
+++ b/src/main/java/com/mockmock/console/Parser.java
@@ -1,6 +1,5 @@
package com.mockmock.console;
-
import com.mockmock.Settings;
import org.apache.commons.cli.*;
import org.springframework.stereotype.Service;
@@ -19,15 +18,15 @@ public Settings parseOptions(String[] args, Settings settings)
{
// define the possible options
Options options = new Options();
- options.addOption("p", true, "The mail port number to use. Default is 25000.");
- options.addOption("h", true, "The http port number to use. Default is 8282.");
- options.addOption("m", true, "The maximum size of the mail qeueue. Default is 1000.");
- options.addOption("c", true, "Comma separated list of channels. Default is #postman.");
- options.addOption("ff", true, "Filters out from email addresses (comma separated).");
- options.addOption("ft", true, "Filters out to email addresses (comma separated).");
- options.addOption("s", true, "Full path to the folder containing the static files like images and css.");
- options.addOption("ec", false, "Turns on emails printing to console. Default off");
- options.addOption("?", false, "Shows this help information.");
+ options.addOption("p", "smtp", true, "The mail port number to use. Default is 25.");
+ options.addOption("h", "http", true, "The http port number to use. Default is 8282.");
+ options.addOption("m", "queue", true, "The maximum size of the mail queue. Default is 1000.");
+ options.addOption("c", "channels", true, "Comma separated list of channels. Default is #postman.");
+ options.addOption("f", "filter-from", true, "Filters out from email addresses (comma separated).");
+ options.addOption("t", "filter-to", true, "Filters out to email addresses (comma separated).");
+ options.addOption("s", "static", true, "Full path to the folder containing the static files like images and css.");
+ options.addOption("ec", "console", false, "Turns on emails printing to console. Default off");
+ options.addOption("?", "help", false, "Shows this help information.");
// parse the given arguments
CommandLineParser parser = new PosixParser();
@@ -43,7 +42,7 @@ public Settings parseOptions(String[] args, Settings settings)
System.exit(0);
}
- partseShowEmailInConsoleOption(cmd, settings);
+ parseShowEmailInConsoleOption(cmd, settings);
parseSmtpPortOption(cmd, settings);
parseHttpPortOption(cmd, settings);
parseMailQueueSizeOption(cmd, settings);
@@ -59,19 +58,11 @@ public Settings parseOptions(String[] args, Settings settings)
return settings;
}
- protected void partseShowEmailInConsoleOption(CommandLine cmd, Settings settings)
+ protected void parseShowEmailInConsoleOption(CommandLine cmd, Settings settings)
{
if(cmd.hasOption("ec"))
{
- try
- {
- // settings.setShowEmailInConsole(Boolean.valueOf(cmd.getOptionValue("ec")));
- settings.setShowEmailInConsole(true);
- }
- catch(IllegalArgumentException e)
- {
- System.err.println("Invalid value given, using default " + settings.getShowEmailInConsole());
- }
+ settings.setShowEmailInConsole(true);
}
}
@@ -81,7 +72,7 @@ protected void parseSmtpPortOption(CommandLine cmd, Settings settings)
{
try
{
- settings.setSmtpPort(Integer.valueOf(cmd.getOptionValue("p")));
+ settings.setSmtpPort(Integer.parseInt(cmd.getOptionValue("p")));
}
catch (NumberFormatException e)
{
@@ -96,7 +87,7 @@ protected void parseHttpPortOption(CommandLine cmd, Settings settings)
{
try
{
- settings.setHttpPort(Integer.valueOf(cmd.getOptionValue("h")));
+ settings.setHttpPort(Integer.parseInt(cmd.getOptionValue("h")));
}
catch (NumberFormatException e)
{
@@ -111,7 +102,7 @@ protected void parseMailQueueSizeOption(CommandLine cmd, Settings settings)
{
try
{
- settings.setMaxMailQueueSize(Integer.valueOf(cmd.getOptionValue("m")));
+ settings.setMaxMailQueueSize(Integer.parseInt(cmd.getOptionValue("m")));
}
catch (NumberFormatException e)
{
@@ -122,9 +113,9 @@ protected void parseMailQueueSizeOption(CommandLine cmd, Settings settings)
protected void parseFilterFromEmailAddressesOption(CommandLine cmd, Settings settings)
{
- if(cmd.hasOption("ff"))
+ if(cmd.hasOption("f"))
{
- String input = cmd.getOptionValue("ff");
+ String input = cmd.getOptionValue("f");
String[] emailAddresses = input.split(",");
settings.setFilterFromEmailAddresses(new HashSet<>(Arrays.asList(emailAddresses)));
}
@@ -132,9 +123,9 @@ protected void parseFilterFromEmailAddressesOption(CommandLine cmd, Settings set
protected void parseFilterToEmailAddressesOption(CommandLine cmd, Settings settings)
{
- if(cmd.hasOption("ft"))
+ if(cmd.hasOption("t"))
{
- String input = cmd.getOptionValue("ft");
+ String input = cmd.getOptionValue("t");
String[] emailAddresses = input.split(",");
settings.setFilterToEmailAddresses(new HashSet<>(Arrays.asList(emailAddresses)));
}
diff --git a/src/main/java/com/mockmock/htmlbuilder/AddressesHtmlBuilder.java b/src/main/java/com/mockmock/htmlbuilder/AddressesHtmlBuilder.java
index 8b51534..c017cfd 100644
--- a/src/main/java/com/mockmock/htmlbuilder/AddressesHtmlBuilder.java
+++ b/src/main/java/com/mockmock/htmlbuilder/AddressesHtmlBuilder.java
@@ -12,7 +12,7 @@ public class AddressesHtmlBuilder implements HtmlBuilder
public String build()
{
- String output = "";
+ StringBuilder output = new StringBuilder();
StringFromHtmlBuilder fromHtmlBuilder = new StringFromHtmlBuilder();
fromHtmlBuilder.setMockMail(mockMail);
@@ -20,26 +20,26 @@ public String build()
StringRecipientHtmlBuilder recipientHtmlBuilder = new StringRecipientHtmlBuilder();
recipientHtmlBuilder.setMockMail(mockMail);
- output += "From: " + fromHtmlBuilder.build() + "
\n";
+ output.append("From: ").append(fromHtmlBuilder.build()).append("
\n");
recipientHtmlBuilder.setRecipientType(MimeMessage.RecipientType.TO);
- output += "To: " + recipientHtmlBuilder.build() + "
\n";
+ output.append("To: ").append(recipientHtmlBuilder.build()).append("
\n");
recipientHtmlBuilder.setRecipientType(MimeMessage.RecipientType.CC);
String ccOutput = recipientHtmlBuilder.build();
if(ccOutput.length() > 0)
{
- output += "CC: " + ccOutput + "
\n";
+ output.append("CC: ").append(ccOutput).append("
\n");
}
recipientHtmlBuilder.setRecipientType(MimeMessage.RecipientType.BCC);
String bccOutput = recipientHtmlBuilder.build();
if(bccOutput.length() > 0)
{
- output += "BCC: " + bccOutput + "
\n";
+ output.append("BCC: ").append(bccOutput).append("
\n");
}
- return output;
+ return output.toString();
}
public void setMockMail(MockMail mockMail)
diff --git a/src/main/java/com/mockmock/htmlbuilder/FooterHtmlBuilder.java b/src/main/java/com/mockmock/htmlbuilder/FooterHtmlBuilder.java
index 41675f3..16ee4ac 100644
--- a/src/main/java/com/mockmock/htmlbuilder/FooterHtmlBuilder.java
+++ b/src/main/java/com/mockmock/htmlbuilder/FooterHtmlBuilder.java
@@ -1,6 +1,5 @@
package com.mockmock.htmlbuilder;
-import com.mockmock.AppStarter;
import com.mockmock.Settings;
import com.mockmock.Util;
import org.springframework.stereotype.Service;
@@ -19,28 +18,20 @@ public void setSettings(Settings settings)
public String build()
{
- String output = "";
+ StringBuilder output = new StringBuilder();
Util util = new Util();
if(settings.getStaticFolderPath() != null)
{
- output +=
- " \n" +
- " \n" +
- " \n";
+ output.append(" \n" + " \n" + " \n");
}
else
{
- output +=
- " \n" +
- " \n" +
- " \n";
+ output.append(" \n").append(" \n").append(" \n");
}
- output +=
- "