final Header hdr = msg.getHeader();
final String listIdRaw = hdr.getField("List-Id").getBody();
final String listId = listIdRaw.substring(1, listIdRaw.length()-1); // remove < and >
String msgId;
final Field msgIdField = hdr.getField("Message-ID");
if (msgIdField != null) {
msgId = msgIdField.getBody();
msgId = msgId.substring(1, msgId.length()-1);
} else {
msgId = Integer.toHexString(hdr.getField("Date").hashCode());
}
msgId = makeJcrFriendly(msgId);
String subject = null;
final Field subjectField = hdr.getField("Subject");
if (subjectField != null) {
subject = subjectField.getBody();
}
String threadPath = store.threadKeyGen.getThreadKey(subject);
String path = store.archivePath + getDomainNodeName(listId) + "/" + getListNodeName(listId) +
"/" + threadPath + "/" + msgId;