Discussion:
JavaMail IMAPFolder search command
Wolfgang Beikircher
2009-01-27 14:57:30 UTC
Permalink
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
is an object of IMAPFolder) to an Exchange server. The task is to search
out 3 mails (on the basis of the Message-Id in the header). Therefore,
I'm constructing a SearchTerm-object. As far as I understood, I have to
construct it like a tree. My tree is looking similar to this one:

OrTerm
| |
HeaderTerm OrTerm
| |
HeaderTerm HeaderTerm

If I'm issueing that command, the server returns 0 elements. If I issue
the HeaderTerms seperately I get the desired elements.

So, what I'm doing wrong? Must the mail server have some capabilities to
perform 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.

===========================================================================
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".
Paolo Spadafora
2009-01-27 15:33:51 UTC
Permalink
Hi,
You can enable debug in javamail and see what's the difference between the 2
imap search commands you run.
The SEARCH command is part of IMAPv4 spec, I don't think you need any
special capabilities on your server.

Bye,
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: martedì 27 gennaio 2009 15.58
A: JAVAMAIL-***@JAVA.SUN.COM
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
is an object of IMAPFolder) to an Exchange server. The task is to search
out 3 mails (on the basis of the Message-Id in the header). Therefore,
I'm constructing a SearchTerm-object. As far as I understood, I have to
construct it like a tree. My tree is looking similar to this one:

OrTerm
| |
HeaderTerm OrTerm
| |
HeaderTerm HeaderTerm

If I'm issueing that command, the server returns 0 elements. If I issue
the HeaderTerms seperately I get the desired elements.

So, what I'm doing wrong? Must the mail server have some capabilities to
perform 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.

===========================================================================
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".
Bill Shannon
2009-01-27 18:16:48 UTC
Permalink
You 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 Spadafora
Hi,
You can enable debug in javamail and see what's the difference between the 2
imap search commands you run.
The SEARCH command is part of IMAPv4 spec, I don't think you need any
special capabilities on your server.
Bye,
Paolo
-----Messaggio originale-----
Da: A mailing list for discussion of the JavaMail(tm) API
Inviato: 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
is an object of IMAPFolder) to an Exchange server. The task is to search
out 3 mails (on the basis of the Message-Id in the header). Therefore,
I'm constructing a SearchTerm-object. As far as I understood, I have to
OrTerm
| |
HeaderTerm OrTerm
| |
HeaderTerm HeaderTerm
If I'm issueing that command, the server returns 0 elements. If I issue
the HeaderTerms seperately I get the desired elements.
So, what I'm doing wrong? Must the mail server have some capabilities to
perform 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.
===========================================================================
of the message "signoff JAVAMAIL-INTEREST". For general help, send email to
===========================================================================
of the message "signoff JAVAMAIL-INTEREST". For general help, send email to
===========================================================================
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".
Wolfgang Beikircher
2009-01-28 13:50:35 UTC
Permalink
Yes, I know. I tried also that variant but with no success.

This is the debug output I get from javaMail when issueing the command:
A6 SEARCH OR OR HEADER Message-ID
***@openmapi.org HEADER Message-ID
rt-3.4.5-16942-1232966693-1122.46544-5-***@blabla.org HEADER Message-ID
***@blabla.org ALL
* SEARCH
A6 OK SEARCH completed.

This is the debug output when I try to search with 2 terms connected
through a OrTerm:
A6 SEARCH OR HEADER Message-ID
***@openmapi.org HEADER Message-ID
rt-3.4.5-16942-1232966693-1122.46544-5-***@blabla.org ALL
* 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
how to use the SearchTerm-constructs:
[...]

IMAPFolder f = (IMAPFolder)
eStore.getDefaultFolder().getFolder("inbox");


f.open(Folder.READ_ONLY);

SearchTerm a = new HeaderTerm(Def.HEADER_MESSAGE_ID,
"***@openmapi.org");
SearchTerm b = new HeaderTerm(Def.HEADER_MESSAGE_ID,
"rt-3.4.5-16942-1232966693-1122.46544-5-***@blabla.org");
SearchTerm c = new OrTerm(a, b);
SearchTerm d = new HeaderTerm(Def.HEADER_MESSAGE_ID,
"***@blabla.org");
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 Shannon
You 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 Spadafora
Hi,
You can enable debug in javamail and see what's the difference
between the 2
Post by Bill Shannon
Post by Paolo Spadafora
imap search commands you run.
The SEARCH command is part of IMAPv4 spec, I don't think you need
any
Post by Bill Shannon
Post by Paolo Spadafora
special capabilities on your server.
Bye,
Paolo
-----Messaggio originale-----
Da: A mailing list for discussion of the JavaMail(tm) API
Beikircher
Post by Bill Shannon
Post by Paolo Spadafora
Inviato: 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 Shannon
Post by Paolo Spadafora
is an object of IMAPFolder) to an Exchange server. The task is to
search
Post by Bill Shannon
Post by Paolo Spadafora
out 3 mails (on the basis of the Message-Id in the header).
Therefore,
Post by Bill Shannon
Post by Paolo Spadafora
I'm constructing a SearchTerm-object. As far as I understood, I have
to
Post by Bill Shannon
Post by Paolo Spadafora
OrTerm
| |
HeaderTerm OrTerm
| |
HeaderTerm HeaderTerm
If I'm issueing that command, the server returns 0 elements. If I
issue
Post by Bill Shannon
Post by Paolo Spadafora
the HeaderTerms seperately I get the desired elements.
So, what I'm doing wrong? Must the mail server have some
capabilities to
Post by Bill Shannon
Post by Paolo Spadafora
perform 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 Shannon
Post by Paolo Spadafora
of the message "signoff JAVAMAIL-INTEREST". For general help, send
email to
===========================================================================
the body
Post by Bill Shannon
Post by Paolo Spadafora
of the message "signoff JAVAMAIL-INTEREST". For general help, send
email to
===========================================================================
body
Post by Bill Shannon
of 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".
Paolo Spadafora
2009-01-28 17:02:55 UTC
Permalink
Check 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-----
Da: A mailing list for discussion of the JavaMail(tm) API [mailto:JAVAMAIL-***@JAVA.SUN.COM] Per conto di Wolfgang Beikircher
Inviato: mercoledì 28 gennaio 2009 14.51
A: JAVAMAIL-***@JAVA.SUN.COM
Oggetto: Re: R: JavaMail IMAPFolder search command

Yes, I know. I tried also that variant but with no success.

This is the debug output I get from javaMail when issueing the command:
A6 SEARCH OR OR HEADER Message-ID
***@openmapi.org HEADER Message-ID
rt-3.4.5-16942-1232966693-1122.46544-5-***@blabla.org HEADER Message-ID
***@blabla.org ALL
* SEARCH
A6 OK SEARCH completed.

This is the debug output when I try to search with 2 terms connected
through a OrTerm:
A6 SEARCH OR HEADER Message-ID
***@openmapi.org HEADER Message-ID
rt-3.4.5-16942-1232966693-1122.46544-5-***@blabla.org ALL
* 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
how to use the SearchTerm-constructs:
[...]

IMAPFolder f = (IMAPFolder)
eStore.getDefaultFolder().getFolder("inbox");


f.open(Folder.READ_ONLY);

SearchTerm a = new HeaderTerm(Def.HEADER_MESSAGE_ID,
"***@openmapi.org");
SearchTerm b = new HeaderTerm(Def.HEADER_MESSAGE_ID,
"rt-3.4.5-16942-1232966693-1122.46544-5-***@blabla.org");
SearchTerm c = new OrTerm(a, b);
SearchTerm d = new HeaderTerm(Def.HEADER_MESSAGE_ID,
"***@blabla.org");
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 Shannon
You 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 Spadafora
Hi,
You can enable debug in javamail and see what's the difference
between the 2
Post by Bill Shannon
Post by Paolo Spadafora
imap search commands you run.
The SEARCH command is part of IMAPv4 spec, I don't think you need
any
Post by Bill Shannon
Post by Paolo Spadafora
special capabilities on your server.
Bye,
Paolo
-----Messaggio originale-----
Da: A mailing list for discussion of the JavaMail(tm) API
Beikircher
Post by Bill Shannon
Post by Paolo Spadafora
Inviato: 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 Shannon
Post by Paolo Spadafora
is an object of IMAPFolder) to an Exchange server. The task is to
search
Post by Bill Shannon
Post by Paolo Spadafora
out 3 mails (on the basis of the Message-Id in the header).
Therefore,
Post by Bill Shannon
Post by Paolo Spadafora
I'm constructing a SearchTerm-object. As far as I understood, I have
to
Post by Bill Shannon
Post by Paolo Spadafora
OrTerm
| |
HeaderTerm OrTerm
| |
HeaderTerm HeaderTerm
If I'm issueing that command, the server returns 0 elements. If I
issue
Post by Bill Shannon
Post by Paolo Spadafora
the HeaderTerms seperately I get the desired elements.
So, what I'm doing wrong? Must the mail server have some
capabilities to
Post by Bill Shannon
Post by Paolo Spadafora
perform 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.
===========================================================================
Post by Bill Shannon
Post by Paolo Spadafora
of the message "signoff JAVAMAIL-INTEREST". For general help, send email to
===========================================================================
Post by Bill Shannon
Post by Paolo Spadafora
of the message "signoff JAVAMAIL-INTEREST". For general help, send email to
===========================================================================
Post by Bill Shannon
of 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".
Wolfgang Beikircher
2009-01-29 08:25:28 UTC
Permalink
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 Spadafora
Check 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 Shannon
You 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 Spadafora
Hi,
You can enable debug in javamail and see what's the difference
between the 2
Post by Bill Shannon
Post by Paolo Spadafora
imap search commands you run.
The SEARCH command is part of IMAPv4 spec, I don't think you need
any
Post by Bill Shannon
Post by Paolo Spadafora
special capabilities on your server.
Bye,
Paolo
-----Messaggio originale-----
Da: A mailing list for discussion of the JavaMail(tm) API
Beikircher
Post by Bill Shannon
Post by Paolo Spadafora
Inviato: 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 Shannon
Post by Paolo Spadafora
is an object of IMAPFolder) to an Exchange server. The task is to
search
Post by Bill Shannon
Post by Paolo Spadafora
out 3 mails (on the basis of the Message-Id in the header).
Therefore,
Post by Bill Shannon
Post by Paolo Spadafora
I'm constructing a SearchTerm-object. As far as I understood, I have
to
Post by Bill Shannon
Post by Paolo Spadafora
OrTerm
| |
HeaderTerm OrTerm
| |
HeaderTerm HeaderTerm
If I'm issueing that command, the server returns 0 elements. If I
issue
Post by Bill Shannon
Post by Paolo Spadafora
the HeaderTerms seperately I get the desired elements.
So, what I'm doing wrong? Must the mail server have some
capabilities to
Post by Bill Shannon
Post by Paolo Spadafora
perform 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 Shannon
Post by Paolo Spadafora
of the message "signoff JAVAMAIL-INTEREST". For general help, send
email to
===========================================================================
the body
Post by Bill Shannon
Post by Paolo Spadafora
of the message "signoff JAVAMAIL-INTEREST". For general help, send
email to
===========================================================================
body
Post by Bill Shannon
of 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".
Paolo Spadafora
2009-01-29 09:58:01 UTC
Permalink
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 Spadafora
Check 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 Shannon
You 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 Spadafora
Hi,
You can enable debug in javamail and see what's the difference
between the 2
Post by Bill Shannon
Post by Paolo Spadafora
imap search commands you run.
The SEARCH command is part of IMAPv4 spec, I don't think you need
any
Post by Bill Shannon
Post by Paolo Spadafora
special capabilities on your server.
Bye,
Paolo
-----Messaggio originale-----
Da: A mailing list for discussion of the JavaMail(tm) API
Beikircher
Post by Bill Shannon
Post by Paolo Spadafora
Inviato: 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 Shannon
Post by Paolo Spadafora
is an object of IMAPFolder) to an Exchange server. The task is to
search
Post by Bill Shannon
Post by Paolo Spadafora
out 3 mails (on the basis of the Message-Id in the header).
Therefore,
Post by Bill Shannon
Post by Paolo Spadafora
I'm constructing a SearchTerm-object. As far as I understood, I have
to
Post by Bill Shannon
Post by Paolo Spadafora
OrTerm
| |
HeaderTerm OrTerm
| |
HeaderTerm HeaderTerm
If I'm issueing that command, the server returns 0 elements. If I
issue
Post by Bill Shannon
Post by Paolo Spadafora
the HeaderTerms seperately I get the desired elements.
So, what I'm doing wrong? Must the mail server have some
capabilities to
Post by Bill Shannon
Post by Paolo Spadafora
perform 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 Shannon
Post by Paolo Spadafora
of the message "signoff JAVAMAIL-INTEREST". For general help, send
email to
===========================================================================
the body
Post by Bill Shannon
Post by Paolo Spadafora
of the message "signoff JAVAMAIL-INTEREST". For general help, send
email to
===========================================================================
body
Post by Bill Shannon
of 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".
Wolfgang Beikircher
2009-01-29 13:29:26 UTC
Permalink
Post by Paolo Spadafora
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>
Yes, the debug output is completely the same. And there it works in all
situations (no matter which flag is on which positions).
Post by Paolo Spadafora
SEARCH OR (ANSWERED) ( OR (UNSEEN) (UNDELETED) ) ALL
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);
I tried your suggestion. But it does not work. The following error will
be thrown:

A5 BAD Protocol Error: "Invalid key supplied in the SEARCH command".

This is the stack trace:

javax.mail.MessagingException: A5 BAD Protocol Error: "Invalid key
supplied in the SEARCH command".;
nested exception is:
com.sun.mail.iap.BadCommandException: A5 BAD Protocol Error: "Invalid
key supplied in the SEARCH command".
at com.sun.mail.imap.IMAPFolder.doCommand(IMAPFolder.java:2588)
at org.zimbra.exchange.MyTestClass.main(MyTestClass.java:305)
Caused by: com.sun.mail.iap.BadCommandException: A5 BAD Protocol Error:
"Invalid key supplied in the SEARCH command".
at com.sun.mail.iap.Protocol.handleResult(Protocol.java:343)
at org.zimbra.exchange.TestOrCommand.doCommand(TestOrCommand.java:32)
at com.sun.mail.imap.IMAPFolder.doProtocolCommand(IMAPFolder.java:2629)
at com.sun.mail.imap.IMAPFolder.doCommand(IMAPFolder.java:2583)
... 1 more


I tried also to construct different search strings but all of them do
not work. I tried following variations:
- SEARCH OR (ANSWERED) ( OR (UNSEEN) (UNDELETED) )
- SEARCH OR (ANSWERED) OR (UNSEEN) (UNDELETED)
- SEARCH OR ((ANSWERED) (UNSEEN) (UNDELETED))
- SEARCH OR (ANSWERED UNSEEN UNDELETED)

In the rfc there is one line which might explain the whole behaviour:
"[...]
When multiple keys are specified, the result is the intersection (AND
function) of all the messages that match those keys.
[...]"
Post by Paolo Spadafora
And see how it goes.
Paolo
-----Messaggio originale-----
Inviato: giovedì 29 gennaio 2009 9.25
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)?
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 Spadafora
Check 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 Shannon
You 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 Spadafora
Hi,
You can enable debug in javamail and see what's the difference
between the 2
Post by Bill Shannon
Post by Paolo Spadafora
imap search commands you run.
The SEARCH command is part of IMAPv4 spec, I don't think you need
any
Post by Bill Shannon
Post by Paolo Spadafora
special capabilities on your server.
Bye,
Paolo
-----Messaggio originale-----
Da: A mailing list for discussion of the JavaMail(tm) API
Beikircher
Post by Bill Shannon
Post by Paolo Spadafora
Inviato: 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 Shannon
Post by Paolo Spadafora
is an object of IMAPFolder) to an Exchange server. The task is to
search
Post by Bill Shannon
Post by Paolo Spadafora
out 3 mails (on the basis of the Message-Id in the header).
Therefore,
Post by Bill Shannon
Post by Paolo Spadafora
I'm constructing a SearchTerm-object. As far as I understood, I have
to
Post by Bill Shannon
Post by Paolo Spadafora
OrTerm
| |
HeaderTerm OrTerm
| |
HeaderTerm HeaderTerm
If I'm issueing that command, the server returns 0 elements. If I
issue
Post by Bill Shannon
Post by Paolo Spadafora
the HeaderTerms seperately I get the desired elements.
So, what I'm doing wrong? Must the mail server have some
capabilities to
Post by Bill Shannon
Post by Paolo Spadafora
perform 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 Shannon
Post by Paolo Spadafora
of the message "signoff JAVAMAIL-INTEREST". For general help, send
email to
===========================================================================
the body
Post by Bill Shannon
Post by Paolo Spadafora
of the message "signoff JAVAMAIL-INTEREST". For general help, send
email to
===========================================================================
body
Post by Bill Shannon
of 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".
Paolo Spadafora
2009-01-29 13:38:33 UTC
Permalink
I think it's a little bug in Exchange server.


Paolo



-----Messaggio originale-----
Da: Wolfgang Beikircher [mailto:***@unibz.it]
Inviato: giovedì 29 gennaio 2009 14.29
A: Paolo Spadafora; JAVAMAIL-***@JAVA.SUN.COM
Oggetto: Re: R: R: R: JavaMail IMAPFolder search command
Post by Paolo Spadafora
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>
Yes, the debug output is completely the same. And there it works in all
situations (no matter which flag is on which positions).
Post by Paolo Spadafora
SEARCH OR (ANSWERED) ( OR (UNSEEN) (UNDELETED) ) ALL
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);
I tried your suggestion. But it does not work. The following error will
be thrown:

A5 BAD Protocol Error: "Invalid key supplied in the SEARCH command".

This is the stack trace:

javax.mail.MessagingException: A5 BAD Protocol Error: "Invalid key
supplied in the SEARCH command".;
nested exception is:
com.sun.mail.iap.BadCommandException: A5 BAD Protocol Error: "Invalid
key supplied in the SEARCH command".
at com.sun.mail.imap.IMAPFolder.doCommand(IMAPFolder.java:2588)
at org.zimbra.exchange.MyTestClass.main(MyTestClass.java:305)
Caused by: com.sun.mail.iap.BadCommandException: A5 BAD Protocol Error:
"Invalid key supplied in the SEARCH command".
at com.sun.mail.iap.Protocol.handleResult(Protocol.java:343)
at org.zimbra.exchange.TestOrCommand.doCommand(TestOrCommand.java:32)
at com.sun.mail.imap.IMAPFolder.doProtocolCommand(IMAPFolder.java:2629)
at com.sun.mail.imap.IMAPFolder.doCommand(IMAPFolder.java:2583)
... 1 more


I tried also to construct different search strings but all of them do
not work. I tried following variations:
- SEARCH OR (ANSWERED) ( OR (UNSEEN) (UNDELETED) )
- SEARCH OR (ANSWERED) OR (UNSEEN) (UNDELETED)
- SEARCH OR ((ANSWERED) (UNSEEN) (UNDELETED))
- SEARCH OR (ANSWERED UNSEEN UNDELETED)

In the rfc there is one line which might explain the whole behaviour:
"[...]
When multiple keys are specified, the result is the intersection (AND
function) of all the messages that match those keys.
[...]"
Post by Paolo Spadafora
And see how it goes.
Paolo
-----Messaggio originale-----
Inviato: giovedì 29 gennaio 2009 9.25
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)?
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 Spadafora
Check 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 Shannon
You 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 Spadafora
Hi,
You can enable debug in javamail and see what's the difference
between the 2
Post by Bill Shannon
Post by Paolo Spadafora
imap search commands you run.
The SEARCH command is part of IMAPv4 spec, I don't think you need
any
Post by Bill Shannon
Post by Paolo Spadafora
special capabilities on your server.
Bye,
Paolo
-----Messaggio originale-----
Da: A mailing list for discussion of the JavaMail(tm) API
Beikircher
Post by Bill Shannon
Post by Paolo Spadafora
Inviato: 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 Shannon
Post by Paolo Spadafora
is an object of IMAPFolder) to an Exchange server. The task is to
search
Post by Bill Shannon
Post by Paolo Spadafora
out 3 mails (on the basis of the Message-Id in the header).
Therefore,
Post by Bill Shannon
Post by Paolo Spadafora
I'm constructing a SearchTerm-object. As far as I understood, I have
to
Post by Bill Shannon
Post by Paolo Spadafora
OrTerm
| |
HeaderTerm OrTerm
| |
HeaderTerm HeaderTerm
If I'm issueing that command, the server returns 0 elements. If I
issue
Post by Bill Shannon
Post by Paolo Spadafora
the HeaderTerms seperately I get the desired elements.
So, what I'm doing wrong? Must the mail server have some
capabilities to
Post by Bill Shannon
Post by Paolo Spadafora
perform 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 Shannon
Post by Paolo Spadafora
of the message "signoff JAVAMAIL-INTEREST". For general help, send
email to
===========================================================================
the body
Post by Bill Shannon
Post by Paolo Spadafora
of the message "signoff JAVAMAIL-INTEREST". For general help, send
email to
===========================================================================
body
Post by Bill Shannon
of 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".
Bill Shannon
2009-01-30 20:21:52 UTC
Permalink
Post by Wolfgang Beikircher
"[...]
When multiple keys are specified, the result is the intersection (AND
function) of all the messages that match those keys.
[...]"
Unless you use the OR key. Read the entire SEARCH spec.

All evidence suggests it's a bug in Exchange. You know where to find
Microsoft. If you get an answer from them, let us know.

===========================================================================
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".
Loading...