Example #1
0
/** FUNCTIONS **/
function getPostAuthorDetails(&$subject, &$content, &$mimeDecodedEmail)
{
    /* we check whether or not the e-mail is a forwards or a redirect. If it is
     * a fwd, then we glean the author details from the body of the post.
     * Otherwise we get them from the headers    
     */
    global $wpdb;
    // see if subject starts with Fwd:
    if (preg_match("/(^Fwd:) (.*)/", $subject, $matches)) {
        $subject = trim($matches[2]);
        if (preg_match("/\nfrom:(.*?)\n/i", $content, $matches)) {
            $theAuthor = GetNameFromEmail($matches[1]);
            $mimeDecodedEmail->headers['from'] = $theAuthor;
        }
        if (preg_match("/\ndate:(.*?)\n/i", $content, $matches)) {
            $theDate = $matches[1];
            $mimeDecodedEmail->headers['date'] = $theDate;
        }
    } else {
        $theDate = $mimeDecodedEmail->headers['date'];
        $theAuthor = GetNameFromEmail($mimeDecodedEmail->headers['from']);
        $theEmail = RemoveExtraCharactersInEmailAddress(trim($mimeDecodedEmail->headers["from"]));
    }
    // now get rid of forwarding info in the content
    $lines = preg_split("/\r\n/", $content);
    $newContents = '';
    foreach ($lines as $line) {
        if (preg_match("/^(from|subject|to|date):.*?/i", $line, $matches) == 0 && preg_match("/^-+\\s*forwarded\\s*message\\s*-+/i", $line, $matches) == 0) {
            $newContents .= preg_replace("/\r/", "", $line) . "\n";
        }
    }
    $content = $newContents;
    echo $newContents;
    $theDetails = array('content' => "<div class='postmetadata alt'>On {$theDate}, {$theAuthor}" . " posted:</div>", 'author' => $theAuthor, 'email' => $theEmail);
    return $theDetails;
}
Example #2
0
function getPostAuthorDetails(&$subject, &$content, &$mimeDecodedEmail)
{
    $theDate = $mimeDecodedEmail->headers['date'];
    $theEmail = $mimeDecodedEmail->headers["from"];
    DebugEcho("getPostAuthorDetails: pre email filter {$theEmail}");
    $theEmail = apply_filters("postie_filter_email", $theEmail);
    DebugEcho("getPostAuthorDetails: post email filter {$theEmail}");
    $theEmail = RemoveExtraCharactersInEmailAddress($theEmail);
    $regAuthor = get_user_by('email', $theEmail);
    if ($regAuthor) {
        $theAuthor = $regAuthor->user_login;
        $theUrl = $regAuthor->user_url;
        $theID = $regAuthor->ID;
    } else {
        $theAuthor = GetNameFromEmail($theEmail);
        $theUrl = '';
        $theID = '';
    }
    // see if subject starts with Fwd:
    if (preg_match("/(^Fwd:) (.*)/", $subject, $matches)) {
        DebugEcho("Fwd: detected");
        $subject = trim($matches[2]);
        if (preg_match("/\nfrom:(.*?)\n/i", $content, $matches)) {
            $theAuthor = GetNameFromEmail($matches[1]);
            $mimeDecodedEmail->headers['from'] = $theAuthor;
        }
        //TODO dosen't always work with HTML
        if (preg_match("/\ndate:(.*?)\n/i", $content, $matches)) {
            $theDate = $matches[1];
            DebugEcho("date in Fwd: {$theDate}");
            if (($timestamp = strtotime($theDate)) === false) {
                DebugEcho("bad date found: {$theDate}");
            } else {
                $mimeDecodedEmail->headers['date'] = $theDate;
            }
        }
        // now get rid of forwarding info in the content
        $lines = preg_split("/\r\n/", $content);
        $newContents = '';
        foreach ($lines as $line) {
            if (preg_match("/^(from|subject|to|date):.*?/i", $line, $matches) == 0 && preg_match("/^-+\\s*forwarded\\s*message\\s*-+/i", $line, $matches) == 0) {
                $newContents .= preg_replace("/\r/", "", $line) . "\n";
            }
        }
        $content = $newContents;
    }
    $theDetails = array('content' => "<div class='postmetadata alt'>On {$theDate}, {$theAuthor}" . " posted:</div>", 'emaildate' => $theDate, 'author' => $theAuthor, 'comment_author_url' => $theUrl, 'user_ID' => $theID, 'email' => $theEmail);
    return $theDetails;
}
Example #3
0
 public function testGetNameFromEmail()
 {
     $this->assertEquals("", GetNameFromEmail(""));
     $this->assertEquals("Wayne", GetNameFromEmail('Wayne <*****@*****.**>'));
     $this->assertEquals("wayne", GetNameFromEmail('*****@*****.**'));
 }