public function testCheckEmailAddress() { $this->assertFalse(isEmailAddressAuthorized(null, null)); $this->assertFalse(isEmailAddressAuthorized(null, array())); $this->assertFalse(isEmailAddressAuthorized("", array())); $this->assertFalse(isEmailAddressAuthorized("", array(""))); $this->assertFalse(isEmailAddressAuthorized("bob", array("jane"))); $this->assertTrue(isEmailAddressAuthorized("bob", array("bob"))); $this->assertTrue(isEmailAddressAuthorized("bob", array("BoB"))); $this->assertTrue(isEmailAddressAuthorized("bob", array("bob", "jane"))); $this->assertTrue(isEmailAddressAuthorized("bob", array("jane", "bob"))); }
/** * 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; }