diff --git a/email_verify.inc.php b/email_verify.inc.php index 19ae6aa..9834c7a 100644 --- a/email_verify.inc.php +++ b/email_verify.inc.php @@ -4,10 +4,29 @@ * Check the email for email_verify module. */ + /* + * Manage cache before calling internal verification function. + */ +function _email_verify_check($mail, $use_caching = FALSE) { + $cache_key = 'email_block_' . $mail; + if ($use_caching && $cache = cache_get($cache_key, 'cache_email_verify')) { + // Log to watchdog. + watchdog('email_verify', t('Cached verification: @error', array('@error' => $cache->data))); + return $cache->data; + } + else { + $result = _email_verify_check_internal($mail); + if (!empty($result)) { + cache_set($cache_key, $result, 'cache_email_verify', CACHE_TEMPORARY); + } + return $result; + } +} + /** * Checks the email address for validity. */ -function _email_verify_check($mail) { +function _email_verify_check_internal($mail) { if (!valid_email_address($mail)) { // The address is syntactically incorrect. // The problem will be caught by the 'user' module anyway, so we avoid diff --git a/email_verify.module b/email_verify.module index 50acb1b..97b0a7d 100644 --- a/email_verify.module +++ b/email_verify.module @@ -86,7 +86,7 @@ function email_verify_form_contact_personal_form_alter(&$form, &$form_state, $fo */ function email_verify_edit_validate($form, &$form_state) { // Validate the e-mail address: - if ($error = email_verify_check($form_state['input']['mail'])) { + if ($error = email_verify_check($form_state['input']['mail'], TRUE)) { form_set_error('mail', $error); } } @@ -101,7 +101,7 @@ function email_verify_edit_validate($form, &$form_state) { * NULL if the address exists, or an error message if we found a problem with * the address. */ -function email_verify_check($mail) { +function email_verify_check($mail, $cache_response = FALSE) { include_once DRUPAL_ROOT . '/' . drupal_get_path('module', 'email_verify') . '/email_verify.inc.php'; - return _email_verify_check($mail); + return _email_verify_check($mail, $cache_response); }