chagenbu                Sat Mar  3 14:06:42 2001 EDT

  Modified files:              
    /php4/pear/Mail     RFC822.php 
  Log:
  Add a validate parameter that allows you to turn off validation of atoms.
  This lets you pass in an address list containing non-mime-encoded addresses,
  for example, and get back a correctly split-up list that you can then encode.
  
  
Index: php4/pear/Mail/RFC822.php
diff -u php4/pear/Mail/RFC822.php:1.3 php4/pear/Mail/RFC822.php:1.4
--- php4/pear/Mail/RFC822.php:1.3       Mon Feb 19 19:03:21 2001
+++ php4/pear/Mail/RFC822.php   Sat Mar  3 14:06:42 2001
@@ -22,7 +22,7 @@
  *
  * @author  Richard Heyes <[EMAIL PROTECTED]>
  * @author  Chuck Hagenbuch <[EMAIL PROTECTED]>
- * @version $Revision: 1.3 $
+ * @version $Revision: 1.4 $
  */
 class Mail_RFC822 {
 
@@ -30,6 +30,7 @@
     var $address = null;
     var $default_host = 'localhost';
     var $nestGroups = true;
+    var $validate = true;
     var $addresses = array();
     var $structure = array();
     var $error = null;
@@ -46,12 +47,14 @@
      * @param $address                    The address(es) to validate.
      * @param $default_host    (Optional) Default domain/host etc. If not supplied, 
will be set to localhost.
      * @param $nest_groups     (Optional) Whether to return the structure with groups 
nested for easier viewing.
+     * @param $validate        (Optional) Whether to validate atoms. Turn this off if 
+you need to run addresses through before encoding the personal names, for instance.
      */
-    function Mail_RFC822($address = null, $default_host = null, $nest_groups = null)
+    function Mail_RFC822($address = null, $default_host = null, $nest_groups = null, 
+$validate = null)
     {
         if (isset($address))      $this->address = $address;
         if (isset($default_host)) $this->default_host = $default_host;
         if (isset($nest_groups))  $this->nestGroups = $nest_groups;
+       if (isset($validate))     $this->validate     = $validate;
     }
 
 
@@ -63,17 +66,19 @@
      * @param $address                    The address(es) to validate.
      * @param $default_host    (Optional) Default domain/host etc.
      * @param $nest_groups     (Optional) Whether to return the structure with groups 
nested for easier viewing.
+     * @param $validate        (Optional) Whether to validate atoms. Turn this off if 
+you need to run addresses through before encoding the personal names, for instance.
      */
-    function parseAddressList($address = null, $default_host = null, $nest_groups = 
null)
+    function parseAddressList($address = null, $default_host = null, $nest_groups = 
+null, $validate = null)
     {
         if (!isset($this->mailRFC822)) {
-            $obj = new Mail_RFC822($address, $default_host, $nest_groups);
+            $obj = new Mail_RFC822($address, $default_host, $nest_groups, $validate);
             return $obj->parseAddressList();
         }
 
         if (isset($address))      $this->address      = $address;
         if (isset($default_host)) $this->default_host = $default_host;
         if (isset($nest_groups))  $this->nestGroups   = $nest_groups;
+       if (isset($validate))     $this->validate     = $validate;
 
         $this->structure  = array();
         $this->addresses  = array();
@@ -411,22 +416,35 @@
      * Function to validate an atom which from rfc822 is:
      * atom = 1*<any CHAR except specials, SPACE and CTLs>
      * 
+     * If validation ($this->validate) has been turned off, then
+     * validateAtom() doesn't actually check anything. This is so that you
+     * can split a list of addresses up before encoding personal names
+     * (umlauts, etc.), for example.
+     * 
      * @access private
      * @param $atom The string to check.
      */
     function validateAtom($atom)
     {
+       if (!$this->validate) {
+           // Validation has been turned off; assume the atom is okay.
+           return true;
+       }
+       
         // Check for any char from ASCII 0 - ASCII 127
-        if (!preg_match('/^[\\x00-\\x7E]+$/i', $atom, $matches))
+        if (!preg_match('/^[\\x00-\\x7E]+$/i', $atom, $matches)) {
             return false;
+       }
         
         // Check for specials:
-        if (preg_match('/[][()<>@,;\\:". ]/', $atom))
+        if (preg_match('/[][()<>@,;\\:". ]/', $atom)) {
             return false;
+       }
         
         // Check for control characters (ASCII 0-31):
-        if (preg_match('/[\\x00-\\x1F]+/', $atom))
+        if (preg_match('/[\\x00-\\x1F]+/', $atom)) {
             return false;
+       }
         
         return true;
     }



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to