in server/src/main/java/org/apache/hupa/server/service/FetchMessagesServiceImpl.java [164:251]
public 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 = getFetchProfile();
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 message = messages[i];
String from = null;
if (message.getFrom() != null && message.getFrom().length > 0) {
from = MessageUtils.decodeText(message.getFrom()[0].toString());
}
msg.setFrom(from);
String replyto = null;
if (message.getReplyTo() != null && message.getReplyTo().length > 0) {
replyto = MessageUtils.decodeText(message.getReplyTo()[0].toString());
}
msg.setReplyto(replyto);
ArrayList<String> to = new ArrayList<String>();
// Add to addresses
Address[] toArray = message.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 = message.getSubject();
if (subject != null) {
subject = MessageUtils.decodeText(subject);
}
msg.setSubject(subject);
// Add cc addresses
Address[] ccArray = message.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(message.getSentDate());
// Add flags
ArrayList<IMAPFlag> iFlags = JavamailUtil.convert(message.getFlags());
ArrayList<Tag> tags = new ArrayList<Tag>();
for (String flag : message.getFlags().getUserFlags()) {
if (flag.startsWith(TagImpl.PREFIX)) {
tags.add(new TagImpl(flag.substring(TagImpl.PREFIX.length())));
}
}
msg.setUid(folder.getUID(message));
msg.setFlags(iFlags);
msg.setTags(tags);
try {
msg.setHasAttachments(hasAttachment(message));
} 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;
}