Well, I could not find any way to extract the message headers, so the solution ended up being a variation on davis' idea about saving to a text file. Unfortunately, olTXT format does not contain the message header either, but the olMSG format does. This format is binary, but the message header is pretty much in tact, so I used the following to get the job done:
#!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; }
Thank you both for your help.

Update: Changed $|++ to $|=1.

bassplayer


In reply to Re: Win32::OLE Outlook help requested by bassplayer
in thread Win32::OLE Outlook help requested by bassplayer

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.