Skip to content

Commit 755aa56

Browse files
committed
[ENHANCEMENT] Dedicated debug logs for significant SMTP details
Failing hooks are also logged at INFO
1 parent b87d20a commit 755aa56

File tree

5 files changed

+22
-5
lines changed

5 files changed

+22
-5
lines changed

protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/HeloCmdHandler.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
import jakarta.inject.Inject;
2525

26+
import org.apache.commons.lang3.StringUtils;
2627
import org.apache.james.metrics.api.MetricFactory;
2728
import org.apache.james.protocols.api.ProtocolSession;
2829
import org.apache.james.protocols.api.ProtocolSession.State;
@@ -82,6 +83,8 @@ protected Response doCoreCmd(SMTPSession session, String command,
8283
response.append(session.getConfiguration().getHelloName()).append(
8384
" Hello ").append(parameters).append(" [").append(
8485
session.getRemoteAddress().getAddress().getHostAddress()).append("])");
86+
87+
LOGGER.debug("HELO {} {}", StringUtils.abbreviate(command, 80), StringUtils.abbreviate(parameters, 80));
8588
return new SMTPResponse(SMTPRetCode.MAIL_OK, response);
8689
}
8790

protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/MailCmdHandler.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import jakarta.inject.Inject;
3030
import jakarta.mail.internet.AddressException;
3131

32+
import org.apache.commons.lang3.StringUtils;
3233
import org.apache.james.core.MailAddress;
3334
import org.apache.james.core.MaybeSender;
3435
import org.apache.james.metrics.api.MetricFactory;
@@ -110,6 +111,8 @@ private Response doMAIL(SMTPSession session) {
110111
responseBuffer.append(sender.asString());
111112
}
112113
responseBuffer.append("> OK");
114+
115+
LOGGER.debug("MAIL FROM {}", StringUtils.abbreviate(sender.asString(), 80));
113116
return new SMTPResponse(SMTPRetCode.MAIL_OK, responseBuffer);
114117
}
115118

protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/QuitCmdHandler.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,24 @@
3131
import org.apache.james.protocols.smtp.dsn.DSNStatus;
3232
import org.apache.james.protocols.smtp.hook.HookResult;
3333
import org.apache.james.protocols.smtp.hook.QuitHook;
34+
import org.slf4j.Logger;
35+
import org.slf4j.LoggerFactory;
3436

3537
import com.google.common.collect.ImmutableSet;
3638

3739
/**
3840
* Handles QUIT command
3941
*/
4042
public class QuitCmdHandler extends AbstractHookableCmdHandler<QuitHook> {
43+
private static final Logger LOGGER = LoggerFactory.getLogger(QuitCmdHandler.class);
4144

4245
/**
4346
* The name of the command handled by the command handler
4447
*/
4548
private static final Collection<String> COMMANDS = ImmutableSet.of("QUIT");
4649

4750
private static final Response SYNTAX_ERROR;
48-
51+
4952
static {
5053
SMTPResponse response = new SMTPResponse(
5154
SMTPRetCode.SYNTAX_ERROR_COMMAND_UNRECOGNIZED, DSNStatus
@@ -80,6 +83,8 @@ private Response doQUIT(SMTPSession session, String argument) {
8083
" Service closing transmission channel");
8184
SMTPResponse ret = new SMTPResponse(SMTPRetCode.SYSTEM_QUIT, response);
8285
ret.setEndSession(true);
86+
87+
LOGGER.debug("QUIT");
8388
return ret;
8489
} else {
8590
return SYNTAX_ERROR;

protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/RcptCmdHandler.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
import jakarta.inject.Inject;
3030

31+
import org.apache.commons.lang3.StringUtils;
3132
import org.apache.commons.lang3.tuple.Pair;
3233
import org.apache.james.core.MailAddress;
3334
import org.apache.james.core.MaybeSender;
@@ -85,12 +86,14 @@ protected Response doCoreCmd(SMTPSession session, String command, String paramet
8586
MailAddress recipientAddress = session.getAttachment(CURRENT_RECIPIENT, State.Transaction).orElse(MailAddress.nullSender());
8687
rcptColl.add(recipientAddress);
8788
session.setAttachment(SMTPSession.RCPT_LIST, rcptColl, State.Transaction);
89+
8890
StringBuilder response = new StringBuilder();
89-
response
90-
.append(
91-
DSNStatus.getStatus(DSNStatus.SUCCESS,
92-
DSNStatus.ADDRESS_VALID))
91+
String status = DSNStatus.getStatus(DSNStatus.SUCCESS, DSNStatus.ADDRESS_VALID);
92+
response.append(status)
9393
.append(" Recipient <").append(recipientAddress).append("> OK");
94+
95+
LOGGER.debug("RCPT TO {}", StringUtils.abbreviate(recipientAddress.asString(), 80));
96+
9497
return new SMTPResponse(SMTPRetCode.MAIL_OK, response);
9598

9699
}

protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/esmtp/EhloCmdHandler.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
import jakarta.inject.Inject;
2727

28+
import org.apache.commons.lang3.StringUtils;
2829
import org.apache.james.metrics.api.MetricFactory;
2930
import org.apache.james.protocols.api.ProtocolSession.State;
3031
import org.apache.james.protocols.api.Response;
@@ -95,6 +96,8 @@ private Response doEHLO(SMTPSession session, String argument) {
9596
COMMAND_NAME, State.Connection);
9697

9798
processExtensions(session, resp);
99+
100+
LOGGER.debug("EHLO {}", StringUtils.abbreviate(argument, 80));
98101

99102
return resp;
100103
}

0 commit comments

Comments
 (0)