b2evolution

Multilingual multiuser multiblog engine

b2evolution Technical Documentation (CVS HEAD) [ class tree: main ] [ index: main ] [ all elements ]

Source for file rfc822_addresses.php

Documentation is available at rfc822_addresses.php

  1. <?php
  2. /*
  3.  * rfc822_addresses.php
  4.  *
  5.  * @(#) $Id: rfc822_addresses.php,v 1.1 2008/12/31 16:04:04 tblue246 Exp $
  6.  *
  7.  */
  8.  
  9. /*
  10. {metadocument}<?xml version="1.0" encoding="ISO-8859-1" ?>
  11. <class>
  12.  
  13.     <package>net.manuellemos.mimeparser</package>
  14.  
  15.     <version>@(#) $Id: rfc822_addresses.php,v 1.1 2008/12/31 16:04:04 tblue246 Exp $</version>
  16.     <copyright>Copyright © (C) Manuel Lemos 2006 - 2008</copyright>
  17.     <title>RFC 822 e-mail addresses parser</title>
  18.     <author>Manuel Lemos</author>
  19.     <authoraddress>mlemos-at-acm.org</authoraddress>
  20.  
  21.     <documentation>
  22.         <idiom>en</idiom>
  23.         <purpose>Parse e-mail addresses from headers of <link>
  24.                 <url>http://www.ietf.org/rfc/rfc822.txt</url>
  25.                 <data>RFC 822</data>
  26.             </link> compliant e-mail messages.</purpose>
  27.         <usage>Use the function <functionlink>ParseAddressList</functionlink>
  28.             function to retrieve the list of e-mail addresses contained in
  29.             e-mail message headers like <tt>From</tt>, <tt>To</tt>, <tt>Cc</tt>
  30.             or <tt>Bcc</tt>.</usage>
  31.     </documentation>
  32.  
  33. {/metadocument}
  34. */
  35.  
  36. {
  37.     /* Private variables */
  38.  
  39.     var $v = '';
  40.  
  41.     /* Public variables */
  42.  
  43. /*
  44. {metadocument}
  45.     <variable>
  46.         <name>error</name>
  47.         <type>STRING</type>
  48.         <value></value>
  49.         <documentation>
  50.             <purpose>Store the message that is returned when an error
  51.                 occurs.</purpose>
  52.             <usage>Check this variable to understand what happened when a call to
  53.                 any of the class functions has failed.<paragraphbreak />
  54.                 This class uses cumulative error handling. This means that if one
  55.                 class functions that may fail is called and this variable was
  56.                 already set to an error message due to a failure in a previous call
  57.                 to the same or other function, the function will also fail and does
  58.                 not do anything.<paragraphbreak />
  59.                 This allows programs using this class to safely call several
  60.                 functions that may fail and only check the failure condition after
  61.                 the last function call.<paragraphbreak />
  62.                 Just set this variable to an empty string to clear the error
  63.                 condition.</usage>
  64.         </documentation>
  65.     </variable>
  66. {/metadocument}
  67. */
  68.     var $error = '';
  69.  
  70. /*
  71. {metadocument}
  72.     <variable>
  73.         <name>error_position</name>
  74.         <type>INTEGER</type>
  75.         <value>-1</value>
  76.         <documentation>
  77.             <purpose>Point to the position of the message data or file that
  78.                 refers to the last error that occurred.</purpose>
  79.             <usage>Check this variable to determine the relevant position of the
  80.                 message when a parsing error occurs.</usage>
  81.         </documentation>
  82.     </variable>
  83. {/metadocument}
  84. */
  85.     var $error_position = -1;
  86.  
  87. /*
  88. {metadocument}
  89.     <variable>
  90.         <name>ignore_syntax_errors</name>
  91.         <type>BOOLEAN</type>
  92.         <value>1</value>
  93.         <documentation>
  94.             <purpose>Specify whether the class should ignore syntax errors in
  95.                 malformed addresses.</purpose>
  96.             <usage>Set this variable to <booleanvalue>0</booleanvalue> if it is
  97.                 necessary to verify whether message data may be corrupted due to
  98.                 to eventual bugs in the program that generated the
  99.                 message.<paragraphbreak />
  100.                 Currently the class only ignores some types of syntax errors.
  101.                 Other syntax errors may still cause the
  102.                 <functionlink>ParseAddressList</functionlink> to fail.</usage>
  103.         </documentation>
  104.     </variable>
  105. {/metadocument}
  106. */
  107.     var $ignore_syntax_errors=1;
  108.  
  109. /*
  110. {metadocument}
  111.     <variable>
  112.         <name>warnings</name>
  113.         <type>HASH</type>
  114.         <value></value>
  115.         <documentation>
  116.             <purpose>Return a list of positions of the original message that
  117.                 contain syntax errors.</purpose>
  118.             <usage>Check this variable to retrieve eventual message syntax
  119.                 errors that were ignored when the
  120.                 <variablelink>ignore_syntax_errors</variablelink> is set to
  121.                 <booleanvalue>1</booleanvalue>.<paragraphbreak />
  122.                 The indexes of this array are the positions of the errors. The
  123.                 array values are the corresponding syntax error messages.</usage>
  124.         </documentation>
  125.     </variable>
  126. {/metadocument}
  127. */
  128.     var $warnings=array();
  129.  
  130.     /* Private functions */
  131.  
  132.     Function SetError($error)
  133.     {
  134.         $this->error = $error;
  135.         return(0);
  136.     }
  137.  
  138.     Function SetPositionedError($error$position)
  139.     {
  140.         $this->error_position = $position;
  141.         return($this->SetError($error));
  142.     }
  143.  
  144.     Function SetWarning($warning$position)
  145.     {
  146.         $this->warnings[$position]=$warning;
  147.         return(1);
  148.     }
  149.  
  150.     Function SetPositionedWarning($error$position)
  151.     {
  152.         if(!$this->ignore_syntax_errors)
  153.             return($this->SetPositionedError($error$position));
  154.         return($this->SetWarning($error$position));
  155.     }
  156.  
  157.     Function QDecode($p&$value&$encoding)
  158.     {
  159.         $encoding $charset null;
  160.         $s 0;
  161.         $decoded '';
  162.         $l strlen($value);
  163.         while($s $l)
  164.         {
  165.             if(GetType($q strpos($value'=?'$s)) != 'integer')
  166.             {
  167.                 if($s == 0)
  168.                     return(1);
  169.                 if($s $l)
  170.                     $decoded .= substr($value$s);
  171.                 break;
  172.             }
  173.             if($s $q)
  174.                 $decoded .= substr($value$s$q $s);
  175.             $q += 2;
  176.             if(GetType($c strpos($value'?'$q)) != 'integer'
  177.             || $q == $c)
  178.                 return($this->SetPositionedWarning('invalid Q-encoding character set'$p $q));
  179.             if(IsSet($charset))
  180.             {
  181.                 $another_charset strtolower(substr($value$q$c $q));
  182.                 if(strcmp($charset$another_charset)
  183.                 && strcmp($another_charset'ascii'))
  184.                     return($this->SetWarning('it is not possible to decode an encoded value using mixed character sets into a single value'$p $q));
  185.             }
  186.             else
  187.             {
  188.                 $charset strtolower(substr($value$q$c $q));
  189.                 if(!strcmp($charset'ascii'))
  190.                     $charset null;
  191.             }
  192.             ++$c;
  193.             if(GetType($t strpos($value'?'$c)) != 'integer'
  194.             || $c==$t)
  195.                 return($this->SetPositionedWarning('invalid Q-encoding type'$p $c));
  196.             $type strtolower(substr($value$c$t $c));
  197.             ++$t;
  198.             if(GetType($e strpos($value'?='$t)) != 'integer')
  199.                 return($this->SetPositionedWarning('invalid Q-encoding encoded data'$p $e));
  200.             switch($type)
  201.             {
  202.                 case 'q':
  203.                     for($s $t$s<$e;)
  204.                     {
  205.                         switch($b $value[$s])
  206.                         {
  207.                             case '=':
  208.                                 $h HexDec($hex strtolower(substr($value$s 12)));
  209.                                 if($s $e
  210.                                 || strcmp(sprintf('%02x'$h)$hex))
  211.                                     return($this->SetPositionedWarning('invalid Q-encoding q encoded data'$p $s));
  212.                                 $decoded .= chr($h);
  213.                                 $s += 3;
  214.                                 break;
  215.  
  216.                             case '_':
  217.                                 $decoded .= ' ';
  218.                                 ++$s;
  219.                                 break;
  220.  
  221.                             default:
  222.                                 $decoded .= $b;
  223.                                 ++$s;
  224.                         }
  225.                     }
  226.                     break;
  227.  
  228.                 case 'b':
  229.                     if($e <= $t
  230.                     || strlen($binary base64_decode($data substr($value$t$e $t))) == 0
  231.                     || GetType($binary!= 'string')
  232.                         return($this->SetPositionedWarning('invalid Q-encoding b encoded data'$p $t));
  233.                     $decoded .= $binary;
  234.                     $s $e;
  235.                     break;
  236.  
  237.                 default:
  238.                     return($this->SetPositionedWarning('Q-encoding '.$type.' is not yet supported'$p $c));
  239.             }
  240.             $s += 2;
  241.         }
  242.         $value $decoded;
  243.         $encoding $charset;
  244.         return(1);
  245.     }
  246.  
  247.     Function ParseCText(&$p&$c_text)
  248.     {
  249.         $c_text null;
  250.         $v $this->v;
  251.         if($p<strlen($v)
  252.         && GetType(strchr("\t\r\n ()\\\0"$c $v[$p])) != 'string'
  253.         && Ord($c)<128)
  254.         {
  255.             $c_text $c;
  256.             ++$p;
  257.         }
  258.         return(1);
  259.     }
  260.  
  261.     Function ParseQText(&$p&$q_text)
  262.     {
  263.         $q_text null;
  264.         $v $this->v;
  265.         if($p>strlen($v)
  266.         || GetType(strchr("\t\r\n \"\\\0"$c $v[$p])) == 'string')
  267.             return(1);
  268.         if(Ord($c>= 128)
  269.         {
  270.             if(!$this->ignore_syntax_errors)
  271.                 return(1);
  272.             $this->SetPositionedWarning('it was used an unencoded 8 bit character'$p);
  273.         }
  274.         $q_text $c;
  275.         ++$p;
  276.         return(1);
  277.     }
  278.  
  279.     Function ParseQuotedPair(&$p&$quoted_pair)
  280.     {
  281.         $quoted_pair null;
  282.         $v $this->v;
  283.         $l strlen($v);
  284.         if($p+$l
  285.         && !strcmp($v[$p]'\\')
  286.         && GetType(strchr("\r\n\0"$c $v[$p 1])) != 'string'
  287.         && Ord($c)<128)
  288.         {
  289.             $quoted_pair $c;
  290.             $p += 2;
  291.         }
  292.         return(1);
  293.     }
  294.  
  295.     Function ParseCContent(&$p&$c_content)
  296.     {
  297.         $c_content null;
  298.         $c $p;
  299.         if(!$this->ParseQuotedPair($c$content))
  300.             return(0);
  301.         if(!IsSet($content))
  302.         {
  303.             if(!$this->ParseCText($c$content))
  304.                 return(0);
  305.             if(!IsSet($content))
  306.             {
  307.                 if(!$this->ParseComment($c$content))
  308.                     return(0);
  309.                 if(!IsSet($content))
  310.                     return(1);
  311.             }
  312.         }
  313.         $c_content $content;
  314.         $p $c;
  315.         return(1);
  316.     }
  317.  
  318.     Function SkipWhiteSpace(&$p)
  319.     {
  320.         $v $this->v;
  321.         $l strlen($v);
  322.         for(;$p<$l++$p)
  323.         {
  324.             switch($v[$p])
  325.             {
  326.                 case ' ':
  327.                 case "\n":
  328.                 case "\r":
  329.                 case "\t":
  330.                     break;
  331.                 default:
  332.                     return(1);
  333.             }
  334.         }
  335.         return(1);
  336.     }
  337.  
  338.     Function ParseComment(&$p&$comment)
  339.     {
  340.         $comment null;
  341.         $v $this->v;
  342.         $l strlen($v);
  343.         $c $p;
  344.         if($c >= $l
  345.         || strcmp($v[$c]'('))
  346.             return(1);
  347.         ++$c;
  348.         for($c $l;)
  349.         {
  350.             if(!$this->SkipWhiteSpace($c))
  351.                 return(0);
  352.             if(!$this->ParseCContent($c$c_content))
  353.                 return(0);
  354.             if(!IsSet($c_content))
  355.                 break;
  356.         }
  357.         if(!$this->SkipWhiteSpace($c))
  358.             return(0);
  359.         if($c >= $l
  360.         || strcmp($v[$c]')'))
  361.             return(1);
  362.         ++$c;
  363.         $comment substr($v$p$c $p);
  364.         $p $c;
  365.         return(1);
  366.     }
  367.  
  368.     Function SkipCommentWhiteSpace(&$p)
  369.     {
  370.         $v $this->v;
  371.         $l strlen($v);
  372.         for(;$p<$l;)
  373.         {
  374.             switch($v[$p])
  375.             {
  376.                 case ' ':
  377.                 case "\n":
  378.                 case "\r":
  379.                 case "\t":
  380.                     ++$p;
  381.                     break;
  382.                 case '(':
  383.                     if(!$this->ParseComment($p$comment))
  384.                         return(0);
  385.                 default:
  386.                     return(1);
  387.             }
  388.         }
  389.         return(1);
  390.     }
  391.  
  392.     Function ParseQContent(&$p&$q_content)
  393.     {
  394.         $q_content null;
  395.         $q $p;
  396.         if(!$this->ParseQuotedPair($q$content))
  397.             return(0);
  398.         if(!IsSet($content))
  399.         {
  400.             if(!$this->ParseQText($q$content))
  401.                 return(0);
  402.             if(!IsSet($content))
  403.                 return(1);
  404.         }
  405.         $q_content $content;
  406.         $p $q;
  407.         return(1);
  408.     }
  409.  
  410.     Function ParseAtom(&$p&$atom$dot)
  411.     {
  412.         $atom null;
  413.         $v $this->v;
  414.         $l strlen($v);
  415.         $a $p;
  416.         if(!$this->SkipCommentWhiteSpace($a))
  417.             return(0);
  418.         for($s $a;$a $l;)
  419.         {
  420.             if(preg_match('/^([-'.($dot '.' '').'A-Za-z0-9!#$&\'*+\\/=?^_{|}~]+)/'substr($this->v$a)$m))
  421.                 $a += strlen($m[1]);
  422.             elseif(Ord($v[$a]128)
  423.                 break;
  424.             elseif(!$this->SetPositionedWarning('it was used an unencoded 8 bit character'$a))
  425.                 return(0);
  426.             else
  427.                 ++$a;
  428.         }
  429.         if($s == $a)
  430.             return(1);
  431.         if(!$this->SkipCommentWhiteSpace($a))
  432.             return(0);
  433.         $atom substr($this->v$p$a $p);
  434.         $p $a;
  435.         return(1);
  436.     }
  437.  
  438.     Function ParseQuotedString(&$p&$quoted_string)
  439.     {
  440.         $quoted_string null;
  441.         $v $this->v;
  442.         $l strlen($v);
  443.         $s $p;
  444.         if(!$this->SkipCommentWhiteSpace($s))
  445.             return(0);
  446.         if($s >= $l
  447.         || strcmp($v[$s]'"'))
  448.             return(1);
  449.         ++$s;
  450.         for($string '';$s $l;)
  451.         {
  452.             $w $s;
  453.             if(!$this->SkipWhiteSpace($s))
  454.                 return(0);
  455.             if($w != $s)
  456.                 $string .= substr($v$w$s $w);
  457.             if(!$this->ParseQContent($s$q_content))
  458.                 return(0);
  459.             if(!IsSet($q_content))
  460.                 break;
  461.             $string .= $q_content;
  462.         }
  463.             $w $s;
  464.         if(!$this->SkipWhiteSpace($s))
  465.             return(0);
  466.         if($w != $s)
  467.             $string .= substr($v$w$s $w);
  468.         if($s >= $l
  469.         || strcmp($v[$s]'"'))
  470.             return(1);
  471.         ++$s;
  472.         if(!$this->SkipCommentWhiteSpace($s))
  473.             return(0);
  474.         $quoted_string $string;
  475.         $p $s;
  476.         return(1);
  477.     }
  478.  
  479.     Function ParseWord(&$p&$word)
  480.     {
  481.         $word null;
  482.         if(!$this->ParseQuotedString($p$word))
  483.             return(0);
  484.         if(IsSet($word))
  485.             return(1);
  486.         if(!$this->ParseAtom($p$word0))
  487.             return(0);
  488.         return(1);
  489.     }
  490.  
  491.     Function ParseObsPhrase(&$p&$obs_phrase)
  492.     {
  493.         $obs_phrase null;
  494.         $v $this->v;
  495.         $l strlen($v);
  496.         $ph $p;
  497.         if(!$this->ParseWord($ph$word))
  498.             return(0);
  499.         $string $word;
  500.         for(;;)
  501.         {
  502.             if(!$this->ParseWord($ph$word))
  503.                 return(0);
  504.             if(IsSet($word))
  505.             {
  506.                 $string .= $word;
  507.                 continue;
  508.             }
  509.             $w $ph;
  510.             if(!$this->SkipCommentWhiteSpace($ph))
  511.                 return(0);
  512.             if($w != $ph)
  513.             {
  514.                 $string .= substr($v$w$ph $w);
  515.                 continue;
  516.             }
  517.             if($ph >= $l
  518.             || strcmp($v[$ph]'.'))
  519.                 break;
  520.             $string .= '.';
  521.             ++$ph;
  522.         }
  523.         $obs_phrase $string;
  524.         $p $ph;
  525.         return(1);
  526.     }
  527.  
  528.     Function ParsePhrase(&$p&$phrase)
  529.     {
  530.         $phrase null;
  531.         if(!$this->ParseObsPhrase($p$phrase))
  532.             return(0);
  533.         if(IsSet($phrase))
  534.             return(1);
  535.         $ph $p;
  536.         if(!$this->ParseWord($ph$word))
  537.             return(0);
  538.         $string $word;
  539.         for(;;)
  540.         {
  541.             if(!$this->ParseWord($ph$word))
  542.                 return(0);
  543.             if(!IsSet($word))
  544.                 break;
  545.             $string .= $word;
  546.         }
  547.         $phrase $string;
  548.         $p $ph;
  549.         return(1);
  550.     }
  551.  
  552.     Function ParseAddrSpec(&$p&$addr_spec)
  553.     {
  554.         $addr_spec null;
  555.         $v $this->v;
  556.         $l strlen($v);
  557.         $a $p;
  558.         if(!$this->ParseQuotedString($a$local_part))
  559.             return(0);
  560.         if(!IsSet($local_part))
  561.         {
  562.             if(!$this->ParseAtom($a$local_part1))
  563.                 return(0);
  564.             $local_part trim($local_part);
  565.         }
  566.         if($a >= $l
  567.         || strcmp($v[$a]'@'))
  568.             return(1);
  569.         ++$a;
  570.         if(!$this->ParseAtom($a$domain1))
  571.             return(0);
  572.         if(!IsSet($domain))
  573.             return(1);
  574.         $addr_spec $local_part.'@'.$domain;
  575.         $p $a;
  576.         return(1);
  577.     }
  578.  
  579.     Function ParseAngleAddr(&$p&$addr)
  580.     {
  581.         $addr null;
  582.         $v $this->v;
  583.         $l strlen($v);
  584.         $a $p;
  585.         if(!$this->SkipCommentWhiteSpace($a))
  586.             return(0);
  587.         if($a >= $l
  588.         || strcmp($v[$a]'<'))
  589.             return(1);
  590.         ++$a;
  591.         if(!$this->ParseAddrSpec($a$addr_spec))
  592.             return(0);
  593.         if($a >= $l
  594.         || strcmp($v[$a]'>'))
  595.             return(1);
  596.         ++$a;
  597.         if(!$this->SkipCommentWhiteSpace($a))
  598.             return(0);
  599.         $addr $addr_spec;
  600.         $p $a;
  601.         return(1);
  602.     }
  603.  
  604.     Function ParseNameAddr(&$p&$address)
  605.     {
  606.         $address null;
  607.         $a $p;
  608.         if(!$this->ParsePhrase($a$display_name))
  609.             return(0);
  610.         if(!$this->ParseAngleAddr($a$addr))
  611.             return(0);
  612.         if(!IsSet($addr))
  613.             return(1);
  614.         $address array('address'=>$addr);
  615.         if(IsSet($display_name))
  616.         {
  617.             if(!$this->QDecode($p$display_name$encoding))
  618.                 return(0);
  619.             $address['name'trim($display_name);
  620.             if(IsSet($encoding))
  621.                 $address['encoding'$encoding;
  622.         }
  623.         $p $a;
  624.         return(1);
  625.     }
  626.  
  627.     Function ParseAddrNameAddr(&$p&$address)
  628.     {
  629.         $address null;
  630.         $a $p;
  631.         if(!$this->ParseAddrSpec($a$display_name))
  632.             return(0);
  633.         if(!IsSet($display_name))
  634.             return(1);
  635.         if(!$this->ParseAngleAddr($a$addr))
  636.             return(0);
  637.         if(!IsSet($addr))
  638.             return(1);
  639.         if(!$this->QDecode($p$display_name$encoding))
  640.             return(0);
  641.         $address array(
  642.             'address'=>$addr,
  643.             'name' => trim($display_name)
  644.         );
  645.         if(IsSet($encoding))
  646.             $address['encoding'$encoding;
  647.         $p $a;
  648.         return(1);
  649.     }
  650.  
  651.     Function ParseMailbox(&$p&$address)
  652.     {
  653.         $address null;
  654.         if($this->ignore_syntax_errors)
  655.         {
  656.             $a $p;
  657.             if(!$this->ParseAddrNameAddr($p$address))
  658.                 return(0);
  659.             if(IsSet($address))
  660.                 return($this->SetPositionedWarning('it was an unquoted address as name'$a));
  661.         }
  662.         if(!$this->ParseNameAddr($p$address))
  663.             return(0);
  664.         if(IsSet($address))
  665.             return(1);
  666.         if(!$this->ParseAddrSpec($p$addr_spec))
  667.             return(0);
  668.         if(IsSet($addr_spec))
  669.             $address array('address'=>$addr_spec);
  670.         return(1);
  671.     }
  672.  
  673.     Function ParseMailboxGroup(&$p&$mailbox_group)
  674.     {
  675.         $v $this->v;
  676.         $l strlen($v);
  677.         $g $p;
  678.         if(!$this->ParseMailbox($g$address))
  679.             return(0);
  680.         if(!IsSet($address))
  681.             return(1);
  682.         $addresses array($address);
  683.         for(;$g $l;)
  684.         {
  685.             if(strcmp($v[$g]','))
  686.                 break;
  687.             ++$g;
  688.             if(!$this->ParseMailbox($g$address))
  689.                 return(0);
  690.             if(!IsSet($address))
  691.                 return(1);
  692.             $addresses[$address;
  693.         }
  694.         $mailbox_group $addresses;
  695.         $p $g;
  696.         return(1);
  697.     }
  698.  
  699.     Function ParseGroup(&$p&$address)
  700.     {
  701.         $address null;
  702.         $v $this->v;
  703.         $l strlen($v);
  704.         $g $p;
  705.         if(!$this->ParsePhrase($g$display_name))
  706.             return(0);
  707.         if(!IsSet($display_name)
  708.         || $g >= $l
  709.         || strcmp($v[$g]':'))
  710.             return(1);
  711.         ++$g;
  712.         if(!$this->ParseMailboxGroup($g$mailbox_group))
  713.             return(0);
  714.         if(!IsSet($mailbox_group))
  715.         {
  716.             if(!$this->SkipCommentWhiteSpace($g))
  717.                 return(0);
  718.             $mailbox_group array();
  719.         }
  720.         if($g >= $l
  721.         || strcmp($v[$g]';'))
  722.             return(1);
  723.         $c = ++$g;
  724.         if($this->SkipCommentWhiteSpace($g)
  725.         && $g $c
  726.         && !$this->SetPositionedWarning('it were used invalid comments after a group of addresses'$c))
  727.             return(0);
  728.         if(!$this->QDecode($p$display_name$encoding))
  729.             return(0);
  730.         $address array(
  731.             'name'=>$display_name,
  732.             'group'=>$mailbox_group
  733.         );
  734.         if(IsSet($encoding))
  735.             $address['encoding'$encoding;
  736.         $p $g;
  737.         return(1);
  738.     }
  739.  
  740.     Function ParseAddress(&$p&$address)
  741.     {
  742.         $address null;
  743.         if(!$this->ParseGroup($p$address))
  744.             return(0);
  745.         if(!IsSet($address))
  746.         {
  747.             if(!$this->ParseMailbox($p$address))
  748.                 return(0);
  749.         }
  750.         return(1);
  751.     }
  752.  
  753.     /* Public functions */
  754.  
  755. /*
  756. {metadocument}
  757.     <function>
  758.         <name>ParseAddressList</name>
  759.         <type>BOOLEAN</type>
  760.         <documentation>
  761.             <purpose>Parse and extract e-mail addresses eventually from headers
  762.                 of an e-mail message.</purpose>
  763.             <usage>Pass a string value with a list of e-mail addresses to the
  764.                 <argumentlink>
  765.                     <function>ParseAddressList</function>
  766.                     <argument>value</argument>
  767.                 </argumentlink>. The <argumentlink>
  768.                     <function>ParseAddressList</function>
  769.                     <argument>addresses</argument>
  770.                 </argumentlink> returns the list of e-mail addresses found.</usage>
  771.             <returnvalue>This function returns <booleanvalue>1</booleanvalue> if
  772.                 the specified value is parsed successfully. Otherwise,
  773.                 check the variables <variablelink>error</variablelink> and
  774.                 <variablelink>error_position</variablelink> to determine what
  775.                 error occurred and the relevant value position.</returnvalue>
  776.         </documentation>
  777.         <argument>
  778.             <name>value</name>
  779.             <type>STRING</type>
  780.             <documentation>
  781.                 <purpose>String with a list of e-mail addresses to parse.</purpose>
  782.             </documentation>
  783.         </argument>
  784.         <argument>
  785.             <name>addresses</name>
  786.             <type>ARRAY</type>
  787.             <out />
  788.             <documentation>
  789.                 <purpose>Return the list of parsed e-mail addresses.
  790.                     Each entry in the list is an associative array.<paragraphbreak />
  791.                     For normal addresses, this associative array has the entry
  792.                     <stringvalue>address</stringvalue> set to the e-mail address.
  793.                     If the address has an associated name, it is stored in the
  794.                     entry <stringvalue>name</stringvalue>.<paragraphbreak />
  795.                     For address groups, there is the entry
  796.                     <stringvalue>name</stringvalue>.
  797.                     The group addresses list are stored in the entry
  798.                     <stringvalue>group</stringvalue> as an array. The structure of
  799.                     the group addresses list array is the same as this addresses
  800.                     list array argument.</purpose>
  801.             </documentation>
  802.         </argument>
  803.         <do>
  804. {/metadocument}
  805. */
  806.     Function ParseAddressList($value&$addresses)
  807.     {
  808.         $this->warnings = array();
  809.         $addresses array();
  810.         $this->v = $v $value;
  811.         $l strlen($v);
  812.         $p 0;
  813.         if(!$this->ParseAddress($p$address))
  814.             return(0);
  815.         if(!IsSet($address))
  816.             return($this->SetPositionedError('it was not specified a valid address'$p));
  817.         $addresses[$address;
  818.         while($p $l)
  819.         {
  820.             if(strcmp($v[$p]','))
  821.                 return($this->SetPositionedError('multiple addresses must be separated by commas: '$p));
  822.             ++$p;
  823.             if(!$this->ParseAddress($p$address))
  824.                 return(0);
  825.             if(!IsSet($address))
  826.                 return($this->SetPositionedError('it was not specified a valid address after comma'$p));
  827.             $addresses[$address;
  828.         }
  829.         return(1);
  830.     }
  831. /*
  832. {metadocument}
  833.         </do>
  834.     </function>
  835. {/metadocument}
  836. */
  837.  
  838. };
  839.  
  840. /*
  841.  
  842. {metadocument}
  843. </class>
  844. {/metadocument}
  845.  
  846. */
  847.  
  848. ?>

Documentation generated on Sat, 06 Mar 2010 03:57:16 +0100 by phpDocumentor 1.4.2. This site is hosted and maintained by Daniel HAHLER (Contact).