Stefano,
Another version of the improved logging stuff, sender and recipient are
the only glaringly obvious pieces of info that are missing. I've added a
method to get these rather than cluttering the code.
The logging is currently in avalon, has anyone begun work on moving this
to something else? Perhaps log4j ;-)
Index: src/java/org/apache/james/smtpserver/RcptCmdHandler.java
===================================================================
--- src/java/org/apache/james/smtpserver/RcptCmdHandler.java (revision
370873)
+++ src/java/org/apache/james/smtpserver/RcptCmdHandler.java (working
copy)
@@ -37,7 +37,9 @@
*/
private final static String SENDER = "SENDER_ADDRESS"; //
Sender's email address
private final static String RCPT_LIST = "RCPT_LIST"; // The
message recipients
-
+ private MailAddress recipientAddress = null;
+ private String recipient = null;
+
/*
* handles RCPT command
*
@@ -60,7 +62,6 @@
String responseString = null;
StringBuffer responseBuffer = session.getResponseBuffer();
- String recipient = null;
if ((argument != null) && (argument.indexOf(":") > 0)) {
int colonIndex = argument.indexOf(":");
recipient = argument.substring(colonIndex + 1);
@@ -96,8 +97,8 @@
StringBuffer errorBuffer =
new StringBuffer(192)
.append("Error parsing recipient
address: ")
- .append(recipient)
- .append(": did not start and end with <
>");
+ .append("Address did not start and end
with < >")
+ .append(getContext(session));
getLogger().error(errorBuffer.toString());
}
return;
@@ -102,7 +103,7 @@
}
return;
}
- MailAddress recipientAddress = null;
+
//Remove < and >
recipient = recipient.substring(1, recipient.length() - 1);
if (recipient.indexOf("@") < 0) {
@@ -123,8 +124,7 @@
StringBuffer errorBuffer =
new StringBuffer(192)
.append("Error parsing recipient
address: ")
- .append(recipient)
- .append(": ")
+ .append(getContext(session))
.append(pe.getMessage());
getLogger().error(errorBuffer.toString());
}
@@ -149,7 +149,10 @@
if (!session.getConfigurationData().getMailServer
().isLocalServer(toDomain)) {
responseString = "530 "+DSNStatus.getStatus
(DSNStatus.PERMANENT,DSNStatus.SECURITY_AUTH)+" Authentication
Required";
session.writeResponse(responseString);
- getLogger().error("Rejected message -
authentication is required for mail request");
+ StringBuffer sb = new StringBuffer(128);
+ sb.append("Rejected message - authentication is
required for mail request");
+ sb.append(getContext(session));
+ getLogger().error(sb.toString());
return;
}
} else {
@@ -168,7 +171,8 @@
.append("User ")
.append(authUser)
.append(" authenticated,
however tried sending email as ")
- .append(senderAddress);
+ .append(senderAddress)
+ .append(getContext(session));
getLogger().error(errorBuffer.toString
());
}
return;
@@ -180,7 +184,7 @@
if (!session.getConfigurationData().getMailServer
().isLocalServer(toDomain)) {
responseString = "550 "+DSNStatus.getStatus
(DSNStatus.PERMANENT,DSNStatus.SECURITY_AUTH)+" Requested action not
taken: relaying denied";
session.writeResponse(responseString);
- getLogger().error("Rejected message - " +
session.getRemoteIPAddress() + " not authorized to relay to " +
toDomain);
+ getLogger().error("Rejected message - " +
session.getRemoteIPAddress() + " not authorized to relay to " + toDomain
+ " " + getContext(session));
return;
}
}
@@ -203,7 +207,8 @@
.append("RCPT command had
unrecognized/unexpected option ")
.append(rcptOptionName)
.append(" with value ")
- .append(rcptOptionValue);
+ .append(rcptOptionValue)
+ .append(getContext(session));
getLogger().debug(debugBuffer.toString());
}
}
@@ -219,5 +224,15 @@
}
}
-
+ private String getContext(SMTPSession session){
+ StringBuffer sb = new StringBuffer(128);
+ if(null!=recipientAddress){
+ sb.append(" [to:" + (recipientAddress).toInternetAddress
().getAddress() + "]");
+ }else if(null!=recipient){
+ sb.append(" [to:" + recipient + "]");
+ }
+ if(null!=session.getState().get(SENDER))
+ sb.append(" [from:" + ((MailAddress)session.getState().get
(SENDER)).toInternetAddress().getAddress() + "]");
+ return sb.toString();
+ }
}
--
Kind Regards
Andrew Sykes <[EMAIL PROTECTED]>
Sykes Development Ltd
http://www.sykesdevelopment.com
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]