1 /*
2 * Copyright (C) The Apache Software Foundation. All rights reserved.
3 *
4 * This software is published under the terms of the Apache Software License
5 * version 1.1, a copy of which has been included with this distribution in
6 * the LICENSE file.
7 */
8 package org.apache.james.util;
9
10 import java.io.FilterOutputStream;
11 import java.io.IOException;
12 import java.io.OutputStream;
13
14 /***
15 * Adds extra dot if dot occurs in message body at beginning of line (according to RFC1939)
16 * Compare also org.apache.james.smtpserver.SMTPInputStream
17 *
18 * @author Stephan Schiessling <s@rapi.com>
19 */
20 public class ExtraDotOutputStream extends FilterOutputStream {
21
22 /***
23 * Counter for number of last (0A or 0D).
24 */
25 protected int countLast0A0D;
26
27 /***
28 * Constructor that wraps an OutputStream.
29 *
30 * @param out the OutputStream to be wrapped
31 */
32 public ExtraDotOutputStream(OutputStream out) {
33 super(out);
34 countLast0A0D = 2; // we already assume a CRLF at beginning (otherwise TOP would not work correctly !)
35 }
36
37 /***
38 * Writes a byte to the stream, adding dots where appropriate.
39 *
40 * @param b the byte to write
41 *
42 * @throws IOException if an error occurs writing the byte
43 */
44 public void write(int b) throws IOException {
45 out.write(b);
46 if (b == '.') {
47 if (countLast0A0D > 1) {
48 // add extra dot
49 out.write('.');
50 }
51 countLast0A0D = 0;
52 } else {
53 if (b == '\r' || b == '\n') {
54 countLast0A0D++;
55 } else {
56 countLast0A0D = 0;
57 }
58 }
59 }
60
61 }
62
This page was automatically generated by Maven