Nilhcem/FakeSMTP

handling of lines starting with . is not quite right

Opened this issue · 1 comments

In SMTP lines starting with . have to be changed to two dots to avoid the problem with eof . at the end.
It looks like currently the smtp server removes one . at the first line of the mail data, but not on the following lines.

To verify this, send a mail containing two lines with a single dot each (assuming that your client correctly converts the lines), the mail data will look like this

DATA
Subject: xxx

..
..
.

The received mail then looks like this

Subject: xxx

.
..
Vest commented

Here is what I found out:
My test case was based on integration tests:

@Test
public void sendEmailWithDots() throws EmailException {
    Email email = new SimpleEmail();
    email.setDebug(true);
    email.setHostName(TestConfig.HOST);
    email.setSmtpPort(TestConfig.PORT_INTEGRATION_TESTS);
    email.setFrom("user@gmail.com");
    email.setSubject("xxx");
    email.setMsg(".\n.");       
    email.addTo("foo@bar.com");
    email.send();
}

If you run this test with FakeSMTP, you will get the message correctly:

Date: Thu, 14 May 2015 09:55:18 +0200 (CEST)
From: user@gmail.com
To: foo@bar.com
Message-ID: <1241276575.0.1431590118127.JavaMail.me@mars.com>
Subject: xxx
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

.
.

However, a similar application DevNull SMTP creates exactly what you wrote, or maybe one leading period less.
According to RFC 5321 - SMTP: 4.5.2. Transparency:

  • Before sending a line of mail text, the SMTP client checks the first character of the line. If it is a period, one additional period is inserted at the beginning of the line.
  • When a line of mail text is received by the SMTP server, it checks the line. <...> If the first character is a period and there are other characters on the line, the first character is deleted.
    Could you please verify my test on the latest release version, or give us an example code how to reproduce the issue.

By the way, if @Nilhcem allows, I can add this integration test to the project: d1d8230