0
votes

In our application, we have different users. Each user will register his own email account to fetch emails through IMAP.

Currently the requirement is to search emails across all registered user email accounts, if any one of the users searches.

For example, when user1 wants to view '[email protected]' related emails, emails from user2, user3 etc, will also be fetched and shown to user1, same with other users too.

We can fetch emails one after another and merge all before showing to end-user, but it is very time consuming. Is there any other optimistic method to search across all mail accounts in IMAP Java?

Note: All users are related to each other and they all agreed to share each other mailbox.

1
The question is: can an IMAP connection be to more than one mailbox at the same time? The answer is no. - user1907906
You could do the search in parallel over all mailboxes using threads. - Markus W Mahlberg

1 Answers

0
votes

Many IMAP servers let you access several people's inboxes, e.g. the inbox of the user you're logged in as is called just inbox, and other people's are called /users/john/inbox, users.john.inbox or similar. When that is the case you'll usually need to adjust the access control on the mailbox to make it readable (the default is invariably that only the mailbox' owner can read the mailbox).

Some people solve this problem by having a shared mailbox; all inbound mail is written to /shared/archive as well as each person's inbox. Then you can search the archive mailbox.

However, I note that you use [email protected] as mailbox. Gmail does not allow shared access. If you use gmail you can only ever access the logged-in user's email.