try
{
if(log.isInfoEnabled())
log.info("import mail from " + mail.getSender());
String recipient;
PersonContactVO pc;
List<PersonContactVO> pcs = new ArrayList<PersonContactVO>();
MimeMessage message = mail.getMessage();
MailetContext mailetContext = getMailetContext();
contact = new ContactVO();
contact.setBoundType(ContactVO.BoundType.IN);
contact.setContactType(ContactVO.ContactType.EMAIL);
contact.setContactTimestamp(new Date());
contact.setImportType(ContactVO.ImportType.NEW);
// Subject setzen
if (message.getSubject() != null)
contact.setSubject(message.getSubject());
else
contact.setSubject("Kein Betreff angegeben");
// Content Setzen
insertContent(message);
if (contentTypetext)
contact.setContentType(ContactVO.ContentType.PLAINTEXT);
else
contact.setContentType(ContactVO.ContentType.HTML);
// Absender
List<PersonVO> senders = new PersonDAO().getByMail(mail.getSender().toString());
if (!senders.isEmpty())
for (PersonVO person : senders)
{
pc = new PersonContactVO(person, contact);
pc.setRelationType(PersonContactVO.Type.SENDER);
pcs.add(pc);
if ((mailetContext.isLocalUser(mail.getSender().getUser())) && mailetContext.isLocalServer(mail.getSender().getHost()))
{
contact.setBoundType(ContactVO.BoundType.OUT);
}
}
else
contact.setContactName("From: " + mail.getSender().toString());
// Emfaenger TO
Address[] addresses = message.getRecipients(MimeMessage.RecipientType.TO);
for (Address address : addresses)
{
recipient = address.toString();
List<PersonVO> recipients = new PersonDAO().getByMail(recipient);
if (!recipients.isEmpty())
for (PersonVO person : recipients)
{
pc = new PersonContactVO(person, contact);
pc.setRelationType(PersonContactVO.Type.TO);
pcs.add(pc);
}
else if (contact.getContactName() == null)
contact.setContactName("To: " + recipient);
else
contact.setContactName(contact.getContactName() + ", To: " + recipient);
}
// Emfaenger CC
addresses = message.getRecipients(MimeMessage.RecipientType.CC);
if (addresses != null)
for (Address address : addresses)
{
recipient = address.toString();
List<PersonVO> recipients = new PersonDAO().getByMail(recipient);
if (!recipients.isEmpty())
for (PersonVO person : recipients)
{
pc = new PersonContactVO(person, contact);
pc.setRelationType(PersonContactVO.Type.CC);
pcs.add(pc);
}
else if (contact.getContactName() == null)
contact.setContactName("CC: " + recipient);
else
contact.setContactName(contact.getContactName() + ", CC: " + recipient);
}
// Emfaenger BCC
addresses = message.getRecipients(MimeMessage.RecipientType.BCC);
if (addresses != null)
for (Address address : addresses)
{
recipient = address.toString();
List<PersonVO> recipients = new PersonDAO().getByMail(recipient);
if (!recipients.isEmpty())
for (PersonVO person : recipients)
{
pc = new PersonContactVO(person, contact);
pc.setRelationType(PersonContactVO.Type.BCC);
pcs.add(pc);
}
else if (contact.getContactName() == null)
contact.setContactName("BCC: " + recipient);
else