Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Notes::OLE - Lotus Domino via Win32::OLE

by diotalevi (Canon)
on Oct 31, 2003 at 21:50 UTC ( #303724=sourcecode: print w/replies, xml ) Need Help??
Category: Miscellaneous
Author/Contact Info
Description: This module makes writing perl for Lotus Domino easy by precreating your session object and providing some utility functions for enumerating available servers and traversing document collections.
package Notes::OLE;
use strict;
use warnings;
use base 'Exporter';
use Win32::OLE;
use vars qw($S $DT @EXPORT @EXPORT_OK $VERSION %SEEN);

BEGIN {
    $VERSION = 0.01;
    $S = Win32::OLE->new('Notes.NotesSession')
    or die "Couldn't instantiate Notes.NotesSession";
    $DT = $S->CreateDateTime( '12/30/1899' );
    @EXPORT = qw($S $DT dc_all Dumper);
    @EXPORT_OK = qw(all_servers server_event_log server_databases
            move_dc server_log);
    *server_log = *server_event_log;
}

sub move_dc {
    my $dc = shift;
    my $tgt = shift;
    my $seen = shift;
    
    return unless $dc and $dc->Count;
    return
        dc_all( $dc, sub {
            my $doc = shift;
        return move_doc( $doc, $tgt, $seen );
        } );
}

sub move_doc { 
    my $doc = shift;
    my $tgt = shift;
    my $seen = shift || {};
    my $unid = $doc->UniversalID;
    return unless defined $unid;
    return if exists $seen->{$unid};
    $seen->{$unid} = undef;
    
    my $new = $doc->CopyToDatabase( $tgt );
    my $r = $doc->{Responses};
    if ( $r and $r->Count ) {
        for ( move_dc( $doc->{'Responses'}, $tgt, $seen ) ) {
            $_->MakeResponse( $new );
        $_->Save( 1, 0 );
        }
    }
    $doc->remove( 1 );
    return $new;
}

sub dc_all {
    my $dc = shift;
    my $cb = shift;

    my $doc = $dc->GetFirstDocument;
    my $next_doc;
    my @return;
    
    if ( wantarray ) {
    while ( $doc ) {
        $next_doc = $dc->GetNextDocument( $doc );
        push @return, $cb->( $doc );
        $doc = $next_doc;
    }
    return @return;
    } else {
    while ( $doc ) {
        $next_doc = $dc->GetNextDocument( $doc );
        $cb->( $doc );
        $doc = $next_doc;
    }
    return;
    }
    
    # NOT REACHED
}

sub all_servers {
  my $nab;
  
  for ( grep $_->Server, @{$S->AddressBooks} ) {
    $nab = $S->GetDatabase( $_->Server, $_->Filepath )
      and last;
  }
  
  if ( not( $nab and $nab->IsOpen ) ) {
    die "No server NAB could be opened - check your notes.ini";
  }
  
  my $servers = $nab->GetView('($Servers)');
  if ( not $servers ) {
    die "notes://@{[$nab->Server]}/@{[$nab->Filepath]} is missing a (\
+$Servers) view";
  }
  
  return dc_all( $servers,
         sub {
             return @{shift()->ServerName};
         } );
}

sub server_databases {
    my $server = shift;
    my $dbdir = $S->GetDbDirectory( $server );

    my @dbs;
    for ( my $db = $dbdir->GetFirstDatabase( 1246 );
      $db;
      $db = $dbdir->GetNextDatabase ) {
    push @dbs, { server => $server,
             title  => $db->Title,
             filepath => $db->Filepath,
             template => $db->TemplateName,
             inherits => $db->DesignTemplateName };
    }
    return @dbs;
}

sub server_event_log {
    my $server = shift;
    my $log = $S->GetDatabase( $server, 'log' )
    or do {
        warn "Couldn't open notes://$server/log";
        return;
    };
    
    my $events = $log->Search( q[FORM = "Events"], $DT, 0 );
    if ( not $events ) {
    warn "Couldn't search notes://$server/log";
    return;
    }

    my @events =
    dc_all( $events, sub {
        my $doc = shift;
            return ( @{ $doc->EventList },
             @{ $doc->EventLog },
                     @{ $doc->Events } );
    } );

    return @events;
}

1;

__END__

=head1 NAME

Notes::OLE - Lotus Domino via Win32::OLE

=head1 SYNOPSIS

 use Notes::OLE qw(all_servers server_event_log);
 $\ = "\n";
 print
     for
     map {
         my $l = $_;
         map "$l->{'name'}: $_",
             @{$l->{'log'}};
     }
     grep @{$_->{'log'}},
     map +{ 'name' => $S->CreateName( $_ )->Abbreviated,
            'log'  => [ server_event_log( $_ ) ],
     },
     all_servers();

=head1 DESCRIPTION

This module makes writing perl for Lotus Domino easy by precreating yo
+ur
session object and providing some utility functions for enumerating av
+ailable
servers and traversing document collections.

=head1 OBJECTS

=over 4

=item $S

This is the global session object. It is exported by default.

=item $DT

This is a NotesDateTime object set to 12/31/1899. This is intended for
+ use
in NotesDatabase.Search( ... ) calls as a "default" limit.

=back

=head1 FUNCTIONS

=over 4

=item dc_all( $DocumentCollection, sub { ... } )

This function traverses NotesView and NotesDocumentCollection document
+s by
calling the .GetFirstDocument / GetNextDocument methods in a loop. The
second argument is a function callback. It is called with each documen
+t as
the sole parameter.

In list context the return results of the callback function is accumul
+ated
and returned by dc_all().

=item all_servers()

This function takes no arguments and it queries the server for a list 
+of other
servers.

=item server_log( "Foobar/Domain" )

This function takes a server name as a single argument. It returns the
+ contents
of the server's log.nsf database. The R5 and R6 log design was account
+ed for
and this function returns both seamlessly.

=item server_databases( "Foobar/Domain" )

This returns an array of hashes, one hash per database on the server. 
+Each
hash has some of the databases' data copied into it.

  server
  title
  filepath
  template
  inherits

=item move_dc

=item move_doc

=back

=head1 AUTHOR

Joshua b. Jore E<lt>jjore@cpan.orgE<gt>

=cut
Replies are listed 'Best First'.
Re: Notes::OLE - Lotus Domino via Win32::OLE
by Roger (Parson) on Nov 01, 2003 at 12:17 UTC
    Hi diotalevi, can OLE method handle private/public key certification and account login on the Domino Server? I would find this module most useful if I could use it to create a simple online Email reader/parser (probably an Outlook filter??) for my Lotus Notes emails. I find the default Lotus Notes client very clumsy to use.

      This is just an interface to Lotus' published COM methods. You'll need to consult the documentation for that though I suspect you aren't going to get anything to authentication without the C API which explicitly addresses it.
Re: Notes::OLE - Lotus Domino via Win32::OLE
by Anonymous Monk on Nov 01, 2003 at 02:45 UTC
    How about Win32::OLE::Notes or Win32::OLE::LotusDomino?

      Oh I don't much care. This isn't something I'm going to public to CPAN. I only created some pod so perlmonks.org users would have some documentation. The other thing to think of is reimplementing this as wrappers to the C and C++ APIs which can do some other things I wish was accessible via the COM interface. I'd probably want to call it Lotus::Domino:: or something.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: sourcecode [id://303724]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2022-01-25 08:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (65 votes). Check out past polls.

    Notices?