1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 package com.mjh.switchrmi.transport.smtp.james;
28
29 import com.mjh.switchrmi.*;
30 import com.mjh.switchrmi.transport.smtp.SmtpServiceHandler;
31
32 import java.util.*;
33
34 import javax.mail.*;
35 import javax.mail.internet.*;
36
37 import javax.naming.*;
38
39 import org.apache.mailet.GenericMailet;
40 import org.apache.mailet.Mail;
41 import org.apache.mailet.MailetConfig;
42
43 public class RmiMailet extends GenericMailet
44 {
45 Context jndiContext;
46
47 public void init(MailetConfig config)
48 throws MessagingException
49 {
50 try
51 {
52 String configurationName =
53 config.getInitParameter("rpcServiceConfiguration");
54 Hashtable env = new Hashtable();
55
56 env.put(Context.PROVIDER_URL, configurationName);
57 jndiContext = new InitialContext(env);
58 }
59 catch (Exception ex)
60 {
61 throw new MessagingException(ex.toString());
62 }
63 }
64
65 public void service(Mail mail)
66 throws MessagingException
67 {
68 try
69 {
70 MimeMessage message = mail.getMessage();
71
72 String subject = message.getSubject();
73
74 if (subject.startsWith("RPC:"))
75 {
76 Multipart multipart = (Multipart) message.getContent();
77
78 if (multipart.getCount() == 2)
79 {
80 SmtpServiceHandler handler =
81 new SmtpServiceHandler(jndiContext);
82
83 handler.setMessage(message);
84
85 handler.invoke();
86 }
87 }
88 }
89 catch (Exception ex)
90 {
91 debug(ex);
92 throw new MessagingException(ex.toString());
93 }
94 }
95
96 private void debug(String msg)
97 {
98 System.out.println(msg);
99 }
100
101 private void debug(Exception ex)
102 {
103 debug(ex.toString());
104 ex.printStackTrace();
105 }
106 }