01: package org.kohsuke.javanet.devrolehandler;
02:
03: import dalma.Description;
04: import dalma.Engine;
05: import dalma.Program;
06: import dalma.Resource;
07: import dalma.endpoints.email.EmailEndPoint;
08: import dalma.endpoints.email.NewMailHandler;
09:
10: import javax.mail.internet.MimeMessage;
11:
12: import org.kohsuke.jnt.tools.RoleRequest;
13:
14: import java.io.InputStreamReader;
15:
16: @Description("This application waits for a developer role request, and sends out an e-mail asking for clarifications")
17: public class Main extends Program {
18: @Resource(description="used to receive role request e-mails and send out clarification e-mails")
19: public EmailEndPoint email;
20:
21: public void init(final Engine engine) throws Exception {
22: email.setNewMailHandler(new NewMailHandler() {
23: public void onNewMail(MimeMessage mail) throws Exception {
24: // technically, we need to get encoding from the e-mail,
25: // but we know java.net uses UTF-8.
26: RoleRequest rr = new RoleRequest(new InputStreamReader(
27: mail.getInputStream(), "UTF-8"));
28:
29: // TODO just for now
30: if (rr.projectName.equals("com4j")
31: && rr.roleName.equals("Developer")) {
32: getLogger().info(
33: "Started a conversation with " + rr);
34: engine.createConversation(new ConversationImpl(
35: email, rr.projectName, rr.roleName,
36: rr.userName));
37: } else {
38: getLogger().info("Ignored " + rr);
39: }
40:
41: }
42: });
43: }
44:
45: @Override
46: public void main(Engine engine) throws Exception {
47: getLogger().info("Started");
48: }
49: }
|