| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
package org.xwiki.mail.internal.factory.files; |
| 21 |
|
|
| 22 |
|
import java.io.File; |
| 23 |
|
import java.io.FileInputStream; |
| 24 |
|
import java.io.FileNotFoundException; |
| 25 |
|
import java.util.Map; |
| 26 |
|
|
| 27 |
|
import javax.mail.MessagingException; |
| 28 |
|
|
| 29 |
|
import org.slf4j.Logger; |
| 30 |
|
import org.slf4j.LoggerFactory; |
| 31 |
|
import org.xwiki.component.manager.ComponentLookupException; |
| 32 |
|
import org.xwiki.component.manager.ComponentManager; |
| 33 |
|
import org.xwiki.environment.Environment; |
| 34 |
|
import org.xwiki.mail.ExtendedMimeMessage; |
| 35 |
|
import org.xwiki.mail.internal.factory.AbstractMessageIterator; |
| 36 |
|
|
| 37 |
|
|
| 38 |
|
|
| 39 |
|
|
| 40 |
|
@version |
| 41 |
|
@since |
| 42 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (17) |
Complexity: 5 |
Complexity Density: 0.36 |
|
| 43 |
|
public class SerializedFilesMimeMessageIterator extends AbstractMessageIterator |
| 44 |
|
{ |
| 45 |
|
private static final Logger LOGGER = LoggerFactory.getLogger(SerializedFilesMimeMessageIterator.class); |
| 46 |
|
|
| 47 |
|
|
| 48 |
|
|
| 49 |
|
|
| 50 |
|
private static final String ROOT_DIRECTORY = "mailstore"; |
| 51 |
|
|
| 52 |
|
private final File[] files; |
| 53 |
|
|
| 54 |
|
private ComponentManager componentManager; |
| 55 |
|
|
| 56 |
|
private Environment environment; |
| 57 |
|
|
| 58 |
|
private File batchDirectory; |
| 59 |
|
|
| 60 |
|
|
| 61 |
|
@param |
| 62 |
|
@param |
| 63 |
|
@param |
| 64 |
|
@throws |
| 65 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 2 |
Complexity Density: 0.25 |
|
| 66 |
3 |
public SerializedFilesMimeMessageIterator(String batchId, Map<String, Object> parameters,... |
| 67 |
|
ComponentManager componentManager) throws MessagingException |
| 68 |
|
{ |
| 69 |
3 |
this.componentManager = componentManager; |
| 70 |
3 |
try { |
| 71 |
3 |
this.environment = this.componentManager.getInstance(Environment.class); |
| 72 |
|
} catch (ComponentLookupException e) { |
| 73 |
1 |
throw new MessagingException("Failed to find an Environment Component", e); |
| 74 |
|
} |
| 75 |
2 |
this.batchDirectory = |
| 76 |
|
new File(new File(this.environment.getPermanentDirectory(), ROOT_DIRECTORY), batchId); |
| 77 |
2 |
this.files = this.batchDirectory.listFiles(); |
| 78 |
2 |
this.iteratorSize = this.files.length; |
| 79 |
2 |
this.parameters = parameters; |
| 80 |
|
} |
| 81 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.4 |
|
| 82 |
4 |
@Override... |
| 83 |
|
protected ExtendedMimeMessage createMessageInternal() throws MessagingException |
| 84 |
|
{ |
| 85 |
4 |
File file = this.files[this.position]; |
| 86 |
4 |
try { |
| 87 |
4 |
FileInputStream emailStream = new FileInputStream(file); |
| 88 |
|
|
| 89 |
|
|
| 90 |
3 |
return new ExtendedMimeMessage(null, emailStream); |
| 91 |
|
} catch (FileNotFoundException e) { |
| 92 |
1 |
throw new MessagingException( |
| 93 |
|
String.format("Failed to create mime message from file [%s]", file.getPath()), e); |
| 94 |
|
} |
| 95 |
|
} |
| 96 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 97 |
1 |
@Override... |
| 98 |
|
protected Logger getLogger() |
| 99 |
|
{ |
| 100 |
1 |
return LOGGER; |
| 101 |
|
} |
| 102 |
|
} |