Home > Domino News > How do I use LotusScript to filter certain email?
Domino News:
EMAIL THIS

How do I use LotusScript to filter certain email?

By Peter Bochner
24 Oct 2005 | SearchDomino.com

Lotus Notes and Domino tips, tutorials and how-to articles
Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google

Cregg Hardwick is Collaboration Solutions Technical Lead for CenterPoint Energy in Houston. He has an MBA, a PCLP and an MCAD and focuses on collaboration and business process support applications, and has been a Notes developer since 1998. He has graciously agreed to answer some of the many questions that come into SearchDomino.com's mailbox regarding LotusScript.

Question: How do I use an agent and/or LotusScript to filter certain e-mails based on words in the Summary Line or in the body of the text?

Cregg Hardwick: Depending on what you are trying to do, you might be able to use the built-in mail rules. But there are two problems: Your organization might not allow use of rules, and rules might not do what you want. For example, rules cannot forward mail to another address. The most flexible approach, as always, is to write a LotusScript agent to do your bidding. Here's how.

First, decide what type of agent to run. For example, in R6 you can choose to run a "before mail arrives" or "after new mail has arrived" agent. For details on the types of agents available, search Lotus.com for "troubleshooting agents in Notes."

Agent details aside, and not knowing exactly what you are trying to do, you most likely need to use the NotesDatabase.UnprocessedSearch method. Search and UnprocessedSearch are fabulously useful methods that let you select documents exactly the way you build a view: by using a selection formula. The formula uses exactly the same syntax as the selection formula in a view. (In fact, it's an excellent idea to use a view to develop the selection formula first.)

The only difference between these two methods is that one selects a subset of the database.unprocessedDocuments collection and the other selects a subset of all documents in the database. Both take the same parameters and return a NotesDocumentCollection. You should search unprocessed documents when you have the option to do so, since doing a search is essentially the same amount of work as building a view index the first time—so anything you can do to cull the herd will pay big dividends.

Here is an example that you might use in an agent to, say, find all messages containing the word "Viagra" in the subject line.

Dim session as new notessession
Dim db as notesdatabase
Set db=session.currentDatabase
Dim spam as notesDocumentCollection
Set spam=db.unprocessedSearch
({@Contains(@upperCase(Subject);
"VIAGRA")},nothing,0)

Dim spamDoc as notesdocument
Set spamDoc=spam.getFirstDocument
Do while not spamDoc is nothing
 …call routine to report or handle spam…
 Set spamDoc=spam.getNextDoc(spamDoc)
Loop
Call spam.removeAll(true)

The three parameters are the selection formula, the cutoff date (maximum age of documents to select) and the maximum number of documents to select. Note that I have wrapped the selection formula in curly brackets, which in LotusScript can be used to delimit a string constant and save you from the tedious task of escaping quotes used in your formula (i.e., {"1"} if the same as "\"1"" but much clearer).

If you want to use the cutoff date, you need to create a data object with a line of code such as dim cutoff as new notesDateTime("01/01/1970"). If you don't use the cutoff date (and you probably won't), passing "nothing" makes the query run faster. Passing zero (0) selects all matching documents.

Tags: AgentLotusScriptLotusScriptVIEW ALL TAGS

Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google



RELATED CONTENT
Agent
Run or restart Notes/Domino agents via text messages
Approve Lotus Notes documents using a BlackBerry mobile device
LotusScript agent indexes Lotus Notes/Domino databases
Open documents in Lotus Notes from the Web without a UNID
Fix and update Lotus Notes documents with limited access
Verify scheduled agent status with Domino Extensible Language (DXL)
How to export data from a Lotus Notes database to a CSV file
Enable or disable scheduled agents without opening the Lotus Notes database design
Creating custom views in Lotus Notes databases
Editing fields in a Lotus Notes view with Ajax

LotusScript
LotusScript finds the first occurrence of a string from the right
Clear Recent Contacts view and prevent repopulation in Lotus Notes 8.x
Search Microsoft Active Directory with LotusScript
Three steps to trap and handle save conflicts with LotusScript
Troubleshoot agents by displaying LotusScript variables online
LotusScript sorts lists alphabetically
LotusScript code rebuilds corrupted busytime.nsf file
Soft-code item names to facilitate LotusScript management
LotusScript agent automates selective mail file replication
LotusScript filters and attaches files to a Notes form

LotusScript
LotusScript finds the first occurrence of a string from the right
Clear Recent Contacts view and prevent repopulation in Lotus Notes 8.x
Search Microsoft Active Directory with LotusScript
Three steps to trap and handle save conflicts with LotusScript
Troubleshoot agents by displaying LotusScript variables online
LotusScript sorts lists alphabetically
Run or restart Notes/Domino agents via text messages
LotusScript code rebuilds corrupted busytime.nsf file
Soft-code item names to facilitate LotusScript management
LotusScript agent automates selective mail file replication

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary



Lotus Notes Server Solutions - Quickr, Domino Server, Websphere
HomeTopicsITKnowledge ExchangeTipsAsk the ExpertsMultimediaWhite PapersDomino IT Downloads
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 1999 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts