wirespeed

the hypothetical maximum data transmission rate of a telecommunications medium

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.

Advertisements

8 Responses to “Using Perl to scan a Lotus Notes database quickly”

  1. É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.

  2. Anonymous said

    Awesome info! How is the performance?

    Is there a way to use Perl to talk to the Notes DB on a server running Linux?

    For example, to have a Domino Server script call a Perl program in order to import/populate note items from a CSV file when running on Linux platform?

    Thank you

    • dlandgren said

      While this code runs on Windows, it’s platform-agnostic in terms of what platform the server is running on. It’s only speaking to your local client, who in term may be speaking to who knows what.

      Also, the performance isn’t blindingly fast. I suspect that the connection between Perl and the local Lotus client is being set up and torn down for each call. But it’s bearable, and if you’re loading stuff on a server it doesn’t really matter if it takes 10 seconds or 2 minutes.

  3. Charlie Zeaiter said

    How do you run Perl code? Is it anything like javascript that is within a HTML document?

  4. Sam said

    very nice…
    Strawberry perl does indeed come with win32::ole bundled.

    How do you handle logon username/password?

  5. Anonymous said

    When I use the following code ..I am getting an empty hash back. Can someone please help

    my $Notes = Win32::OLE->new(‘Notes.NotesSession’)
    or die “Cannot start Lotus Notes Session object.$!\n”;

    • dlandgren said

      Man I have no idea! I haven’t used Notes in years and have no way of investigating.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: