updated/moved plugin from plugins/abook_take to squirrelmail/plugins/abook_take
authorcentaurix <centaurix@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Thu, 27 Jun 2002 10:37:57 +0000 (10:37 +0000)
committercentaurix <centaurix@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Thu, 27 Jun 2002 10:37:57 +0000 (10:37 +0000)
fixed bug [ 574135 ]

git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@3019 7612ce4b-ef26-0410-bec9-ea0150e637f0

plugins/abook_take/INSTALL [new file with mode: 0644]
plugins/abook_take/README [new file with mode: 0755]
plugins/abook_take/setup.php [new file with mode: 0755]
plugins/abook_take/take.php [new file with mode: 0644]

diff --git a/plugins/abook_take/INSTALL b/plugins/abook_take/INSTALL
new file mode 100644 (file)
index 0000000..af088c6
--- /dev/null
@@ -0,0 +1,16 @@
+Installing Plugins
+==================
+Simply untar the file in the plugins directory, and make sure it is
+in its own directory, and that the name of the directory is the name
+of the plugin.  Example below uses "plug_demo" as the name of the 
+plugin:
+
+  $ cd plugins
+  $ tar -zxvf /usr/archives/plug_demo.tar.gz
+
+Then go to your config directory and run conf.pl.  Choose option
+8 and add the plugin (+).  Save and exit, then that should be all
+if the plugin was made correctly.  :)
+
+  $ cd ../config
+  $ ./conf.pl
diff --git a/plugins/abook_take/README b/plugins/abook_take/README
new file mode 100755 (executable)
index 0000000..0f237cb
--- /dev/null
@@ -0,0 +1,66 @@
+Address Book Take -- Version 1.3
+
+If you would like to add the sender of a message you're reading to your
+address book quickly and easily without cutting and pasting, then this
+plugin simplifies the process.  It scans the mail message you're reading
+for any email address and lets you add it with a quick form.
+
+
+Features
+========
+
+* Saves you the need to Cut & Paste
+* Steals from the To, From, Reply-To, and CC fields
+* Steals from the body of the message
+* Address verification (pretty good)
+
+
+Description
+===========
+
+By pulling down a list and selecting the address you want to add, you
+are then presented with a familiar Add to Personal Address Book screen.
+By filling out this form, you will then add the email address to your
+personal address book.
+
+The user can decide if the box is shown, where it is shown on the bottom
+of the Read screen, and whether or not to attempt to verify that the
+address works.
+
+When trying to verify if the address works, it checks to see if the host
+has any DNS record available.  Usually this will work.
+
+
+Future Work
+===========
+
+* Maybe grab the name, if available
+* Search more headers (when they become available)
+* Steal from the body of the message directly (when possible)
+* When new domains are added, update the email verification function
+
+
+Installation
+============
+
+As with other plugins, just uncompress the archive in the plugins
+directory, go back to the main directory, run configure and add the plugin.
+
+Questions/comments/flames/etc can be sent to
+    Tyler Akins <fidian@tiny.net>
+
+
+Changes
+=======
+1.2 -> 1.3
+  * Removed warning created when all warning were enabled in PHP
+  
+1.1 -> 1.2
+  * Fixed some HTML
+  * Fixed how message body is grabbed
+  
+1.0 -> 1.1
+  * Fixed where a color was hardcoded
+  * Moved address <select> to take.php
+  * Moved verification to take.php
+  * Added & changed preferences
diff --git a/plugins/abook_take/setup.php b/plugins/abook_take/setup.php
new file mode 100755 (executable)
index 0000000..7659d81
--- /dev/null
@@ -0,0 +1,215 @@
+<?php
+
+
+/* Address Take -- steals addresses from incoming email messages.  Searches
+   the To, Cc, From and Reply-To headers, also searches the body of the
+   message.  */
+
+function squirrelmail_plugin_init_abook_take()
+{
+  global $squirrelmail_plugin_hooks;
+  
+  $squirrelmail_plugin_hooks['read_body_bottom']['abook_take'] = 'abook_take_read';
+  $squirrelmail_plugin_hooks['loading_prefs']['abook_take'] = 'abook_take_pref';
+  $squirrelmail_plugin_hooks['options_display_inside']['abook_take'] = 'abook_take_options';
+  $squirrelmail_plugin_hooks['options_display_save']['abook_take'] = 'abook_take_save';
+}
+
+
+function valid_email ($email, $verify)
+{
+  global $abook_take_verify;
+  
+  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 (checkdnsrr(substr(strstr($email, '@'), 1), 'ANY'))
+    {
+      return TRUE;
+    }
+  }
+  return FALSE;
+}
+
+
+function abook_take_read_string($str)
+{
+  global $abook_found_email;
+  
+  $str = eregi_replace('[^-0-9a-z_.@]', ' ', $str);
+  $str = eregi_replace('[[:space:]]+', ' ', $str);
+  $chances = split(' ', $str);
+  $i = 0;
+  while ($i < count($chances))
+  {
+    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 ++;
+  }
+}
+
+
+function abook_take_read_array($array)
+{
+  $i = 0;
+  while ($i < count($array))
+  {
+    abook_take_read_string($array[$i]);
+    $i ++;
+  }
+}
+
+
+function abook_take_read()
+{
+  global $color, $abook_take_location;
+  global $body, $abook_take_hide, $message, $imapConnection;
+
+  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
+              abook_take_read_string($message->header->from);
+              abook_take_read_array($message->header->cc);
+              abook_take_read_array($message->header->reply_to);
+              abook_take_read_array($message->header->to);
+
+
+              $new_body = $body;
+              $pos = strpos($new_body, 
+                '">Download this as a file</A></CENTER><BR></SMALL>');
+              if (is_int($pos))
+              {
+                $new_body = substr($new_body, 0, $pos);
+              }
+                     
+              $trans = get_html_translation_table(HTML_ENTITIES);
+              $trans[' '] = '&nbsp;';
+              $trans = array_flip($trans);
+              $new_body = strtr($new_body, $trans);
+
+              $new_body = urldecode($new_body);
+              $new_body = strip_tags($new_body);
+              
+              $new_body = strtr($new_body, "\n", ' ');
+    
+              abook_take_read_string($body);
+            ?>
+              <INPUT TYPE="submit" VALUE="Take Address">
+            </td>
+          </tr>
+        </table>
+      </td>
+    </tr>
+  </table>
+  </form>
+  <?PHP
+}
+
+function abook_take_pref()
+{ 
+  global $username, $data_dir;
+  global $abook_take_hide, $abook_take_location, $abook_take_verify;
+
+  $abook_take_location = getPref($data_dir, $username, 'abook_take_location');
+  if ($abook_take_location == '')
+    $abook_take_location = 'center';
+    
+  $abook_take_hide = getPref($data_dir, $username, 'abook_take_hide');
+  $abook_take_verify = getPref($data_dir, $username, 'abook_take_verify');
+}
+
+
+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
+}
+
+
+function abook_take_save()
+{
+  global $username, $data_dir;
+  global $abook_take_abook_take_location;
+  global $abook_take_abook_take_hide;
+  global $abook_take_abook_take_verify;
+  
+  
+  if (isset($abook_take_abook_take_location)) 
+  {
+    setPref($data_dir, $username, 'abook_take_location', $abook_take_abook_take_location);
+  } 
+  else 
+  {
+    setPref($data_dir, $username, 'abook_take_location', 'center');
+  }
+
+  if (isset($abook_take_abook_take_hide)) 
+  {
+    setPref($data_dir, $username, 'abook_take_hide', '1');
+  } 
+  else 
+  {
+    setPref($data_dir, $username, 'abook_take_hide', '');
+  }
+
+  if (isset($abook_take_abook_take_verify)) 
+  {
+    setPref($data_dir, $username, 'abook_take_verify', '1');
+  } 
+  else 
+  {
+    setPref($data_dir, $username, 'abook_take_verify', '');
+  }
+}
+
+?>
diff --git a/plugins/abook_take/take.php b/plugins/abook_take/take.php
new file mode 100644 (file)
index 0000000..a72c6fa
--- /dev/null
@@ -0,0 +1,94 @@
+<?php /* Modified at 6 places by ri_once */ ?>
+<?php
+  /**
+   **  take.php
+   **  
+   **  Adds a "taken" address to the address book.  Takes addresses from
+   **   incoming mail -- the body, To, From, Cc, or Reply-To.
+   **/
+
+   session_start();
+
+   if(!isset($username)) {
+      echo "You need a valid user and password to access this page!";
+      exit;
+   }
+
+   chdir("..");
+   if (!isset($config_php))
+      /* '_once' Added by ri_once */ include_once("../config/config.php");
+   if (!isset($i18n_php))
+      /* '_once' Added by ri_once */ include_once("../functions/i18n.php");
+   if (!isset($page_header_php))
+      /* '_once' Added by ri_once */ include_once("../functions/page_header.php");
+   if (!isset($addressbook_php))
+      /* '_once' Added by ri_once */ include_once("../functions/addressbook.php");
+   if (!isset($strings_php))
+      /* '_once' Added by ri_once */ include_once("../functions/strings.php");
+
+   /* '_once' Added by ri_once */ include_once("../src/load_prefs.php");
+   
+   displayPageHeader($color, "None");
+   
+   $abook_take_verify = getPref($data_dir, $username, 'abook_take_verify');
+
+?>
+<FORM ACTION="../../src/addressbook.php" NAME=f_add METHOD="POST">
+<TABLE WIDTH=100% COLS=1 ALIGN=CENTER>
+<TR><TH BGCOLOR="<?PHP 
+    echo $color[0]; 
+?>" ALIGN=CENTER><?PHP
+   // open address book, trash errors, skip LDAP
+   $abook = addressbook_init(false, true);
+   printf(_("Add to %s"), $abook->localbackendname);
+?></TH></TR>
+</TABLE>
+<TABLE BORDER=0 CELLPADDING=1 COLS=2 WIDTH="90%" ALIGN=center>
+<?PHP
+  $name = 'addaddr';
+  
+  printf("<TR><TD WIDTH=50 BGCOLOR=\"$color[4]\" ALIGN=RIGHT>%s:</TD>",
+     _("Nickname"));
+  printf("<TD BGCOLOR=\"%s\" ALIGN=left>".
+     "<INPUT NAME=\"%s[nickname]\" SIZE=15 VALUE=\"\">".
+     "&nbsp;<SMALL>%s</SMALL></TD></TR>\n",
+     $color[4], $name, _("Must be unique"));
+  printf("<TR><TD WIDTH=50 BGCOLOR=\"$color[4]\" ALIGN=RIGHT>%s:</TD>",
+     _("E-mail address"));
+  
+  echo "<TD BGCOLOR=\"$color[4]\" ALIGN=left>\n";
+  echo '<select name="' . $name . "[email]\">\n";
+  foreach ($email as $Val)
+  {
+      if (valid_email($Val, $abook_take_verify))
+      {
+          echo '<option value="' . htmlspecialchars($Val) .
+              '">' . htmlspecialchars($Val) . "</option>\n";
+      }
+  }
+  echo "</select>\n";
+  
+  printf("<TR><TD WIDTH=50 BGCOLOR=\"$color[4]\" ALIGN=RIGHT>%s:</TD>",
+     _("First name"));
+  printf("<TD BGCOLOR=\"%s\" ALIGN=left>".
+     "<INPUT NAME=\"%s[firstname]\" SIZE=45 VALUE=\"\"></TD></TR>\n",
+     $color[4], $name);
+  printf("<TR><TD WIDTH=50 BGCOLOR=\"$color[4]\" ALIGN=RIGHT>%s:</TD>",
+     _("Last name"));
+  printf("<TD BGCOLOR=\"%s\" ALIGN=left>".
+     "<INPUT NAME=\"%s[lastname]\" SIZE=45 VALUE=\"\"></TD></TR>\n",
+     $color[4], $name);
+  printf("<TR><TD WIDTH=50 BGCOLOR=\"$color[4]\" ALIGN=RIGHT>%s:</TD>",
+     _("Additional info"));
+  printf("<TD BGCOLOR=\"%s\" ALIGN=left>".
+     "<INPUT NAME=\"%s[label]\" SIZE=45 VALUE=\"\"></TD></TR>\n",
+     $color[4], $name);
+
+  printf("<TR><TD COLSPAN=2 BGCOLOR=\"%s\" ALIGN=center>\n".
+     "<INPUT TYPE=submit NAME=\"%s[SUBMIT]\" VALUE=\"%s\"></TD></TR>\n",
+     $color[4], $name, _("Add address"));
+
+      print "</TABLE>\n";
+?>
+</FORM></BODY>
+</HTML>