views:

808

answers:

1

Hi,

In the application I'm working on, there is a function that connects with a mail server via IMAP using JavaMail. One of our clients had the following stack trace:

javax.mail.MessagingException: A13 BAD Command Argument Error. 11; 
nested exception is: 
com.sun.mail.iap.BadCommandException: A13 BAD Command Argument Error. 11 
at com.sun.mail.imap.IMAPMessage.setFlags(IMAPMessage.java:847) 
at javax.mail.Message.setFlag(Message.java:565) ...

Now, what it was trying to do is the following:

messages[i].setFlag(Flags.Flag.RECENT, false);

Where messages[i] is a javax.mail.Message.

Now, this error has never occurred to any of our clients who use Exchange Server 2003 and since this client is using Exchange Server 2007 I'm presuming it has something to do with it (bug?). I also made sure they updated it to the latest service pack and rollup update (Service pack 1 update 8 as of this writing) and the latest JavaMail (1.4.2 as of this writing) and it had no affect. My question is, is this something I have to wait for Microsoft to fix? Is there a workaround I can employ?

For the record, the reason why I am setting the recent flag to false is so that the given message will not be processed again in a second pass (i.e. it only processes recent or new messages).

+1  A: 

My reading of the API for Flags.Flag.RECENT indicates that it's read-only from a client app. The folder implementation should set it when the "message is new to this folder". So unless you're writing a Folder implementation you shouldn't be modifying this flag.

That leaves one to wonder why your other clients don't get the error. Perhaps it's treated as a NOOP in some cases? Perhaps there is something special about this particular client's folder? Perhaps a shared folder, or a folder the user has read-access too? I'm not equipped to ponder the mysteries of the Exchange message store.

Dave Smith
One other client on Exchange Server 2007 had the same problem. They "self resolved" the issue by deleting and recreating the mailbox and chalked it up to a upgrade issue from 2003 to 2007. This other client still has the issue despite recreating the mailbox. No client currently using 2003 has complained yet.
Avrom
If I understand the Javadocs you pointed to correctly, if I properly close the mail folder and then reopen at a later date, the recent flag should be off for all messages that were there the previous time it was opened. If so, that should meet my needs.
Avrom
@Avrom: That would be my understanding. Closing and re-opening should mark any new messages as RECENT. But, is your app the only one accessing the folders? If not, I suspect you'll have a problem if some other app opens/closes the folder. I doubt if Exchange (or any IMAP server) would keep a RECENT flag just for your application. If it's important for your application to know which messages it's processed, then you'll probably have to set a user defined flag on the messages.
Dave Smith
It should be the only app that accesses that particular mailbox and if not, we stress to our clients that that may be a problem. (In other words, we recommend that they devote an exclusive mailbox for this process.)
Avrom