if (gmailMessages == null || gmailMessages.length <= 0) {
LOG.warn("ImapGmailClient requires GmailMessage(s) to move"
+ " to move messages to trash folder");
return;
}
Folder folder = null;
try {
final Store store = openGmailStore();
folder = getFolder(this.srcFolder,store);
if(!folder.isOpen())
{
folder.open(Folder.READ_WRITE);
}
List<Message> markedMsgList = new ArrayList<Message>();
for (GmailMessage gmailMessage : gmailMessages) {
// get only messages that match to the specified message number
Message message = folder.getMessage(gmailMessage.getMessageNumber());
message.setFlag(Flags.Flag.SEEN, true);
// mark message as delete
message.setFlag(Flags.Flag.DELETED, true);
markedMsgList.add(message);
}
Folder trash = getFolder(ImapGmailLabel.TRASH.getName(),store);
if(folder.getURLName().equals(trash.getURLName())){
LOG.warn("ImapGmailClient trying to move GmailMessage(s) within"
+ " same folder(ImapGmailLabel.TRASH.getName())");
}
// move the marked messages to trash folder
if (!markedMsgList.isEmpty()) {