Example #1
0
function fetch_mails()
{
    global $wpdb;
    /* checks mail from various mailboxes and posts those e-mails */
    //Load up some usefull libraries
    //Retreive emails
    $fetch_query = 'SELECT * FROM ' . $wpdb->prefix . 'postie_addresses';
    $mailboxes = $wpdb->get_results($fetch_query);
    print_r($mailboxes);
    $config = get_config();
    foreach ($mailboxes as $mailbox) {
        $emails = FetchMail($mailbox->server, $mailbox->port, $mailbox->email, $mailbox->passwd, $mailbox->protocol);
        //loop through messages
        foreach ($emails as $email) {
            //sanity check to see if there is any info in the message
            if ($email == NULL) {
                print 'Dang, message is empty!';
                continue;
            }
            $mimeDecodedEmail = DecodeMimeMail($email);
            $from = RemoveExtraCharactersInEmailAddress(trim($mimeDecodedEmail->headers["from"]));
            //Check poster to see if a valid person
            $poster = ValidatePoster($mimeDecodedEmail, $config);
            if (!empty($poster)) {
                if ($config['TEST_EMAIL']) {
                    DebugEmailOutput($email, $mimeDecodedEmail);
                }
                if ($mailbox->category) {
                    $config['DEFAULT_POST_CATEGORY'] = $mailbox->category;
                }
                PostEmail($poster, $mimeDecodedEmail, $config);
            } else {
                print "<p>Ignoring email - not authorized.\n";
            }
        }
        // end looping over messages
    }
}
Example #2
0
/**
 * Determines if the sender is a valid user.
 * @return integer|NULL
 */
function ValidatePoster(&$mimeDecodedEmail, $config)
{
    $test_email = '';
    extract($config);
    global $wpdb;
    $poster = NULL;
    $from = "";
    if (property_exists($mimeDecodedEmail, "headers") && array_key_exists('from', $mimeDecodedEmail->headers)) {
        $from = RemoveExtraCharactersInEmailAddress(trim($mimeDecodedEmail->headers["from"]));
        $from = apply_filters("postie_filter_email", $from);
        DebugEcho("ValidatePoster: post email filter {$from}");
    } else {
        DebugEcho("No 'from' header found");
        DebugDump($mimeDecodedEmail->headers);
    }
    $resentFrom = "";
    if (property_exists($mimeDecodedEmail, "headers") && array_key_exists('resent-from', $mimeDecodedEmail->headers)) {
        $resentFrom = RemoveExtraCharactersInEmailAddress(trim($mimeDecodedEmail->headers["resent-from"]));
    }
    //See if the email address is one of the special authorized ones
    if (!empty($from)) {
        DebugEcho("Confirming Access For {$from} ");
        $user = get_user_by('email', $from);
        if ($user !== false) {
            $user_ID = $user->ID;
        }
    } else {
        $user_ID = "";
    }
    if (!empty($user_ID)) {
        $user = new WP_User($user_ID);
        if ($user->has_cap("post_via_postie")) {
            DebugEcho("{$user_ID} has 'post_via_postie' permissions");
            $poster = $user_ID;
            DebugEcho("posting as user {$poster}");
        } else {
            DebugEcho("{$user_ID} does not have 'post_via_postie' permissions");
            $user_ID = "";
        }
    }
    if (empty($user_ID) && ($turn_authorization_off || isEmailAddressAuthorized($from, $authorized_addresses) || isEmailAddressAuthorized($resentFrom, $authorized_addresses))) {
        DebugEcho("ValidatePoster: looking up default user {$admin_username}");
        $user = get_user_by('login', $admin_username);
        if ($user === false) {
            EchoInfo("Your 'Default Poster' setting '{$admin_username}' is not a valid WordPress user (2)");
            $poster = 1;
        } else {
            $poster = $user->ID;
        }
        DebugEcho("ValidatePoster: found user '{$poster}'");
    }
    $validSMTP = isValidSmtpServer($mimeDecodedEmail, $smtp);
    if (!$poster || !$validSMTP) {
        EchoInfo('Invalid sender: ' . htmlentities($from) . "! Not adding email!");
        if ($forward_rejected_mail) {
            $admin_email = get_option("admin_email");
            if (MailToRecipients($mimeDecodedEmail, $test_email, array($admin_email), $return_to_sender)) {
                EchoInfo("A copy of the message has been forwarded to the administrator.");
            } else {
                EchoInfo("The message was unable to be forwarded to the adminstrator.");
            }
        }
        return '';
    }
    return $poster;
}
/**
* Determines if the sender is a valid user.
* @return integer|NULL
*/
function ValidatePoster(&$mimeDecodedEmail, $config)
{
    global $wpdb;
    $poster = NULL;
    $from = RemoveExtraCharactersInEmailAddress(trim($mimeDecodedEmail->headers["from"]));
    $resentFrom = RemoveExtraCharactersInEmailAddress(trim($mimeDecodedEmail->headers["resent-from"]));
    /*
    if ( empty($from) ) { 
        echo 'Invalid Sender - Emtpy! ';
        return;
    }
    */
    //See if the email address is one of the special authorized ones
    print "Confirming Access For {$from} \n";
    $sql = 'SELECT id FROM ' . $wpdb->users . ' WHERE user_email=\'' . addslashes($from) . "' LIMIT 1;";
    $user_ID = $wpdb->get_var($sql);
    $user = new WP_User($user_ID);
    if ($config["TURN_AUTHORIZATION_OFF"] || CheckEmailAddress($from, $config['AUTHORIZED_ADDRESSES']) || CheckEmailAddress($resentFrom, $config['AUTHORIZED_ADDRESSES'])) {
        if (empty($user_ID)) {
            print "{$from} is authorized to post as the administrator\n";
            $from = get_option("admin_email");
            $adminUser = $config['ADMIN_USERNAME'];
            echo "adminUser='******'";
            $poster = $wpdb->get_var("SELECT ID FROM {$wpdb->users} WHERE\n          user_login  = '******'");
        } else {
            $poster = $user_ID;
        }
    } else {
        if ($user->has_cap("post_via_postie")) {
            $poster = $user_ID;
        }
    }
    $validSMTP = checkSMTP($mimeDecodedEmail, $config['SMTP']);
    if (!$poster || !$validSMTP) {
        echo 'Invalid sender: ' . htmlentities($from) . "! Not adding email!\n";
        if ($config["FORWARD_REJECTED_MAIL"]) {
            if (MailToRecipients($mimeDecodedEmail, $config['TEST_EMAIL'], array(), $config['RETURN_TO_SENDER'])) {
                echo "A copy of the message has been forwarded to the administrator.\n";
            } else {
                echo "The message was unable to be forwarded to the adminstrator.\n";
            }
        }
        return;
    }
    return $poster;
}
Example #4
0
/**
* Determines if the sender is a valid user.
* @return integer|NULL
*/
function ValidatePoster(&$mimeDecodedEmail, $config)
{
    extract($config);
    global $wpdb;
    $poster = NULL;
    $from = RemoveExtraCharactersInEmailAddress(trim($mimeDecodedEmail->headers["from"]));
    $resentFrom = RemoveExtraCharactersInEmailAddress(trim($mimeDecodedEmail->headers["resent-from"]));
    /*
    if ( empty($from) ) { 
        echo 'Invalid Sender - Emtpy! ';
        return;
    }
    */
    //See if the email address is one of the special authorized ones
    print "Confirming Access For {$from} \n";
    $sql = 'SELECT id FROM ' . $wpdb->users . ' WHERE user_email=\'' . addslashes($from) . "' LIMIT 1;";
    $user_ID = $wpdb->get_var($sql);
    if (!empty($user_ID)) {
        $user = new WP_User($user_ID);
        if ($user->has_cap("post_via_postie")) {
            $poster = $user_ID;
            echo "posting as user {$poster}";
        } else {
            $poster = $wpdb->get_var("SELECT ID FROM {$wpdb->users} WHERE\n            user_login  = '******'");
        }
    } elseif ($turn_authorization_off || CheckEmailAddress($from, $authorized_addresses) || CheckEmailAddress($resentFrom, $authorized_addresses)) {
        $poster = $wpdb->get_var("SELECT ID FROM {$wpdb->users} WHERE\n          user_login  = '******'");
    }
    $validSMTP = checkSMTP($mimeDecodedEmail, $smtp);
    if (!$poster || !$validSMTP) {
        echo 'Invalid sender: ' . htmlentities($from) . "! Not adding email!\n";
        if ($forward_rejected_mail) {
            $admin_email = get_option("admin_email");
            if (MailToRecipients($mimeDecodedEmail, $test_email, array($admin_email), $return_to_sender)) {
                echo "A copy of the message has been forwarded to the administrator.\n";
            } else {
                echo "The message was unable to be forwarded to the adminstrator.\n";
            }
        }
        return;
    }
    return $poster;
}
Example #5
0
/**
 * Determines if the sender is a valid user.
 * @return integer|NULL
 */
function ValidatePoster(&$mimeDecodedEmail)
{
    global $wpdb;
    $config = GetConfig();
    $poster = NULL;
    $from = RemoveExtraCharactersInEmailAddress(trim($mimeDecodedEmail->headers["from"]));
    $resentFrom = RemoveExtraCharactersInEmailAddress(trim($mimeDecodedEmail->headers["resent-from"]));
    if (empty($from)) {
        echo 'Invalid Sender - Emtpy! ';
        return;
    }
    //See if the email address is one of the special authorized ones
    print "Confirming Access For {$from} \n";
    $sql = 'SELECT id FROM ' . $wpdb->users . ' WHERE user_email=\'' . addslashes($from) . "' LIMIT 1;";
    $user_ID = $wpdb->get_var($sql);
    $user = new WP_User($user_ID);
    if ($config["TURN_AUTHORIZATION_OFF"] || CheckEmailAddress($from) || CheckEmailAddress($resentFrom)) {
        if (empty($user_ID)) {
            print "{$from} is authorized to post as the administrator\n";
            $from = get_option("admin_email");
            $poster = $wpdb->get_var("SELECT ID FROM {$wpdb->users} WHERE ID = 1");
        } else {
            $poster = $user_ID;
        }
    } else {
        if ($user->has_cap("post_via_postie")) {
            $poster = $user_ID;
        }
    }
    if (!$poster) {
        echo 'Invalid sender: ' . htmlentities($from) . "! Not adding email!\n";
        if ($config["FORWARD_REJECTED_MAIL"]) {
            if (ForwardRejectedMailToAdmin($mimeDecodedEmail)) {
                echo "A copy of the message has been forwarded to the administrator.\n";
            } else {
                echo "The message was unable to be forwarded to the adminstrator.\n";
            }
        }
        return;
    }
    return $poster;
}
Example #6
0
 if (function_exists('memory_get_usage')) {
     echo "memory at start of e-mail processing:" . memory_get_usage() . "\n";
 }
 //sanity check to see if there is any info in the message
 if ($email == NULL) {
     $message = __('Dang, message is empty!', 'postie');
     continue;
 } else {
     if ($email == 'already read') {
         $message = "\n" . __("There does not seem to be any new mail.", 'postie') . "\n";
         continue;
     }
 }
 $message = '';
 $mimeDecodedEmail = DecodeMimeMail($email, true);
 $from = RemoveExtraCharactersInEmailAddress(trim($mimeDecodedEmail->headers["from"]));
 /*
 if ($from != "") {
     continue;
 }
 */
 //Check poster to see if a valid person
 $poster = ValidatePoster($mimeDecodedEmail, $config);
 if (!empty($poster)) {
     if ($config['TEST_EMAIL']) {
         DebugEmailOutput($email, $mimeDecodedEmail);
     }
     PostEmail($poster, $mimeDecodedEmail, $config);
 } else {
     print "<p>Ignoring email - not authorized.\n";
 }