Is the debug output of the search command you run on Zimbra the same?
I mean this: SEARCH OR OR (ANSWERED) (UNSEEN) (UNDELETED) ALL
Imap Spec doesn't say much, just OR <expr1> <expr2>
Try writing a custom command like this(1):
SEARCH OR (ANSWERED) ( OR (UNSEEN) (UNDELETED) ) ALL
Something like this (didn't test it!):
public class TestOrCommand implements IMAPFolder.ProtocolCommand {
public Object doCommand(IMAPProtocol protocol) throws ProtocolException{
Argument args = new Argument();
args.writeString("ALL");
Response[] r = protocol.command("SEARCH OR (ANSWERED) ( OR (UNSEEN) (UNDELETED) ) ", args);
//check the output, has to be as (1)
Response response = r[r.length - 1];
// Grab all SORT responses
if (response.isOK()) { // command successful
for (int i = 0, len = r.length; i < len; i++) {
if (!(r[i] instanceof IMAPResponse))
continue;
IMAPResponse ir = (IMAPResponse) r[i];
if (ir.keyEquals("SEARCH")) {
String num;
while ((num = ir.readAtomString()) != null) {
System.out.print(num+" ");
}
}
}
}
protocol.notifyResponseHandlers(r);
protocol.handleResult(response);
return null; //just a test, don't need a return value
}
}
TestOrCommand com = new TestOrCommand();
folder.open(Folder.READ_ONLY);
folder.doCommand(com);
And see how it goes.
Paolo
-----Messaggio originale-----
Da: A mailing list for discussion of the JavaMail(tm) API [mailto:JAVAMAIL-***@JAVA.SUN.COM] Per conto di Wolfgang Beikircher
Inviato: giovedì 29 gennaio 2009 9.25
A: JAVAMAIL-***@JAVA.SUN.COM
Oggetto: Re: R: R: JavaMail IMAPFolder search command
Okay, I tried it now with the 'FlagTerm'. I search of emails with the
following flags: UNSEEN, ANSWERED, UNDELETED. All of these flags are
connected through OR. I expect as a result all mails of the folder
because no one is marked as deleted.
Situation in my folder: 11 mails are marked as ANSWERED, 0 mails are
marked as DELETED, and 90 mails are marked as SEEN.
If I executed the search command only with the UNDELETED flag, I got the
correct result (reference to all mails). The search command in
connection with both other terms, I got the empty set.
Just for curiosity, I tried to mark some mails (3 mails) as UNSEEN.
Therefore, each search command issued alone would return some result
set. To my surprise I got exactly these mails which I marked as UNSEEN.
It seems to me, that Exchange looks only to the last 2 terms in the
search command.
Therefore I tried to switch the single search terms and... boom... I got
another result.
My conclusion is, that Exchange searches only for the last 2 terms in
the OR conjunction. Do you agree on that? Or is it on the side of
JavaMail (maybe the command must be put somehow in brackets)?
Here is the list of commands issued to the server:
1. case: 11 mails ANSWERED, 0 mails DELETED, 0 mails UNSEEN
A6 SEARCH OR OR (ANSWERED) (UNSEEN) (UNDELETED) ALL
* SEARCH
A6 OK SEARCH completed.
2. case: 11 mails ANSWERED, 0 mails DELETED, 3 mails UNSEEN
A6 SEARCH OR OR (ANSWERED) (UNSEEN) (UNDELETED) ALL
* SEARCH 87 88 89
A6 OK SEARCH completed.
3. case: 11 mails ANSWERED, 0 mails DELETED, 3 mails UNSEEN (switch
ordering of search terms)
A6 SEARCH OR OR (UNSEEN) (ANSWERED) (UNDELETED) ALL
* SEARCH 22 24 26 36 38 50 61 62 65 68 74
A6 OK SEARCH completed.
Post by Paolo SpadaforaCheck to see if it happens only for headerterm or any other term search.
Try with the same code but use flagterm or another term class and use simple values, avoid special chars, let's see what happens.
Bye.
Paolo
-----Messaggio originale-----
Inviato: mercoledì 28 gennaio 2009 14.51
Oggetto: Re: R: JavaMail IMAPFolder search command
Yes, I know. I tried also that variant but with no success.
A6 SEARCH OR OR HEADER Message-ID
* SEARCH
A6 OK SEARCH completed.
This is the debug output when I try to search with 2 terms connected
A6 SEARCH OR HEADER Message-ID
* SEARCH 66 72
A6 OK SEARCH completed.
You can clearly see, that in the second example there will be returned 2
mail items (66, 72).
This is my code which returns such results. Maybe I didn't understand
[...]
IMAPFolder f = (IMAPFolder)
eStore.getDefaultFolder().getFolder("inbox");
f.open(Folder.READ_ONLY);
SearchTerm a = new HeaderTerm(Def.HEADER_MESSAGE_ID,
SearchTerm b = new HeaderTerm(Def.HEADER_MESSAGE_ID,
SearchTerm c = new OrTerm(a, b);
SearchTerm d = new HeaderTerm(Def.HEADER_MESSAGE_ID,
SearchTerm g = new OrTerm(new SearchTerm[] {a, b, d});
Message[] ms = f.search(c);
[...]
As a side note: I'm using an Exchange 2003 server for my tests. I tried
also to use another server (Zimbra server) and there it is working. So,
only the Exchange server returns such strange results. The login
procedure produces the following debug output. Maybe does it make sense
for you...
* OK Microsoft Exchange Server 2003 IMAP4rev1 server version 6.5.7638.1
(myServer.org) ready.
A0 CAPABILITY
* CAPABILITY IMAP4 IMAP4rev1 IDLE LOGIN-REFERRALS MAILBOX-REFERRALS
NAMESPACE LITERAL+ UIDPLUS CHILDREN
A0 OK CAPABILITY completed.
DEBUG: protocolConnect login, host=myFancyHost.org, user=myUsername,
password=<non-null>
A1 LOGIN myUsername myPassword
A1 OK LOGIN completed.
A2 CAPABILITY
* CAPABILITY IMAP4 IMAP4rev1 IDLE LOGIN-REFERRALS MAILBOX-REFERRALS
NAMESPACE LITERAL+ UIDPLUS CHILDREN
A2 OK CAPABILITY completed.
DEBUG: setDebug: JavaMail version 1.4.1
DEBUG: getProvider() returning
javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun
Microsystems, Inc]
DEBUG: mail.imap.fetchsize: 16384
Thanks for your help.
Kind regards,
Wolfgang
Post by Bill ShannonYou can also simplify your expression by using a single OrTerm with
three HeaderTerms, although it shouldn't make a difference.
The debug output should help figure out what's going on.
Post by Paolo SpadaforaHi,
You can enable debug in javamail and see what's the difference
between the 2
Post by Bill ShannonPost by Paolo Spadaforaimap search commands you run.
The SEARCH command is part of IMAPv4 spec, I don't think you need
any
Post by Bill ShannonPost by Paolo Spadaforaspecial capabilities on your server.
Bye,
Paolo
-----Messaggio originale-----
Da: A mailing list for discussion of the JavaMail(tm) API
Beikircher
Post by Bill ShannonPost by Paolo SpadaforaInviato: martedì 27 gennaio 2009 15.58
Oggetto: JavaMail IMAPFolder search command
Hi there!
I'm quite new to the list and therefore I don't know if I'm in the
correct place. I hope so. :)
Actually I'm trying to issue a SEARCH command (through f.search
where f
Post by Bill ShannonPost by Paolo Spadaforais an object of IMAPFolder) to an Exchange server. The task is to
search
Post by Bill ShannonPost by Paolo Spadaforaout 3 mails (on the basis of the Message-Id in the header).
Therefore,
Post by Bill ShannonPost by Paolo SpadaforaI'm constructing a SearchTerm-object. As far as I understood, I have
to
Post by Bill ShannonPost by Paolo SpadaforaOrTerm
| |
HeaderTerm OrTerm
| |
HeaderTerm HeaderTerm
If I'm issueing that command, the server returns 0 elements. If I
issue
Post by Bill ShannonPost by Paolo Spadaforathe HeaderTerms seperately I get the desired elements.
So, what I'm doing wrong? Must the mail server have some
capabilities to
Post by Bill ShannonPost by Paolo Spadaforaperform searches with a higher depth than 1?
Thanks for your help.
Kind regards,
Wolfgang
P.S: I'm working with JavaMail version 1.4.1.
===========================================================================
the body
Post by Bill ShannonPost by Paolo Spadaforaof the message "signoff JAVAMAIL-INTEREST". For general help, send
email to
===========================================================================
the body
Post by Bill ShannonPost by Paolo Spadaforaof the message "signoff JAVAMAIL-INTEREST". For general help, send
email to
===========================================================================
body
Post by Bill Shannonof the message "signoff JAVAMAIL-INTEREST". For general help, send
email to
--
Wolfgang Beikircher
Center for Applied Software Engineering (CASE)
Free University of Bozen/Bolzano
Mustergasse/Via della Mostra 4
39100 Bozen/Bolzano
Italy
===========================================================================
To unsubscribe, send email to ***@java.sun.com and include in the body
of the message "signoff JAVAMAIL-INTEREST". For general help, send email to
***@java.sun.com and include in the body of the message "help".
===========================================================================
To unsubscribe, send email to ***@java.sun.com and include in the body
of the message "signoff JAVAMAIL-INTEREST". For general help, send email to
***@java.sun.com and include in the body of the message "help".