我正在从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进行纠正将是理想选择,否则我将继续进行纠正,希望不会有更多类型的问题。
答案 0 :(得分:0)
这是带引号的可打印编码问题