Link to home
Start Free TrialLog in
Avatar of fhios
fhios

asked on

Querying received e-mails from an agent

Hi,

I'm new to Lotus Notes development and I'm trying to write an agent that when triggered searches a mail database of any received e-mails with a specified time range.

I figured out how to query by date range but I don't know how to limit the search to received e-mails only (e.g. no drafts, not sent items, etc.).

Any help would be greatly appreciated.

Thank you in advance.

Alex
Avatar of Sjef Bosman
Sjef Bosman
Flag of France image

How do you do the search, which method do you use: NotesDatabase.Search, NotesDatabase.FTSearch, NotesView.FTSearch, or do you use a view that your code traverses from beginning to end, maybe with a GetElementsByKey with a date?

In all cases: check the Sent view in the mail database, more precisely the Select statement. That's what you need to copy to your Search. If you use FTSearch, the syntax is different but the same can be accomplished (usually).

Could you show us some leg, er... some code of the agent? Thanks.
Avatar of fhios
fhios

ASKER

Here is a snippet of the code in the agent.

The logic within the callback marks the document as processed by calling
context.updateProcessedDoc(document);

Open in new window

.

	public <T> int withEachDocumentFromBatch(AgentContext context, AgentLog log, DocumentCallback<T> callback) throws Exception {
		int processedCount = 0;
		DocumentCollection unprocessedDocuments = context.unprocessedSearch([NEED TO FIGURE OUT THE QUERY HERE]);
		log.info("Documents found in 'batch' mode");

		int count = (unprocessedDocuments != null) ? unprocessedDocuments.getCount() : 0;
		log.info("Found " + count + " documents");

		for (int i = 1; i <= count; i++) {
			try {
				Document document = unprocessedDocuments.getNthDocument(i);
				try {
					callback.call(context, document);
				} finally {
					recycle(log, document);
				}
				// printDebugInfo(document);
				processedCount++;
			} catch (Throwable e) {
				log.error("Unable to process document number [" + i + "]", e);
			}
		}
		return processedCount;
	}

Open in new window


Thanks
I have some difficulty in understanding your code (Java isn't one of my stronger points, I'm afraid, but I'm working on it). Assuming you are developing a Java Agent using the Domino Designer, there are some elements I don't know: AgentLog log (your own instead of the Log class?), the unprocessedSearch method (your invention?), recycle() which probably should be document.recycle(), but that's not the real issue here.

Here's a simple agent in Java that searches a database using a linear search method:
http://www-01.ibm.com/support/knowledgecenter/SSVRGU_9.0.1/com.ibm.designer.domino.main.doc/H_EXAMPLES_SEARCH_METHOD_JAVA.html

To access every document in a collection, you'd better use the getFirstDocument and getNextDocument methods. getNthDocument is slower, usually, but it should work all-right. An example as well:
http://www-01.ibm.com/support/knowledgecenter/SSVRGU_9.0.1/com.ibm.designer.domino.main.doc/H_EXAMPLES_GETNEXTDOCUMENT_METHOD_COLLECTION_JAVA.html

The Select statement in the Sent view is
SELECT DeliveredDate = "" & PostedDate != "" & !(@IsMember("S"; ExcludeFromView))
Avatar of fhios

ASKER

Hi,

AgentLog is my own class that uses org.apache.log4j.net.SocketAppender to send the logs to a centralised server.

recycle() is a defensive version of document.recycle() that handles exceptions more gracefully.

The getFirstDocument and getNextDocument methods, unfortunately they don't seem to be working from JAVA.

unprocessedSearch is a method in the Lotus Notes JAVA API that takes as a first parameter a "A Lotus Domino formula that defines the selection criteria."

Looking at the formula from the sent view, I would need to invert the criteria because I need to search for incoming e-mails rather than outgoing. Does the following make sense?

SELECT DeliveredDate != "" & PostedDate = "" & (@IsMember("S"; ExcludeFromView))

Open in new window


What does (@IsMember("S"; ExcludeFromView)) do?

Thanks
ASKER CERTIFIED SOLUTION
Avatar of Sjef Bosman
Sjef Bosman
Flag of France image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of fhios

ASKER

Thank you, I'll play around following your suggestions.
I'd love to hear from you when you cracked it. Thanks!