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.
10 import org.ibex.io.Fountain;
12 // FIXME FIXME: rate limiting
14 // FIXME: DSN's: RFC 3464 ==> NOTIFY=NEVER
15 // FIXME: MDN's: RFC 3798
18 // SHOULD NOT issue the same response to the same sender more
19 // than once within a period of several days, even though that
20 // sender may have sent multiple messages. A 7-day period is
21 // RECOMMENDED as a default.
23 // Personal and Group responses whose purpose is to notify the
24 // sender of a message of a temporary absence of the recipient
25 // (e.g., "vacation" and "out of the office" notices) SHOULD
26 // NOT be issued unless a valid address for the recipient is
27 // explicitly included in a recipient (e.g., To, Cc, Bcc,
28 // Resent-To, Resent-Cc, or Resent- Bcc) field of the subject
31 // FIXME: be sure to never, ever return large responses (> a few kb)
33 /** Implements RFC3834-safe/compliant auto-generated messages+replies */
37 * Compose an auto-generated message (not a reply) compliant with RFC3834.
40 * <b>personal</b>: should be the recipient of the message, might guess from message, MUST be customizable<br>
41 * <b>service</b>: should be a human, and description should describe the service
42 * @param includeAutoInSubject if true; the string "Auto: " is prepended to the subject
44 public Message autoGenerate(Headers headers, Fountain body, Address autoFrom, Address autoTo, boolean includeAutoInSubject) {
45 return Message.newMessageFromHeadersAndBody(new Headers(headers, new String[] {
46 "Auto-Submitted", "auto-generated",
48 "Subject", (includeAutoInSubject ? "Auto: " : "")+headers.get("subject"),
49 "From", autoFrom.toString(true),
50 "Reply-To", autoFrom.toString(false)
56 * Compose an auto-generated reply compliant with RFC3834.
59 * <b>personal</b>: should be the recipient of the message, might guess from message, MUST be customizable<br>
60 * <b>service</b>: should be a human, and description should describe the service
61 * @param includeAutoInSubject if true; the string "Auto: " is prepended to the subject
63 public Message autoReply(Fountain fountain, Message m, Address autoFrom, boolean includeAutoInSubject) {
65 if (m.envelopeFrom==null) return null;
67 String auto = m.headers.get("auto-submittted");
68 if (auto!=null && !auto.equals("no")) return null;
70 String precedence = m.headers.get("precedence");
71 if (precedence != null) precedence = precedence.trim().toLowerCase();
72 if ("bulk".equals(precedence)) return null;
73 if ("list".equals(precedence)) return null;
74 if ("junk".equals(precedence)) return null;
76 // recommended, not required.
77 if (m.envelopeFrom.user.endsWith("-request")) return null;
78 if (m.envelopeFrom.user.startsWith("owner-")) return null;
79 if (m.envelopeFrom.description.equalsIgnoreCase("mailer-daemon")) return null;
80 for(String key : m.headers.getHeaderNames())
81 if (key.toLowerCase().startsWith("list-")) return null;
83 return m.reply(new String[] {
84 "Auto-Submitted", "auto-replied",
86 "Subject", (includeAutoInSubject ? "Auto: " : "")+m.subject,
87 "From", autoFrom.toString(true),
88 "Reply-To", autoFrom.toString(false)
90 fountain, null, false);