Re: Email::Folder->messages returns only one element
- From: Michael Yang <Michael.Yxf@xxxxxxxxx>
- Date: 31 May 2007 00:22:10 -0700
On May 31, 3:11 pm, Michael Yang <Michael....@xxxxxxxxx> wrote:
On May 31, 2:33 pm, "Mumia W." <paduille.4061.mumia.w
+nos...@xxxxxxxxxxxxx> wrote:
On 05/30/2007 11:11 PM, Michael Yang wrote:
I'm working on parsing multiple messages out of one msf file(mbox
folder type).
I took the module of Email::Folder to construct with msf file, and
then get the list of all messages contained in the msf file.
But, the msf file is considered as a wholly one message, not multiple
messages (actually I have multiple messages within the msf file)
Here is my code snippet:
my $folder = Email::Folder->new($file); //$file is a valid mbox
folder type
foreach ($folder->messages){
print $_->header("Subject"), "\n";
print $_->as_string(), "\n";
//$imapserver->append($box, $_->as_string()); // i want to import
this message to my $imapserver, you can comment this one.
}
The result is:
The first print prints only the first message's subject.
The second print prints all the messages(all of the other messages) in
the msf file as a whole one.
The Email::Folder parses this file as one mail message.
Doesn't $folder->messages return a list of messages?
Is there any where I missed to set the preference of parsing rule?
Thanks.
Your code, with minor modifications, works for me. Hint: C++ comments
are not Perl comments ;-)
Is it because of the module version?
I tried Mail::Box::Manager to parse the same file, it works.
Because Mail::Box::Manager module has too many dependency modules to
attach, I want to try Email::Folder instead to parse the message data.
I need to wrap this harness as a package in the end.
This is obviously not your real code, and you typed it in by hand
without using cut-and-paste.
http://www.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
When I read the POD for Email::Folder, I see this helpful message:
messages
Returns a list containing all of the messages in the folder. Can only
be called once as it drains the iterator.
Maybe in your real code, you're doing a while or something rather than a
foreach.
The purpose of my script is quite simple. Parse the message data out
of the local msf file, and then import each messages into mail server
by Email::IMAPClient->append("INBOX", $msg);
This snippet only deals with parsing the message data out of the file.
There isn't anywhere Email::Folder module required anymore.
I typed this snippet to show the problems that Email::Folder->messages
doesn't function as it should do.
In my snippet, sorry for that I paste it again:
eval { require Email::Folder; };
die "The module Email::Folder is required for this script.\n" if $!;
my $file = "mail"; //$file is a valid mbox folder,with
"mail.msf"
my $folder = Email::Folder->new($file);
foreach ($folder->messages){
print $_->header("Subject"), "\n";
print $_->as_string(), "\n";
}
what I expected is that multiple messages contained in the "mail" file
will be outputed.
But only one is returned by this snippet.
It's RHEL AS4 distribution with Perl 5.8.5 installed on my pc.
I am wondering it...
Anyway, a code snippet is inadequate. You should create the smallest
program that demonstrates your problem and ask for help with that.
I wrote another script to demonstrate my problems:
1 #!/usr/bin/perl -w
2 # Author: Michael Yang
3 # Date: May/31/2007
4 # Purpose: To test the function of Email::Folder module.
5
6 use strict;
7 use warnings;
8
9 my @mail_list = @ARGV;
10
11 die "Usage: $0 <.msf file> \n" if not @mail_list;
12
13 eval { require Email::Folder; };
14 die "The module Email::Folder is required for this script.\n"
if $!;
15
16 foreach my $file (@mail_list){
17 if ($file =~ m/^(.*)\.msf$/i){
18 $file = $1;
19 print "$file MSF file detected.\n"
20 }
21 die "can't access import file $file" unless -r $file;
22
23 my $folder = Email::Folder->new($file);
24
25 my @msg_list = $folder->messages();
26 foreach(@msg_list){
27 print $_->header("Subject"), "\n";
28 # print $_->as_string(), "\n";
29 }
30 }
To run this script, one valid *.msf file is required to pass in, which
contains multiple messages.
In this script, it will print out each message's subject data.
The result on my pc is that there is only one subject is printed out.
Thanks all!!
.
- Follow-Ups:
- Re: Email::Folder->messages returns only one element
- From: Christian Winter
- Re: Email::Folder->messages returns only one element
- From: Mumia W.
- Re: Email::Folder->messages returns only one element
- References:
- Email::Folder->messages returns only one element
- From: Michael Yang
- Re: Email::Folder->messages returns only one element
- From: Mumia W.
- Re: Email::Folder->messages returns only one element
- From: Michael Yang
- Email::Folder->messages returns only one element
- Prev by Date: Re: Email::Folder->messages returns only one element
- Next by Date: Re: Using CPAN to install Mail::Box module
- Previous by thread: Re: Email::Folder->messages returns only one element
- Next by thread: Re: Email::Folder->messages returns only one element
- Index(es):