Ticket #3836 (closed defect: fixed)

Opened 2 years ago

Last modified 2 years ago

class-pop3's get() method doesn't handle newlines correctly when reading a mail

Reported by: nreid Assigned to: anonymous
Priority: normal Milestone: 2.2
Component: General Version: 2.1
Severity: normal Keywords: has-patch
Cc:

Description

I'm using wordpress 2.1

When posting to a blog using the e-mail feature, I was noticing that long subjects were being truncated. I searched into wp-mail.php and it appeared that the subject line that is processed was being 'truncated' in the class-pop3.php. In the get method, around line 396 in class-pop3.php, the fgets method simply reads from the 'fp' until newlines are reached, and puts those lines into the returned MsgArray?. However, when debugging the lines read by fgets, I was seeing that my long subject lines were being split into multiple lines, and since the line processor in wp-mail only looks at one line at a time, it was missing the 'extra' lines. My solution was to only add another line to the MsgArray? if the beginning of that line is a non-whitespace character. According to the spec, it appears that lines in the header of the message will always either start with a known header, such as 'Reply-to:', or 'Subject:', etc, or be prepended with a space. If there's a space, it means that the line belongs to the prior line's data. My rewritten while look looks like this:

$line = ""; while ( !ereg("\.\r\n",$line)) {

$line = fgets($fp,$buffer); if (preg_match("/\s+/",$line)) {

$MsgArray?[$count-1] .= $line; continue;

} if(empty($line)) { break; }

$MsgArray?[$count] = $line; $count++;

} return $MsgArray?;

Basically, the preg_match checks if the 'just-read' line begins with a space. If so, it appends it to the last read line (the MsgArray?[$count-1]) and continue's. This appears to work with e-mails from my testing.

sending e-mails with long subjects > 60 or so characters, the

Attachments

class-pop3.php (21.5 kB) - added by nreid on 02/21/07 23:11:10.
3836.diff (0.8 kB) - added by Nazgul on 02/23/07 20:54:56.

Change History

02/21/07 23:11:10 changed by nreid

  • attachment class-pop3.php added.

02/23/07 20:54:56 changed by Nazgul

  • attachment 3836.diff added.

02/23/07 20:55:56 changed by Nazgul

  • keywords set to has-patch.
  • milestone changed from 2.3 to 2.2.

Created a patch based on the given code.

02/25/07 13:33:06 changed by markjaquith

  • status changed from new to closed.
  • resolution set to fixed.

(In [4938]) Handle multi-line subjects in class-pop3.php. Props nreid. fixes #3836