0N/A/*
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
0N/A *
721N/A * Copyright (c) 1997-2015 Oracle and/or its affiliates. All rights reserved.
0N/A *
0N/A * The contents of this file are subject to the terms of either the GNU
0N/A * General Public License Version 2 only ("GPL") or the Common Development
0N/A * and Distribution License("CDDL") (collectively, the "License"). You
292N/A * may not use this file except in compliance with the License. You can
292N/A * obtain a copy of the License at
292N/A * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
292N/A * or packager/legal/LICENSE.txt. See the License for the specific
0N/A * language governing permissions and limitations under the License.
0N/A *
0N/A * When distributing the software, include this License Header Notice in each
292N/A * file and include the License file at packager/legal/LICENSE.txt.
292N/A *
292N/A * GPL Classpath Exception:
292N/A * Oracle designates this particular file as subject to the "Classpath"
292N/A * exception as provided by Oracle in the GPL Version 2 section of the License
292N/A * file that accompanied this code.
292N/A *
292N/A * Modifications:
292N/A * If applicable, add the following below the License Header, with the fields
292N/A * enclosed by brackets [] replaced by your own identifying information:
292N/A * "Portions Copyright [year] [name of copyright owner]"
0N/A *
0N/A * Contributor(s):
0N/A * If you wish your version of this file to be governed by only the CDDL or
0N/A * only the GPL Version 2, indicate your decision by adding "[Contributor]
0N/A * elects to include this software in this distribution under the [CDDL or GPL
0N/A * Version 2] license." If you don't indicate a single choice of license, a
0N/A * recipient has the option to distribute your version of this file under
0N/A * either the CDDL, the GPL Version 2 or to extend the choice of license to
0N/A * its licensees as provided above. However, if you add GPL Version 2 code
0N/A * and therefore, elected the GPL Version 2 license, then the option applies
0N/A * only if the new code is made subject to such option by the copyright
0N/A * holder.
0N/A */
0N/A
0N/Apackage com.sun.mail.smtp;
0N/A
0N/Aimport java.io.*;
0N/Aimport com.sun.mail.util.CRLFOutputStream;
0N/A
0N/A/**
0N/A * In addition to converting lines into the canonical format,
0N/A * i.e., terminating lines with the CRLF sequence, escapes the "."
0N/A * by adding another "." to any "." that appears in the beginning
0N/A * of a line. See RFC821 section 4.5.2.
0N/A *
0N/A * @author Max Spivak
0N/A * @see CRLFOutputStream
0N/A */
0N/Apublic class SMTPOutputStream extends CRLFOutputStream {
0N/A public SMTPOutputStream(OutputStream os) {
0N/A super(os);
0N/A }
0N/A
0N/A public void write(int b) throws IOException {
0N/A // if that last character was a newline, and the current
0N/A // character is ".", we always write out an extra ".".
0N/A if ((lastb == '\n' || lastb == '\r' || lastb == -1) && b == '.') {
0N/A out.write('.');
0N/A }
0N/A
0N/A super.write(b);
0N/A }
0N/A
0N/A /*
0N/A * This method has been added to improve performance.
0N/A */
0N/A public void write(byte b[], int off, int len) throws IOException {
0N/A int lastc = (lastb == -1) ? '\n' : lastb;
0N/A int start = off;
0N/A
0N/A len += off;
0N/A for (int i = off; i < len; i++) {
0N/A if ((lastc == '\n' || lastc == '\r') && b[i] == '.') {
0N/A super.write(b, start, i - start);
0N/A out.write('.');
0N/A start = i;
0N/A }
0N/A lastc = b[i];
0N/A }
0N/A if ((len - start) > 0)
0N/A super.write(b, start, len - start);
0N/A }
0N/A
0N/A /**
0N/A * Override flush method in FilterOutputStream.
0N/A *
0N/A * The MimeMessage writeTo method flushes its buffer at the end,
0N/A * but we don't want to flush data out to the socket until we've
0N/A * also written the terminating "\r\n.\r\n".
0N/A *
0N/A * We buffer nothing so there's nothing to flush. We depend
0N/A * on the fact that CRLFOutputStream also buffers nothing.
0N/A * SMTPTransport will manually flush the socket before reading
0N/A * the response.
0N/A */
0N/A public void flush() {
0N/A // do nothing
0N/A }
0N/A
0N/A /**
0N/A * Ensure we're at the beginning of a line.
0N/A * Write CRLF if not.
721N/A *
721N/A * @exception IOException if the write fails
0N/A */
0N/A public void ensureAtBOL() throws IOException {
0N/A if (!atBOL)
0N/A super.writeln();
0N/A }
0N/A}