in server/src/main/java/org/apache/hupa/server/service/FetchMessagesBaseServiceImpl.java [101:187]
protected List<org.apache.hupa.shared.domain.Message> convert(int offset, com.sun.mail.imap.IMAPFolder folder, Message[] messages) throws MessagingException {
List<org.apache.hupa.shared.domain.Message> mList = new ArrayList<org.apache.hupa.shared.domain.Message>();
// Setup fetchprofile to limit the stuff which is fetched
FetchProfile fp = new FetchProfile();
fp.add(FetchProfile.Item.ENVELOPE);
fp.add(FetchProfile.Item.FLAGS);
fp.add(FetchProfile.Item.CONTENT_INFO);
fp.add(UIDFolder.FetchProfileItem.UID);
folder.fetch(messages, fp);
// loop over the fetched messages
for (int i = 0; i < messages.length && i < offset; i++) {
org.apache.hupa.shared.domain.Message msg = new org.apache.hupa.shared.data.MessageImpl();
Message m = messages[i];
String from = null;
if (m.getFrom() != null && m.getFrom().length >0 ) {
from = MessageUtils.decodeText(m.getFrom()[0].toString());
}
msg.setFrom(from);
String replyto = null;
if (m.getReplyTo() != null && m.getReplyTo().length >0 ) {
replyto = MessageUtils.decodeText(m.getReplyTo()[0].toString());
}
msg.setReplyto(replyto);
ArrayList<String> to = new ArrayList<String>();
// Add to addresses
Address[] toArray = m.getRecipients(RecipientType.TO);
if (toArray != null) {
for (Address addr : toArray) {
String mailTo = MessageUtils.decodeText(addr.toString());
to.add(mailTo);
}
}
msg.setTo(to);
// Check if a subject exist and if so decode it
String subject = m.getSubject();
if (subject != null) {
subject = MessageUtils.decodeText(subject);
}
msg.setSubject(subject);
// Add cc addresses
Address[] ccArray = m.getRecipients(RecipientType.CC);
ArrayList<String> cc = new ArrayList<String>();
if (ccArray != null) {
for (Address addr : ccArray) {
String mailCc = MessageUtils.decodeText(addr.toString());
cc.add(mailCc);
}
}
msg.setCc(cc);
userPreferences.addContact(from);
userPreferences.addContact(to);
userPreferences.addContact(replyto);
userPreferences.addContact(cc);
// Using sentDate since received date is not useful in the view when using fetchmail
msg.setReceivedDate(m.getSentDate());
// Add flags
ArrayList<IMAPFlag> iFlags = JavamailUtil.convert(m.getFlags());
ArrayList<Tag> tags = new ArrayList<Tag>();
for (String flag : m.getFlags().getUserFlags()) {
if (flag.startsWith(TagImpl.PREFIX)) {
tags.add(new TagImpl(flag.substring(TagImpl.PREFIX.length())));
}
}
msg.setUid(folder.getUID(m));
msg.setFlags(iFlags);
msg.setTags(tags);
try {
msg.setHasAttachments(hasAttachment(m));
} catch (MessagingException e) {
logger.debug("Unable to identify attachments in message UID:" + msg.getUid() + " subject:" + msg.getSubject() + " cause:" + e.getMessage());
logger.info("");
}
mList.add(0, msg);
}
return mList;
}