Skip to content
This repository has been archived by the owner on Apr 19, 2021. It is now read-only.

"From:" header field has been lost in received-emails. #26

Closed
baal opened this issue Mar 15, 2015 · 11 comments
Closed

"From:" header field has been lost in received-emails. #26

baal opened this issue Mar 15, 2015 · 11 comments

Comments

@baal
Copy link

baal commented Mar 15, 2015

"From:" is not found in received email file.

@Vest
Copy link
Contributor

Vest commented Apr 13, 2015

I have run integration tests, as was specified in the documentation. All emails have the "From:" field. E.g.:

Date: Mon, 13 Apr 2015 17:50:02 +0200 (CEST)
From: Me <me@example.org>
To: John Doe <jdoe@somewhere.org>

Could you please tell us how to reproduce the issue?

@baal
Copy link
Author

baal commented Apr 17, 2015

Thank you for reply.
Please run this.

import java.io.*;
import java.net.*;

public class SMTPTest {
    public static void main(String[] args) {
        try {
            try (Socket so = new Socket("127.0.0.1", 25)) {
                try (DataOutputStream send = new DataOutputStream(so.getOutputStream())) {
                    try (BufferedReader recv = new BufferedReader(new InputStreamReader(so.getInputStream()))) {
                        String msg;
                        msg = "HELO 127.0.0.1\r\n";
                        send.writeBytes(msg);
                        System.out.println(msg);
                        msg = recv.readLine();
                        System.out.println(msg);
                        msg = "MAIL FROM: info@example.com\r\n";
                        send.writeBytes(msg);
                        System.out.println(msg);
                        msg = recv.readLine();
                        System.out.println(msg);
                        msg = "RCPT TO: test1@example.com\r\n";
                        send.writeBytes(msg);
                        System.out.println(msg);
                        msg = recv.readLine();
                        System.out.println(msg);
                        msg = "RCPT TO: test2@example.com\r\n";
                        send.writeBytes(msg);
                        System.out.println(msg);
                        msg = recv.readLine();
                        System.out.println(msg);
                        msg = "RCPT TO: test3@example.com\r\n";
                        send.writeBytes(msg);
                        System.out.println(msg);
                        msg = recv.readLine();
                        System.out.println(msg);
                        msg = "DATA\r\n"
                            + "From: =?ISO-2022-JP?B?GyRCJCIkJCQmJCgkKhsoQg==?= <info@example.com>\r\n"
                            + "Subject: =?ISO-2022-JP?B?GyRCJCIkJCQmJCgkKhsoQg==?=\r\n"
                            + "To: test1@example.com, test2@example.com, test3@example.com\r\n"
                            + "Content-Type: text/plain; charset=ISO-2022-JP\r\n"
                            + "Content-Transfer-Encoding: 7bit\r\n"
                            + "MIME-Version: 1.0\r\n"
                            + "Date: Fri, 12 Apr 2015 12:00:00 +0900\r\n"
                            + "Message-ID: TEST\r\n"
                            + "\r\n"
                            + "TEST\r\n"
                            + ".\r\n";
                        send.writeBytes(msg);
                        System.out.println(msg);
                        msg = recv.readLine();
                        System.out.println(msg);
                        msg = "QUIT.\r\n";
                        send.writeBytes(msg);
                        System.out.println(msg);
                        msg = recv.readLine();
                        System.out.println(msg);
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

@Vest
Copy link
Contributor

Vest commented Apr 19, 2015

I had to add this part right before "DATA":

msg = recv.readLine();
System.out.println(msg);
msg = "DATA\r\n" ...

Otherwise, I get java.net.SocketException: Software caused connection abort: recv failed.
I have found out that if you put the "Date" line in DATA right before "From", the sender email is displayed. However, what I couldn't figure out yet is why the "Date" field is not shown in the resulted eml-file.
Could you please verify my workaround?
workaround

@caarmen
Copy link

caarmen commented May 1, 2015

I confirm that if there are multiple recipients (multiple RCPT TO commands), the first header of the message data is lost. It could be "From:" or another header, depending on the mail client. This doesn't happen if there is just one RCPT TO command.

@caarmen
Copy link

caarmen commented May 1, 2015

One recipient:

telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 192.168.1.4 ESMTP SubEthaSMTP null
helo me@me.com
250 192.168.1.4
mail from: jdoe@gmail.com
250 Ok
rcpt to: jsmith@gmail.com
250 Ok
data
354 End data with <CR><LF>.<CR><LF>
Foo: bar
Foo: baz
From: jdoe@gmail.com
To: jsmith@gmail.com
Subject: test

asfd asfd


.
250 Ok
quit
221 Bye

Results in this mail (all ok):

Foo: bar
Foo: baz
From: jdoe@gmail.com
To: jsmith@gmail.com
Subject: test

asfd asfd

Two recipients:

telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 192.168.1.4 ESMTP SubEthaSMTP null
helo me@me.com
250 192.168.1.4
mail from: jdoe@gmail.com
250 Ok
rcpt to: jsmith@gmail.com
250 Ok
rcpt to: jsmith2@gmail.com
250 Ok
data
354 End data with <CR><LF>.<CR><LF>
Foo: bar
Foo: baz
From: jdoe@gmail.com
To: jsmith@gmail.com
Subject: test

asfd asfd


.
250 Ok
quit
221 Bye

Results in this mail, missing the "Foo: bar" header:

Foo: baz
From: jdoe@gmail.com
To: jsmith@gmail.com
Subject: test

asfd asfd

@caarmen
Copy link

caarmen commented May 1, 2015

If I modify the pom.xml to use version 3.1.7 of the subethasmtp library (instead of 3.1.6), the issue goes away.

@caarmen
Copy link

caarmen commented May 1, 2015

Looks like it's fixed in this commit of subethasmtp:
voodoodyne/subethasmtp@34e8a14#diff-15d4579aba4b63fa6c644f58d6af4692R45

By this change in ReceivedHeaderStream.java:

        StringBuilder header = new StringBuilder();
        header.append("Received: from " + heloHost + " (" + constructTcpInfo(host) + ")\r\n");
-       header.append("        by " + whoami + " with SMTP");
+       header.append("        by " + whoami + "\r\n");
+       header.append("        with SMTP");
        if (softwareName != null)
            header.append(" (" + softwareName + ")");

@Vest
Copy link
Contributor

Vest commented May 4, 2015

@caarmen, can you prepare a small pull request with the new pom.xml file?

caarmen added a commit to caarmen/FakeSMTP that referenced this issue May 4, 2015
@caarmen
Copy link

caarmen commented May 4, 2015

Pull request created: #28

@Nilhcem
Copy link
Owner

Nilhcem commented May 4, 2015

Many thanks to everyone for having found and contributed to this issue.
I will see what I can do this week end.
You are right, best option would be to completely remove the ability to restart the server, as the missing header is a bigger issue.

Nilhcem added a commit that referenced this issue May 8, 2015
The subethaSMTP upgrade that fixes multiple issues, such as #26
forbids us to restart the server.
@Nilhcem
Copy link
Owner

Nilhcem commented May 8, 2015

FakeSMTP 2.0 is now released with subethasmtp 3.1.7.
http://nilhcem.github.io/FakeSMTP/

It should fix the issue.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants