On Nov 27, 2007 7:20 PM, Tom Phoenix <[EMAIL PROTECTED]> wrote: > Well, the first part of what you'd like would seem to imply that > somebody else should write your program for you. But maybe you don't > mean that, you just want code that shows how to use the module? Any > good module should include examples (in the documentation, or > elsewhere) to show how it should be used in working code. Often these > examples are simple to adapt for many typical tasks, perhaps even > yours. > > So, on to the second part. If you're ready to see where you went > wrong, post your code. Someone here will surely help you to bring it > closer to what you need. > Ok, thank you for your quick response. The closest I got was by using code based on th "mimedump" example here:
http://www.iaeste.or.at/doc/libmime-perl/examples/ sub convert_mime_to_8bit { my ($log_fh, $loglevel, $entity, $nextpart) = @_; my @parts; my $IO; my $tempstring; my $returnstring; if (!($nextpart) && ($entity->head->original_text =~ /boundary=\"(.*)\"$/m)) { $nextpart = $1; }; $returnstring = "--$nextpart\n".$entity->head->original_text; $returnstring =~ s/^Content-Transfer-Encoding: quoted-printable/Content-Transfer-Encoding: 8bit/m; $returnstring .= "\n"; @parts = $entity->parts; if (@parts) { foreach my $i (0 .. $#parts) { log_it (2, $log_fh, "|convert_mime_to_8bit(): part $i: $parts[$i] - $nextpart\n"); $returnstring .= convert_mime_to_8bit($log_fh, $loglevel, $parts[$i], $nextpart); }; } else { my ($type, $subtype) = split('/', $entity->head->mime_type); my $body = $entity->bodyhandle; if ($type =~ /^(text|message)$/) { if ($IO = $body->open("r")) { log_it (2, $log_fh, "|convert_mime_to_8bit(): converting $type part\n"); $returnstring .= $_ while (defined($_ = $IO->getline)); $returnstring .= "\n"; $IO->close; }; } else { if ($IO = $body->open("r")) { log_it (2, $log_fh, "|convert_mime_to_8bit(): base64-encoding $type part\n"); $tempstring .= $_ while (defined($_ = $IO->getline)); $IO->close; $returnstring .= encode_base64($tempstring); }; }; }; return $returnstring; } I am calling this code like this: my $parser = new MIME::Parser; $entity = $parser->parse_data($lines); $convertedstring = convert_mime_to_8bit($log_fh, $loglevel, $entity, ""); where $lines is a reference to an array (of lines containing the original mail). While the code itself does convert parts of the mail to 8bit, here are two problems with it: - for some reason, for every attachment in the email, it creates files on the local filesystem. I don't want to have to clean these up manually. - more importantly, the email that I am puzzling back together, is not a "valid" email: another application (in php) is reading it, and is simply complaining that the email format is wrong. So basically, the subroutine is screwing up spaces or MIME metadata somewhere. At this point I am thinking: there's got to be better ways to do this, without my code having to puzzle back together the email etc. So I'm digging around, reading up on all the MIME modules Perl has. There is Email::MIME::Modifier which talks about this method: encoding_set However, I am unable to find any example code. As you can see, the Email::MIME and Email::MIME::Modifier don't have that much example code, especially for a non-MIME expert. Best regards, Filip -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/