/** * 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; }
/** * 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) { 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; }