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());
}
//construct the target node
Address[] recipietsTo = null;
try {
recipietsTo = msg.getRecipients(RecipientType.TO);
} catch (MessagingException ex) {
report.log("message:" + msg + ",can't get the To adress of the email");
return;//log
}
if (recipietsTo != null) {
for (Address addr : recipietsTo) {
InternetAddress addrTo = (InternetAddress) addr;
if (!container.nodeExists(addrTo.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())) {
targetNode = container.getNode(node.getId());
exist = true;
break;
}
}
}
}
if (!exist) {
targetNode = container.factory().newNodeDraft();
targetNode.setId(Utilities.codecTranslate(codecType, addrTo.getAddress()));
targetNode.setLabel(Utilities.codecTranslate(codecType, addrTo.getPersonal()));
container.addNode(targetNode);
}
} else {
targetNode = container.getNode(addrTo.getAddress());
}
//add an edge
EdgeDraft edge = container.getEdge(sourceNode, targetNode);
if (edge == null) {
edge = container.factory().newEdgeDraft();
edge.setSource(sourceNode);
edge.setTarget(targetNode);
edge.setWeight(1f);
container.addEdge(edge);
} else {
edge.setWeight(edge.getWeight() + 1f);
}
}
}
// cc or bcc as weight
if (hasCcAsWeight()) {
//construct the target node of cc
Address[] recipietsCc = null;
try {
recipietsCc = msg.getRecipients(RecipientType.CC);
} catch (MessagingException ex) {
report.log("message:" + msg + ",can't get the Cc of the email");
return;
//log
}
if (recipietsCc != null) {
for (Address addr : recipietsCc) {
InternetAddress addrCc = (InternetAddress) addr;
if (!container.nodeExists(addrCc.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().equalsIgnoreCase(fromAddress.getPersonal())) {
targetNode = container.getNode(node.getId());
exist = true;
break;
}
}
}
}
if (!exist || !isUseOneNodeIfSameDisplayName()) {
targetNode = container.factory().newNodeDraft();
targetNode.setId(Utilities.codecTranslate(codecType, addrCc.getAddress()));
targetNode.setLabel(Utilities.codecTranslate(codecType, addrCc.getPersonal()));
container.addNode(targetNode);
}
} else {
targetNode = container.getNode(addr.toString());
}
//if use cc as weight, add an edge between cc
EdgeDraft edge = container.getEdge(sourceNode, targetNode);
if (edge == null) {
edge = container.factory().newEdgeDraft();
edge.setSource(sourceNode);
edge.setTarget(targetNode);
container.addEdge(edge);
edge.setWeight(1f);
} else {
edge.setWeight(edge.getWeight() + 1f);
}
}
}
}
if (hasBccAsWeight()) {
//construct the target node of bcc
Address[] recipietsBcc = null;
try {
recipietsBcc = msg.getRecipients(RecipientType.BCC);
} catch (MessagingException ex) {
report.log("message:" + msg + ",can't get the Bcc of the email");
return;
//TODO log
}
if (recipietsBcc != null) {
for (Address addr : recipietsBcc) {
InternetAddress addrBcc = (InternetAddress) addr;
if (!container.nodeExists(addrBcc.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())) {