Deleting mail from a user's folder

Question…

How do I “get a hold” of a folder via script? I have an agent that is going out to a user’s mailfile, doing a search of the documents in the db, and purging mail that is 90 days old or older. The problem I’m having is that only mail that is in the user’s Inbox, Trash Bin, and Sent view that meet the criteria are to be purged. I’ve tried using the search method in the NotesDatabase class, which allows me to use a formula for my search key, but it doesn’t help with my issue. Anyone have any suggestions?

Thanks

Subject: Deleting mail from a user’s folder

The inbox, trash bin and sent view is to be considered as any standard view when writing a script. LotusScript doesn’t treat the folders differently from views, so in order to get a hold of a folder - use the GetView method of the NotesDatabase class:

Dim sess as New NotesSession

Dim db as NotesDatabase

Dim inbx as NotesView

Set db = sess.CurrentDatabase

Set inbx = db.GetView(“($Inbox)”)

Now, the object inbx contains all mail in the inbox-folder. Then simply do a FTsearch to select the documents from the folder that You want to discard/delete.

hth

Subject: RE: Deleting mail from a user’s folder

Thanks for your response Kenneth. I guess I should have worded my question a bit differently. I am aware of using getview to obtain the views/folders I need, but my difficulty is in getting all documents in that view that meet my criteria. If I use, for example, GetAllEntriesByKey, how do I specify “docs 90 days old or older” as my key? What I don’t want to do is go doc by doc. I want to get a collection and then use a removeall method to purge them.

Thanks again.

Subject: RE: Deleting mail from a user’s folder

Oh, I see… Then, I’ll think that You have to do like:

Dim sess As New NotesSession

Dim db As NotesDatabase

Dim vw As NotesView

Dim coll As NotesDocumentCollection

Dim cutOff As NotesDateTime

dim numDocs As Long

Set db = sess.CurrentDatabase

Set cutOff = New NotesDateTime(Now)

Call cutOff.AdjustDay(-90)

Set vw = db.GetView(“($Inbox)”)

numDocs = vw.FTSearch(|@Created <=| & cutOff.LSLocalTime,0)

If numDocs > 0 Then

Call vw.AllEntries.RemoveAll(True)

End If

I haven’t tested it, but You get the idea.

hth

Subject: RE: Deleting mail from a user’s folder

Thanks again Kenneth. I’ve been testing it out this am, but so far, I keep getting the following error: “Notes error: can not understand query”, when it attempts to interpret the numDocs formula. Could it be just a syntax issue?

Paul

Subject: RE: Deleting mail from a user’s folder

Yes - it’s most likely just a matter of the syntax in the search formula. I’ll bet that it doesn’t understand @Formulas in the query or it could be that the @Created is returning a date but the cutoff-date is in string (LSLocalTime). Try convert the @Created to a string:

@Text(@Created;“D0T1”)

hth

Subject: RE: Deleting mail from a user’s folder

Ok, so this is what I did:

numDocs = vw.FTSearch(“@Text(@Created)” <= cutOff.LSLocalTime,0. I don’t get an error message, and based on what I’m running it on, it returns “5”. I’m confused by this number because there are a lot of documents that are 90 days old or older, so I’m not sure why its returning 5. Also, in the if statement, you say in numdocs > 0 then Call vw.AllEntries.RemoveAll(True). Is this going to remove the “5” entries, or will it remove all entries in the view? I appreciate all the help Ken.

Thanks

Subject: RE: Deleting mail from a user’s folder

That is confusing…

According to the help documentation it SOUNDS like it is only going to delete the number of documents indicated in the return value, but I have never tested the fact. You’d better test this in a copy of a real database before putting it in a live system.

The number of documents is most likely correct, but it could be the fact that LSLocalTime isn’t the parameter to use. Do You use several timezones? Then it could be a timezoneproblem, and You could test using ZoneTime instead.

Tricky thing it is to handle date/time values…