/** * Listens to requests to check the IMAP inbox. * * If a POST request is made to check the IMAP inbox, RBE will actually * process this request in this function. We also make sure that WP-cron is * running before pinging the IMAP inbox. * * @since 1.0-RC3 * * @see bp_rbe_spawn_inbox_check() */ function bp_rbe_run_inbox_listener() { if (empty($_POST['_bp_rbe_check'])) { return; } // make sure WP-cron isn't running if (defined('DOING_CRON') || isset($_GET['doing_wp_cron'])) { return; } if (bp_rbe_is_connecting(array('clearcache' => true))) { return; } if (bp_rbe_is_connected()) { return; } bp_rbe_add_imap_lock(); // run our inbox check $imap = BP_Reply_By_Email_IMAP::init(); $imap = $imap->run(); // Do not run the inbox check again on failure. if (false === $imap) { remove_action('shutdown', 'bp_rbe_spawn_inbox_check'); } // kill the rest of this page die; }
/** * Parses the body of an email message. * * Tries to fetch the plain-text version when available first. Otherwise, will * fallback to the HTML version. * * @uses imap_fetchstructure() Get the structure of an email * @uses imap_fetchbody() Using the third parameter will return a portion of the email depending on the email structure. * @param resource $imap The current IMAP connection * @param int $i The current email message number * @param bool $reply If we're parsing a reply or not. Default set to true. * @return mixed Either the email body on success or false on failure */ public static function body_parser($imap, $i, $reply = true) { // get the email structure $structure = imap_fetchstructure($imap, $i); // setup encoding variable $encoding = $structure->encoding; // this is a multipart email if (!empty($structure->parts)) { // parse the parts! $data = self::multipart_plain_text_parser($structure->parts, $imap, $i); // we successfully parsed something from the multipart email if (!empty($data)) { // $data when extracted includes: // $body // $encoding // $params (if applicable) extract($data); unset($data); } // either a plain-text email or a HTML email } else { $body = imap_body($imap, $i); } // decode emails with the following encoding switch ($encoding) { // quoted-printable case 4: $body = quoted_printable_decode($body); break; // base64 // base64 case 3: $body = base64_decode($body); break; } // convert email to UTF-8 if not UTF-8 if (!empty($params['charset']) && $params['charset'] != 'utf-8') { // try to use mb_convert_encoding() first if it exists // there are differing opinions as to whether iconv() is better than // mb_convert_encoding() // mb_convert_encoding() appears to have less problems than iconv() // so this is used first if (function_exists('mb_convert_encoding')) { $body = mb_convert_encoding($body, 'utf-8', $params['charset']); // fallback to iconv() if mb_convert_encoding()_doesn't exist } elseif (function_exists('iconv')) { $body = iconv($params['charset'], 'utf-8//TRANSLIT', $body); } } // do something special for emails that only contain HTML if (strtolower($structure->subtype) == 'html') { self::$html = true; } return $body; }