tmp.renameTo(uidNext);
return 1;
}
- FileInputStream fis = null;
- int ret = -1;
- try {
- fis = new FileInputStream(uidNext);
- BufferedReader br = new BufferedReader(new InputStreamReader(fis));
- ret = Integer.parseInt(br.readLine());
- if (inc) {
- File tmp = new File(uidNext + "-");
- FileOutputStream fos = null;
- try {
- fos = new FileOutputStream(tmp);
- PrintWriter pw = new PrintWriter(new OutputStreamWriter(fos));
- pw.println(ret+1);
- pw.flush();
- } finally { if (fos != null) fos.close(); }
- tmp.renameTo(uidNext);
- }
- } finally { if (fis != null) fis.close(); }
+ BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(uidNext)));
+ int ret = Integer.parseInt(br.readLine());
+ br.close();
+ if (inc) {
+ File tmp = new File(uidNext + "-");
+ PrintWriter pw = new PrintWriter(new OutputStreamWriter(new FileOutputStream(tmp)));
+ pw.println(ret+1);
+ pw.flush();
+ pw.close();
+ tmp.renameTo(uidNext);
+ }
return ret;
} catch (IOException e) { throw new MailException.IOException(e); }
}
public synchronized void add(Message message) { add(message, Mailbox.Flag.RECENT); }
public synchronized void add(Message message, int flags) {
- Log.info(path, message.summary());
+ Log.info(this, "adding message to ["+toString()+"]:\n" + message.summary());
try {
int num = new File(path).list(filter).length;
String name = path + slash + uidNext(true) + "." +
((flags & Mailbox.Flag.ANSWERED) == Mailbox.Flag.ANSWERED ? "a" : "") +
((flags & Mailbox.Flag.FLAGGED) == Mailbox.Flag.FLAGGED ? "f" : "") +
((flags & Mailbox.Flag.SEEN) == Mailbox.Flag.SEEN ? "s" : "");
- //Log.info(this, " with chosen filename " + name);
+ Log.info(this, " with chosen filename " + name);
File target = new File(name);
File f = new File(target.getCanonicalPath() + "-");
FileOutputStream fo = new FileOutputStream(f);
message.dump(stream);
fo.close();
f.renameTo(target);
- //Log.info(this, " done writing.");
+ Log.info(this, " done writing.");
} catch (IOException e) { throw new MailException.IOException(e); }
}
if (cur >= names.length) return null;
try {
File file = new File(path + File.separatorChar + names[cur]);
- FileInputStream fis = null;
- try {
- fis = new FileInputStream(file);
- return new Message(new Stream(fis), new Message.Envelope(null, null, new Date(file.lastModified())));
- } finally { if (fis != null) fis.close(); }
+ FileInputStream fis = new FileInputStream(file);
+ Stream stream = new Stream(fis);
+ Address envelopeFrom = null;
+ Address envelopeTo = null;
+ /*
+ for(String s = stream.readln(); s != null; s = stream.readln()) {
+ if (s.startsWith("X-org.ibex.mail.headers.envelope.From: "))
+ envelopeFrom = Address.parse(s.substring(38).trim());
+ else if (s.startsWith("X-org.ibex.mail.headers.envelope.To: "))
+ envelopeTo = Address.parse(s.substring(36).trim());
+ else {
+ stream.unread(s + "\r\n");
+ break;
+ }
+ }
+ */
+ Message ret = new Message(stream, new Message.Envelope(null, null, new Date(file.lastModified())));
+ fis.close();
+ return ret;
} catch (IOException e) { throw new MailException.IOException(e);
} catch (Message.Malformed e) { throw new MailException(e.getMessage()); }
}