Skip to content

Commit

Permalink
Fixes #16.
Browse files Browse the repository at this point in the history
  • Loading branch information
nickgrealy committed Jun 14, 2016
1 parent ca94af8 commit 2a9f217
Show file tree
Hide file tree
Showing 12 changed files with 140 additions and 24 deletions.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,23 @@ to further configure the connection.

Below are some sample configurations for common web based email services:

#### GMAIL
#### GMAIL (IMAPS)
For google passwords, go to "Google account > security > app passwords".

host=imap.gmail.com
username=<your_email>@gmail.com
password=<your_application_password>

#### GMAIL (POP3S)
For google passwords, go to "Google account > security > app passwords".

host=pop.gmail.com
username=<your_email>@gmail.com
password=<your_application_password>

storeName=pop3s
receivedXMinutesAgo=

#### HOTMAIL
For hotmail passwords, go to "Account Settings > Security Info > Create a new app password".

Expand Down
7 changes: 7 additions & 0 deletions TEST.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
| | Version |
| --- | --- |
| **Latest Release** | <span style="background-color:lightgreen;border:1px solid lightgrey;padding:4px 8px;border-radius:5px;">1.022</span> |
| **Java Runtime Environment**| <span style="background-color:lightgreen;border:1px solid lightgrey;padding:4px 8px;border-radius:5px;">1.6+</span> |
| **Jenkins** | <span style="background-color:lightgreen;border:1px solid lightgrey;padding:4px 8px;border-radius:5px;">1.424+</span> |
| **Jenkins Plugin Type** | <span style="background-color:lightgreen;border:1px solid lightgrey;padding:4px 8px;border-radius:5px;">Build Trigger</span> |
| **Mail Protocols** | <span style="background-color:lightgreen;border:1px solid lightgrey;padding:4px 8px;border-radius:5px;">IMAP</span> <span style="background-color:lightgreen;border:1px solid lightgrey;padding:4px 8px;border-radius:5px;">IMAPs</span> |
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
}
}
dependencies {
classpath 'org.jenkins-ci.tools:gradle-jpi-plugin:0.15.0'
classpath 'org.jenkins-ci.tools:gradle-jpi-plugin:0.18.1'
}
}

Expand All @@ -28,11 +28,11 @@ apply from: "$rootDir/config/gradle/staticCodeAnalysis.gradle"

repositories {
mavenLocal()
mavenCentral()
jcenter()
maven {
url 'http://repo.jenkins-ci.org/releases/'
}
mavenCentral()
jcenter()
}

jenkinsPlugin {
Expand Down
10 changes: 5 additions & 5 deletions config/gradle/common.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

apply plugin: 'idea'
//apply plugin: 'groovy'
apply plugin: 'groovy'
apply plugin: 'java'

idea.project?.vcs = 'Git'
Expand All @@ -12,7 +12,7 @@ ext {
/* optional - set variable enforceJavaVersion */
enforceJavaVersionFlag = project.getProperties().containsKey('enforceJavaVersion')
javaVersion = project.getProperties().get('enforceJavaVersion') ?: JavaVersion.VERSION_1_6
compileTasks = [compileJava, compileTestJava] //, compileGroovy, compileTestGroovy]
compileTasks = [compileJava, compileTestJava, compileGroovy, compileTestGroovy]
}


Expand All @@ -30,7 +30,7 @@ allprojects {

ext {
groovyVersion = '2.4.4'
customJvmArgs = ['-Xmx128m']
customJvmArgs = ['-Xmx1g', '-XX:MaxPermSize=1g']
}

dependencies {
Expand Down Expand Up @@ -100,7 +100,7 @@ task enforceJavaVersionTask << {
if (enforceJavaVersionFlag){
def foundVersion = JavaVersion.current()
if (foundVersion.toString() != enforceJavaVersion.toString()){
println("WARN: Wrong Java version: required is $enforceJavaVersion, but found $foundVersion")
println("\nWARNING: Wrong Java version: required is $enforceJavaVersion, but found $foundVersion \n")
}
} else {
println "Java version not enforced."
Expand All @@ -121,6 +121,6 @@ compileTasks*.dependsOn(enforceJavaVersionTask);

ext.verifySize = { File file, int expectedSizeKB ->
def actualSizeBytes = file.length()
println "Output file size is: ${(int) actualSizeBytes / 1024} KB"
println "Output file size is: ${(int) (actualSizeBytes / 1024)} KB"
assert actualSizeBytes < (expectedSizeKB * 1024)
}
5 changes: 5 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,8 @@ version = 1.023-SNAPSHOT
jenkinsDisplayName = Poll Mailbox Trigger Plugin

org.gradle.daemon = false

# Set system properties
systemProp.stapler.trace = false
systemProp.stapler.jelly.noCache = false
systemProp.debug.YUI = false
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Tue Sep 22 04:02:36 UTC 2015
#Tue Jun 14 15:22:03 EST 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.7-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.13-bin.zip
2 changes: 1 addition & 1 deletion gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
##############################################################################

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS="-Xmx128m"
DEFAULT_JVM_OPTS="-Xmx1g -XX:MaxPermSize=1g"

APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
Expand Down
2 changes: 1 addition & 1 deletion gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
if "%OS%"=="Windows_NT" setlocal

@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=-Xmx128m
set DEFAULT_JVM_OPTS=-Xmx1g -XX:MaxPermSize=1g

set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ public class PollMailboxTrigger extends AbstractTriggerExt {

public static final String DATE_FORMAT_TEXT = "yyyy/MM/dd HH:mm:ss a";
public static final int ONE_DAY_IN_MINUTES = 1440;
public static final int PORT_IMAP = 143;
public static final int PORT_IMAPS = 993;
public static final int PORT_POP3 = 110;
public static final int PORT_POP3S = 995;

private String host;
private String username;
Expand Down Expand Up @@ -167,9 +171,14 @@ public static CustomProperties initialiseDefaults(
p.putIfBlank(subjectContains, "jenkins >");
p.putIfBlank(receivedXMinutesAgo, Integer.toString(ONE_DAY_IN_MINUTES));
String cnfHost = p.get(Properties.host);
String cnfStoreName = p.get(storeName);
String cnfStoreName = p.get(storeName).toLowerCase();
int port = "imap".equals(cnfStoreName) ? PORT_IMAP
: "imaps".equals(cnfStoreName) ? PORT_IMAPS
: "pop3".equals(cnfStoreName) ? PORT_POP3
: "pop3s".equals(cnfStoreName) ? PORT_POP3S
: PORT_IMAPS;
p.putIfBlank("mail." + cnfStoreName + ".host", cnfHost);
p.putIfBlank("mail." + cnfStoreName + ".port", cnfStoreName.toLowerCase().endsWith("s") ? "993" : "143");
p.putIfBlank("mail." + cnfStoreName + ".port", String.valueOf(port));
p.putIfBlank("mail.debug", "false");
p.putIfBlank("mail.debug.auth", "false");
// re-override the user properties, to ensure they're set.
Expand Down Expand Up @@ -243,7 +252,8 @@ public static FormValidation checkForEmails(final CustomProperties properties, f
List<Message> messageList = messagesTool.getMessages();
StringBuilder subjects = new StringBuilder();
for (Message message : messageList) {
subjects.append("\n\n- ").append(message.getSubject()).append(" (").append(dateFormat.format(message.getReceivedDate())).append(")");
Date receivedDate = message.getReceivedDate();
subjects.append("\n\n- ").append(message.getSubject()).append(" (").append(receivedDate != null ? dateFormat.format(receivedDate) : "null").append(")");
}
final String foundEmails = "Found matching email(s) : " + messageList.size() + subjects.toString();
log.info(foundEmails);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@

Feature: Configuration

Background: The tests are setup.
Given the plugin is initialised


Scenario: I want to have sensible default config values.
Scenario: I want the default config values to be IMAPS.
When I set the configuration to
| Host | Username | Password | Script |
Then the effective configuration should be
Expand Down Expand Up @@ -129,7 +128,7 @@ Feature: Configuration
| username | bbb |


Scenario: I want the imap port and host varaibles to be automatically updated, if I switch to IMAP [no 'S'].
Scenario: I want default values for IMAP.
When I set the configuration to
| Host | Username | Password |
| mail.com | morty | chickens |
Expand All @@ -149,4 +148,73 @@ Feature: Configuration
| receivedXMinutesAgo | 1440 |
| storeName | imap |
| subjectContains | jenkins > |
| username | morty |
| username | morty |


Scenario: I want default values for IMAPS.
When I set the configuration to
| Host | Username | Password |
| mail.com | morty | chickens |
And the script
"""
storeName=imaps
"""
Then the effective configuration should be
| attachments | IGNORE |
| folder | INBOX |
| host | mail.com |
| mail.debug | false |
| mail.debug.auth | false |
| mail.imaps.host | mail.com |
| mail.imaps.port | 993 |
| password | snekcihc |
| receivedXMinutesAgo | 1440 |
| storeName | imaps |
| subjectContains | jenkins > |
| username | morty |


Scenario: I want default values for POP3.
When I set the configuration to
| Host | Username | Password |
| pop.gmail.com | morty@gmail.com | chickens |
And the script
"""
storeName=pop3
"""
Then the effective configuration should be
| attachments | IGNORE |
| folder | INBOX |
| host | pop.gmail.com |
| mail.debug | false |
| mail.debug.auth | false |
| mail.pop3.host | pop.gmail.com |
| mail.pop3.port | 110 |
| password | snekcihc |
| receivedXMinutesAgo | 1440 |
| storeName | pop3 |
| subjectContains | jenkins > |
| username | morty@gmail.com |


Scenario: I want default values for POP3S.
When I set the configuration to
| Host | Username | Password |
| pop.gmail.com | morty@gmail.com | chickens |
And the script
"""
storeName=pop3s
"""
Then the effective configuration should be
| attachments | IGNORE |
| folder | INBOX |
| host | pop.gmail.com |
| mail.debug | false |
| mail.debug.auth | false |
| mail.pop3s.host | pop.gmail.com |
| mail.pop3s.port | 995 |
| password | snekcihc |
| receivedXMinutesAgo | 1440 |
| storeName | pop3s |
| subjectContains | jenkins > |
| username | morty@gmail.com |
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,5 @@ Feature: Test Connection - Error Handling
"""
And I test the connection
Then the response should be ERROR with message 'Please set the &#039;folder=XXX&#039; parameter to one of the following values: <br>Folders: '

# todo test getReceivedDate() returns null (when using pop3)
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
@wip @ignore
@ignore
Feature: Test Live Connection
This is just for testing a connection to an email server.

Scenario: Test connecting to gmail
Scenario: Test connecting to GMAIL via IMAPS
Given the plugin is initialised
And I set the configuration to
| Host | Username | Password |
Expand All @@ -11,5 +11,19 @@ Feature: Test Live Connection
# When I test the connection
# Then the response should be OK with message 'Connected to mailbox. <br>Searching folder...<br>Found matching email(s) : 1'

When the Plugin's polling is triggered
Then a Jenkins job is scheduled with quietPeriod 0 and cause '[PollMailboxTrigger] Job was triggered by email sent from [email protected] (<a href="triggerCauseAction">log</a>)'
# When the Plugin's polling is triggered
# Then a Jenkins job is scheduled with quietPeriod 0 and cause '[PollMailboxTrigger] Job was triggered by email sent from [email protected] (<a href="triggerCauseAction">log</a>)'


@wip
Scenario: Test connecting to GMAIL via POP3
Given the plugin is initialised
And I set the configuration to
| Host | Username | Password |
| pop.gmail.com | morty@gmail.com | foobar |
And the script
"""
storeName=pop3
"""
When I test the connection
Then the response should be OK with message 'Connected to mailbox. <br>Searching folder...<br>Found matching email(s) : 1'

0 comments on commit 2a9f217

Please sign in to comment.