Как получить текстовое содержимое ответной почты из gmail и Outlook без оригинального сообщения и почты, предоставленного автоматическим текстом
подобно
ПРОГНОЗ:
Кому: [email protected]
Тема: тестовый ответ
Дата: Чт, 21 мая 2015 г. 05:34:42 +0000
GMAIL:
20 мая 2015 года в 17:52, Новый пользователь написал:
Также удалите подпись электронной почты пользователя.
Поэтому, основываясь на приведенном выше сценарии, я подготовил класс полезности, который помог решить проблему
<?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
* 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;
}
}