IMAP search with a full string - imap

I am currently trying to search some email in my Inbox with a string like that "not working anymore" but the problem is that imap will return me the list of email containing the 3 words and not the string "not working anymore".
Any idea how to resolve this? I have no messages containing this string, but the IMAP returns me 2 results because of the problem explained above.
a1 SEARCH BODY "not working anymore"
* SEARCH 4090 7752

Filter/verify the server's result in your client code.
The longer answer is that IMAP servers used to do what you want, but as users wanted smarter fuzzier faster searching, servers started implementing it. For example, users wanted to find messages like this:
foo foo foo foo foo foo foo not working
anymore foo foo foo foo
The whitespace does not match your search term. Do you think the server should return that message?
The IMAP specification is silentish on the issue. As I read it, if a message contains the exact string, that specification says the message must match the search, but if the message doesn't, then... well, then server and client should act to satisfy the user and bring about world peace. This implies that the search result you get from the server contains all the messages you want, so filtering won't miss any results.

Related

Inconsistency with $filter /messages on Graph

We have encountered an odd issue (inconsistency) which seems to be related to the $filter capability of the fetch messages endpoint on Graph.
We reply on querying for messages by their internetMessageId field.
This normally works, but in some cases we’ve seen that the result set is empty (no error), and the odd thing is the same message can be fetched by its subject or sender’s address.
This API call returns an empty result:
https://graph.microsoft.com/v1.0/users/<user_principal_name>/messages?$filter=internetMessageId eq '<CAPJZXvF23=Ut7ksuJzCV+dQa6Pjy+3+uRU7j0v-GLydAi974Rg#mail.gmail.com>'
This API call works:
https://graph.microsoft.com/v1.0/users/<user_principal_name>/messages?$filter=sender/emailAddress/address eq '<sender_address>'
We looked into this, and the problem here is with the app behavior, not the service.
Both queries work as expected, provided that the URL query parameters are correctly encoded by the app, per HTTP encoding practices.
In the first request, there are + characters in the internetMessageId value that the app does not encode before sending the request; the service decodes them into spaces, and that is why the query returns empty results.
When the query string is properly, the correct results are returned, as expected.
We recommend apps always encode the request URL.

GET by Email fails when looking for Email with a "+"

I have an application that stores information about a person onto a database, but when I try to use the URL to GET a user based on their email address users with a + in their email cannot be found.
Example URL that returns person:
https://www.someURL.com/api/people/johnsmith#someemail.com
Example URL that does not return person (returns null):
https://www.someURL.com/api/people/jane+doe#someemail.com
Both emails are in the database as written in the URL so it does not appear to be a typo issue, and I am using postman to test the GET method. Why am I not able to find them, and how can I make it so that they can be found even with the + character?
Working postman request
NOT working postman request
When I search with id I am able to find the person so I know the person exists.
Verification that person exists
My suggestion would be: change your server implementaion from GET to POST and provide an email as a String parameter within the body of request. It'll prevent this and any similar issue with escaping special characters in URI.
If it's not possible, try to frame email address with a single ' or double " quotes, depending on how your web server treats incoming request it may help as well.
Nice to know that "+" is not really a 'valid' character for a lot of email providers for a reason. For instance, Gmail will not let you to create an email address with anything but [A-z0-9] (alphanumeric) and dot (.) characters. I'm pretty sure they were tired of validating input emails with complex regular expression and just limited it to basic ones.
'+' is a reserved character in URIs, so in order to prevent it being interpreted as a space character you would need to percent-encode it. In your example, replace '+' with '%2B'.
https://www.someURL.com/api/people/jane%2Bdoe#someemail.com
There are other characters that are allowed in email addresses but are reserved characters in URIs, so it would be best to percent-encode the whole email address, just in case.

MicrosoftGraph querying for #microsoft.graph.downloadUrl returns character '#' is not valid

I have problem querying for "#microsoft.graph.downloadUrl" using microsoft graph endpoint.
Running a query like this:
https://graph.microsoft.com/v1.0/me/drive/root/children?$select=id,name,file,folder,size,lastModifiedDateTime,#microsoft.graph.downloadUrl
Returns a bad request error with message: "Syntax error: character '#' is not valid at position..." I had not such a problem with OneDrive direct endpoint so I am wondering how exactly should I run the intended query?
Earlier this year the attribute #content.downloadUrl was renamed to #microsoft.graph.downloadUrl.It looks like there is an issue/discrepancy between the attribute's name in the results verse the query parameters.
The $select clause is still looking for the original name. As best I can tell, this isn't documented at the moment. That said, this query should do the trick for you:
/me/drive/root/children?$select=id,name,file,folder,size,lastModifiedDateTime,content.downloadUrl

facebook graph api returns error 2500 when there are commas in the id url

I'm attempting to retrieve the "shares" graph data for a number of pages in JSON format. I suspect that the errors I am encountering stem from the fact that some of the URLs have commas in them, and are being parsed as an attempt to pass multiple ids.
Returns graph data.
https://graph.facebook.com/?ids=http://celebritybabies.people.com/2012/08/23/backstreet-boys-howie-dorough-expecting-second-son/
Returns error 2500 "Cannot specify an empty identifier"
https://graph.facebook.com/?ids=http://www.people.com/people/article/0,,20624518,00.html
Encode the commas, still returns 2500
https://graph.facebook.com/?ids=http://www.people.com.people.article/0%2C%2C20624518%2C00.html
There doesn't seem to a way around it other than to use the normal inspection
http://graph.facebook.com/http://www.people.com/people/article/0,,20624518,00.html
You may have to file a bug at http://developers.facebook.com/bugs though I feel as the answer would most likely be "Status by design".
You could try using FQL instead, querying the link_stat table:
SELECT url, normalized_url, share_count, comments_fbid FROM link_stat
WHERE url = 'http://www.people.com/people/article/0,,20624518,00.html'
(See result in Graph API Explorer.) You can also use WHERE url IN ("…", "…", …) to check multiple URLs at once.
This also returns a comments_fbid of 10151022112466453, and that one you can look up via the API, https://graph.facebook.com/10151022112466453
Maybe this can work as a workaround, until Facebook fixes this problem.

Sending a regEx pattern as a parameter in a query string

I have to design a RESTful client and service in Java. For a GET request, i need to send a regEx pattern as a query parameter.
in the client i'm sending the pattern as
http://localhost:6520/restservice/foo?pattern=^BP$
i'm getting Illegal Endpoint address exception.
I even tried
http://localhost:6520/restservice/foo?pattern='^BP$'
and it still gives the same exception. Can anyone help me with this?
The ^ is an illegal character in URL's and the $ is a reserved character in URL's. You'd like to URL-encode those characters first. The correct URL would then end up to be http://localhost:6520/restservice/foo?pattern=%5eBP%24
Most server side programming languages and view technologies offer facilities to convert URL's that way. Since it's unclear which one you're using, we can't give any hints how to do this. You now at least know the right keywords to search on: "URL encoding". Google around together with the programming language as keyword.

Resources