1
22
23 package com.liferay.portal.smtp;
24
25 import com.liferay.portal.kernel.smtp.MessageListener;
26 import com.liferay.portal.kernel.smtp.MessageListenerException;
27
28 import java.io.IOException;
29 import java.io.InputStream;
30
31 import org.apache.commons.logging.Log;
32 import org.apache.commons.logging.LogFactory;
33
34 import org.subethamail.smtp.TooMuchDataException;
35
36
42 public class SubEthaMessageListenerImpl
43 implements org.subethamail.smtp.MessageListener {
44
45 public SubEthaMessageListenerImpl(MessageListener listener) {
46 _listener = listener;
47 }
48
49 public boolean accept(String from, String recipient) {
50 if (_log.isDebugEnabled()) {
51 _log.debug("Listener " + _listener.getClass().getName());
52 _log.debug("From " + from);
53 _log.debug("Recipient " + recipient);
54 }
55
56 boolean value = _listener.accept(from, recipient);
57
58 if (_log.isDebugEnabled()) {
59 _log.debug("Accept " + value);
60 }
61
62 return value;
63 }
64
65 public void deliver(String from, String recipient, InputStream data)
66 throws IOException, TooMuchDataException {
67
68 try {
69 if (_log.isDebugEnabled()) {
70 _log.debug("Listener " + _listener.getClass().getName());
71 _log.debug("From " + from);
72 _log.debug("Recipient " + recipient);
73 _log.debug("Data " + data);
74 }
75
76 _listener.deliver(from, recipient, data);
77 }
78 catch (MessageListenerException mle) {
79 Throwable cause = mle.getCause();
80
81 if (cause instanceof IOException) {
82 throw (IOException)cause;
83 }
84 else if (cause instanceof TooMuchDataException) {
85 throw (TooMuchDataException)cause;
86 }
87 else if (cause != null) {
88 throw new IOException(cause.getMessage());
89 }
90 else {
91 throw new IOException(mle.getMessage());
92 }
93 }
94 }
95
96 public String getId() {
97 return _listener.getId();
98 }
99
100 public boolean equals(Object obj) {
101 if (obj == null) {
102 return false;
103 }
104
105 SubEthaMessageListenerImpl listener = null;
106
107 try {
108 listener = (SubEthaMessageListenerImpl)obj;
109 }
110 catch (ClassCastException cce) {
111 return false;
112 }
113
114 String id = listener.getId();
115
116 if (getId().equals(id)) {
117 return true;
118 }
119 else {
120 return false;
121 }
122 }
123
124 private static Log _log =
125 LogFactory.getLog(SubEthaMessageListenerImpl.class);
126
127 private MessageListener _listener;
128
129 }