diff -r a059aecd1794 -r e5bfc969d41f src/org/sonews/daemon/command/PostCommand.java --- a/src/org/sonews/daemon/command/PostCommand.java Sun Oct 30 22:15:03 2011 +0100 +++ b/src/org/sonews/daemon/command/PostCommand.java Sat Nov 05 00:06:09 2011 +0100 @@ -37,6 +37,7 @@ import org.sonews.storage.StorageManager; import org.sonews.feed.FeedManager; import org.sonews.util.Stats; +import org.sonews.util.io.SMTPInputStream; /** * Implementation of the POST command. This command requires multiple lines @@ -103,6 +104,7 @@ if ("".equals(line) || ".".equals(line)) { // we finally met the blank line // separating headers from body + // WTF: "." try { // Parse the header using the InternetHeader class from JavaMail API @@ -124,6 +126,7 @@ state = PostState.ReadingBody; + // WTF: do we need articles without bodies? if (".".equals(line)) { // Post an article without body postArticle(conn, article); @@ -138,7 +141,7 @@ headers.setHeader(Headers.LINES, Integer.toString(lineCount)); headers.setHeader(Headers.BYTES, Long.toString(bodySize)); - byte[] body = bufBody.toByteArray(); + byte[] body = unescapeDots(bufBody.toByteArray()); if (body.length >= 2) { // Remove trailing CRLF body = Arrays.copyOf(body, body.length - 2); @@ -213,7 +216,7 @@ if (conn.getUser() != null && conn.getUser().isAuthenticated()) { article.setAuthenticatedUser(conn.getUser().getUserName()); } - + if (article.getHeader(Headers.CONTROL)[0].length() > 0) { controlMessage(conn, article); } else if (article.getHeader(Headers.SUPERSEDES)[0].length() > 0) { @@ -273,4 +276,27 @@ } } } + + /** + * TODO: rework, integrate into NNTPConnection + * + * @param body message body with doubled dots + * @return message body with unescaped dots (.. → .) + */ + private static byte[] unescapeDots(byte[] body) throws IOException { + byte[] result = new byte[body.length]; + int resultLength = 0; + + ByteArrayInputStream escapedInput = new ByteArrayInputStream(body); + SMTPInputStream unescapedInput = new SMTPInputStream(escapedInput); + + int ch = unescapedInput.read(); + while (ch >= 0) { + result[resultLength] = (byte) ch; + resultLength++; + ch = unescapedInput.read(); + } + + return Arrays.copyOfRange(result, 0, resultLength); + } }