1 // Copyright 2000-2005 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.
5 package org.ibex.mail.target;
6 import org.ibex.mail.*;
7 import org.ibex.util.*;
14 /** a fast-write, slow-read place to stash all messages we touch -- in case of a major f*ckup */
15 public class Transcript extends Target {
17 public static final Transcript transcript = new Transcript(Mailbox.STORAGE_ROOT + File.separatorChar + "transcript");
20 public Transcript(String path) { new File(this.path = path).mkdirs(); }
21 private static String lastTime = null;
22 private static int lastCounter = 0;
24 public synchronized void accept(Message message) {
26 File today = new File(path + File.separatorChar + (new SimpleDateFormat("yy-MMM-dd").format(new Date())));
29 String time = new SimpleDateFormat("HH:mm:ss").format(new Date());
30 synchronized (Transcript.class) {
31 if (lastTime != null && lastTime.equals(time)) {
32 time += "." + (++lastCounter);
39 File target = new File(today.getPath() + File.separatorChar + time + ".txt");
40 OutputStream os = new FileOutputStream(target);
42 message.getStream().transcribe(new Stream(os));
44 } finally { os.close(); }
45 } catch (IOException e) { throw new MailException.IOException(e); }