}
}
}
//process after filter
NodeDraft sourceNode = null, targetNode = null;
//construct the source node
InternetAddress fromAddress = null;
try {
Address[] froms = msg.getFrom();
if (froms == null || froms.length == 0) {
report.log("message " + msg + "don't have from address");
return;
}
fromAddress = (InternetAddress) froms[0];
} catch (MessagingException e) {
try {
fromAddress = constructFromAddress(msg);
} catch (MessagingException ex) {
report.log("Can't parse message :" + msg.toString());
return;
}
}
//address string
if (fromAddress == null) {
report.log("From address of message " + msg + " is null.");
return;
}
if (fromAddress.getAddress() == null || fromAddress.getAddress().isEmpty()) {
report.log("Can't parse from message " + msg + ".");
return;
}
if (fromAddress.getPersonal() == null || fromAddress.getPersonal().isEmpty()) {
try {
fromAddress.setPersonal(fromAddress.getAddress());
} catch (UnsupportedEncodingException ex) {
report.log("message " + msg + " cann't be parsed.");
return;
}
}
//get the codec type
String codecType = null;
String contentType = null;
try {
contentType = msg.getContentType();
} catch (MessagingException ex) {
report.log("message:" + msg + ",can't get the content type of the email");
return;
//log
}
StringTokenizer s = new StringTokenizer(contentType, ";");
while (s.hasMoreTokens()) {
String temp = s.nextToken();
if (temp.contains("charset")) {
codecType = temp.substring(9, temp.length());
}
}
if (contentType == null || contentType.isEmpty()) {
contentType = "UTF-8";
}
if (codecType == null || codecType.isEmpty()) {
codecType = "UTF-8";
}
if (!container.nodeExists(fromAddress.getAddress())) {
//whether use one node to display the same display name
boolean exist = false;
if (isUseOneNodeIfSameDisplayName()) {
if (container instanceof ContainerUnloader) {
ContainerUnloader con = (ContainerUnloader) container;
Collection<? extends NodeDraftGetter> allNodes = con.getNodes();
for (NodeDraftGetter node : allNodes) {
if (node.getLabel() == null || node.getLabel().isEmpty()) {
continue;
}
if (node.getLabel().equals(fromAddress.getPersonal())) {
sourceNode = container.getNode(node.getId());
exist = true;
break;
}
}
}
}
if (!exist || !isUseOneNodeIfSameDisplayName()) {
sourceNode = container.factory().newNodeDraft();
sourceNode.setId(Utilities.codecTranslate(codecType, fromAddress.getAddress()));
sourceNode.setLabel(Utilities.codecTranslate(codecType, fromAddress.getPersonal()));
container.addNode(sourceNode);
}
} else {
sourceNode = container.getNode(fromAddress.getAddress());
}