Skip to content

Commit

Permalink
Introduced attachments splitting
Browse files Browse the repository at this point in the history
* Added possibility to limit Email size and splitting it to several parts.
* Fixed bug when several emails are processed at once.
* Version increased: 0.0.4 -> 0.1.0
  • Loading branch information
domax committed Jul 1, 2015
1 parent c4793d3 commit b9eb297
Show file tree
Hide file tree
Showing 8 changed files with 259 additions and 76 deletions.
Binary file modified .gitignore
Binary file not shown.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -468,8 +468,6 @@ TODO

0. Add setting to delete emails into Trash folder instead of hard remove.
0. Add additional filtering emails by sender.
0. Fix bug when several emails are processed at once.
0. Add possibility to limit Email size and splitting it to several parts.
0. Setup ESW folder for data exchange, extend Config accordingly.
0. Include daemonizing feature - to allow user start, stop and check status of
service w/o additional complex scripts.
5 changes: 5 additions & 0 deletions data/config-template.properties
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,8 @@ email.recipients.to =
# Optional extension for encrypted file.
# Default value is ".enc"
#email.attach.ext.enc =

# Optional max size in megabytes of file attachment.
# If file size is bigger, it will be split to several parts.
# Default value is 5.
#email.attach.max.size =
8 changes: 7 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>org.exchange.git</groupId>
<artifactId>email-bridge</artifactId>
<version>0.0.4</version>
<version>0.1.0</version>
<packaging>jar</packaging>

<name>email-bridge</name>
Expand All @@ -23,6 +23,7 @@
<ews-java-api.version>2.0-SNAPSHOT</ews-java-api.version>
<argparse4j.version>0.5.0</argparse4j.version>
<commons-exec.version>1.3</commons-exec.version>
<zip4j.version>1.3.2</zip4j.version>
<slf4j.version>1.7.12</slf4j.version>
<junit.version>4.12</junit.version>
</properties>
Expand Down Expand Up @@ -107,6 +108,11 @@
<artifactId>commons-exec</artifactId>
<version>${commons-exec.version}</version>
</dependency>
<dependency>
<groupId>net.lingala.zip4j</groupId>
<artifactId>zip4j</artifactId>
<version>${zip4j.version}</version>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
Expand Down
19 changes: 17 additions & 2 deletions src/main/java/org/mail/bridge/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public class Config {
private final boolean emailAttachGzip;
private final String emailAttachExtGzip;
private final String emailAttachExtEnc;
private final int emailAttachMaxSize;

public Config(String propertiesFileName) throws IOException {
Properties config = new Properties();
Expand Down Expand Up @@ -159,9 +160,11 @@ public Config(String propertiesFileName) throws IOException {
emailAttachGzip = !s.isEmpty() && Boolean.parseBoolean(s);

s = config.getProperty("email.attach.ext.gzip", "");
emailAttachExtGzip = s.isEmpty() ? ".gz" : s;
emailAttachExtGzip = checkExt(s.isEmpty() ? ".gz" : s);
s = config.getProperty("email.attach.ext.enc", "");
emailAttachExtEnc = s.isEmpty() ? ".enc" : s;
emailAttachExtEnc = checkExt(s.isEmpty() ? ".enc" : s);
s = config.getProperty("email.attach.max.size", "");
emailAttachMaxSize = s.isEmpty() ? 5 : Integer.parseInt(s);
}

public String getEwsEmail() {
Expand Down Expand Up @@ -284,6 +287,10 @@ public String getEmailAttachExtEnc() {
return emailAttachExtEnc;
}

public int getEmailAttachMaxSize() {
return emailAttachMaxSize;
}

public Map<String, String> asEnvironmentMap() {
Map<String, String> result = new HashMap<>();
result.put("EWS_EMAIL", ewsEmail);
Expand Down Expand Up @@ -316,9 +323,16 @@ public Map<String, String> asEnvironmentMap() {
result.put("EMAIL_ATTACH_GZIP", "" + emailAttachGzip);
result.put("EMAIL_ATTACH_EXT_GZIP", emailAttachExtGzip);
result.put("EMAIL_ATTACH_EXT_ENC", emailAttachExtEnc);
result.put("EMAIL_ATTACH_MAX_SIZE", "" + emailAttachMaxSize);
return result;
}

private String checkExt(String ext) throws IOException {
if (ext.matches("^\\.z\\d\\d$"))
throw new IOException(String.format("Extension '%s' is reserved for inner usage", ext));
return ext;
}

@Override
public String toString() {
return "Config {" +
Expand Down Expand Up @@ -352,6 +366,7 @@ public String toString() {
",\n\temailAttachGzip=" + emailAttachGzip +
",\n\temailAttachExtGzip='" + emailAttachExtGzip + '\'' +
",\n\temailAttachExtEnc='" + emailAttachExtEnc + '\'' +
",\n\temailAttachMaxSize=" + emailAttachMaxSize +
'}';
}
}
Loading

0 comments on commit b9eb297

Please sign in to comment.