0df2b46585dc69543dc8132aef605adc9f86fa53
[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.get("precedence");
43         if (precedence != null) precedence = precedence.trim().toLowerCase();
44         if ("bulk".equals(precedence)) return null;
45         if ("list".equals(precedence)) return null;
46         if ("junk".equals(precedence)) return null;
47
48         // recommended, not required.
49         if (m.envelopeFrom.user.endsWith("-request"))                     return null;
50         if (m.envelopeFrom.user.startsWith("owner-"))                     return null;
51         if (m.envelopeFrom.description.equalsIgnoreCase("mailer-daemon")) return null;
52         for(String key : m.headers.getHeaderNames())
53             if (key.toLowerCase().startsWith("list-")) return null;
54
55         // SHOULD NOT issue the same response to the same sender more
56         // than once within a period of several days, even though that
57         // sender may have sent multiple messages.  A 7-day period is
58         // RECOMMENDED as a default.
59
60         // Personal and Group responses whose purpose is to notify the
61         // sender of a message of a temporary absence of the recipient
62         // (e.g., "vacation" and "out of the office" notices) SHOULD
63         // NOT be issued unless a valid address for the recipient is
64         // explicitly included in a recipient (e.g., To, Cc, Bcc,
65         // Resent-To, Resent-Cc, or Resent- Bcc) field of the subject
66         // message.
67         
68         throw new Error("FIXME");
69         /*
70         Message ret = m.reply(fountain, null, false);
71
72         ret.headers.put("Auto-Submitted", "auto-replied");
73         ret.headers.put("Precedence",     "bulk"); // or list
74         ret.headers.put("From",           autoFrom);
75         ret.headers.put("Reply-To",       autoFrom);
76         if (includeAutoInSubject)
77             ret.headers.put("Subject",    "Auto: " + m.subject);
78         */
79     }
80
81     // don't return large responses (> a few kb)
82
83 }