[wp-trac] [WordPress Trac] #30266: wp_mail() can send emails with a blank 'From' address

WordPress Trac noreply at wordpress.org
Tue Feb 24 06:45:54 UTC 2015


#30266: wp_mail() can send emails with a blank 'From' address
---------------------------+---------------------------
 Reporter:  drtonyb        |       Owner:  valendesigns
     Type:  defect (bug)   |      Status:  assigned
 Priority:  normal         |   Milestone:  4.2
Component:  Mail           |     Version:  4.0
 Severity:  normal         |  Resolution:
 Keywords:  needs-testing  |     Focuses:
---------------------------+---------------------------
Changes (by valendesigns):

 * keywords:  has-patch needs-unit-tests => needs-testing


Comment:

 My latest patch [attachment:30266.1.diff] doesn't make the same
 assumptions as the first one. I added 4 unit tests and found that the real
 issue was in the `switch` statement. Basically, we have four bugs.

 * First, the `$from_email` was being set to an empty string and was
 remedied by changing `else` to `else if ( '' !== trim( $content ) )` so it
 doesn't get set.

 * Second, we have an issue where one is not like the other. If you pass in
 an email as the from header like `From: wordpress at example.com` you get
 back `From: WordPress <wordpress at example.com>`, though if you pass in the
 email like `From: <wordpress at example.com>` you get back
 `"<wordpress at example.com" <wordpress at example.com>`, which I fixed by
 checking if the less than symbol is not in the first position before
 setting the `$from_name`.

 * Third, there was an issue where `$charset` was coming back empty because
 of `list( $type, $charset )` setting the variable. I changed that to
 `list( $type, $charset_content )` and updated the associated code so
 `$charset` is not set to an empty value.

 * Last, `$content_type` was also being set to an empty value so I replaced
 the `else` with `else if ( '' !== trim( $content ) )` like the first
 issue.

 I did not touch the `isset` checks as they are now being correctly handled
 in the `switch` statement. Please test and let me know if there's
 something that still needs work.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/30266#comment:8>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list