php MIME 解码,解码mime邮件的代码-PHP教程,邮件处理

function decode_mime_string ($string) {

$pos = strpos($string, =?);

if (!is_int($pos)) {

return $string;

}

$preceding = substr($string, 0, $pos); // save any preceding text

$search = substr($string, $pos+2, 75); /* the mime header spec says this is the longest a single encoded word can be */

$d1 = strpos($search, ?);

if (!is_int($d1)) {

return $string;

}

$charset = substr($string, $pos+2, $d1);

$search = substr($search, $d1+1);

$d2 = strpos($search, ?);

if (!is_int($d2)) {

return $string;

}

$encoding = substr($search, 0, $d2);

$search = substr($search, $d2+1);

$end = strpos($search, ?=);

if (!is_int($end)) {

return $string;

}

$encoded_text = substr($search, 0, $end);

$rest = substr($string, (strlen($preceding . $charset . $encoding . $encoded_text)+6));

switch ($encoding) {

case q:

case q:

$encoded_text = str_replace(_, %20, $encoded_text);

$encoded_text = str_replace(=, %, $encoded_text);

$decoded = urldecode($encoded_text);

if (strtolower($charset) == windows-1251) {

$decoded = convert_cyr_string($decoded, w, k);

}

break;

case b:

case b:

$decoded = urldecode(base64_decode($encoded_text));

if (strtolower($charset) == windows-1251) {

$decoded = convert_cyr_string($decoded, w, k);

}

break;

default:

$decoded = =? . $charset . ? . $encoding . ? . $encoded_text . ?=;

break;

}

return $preceding . $decoded . decode_mime_string($rest);

} // decode_mime_string()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值