Using Perl to scan a Lotus Notes database quickly
Posted by dlandgren on 2009-04-22
I had a couple of hundred messages lying around in the depths of my work e-mail account. They were old Majordomo subscribe/unsubscribe alerts for a mailing list I managed (until we switched over to Mailman). I had kept them around because one of these days I figured I’d load the information into a database to track the evolution of the subscriber base.
I haven’t managed to get around to doing that yet, but I did want to get rid of the messages. All I needed was the subject line of the mail (which contained all the necessary info) and the date the message was received. The idea of doing it manually would have been a nightmare. I searched around a bit for a way of automating the task, and discovered that it could be done through OLE.
So I wrote a quick Perl program to do it. It went like this:
use strict;
use warnings;
use Win32::OLE;
my $Notes = Win32::OLE->new('Notes.NotesSession')
or die "Cannot start Lotus Notes Session object.\n";
my $db = $Notes->GetDatabase("MyServer/MyDomain", "mail/mymail.nsf")
or die "Could not open database.\n";
my $all = $db->AllDocuments;
foreach my $n (1 .. $all->Count) {
my $doc = $all->GetNthDocument($n);
my $item = $doc->GetFirstItem('Subject');
if (!$item) {
warn "doc $n has no subject\n";
next;
}
my $subject = $item->{Text};
next unless $subject =~ /^(?:UN)?SUBSCRIBE my-mailing-list/;
print $doc->GetFirstItem('DeliveredDate')->{Text}, " $subject\n";
}
and presto, the deed was done. This saved me I don’t know how many hours of mind-crushingly boring and RSI-inducing cutting and pasting. It’s so trivial it’s not even worth bundling up, so this is probably the best place for other people to stumble across it in a search (hi!).
I’m not sure if Strawberry Perl is bundled with Win32::OLE, but this works straight out of the box with ActivePerl.
Éric said
Thanks for this Perl-Lotus Notes example.
I would be really interested about Lotus Notes OLE methods and properties documentation. Thanks in advance if you’ve something to point me out!
dlandgren said
Hi Éric,
if you have the Lotus Domino Designer help online it’s all detailed there. It contains lots of LotusScript examples, that, in my experience, translate exactly as you would expect to Perl.
Searching for NotesDocument, NotesDocumentCollection, NotesEmbeddedObject, NotesItem on the web may lead to some useful resources.
If you need to grovel around in a document and you don’t know what it contains…
my @item = $doc->Items()… will return a list of document attributes that you can look at.