Wiggins d Anconia wrote:
Howdy group.

In a recent post someone mentioned this url:
http://www.perl.com/pub/a/2004/06/10/email.html

Thanks for you input with the question about some code at that url Wiggins :)


I think I'm a bit closer to getting it but here is what I'm getting:

my $obj = Mail::Internet->new([EMAIL PROTECTED]);

#I've not said anything about MIME yet. Mail::Internet is reasonably #handy for simple tasks, but it doesn't handle MIME at all. Thankfully, #MIME::Entity is a MIME-aware subclass of Mail::Internet; it allows you #to read individual parts of a MIME message:
my $num_parts = $obj->parts;
for (0..$num_parts) {
my $part = $obj->parts($_);
# ...
}


the first call to parts() gives me:
 Can't locate auto/Mail/Internet/parts.al in @INC ...

Since parts() is in MIME::Entity I imagine is why that is happening, which is fine except, I'm not sure how I can use the MIME::Entity subclass to use parts() with the message I have in the Mail::Internet Object...

Anyone know the (likely obviouse ;p) thing I'm missing?

Thanks

Lee.M - JupiterHost.Net

PS - in case you're wondering perl -e 'use MIME::Entity;use Mail::Internet;' executes without error (IE they are installed)



The key to understanding that snippet is the line:


"Thankfully, MIME::Entity is a MIME-aware subclass of Mail::Internet;"

and specifically that little word in the middle, 'subclass'. MIME::Entity objects are subclasses of Mail::Internet objects, so my
understanding would be that anywhere in the article above the parts
accessing lines, you should switch Mail::Internet to MIME::Entity and it
should just work. Therefore, for more information about the 'parts'
method you should check the docs for MIME::Entity as that is what
provides the method. (Though I certainly agree that the author should
have made his transition a bit more clear.)


My question is about the Mail::Internet Mime::Entity object and example mentioned at that url:


my $num_parts = $obj->parts; for (0..$num_parts) { my $part = $obj->parts($_); ... }


1) $obj is the Mail::Internet object created above that example correct?



Yes, sort of. I believe to make it work you are going to have
instantiate MIME::Entity on the original string rather than
Mail::Internet. For future reference if you are ever wondering what
type of object a variable is holding just print the reference,


print "$obj";

In most cases will show you, in the other cases, when $obj can be
stringified, use the 'ref' built-in,

print ref($obj);

Will tell you what kind of object you are accessing, which will then
tell you what docs to look at first, making sure to check the docs for
anything that that object subclasses/inherits.


2) I can't seem to find out how to use $part to examine the part, and the docs don't seem to helpful, so how do you use the object that is

$part?

Say to get the content, encoding, ctype, etc...

Somethgin like this perhaps:
 my $desc = $part->description();
 my $ctype = $part->ctype();

IE I'd like to ultimately get the attachment information seperated...



To get this information, you go through the same steps as any other
header, aka request a head object from the part, and then access into it
to get the various header's values.  The mime/content-type is provided
free of charge using either the 'mime_type' or 'effective_type' methods.


but anystart on what Ii can do with $part would be greatly appreciated.



Check the docs of MIME::Entity for more,

http://danconia.org




-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to