我正在从gmail帐户检索XML ADF格式的电子邮件。我正在使用imap_body检索电子邮件。查看电子邮件帐户,我可以看到电子邮件是以两种方式接收的。第一个是这样开始的:
<?xml version="1.0" encoding="UTF-8"?>
<?adf version="1.0"?>
<adf>
<prospect status="new">
<id sequence="1" source=...第二种类型的开头类似于:
<?xml version="1.0" encoding="UTF-8"?><?adf version="1.0"?><adf><prospect status="new"><id sequence="1" source=...对于第二种类型,imap_body返回值固定为75个字符。第75个字符作为等号(=)插入。此外,字符3D被添加到正常的等号后面,生成:
<?xml version=3D"1.0" encoding=3D"UTF-8"?><?adf version=3D"1.0"?><adf><pros=
pect status=3D"new"><id sequence=3D"1" source=3D...我可以使用第75个字符的循环来更正字符串,但如果第74个字符是等号,则在未插入的等号之前插入等号和空格。
例如。
<name part=3D"full" type=
=3D"business"这让人大失所望。我也想补偿这一点,但如果可能的话,我想在这里尝试修复实际的imap_body请求。
//Retrieve emails, make corrections if needed, convert to array
$inbox = imap_open($cred['host'],$cred['user'],$cred['pass']);
if(!$inbox){
$output = ['success' => false,'error' => "Unable to connect to host. ".imap_last_error()];
}else{
/* Get email list */
$emails = imap_num_msg($inbox);
/* Cycle through each email based on count */
if($emails > 0){
for($key = 1;$key <= $emails;$key++) {
/* Retrieve the email body */
$pull = imap_body($inbox,$key);
$init = str_replace(["\r","\n"],'',stripslashes($pull));
//Clears the breaks having the = character and clears the added characters 3D
if(substr($init,14,2) == "3D" && substr($init,75,1) == "="){
$max = strlen($init);
$cnt = 75;//First = character occurance
while($cnt < $max){
$init = substr($init,0,$cnt).substr($init,$cnt + 1);//remove =
$cnt += 75;//Set for next iteration
}
$init = str_replace("3D",'',$init);//Remove additional
}
$data = simplexml_load_string($init);
$xml[$key] = json_decode(json_encode($data),true);
}
}
}第二种类型的电子邮件需要进行更正,但由于电子邮件中的双等/空格问题,它将被关闭。由于这些问题,simplexml_load_string失败。同样,从imap_body更正将是理想的,否则我将继续更正,希望不会有更多类型的问题。
发布于 2019-05-10 02:58:11
这是一个引用的可打印编码问题
https://stackoverflow.com/questions/56065625
复制相似问题