in reply to Win32::OLE Outlook help requested
Thank you both for your help.#!C:/perl/bin/perl use strict; use Win32::OLE qw(in with); use Win32::OLE::Const 'Microsoft Outlook'; $|=1; $Win32::OLE::Warn = 3; my $Outlook = Win32::OLE->GetActiveObject('Outlook.Application') or Wi +n32::OLE->new('Outlook. +Application', 'Quit'); my $ol = Win32::OLE::Const->Load($Outlook); my $namespace = $Outlook->GetNameSpace("MAPI") or die "Can't open MAPI + namespace: $!"; my $Folder1 = $namespace->GetDefaultFolder(olFolderInbox); my $Folder2 = $Folder1->Folders("SPAM"); my $temp_file_name = 'D:\\exchange\\temp_spam.msg'; my @return_paths; foreach my $item (in $Folder2->{Items}){ unlink $temp_file_name if -f $temp_file_name; $item->saveAs( $temp_file_name, olMSG ); if ( -f $temp_file_name ) { my $previous_return_path = ''; open( SPAMFILE, $temp_file_name ) || die "Couldn't ope +n the $temp_file_name"; binmode( SPAMFILE ); while ( <SPAMFILE> ) { $_ =~ m/Return-Path: <(.*)>/; push ( @return_paths, $1 ) if $1 && $1 ne '' & +& $1 ne $previous_return_path; $previous_return_path = $1; } close( SPAMFILE ); } } my @deduped_return_paths = remove_duplicates( @return_paths ); my $deduped_return_paths = "deduped_return_paths.txt"; open( DEDUPEDSPAMFILE, ">>$deduped_return_paths" ) || die "Couldn't op +en the $deduped_return_paths"; foreach ( @deduped_return_paths ) { print DEDUPEDSPAMFILE "$_\n"; } close( DEDUPEDSPAMFILE ); exit 0; ####################### sub remove_duplicates { ####################### my @dirty_array = @_; my @clean_array = (); my %hash = (); foreach my $item ( @dirty_array ) { push @clean_array, $item unless $hash{$item}++; } return @clean_array; }
bassplayer
|
|---|