1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.apache.james.mailrepository;
23
24 import org.apache.avalon.cornerstone.services.store.Store;
25 import org.apache.avalon.framework.activity.Initializable;
26 import org.apache.avalon.framework.configuration.Configurable;
27 import org.apache.avalon.framework.configuration.Configuration;
28 import org.apache.avalon.framework.configuration.ConfigurationException;
29 import org.apache.avalon.framework.logger.AbstractLogEnabled;
30 import org.apache.avalon.framework.service.ServiceException;
31 import org.apache.avalon.framework.service.ServiceManager;
32 import org.apache.avalon.framework.service.Serviceable;
33 import org.apache.james.services.SpoolRepository;
34 import org.apache.mailet.Mail;
35
36 import javax.mail.MessagingException;
37
38 import java.util.Collection;
39 import java.util.Iterator;
40
41
42
43
44
45
46
47
48
49
50
51
52
53 public class MailStoreSpoolRepository
54 extends AbstractLogEnabled
55 implements Serviceable, Initializable, Configurable, SpoolRepository {
56
57
58
59
60 private SpoolRepository spoolRep;
61
62
63
64
65 private Store mailStore;
66
67
68
69
70 private Configuration configuration;
71
72
73 public void setStore(Store store) {
74 mailStore = store;
75 }
76
77
78
79
80 public void service(ServiceManager serviceManager) throws ServiceException {
81 Store mailStore = (Store) serviceManager.lookup(Store.ROLE);
82 setStore(mailStore);
83 }
84
85
86
87
88 public void configure(Configuration conf) throws ConfigurationException {
89 this.configuration = conf;
90 }
91
92
93
94
95 public void initialize() throws Exception {
96 try {
97 spoolRep = (SpoolRepository) mailStore.select(configuration);
98 } catch (Exception e) {
99 getLogger().error("Cannot open private SpoolRepository");
100 throw e;
101 }
102 if (getLogger().isInfoEnabled()) {
103 getLogger().info("SpoolRepository opened: "
104 + spoolRep.hashCode());
105 }
106 }
107
108
109
110
111 public Mail accept() throws InterruptedException {
112 return spoolRep.accept();
113 }
114
115
116
117
118 public Mail accept(final long delay) throws InterruptedException {
119 return spoolRep.accept(delay);
120 }
121
122
123
124
125 public Mail accept(SpoolRepository.AcceptFilter filter) throws InterruptedException {
126 return spoolRep.accept(filter);
127 }
128
129
130
131
132 public void store(Mail mc) throws MessagingException {
133 spoolRep.store(mc);
134 }
135
136
137
138
139 public Iterator list() throws MessagingException {
140 return spoolRep.list();
141 }
142
143
144
145
146 public Mail retrieve(String key) throws MessagingException {
147 return spoolRep.retrieve(key);
148 }
149
150
151
152
153 public void remove(Mail mail) throws MessagingException {
154 spoolRep.remove(mail);
155 }
156
157
158
159
160 public void remove(Collection mails) throws MessagingException {
161 spoolRep.remove(mails);
162 }
163
164
165
166
167 public void remove(String key) throws MessagingException {
168 spoolRep.remove(key);
169 }
170
171
172
173
174 public boolean lock(String key) throws MessagingException {
175 return spoolRep.lock(key);
176 }
177
178
179
180
181 public boolean unlock(String key) throws MessagingException {
182 return spoolRep.unlock(key);
183 }
184
185 }