Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Querying received e-mails from an agent

Posted on 2014-12-04
7
Medium Priority
?
230 Views
Last Modified: 2014-12-04
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
0
Comment
Question by:fhios
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 40480837
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.
0
 

Author Comment

by:fhios
ID: 40480942
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
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 40481298
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))
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:fhios
ID: 40481775
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
0
 
LVL 46

Accepted Solution

by:
Sjef Bosman earned 2000 total points
ID: 40481824
Now why on earth did I take the Sent view... Goodness, what was I thinking? Never mind, humble apologies.

There are 2 ways to get received mails, but the approach is different, and so might be the number of mails found. If you want really all mails received, there is this query (source: Richard Schwarz):

SELECT ( @IsNotMember("A"; ExcludeFromView) & IsMailStationery != 1 & Form != "Group" & Form != "Person" ) & !( DeliveredDate = "" & PostedDate != "" & !(@IsMember("S"; ExcludeFromView)) )

If you can do with the messages that are in the Inbox at the moment of the search (the Inbox is a folder, mails can be moved out of this folder to other folders), you don't need to do a search: you can just open the Inbox view and walk through it (using getFirst and getNext calls).

The IsMember "S" tests if the mail is in the Sent folder.

Strange that getFirstDocument and getNextDocument don't work, it's the first time I hear of this.

And a warning. Do not rely too much on "unprocessed documents": once processed they can revert to unprocessed easily, e.g. when you change the agent code and save it. Or when someone switches the agent off and back on (when scheduled). It might be better to use a profile document somewhere, where you save the current cutoff date and time. You need another agent (can be in Formula language) if you want to change that cutoff date manually.
0
 

Author Comment

by:fhios
ID: 40481999
Thank you, I'll play around following your suggestions.
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 40482069
I'd love to hear from you when you cracked it. Thanks!
0

Featured Post

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Progress

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question