Chinaunix首页 | 论坛 | 博客
  • 博客访问: 5272248
  • 博文数量: 1144
  • 博客积分: 11974
  • 博客等级: 上将
  • 技术积分: 12312
  • 用 户 组: 普通用户
  • 注册时间: 2005-04-13 20:06
文章存档

2017年(2)

2016年(14)

2015年(10)

2014年(28)

2013年(23)

2012年(29)

2011年(53)

2010年(86)

2009年(83)

2008年(43)

2007年(153)

2006年(575)

2005年(45)

分类: PERL

2014-12-11 17:48:00

#!/usr/bin/perl -w
use MIME::Parser; use MIME::Entity;
my $parser = new MIME::Parser; $parser->output_to_core(1);
my $test = MIME::Entity->build(Type     => "multipart/alternative",From     => 'me@myhost.com',To       => 'you@yourhost.com',Subject  => "Test Test Test");
$test->attach(Type => "text/plain",  Data => "This is the plain text stuff");
$test->attach(Type => "text/html",  Data => "

This is the HTML stuff

");
print $test->as_string();$test = tweak_plain_text($test); print "\n\nAnd After...\n\n\n";print $test->as_string();
sub tweak_plain_text {
    my $entity = shift;
    my @parts  = $entity->parts;
    if(@parts){
        my $i;
        foreach $i (0 .. $#parts) {
            $parts[$i]= tweak_plain_text($parts[$i]);    
        }
        $entity->sync_headers('Length'      =>  'COMPUTE','Nonstandard' =>  'ERASE');
    }else{
        if($entity->head->mime_type eq 'text/plain'){
            my $body = $entity->bodyhandle;
            my $content = $body->as_string;
               $content .= "\nThis has been tweaked!!!!\n";
               my $io = $body->open('w');$io->print( $content );$io->close;
            $entity->sync_headers('Length'      =>  'COMPUTE',
                                  'Nonstandard' =>  'ERASE');
        }
        return $entity;
    } my $content = $entity->as_string; return $entity; }

阅读(947) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~