# Dim rtitem As Variant
# Set rtitem = doc.GetFirstItem( "Body" )
# Forall o In rtitem.EmbeddedObjects
# If o.Type = EMBED_ATTACHMENT Then
# Call o.ExtractFile( "c:\newfiles\" & o.Source )
# Call o.Remove
# Call doc.Save( True, True )
# End If
# End Forall
#End Sub
####
foreach my $embeddedDoc ( $DocumentBody->{EmbeddedObjects} ) {
my $edocType =$embeddedDoc->{Type};
# Above returns a blank
if ( $edocType eq 'EMBED_ATTACHMENT' ) {
print "Embedded Attachment!\n";
} elseif ( $edocType eq 'RICH_TEXT' ) {
print "Some sort of Rich Document\n";
} else {
print "Unknown Attachment!\n";
}
}
####
use strict;
use Win32::OLE;
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('', 'help4.nsf');
# muser.nsf -- local mail file
my $Database = $Notes->GetDatabase('', 'muser.nsf');
my $AllDocuments = $Database->AllDocuments;
my $Count = $AllDocuments->Count;
print "There are $Count documents in the database.\n";
for (my $Index = 1 ; $Index <= $Count ; ++$Index) {
my $Document = $AllDocuments->GetNthDocument($Index);
# Get subget of document
printf "$Index. %s\n", $Document->GetFirstItem('Subject')->{Text};
# He called the Text property of Subject, how did he know?-^^^^^^
if ( $Document->HasEmbedded ) {
my $DocumentBody = $Document->GetFirstItem('Body');
#my $bodytext = $Document->GetFirstItem('Body')->{Text};
#print $bodytext."\n";
# Works occasionally, but not always
foreach my $embeddedDoc ( $DocumentBody->{EmbeddedObjects} ) {
# I asked for an array of embedded objects
# but what I get back is an array reference
my $edocType =$embeddedDoc->{Type};
# This yields nothing
if ( $edocType eq 'EMBED_ATTACHMENT' ) {
print "Embedded Attachment!\n";
} elseif ( $edocType eq 'RICH_TEXT' ) {
print "Some sort of Rich Document\n";
} else {
print "Unknown Attachment!\n";
}
# I get back Win32::OLE=hash(0xnnnn)
#my $embed_type = ${$embeddedDoc}{Type}
#print $embed_type."\n"
}
}
# limiter
last unless $Index < 100; # Get only 5 entries
}
# Sample notes code that I'm trying to copy
#
#Sub Click(Source As Button)
# Dim session As New NotesSession
# Dim db As NotesDatabase
# Dim collection As NotesDocumentCollection
# Dim doc As NotesDocument
# Set db = session.CurrentDatabase
# Set collection = db.AllDocuments
# For i = 1 To collection.Count
# Set doc = collection.GetNthDocument( i )
# If doc.HasEmbedded Then
# Call detachFiles( doc )
# End If
# Next
#End Sub
#Sub detachFiles( doc As NotesDocument )
# Dim rtitem As Variant
# Set rtitem = doc.GetFirstItem( "Body" )
# Forall o In rtitem.EmbeddedObjects
# If o.Type = EMBED_ATTACHMENT Then
# Call o.ExtractFile( "c:\newfiles\" & o.Source )
# Call o.Remove
# Call doc.Save( True, True )
# End If
# End Forall
#End Sub
# You can get documentation on Notes objects from
# http://www.lotus.com/products/lotusscript.nsf