1
2
3
4
5
6
7
8
9
10
11
12
13 package org.abstracthorizon.mercury.smtp.command;
14
15 import java.io.IOException;
16
17 import org.abstracthorizon.mercury.common.command.CommandException;
18 import org.abstracthorizon.mercury.smtp.SMTPResponse;
19 import org.abstracthorizon.mercury.smtp.SMTPScanner;
20 import org.abstracthorizon.mercury.smtp.SMTPSession;
21 import org.abstracthorizon.mercury.smtp.exception.ParserException;
22
23
24
25
26
27
28 public class EhloCommand extends ResetCommand {
29
30
31
32
33 public EhloCommand() {
34 }
35
36
37
38
39
40
41
42
43 protected void execute(SMTPSession connection) throws CommandException, IOException, ParserException {
44
45
46
47
48
49 SMTPScanner scanner = connection.getScanner();
50 if (!scanner.is_char(' ')) { throw new ParserException("space"); }
51
52
53 boolean bracked = scanner.is_char('[');
54 StringBuffer domain = new StringBuffer();
55 if (!scanner.domain(domain)) { throw new ParserException("domain"); }
56 if (bracked) {
57 if (!scanner.is_char(']')) { throw new ParserException("]"); }
58 }
59
60 readExtraParameters(connection, scanner);
61
62 String domainStr = domain.toString();
63 connection.getMailSessionData().setSourceDomain(domainStr);
64 processEHLO(connection, domainStr);
65 }
66
67
68
69
70
71
72
73
74
75
76 protected void readExtraParameters(SMTPSession connection, SMTPScanner scanner) throws IOException, ParserException, CommandException {
77 scanner.check_eol();
78 }
79
80
81
82
83
84
85
86 protected void processEHLO(SMTPSession connection, String domain) throws IOException {
87 resetSession(connection);
88 connection.setState(SMTPSession.STATE_READY);
89 SMTPResponse ehloResponse = new SMTPResponse(250, connection.getConnectionHandler().getStorageManager().getMainDomain());
90 connection.sendResponse(ehloResponse);
91 }
92
93 }