1 /*
2 * Copyright (c) 2006-2007 Creative Sphere Limited.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 *
10 * Creative Sphere - initial API and implementation
11 *
12 */
13 package org.abstracthorizon.mercury.smtp.logging;
14
15 import org.abstracthorizon.danube.connection.Connection;
16 import org.abstracthorizon.danube.support.logging.AccessLogConnectionHandler;
17 import org.abstracthorizon.mercury.smtp.SMTPSession;
18 import org.abstracthorizon.mercury.smtp.filter.MailSessionData;
19
20 import java.util.List;
21
22 /**
23 * <p>
24 * Utility class that adds new pattern codes to existing in {@link AccessLogConnectionHandler}
25 * </p>
26 * <ul>
27 * <li><code>%A</code> - local IP address</li>
28 * </ul>
29 * <p>
30 * Those are added through {@link SMTPSPAMPatternProcessor}
31 * </p>
32 * <p>
33 * Also it sets default pattern to "%y %S %R %h localhost SMTP - %r %b"
34 * </p>
35 * @author Daniel Sendula
36 */
37 public class SMTPSPAMAccessLogConnectionHandler extends AccessLogConnectionHandler {
38
39 /**
40 * <p>Adds lists of predefined processors to the lists of provider classes.</p>
41 * <p>This method adds following:</p>
42 * <ul>
43 * <li>{@link SMTPSPAMPatternProcessor}</li>
44 * </ul>
45 * <p>Also it calls super method {@link AccessLogConnectionHandler#addPredefinedProcessors(List)}</p>
46 *
47 * @param providerClasses list of provider classes
48 */
49 protected void addPredefinedProcessors(List<String> providerClasses) {
50 super.addPredefinedProcessors(providerClasses);
51 if (!providerClasses.contains(SMTPSPAMPatternProcessor.class.getName())) {
52 providerClasses.add(SMTPSPAMPatternProcessor.class.getName());
53 }
54 }
55
56
57 /**
58 * Returns default log pattern
59 * @return default log pattern
60 */
61 protected String getDefaultLogPattern() {
62 return "%y %S %R %h localhost SMTP - %r %b";
63 }
64
65 protected String createLogLine(Connection connection, long start) {
66 SMTPSession smtpSession = (SMTPSession)connection.adapt(SMTPSession.class);
67 MailSessionData data = smtpSession.getMailSessionData();
68 if (data.getSourceMailbox() == null) {
69 return null;
70 }
71 return super.createLogLine(connection, start);
72 }
73 }