title: Javamail Message, set as seen while folder is open in read only mode?
body: <p>I have an IMAP <code>Folder</code> opened as <code>READ_ONLY</code> and I want to set a specific message as <code>SEEN</code> (read) at a specific point in my program.</p>
  
  <p>I tried to find a way to change the mode from <code>READ_ONLY</code> to <code>READ_WRITE</code> on the fly but apparently the only way to do this is closing the <code>Folder</code> and opening it again.</p>
  
  <p>I wrote a hefty method that achieves the above but I'm really unhappy about the situation.</p>
  
  <p>If I open the folder as <code>READ_WRITE</code> from the beginning, the messages gets marked as <code>READ</code> during my processing, which is not the point of time that I want the message to be marked as <code>READ</code>.</p>
  
  <p>Here have a peek on the method that I wrote and don't giggle.</p>
  
  <pre><code>/**
   * @param message The message to be processed.
   * @param read True to mark as READ, False to mark as UNREAD.
   */
  public static void markMessageAsRead(Message message, boolean read) {
          try {
              //Getting required variables
              Folder messageFolder = message.getFolder();
              int initialFolderMode = messageFolder.getMode();
              boolean initialFolderOpenState = messageFolder.isOpen();
  
              //If the folder is readonly then lets set it to readwrite
              if(initialFolderMode == Folder.READ_ONLY) {
                  if(initialFolderOpenState) {
                      messageFolder.close(false);
                  }
  
                  messageFolder.open(Folder.READ_WRITE);
              }
  
              //Make sure folder is open (incase the above if didn't evaluate)
              if(!initialFolderOpenState) {
                  messageFolder.open(Folder.READ_WRITE);
              }
  
              //Marking message as seen/unseen
              message.setFlag(Flags.Flag.SEEN, read);
  
              //Now lets revert the folder to it's state before it came here
              if(initialFolderOpenState) {
                  if(!messageFolder.isOpen()) {
                      messageFolder.open(initialFolderMode);
                  }
              } else {
                  if(messageFolder.isOpen()) {
                      messageFolder.close(false);
                  }
              }
          } catch (MessagingException e) {
              e.printStackTrace();
          }
  }
  </code></pre>
  
  <p>Is there a way to achieve what I want in a more neatly manner?</p>