Skip to:
Content

Opened 5 months ago

Closed 5 months ago

#7509 closed defect (bug) (fixed)

BP_PHPMailer needs to set the `Date` header

Reported by: r-a-y Owned by: DJPaul
Milestone: 2.9 Priority: normal
Severity: normal Version: 2.5.0
Component: Emails Keywords: has-patch
Cc:

Description

I'm using a long-running script that includes sending email with BuddyPress native emails.

What I'm seeing is the Date field is only initialized once during the first send. Subsequent sendouts uses the original date.

The problem is because BuddyPress uses a static version of PHPMailer:
https://buddypress.trac.wordpress.org/browser/tags/2.8.2/src/bp-core/classes/class-bp-phpmailer.php?marks=28,39,47#L27

And PHPMailer doesn't set the Date field again if one already exists:
https://github.com/WordPress/WordPress/blob/4.7-branch/wp-includes/class-phpmailer.php#L2028

So subsequent mailouts will be sent out with the wrong date, making new emails hard to view in an email client.

My use-case might be a little specific, but I think it will help if we always set the Date header so other scripts will not run into the same problem as me.

Attachments (1)

7509.01.patch (425 bytes) - added by r-a-y 5 months ago.

Download all attachments as: .zip

Change History (3)

@r-a-y
5 months ago

#1 @boonebgorges
5 months ago

  • Milestone changed from Awaiting Review to 2.9

Maybe edge case, but it seems like a flaw in WP's mail date handling nonetheless (one that never really comes up, because even batches of emails are generally expected to be sent out immediately). I'd say go for it.

#2 @r-a-y
5 months ago

  • Resolution set to fixed
  • Status changed from new to closed

In 11536:

Emails: Set the 'Date' header for BP_PHPMailer.

Since the BP_PHPMailer class uses a static instance of PHPMailer:
https://buddypress.trac.wordpress.org/browser/tags/2.8.2/src/bp-core/classes/class-bp-phpmailer.php?marks=28,39,47#L27

PHPMailer would only set the Date field for the email on the initial send:
https://github.com/WordPress/WordPress/blob/4.7-branch/wp-includes/class-phpmailer.php#L2028

In cases where a long-running script is utilizing BP_PHPMailer,
subsequent emails would be sent out with the wrong Date field, making
these emails hard to find in an email client.

This commit rectifies this by always setting the Date field for our
version of PHPMailer.

Fixes #7509.

Note: See TracTickets for help on using tickets.