issues@javamail.java.net

[Bug 4581] New: Some messages are marked as read after getting their content

From: <bugzilla-daemon_at_kenai.com>
Date: Sat, 5 Nov 2011 17:17:56 +0000 (GMT)

http://kenai.com/bugzilla/show_bug.cgi?id=4581

           Summary: Some messages are marked as read after getting their
                    content
           Product: javamail
           Version: 1.4.4
          Platform: All
        OS/Version: Linux
            Status: NEW
          Severity: enhancement
          Priority: P3
         Component: imap
        AssignedTo: shannon_at_kenai.com
        ReportedBy: haitimeid_at_kenai.com
                CC: issues_at_javamail.kenai.com


I am using JavaMail to check mail via IMAP + SSL. Here is part of my code:

Get unread messages:

import javax.mail.BodyPart;
import javax.mail.Folder;
import javax.mail.search.FlagTerm;
import javax.mail.Multipart;

...

  private void checkMail() {
    //login
    ...

    //get unread messages
    Folder inbox = store.getFolder("inbox");
    inbox.open(Folder.READ_WRITE);
    FlagTerm ft = new FlagTerm(new Flags(Flags.Flag.SEEN), false);
    Message[] messages = inbox.search(ft);

    //for each message
    for (Message message : messages) {
      //do something
      ...

      //check attachment
      boolean hasAttachment = false;
      try {
        Object content = message.getContent();
        if (content instanceof Multipart) {
          Multipart multipart = (Multipart) content;
          for (int i = 0; i < multipart.getCount(); i++) {
            if
(BodyPart.ATTACHMENT.equalsIgnoreCase(multipart.getBodyPart(i).getDisposition()))
{
              hasAttachment = true;
              break;
            }
          }//for
        }//if
      } catch (Exception ex) {}
      finally {
        /*
         * currently, for some messages, after checking attachment by this way,
         * the messages are marked as read, so we need to mark them as unread
         */
        message.setFlag(Flag.SEEN, false);
      }
    }

Please see the comments, currently, after getting content of some messages, the
message will be marked as read. For instance, those messages are sent from
vworker.com to me daily. They are about new projects on the site. I tested by
forwarding messages to another mail account, but the code ran fine. So the code
runs failed with original messages.

It is hard for you to check this. But if you have free time, please register at
vworker.com, then make a search settings, the site will send you email about
new projects daily.

My project is open source. Here is the link to the file containing above code:
http://code.google.com/p/mail-gate/source/browse/src/main/java/group/pals/mailgate/threads/EmailReader.java

-- 
Configure bugmail: http://kenai.com/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.