Skip to content

Commit 620424a

Browse files
author
gm2552
committed
Removing dependencies to James 2.3.2 libraries.
The james library is no longer available in the main maven repo. Copying the MessagingSizeException and SizeLimiteInputStream classes from the old library.
1 parent 4529753 commit 620424a

5 files changed

Lines changed: 93 additions & 15 deletions

File tree

pom.xml

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -134,18 +134,7 @@
134134
<groupId>javax.mail</groupId>
135135
</exclusion>
136136
</exclusions>
137-
</dependency>
138-
<dependency>
139-
<groupId>org.apache.james</groupId>
140-
<artifactId>james</artifactId>
141-
<version>2.3.2</version>
142-
<exclusions>
143-
<exclusion>
144-
<artifactId>mail</artifactId>
145-
<groupId>javax.mail</groupId>
146-
</exclusion>
147-
</exclusions>
148-
</dependency>
137+
</dependency>
149138
<dependency>
150139
<groupId>commons-net</groupId>
151140
<artifactId>commons-net</artifactId>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package org.nhindirect.smtpmq.gateway.server;
2+
3+
import java.io.IOException;
4+
5+
/**
6+
* Taken from the apache james 2.3.2 server which is no longer in the main maven repository.
7+
*
8+
*/
9+
public class MessageSizeException extends IOException
10+
{
11+
/**
12+
*
13+
*/
14+
private static final long serialVersionUID = 420903468326823983L;
15+
16+
/**
17+
* Sole contructor for this class. This constructor sets
18+
* the exception message to a fixed error message.
19+
*/
20+
public MessageSizeException() {
21+
super("Message size exceeds fixed maximum message size.");
22+
}
23+
}

src/main/java/org/nhindirect/smtpmq/gateway/server/SMTPMessageHandler.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
import org.apache.commons.io.IOUtils;
1717
import org.apache.commons.io.input.CountingInputStream;
18-
import org.apache.james.smtpserver.MessageSizeException;
1918
import org.nhindirect.common.mail.SMTPMailMessage;
2019
import org.nhindirect.smtpmq.gateway.streams.SmtpGatewayMessageSource;
2120
import org.slf4j.Logger;
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package org.nhindirect.smtpmq.gateway.server;
2+
3+
import java.io.IOException;
4+
import java.io.InputStream;
5+
6+
7+
/**
8+
* Taken from the apache james 2.3.2 server which is no longer in the main maven repository.
9+
*
10+
*/
11+
public class SizeLimitedInputStream extends InputStream
12+
{
13+
/**
14+
* Maximum number of bytes to read.
15+
*/
16+
private long maxmessagesize = 0;
17+
/**
18+
* Running total of bytes read from wrapped stream.
19+
*/
20+
private long bytesread = 0;
21+
22+
/**
23+
* InputStream that will be wrapped.
24+
*/
25+
private InputStream in = null;
26+
27+
/**
28+
* Constructor for the stream. Wraps an underlying stream.
29+
* @param in InputStream to use as basis for new Stream.
30+
* @param maxmessagesize Message size limit, in Kilobytes
31+
*/
32+
public SizeLimitedInputStream(InputStream in, long maxmessagesize) {
33+
this.in = in;
34+
this.maxmessagesize = maxmessagesize;
35+
}
36+
37+
/**
38+
* Overrides the read method of InputStream to call the read() method of the
39+
* wrapped input stream.
40+
* @throws IOException Throws a MessageSizeException, which is a sub-type of IOException
41+
* @return Returns the number of bytes read.
42+
*/
43+
public int read(byte[] b, int off, int len) throws IOException {
44+
int l = in.read(b, off, len);
45+
46+
bytesread += l;
47+
48+
if (maxmessagesize > 0 && bytesread > maxmessagesize) {
49+
throw new MessageSizeException();
50+
}
51+
52+
return l;
53+
}
54+
55+
/**
56+
* Overrides the read method of InputStream to call the read() method of the
57+
* wrapped input stream.
58+
* @throws IOException Throws a MessageSizeException, which is a sub-type of IOException.
59+
* @return Returns the int character value of the byte read.
60+
*/
61+
public int read() throws IOException {
62+
if (maxmessagesize > 0 && bytesread <= maxmessagesize) {
63+
bytesread++;
64+
return in.read();
65+
} else {
66+
throw new MessageSizeException();
67+
}
68+
}
69+
}

src/main/java/org/nhindirect/smtpmq/gateway/server/SizeLimitedInputStreamFactory.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
import java.io.InputStream;
44

5-
import org.apache.james.smtpserver.SizeLimitedInputStream;
6-
75
public class SizeLimitedInputStreamFactory
86
{
97
private static SizeLimitedInputStreamFactory instance = new SizeLimitedInputStreamFactory();

0 commit comments

Comments
 (0)