Skip to content

Commit

Permalink
Initial pass at stripping common email signatures from email replies.…
Browse files Browse the repository at this point in the history
… See #6.
  • Loading branch information
r-a-y committed Apr 23, 2012
1 parent 41ae236 commit 19e8664
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
43 changes: 43 additions & 0 deletions includes/bp-rbe-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,17 @@ function bp_rbe_log( $message ) {
error_log( '[' . gmdate( 'd-M-Y H:i:s' ) . '] ' . $message . "\n", 3, BP_RBE_DEBUG_LOG_PATH );
}

/**
* Gets the last line of a given string.
*
* @param string $text The text we want to grab the last line for
* @return string
* @since 1.0-beta
*/
function bp_rbe_get_last_line( $text ) {
return substr( strrchr( $text, 10 ), 1 );
}

/** Hook-related ********************************************************/

/**
Expand Down Expand Up @@ -396,6 +407,38 @@ function bp_rbe_remove_eol_char( $content ) {
return $content;
}

/**
* Tries to remove the email signature of most common email clients from email replies.
*
* @uses bp_rbe_get_last_line() Gets the last line of a given string
* @param string $content The content we want to modify
* @return string
* @since 1.0-beta
*/
function bp_rbe_remove_email_client_signature( $content ) {
$last_line = bp_rbe_get_last_line( $content );

switch( $last_line ) {
// remove common mobile device sigs
// is this string localized in other countries? better safe than sorry!
case strpos( $last_line, __( 'Sent from my ', 'bp-rbe' ) ) === 0 :
$content = rtrim( $content, PHP_EOL . $last_line );

break;

// remove common desktop email client reply lines
// if last character of last line is a colon (':'), remove the last line entirely
// eg. 'On DATE, USER wrote:'
// 'USER wrote:'
case substr( $last_line, -1 ) === ':' :
$content = rtrim( $content, PHP_EOL . $last_line );

break;
}

return $content;
}

/**
* After successfully posting an email message to BuddyPress,
* we mark the email for deletion for user privacy issues.
Expand Down
3 changes: 2 additions & 1 deletion includes/bp-rbe-hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
add_action( 'admin_init', 'bp_rbe_cron' );

// email body parsing
add_filter( 'bp_rbe_parse_email_body_reply', 'bp_rbe_remove_eol_char' );
add_filter( 'bp_rbe_parse_email_body_reply', 'bp_rbe_remove_eol_char', 1 );
add_filter( 'bp_rbe_parse_email_body_reply', 'bp_rbe_remove_email_client_signature' );

// email inbox parsing
/**
Expand Down

0 comments on commit 19e8664

Please sign in to comment.