public static function init($args = array(), $i = 1)
{
/**
* Hook to allow plugins to do something before parser begins.
*
* @since 1.0-RC4
*/
do_action('bp_rbe_before_parser');
$instance = new self($args, $i);
// Email header check ******************************************
if (empty(self::$headers)) {
//do_action( 'bp_rbe_imap_no_match', $this->connection, $i, false, 'no_headers' );
return new WP_Error('no_headers');
}
bp_rbe_log('Message #' . $i . ': email headers successfully parsed');
// Querystring check *******************************************
if (empty(self::$querystring)) {
//do_action( 'bp_rbe_imap_no_match', $this->connection, $i, self::$headers, 'no_address_tag' );
return new WP_Error('no_address_tag', '', $args);
}
bp_rbe_log('Message #' . $i . ': address tag successfully parsed');
// User check **************************************************
if (empty(self::$user)) {
//do_action( 'bp_rbe_imap_no_match', $this->connection, $i, self::$headers, 'no_user_id' );
return new WP_Error('no_user_id', '', $args);
}
// Spammer check ***********************************************
$is_spammer = false;
// Multisite spammer check
if (!empty(self::$user->spam)) {
$is_spammer = true;
}
// Single site spammer check
if (1 == self::$user->user_status) {
$is_spammer = true;
}
if ($is_spammer) {
//do_action( 'bp_rbe_imap_no_match', $this->connection, $i, $headers, 'user_is_spammer' );
return new WP_Error('user_is_spammer', '', $args);
}
// Parameters parser *******************************************
// Check if we're posting a new item or not
$params = self::get_parameters();
if (!$params) {
//do_action( 'bp_rbe_imap_no_match', $this->connection, $i, $headers, 'no_params' );
return new WP_Error('no_params', '', $args);
}
bp_rbe_log('Message #' . $i . ': params = ' . print_r($params, true));
// Email body parser *******************************************
self::$content = self::get_body(self::$content, self::$is_html, !self::is_new_item(), $i);
// If there's no email body and this is a reply, stop!
if (!self::$content && !self::is_new_item()) {
//do_action( 'bp_rbe_imap_no_match', $this->connection, $i, $headers, 'no_reply_body' );
return new WP_Error('no_reply_body', '', $args);
}
// log the body for replied items
if (!self::is_new_item()) {
bp_rbe_log('Message #' . $i . ': body contents - ' . self::$content);
}
// Parsing completed! ******************************************
$data = array('headers' => self::$headers, 'content' => self::$content, 'subject' => self::$subject, 'user_id' => self::$user->ID, 'is_html' => self::$is_html, 'i' => $i);
// plugins should use the following hook to do their posting routine
$retval = apply_filters('bp_rbe_parse_completed', true, $data, $params);
// clean up after ourselves
self::clear_properties();
return $retval;
}