added Auto
[org.ibex.mail.git] / src / org / ibex / mail / Auto.java
1 // Copyright 2000-2006 the Contributors, as shown in the revision logs.
2 // Licensed under the Apache Public Source License 2.0 ("the License").
3 // You may not use this file except in compliance with the License.
4
5 package org.ibex.mail;
6 import java.io.*;
7 import java.util.*;
8 import org.ibex.js.*;
9 import org.ibex.mail.target.*;
10
11 // FIXME FIXME: rate limiting
12
13
14 // FIXME: DSN's: RFC 3464 ==> NOTIFY=NEVER
15 // FIXME: MDN's: RFC 3798
16
17 /** Implements RFC3834-compliant auto-generated messages+replies */
18 public class Auto {
19
20     /*
21     public Message autoGenerate() {
22         // same as other, but:
23         ret.headers.put("Auto-Submitted", "auto-generated");
24     }
25     */
26
27     /**
28      *  Compose an auto-generated reply compliant with RFC3834.
29      *
30      *  @param from
31      *    <b>personal</b>: should be the recipient of the message, might guess from message, MUST be customizable<br>
32      *    <b>service</b>:  should be a human, and description should describe the service
33      *  @param includeAutoInSubject if true; the string "Auto: " is prepended to the subject
34      */
35     public Message autoReply(Fountain fountain, Message m, Address autoFrom, boolean includeAutoInSubject) {
36
37         if (m.envelopeFrom==null) return null;
38
39         String auto = m.headers.get("auto-submittted");
40         if (auto!=null && !auto.equals("no"))                             return null;
41
42         String precedence = m.headers.getLowerCaseTrimmed("precedence");
43         if ("bulk".equals(precedence)) return null;
44         if ("list".equals(precedence)) return null;
45         if ("junk".equals(precedence)) return null;
46
47         // recommended, not required.
48         if (m.envelopeFrom.user.endsWith("-request"))                     return null;
49         if (m.envelopeFrom.user.startsWith("owner-"))                     return null;
50         if (m.envelopeFrom.description.equalsIgnoreCase("mailer-daemon")) return null;
51         for(Enumeration e = m.headers.names(); e.hasMoreElements();) {
52             String key = (String)e.nextElement();
53             if (key.toLowerCase().startsWith("list-")) return null;
54         }
55
56         // SHOULD NOT issue the same response to the same sender more
57         // than once within a period of several days, even though that
58         // sender may have sent multiple messages.  A 7-day period is
59         // RECOMMENDED as a default.
60
61         // Personal and Group responses whose purpose is to notify the
62         // sender of a message of a temporary absence of the recipient
63         // (e.g., "vacation" and "out of the office" notices) SHOULD
64         // NOT be issued unless a valid address for the recipient is
65         // explicitly included in a recipient (e.g., To, Cc, Bcc,
66         // Resent-To, Resent-Cc, or Resent- Bcc) field of the subject
67         // message.
68         
69         throw new Error("FIXME");
70         /*
71         Message ret = m.reply(fountain, null, false);
72
73         ret.headers.put("Auto-Submitted", "auto-replied");
74         ret.headers.put("Precedence",     "bulk"); // or list
75         ret.headers.put("From",           autoFrom);
76         ret.headers.put("Reply-To",       autoFrom);
77         if (includeAutoInSubject)
78             ret.headers.put("Subject",    "Auto: " + m.subject);
79         */
80     }
81
82     // don't return large responses (> a few kb)
83
84 }