use strict;
use Win32::OLE qw(in);
use HTML::Template;
{
package Wrapper::Notes::Template;
use strict;
use File::Spec;
sub new {
my ($class,$document, $attachmentdir) = @_;
my $self = { document => $document, attachments => $attachmentdir
+};
bless $self, $class;
$self;
};
sub document { $_[0]->{document} };
sub param {
my ($self,@args) = @_;
if (scalar @args) {
my $result;
if ($_[1] eq 'Attachments') {
my $result = [];
my $body = $self->document->GetFirstItem('Body');
my @attachments = grep { warn join ":",$_->{Name}, $_->{Type},
+$_->{Text}; $_->{Type} == 4 } (@{$self->document->Items()});
mkdir $self->{attachments};
for my $attname (@attachments) {
my $url = File::Spec->catfile($self->{attachments},$attname)
+;
$url = File::Spec->rel2abs($url);
#warn "Extracting $attname to $url";
my $f = $self->document->getAttachment($attname);
if ($f) {
$f->extractFile($url);
push @$result, { name => $attname, url => $url };
};
};
return $result;
} elsif ($_[1] eq 'EmbeddedObjects') {
my $result = [];
my $body = $self->document->GetFirstItem('Body');
my $attachments = $body->EmbeddedObjects;
if ($attachments) {
mkdir $self->{attachments};
for my $att (Win32::OLE::in $attachments) {
warn $att->{Type};
my $url = File::Spec->catfile($self->{attachments},$att-
+>{Name});
$url = File::Spec->rel2abs($url);
$att->extractFile($url);
push @$result, { name => $att->{Name}, url => $url };
};
};
return $result;
} else {
$result = $self->document->{$_[1]};
};
if (ref $result) {
return [ map { "value" => $_ }, @$result ];
} else {
$result;
};
} else {
return (map { $_->Name } (Win32::OLE::in ($self->document->Items
+()))), "Attachments", "EmbeddedObjects";
};
};
};
my ($server,$database) = ('server','mail/corion.nsf');
my $Notes = Win32::OLE->new('Notes.NotesSession')
or die "Cannot start Lotus Notes Session object.\n";
my ($Version) = ($Notes->{NotesVersion} =~ /\s*(.*\S)\s*$/);
print "The current user is $Notes->{UserName}.\n";
print "Running Notes \"$Version\" on \"$Notes->{Platform}\".\n";
my $Database = $Notes->GetDatabase($server, $database);
my $AllDocuments = $Database->AllDocuments;
my $Count = $AllDocuments->Count;
print "There are $Count documents in the database.\n";
my $Index = 4419;
while (++$Index <= $Count) {
my $Document = $AllDocuments->GetNthDocument($Index);
my $wrapper = Wrapper::Notes::Template->new($Document,sprintf "ema
+il/mail.%05g",$Index);
my $template = HTML::Template->new(
filename => 'lotus-email.tmpl',
die_on_bad_params => 0,
loop_context_vars => 1,
associate => [ $wrapper ],
case_sensitive => 1,
);
my $outfile = sprintf "email/mail.%05g.html", $Index;
open MAIL, ">", $outfile or die "Couldn't create '$outfile' : $!\n
+";
$template->output( print_to => *MAIL );
close MAIL;
last unless $Index <= 4420; # magic number!
}
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.