Changeset e4acbbd in github


Ignore:
Timestamp:
Oct 14, 2009 6:52:27 AM (4 years ago)
Author:
alecpl <alec@…>
Branches:
master, HEAD, courier-fix, dev-browser-capabilities, pdo, release-0.6, release-0.7, release-0.8
Children:
d31513b
Parents:
b571339
Message:
  • Added server-side e-mail address validation with 'email_dns_check' option (#1485857)
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • CHANGELOG

    rccc80d1 re4acbbd  
    22=========================== 
    33 
     4- Added server-side e-mail address validation with 'email_dns_check' option (#1485857) 
    45- Fix login page loading into an iframe when session expires (#1485952) 
    56- added option 'force_https_port' in 'force_https' plugin (#1486091) 
  • config/main.inc.php.dist

    r65c0a0e re4acbbd  
    365365$rcmail_config['min_keep_alive'] = 60; 
    366366 
     367// Enable DNS checking for e-mail address validation 
     368$rcmail_config['email_dns_check'] = false; 
     369 
    367370/***** these settings can be overwritten by user's preferences *****/ 
    368371 
  • plugins/managesieve/managesieve.php

    rfcc34c0 re4acbbd  
    819819  private function check_email($email) 
    820820  { 
     821    if (function_exists('check_email')); 
     822      return check_email($email); 
     823 
    821824    // Check for invalid characters 
    822825    if (preg_match('/[\x00-\x1F\x7F-\xFF]/', $email)) 
  • program/include/main.inc

    ra9bfe21 re4acbbd  
    14021402 
    14031403/** 
     1404 * E-mail address validation 
     1405 */ 
     1406function check_email($email) 
     1407{ 
     1408  // Check for invalid characters 
     1409  if (preg_match('/[\x00-\x1F\x7F-\xFF]/', $email)) 
     1410    return false; 
     1411 
     1412  // Check that there's one @ symbol, and that the lengths are right 
     1413  if (!preg_match('/^([^@]{1,64})@([^@]{1,255})$/', $email, $email_array)) 
     1414    return false; 
     1415 
     1416  // Check local part 
     1417  $local_array = explode('.', $email_array[1]); 
     1418  foreach ($local_array as $local_part) 
     1419    if (!preg_match('/^(([A-Za-z0-9!#$%&\'*+\/=?^_`{|}~-]+)|("[^"]+"))$/', $local_part)) 
     1420      return false; 
     1421 
     1422  // Check domain part 
     1423  if (preg_match('/^(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3}$/', $email_array[2])  
     1424      || preg_match('/^\[(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3}\]$/', $email_array[2])) 
     1425    return true; // If an IP address 
     1426  else { 
     1427    // If not an IP address 
     1428    $domain_array = explode('.', $email_array[2]); 
     1429    if (sizeof($domain_array) < 2) 
     1430      return false; // Not enough parts to be a valid domain 
     1431 
     1432    foreach ($domain_array as $domain_part) 
     1433      if (!preg_match('/^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]))$/', $domain_part)) 
     1434        return false; 
     1435 
     1436    if (!rcmail::get_instance()->config->get('email_dns_check')) 
     1437      return true; 
     1438 
     1439    if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN' && version_compare(PHP_VERSION, '5.3.0', '<')) 
     1440      return true; 
     1441 
     1442    // find MX record(s) 
     1443    if (getmxrr($email_array[2], $mx_records)) 
     1444      return true; 
     1445 
     1446    // find any DNS record 
     1447    if (checkdnsrr($email_array[2], 'ANY')) 
     1448      return true; 
     1449  } 
     1450 
     1451  return false; 
     1452} 
     1453 
     1454 
     1455/** 
    14041456 * Helper class to turn relative urls into absolute ones 
    14051457 * using a predefined base 
  • program/localization/en_US/messages.inc

    r3f97120 re4acbbd  
    107107$messages['smtprecipientserror'] = 'SMTP Error: Unable to parse recipients list'; 
    108108$messages['smtperror'] = 'SMTP Error: $msg'; 
     109$messages['emailformaterror'] = 'Incorrect e-mail address: $email'; 
    109110 
    110111?> 
  • program/localization/pl_PL/messages.inc

    rebf8726 re4acbbd  
    150150$messages['invalidrequest'] = 'Błędne ŌĠ
    151151danie! Nie zapisano danych.'; 
     152$messages['emailformaterror'] = 'Błędny adres e-mail: $email'; 
    152153 
    153154?> 
  • program/steps/mail/sendmail.inc

    rddc891d re4acbbd  
    152152function rcmail_email_input_format($mailto) 
    153153{ 
     154  global $EMAIL_FORMAT_ERROR; 
     155 
    154156  $regexp = array('/[,;]\s*[\r\n]+/', '/[\r\n]+/', '/[,;]\s*$/m', '/;/', '/(\S{1})(<\S+@\S+>)/U'); 
    155157  $replace = array(', ', ', ', '', ',', '\\1 \\2'); 
     
    182184 
    183185      $result[] = $name.' '.$address; 
     186      $item = $address; 
    184187    } else if (trim($item)) { 
    185       // @TODO: handle errors 
     188      continue; 
     189    } 
     190 
     191    // check address format 
     192    $item = trim($item, '<>'); 
     193    if ($item && !check_email($item)) { 
     194      $EMAIL_FORMAT_ERROR = $item; 
     195      return; 
    186196    } 
    187197  } 
     
    201211$message_charset = isset($_POST['_charset']) ? $_POST['_charset'] : $input_charset; 
    202212 
     213$EMAIL_FORMAT_ERROR = NULL; 
     214 
    203215$mailto = rcmail_email_input_format(get_input_value('_to', RCUBE_INPUT_POST, TRUE, $message_charset)); 
    204216$mailcc = rcmail_email_input_format(get_input_value('_cc', RCUBE_INPUT_POST, TRUE, $message_charset)); 
    205217$mailbcc = rcmail_email_input_format(get_input_value('_bcc', RCUBE_INPUT_POST, TRUE, $message_charset)); 
     218 
     219if ($EMAIL_FORMAT_ERROR) { 
     220  $OUTPUT->show_message('emailformaterror', 'error', array('email' => $EMAIL_FORMAT_ERROR));  
     221  $OUTPUT->send('iframe'); 
     222} 
    206223 
    207224if (empty($mailto) && !empty($mailcc)) { 
Note: See TracChangeset for help on using the changeset viewer.