public MessagesWrapper search(List<SearchTerm> term) throws MessagingException {
   if (!folder.isOpen()) {
     folder.open(Folder.READ_ONLY);
   }
   Message[] messages = folder.search(and(term));
   return new MessagesWrapper(logger, Arrays.asList(messages), folder);
 }
 public MessagesWrapper markAsRead(List<Message> messagez)
     throws IOException, MessagingException {
   if (folder.isOpen() && folder.getMode() != Folder.READ_WRITE) {
     folder.close(true);
   }
   if (!folder.isOpen()) {
     folder.open(Folder.READ_WRITE);
   }
   for (Message message : messagez) {
     message.setFlag(Flags.Flag.SEEN, true);
   }
   logger.info("Marked email(s) as read : " + messagez.size());
   return this;
 }
 public void close() throws MessagingException {
   folder.close(true);
 }