Issues

ZF-11371: Exception in case of optional Headers

Issue Type: Bug Created: 2011-05-13T14:39:39.000+0000 Last Updated: 2012-08-16T19:18:14.000+0000 Status: Postponed Fix version(s): Reporter: Nawar Nory (nawar) Assignee: Dolf Schimmel (Freeaqingme) (freak) Tags: - Zend_Mail

  • validating
  • zf-crteam-review

Related issues: Attachments:

Description

Part.php throws an exception in case of the optional header of "Subject" is not seen in the list of headers of a mail file in the Maildir type of mailboxes.

The functions of getHeader() or headerExists() should handle this gracefully by ignoring it all these optional headers. Subject header is an optional field as described in RFC 2822.

<pre class="highlight">
PHP Fatal error:  Uncaught exception 'Zend_Mail_Exception' with message 'no Header with Name subject or subject found' in /usr/share/php/Zend/Mail/Part.php:347
Stack trace:
#0 /usr/share/php/Zend/Mail/Part.php(418): Zend_Mail_Part->getHeader('subject', 'string')
#1 /var/www/email/mail_parser.php(247): Zend_Mail_Part->__get('subject')
#2 {main}
  thrown in /usr/share/php/Zend/Mail/Part.php on line 347

Comments

Posted by Matthew Weier O'Phinney (matthew) on 2011-05-18T18:43:19.000+0000

Part of the reason that Subject is considered a required field is due to how mail() works in PHP; subject is a required parameter of that method. As such, if you're using the Sendmail Zend_Mail transport, we have to require it.

One option would be to have it default to an empty string, however.

Posted by Adam Lundrigan (adamlundrigan) on 2012-02-24T12:19:11.000+0000

Can this be considered just a documentation issue? (ie: informing developers that subject is a required field despite RFC2822) Or should the default-value behavior be implemented?

Posted by Gonzalo Sainz-Trapaga (gomox) on 2012-05-30T16:30:02.000+0000

This is not a problem when sending mail but when receiving it. Mails will come in without a subject and accessing $this->subject raises an Exception.

Posted by J B (dubnut) on 2012-06-28T22:08:48.000+0000

Bump for this... It's not a matter of sending, but of receiving: if you're trying to do any work with reading contents of a mail folder and somewhere in there is an email without a subject, the exception will cause things to crash out...

Posted by stephen (farzher) on 2012-08-16T19:06:18.000+0000

I was reading emails in a loop, this crashed my application. This should not throw an exception.

Posted by stephen (farzher) on 2012-08-16T19:18:14.000+0000

For anyone who needs a quick fix, you can do this:

try { $data['subject'] = $message->subject; } catch(Exception $e) { $data['subject'] = ''; }

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts