+
+ public static class Drop extends JS.Obj implements Target {
+ public static final Drop instance = new Drop();
+ public final String reason;
+ public Drop() { this(null); }
+ public Drop(String reason) { this.reason = reason; }
+ public void accept(Message m) throws IOException, MailException {
+ Log.warn(this, "dropping" +(reason==null?"":(" because "+reason))+ ": " + m.summary());
+ }
+ }
+
+ public static class Later extends JS.Obj implements Target {
+ public static final Later instance = new Later();
+ public static class LaterException extends RuntimeException { }
+ public void accept(Message m) throws IOException, MailException {
+ Log.warn(this, "delaying message " + m.summary());
+ throw new LaterException();
+ }
+ }
+
+ /** a fast-write, slow-read place to stash all messages we touch -- in case of a major f*ckup */
+ public static class Transcript implements Target {
+
+ public static final Transcript transcript = new Transcript(Mailbox.STORAGE_ROOT + File.separatorChar + "transcript");
+
+ private String path;
+ public Transcript(String path) { new File(this.path = path).mkdirs(); }
+ private static String lastTime = null;
+ private static int lastCounter = 0;
+
+ public synchronized void accept(Message message) {
+ try {
+ File today = new File(path + File.separatorChar + (new SimpleDateFormat("yy-MMM-dd").format(new Date())));
+ today.mkdirs();
+
+ String time = new SimpleDateFormat("HH:mm:ss").format(new Date());
+ synchronized (Transcript.class) {
+ if (lastTime != null && lastTime.equals(time)) {
+ time += "." + (++lastCounter);
+ } else {
+ lastTime = time;
+ lastCounter = 0;
+ }
+ }
+
+ File target = new File(today.getPath() + File.separatorChar + time + ".txt");
+ OutputStream os = new FileOutputStream(target);
+ try {
+ message.getStream().transcribe(new Stream(os));
+ os.flush();
+ } finally { os.close(); }
+ } catch (IOException e) { throw new MailException.IOException(e); }
+ }
+ }
+
+ public static class Reject extends JS.Obj implements Target {
+ public final String reason;
+ public Reject(String reason) { this.reason = reason; }
+ public void accept(Message m) throws IOException, MailException {
+ throw new RejectException(m, reason);
+ }
+ public static class RejectException extends RuntimeException {
+ public final Message m;
+ public final String reason;
+ public RejectException(Message m, String reason) { this.m = m; this.reason = reason; }
+ }
+ }
+
+