imap "search all" scope: all folders/current folder? - search

I'm trying to figure out if IMAP's search (with args: "unseen all") command works by searching all folders in a mailbox, or just the currently selected folder?
I.e. when selecting INBOX and issuing search command, it doesn't find any new messages.
a select "INBOX"
* 383 EXISTS
* 0 RECENT
[...]
a search unseen all
* SEARCH
a OK Success
But when I move into a folder which has a new message, it works:
a select "inbox/test1/test2"
[...]
a uid search unseen all
* SEARCH 7 8 9
It detects three new messages, which is the truth. So my question is, is this behavior correct? Shouldn't search unseen all search all folders for new messages?

According to the RFC
The SEARCH command searches the
mailbox for messages that match
the given searching criteria. Searching criteria consist of one
or more search keys. The untagged SEARCH response from the
server
contains a listing of message sequence numbers corresponding to
those messages that match the searching criteria.
where the keyword ALL refers to
All messages in the mailbox; the
default initial key for
ANDing.
So, no, there does not appear to be a standard way to do what you're looking for (although there may well be plugins for various IMAP servers that facilitate that).

Related

Gmail IMAP Javamail search returns no messages where web does

I'm working on load testing a web application that sends links via email. I have a gmail account set up specifically to be the recipient for this. When generating new accounts I add a guid to the recipient email (eg. loadtest_nmndbiwpdi#gmaildomain.com). When I execute the test it will either succeed entirely or fail entirely, but failures seem to be pretty random.
Here is my search snippet:
if (!inbox.isOpen()) {
inbox.open(Folder.READ_ONLY);
}
SearchTerm toTerm = new RecipientTerm(RecipientType.TO, new InternetAddress(to));
messages = inbox.search(toTerm);
While the script is running, it executes this in a 100 iteration loop with a 3 second pause. When it's failing script output with imap debugging on repeatedly shows the following:
A4 SEARCH TO loadtest_nmndbiwpdi#gmaildomain.com ALL
* SEARCH
A4 OK SEARCH completed (Success)
But no actual result. during the period of execution, however, I can do a search in gmail for this recipient and it pops right up. Any suggestions for getting to the bottom of this?
Gmail doesn't exactly implement the IMAP spec, especially for searching. Gmail searches are always for whole words, although that shouldn't be a problem here.
You can try using the Gmail-specific support in JavaMail, e.g., the GmailRawSearchTerm class.
I implemented a local cache. I initialize it at the beginning of the load test scenario, downloading the last days messages and capturing the last messages UID (using gmail imap plugin). Any time a session looks for an email it looks in the local cache. If it's not there it sets a flag so other sessions don't overlap caching and retrieves the newest messages.
Because it was intermittent, I wanted to give it a few days. It's run perfectly for the past 4 days. I could probably go one step better and set up a listener on the folder for new mail, but for now I'm satisfied that gmail was just returning 'success' but not doing the search after so many imap searches in succession.
Thanks to all for your feedback and suggestions!

gmail-api to check how many mails are unread and user has not replied to

I am developing an android app based on gmail-api in which I need to show how many mails are unread (based on a particular sender/subject) , and also need to show how many mails the user has not replied to (based on a particular sender/subject) . If anybody has done this pls let me know if this is feasible.
You need to use Users.messages: list method since it only return messages that match the specified query. It supports the same query format as the Gmail search box. For example, from:someuser#example.com rfc822msgid: is:unread.
Based also from this related SO ticket, the q parameter (query) can be all kinds of stuff and it is the same as the gmail search bar on the top of the web interface. You can use this search method to find unread messages, for example like
List<Message> unreadMessageIDs = ListMessages(service, "me", "is:unread");.
Hope this helps! :)

What is Lucene query to search for a wild character string

In Kibana I am trying to pull the my application log messages that had masked fields.
Example log message:
***statusMessage=, displayMessage=, securityInfoOutput=securityPin=pin=****, pinHint=*************
I want to search and pull the messages that have masked data - more than two consecutive *'s in the message.
Trying with search term message:"pin=\*\*\*\*"
but it didn't work
You seem to be thinking of search in the same way you'd type CTRL+F and search in a file. Search engines don't work that way. Search works based on exact matches of tokens. Tokens typically correspond to words extracted from text.
You can control how text is transformed into tokens using a process known as analysis. Analysis runs text through tokenization and various filters that decide how text is broken up into tokens and other pieces of metadata associated with each token.
This blog post I wrote might help put some of this into context.

How IMAP client can detact Gmail Label rename programmatically

I am working on Email client App and using GMAIL IMAP condstore capability for syncing label,read and unread changes.
My application flow looks like below.
1) Initially Selecting the "Gmail/All Mail"
2) Fetching the changes from the server since last sync with last modseq like
FETCH 1:* (X-GM-LABELS) (CHANGEDSINCE highestmodseq)
Here IMAP server returns the messages for which label,read and unread changes detected since last sync.
Suppose I have label "A" and it has got 100 emails. Now if Label A is deleted then server returns 100 messages as changes,it works as expected.
But in case if label "A" is renamed to Label "B" then server should return 100 messages as changes but it won't.
Can you please suggest how to sync messages which are under Label A previously and got renamed to Label B
PS: According to IMAP server standards uniqueness of a label is identified based on label name and uid validity.
Gmail labels are retrieving with 'LIST "" "*"'.
Suppose if Label is renamed to some thing else then how to find whether it was newly created label or the renamed label
Thanks
Subbi Reddy
PS: According to IMAP server standards uniqueness of a label is identified based on label name and uid validity.
This is not true. The IMAP protocol does not define a "label". It defines what a "mailbox" is, and that each message has a set of "flags" or "keywords".
When GMail decided to implement IMAP, they made an unfortunate choice to shoehorn their concept of labels on top of the mailboxes instead of reusing the existing flags metadata. (They had some reasons for that, some of them are valid, some of them are not, and that discussion is out-of-scope for stackoverflow.)
But in case if label "A" is renamed to Label "B" then server should return 100 messages as changes but it won't.
This understanding certainly makes sense. The fact that GMail behaves differently is disappointing from the IMAP client's perspective. I suggest to bring this up to GMail's developers; they do read the ietf-imapext mailing list.
You're correct that a label rename seems like it should result in updates to the MODSEQ of all messages whose label set was affected by the rename. But it doesn't. So you're going to have to fetch the list of folders/labels and correlate the old label list with the new one.
As you know, you get the list of Gmail labels by issuing a LIST command:
A001 LIST "" "*"
What happens when the response to this command differs from the previous set of folders that you knew about? Unfortunately, IMAP doesn't give you a folder identifier that you can use to track an individual folder through renames. Fortunately, Gmail kinda sorta does.
(NOTE: THIS SOLUTION IS NOT SANCTIONED BY GMAIL, BUT IT APPARENTLY WORKS, SO THERE'S THAT.)
Every IMAP folder has a UIDVALIDITY value associated with it. It's generally there to let you know if somethin has happened on the server such that the UID-to-message mapping you've cached is no longer valid. According to the IMAP RFC,
3) If the [folder] is deleted and a new [folder] with the
same name is created at a later date, the server must
either keep track of unique identifiers from the
previous instance of the [folder], or it must assign a
new UIDVALIDITY value to the new instance of the
[folder].
4) The combination of [folder] name, UIDVALIDITY, and UID
must refer to a single immutable message on that server
forever.
Every folder exposed by Gmail IMAP happens to have a distinct UIDVALIDITY value. When you rename a folder, its UIDVALIDITY does not change. So if you notice that the set of folders has changed and you grab the UIDVALIDITY for every label-folder in the Gmail store, you can match up folders from your old snapshot and from the current store by finding which ones have matching UIDVALIDITY values.
# before, label "blurdybloop" had UIDVALIDITY 32
A002 STATUS "mylabel" (UIDVALIDITY)
* STATUS "mylabel" (UIDVALIDITY 32)
A002 OK Success
# this indicates that "blurdybloop" has been renamed to "mylabel"
If you want to be extra-careful, you may want to do a STATUS on every label folder even if the folder list hasn't changed just to catch circular renames like A -> B, C -> A, B -> C (which results in swapping the names of labels A and C). But that's probably overkill.
No, You can't do this with the IMAP language. Gmail labels are exclusively handled with http(s) API produced by Google.
IMAP has been designed to be used a set of commands send over TCP port 143.
You can check the list of the available commands.

Sharepoint 2010 Search - Auto add property to QueryString

Have a bit of a difficult question which as far as I can see, no one has really managed to fix yet.
Here's the scenario. Sharepoint 2010 EnterPrise Search Centre.
I've created a custom Search Results Page. I want people who type any word in the Search box to only display results where the Value provided by the user matches with a specific Managed Search Property.
Now I know a user can search for People with specific criteria by entering for example
Continent:Europe in the actual Search Box. Sharepoint will refresh the page with the following added to the Query String: k=Continent:Europe and the results will only show people who are from Europe.
So my question is : How can I fix this so that the user does not have to enter the Continent:Europe in the Search box and can just type Europe?
Thanks
One option is to create your own webpart that acts as the search box and replaces the standard one with your custom search box. The advantage of this is that you can more tightly control the user interface and then set up the query passed to the server (with the "k" parameter). You could prepend "Continent:" before the search term entered to help narrow the search.
Another use for this is to append * onto any search term because the People search does include partial words by default.
We did this on one site to simplify the input and allow users to search with one text box (without the advanced features) and then users can use the refinements to narrow the search.

Resources