IMailbox mailbox = SessionManager.get().getMailbox();
UserAccount account = SessionManager.get().getUserAccount();
log.debug( "retrieving messages from " + folderId + " ..." );
try {
IMailFolder currentFolder = mailbox.getMailFolderById( folderId );
if ( currentFolder == null ) {
mailbox.reloadFolder();
currentFolder = mailbox.getMailFolderById( folderId );
}
mailbox.setCurrentFolder( currentFolder );
Message[] msgs = currentFolder.retrieveMessages( sortField, ascending, searchFields, searchValues );
if ( msgs != null && msgs.length > 0 ) {
int total_count = msgs.length;
start = Math.min( total_count - 1, start == -1 ? 0 : start );
pageSize = pageSize == -1 ? account.getPreferences().getPageCount() : pageSize;
pageSize = Math.min( pageSize, total_count - start );
Message[] pagedMessages = new Message[pageSize];
int pagedIndex = 0;
for (int msgIndex = start; msgIndex < start + pageSize; msgIndex++) {
pagedMessages[pagedIndex++] = msgs[msgIndex];
}
FetchProfile completeProfile = MessageUtils.createFetchProfile( true, null );
currentFolder.fetch( pagedMessages, completeProfile );
Preferences preferences = SessionManager.get().getPreferences();
GWTMessageRecord[] messageStringArray = ConvertUtil.convertMessagesToStringArray(
getApplicationContext(), preferences, (IMAPFolder) currentFolder.getFolder(), pageSize,
pagedMessages );
return new GWTMessageList( messageStringArray, msgs.length );
}