You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by bt...@apache.org on 2022/08/23 09:19:56 UTC
[james-project] 02/06: JAMES-3775 Truncate the logging in ClamAVScan mailet
This is an automated email from the ASF dual-hosted git repository.
btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 900b8556720a3b3db16daf9fc5f1a1902c9777e0
Author: Quan Tran <hq...@linagora.com>
AuthorDate: Wed Aug 17 15:19:55 2022 +0700
JAMES-3775 Truncate the logging in ClamAVScan mailet
We would like a INFO level log when there is a virus mail, instead of a long debug log.
---
.../apache/james/transport/mailets/ClamAVScan.java | 82 +---------------------
1 file changed, 1 insertion(+), 81 deletions(-)
diff --git a/mailet/standard/src/main/java/org/apache/james/transport/mailets/ClamAVScan.java b/mailet/standard/src/main/java/org/apache/james/transport/mailets/ClamAVScan.java
index f71f22251a..41378b0108 100644
--- a/mailet/standard/src/main/java/org/apache/james/transport/mailets/ClamAVScan.java
+++ b/mailet/standard/src/main/java/org/apache/james/transport/mailets/ClamAVScan.java
@@ -29,7 +29,6 @@ import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
-import java.io.StringWriter;
import java.net.ConnectException;
import java.net.InetAddress;
import java.net.Socket;
@@ -37,13 +36,11 @@ import java.net.UnknownHostException;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.HashSet;
-import java.util.Iterator;
import java.util.Set;
import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
-import org.apache.james.core.MailAddress;
import org.apache.james.server.core.MimeMessageInputStream;
import org.apache.mailet.Attribute;
import org.apache.mailet.AttributeName;
@@ -584,17 +581,13 @@ public class ClamAVScan extends GenericMailet {
if (mimeMessage == null) {
LOGGER.debug("Null MimeMessage. Will send to ghost");
- // write mail info to log
- logMailInfo(mail);
mail.setState(Mail.GHOST);
return;
}
try {
if (hasVirus(new MimeMessageInputStream(mimeMessage))) {
- // write mail and message info to log
- logMailInfo(mail);
- logMessageInfo(mimeMessage);
+ LOGGER.info("Detected mail {} containing virus, adding infected header/attribute.", mail);
// mark the mail with a mail attribute to check later on by other matchers/mailets
mail.setAttribute(makeInfectedAttribute(true));
@@ -711,79 +704,6 @@ public class ClamAVScan extends GenericMailet {
}
}
- private void logMailInfo(Mail mail) {
-
- if (LOGGER.isDebugEnabled()) {
- // writes the error message to the log
- StringWriter sout = new StringWriter();
- PrintWriter out = new PrintWriter(sout, true);
-
- out.print("Mail details:");
- out.print(" MAIL FROM: " + mail.getMaybeSender().asString());
- Iterator<MailAddress> rcptTo = mail.getRecipients().iterator();
- out.print(", RCPT TO: " + rcptTo.next());
- while (rcptTo.hasNext()) {
- out.print(", " + rcptTo.next());
- }
-
- LOGGER.debug(sout.toString());
- }
- }
-
- private void logMessageInfo(MimeMessage mimeMessage) {
-
- if (LOGGER.isDebugEnabled()) {
- // writes the error message to the log
- StringWriter sout = new StringWriter();
- PrintWriter out = new PrintWriter(sout, true);
-
- out.println("MimeMessage details:");
-
- try {
- if (mimeMessage.getSubject() != null) {
- out.println(" Subject: " + mimeMessage.getSubject());
- }
- if (mimeMessage.getSentDate() != null) {
- out.println(" Sent date: " + mimeMessage.getSentDate());
- }
- String[] sender;
- sender = mimeMessage.getHeader(RFC2822Headers.FROM);
- if (sender != null) {
- out.print(" From: ");
- for (String aSender : sender) {
- out.print(aSender + " ");
- }
- out.println();
- }
- String[] rcpts;
- rcpts = mimeMessage.getHeader(RFC2822Headers.TO);
- if (rcpts != null) {
- out.print(" To: ");
- for (String rcpt : rcpts) {
- out.print(rcpt + " ");
- }
- out.println();
- }
- rcpts = mimeMessage.getHeader(RFC2822Headers.CC);
- if (rcpts != null) {
- out.print(" CC: ");
- for (String rcpt : rcpts) {
- out.print(rcpt + " ");
- }
- out.println();
- }
- out.print(" Size (in bytes): " + mimeMessage.getSize());
- if (mimeMessage.getLineCount() >= 0) {
- out.print(", Number of lines: " + mimeMessage.getLineCount());
- }
- } catch (MessagingException me) {
- LOGGER.error("Exception caught reporting message details", me);
- }
-
- LOGGER.debug(sout.toString());
- }
- }
-
public boolean hasVirus(InputStream mimeMessage) throws IOException {
try (Socket socket = getClamdSocket();
OutputStream clamAVOutputStream = new BufferedOutputStream(socket.getOutputStream(), getStreamBufferSize());
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org