{
CharBuffer line = CharBuffer.allocate();
String topId = null;
int count = 1;
WriteStream ws = null;
IntMap messages = new IntMap();
try {
while (true) {
do {
line.clear();
if (! is.readLine(line)) {
if (ws != null)
ws.println("</message>");
return false;
}
if (ws != null && ! line.startsWith("From ")) {
for (int i = 0; i < line.length(); i++) {
char ch = line.charAt(i);
if (ch == '<')
ws.print("<");
else
ws.print(ch);
}
ws.println();
}
} while (! line.startsWith("From "));
if (ws != null) {
ws.println("</message>");
ws.close();
ws = null;
}
String date = null;
String subject = null;
String from = null;
String id = null;
String references = null;
do {
line.clear();
if (! is.readLine(line))
return false;
if (line.length() == 0)
break;
String lower = line.toString().toLowerCase(Locale.ENGLISH);
if (lower.startsWith("subject: ")) {
subject = line.substring("subject: ".length()).trim();
if (subject.toLowerCase(Locale.ENGLISH).startsWith("re:"))
subject = subject.substring(3).trim();
}
else if (lower.startsWith("from: ")) {
from = line.substring("from: ".length());
}
else if (lower.startsWith("date: ")) {
date = line.substring("from: ".length());
}
} while (line.length() > 0);
int index = messages.get(subject);
if (index >= 0) {
ws = dst.lookup("" + index + ".xtp").openAppend();
}
else {
if (subject != null && ! subject.equals(""))
messages.put(subject, count);
ws = dst.lookup("" + count++ + ".xtp").openWrite();
ws.println("<title>" + subject + "</title>");
}
ws.println("<em>" + from + "</em>");