Bloodelf has asked for the wisdom of the Perl Monks concerning the following question:

Wise ones......
I have a script which uses Win32::OLE to open a specific email and grab the entire body of the text. To get the text, I use:
my $item = $Folder->Items("Mail_being_got"); $text = $item->Body;
When $text is then printed to a text file, the data looks exactly the same as when I cut & paste from the mail, into a text file. However when I further process the text file, strange formatting occurs (which doesn't occur with the cut & paste file.)
The problem is caused by rogue \r's next to \n's, but for some reason, I can't substitute them before writing the original file - I have to re-open the file and do extra formatting....
Anyone met this before??

Replies are listed 'Best First'.
Re: Win32::OLE and outlook
by Bloodelf (Beadle) on Jun 29, 2001 at 02:59 UTC
    SUSSED IT......(sort of!)
    For some strange reason I can't pattern match for \r's with this string. However I've split it to an array, and printed that to the file to get around it.
    Thanks anyway!
      Congratulations on solving it yourself! I'm glad to see you continued to work through your problem after posting it here.
      I noticed you worked on Outlook & OLE (quite a long time ago) - I'm currently working on that too and I'd like to get your insights on the whole thing :
           I want to find out whether there's an active email open and how to retrieve the text from that email. Note that since it's a new mail, it is highly unlikely that it's been saved.

      I did the same with Word and Excel easily enough (even though I must admit I did have a bit a trouble there as well) but it seems to me Outlook is not as easy.
           Please let me know if you come across anything that could be helpful.

      Thanks, David.

      Heureux qui, comme Ulysse, a fait un beau voyage
      Ou comme celui-là qui conquit la Toison,
      Et puis est retourné plein d'usage et raison,
      Vivre entre ses parents le reste de son âge!

      J. du Bellay, poëte angevin

        Any time you have an Outlook item open in a separate window, it's in an Inspector.

        What I would do in this case is get the list of all the Inspectors, filter out the ones that aren't open on a Mail item, and then, if necessary, apply further filtering on the contents of the item. For example:
        use Win32::OLE; use Win32::OLE::Const '.*Outlook'; # load the relevant constants my $ol = new Win32::OLE 'Outlook.Application'; my $inspectors = $ol->Inspectors; my @inspectors = Win32::OLE::Enum->new( $inspectors )->All; my @mail_items = grep { $_->Class == olMail } map { $_->CurrentItem } # get the MailItem object @inspectors;
        You could, perhaps, try to rely on the fact that for a brand spanking new mail message, the Inspector has a caption (that is, its window has a title) of Untitled - Message (Plain Text)
        my @mail_items = grep { $_->Class == olMail } map { $_->CurrentItem } # get the MailItem object grep { $_->Caption eq 'Untitled - Message (Plain Text)' } @inspectors;
        Once you've found the element in @mail_items which is the one you want, you can extract its body text with the Body method, of course.

        jdporter
        The 6th Rule of Perl Club is -- There is no Rule #6.