/**
  * Parses and returns the email body content.
  *
  * @param string $body The email body content.
  * @param bool $html Whether the email body is HTML or not. Defaults to false.
  * @param bool $reply Whether the current item is a reply.  Defaults to true.
  * @param int $i The current email message number.
  * @return string|bool
  */
 public static function get_body($body = '', $html = false, $reply = true, $i = 1)
 {
     if ($html) {
         $body = apply_filters('bp_rbe_parse_html_email', $body);
     }
     // Check to see if we're parsing a reply
     if ($reply) {
         // Find our pointer
         $pointer = strpos($body, bp_rbe_get_marker());
         // If our pointer isn't found, return false
         if ($pointer === false) {
             return false;
         }
         // Return email body up to our pointer only
         $body = apply_filters('bp_rbe_parse_email_body_reply', trim(substr($body, 0, $pointer)), $body);
         // this means we're posting something new (eg. new forum topic)
         // do something special for this case
     } else {
         $body = apply_filters('bp_rbe_parse_email_body_new', $body);
     }
     if (empty($body)) {
         bp_rbe_log('Message #' . $i . ': empty body');
         return false;
     }
     return apply_filters('bp_rbe_parse_email_body', trim($body));
 }
/**
 * Logs no match errors during RBE parsing.
 *
 * Also sends a failure message back to the original sender for feedback
 * purposes if enabled.
 *
 * @since 1.0-RC3
 *
 * @uses bp_rbe_log() Logs error messages in a custom log
 * @param object $parser The WP_Error object.
 * @param array $data {
 *     An array of arguments.
 *
 *     @type array $headers Email headers.
 *     @type string $to_email The 'To' email address.
 *     @type string $from_email The 'From' email address.
 *     @type string $content The email body content.
 *     @type string $subject The email subject line.
 *     @type bool $is_html Whether the email content is HTML or not.
 * }
 * @param int $i The current message number
 * @param resource|bool $imap The IMAP connection if passed. Boolean false if not.
 */
function bp_rbe_log_no_matches($parser, $data, $i, $imap)
{
    $log = $message = false;
    $type = is_wp_error($parser) ? $parser->get_error_code() : false;
    // log messages based on the type
    switch ($type) {
        /** RBE **********************************************************/
        case 'no_address_tag':
            $log = __('error - no address tag could be found', 'bp-rbe');
            break;
        case 'no_user_id':
            $log = __('error - no user ID could be found', 'bp-rbe');
            $sitename = wp_specialchars_decode(get_blog_option(bp_get_root_blog_id(), 'blogname'), ENT_QUOTES);
            $message = sprintf(__('Hi there,

You tried to use the email address - %s - to reply by email.  Unfortunately, we could not find this email address in our system.

This can happen in a couple of different ways:
* You have configured your email client to reply with a custom "From:" email address.
* You read email addressed to more than one account inside of a single Inbox.

Make sure that, when replying by email, your "From:" email address is the same as the address you\'ve registered at %s.

If you have any questions, please let us know.', 'bp-rbe'), BP_Reply_By_Email_Parser::get_header($data['headers'], 'From'), $sitename);
            break;
        case 'user_is_spammer':
            $log = __('notice - user is marked as a spammer.  reply not posted!', 'bp-rbe');
            break;
        case 'no_params':
            $log = __('error - no parameters were found', 'bp-rbe');
            break;
        case 'no_reply_body':
            $log = __('error - body message for reply was empty', 'bp-rbe');
            $message = sprintf(__('Hi there,

Your reply could not be posted because we could not find the "%s" marker in the body of your email.

In the future, please make sure you reply *above* this line for your comment to be posted on the site.

For reference, your entire reply was:

"%s".

If you have any questions, please let us know.', 'bp-rbe'), bp_rbe_get_marker(), $data['content']);
            break;
            /** ACTIVITY *****************************************************/
        /** ACTIVITY *****************************************************/
        case 'root_activity_deleted':
            $log = __('error - root activity update was deleted before this could be posted', 'bp-rbe');
            $message = sprintf(__('Hi there,

Your reply:

"%s"

Could not be posted because the activity entry you were replying to no longer exists.

We apologize for any inconvenience this may have caused.', 'bp-rbe'), BP_Reply_By_Email_Parser::get_body($data['content'], $data['is_html'], true, $i));
            break;
        case 'root_or_parent_activity_deleted':
            $log = __('error - root or parent activity update was deleted before this could be posted', 'bp-rbe');
            $message = sprintf(__('Hi there,

Your reply:

"%s"

Could not be posted because the activity entry you were replying to no longer exists.

We apologize for any inconvenience this may have caused.', 'bp-rbe'), BP_Reply_By_Email_Parser::get_body($data['content'], $data['is_html'], true, $i));
            break;
            /** GROUP FORUMS *************************************************/
        /** GROUP FORUMS *************************************************/
        case 'user_not_group_member':
            $log = __('error - user is not a member of the group. forum reply not posted.', 'bp-rbe');
            $message = sprintf(__('Hi there,

Your forum reply:

"%s"

Could not be posted because you are no longer a member of this group.  To comment on the forum thread, please rejoin the group.

We apologize for any inconvenience this may have caused.', 'bp-rbe'), BP_Reply_By_Email_Parser::get_body($data['content'], $data['is_html'], true, $i));
            break;
        case 'user_banned_from_group':
            $log = __('notice - user is banned from group. forum reply not posted.', 'bp-rbe');
            break;
        case 'new_forum_topic_empty':
            $log = __('error - body message for new forum topic was empty', 'bp-rbe');
            $message = __('Hi there,

We could not post your new forum topic by email because we could not find any text in the body of the email.

In the future, please make sure to type something in your email! :)

If you have any questions, please let us know.', 'bp-rbe');
            break;
        case 'forum_reply_exists':
            $log = __('error - forum reply already exists in topic', 'bp-rbe');
            $message = sprintf(__('Hi there,

Your forum reply:

"%s"

Could not be posted because you have already posted the same message in the forum topic you were attempting to reply to.

We apologize for any inconvenience this may have caused.', 'bp-rbe'), BP_Reply_By_Email_Parser::get_body($data['content'], $data['is_html'], true, $i));
            break;
        case 'forum_reply_fail':
            $log = __('error - forum topic was deleted before reply could be posted', 'bp-rbe');
            $message = sprintf(__('Hi there,

Your forum reply:

"%s"

Could not be posted because the forum topic you were replying to no longer exists.

We apologize for any inconvenience this may have caused.', 'bp-rbe'), BP_Reply_By_Email_Parser::get_body($data['content'], $data['is_html'], true, $i));
            break;
        case 'forum_topic_fail':
            $log = __('error - forum topic failed to be created', 'bp-rbe');
            // this is a pretty generic message...
            $message = sprintf(__('Hi there,

Your forum topic titled "%s" could not be posted due to an error.

We apologize for any inconvenience this may have caused.', 'bp-rbe'), $data['subject']);
            break;
            /** PRIVATE MESSAGES *********************************************/
            // most likely a spammer trying to infiltrate an existing PM thread
        /** PRIVATE MESSAGES *********************************************/
        // most likely a spammer trying to infiltrate an existing PM thread
        case 'private_message_not_in_thread':
            $log = __('error - user is not a part of the existing PM conversation', 'bp-rbe');
            break;
        case 'private_message_thread_deleted':
            $log = __('error - private message thread was deleted by all parties before this could be posted', 'bp-rbe');
            $message = sprintf(__('Hi there,

Your private message reply:

"%s"

Could not be posted because the private message thread you were replying to no longer exists.

We apologize for any inconvenience this may have caused.', 'bp-rbe'), BP_Reply_By_Email_Parser::get_body($data['content'], $data['is_html'], true, $i));
            break;
        case 'private_message_fail':
            $log = __('error - private message failed to post', 'bp-rbe');
            $message = sprintf(__('Hi there,

Your reply:

"%s"

Could not be posted due to an error.

We apologize for any inconvenience this may have caused.', 'bp-rbe'), BP_Reply_By_Email_Parser::get_body($data['content'], $data['is_html'], true, $i));
            break;
            // 3rd-party plugins can filter the two variables below to add their own logs and email messages.
        // 3rd-party plugins can filter the two variables below to add their own logs and email messages.
        default:
            $log = apply_filters('bp_rbe_extend_log_no_match', $log, $type, $data, $i, $imap);
            $message = apply_filters('bp_rbe_extend_log_no_match_email_message', $message, $type, $data, $i, $imap);
            break;
    }
    // internal logging
    if ($log) {
        bp_rbe_log(sprintf(__('Message #%d: %s', 'bp-rbe'), $i, $log));
    }
    // failure message to author
    // if you want to turn off failure messages, use the filter below
    if (apply_filters('bp_rbe_enable_failure_message', true) && $message) {
        $to = BP_Reply_By_Email_Parser::get_header($data['headers'], 'From');
        if (!empty($to)) {
            $sitename = wp_specialchars_decode(get_blog_option(bp_get_root_blog_id(), 'blogname'), ENT_QUOTES);
            $subject = sprintf(__('[%s] Your Reply By Email message could not be posted', 'bp-rbe'), $sitename);
            // temporarily remove RBE mail filter by wiping out email querystring
            add_filter('bp_rbe_querystring', '__return_false');
            // send email
            wp_mail($to, $subject, $message);
            // add it back
            remove_filter('bp_rbe_querystring', '__return_false');
        }
    }
}
 /**
  * Prepend our RBE marker to a string.
  *
  * This adds the '--- Reply ABOVE THIS LINE to add a comment ---' line to the
  * beginning of an email's content.  Inspired by Basecamp!
  *
  * @since 1.0-RC4
  *
  * @param  string $content
  * @return string
  */
 protected function prepend_rbe_marker_to_content($content = '')
 {
     $reply_line = bp_rbe_get_marker();
     return "{$reply_line}\n\n{$content}";
 }