Skip to content

Commit

Permalink
Switched unittests from greenmail to javamail-mock2, some other small…
Browse files Browse the repository at this point in the history
… fixes
  • Loading branch information
salyh committed May 2, 2014
1 parent 57255b5 commit 9d7ad7e
Show file tree
Hide file tree
Showing 20 changed files with 437 additions and 353 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ target/
.classpath
.project
.settings/
*.sh
elasticsearch-*/
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ jdk:
- openjdk6
- openjdk7
- oraclejdk7
- oraclejdk8

notifications:
email:
recipients:
- [email protected]
on_success: always
on_failure: always
on_failure: always
51 changes: 49 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ Prerequisites:
* Elasticsearch 1.1.0 or higher
* At least one IMAP4 or POP3 server to connect to

``plugin.sh|.bat -i river-imap -u http://dl.bintray.com/salyh/maven/de/saly/elasticsearch/plugin/elasticsearch-river-imap/0.0.5/elasticsearch-river-imap-0.0.5-plugin.zip``
``plugin.sh|.bat -i river-imap -u http://dl.bintray.com/salyh/maven/de/saly/elasticsearch/plugin/elasticsearch-river-imap/0.0.6/elasticsearch-river-imap-0.0.6-plugin.zip``

<h3>Configuration</h3>
<pre>curl -XPUT 'http://localhost:9200/_river/name of your river/_meta' -d '{
<pre>curl -XPUT 'http://localhost:9200/_river/nameofyourriver/_meta' -d '{

"type":"imap",
"mail.store.protocol":"imap",
Expand Down Expand Up @@ -86,6 +86,53 @@ Prerequisites:

Note: For POP3 only the "INBOX" folder is supported. This is a limitation of the POP3 protocol.

<h3>Default Mapping Example</h3>
```json
{
"_index":"my_imap_river_index",
"_type":"my_imap_river_type",
"_id":"759::imap://es_imapriver_unittest%[email protected]/INBOX",
"_score":1.0,
"_source":{
"attachmentCount":0,
"attachments":null,
"bcc":null,
"cc":null,
"contentType":"text/plain; charset=us-ascii",
"folderFullName":"INBOX",
"folderUri":"imap://es_imapriver_unittest%[email protected]/INBOX",
"from":{
"email":"[email protected]",
"personal":null
},
"headers":{
"MIME-Version":"1.0",
"Message-ID":"<[email protected]>",
"Subject":"SID::2",
"Date":"Fri, 2 May 2014 19:18:59 +0200 (CEST)",
"Content-Transfer-Encoding":"7bit",
"To":"es_imapriver_unittest@localhost",
"Content-Type":"text/plain; charset=us-ascii",
"From":"[email protected]"
},
"mailboxType":"IMAP",
"popId":null,
"receivedDate":1399051139000,
"sentDate":1399051139000,
"size":337,
"subject":"SID::2",
"textContent":"This is a test e-mail.::2\r\n",
"to":[
{
"email":"es_imapriver_unittest@localhost",
"personal":null
}
],
"uid":759
}
}
```

<h3>License</h3>
Copyright (C) 2014 by Hendrik Saly (http://saly.de) and others.

Expand Down
90 changes: 64 additions & 26 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<name>elasticsearch-river-imap</name>
<name>Elasticsearch IMAP River</name>
<modelVersion>4.0.0</modelVersion>

<prerequisites>
<maven>3.1.0</maven>
</prerequisites>

<groupId>de.saly.elasticsearch.plugin</groupId>
<artifactId>elasticsearch-river-imap</artifactId>
<version>0.0.5</version>
<version>0.0.6</version>
<packaging>jar</packaging>
<description>IMAP river for Elasticsearch</description>
<inceptionYear>2014</inceptionYear>
Expand Down Expand Up @@ -74,28 +79,16 @@


<dependency>
<groupId>com.icegreen</groupId>
<artifactId>greenmail</artifactId>
<version>1.3.1b</version>
<groupId>de.saly</groupId>
<artifactId>javamail-mock2-halfmock</artifactId>
<version>0.5-beta3</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.5</version>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.5</version>
<version>1.7.7</version>
<scope>test</scope>

</dependency>
Expand Down Expand Up @@ -194,7 +187,7 @@

<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.4.1</version>
<version>2.5</version>
<configuration>
<filesets>
<fileset>
Expand Down Expand Up @@ -256,7 +249,7 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>1.2</version>
<version>1.3</version>
<executions>
<execution>
<phase>validate</phase>
Expand Down Expand Up @@ -301,10 +294,22 @@
<outputEncoding>UTF-8</outputEncoding>
</configuration>
</plugin>
<!--<plugin> <groupId>com.github.github</groupId> <artifactId>site-maven-plugin</artifactId>
<version>0.9</version> <configuration> <message>Building site for ${project.version}</message>
</configuration> <executions> <execution> <goals> <goal>site</goal> </goals>
<phase>site</phase> </execution> </executions> </plugin> -->
<plugin>
<groupId>com.github.github</groupId>
<artifactId>site-maven-plugin</artifactId>
<version>0.9</version>
<configuration>
<message>Building site for ${project.version}</message>
</configuration>
<executions>
<execution>
<goals>
<goal>site</goal>
</goals>
<phase>site</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>

Expand All @@ -328,7 +333,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jxr-plugin</artifactId>
<version>2.1</version>
<version>2.4</version>
</plugin>

<plugin>
Expand All @@ -340,7 +345,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.12</version>
<version>2.12.1</version>
<configuration>
<configLocation>buildconf/checkstyle/checkstyle.xml</configLocation>
<suppressionsLocation>buildconf/checkstyle/checkstyle-suppressions.xml</suppressionsLocation>
Expand Down Expand Up @@ -382,5 +387,38 @@
</plugins>
</build>
</profile>

<profile>
<id>release-sign-artifacts</id>
<activation>
<property>
<name>sign</name>
<value>true</value>
</property>
</activation>
<properties>
<gpg.keyname>7903F81190910A83</gpg.keyname>
<gpg.useagent>false</gpg.useagent>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>

</profiles>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ public class ElasticsearchMailDestination implements MailDestination {
private volatile boolean closed;

private volatile boolean error;

private volatile boolean started;

private String index;

private Map<String, Object> mapping;

private Map<String, Object> settings;

private volatile boolean started;

private boolean stripTagsFromTextContent = true;

private String type;
Expand Down Expand Up @@ -285,8 +285,10 @@ public ElasticsearchMailDestination setWithTextContent(final boolean withTextCon

@Override
public synchronized ElasticsearchMailDestination startup() throws IOException {

if(started) return this;

if (started) {
return this;
}
waitForCluster();
createIndexIfNotExists();
started = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,7 @@ protected void fetch(final Pattern pattern, final String folderName) throws Mess
}*/

if (pattern != null && !isRoot && !pattern.matcher(folder.getFullName()).matches()) {
logger.info(folder.getFullName() + " does not match pattern " + pattern.toString());
return;
}

Expand Down Expand Up @@ -494,7 +495,7 @@ protected void recurseFolders(final Folder folder, final Pattern pattern) throws
if ((folder.getType() & Folder.HOLDS_MESSAGES) != 0) {

if (pattern != null && !pattern.matcher(folder.getFullName()).matches()) {
logger.trace("Pattern {} does not match {}", pattern.pattern(), folder.getFullName());
logger.info("Pattern {} does not match {}", pattern.pattern(), folder.getFullName());
return;
}
IMAPUtils.open(folder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,15 @@ public static Build getInstance() {
return INSTANCE;
}

private final String version;
private final String date;

private final String hash;

private final String hashShort;

private final String timestamp;

private final String date;
private final String version;

Build(final String version, final String hash, final String hashShort, final String timestamp, final String date) {
this.version = version;
Expand Down
20 changes: 15 additions & 5 deletions src/main/java/de/saly/elasticsearch/river/imap/IMAPRiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.util.Map;
import java.util.Properties;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;

import javax.mail.MessagingException;

Expand Down Expand Up @@ -132,9 +133,10 @@ public IMAPRiver(final RiverName riverName, final RiverSettings riverSettings, f
true);

// get two maps from the river settings to improve index creation
final Map<String, Object> indexSettings = imapSettings.containsKey("index_settings") ? XContentMapValues.nodeMapValue(
final Map<String, Object> indexSettings = imapSettings.get("index_settings") != null ? XContentMapValues.nodeMapValue(
imapSettings.get("index_settings"), null) : null;
final Map<String, Object> typeMapping = imapSettings.containsKey("type_mapping") ? XContentMapValues.nodeMapValue(

final Map<String, Object> typeMapping = imapSettings.get("type_mapping") != null ? XContentMapValues.nodeMapValue(
imapSettings.get("type_mapping"), null) : null;

for (final Map.Entry<String, Object> entry : imapSettings.entrySet()) {
Expand Down Expand Up @@ -216,7 +218,11 @@ public void once() throws MessagingException, IOException {

logger.debug("once() start");
final MailFlowJob mfj = new MailFlowJob();
mfj.setPattern(folderPattern == null ? null : Pattern.compile(folderPattern));
try {
mfj.setPattern(folderPattern == null ? null : Pattern.compile(folderPattern));
} catch (final PatternSyntaxException e) {
logger.error("folderpattern is invalid due to {}", e, e.toString());
}
mfj.setMailSource(mailSource);
mfj.execute();
logger.debug("once() end");
Expand All @@ -242,8 +248,12 @@ public void start() {
final JobDataMap jdm = new JobDataMap();
jdm.put("mailSource", mailSource);

if (folderPattern != null) {
jdm.put("pattern", Pattern.compile(folderPattern));
try {
if (folderPattern != null) {
jdm.put("pattern", Pattern.compile(folderPattern));
}
} catch (final PatternSyntaxException e) {
logger.error("folderpattern is invalid due to {}", e, e.toString());
}

final JobDetail job = newJob(MailFlowJob.class).withIdentity(riverName + "-" + props.hashCode(), "group1").usingJobData(jdm)
Expand Down
Loading

0 comments on commit 9d7ad7e

Please sign in to comment.