I never use Windows, so cannot help you with the installation. However, I know that the tests produce many errors and warnings which can be ignored: the Windows users of MailBox seem unable to help me with real fixes for the tests.
I have only previously used Perl on a Linux box, and apart from my ignorance of Perl, there have really been no problems. Using it on Windows has been SO different, lots of problems, but I wanted to also use it on Win to improve my Perl skills, plus I save on bandwidth. There are many ad-hoc things I would have previously done in Clipper, but I can see how much more powerful, for tasks of this nature, Perl is.
In regards to getting it all going on Win, fortunately it is all sorted out now. I removed everything, re-installed ActiveState Perl 5.8.0.806, and then tried the sample code that Roger kindly supplied. There were so many error messages (not from Rogers code), that I added the CGI::Carp module to log all the messages out to a file. That was very handy. Then as I found out the cause (looking in various .PM files), I first attempted to install the missing modules by using PPM. However with only two standard repositories and the trouble I had with referencing either local or remote 'repositories', I decided the only (best) option for the missing modules was to download the entire ...tar.gz file in each case, read the 'install/redame' then do the actual install. All of them worked fine, so the underlying problem in using the code supplied was not the code itself, but module dependency. The modules I had to install manually (makefile, ,etc,etc) were:
IO
IO-stringy
Mail-Box
MailTools
TimeDate
then the Perl script worked. There is only one minor problem, where it is not jumping into a 'foreach' loop, but I _think_ that is because I need to do a bit more research on the 'type' of mailbox being opened. :)
For your implementation, I advice one of these two approached: use Mail::Message->build() (look for the details of build in this module by selecting the "methods sorted alphabetically" in the right column).
Thanks for that, I did have a look. In the current task/probem, I'm wanting to read multilple email boxes and check that I have distribution lists up to date. However, I will certainly come back to the "build" because another task is to fix the problems I'm having with using Net::SMTP, so possibly I could look at using Mail::Message instead.
The other approach may be much simpler: first reconstruct your data into a MIME compliant message, and then call Mail::Message->read($m)
That could be a good solution for this problem, because the mailboxes are not what I would call 'standard', if standard means anything of a *nix flavour. I notice when I go to add a new mailbox under Pegasus mail, there is an option to create it in either:
Pegasus Mail v2.X
Unix Mailbox format
unfortunately, the default is the first one, so I think the only remaining problem with using Mail::Box on a Win box is for me to get into a hexviewer and see what is there that is so different to a *nix mailbox. It may be better to just open each mailbox as an ascii file, and then re-create it, for temporary purposes, as a Unix format. The other two subs in Rogers code work perfectly ("load_mail_list" and "load_mail_folders"), but I have a feeling the only reason the 'foreach' loop isn't being executed in sub "parse_mail_folder" is only because the actual mailbox (Pegasus format) is not "normal". There is all the usuall email headers and many of the folders/mailboxes have multi-part messages in them, but the first record has a lot of extra chars in it. :)
More help available at the mailbox mailinglist
Thanks, I will do a little bit more reading on the Mail::Box information in regards to opening mailboxes, and then will ask for help (I did add a "or die" after the open, but it's okay ??)
By the way: best way to parse e-mail addresses from a header line is like this:
my $msg = Mail::Message->read($data); my @addr = $msg->get('To')->addresses;
The addresses are Mail::Address objects, which are relatively smart. Parsing addresses in reality is a very complicated task.
I will try that method out, the code I had been using
my $mgr = Mail::Box::Manager->new(); my $folder = $mgr->open($folder_file) or die "Cannot open Folder","\n" +; my @email_addr; foreach my $message ($folder->messages) { print $message->get('Subject') || '<no subject>', "\n"; print "into foreach loop","\n"; # etc,etc
.. never gets to print the "into foreach loop", but I guess it is the mailbox 'type'. :)
Thanks for all your help,
Peter
In reply to Re: Re: Re: Parsing email files, what are the best modules ?
by peterr
in thread Parsing email files, what are the best modules ?
by peterr
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |