1 22 package gnu.mail.providers.smtp; 23 24 import java.io.*; 25 import gnu.mail.util.CRLFOutputStream; 26 27 35 public class SMTPOutputStream 36 extends FilterOutputStream 37 { 38 39 42 public static final int LF = 0x0a; 43 44 47 public static final int DOT = 0x2e; 48 49 52 protected int last; 53 54 60 public SMTPOutputStream(CRLFOutputStream out) 61 { 62 super(out); 63 } 64 65 69 public void write(int ch) 70 throws IOException 71 { 72 if (ch==DOT) 73 { 74 if (last==LF) 75 out.write(DOT); 76 } 77 out.write(ch); 78 last = ch; 79 } 80 81 85 public void write(byte b[]) 86 throws IOException 87 { 88 write(b, 0, b.length); 89 } 90 91 95 public void write(byte b[], int off, int len) 96 throws IOException 97 { 98 int d = off; 99 len += off; 100 for (int i=off; i<len; i++) 101 { 102 switch (b[i]) 103 { 104 case DOT: 105 int l = (i-d); 106 if (l>0) 107 out.write(b, d, l); 108 d = i; 109 if (last==LF) 110 out.write(DOT); 111 break; 112 } 113 last = b[i]; 114 } 115 if (len-d>0) 116 out.write(b, d, len-d); 117 } 118 119 } 120 | Popular Tags |