mail : getHeaders function added
git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@5827 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
@@ -133,4 +133,94 @@ class mailTest extends PHPUnit_Framework_TestCase
|
|||||||
array ("name" => "",
|
array ("name" => "",
|
||||||
"mail" => "titi@titi.com")));
|
"mail" => "titi@titi.com")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Read all the headers and return them as JSON object
|
||||||
|
*/
|
||||||
|
public function testHeadersToJSON1 ()
|
||||||
|
{
|
||||||
|
$mail = new mail ();
|
||||||
|
$mail->readMail ( // {{{
|
||||||
|
"Return-Path: <dominique.fournier@grenoble.cnrs.fr>
|
||||||
|
Delivered-To: dominique@fournier38.fr
|
||||||
|
Received: from mail-postfix-mx.fournier38.fr ([192.168.1.103])
|
||||||
|
by mail-dovecot.fournier38.fr with LMTP
|
||||||
|
id z706BqQt7V15IAAAA28uxw
|
||||||
|
(envelope-from <dominique.fournier@grenoble.cnrs.fr>)
|
||||||
|
for <dominique@fournier38.fr>; Sun, 08 Dec 2019 18:06:44 +0100
|
||||||
|
Received: from mailgw-out1.grenoble.cnrs.fr (mailgw-out1.grenoble.cnrs.fr [147.173.1.68])
|
||||||
|
(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
|
||||||
|
(No client certificate requested)
|
||||||
|
by mail-postfix-mx.fournier38.fr (Postfix) with ESMTPS id 8A2DF820733
|
||||||
|
for <dominique@fournier38.fr>; Sun, 8 Dec 2019 18:06:43 +0100 (CET)
|
||||||
|
DMARC-Filter: OpenDMARC Filter v1.3.2 mail-postfix-mx.fournier38.fr 8A2DF820733
|
||||||
|
Delivered-To: dominique.fournier@grenoble.cnrs.fr
|
||||||
|
Received: from [192.168.1.154] (82-64-55-197.subs.proxad.net [82.64.55.197])
|
||||||
|
(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
|
||||||
|
(No client certificate requested)
|
||||||
|
by mailgw-out1.grenoble.cnrs.fr (Postfix) with ESMTPSA id 458EDBFCE4
|
||||||
|
for <dominique@fournier38.fr>; Sun, 8 Dec 2019 18:08:06 +0100 (CET)
|
||||||
|
From: Dominique Fournier <dominique.fournier@grenoble.cnrs.fr>
|
||||||
|
Subject: Analyse de texte
|
||||||
|
To: Dominique Fournier / Fournier38 <dominique@fournier38.fr>
|
||||||
|
Message-ID: <81d7982f-7fee-96b4-078f-a6365234356f@grenoble.cnrs.fr>
|
||||||
|
Date: Sun, 8 Dec 2019 18:08:06 +0100
|
||||||
|
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101
|
||||||
|
Thunderbird/68.2.2
|
||||||
|
MIME-Version: 1.0
|
||||||
|
Content-Type: text/plain; charset=utf-8; format=flowed
|
||||||
|
Content-Language: en-US
|
||||||
|
Content-Transfer-Encoding: 7bit
|
||||||
|
Authentication-Results: mail-postfix-mx.fournier38.fr;
|
||||||
|
dkim=none;
|
||||||
|
dmarc=none;
|
||||||
|
spf=pass (mail-postfix-mx.fournier38.fr: domain of dominique.fournier@grenoble.cnrs.fr designates 147.173.1.68 as permitted sender) smtp.mailfrom=dominique.fournier@grenoble.cnrs.fr
|
||||||
|
X-Spamd-Bar: --------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
https://openclassrooms.com/fr/courses/4470541-analysez-vos-donnees-textuelles/4854971-nettoyez-et-normalisez-les-donnees
|
||||||
|
|
||||||
|
http://www.nltk.org/nltk_data/
|
||||||
|
|
||||||
|
http://www.cs.cmu.edu/~ralf/langid.html
|
||||||
|
");
|
||||||
|
// }}}
|
||||||
|
$this->assertSame ($mail->getHeaders (), array (
|
||||||
|
["Return-Path" => "<dominique.fournier@grenoble.cnrs.fr>\n"],
|
||||||
|
["Delivered-To" => "dominique@fournier38.fr\n"],
|
||||||
|
["Received" => "from mail-postfix-mx.fournier38.fr ([192.168.1.103])
|
||||||
|
by mail-dovecot.fournier38.fr with LMTP
|
||||||
|
id z706BqQt7V15IAAAA28uxw
|
||||||
|
(envelope-from <dominique.fournier@grenoble.cnrs.fr>)
|
||||||
|
for <dominique@fournier38.fr>; Sun, 08 Dec 2019 18:06:44 +0100\n"],
|
||||||
|
["Received" => "from mailgw-out1.grenoble.cnrs.fr (mailgw-out1.grenoble.cnrs.fr [147.173.1.68])
|
||||||
|
(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
|
||||||
|
(No client certificate requested)
|
||||||
|
by mail-postfix-mx.fournier38.fr (Postfix) with ESMTPS id 8A2DF820733
|
||||||
|
for <dominique@fournier38.fr>; Sun, 8 Dec 2019 18:06:43 +0100 (CET)\n"],
|
||||||
|
["DMARC-Filter" => "OpenDMARC Filter v1.3.2 mail-postfix-mx.fournier38.fr 8A2DF820733\n"],
|
||||||
|
["Delivered-To" => "dominique.fournier@grenoble.cnrs.fr\n"],
|
||||||
|
["Received" => "from [192.168.1.154] (82-64-55-197.subs.proxad.net [82.64.55.197])
|
||||||
|
(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
|
||||||
|
(No client certificate requested)
|
||||||
|
by mailgw-out1.grenoble.cnrs.fr (Postfix) with ESMTPSA id 458EDBFCE4
|
||||||
|
for <dominique@fournier38.fr>; Sun, 8 Dec 2019 18:08:06 +0100 (CET)\n"],
|
||||||
|
["From" => "Dominique Fournier <dominique.fournier@grenoble.cnrs.fr>\n"],
|
||||||
|
["Subject" => "Analyse de texte\n"],
|
||||||
|
["To" => "Dominique Fournier / Fournier38 <dominique@fournier38.fr>\n"],
|
||||||
|
["Message-ID" => "<81d7982f-7fee-96b4-078f-a6365234356f@grenoble.cnrs.fr>\n"],
|
||||||
|
["Date" => "Sun, 8 Dec 2019 18:08:06 +0100\n"],
|
||||||
|
["User-Agent" => "Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101
|
||||||
|
Thunderbird/68.2.2\n"],
|
||||||
|
["MIME-Version" => "1.0\n"],
|
||||||
|
["Content-Type" => "text/plain; charset=utf-8; format=flowed\n"],
|
||||||
|
["Content-Language" => "en-US\n"],
|
||||||
|
["Content-Transfer-Encoding" => "7bit\n"],
|
||||||
|
["Authentication-Results" => "mail-postfix-mx.fournier38.fr;
|
||||||
|
dkim=none;
|
||||||
|
dmarc=none;
|
||||||
|
spf=pass (mail-postfix-mx.fournier38.fr: domain of dominique.fournier@grenoble.cnrs.fr designates 147.173.1.68 as permitted sender) smtp.mailfrom=dominique.fournier@grenoble.cnrs.fr\n"],
|
||||||
|
["X-Spamd-Bar" => "--------------------------------------------------------------------------------------------------\n"],
|
||||||
|
|
||||||
|
|
||||||
|
));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
36
mail.php
36
mail.php
@@ -1292,6 +1292,22 @@ class mail
|
|||||||
}
|
}
|
||||||
// }}}
|
// }}}
|
||||||
|
|
||||||
|
/** Get all the headers, in the order in EML. The format is
|
||||||
|
* [] => array ("header" => "value")
|
||||||
|
* @param array|null $headers The headers to examine
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getHeaders ($headers=null)
|
||||||
|
{
|
||||||
|
$sectionMainID = $this->sectionMainID ();
|
||||||
|
if ($sectionMainID === false ||
|
||||||
|
! key_exists ("_headersArray", $this->sections[$sectionMainID]))
|
||||||
|
$headers = array ();
|
||||||
|
else
|
||||||
|
$headers = $this->sections[$sectionMainID]["_headersArray"];
|
||||||
|
return $headers;
|
||||||
|
}
|
||||||
|
|
||||||
/** Get a generic header
|
/** Get a generic header
|
||||||
* If there is multiple headers with the same name, return the first
|
* If there is multiple headers with the same name, return the first
|
||||||
* @param string $header The header to get
|
* @param string $header The header to get
|
||||||
@@ -1301,15 +1317,7 @@ class mail
|
|||||||
public function getHeader ($header, $headers=null)
|
public function getHeader ($header, $headers=null)
|
||||||
// {{{
|
// {{{
|
||||||
{
|
{
|
||||||
if ($headers === null)
|
$headers = $this->getHeaders ($headers);
|
||||||
{
|
|
||||||
$sectionMainID = $this->sectionMainID ();
|
|
||||||
if ($sectionMainID === false ||
|
|
||||||
! key_exists ("_headersArray", $this->sections[$sectionMainID]))
|
|
||||||
$headers = array ();
|
|
||||||
else
|
|
||||||
$headers = $this->sections[$sectionMainID]["_headersArray"];
|
|
||||||
}
|
|
||||||
foreach ($headers as $key=>$val)
|
foreach ($headers as $key=>$val)
|
||||||
{
|
{
|
||||||
$head = key ($val);
|
$head = key ($val);
|
||||||
@@ -1330,15 +1338,7 @@ class mail
|
|||||||
public function getHeaderValue ($header, $headers=null)
|
public function getHeaderValue ($header, $headers=null)
|
||||||
// {{{
|
// {{{
|
||||||
{
|
{
|
||||||
if ($headers === null)
|
$headers = $this->getHeaders ($headers);
|
||||||
{
|
|
||||||
$sectionMainID = $this->sectionMainID ();
|
|
||||||
if ($sectionMainID === false ||
|
|
||||||
! key_exists ("_headersArray", $this->sections[$sectionMainID]))
|
|
||||||
$headers = array ();
|
|
||||||
else
|
|
||||||
$headers = $this->sections[$sectionMainID]["_headersArray"];
|
|
||||||
}
|
|
||||||
foreach ($headers as $key=>$val)
|
foreach ($headers as $key=>$val)
|
||||||
{
|
{
|
||||||
$head = key ($val);
|
$head = key ($val);
|
||||||
|
|||||||
Reference in New Issue
Block a user