Solved

Querying received e-mails from an agent

Posted on 2014-12-04
7
202 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
  • 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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

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 500 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
mapAB Challlenge 35 84
Access left join query 5 31
ms sql stored procedure 22 77
tvirtualstringtree freeze when load too manny images 10 24
IBM Notes offer Encryption feature using which the user can secure its NSF emails or entire database easily. In this section we will discuss about the process to Encrypt Incoming and Outgoing Mails in depth.
This article will show, step by step, how to integrate R code into a R Sweave document
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
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…

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now