#014257: Problem accessing multiple headers with same headername

Description:

I use the ezComponent 'Mail' to save mails into a database including headers. However, in case of multiple headers with the same headername, only the last entry is accessible (through method generateHeaders). This is very unfortunate, since in case of the 'Received'-headers I cannot determine which servers are passed until the mail was delivered (for each passed SMTP server a 'Received' header is created).

I solved this by changing the method 'parseHeader' of class 'part_parse.php'. I added the following code right under linenumber 179.

$counter = null;
while(isset($headers[$matches[0][1].$counter]))
{

if(empty($counter))
{
$counter = 1;
}
else
{
$counter++;
}
}

$headers[$matches[0][1].$counter] = str_replace( "\t", " ", trim( $matches[0][2] ) );
$this->lastParsedHeader = $matches[0][1].$counter;

An example of the result of 'echo $mail->generateHeaders()' for only Received-headers:

Received: from relay.n01.nxs.nl (217.115.192.39) by EXCHANGEMULTI.exchange.nxs.nl
(217.115.197.41) with Microsoft SMTP Server id 8.1.278.0; Mon, 12 Jan 2009
11:15:54 +0100
Received1: from n01.nxs.nl (n01.nxs.nl [217.115.192.42]) by relay.n01.nxs.nl (Postfix)
with ESMTP id 618ED1098F8 for ; Mon, 12 Jan 2009
11:15:45 +0100 (CET)
Received2: (qmail 24749 invoked by uid 1009); 12 Jan 2009 11:15:44 +0100
Received3: (qmail 24744 invoked by uid 1011); 12 Jan 2009 11:15:44 +0100
Received4: from 217.115.197.68 by n01 (envelope-from , uid
1009) with qmail-scanner-1.25-st-qms (clamdscan: 0.92/5572. spamassassin:
3.0.2. perlscan: 1.25-st-qms. Clear:RC:0(217.115.197.68):SA:0(-2.6/5.0):.
Processed in 0.169345 secs); 12 Jan 2009 10:15:44 -0000
Received5: from mailscanner12.cluster.nxs.nl (217.115.197.68) by n01.nxs.nl with
AES256-SHA encrypted SMTP; 12 Jan 2009 11:15:44 +0100
Received6: from bay0-omc1-s38.bay0.hotmail.com ([65.54.246.110]) by
mailscanner12.cluster.nxs.nl with esmtp (Exim 4.69) (envelope-from
) id 1LMJpY-0000Jo-OJ for testingaccount@nxs.nl; Mon,
12 Jan 2009 11:15:44 +0100
Received7: from BAY132-W19 ([65.55.137.54]) by bay0-omc1-s38.bay0.hotmail.com with
Microsoft SMTPSVC(6.0.3790.3959); Mon, 12 Jan 2009 02:15:28 -0800

The method 'generateHeaders' should actually eliminate the counter from the headernames. A more fancy solution would be using an array to store the Received headers (and any other header), instead of creating a new array-key. But I think it's up to the ezComponent-team to find the best way of solving this issue.


Environment:

Operating System: Debian GNU/Linux 4.0
PHP Version: PHP 5.2.0-8+etch10 (cli) (built: Jan 18 2008 18:52:58)
Database and version: MySQL 5.0.51
Browser (and version): FireFox 3.0.5


Steps to Reproduce:

When I fetch and parse an email with ezComponents, I'm able to access the headers with method 'generateHeaders' of class 'ezcMail'.


- Attachments

No attachments for this issue.


- Comments

The Steps to Reproduce is not quite understandable:

Fetch and parse an email with ezComponents. The call the headers with method 'generateHeaders' of class 'ezcMail'. Always only one entry of the 'Received'-header is displayed (the last one).

#259755 by Enforcer x on January 12th, 2009 [Permanent Link]

In addition to my custom change in the file 'part_parse.php' here's a custom method for generateHeaders() to remove the numbers in the headername (in case of multiple headers with same headername)

class nxsMail extends ezcMail
{

public function generateHeaders()
{
$headers = explode("\n", parent::generateHeaders());

foreach($headers as $key => $header)
{
$matches = array();
preg_match_all('/^([\w-_]*)([0-9]+):\s?(.*)/', $header, $matches, PREG_SET_ORDER);

if(!empty($matches))
{
$headers[$key] = $matches[0][1].': '.$matches[0][3];
}
}

return implode("\n", $headers);
}
}

The follow code should be added right after the $mailParser object is created.

$mailParser->options->mailClass = 'nxsMail'; // extends ezcMail

#259767 by Enforcer x on January 12th, 2009 [Permanent Link]

Implemented in SVN rev. 10631 (trunk).

#262124 by Alexandru Stanoi on June 30th, 2009 [Permanent Link]

Support is needed for multiple headers when generating and forwarding/replying to email.

#262751 by Alexandru Stanoi on August 25th, 2009 [Permanent Link]

- History
Properties
Type Enhancement
Priority Medium
Components Components
Components » Mail
Affects 1.6 - Mail 1.6
Fix Versions 2009.2 sprint 1 - eZ components 2009.2 sprint 1
2009.2 sprint 3 - eZ components 2009.2 sprint 3
2009.2alpha1 - eZ components 2009.2alpha1
Reporter Enforcer x
Responsible Alexandru Stanoi
Status 0 Assigned
Resolution UNRESOLVED
Created January 12th, 2009
Updated September 1st, 2009
Resolved -
 
Navigation [Permanent Link]
Previous Issue
Back to Issues List
Next Issue: #015537
  Graph shows to small and truncated rotated axis labels