Exchange 2010 strange behaviour on search UID SEARCH CHARSET US-ASCII FROM - imap

I'm really spent a lot of time searching about, but no luck.
My issue is not directly related to Mailkit working or not, it is doing right but perhaps someone here have a clue.
I have to look for mails unseen mails from specific mail address on a Exchange 2010 using IMAP. All work fine (until now) for any server except this one.
When "from" mail address in format like John Doe <johndoe#pluto.com> a search for johndoe#pluto.com does not return any UIDs;
John Doe return UID collection;
On the other hand if "from" mail is in plain format all works fine.
Does anybody have any idea or know if is it an issue on Exch2010?
As a work around I'm thinking to make a simple search unseen to get UIDs then Fetch and look at Envelope
By the way here I have on log when message from = John Doe <johndoe#pluto.com>;
C: A00000006 UID SEARCH CHARSET US-ASCII FROM johndoe#pluto.com
S: * SEARCH
S: A00000006 OK SEARCH completed.

Almost 1 year later, seems I found why I canĀ“t get any result when searching From when mail address have Display Name.
Here Dmitry explain Exchange behaviour
https://blogs.technet.microsoft.com/dkhrebin/2013/10/04/how-exchange-imap-search-in-message-header/
A short quote say:
If you use SEARCH FROM (for CC, BCC, TO idea the same) Exchange will search in message's Property: PR_SENT_REPRESENTING_NAME, PR_SENT_REPRESENTING_NAME_A,
ptagSentRepresentingName
The PR_SENT_REPRESENTING_NAME property contains the display name for the messaging user represented by the sender.
So in addition to:SearchQuery.FromContains ("johndoe#pluto.com").Or (SearchQuery.FromContains ("John Doe"));
I can use SearchQuery.HeaderContains ("from", "johndoe#pluto.com");
Since Display Name can be anything and can be changed anytime, and mail address is always same. I can deal with both commands command lines above.
But I can't determine which has the best performance.

I've noticed that each IMAP server seems to behave differently with respect to searching for email addresses and/or Message-Id tokens.
What you may need to do is either do an OR search query:
SearchQuery.FromContains ("johndoe#pluto.com").Or (SearchQuery.FromContains ("John Doe"));
Perhaps that will work around the problem so it works with all IMAP servers?

Related

What causes a "NO UID SEARCH State error"

I have a script that connects via TCP/Sockets, Authenticates SSL, and then checks if the response from stream returns "OK".
It then sends a UID search command:
{tag} UID SEARCH (UNDELETED) (SENTSINCE "{RFC2060 Format Date}")
I then follow that with another OK check aswell as a * SEARCH stream response check.
When both of those are not true, I always end up with this as a result from the stream: xm005 NO UID SEARCH State error
Im not certain but is it possible this returns if the email has no UNDELETED inbox or something?
This seems to occur all the time on one of my chinese friends specific accounts on yeah.net (163-China related email service).
When I login to it with Windows 10's Mail App, I can see it has inboxes in CHINESE. Is it possible something to do with that is causing this issue?
I'm essentially wanting to search for every email within the sent-since date that has not been deleted, perhaps (UNDELETED) isn't a global declaration and is an actual inbox or something?
According to IMAPv4.1's RFC:
UNDELETED
Messages that do not have the \Deleted flag set.
So maybe its not to do with Inbox's? regardless its pretty odd that both emails this occurs on have Chinese Inbox's yet my English-Only one works splendid.
I removed (UNDELETED) and attempted running, and the same issue occurs, so it's not that.
The "state" in the error message could mean "your state does not include a mailbox". Make sure to issue a SELECT command before UID SEARCH.

IMAP FETCH Subject

Using IMAP via telnet, I want to be able to extract the subject from the specific given email. Now I know that the fetch command is responsible for getting data from an email.
My question is, how do I get the subject header specifically, without using a call to BODY[HEADER.FIELDS (SUBJECT)] (which will, in the eyes of the server, 'open the email' and thus set the /seen flag, which is what I don't want to occur)?
I understand FETCH FULL returns the full header, which contains the subject but it's a nightmare to parse through and could be riddled with unseen pitfalls if I manually parse it. How would I get the server to give me just the subject from the header?
I discovered the answer:
BODY.PEEK[HEADER.FIELDS (SUBJECT)]
.PEEK tells it not open it (so /seen isn't set).
Besides BODY.PEEK, you could fetch ENVELOPE, which gives you a parsed summary of much of the message metadata.
"a1 FETCH 1:* (FLAGS BODY[HEADER.FIELDS (SUBJECT DATE FROM)])\r\n"

IMAP search on header not working as expected

I am building library for IMAP my search command works file for the Inbox folder it returns me a number which I can use to fetch the mail. However when I try to search on Sent Items it does not work it does not give an error but just returns Search OK without any numbers. Can you please point out why this behavior. I am hitting Exchange 2010.
My search command is something like:
search all HEADER Message-ID "<cc6aed80-955b-4800-a3ac-6c3942ceecac>"
This is exactly how it is described in http://support.microsoft.com/kb/302965
Possibly of no use, but I ran into possibly the same problem.
In a mailbox with an email from "Bill Gates ", a search with the expression '(FROM "billy#microsoft.com")' returned nothing; a search for '(FROM gates)' return a hit.
I had to change my code to '(HEADER FROM "billy#microsoft.com")' to get it to work.
ALTERNATIVELY:
You may be able to use IMAP4.uid(command, arg[, ...])
See http://docs.python.org/2/library/imaplib.html#imaplib.IMAP4.uid

Can't parse new google urls - HTTP_REFERER doesn't contain parameters anymore

It seems a little odd to my, but although everybody knows about the new google search urls (see Google using # instead of search? in URL. Why?) no one has a problem with the HTTP_REFERER.
I'm using the referrer to parse the google string for the searchquery (&q= ) but as this is all in a hash-tag it wont be sent to the server and all i get is "http://www.google.de/".
So do you know a way of getting the query the user searched for, befor landing on my site?
Due to late-2011 Google security changes, this is no longer possible when the search was performed by a signed-in Google user. See:
http://googleblog.blogspot.com/2011/10/making-search-more-secure.html
http://analytics.blogspot.com/2011/10/making-search-more-secure-accessing.html
Since there are multiple q's in the query string you have to match the "q" parameter globally and take the last one:
/[?|&|#]q=([^&|^#]+)/ig
Get rid of "site:" searches (there are others, but I haven't done them)
/[\+|?|&]?site:([^&|^#])+/g, '');
Then parse the results.
/[\w^'\(\)\{\}]+|"[^"]+"/g
This has been working well for me.

JavaMail: how to get new messages comparing with time-stamps

I'm trying to get messages after a certain time-stamp, the way I've coded it was suggested by another programmer in this site:
GregorianCalendar date = new GregorianCalendar();
SearchTerm newer = new ReceivedDateTerm(ComparisonTerm.GT,date.getTime());
Message msgs[] = folder.search(newerThen);
The issue is that I get all the messages since the date, not the specific time. I was wondering if there is some work-around to emulate this. I mean, for an instance, if I want to get all the messages since today in the midday I would get those messages spicifically and not those ones received in today's morning.
Thanks in advance,
EDIT:
A new thought concerning to this: perhaps some date manipulation could do the job. I mean, comparing the minutes in the timestamp and filter programmatically those messages that don't fit the criteria. I know it's not the best way, but it could work.
PS: I'm using IMAP and trying to get mails from gmail, but I guess it should work no matter what the mail-server is.
Unfortunately, no. In this case, the IMAP protocol is being used by the JavaMail classes, and IMAP's SEARCH command takes only dates, not times (see the SINCE and SENTSINCE criteria).
You could use the setTime() method to query for some specific time.
Example:
setTime(timeInMilliseconds)

Resources