Masato's Fix
[squirrelmail.git] / plugins / abook_take / setup.php
index 7659d814e0199205bbbfa99031f82ddd4ef33fbd..1130d9241e39649c81bca9203783eb5a4fa043c0 100755 (executable)
@@ -1,5 +1,10 @@
 <?php
 
+/* Path for SquirrelMail required files. */
+define('SM_PATH','../../');
+
+/* SquirrelMail required files. */
+require_once(SM_PATH . 'functions/url_parser.php');
 
 /* Address Take -- steals addresses from incoming email messages.  Searches
    the To, Cc, From and Reply-To headers, also searches the body of the
@@ -18,45 +23,36 @@ function squirrelmail_plugin_init_abook_take()
 
 function valid_email ($email, $verify)
 {
-  global $abook_take_verify;
+  global $abook_take_verify, $Email_RegExp_Match;
   
-  if (eregi("^[0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-wyz][a-z](g|l|m|pa|t|u|v)?$", 
-    $email, $check)) 
-  {
-    if (! $verify)
-    {
-      return TRUE;
-    }
+  if (! eregi('^' . $Email_RegExp_Match . '$', $email))
+    return false;
     
-    if (checkdnsrr(substr(strstr($email, '@'), 1), 'ANY'))
-    {
-      return TRUE;
-    }
-  }
-  return FALSE;
+  if (! $verify)
+    return true;
+
+  if (! checkdnsrr(substr(strstr($email, '@'), 1), 'ANY'))
+    return false;
+
+  return true;
 }
 
 
 function abook_take_read_string($str)
 {
-  global $abook_found_email;
+  global $abook_found_email, $Email_RegExp_Match;
   
-  $str = eregi_replace('[^-0-9a-z_.@]', ' ', $str);
-  $str = eregi_replace('[[:space:]]+', ' ', $str);
-  $chances = split(' ', $str);
-  $i = 0;
-  while ($i < count($chances))
+
+  while (eregi('(' . $Email_RegExp_Match . ')', $str, $hits))
   {
-    if (valid_email($chances[$i], 0) && 
-        ! isset($abook_found_email[$chances[$i]]))
-    {
-      //echo '<option value="' . $chances[$i] . '">' . $chances[$i] . 
-      //  '</option>' . "\n";
-      echo "<input type=\"hidden\" name=\"email[]\" value=\"$chances[$i]\">\n";
-      $abook_found_email[$chances[$i]] = 1;
-    }
-    $i ++;
+      $str = substr(strstr($str, $hits[0]), strlen($hits[0]));
+      if (! isset($abook_found_email[$hits[0]]))
+      {
+          echo "<input type=\"hidden\" name=\"email[]\" value=\"$hits[0]\">\n";
+         $abook_found_email[$hits[0]] = 1;
+      }
   }
+  return;
 }
 
 
@@ -79,21 +75,14 @@ function abook_take_read()
   if ($abook_take_hide)
     return;
     
-  ?>
-  <FORM ACTION="../plugins/abook_take/take.php" METHOD=POST>
-  <table align="<?PHP 
-      echo $abook_take_location;
-  ?>" cellpadding=3 cellspacing=0 border=0 bgcolor="<?PHP 
-      echo $color[10] 
-  ?>">
-    <tr>
-      <td>
-        <table cellpadding=2 cellspacing=1 border=0 bgcolor="<?PHP 
-            echo $color[5] 
-        ?>">
-          <tr>
-            <td>
-            <?PHP
+  echo '<form action="../plugins/abook_take/take.php" method="post">' . "\n" .
+  html_tag( 'table', '', $abook_take_location, $color[10], 'cellpadding="3" cellspacing="0" border="0"' ) .
+      html_tag( 'tr' ) .
+          html_tag( 'td', '', 'left' ) .
+              html_tag( 'table', '', '', $color[5], 'cellpadding="2" cellspacing="1" border="0"' ) .
+                  html_tag( 'tr' ) .
+                      html_tag( 'td' );
+
               abook_take_read_string($message->header->from);
               abook_take_read_array($message->header->cc);
               abook_take_read_array($message->header->reply_to);
@@ -102,7 +91,7 @@ function abook_take_read()
 
               $new_body = $body;
               $pos = strpos($new_body, 
-                '">Download this as a file</A></CENTER><BR></SMALL>');
+                '">' . _("Download this as a file") . '</a></center><br></small>');
               if (is_int($pos))
               {
                 $new_body = substr($new_body, 0, $pos);
@@ -119,8 +108,9 @@ function abook_take_read()
               $new_body = strtr($new_body, "\n", ' ');
     
               abook_take_read_string($body);
+            
+              echo '<input type="submit" value="' . _("Take Address") . '">';
             ?>
-              <INPUT TYPE="submit" VALUE="Take Address">
             </td>
           </tr>
         </table>
@@ -149,30 +139,31 @@ function abook_take_options()
 {
   global $abook_take_location, $abook_take_hide, $abook_take_verify;
   
-  ?><tr><td align=right nowrap valign="top">Address Book Take:</td>
-    <td><select name="abook_take_abook_take_location">
-    <option value="left"<?PHP
-      if ($abook_take_location == 'left')
-        echo ' SELECTED';
-    ?>>Left aligned</option>
-    <option value="center"<?PHP
-      if ($abook_take_location == 'center')
-        echo ' SELECTED';
-    ?>>Centered</option>
-    <option value="right"<?PHP
-      if ($abook_take_location == 'right')
-        echo ' SELECTED';
-    ?>>Right aligned</option>
-  </select> on the Read screen<br>
-  <input type=checkbox name="abook_take_abook_take_hide"<?PHP
-      if ($abook_take_hide)
-        echo ' CHECKED';
-    ?>> Hide the box<br>
-  <input type=checkbox name="abook_take_abook_take_verify"<?PHP
-      if ($abook_take_verify)
-        echo ' CHECKED';
-    ?>> Try to verify addresses
-  </td></tr><?PHP
+  echo html_tag( 'tr' ) .
+      html_tag( 'td', _("Address Book Take") . ':', 'right', '', 'nowrap valign="top"' ) .
+      html_tag( 'td', '', 'left' ) .
+          '<select name="abook_take_abook_take_location">' .
+          '<option value="left"';
+          if ($abook_take_location == 'left')
+            echo ' selected';
+          echo '>' . _("Left aligned") . '</option>' .
+          '<option value="center"';
+          if ($abook_take_location == 'center')
+            echo ' selected';
+          echo '>' . _("Centered") . '</option>' .
+          '<option value="right"';
+          if ($abook_take_location == 'right')
+            echo ' selected';
+          echo '>' . _("Right aligned") . '</option>' .
+          '</select> ' . _("on the Read screen") .'<br>' .
+          '<input type="checkbox" name="abook_take_abook_take_hide"';
+          if ($abook_take_hide)
+            echo ' checked';
+          echo '>&nbsp;' . _("Hide the box") . '<br>' .
+          '<input type=checkbox name="abook_take_abook_take_verify"';
+          if ($abook_take_verify)
+            echo ' checked';
+          echo '>&nbsp;' . _("Try to verify addresses") . '</td></tr>';
 }