免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2930 | 回复: 8
打印 上一主题 下一主题

 问个MIME问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2003-05-12 20:36 |只看该作者 |倒序浏览
当收取邮件是HTML格式时应该如何得到它的bodyhandle->;path,老是出错,观察从@sohu.com发出的HTML信:
Content-Type: multipart/related
我想这就是不成功的原因吧,哪位知道解决之道?
在两个地方发贴子还没有解答,比较着急,听OYXin说这里会有人解答的,希望能指点一下问题所在,谢谢:)

论坛徽章:
0
2 [报告]
发表于 2003-05-12 23:32 |只看该作者

 问个MIME问题

给个分析,希望哪位帮看一下到底是卡在哪儿了,第一封没问题,第二封会出问题,是从@sohu.com发出的HTML信件
######################################
MIME:arser::Results=HASH(0x22f583c)
debug:    process_header
debug:    type = multipart, subtype = mixed
debug:    process_multipart...
debug:    parsing part 1...
debug:       process_header
debug:       type = text, subtype = plain
debug:       process_singlepart...
debug:       using temp file
debug:       t bound:  0 wallclock secs ( 0.00 usr +  0.00 sys =  0.00 CPU)
debug:       extract uuencode? 0
debug:       encoding?         base64
debug:       effective type?   text/plain
debug:       no filename recommended: synthesizing our own
debug:       planning to use 'msg-425633-1.txt'
debug:       outputting body to disk file: .\msg-425633-1.txt
debug:       t decode:  0 wallclock secs ( 0.00 usr +  0.00 sys =  0.00 CPU)
debug:    parsing part 2...
debug:       process_header
debug:       type = image, subtype = pjpeg
debug:       process_singlepart...
debug:       using temp file
debug:       t bound:  0 wallclock secs ( 0.28 usr +  0.00 sys =  0.28 CPU)
debug:       extract uuencode? 0
debug:       encoding?         base64
debug:       effective type?   image/pjpeg
debug:       is this evil? '1'
debug:       it's ok
debug:       planning to use '1'
debug:       outputting body to disk file: .\1
debug:       t decode:  0 wallclock secs ( 0.06 usr +  0.00 sys =  0.06 CPU)
debug:    process_epilogue
debug: t parse:  0 wallclock secs ( 0.66 usr +  0.00 sys =  0.66 CPU)

MIME:arser::Results=HASH(0x22e95e
debug:    process_header
debug:    type = multipart, subtype = related
debug:    process_multipart...
debug:    parsing part 1...
debug:       process_header
debug:       type = multipart, subtype = alternative
debug:       process_multipart...
debug:       parsing part 1...
debug:          process_header
debug:          type = text, subtype = plain
debug:          process_singlepart...
debug:          using temp file
debug:          t bound:  0 wallclock secs ( 0.00 usr +  0.00 sys =  0.00 CPU)
debug:          extract uuencode? 0
debug:          encoding?         8bit
debug:          effective type?   text/plain
debug:          no filename recommended: synthesizing our own
debug:          planning to use 'msg-425633-2.txt'
debug:          outputting body to disk file: .\msg-425633-2.txt
debug:          t decode:  0 wallclock secs ( 0.05 usr +  0.00 sys =  0.05 CPU)
debug:       parsing part 2...
debug:          process_header
debug:          type = text, subtype = html
debug:          process_singlepart...
debug:          using temp file
debug:          t bound:  0 wallclock secs ( 0.00 usr +  0.00 sys =  0.00 CPU)
debug:          extract uuencode? 0
debug:          encoding?         8bit
debug:          effective type?   text/html
debug:          no filename recommended: synthesizing our own
debug:          planning to use 'msg-425633-3.html'
debug:          outputting body to disk file: .\msg-425633-3.html
debug:          t decode:  0 wallclock secs ( 0.00 usr +  0.00 sys =  0.00 CPU)
debug:       process_epilogue
debug:    process_epilogue
debug: t parse:  1 wallclock secs ( 0.11 usr +  0.00 sys =  0.11 CPU)

论坛徽章:
1
荣誉会员
日期:2011-11-23 16:44:17
3 [报告]
发表于 2003-05-13 08:43 |只看该作者

 问个MIME问题

沒用過MIME::* module...
我查了一下MIME的common type,你說的應該是屬於
multipart/*--->;a message containing multiple parts
可以的話..把代碼貼一下..比較清楚..
給你一個MIME:arser的例子...
#!/usr/bin/perl
# file: simple_parse.pl

use strict;
use MIME:arser;

my $file=shift;
open F,$file or die "can't open $file: $!\n";

# create and configure parser
my $parser = MIME:arser->;new;
$parser->;output_dir("/tmp";
# parse the file
my $entity = $parser->;parse(\*F);
print "From          = " , $entity->;head->;get('From');
print "Subject      = ", $entity->;head->;get('Subject');
print "MIME type = ",$entity->;mime_type,"\n";
print "arts         = ",scalar $entity->;parts,"\n";
for my $part ( $entity->;parts){
   print "\t",$part->;mime_type,"\t",$part->;bodyhandle->;path,"\n";
}
$entity->;purge;
^^^代碼取至Networking Programming with Perl...

雖然我沒用過,不過看起來,你應該是要parsing某個文件....
你可以試著打開那個文件..比較一下...
看看到底有沒有Parse 到你想要的內容..

论坛徽章:
0
4 [报告]
发表于 2003-05-13 21:00 |只看该作者

 问个MIME问题

这么快就回复了,先谢谢了:)
程序和你差不多,能帮先试一下从@sohu.com发HTML信件给自己看看能不能调用bodyhandle(或我发信给你),我调用后得到空值,path就更不用call了,所以程序不成功,但可以用srtingify_body得到它的主体,一定要用@sohu.com发HTML信测试哦,别地方发来的信收取时bodyhandle还没有碰到问题,请帮试一下,一直没搞定:(
这是我的毕业设计,再没搞定就惨了:((
以下是个范例,主要是看能不能bodyhandle
#####################################
use Net:OP3;
use MIME:arser;

my $oPop = Net:OP3->;new('pop3.linuxforum.net') or die "Can't not open account.";
my $oParse = new MIME:arser;
$oPop->;login('pgg@linuxforum.net',"***********";
my $rhMsg = $oPop->;list();
foreach $sMsgId (keys %$rhMsg){
my $oEnt=$oParse->;parse_data($oPop->;get($sMsgId));
my $bodyhandle=$oEnt->;bodyhandle;
print "$bodyhandle\n";
}
$oPop->;quit;

论坛徽章:
1
荣誉会员
日期:2011-11-23 16:44:17
5 [报告]
发表于 2003-05-14 14:41 |只看该作者

 问个MIME问题

在不了解發生什麼事情之前..建議你先把pop3抓回來的
資料..存到檔案中..然後用我給你例子..去做分析...
一次做一件事情..會比較清楚發生了什麼事情.


for my $part ( $entity->;parts){
print "\t",$part->;mime_type,"\t",$part->;bodyhandle->;path,"\n";
}
你必需要將MIME的文件看成有好幾個部份...
因為MIME文件可能包含很多圖片與本文...
而你用
my $oEnt=$oParse->;parse_data($oPop->;get($sMsgId));
my $bodyhandle=$oEnt->;bodyhandle;
不對...
因為$oEnt他裡面有很多個bodyhandle..所以你必須用
for my $part ( $oEnt->;parts){
print "\t",$part->;mime_type,"\t",$part->;bodyhandle->;path,"\n";
}
這樣你每一個part的bodyhandle就可以得到了..

抱歉我最近工作有點多..要幫你debug..可能有點困難..
來這兒都是利用晚上或是寫程序休息時間...

论坛徽章:
0
6 [报告]
发表于 2003-05-15 22:32 |只看该作者

 问个MIME问题

看了模块,果然是multipart/related的问题,如果是multipart/*或message/*则bodyhandle返回undef,难怪一直都是得到undef,现在是无法调用bodyhandle了,不知还有没有别的方法可以得到相对应的临时文件名呢,因为我要得主体的内容。apile兄可有良药解我心头的痛,谢谢:)

论坛徽章:
1
荣誉会员
日期:2011-11-23 16:44:17
7 [报告]
发表于 2003-05-16 08:50 |只看该作者

 问个MIME问题

上CPAN找MIME的module..
研究一下吧..MIME:arser目前還是實驗性的CLASS..
所以你可能要用其他的方式取得數值...

论坛徽章:
0
8 [报告]
发表于 2003-05-16 14:03 |只看该作者

 问个MIME问题

呵呵,在新闻组贴了个贴子还没人答,不过自己倒是先找到答案,狂笑中。。。
费神了,apile兄:)
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP