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! }

In reply to Extract Lotus Notes Mail to HTML by Corion

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.