Skip to content

Commit

Permalink
JSIEVE-103 Integrate storage time for scripts and current date to res…
Browse files Browse the repository at this point in the history
…ource locators
  • Loading branch information
chibenwa committed Mar 2, 2016
1 parent 57de095 commit 8e7edd2
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 8 deletions.
Expand Up @@ -21,6 +21,7 @@
package org.apache.james.sieverepository.api;

import java.io.InputStream;
import java.util.Date;
import java.util.List;

import org.apache.james.sieverepository.api.exception.DuplicateException;
Expand All @@ -37,7 +38,7 @@
* <code>SieveRepository</code>
*/
public interface SieveRepository {

void haveSpace(String user, String name, long size) throws UserNotFoundException, QuotaExceededException, StorageException;

/**
Expand All @@ -57,6 +58,8 @@ public interface SieveRepository {
List<ScriptSummary> listScripts(String user) throws UserNotFoundException, StorageException;

InputStream getActive(String user) throws UserNotFoundException, ScriptNotFoundException, StorageException;

Date getActivationDateForActiveScript(String user) throws StorageException, UserNotFoundException, ScriptNotFoundException;

void setActive(String user, String name) throws UserNotFoundException, ScriptNotFoundException, StorageException;

Expand Down
Expand Up @@ -24,6 +24,7 @@
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.Date;
import java.util.List;

import javax.inject.Inject;
Expand Down Expand Up @@ -78,13 +79,22 @@ public InputStream getActive(String user) throws UserNotFoundException, ScriptNo
}
}

public File retrieveUserFile(String user) throws FileNotFoundException {
@Override
public Date getActivationDateForActiveScript(String user) throws StorageException, UserNotFoundException, ScriptNotFoundException {
return new Date(retrieveUserFile(user).lastModified());
}

public File retrieveUserFile(String user) throws ScriptNotFoundException {
// RFC 5228 permits extensions: .siv .sieve
String sieveFilePrefix = FileSystem.FILE_PROTOCOL + "sieve/" + user + ".";
try {
return fileSystem.getFile(sieveFilePrefix + "sieve");
} catch (FileNotFoundException e) {
return fileSystem.getFile(sieveFilePrefix + "siv");
try {
return fileSystem.getFile(sieveFilePrefix + "siv");
} catch (FileNotFoundException fileNotFoundException) {
throw new ScriptNotFoundException(fileNotFoundException);
}
}
}

Expand Down
Expand Up @@ -43,8 +43,10 @@
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.Scanner;
Expand Down Expand Up @@ -294,6 +296,10 @@ public InputStream getActive(String user) throws UserNotFoundException,
return script;
}

public Date getActivationDateForActiveScript(String user) throws StorageException, UserNotFoundException, ScriptNotFoundException {
return new Date(getActiveFile(user).lastModified());
}

@Override
public void setActive(String user, String name) throws UserNotFoundException,
ScriptNotFoundException, StorageException {
Expand Down
Expand Up @@ -19,12 +19,12 @@

package org.apache.james.transport.mailets;

import java.io.InputStream;

import org.apache.james.sieverepository.api.SieveRepository;
import org.apache.james.sieverepository.api.exception.SieveRepositoryException;
import org.apache.jsieve.mailet.ResourceLocator;

import java.util.Date;

public class ResourceLocatorImpl implements ResourceLocator {

private final boolean virtualHosting;
Expand All @@ -35,7 +35,7 @@ public ResourceLocatorImpl(boolean virtualHosting, SieveRepository sieveReposito
this.sieveRepository = sieveRepository;
}

public InputStream get(String uri) throws SieveRepositoryException {
public UserSieveInformation get(String uri) throws SieveRepositoryException {
// Use the complete email address for finding the sieve file
uri = uri.substring(2);

Expand All @@ -46,6 +46,6 @@ public InputStream get(String uri) throws SieveRepositoryException {
username = uri.substring(0, uri.indexOf("@"));
}

return sieveRepository.getActive(username);
return new UserSieveInformation(sieveRepository.getActivationDateForActiveScript(username), new Date(), sieveRepository.getActive(username));
}
}
Expand Up @@ -52,6 +52,6 @@ public void resourceLocatorImplShouldPropagateScriptNotFound() throws Exception
public void resourceLocatorImplShouldWork() throws Exception {
InputStream inputStream = new ByteArrayInputStream(new byte[0]);
when(sieveRepository.getActive("receiver@localhost")).thenReturn(inputStream);
assertThat(resourceLocator.get("//receiver@localhost/sieve")).isEqualTo(inputStream);
assertThat(resourceLocator.get("//receiver@localhost/sieve").getScriptContent()).isEqualTo(inputStream);
}
}

0 comments on commit 8e7edd2

Please sign in to comment.