2012-08-31 164 views
0

我有一个脚本来检查电子邮件并将它们放入数据库中。当新的电子邮件编写和发送时,这工作正常。但是,如果我回复电子邮件,imap_fetchbody不起作用,并且它是空的。imap_fetchbody和剥离行

我在哪里错了?

/* get information specific to this email */ 
$overview = imap_fetch_overview($inbox,$email_number,0); 
$structure = imap_fetchstructure($inbox,$email_number); 
$message = imap_fetchbody($inbox,$email_number,0); 
$header = imap_headerinfo($inbox,$email_number); 

//print_r($structure); 

    //make sure emails are read or do nothing 
if($overview[0]->seen = 'read'){ 

//strip everything below line 
$param="## In replies all text above this line is added to the ticket ##"; 
$strip_func = strpos($message, $param); 
$message_new = substr($message,0,$strip_func); 


    /* output the email body */ 
    $output.= '<div class="body">'.$message_new.'<br><br></div>'; 

如果我输出$ message而不是$ message_new,那么在我开始剥离文本之前,一切都会显示出来。

回答

0

如果该行“在答复......”是不存在的消息在所有的,strpos将返回布尔false,当其强制转换为整数将为0

所以,当你问子从0到该位置,您要求的子字符串从0到0,$message_new是空的。

在尝试根据此字符串获取子字符串之前,请检查邮件中是否存在该行。

$param="## In replies all text above this line is added to the ticket ##"; 
$strip_func = strpos($message, $param); 
$message_new = ($strip_func === false) ? $message : substr($message,0,$strip_func); 
+0

该行在回复中。它没有被删除。 – ipengineer

+0

答案中的内容在'strpos'中不匹配。开始调试。 'var_dump $ message'和'$ strip_func'。 –

+0

没有,如果我从另一个电子邮箱回复它的作品。我做了你的改变,现在身体出现了。这只是混乱编码的文本。这必须是为什么strip_func没有工作,它不能读取“in reply”,因为它是编码的。我想我的问题是现在,我如何解码所有的文本。我需要在strip函数之前解码,尽管它看到它。 – ipengineer