如何从gmail和Outlook获取已回复邮件的文本内容,而不提供原始邮件和邮件提供的自动文本
像
OUTLOOK:
来自:test@gmail.com
致:tests@outlook.com
主题:测试回复
日期:星期四,2015年5月21日05:34:42 +0000
GMAIL:
2015年5月20日17:52,New User写道:
同时删除用户电子邮件签名。
答案 0 :(得分:1)
基于上面的场景,我准备了一个实用程序类来帮助解决问题
<?php
/**
* Thic Utility class is used to piping the mail content.
*
*
*/
class EmailPiping {
public $gmailRegex = '#\R+^on.*wrote:(.*)#msi';
public $outlookRegex = '#\R*From: (.*)#msi';
/**
* This method is used to filter only replied text from the gmail text
* content.
*
*
* @param string $content
* @return string return piped reply text only
*/
public function pipeGMailReplyText($content) {
return nl2br(preg_replace($this->gmailRegex, "", $content));
}
/**
* This method is used to filter only replied text from the outlook mail
* text content.
*
*
* @param string $content
* @return string return piped reply text only
*/
public function pipeOutlookReplyText($content) {
return nl2br(preg_replace($this->outlookRegex, "", $content));
}
/**
* This the generic method which is used when user don't know from which
* mail service provider the email was arrived means he just pass the
* content it will detect based on preg match and apply matched email's
* method call.
*
*
* @param string $content
* @return string return piped reply text only
*/
public function pipeReplyText($content) {
$fp = fopen($_SERVER["DOCUMENT_ROOT"] . "/logfile/EmailPiping.txt", "w");
if (preg_match($this->gmailRegex, $content)) {
$result = $this->pipeGMailReplyText($content);
} else if (preg_match($this->outlookRegex, $content)) {
$result = $this->pipeOutlookReplyText($content);
} else {
$result = nl2br($content);
}
fputs($fp, $result);
return $result;
}
}