01: package org.kohsuke.javanet.approval;
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.MessagingException;
11: import javax.mail.internet.AddressException;
12: import javax.mail.internet.InternetAddress;
13: import javax.mail.internet.MimeMessage;
14: import java.util.logging.Level;
15: import java.util.List;
16: import java.util.ArrayList;
17: import java.util.StringTokenizer;
18: import java.io.File;
19:
20: @Description("Automates java.net project routing and approval process")
21: public class Main extends Program {
22: @Resource(description="e-mail address of the daemon")
23: public EmailEndPoint email;
24:
25: protected InternetAddress[] domainAdmin;
26:
27: @Resource(description="domain admin e-mail addresses")
28: public void setDomainAdmin(String name) throws AddressException {
29: List<InternetAddress> adrs = new ArrayList<InternetAddress>();
30: StringTokenizer tokens = new StringTokenizer(name);
31: while (tokens.hasMoreTokens()) {
32: adrs.add(new InternetAddress(tokens.nextToken()));
33: }
34: domainAdmin = adrs.toArray(new InternetAddress[adrs.size()]);
35: }
36:
37: @Resource(description="'.java.net' connection configuration file. Defaults to ~/.java.net",optional=true)
38: public File accountFile = new File(new File(System
39: .getProperty("user.home")), ".java.net");
40:
41: @Override
42: public void init(final Engine engine) throws Exception {
43: email.setNewMailHandler(new NewMailHandler() {
44: public void onNewMail(MimeMessage mail) {
45: try {
46: ProjectCreationEmail em;
47:
48: try {
49: em = new ProjectCreationEmail(mail);
50: } catch (MessagingException e) {
51: getLogger().log(
52: Level.INFO,
53: "Not an approval e-mail: "
54: + mail.getSubject(), e);
55: return;
56: }
57:
58: //if(!em.getProject().startsWith("kohsuke-test-")) {
59: // getLogger().info("Ignoring "+em.getProject());
60: // return;
61: //}
62:
63: getLogger().info(
64: "Started an approval workflow for "
65: + em.getProject());
66: engine.createConversation(new ConversationImpl(
67: Main.this , em.getProject(), em.getUser(),
68: em.getDescription()));
69: } catch (Exception e) {
70: getLogger().log(Level.WARNING, e.getMessage(), e);
71: }
72: }
73: });
74: }
75: }
|