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.transport.mailets;
23
24 import org.apache.avalon.cornerstone.services.store.Store;
25 import org.apache.avalon.framework.configuration.DefaultConfiguration;
26 import org.apache.avalon.framework.service.ServiceException;
27 import org.apache.avalon.framework.service.ServiceManager;
28 import org.apache.james.Constants;
29 import org.apache.james.services.MailRepository;
30 import org.apache.mailet.base.GenericMailet;
31 import org.apache.mailet.Mail;
32
33
34
35
36
37
38
39
40
41 public class ToRepository extends GenericMailet {
42
43
44
45
46 private MailRepository repository;
47
48
49
50
51
52 private boolean passThrough = false;
53
54
55
56
57 private String repositoryPath;
58
59
60
61
62 public void init() {
63 repositoryPath = getInitParameter("repositoryPath");
64 try {
65 passThrough = new Boolean(getInitParameter("passThrough")).booleanValue();
66 } catch (Exception e) {
67
68 }
69
70 ServiceManager compMgr = (ServiceManager)getMailetContext().getAttribute(Constants.AVALON_COMPONENT_MANAGER);
71 try {
72 Store mailstore = (Store) compMgr.lookup(Store.ROLE);
73 DefaultConfiguration mailConf
74 = new DefaultConfiguration("repository", "generated:ToRepository");
75 mailConf.setAttribute("destinationURL", repositoryPath);
76 mailConf.setAttribute("type", "MAIL");
77 mailConf.setAttribute("CACHEKEYS", getInitParameter("CACHEKEYS","TRUE"));
78 repository = (MailRepository) mailstore.select(mailConf);
79 } catch (ServiceException cnfe) {
80 log("Failed to retrieve Store component:" + cnfe.getMessage());
81 } catch (Exception e) {
82 log("Failed to retrieve Store component:" + e.getMessage());
83 }
84
85 }
86
87
88
89
90
91
92 public void service(Mail mail) throws javax.mail.MessagingException {
93 StringBuffer logBuffer =
94 new StringBuffer(160)
95 .append("Storing mail ")
96 .append(mail.getName())
97 .append(" in ")
98 .append(repositoryPath);
99 log(logBuffer.toString());
100 repository.store(mail);
101 if (!passThrough) {
102 mail.setState(Mail.GHOST);
103 }
104 }
105
106
107
108
109
110
111 public String getMailetInfo() {
112 return "ToRepository Mailet";
113 }
114 }