Description: <short summary of the patch>
 TODO: Put a short summary on the line above and replace this paragraph
 with a longer explanation of this change. Complete the meta-information
 with other relevant fields (see below for details). To make it easier, the
 information below has been extracted from the changelog. Adjust it or drop
 it.
 .
 squirrelmail-abook-import-export (1.0-1) wheezy; urgency=low
 .
   * Initial release (Closes: #nnnn)  <nnnn is the bug number of your ITP>
Author: Jean-Denis Gebhardt <jean-denis.gebhardt@noris.net>

---
The information above should follow the Patch Tagging Guidelines, please
checkout http://dep.debian.net/deps/dep3/ to learn about the format. Here
are templates for supplementary fields that you might want to add:

Origin: <vendor|upstream|other>, <url of original patch>
Bug: <url in upstream bugtracker>
Bug-Debian: http://bugs.debian.org/<bugnumber>
Bug-Ubuntu: https://launchpad.net/bugs/<bugnumber>
Forwarded: <no|not-needed|url proving that it has been forwarded>
Reviewed-By: <name and email of someone who approved the patch>
Last-Update: <YYYY-MM-DD>

--- /dev/null
+++ squirrelmail-abook-import-export-1.0/Makefile
@@ -0,0 +1,5 @@
+build:
+
+install: build
+	mkdir -p ${DESTDIR}/usr/share/squirrelmail/plugins/
+	cp -a abook_import_export ${DESTDIR}/usr/share/squirrelmail/plugins/
--- /dev/null
+++ squirrelmail-abook-import-export-1.0/abook_import_export/functions.php
@@ -0,0 +1,38 @@
+<?php
+  /**
+   ** functions.php
+   **
+   **  Copyright (c) 1999-2000 The SquirrelMail development team
+   **  Licensed under the GNU GPL. For full terms see the file COPYING.
+   **
+   ** Uses standard plugin format to create a couple of forms to
+   ** enable import/export of CSV files to/from the address book.
+   **/
+
+   function create_plugin_form() {
+      global $color;
+
+?>
+<CENTER>
+<TABLE BGCOLOR=<?php print $color[0] ?> WIDTH="90%" BORDER="0" CELLPADDING="1" CELLSPACING="0" ALIGN="center">
+   <TR>
+      <!-- ----------------- begin csv import form --------------------- -->
+      <FORM ENCTYPE="multipart/form-data" ACTION="../plugins/abook_import_export/address_book_import.php" METHOD=POST>
+      <INPUT TYPE="hidden" NAME="max_file_size" value="5000">
+      <TD VALIGN="middle" ALIGN="right">Import CSV File:</TD>
+      <TD><INPUT NAME="smusercsv" TYPE="file"></TD>
+      <TD VALIGN="middle" ALIGN="left"><INPUT TYPE="submit" VALUE="Import CSV File"></TD>
+      </FORM>
+      <!-- ----------------- end csv import form  ---------------------- -->
+      <TD>&nbsp</TD>
+      <!-- ----------------- begin csv export form --------------------- -->
+      <FORM ENCTYPE="multipart/form-data" ACTION="../plugins/abook_import_export/address_book_export.php" METHOD=POST>
+      <TD VALIGN="middle" ALIGN="right"><INPUT TYPE="submit" VALUE="Export CSV File" READONLY></TD>
+      </FORM>
+      <!-- ----------------- end csv import form  ---------------------- -->
+  </TR>
+</TABLE>
+</CENTER>
+<?php
+   }
+?>
--- /dev/null
+++ squirrelmail-abook-import-export-1.0/abook_import_export/CHANGELOG
@@ -0,0 +1,15 @@
+Changes
+-------------------
+
+ 0.7: Major changes to the import function. Can now import from Outlook as
+      long as it has a "First Name", "Last Name", and "E-mail Address"
+      feild specified somewhere in the first row. Also changed
+      reordering functionality after the file has been uploaded and 
+      before the changes to the address book
+
+
+=========================================================================
+ 0.6: Fixes a bug with the export feature.  The username variable was not
+      being exported to that procedure and the download stream was not
+      opening correctly. 
+
--- /dev/null
+++ squirrelmail-abook-import-export-1.0/abook_import_export/INSTALL
@@ -0,0 +1,19 @@
+Installing the abook_import_export Plugin
+==================================
+
+1) Start with untaring the file into the plugins directory.
+Here is a example for the 0.1 version of the abie plugin.
+
+    $ cd plugins
+    $ tar -xzvf abook_import_export-0.1-1.4.0.tar.gz
+
+2) Then go to your config directory and run conf.pl.  Choose
+option 8 and move the plugin from the "Available Plugins"
+category to the "Installed Plugins" category.  Save and exit.
+
+    $ cd ../config/
+    $ ./conf.pl
+
+3) Log into SquirrelMail and goto 'Addresses' and at the bottom
+of the page will be the buttons for importing and exporting your
+address book.
--- /dev/null
+++ squirrelmail-abook-import-export-1.0/abook_import_export/README
@@ -0,0 +1,37 @@
+This file is to inform you of any bugs or issues related to using this plugin.
+
+GENERAL USE
+===========
+1. Sanity checks
+	
+	There still aren't a lot of sanity checks on the file that you upload. 
+	As of right now it will check to see if you uploaded an Outlook file or 
+	one that was downloaded from Squirrelmail. It will perform it's upload 
+	a little differently from each side. 
+
+
+Credit where Credit is due. 
+===========================
+
+	The original plugin that I made my updates to was Dustin Anders' 
+	abook_import_export plugin version 0.6 the Squirrelmail 1.4 version. The
+	plugin interface on the Address page is still the same, as well as the 
+	address_book_export.php, for the most part. There is one small change to 
+	use the hashed directory structure. The majority of my changes went into 
+	the address_book_import.php. There is still some of the original code, but 
+	not a whole lot. I moved where things are to make it easier to read and 
+	to write to.
+
+
+	I developed and tested this version of the plugin using PHP 4.1.1, Squirrelmail
+	1.4.0 and Outlook 2000 as the export file to test with. Please let me know 
+	if you find any bugs or issues, as well as enhancements and feature 
+	requests. 
+- Andy Brook <andyb@iserv.net>
+
+
+  Did some "under the cover" work, cleaned up some E_ALL errors, and updated
+  the plugin for 1.4+ compatability.
+- Christian Sauer <christian@endrun.org>
+
+
--- /dev/null
+++ squirrelmail-abook-import-export-1.0/abook_import_export/VERSION
@@ -0,0 +1,2 @@
+Addressbook Import-Export
+0.7
--- /dev/null
+++ squirrelmail-abook-import-export-1.0/abook_import_export/address_book_export.php
@@ -0,0 +1,31 @@
+<?php
+
+define('SM_PATH', '../../');
+require_once(SM_PATH . 'include/validate.php');
+include_once(SM_PATH . 'functions/addressbook.php');
+
+/*
+ * Main Code
+ *
+ */
+
+global $username;
+
+$abook = addressbook_init(true,true);
+$rows = $abook->list_addr();
+
+header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
+header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); 
+header("Cache-Control: no-store, no-cache, must-revalidate");
+header("Cache-Control: post-check=0, pre-check=0", false);
+header("Pragma: no-cache");
+
+header('Cache-control: private', false);
+header('Content-Type: application/CSV');
+header('Content-Disposition: attachment; filename="' . $username . '-addresses.csv"');
+
+foreach($rows as $row) {
+	echo implode(',', array_slice($row, 0, -2)) . "\n";
+}
+
+?>
--- /dev/null
+++ squirrelmail-abook-import-export-1.0/abook_import_export/address_book_import.php
@@ -0,0 +1,343 @@
+<?PHP
+
+  /**
+   **  address_book_import.php
+   **    
+   **  Copyright (c) 1999-2000 The SquirrelMail development team
+   **  Licensed under the GNU GPL. For full terms see the file COPYING.
+   **            
+   **    Import csv files for address book
+   **      This takes a comma delimited file uploaded from addressbook.php
+   **      and allows the user to rearrange the field order to better
+   **      fit the address book. A subset of data is manipulated to save time.
+   **
+   **   This was a part of the Squirrelmail source tree and is being ported
+   **   to a plugin.
+   **/
+
+   define( 'SM_PATH' , '../../');
+
+   require_once(SM_PATH . 'include/validate.php');
+   include_once(SM_PATH . 'functions/page_header.php');
+   include_once(SM_PATH . 'functions/addressbook.php');
+   include_once(SM_PATH . 'include/load_prefs.php');
+
+
+   // Local Variables
+   $errorstring = '';
+   $finish = '';
+   $csvmax = 0;
+   $key = 0;
+   $x = 0;
+   $row = 0;
+   $cols = 0;
+   $colspan = 0;
+   $c = 0;
+   $error = 0;
+   $reorg = array();
+   $selrow = '';
+
+   global $color;
+   
+    // Grab the needed variable
+   $finish = (isset($_POST['finish'])?$_POST['finish']:'');
+
+// Here we will split the script into finished and not finished parts 
+if (!$finish) {
+
+   displayPageHeader($color, "None");
+
+   // Check to make sure the user actually put a file in the upload file box. 
+   $smusercsv = $_FILES['smusercsv'];
+ 
+   if ($smusercsv['tmp_name'] == '' || $smusercsv['size'] == 0) {
+      echo '
+      <br><br>
+      <table align="center">
+      <tr>
+      <td>' . _("Please select a file for uploading.  You can do this by clicking on the browse button on the ") . '<a href="' . SM_PATH .  'src/addressbook.php">' . _("Address Book") . '</a> ' . _("page.") . '</td>
+      </tr>
+      </table>
+      </body>
+      </html>
+      ';
+
+      exit;
+   }
+
+   /**
+    ** Use file() to get the data from the php temp file into an array so 
+    ** that we don't have to save files on the server. 
+    **/
+
+   // These shouldn't be set at all at this point. 
+   $_SESSION['csvdata'] = array(); 
+   $_SESSION['csvorder'] = array();
+
+   $csvfile = @fopen($smusercsv['tmp_name'],"r");
+
+   if (!$csvfile) {
+     echo '
+     <br><br>
+     <table align="center">
+        <tr>
+           <td>' . _("Error, could not open address file.") . '</td>
+        </tr>
+     </table>
+     ';
+
+     exit;
+   }
+   
+   while ($csvarray = fgetcsv($csvfile,4096)) { 
+      // Let fgetcsv deal with splitting the line into it's parts. (I.E. it deals with quoted commas right. 
+      $temp = CSVProcess($csvarray);
+      
+      if (count($temp) >2) {
+         $_SESSION['csvdata'][$key] = $temp;
+         $key++;
+      }
+      elseif (isset($temp[0])) { 
+         //This means it returned an error
+         $errorstring .= $temp[0] . '<p>';
+      } 
+
+      // After this, the function was just doing some calculations, and returned without a problem.
+      if(count($csvarray) > $csvmax) {
+         $csvmax = count($csvarray);
+      }
+   }
+
+   unset($_SESSION['csvorder']);
+
+   echo '
+   <FORM METHOD="post" action="' . $PHP_SELF . '">
+   <INPUT TYPE="submit" NAME="finish" VALUE="Finish" TABINDEX="4">
+   <CENTER><TABLE WIDTH="95%" FRAME="void" CELLSPACING="1">
+   ';    // user's data table
+
+   // Here I will create the headers that I want.
+   echo '
+   <TR BGCOLOR="' . $color[9] . '" ALIGN="center">
+   <TD WIDTH="1">' .  _("Omit") . '</TD>
+   '; // The Omit column
+
+   for($x = 0; $x < $csvmax; $x++) { // The Drop down boxes to select what each column is
+      echo '<TD>';
+      create_Select($csvmax,$x); 
+      echo '</TD>
+      ';
+   }
+
+   echo '</TR>
+   ';
+
+   do {
+      if (count($_SESSION['csvdata'][$row]) >= 5) {    // This if ensures the minimum number of columns
+         $cols = count($_SESSION['csvdata'][$row]);    // so importing can function for all 5 fields
+      } else {
+         $cols = 5;
+      }        
+
+      $colspan = $cols + 1;
+      if ($row % 2) {                   // Set up the alternating colored rows
+         echo '<TR BGCOLOR="' . $color[0] . '">
+         ';
+      } else {
+         echo '<TR>
+         ';
+      }
+
+      echo '<TD WIDTH="1"><INPUT TYPE="checkbox" NAME="sel' . $row . '">
+      '; // Print the omit checkbox, to be checked before write
+
+      for($c = 0; $c < $cols; $c++) { // For each column in the current row
+         if ($_SESSION['csvdata'][$row][$c] != "") {                                // if not empty, put data in cell.
+            echo '<TD NOWRAP>' . $_SESSION['csvdata'][$row][$c] . '</TD>
+            ';
+         } else {                                          // if empty, put space in cell keeping colors correct.
+            echo '<TD>&nbsp;</TD>
+            ';
+         }
+      }
+      echo '</TR>
+      ';
+      $row++;
+   } while ($row < count($_SESSION['csvdata']));
+   
+   echo '
+   </TABLE>
+   </CENTER>
+   ';
+
+   if(strlen($errorstring)) {   
+      echo _("The following rows have errors") . ': <p>
+      ' . $errorstring;
+   }
+   
+} else {
+   /** 
+    **   $abook ---->Setup the addressbook functions for Pallo's Addressbook.
+    **/
+   $abook = addressbook_init(true, true); // We only need to do this here because we will only access the address book in this section
+
+   do {
+      if (count($_SESSION['csvdata'][$row]) >= 5) {    // This if ensures the minimum number of columns
+         $cols = count($_SESSION['csvdata'][$row]);    // so importing can function for all 5 fields
+      } else {
+         $cols = 5;
+      }  
+            
+      $reorg = array('', '', '', '', '');
+      
+      for ($c=0; $c < $cols; $c++) {
+         // Reorganize the data to fit the header cells that the user chose
+         // concatenate fields based on user input into text boxes.
+         $column = "COL$c";
+         
+         if($_POST[$column] != 5)  {
+            if ($_POST[$column] == 4) {
+               $reorg[4] .= $_SESSION['csvdata'][$row][$c] . ";";
+            } else {
+               $reorg[$_POST[$column]] = $_SESSION['csvdata'][$row][$c];
+               $reorg[$c] = trim($reorg[$c],"\r\n \"");
+            }
+         }
+      }
+      
+      $reorg[4] = trim($reorg[4],";");
+      $_SESSION['csvdata'][$row] = $reorg;
+      unset($reorg); // So that we don't get any weird information from a previous rows
+
+      // If finished, do the import. This uses Pallo's excellent class and object stuff 
+      $selrow = 'sel' . $row;
+      
+      if (!isset($_POST[$selrow])) {
+         if (eregi('[ \\:\\|\\#\\"\\!]', $_SESSION['csvdata'][$row][0])) {
+            $_SESSION['csvdata'][$row][0] = '';
+         }
+
+         //Here we should create the right data to input 
+         if (count($_SESSION['csvdata'][$row]) < 5) {
+            array_pad($_SESSION['csvdata'][$row],5,'');
+         }
+
+         $addaddr['nickname'] 	= $_SESSION['csvdata'][$row][0];
+         $addaddr['firstname'] 	= $_SESSION['csvdata'][$row][1];
+         $addaddr['lastname'] 	= $_SESSION['csvdata'][$row][2];
+         $addaddr['email'] 	= $_SESSION['csvdata'][$row][3];
+         $addaddr['label'] 	= $_SESSION['csvdata'][$row][4];
+
+         if (false == $abook->add($addaddr,$abook->localbackend)) {
+            $errorstring .= $abook->error . "<br>\n";
+            $error++;
+         }
+
+         unset($addaddr); // Also so we don't get any weird information from previous rows
+      }
+      
+      $row++;
+      
+   } while($row < count($_SESSION['csvdata']));
+
+   unset($_SESSION['csvdata']); // Now that we've uploaded this information, we dont' need this variable anymore, aka cleanup
+
+   // Print out that we've completed this operation
+   if ($error) {
+      // Since we will print something to the page at this point
+      displayPageHeader($color, "None");
+
+      echo '<BR>' . _("There were errors uploading the data, as listed below. Entries not listed here were uploaded.") . '<br> ' . $errorstring . '<BR> ';
+   } else {
+      // Since we will print something to the page at this point
+      displayPageHeader($color, "None");
+
+      echo '<BR><BR><H1><STRONG><CENTER>' . _("Upload Completed!") . '</STRONG></H1>' . _("Click on the link below to verify your work.") . '</CENTER>';
+   }
+
+   echo '<BR><BR><CENTER><A HREF="' . SM_PATH . 'src/addressbook.php">' . _("Addresses") . '</A></CENTER>
+   ';
+}
+
+   // Send the field numbers entered in the text boxes by the user back to this script for more processing
+   // email is handled differently, not being an array
+function create_Select($csvmax,$column) {
+   // $column is the one that should be selected out of the bunch
+   echo "<SELECT NAME=\"COL$column\">\n";
+
+   if($column > 5)
+    $column = 5; // So we have only our normal choices. 
+    
+   for($temp = 0; $temp <= 5; $temp++) {
+      echo "<OPTION value=$temp ";
+      if ($column==$temp)
+        echo "SELECTED";
+      if ($temp == 0)
+        echo ">Nickname</option>\n";
+      if ($temp == 1)
+        echo ">First Name</option>\n";
+      if ($temp == 2)
+        echo ">Last Name</option>\n";
+      if ($temp == 3)
+        echo ">Email</option>\n";
+      if ($temp == 4)
+        echo ">Additional Info</option>\n";
+      if ($temp == 5)
+        echo ">Do Not Include</option>\n";
+   }
+   echo "</select>\n";
+}
+
+function CSVProcess($row) {
+   if (preg_grep("/((?:\/ou\=)|(?:\/cn\=)|(?:\/o\=))/",$row)) {
+      $temprow = join(",",$row);
+      $return[] = "$temprow <br> - ". _("contains LDIF email address. This is not currently supported.")."\n";
+      return $return;
+   }
+   
+   if (preg_grep("/((?:First Name)|(?:Last Name)|(?:E-mail Address))/",$row)) {
+      foreach($row as $key => $value) {
+         if ($value == "First Name" ) { 
+            if(isset($_SESSION['csvorder'][$key])) { 
+               $_SESSION['csvorder'][1] = $_SESSION['csvorder'][$key]; 
+            }
+            else { 
+               $_SESSION['csvorder'][1]= $key; 
+            }
+         }
+         if ($value == "Last Name" ) { 
+            if(isset($_SESSION['csvorder'][$key])) { 
+               $_SESSION['csvorder'][2] = $_SESSION['csvorder'][$key]; 
+            }
+            else { 
+               $_SESSION['csvorder'][2]= $key; 
+            }
+         }
+         if ($value == "E-mail Address" ) { 
+            if(isset($_SESSION['csvorder'][$key])) { 
+               $_SESSION['csvorder'][3] = $_SESSION['csvorder'][$key]; 
+            }
+            else { 
+               $_SESSION['csvorder'][3]= $key; 
+            }
+         }
+      }
+      return array();
+   }
+   
+   if (count($_SESSION['csvorder']) > 0) { // This is swapping elements to make firstname, last name, and email be in the 1,2,3 spot, respectively
+      foreach($_SESSION['csvorder'] as $key => $value) {
+         $temp = $row[$key];
+         $row[$key] = $row[$value];
+         $row[$value] = $temp;
+      }
+      return $row;
+   }
+   
+   return $row;
+}
+  
+?>
+</FORM>
+</BODY>
+</HTML>
--- /dev/null
+++ squirrelmail-abook-import-export-1.0/abook_import_export/index.php
@@ -0,0 +1,20 @@
+<?php
+
+/**
+ * index.php
+ *
+ * Copyright (c) 1999-2003 The SquirrelMail Project Team
+ * Licensed under the GNU GPL. For full terms see the file COPYING.
+ *
+ * This file simply takes any attempt to view source files and sends those
+ * people to the login screen. At this point no attempt is made to see if
+ * the person is logged or not.
+ *
+ * $Id: index.php,v 1.5 2002/12/31 12:49:33 kink Exp $
+ */
+
+header("Location:../index.php");
+
+/* pretty impressive huh? */
+
+?>
--- /dev/null
+++ squirrelmail-abook-import-export-1.0/abook_import_export/setup.php
@@ -0,0 +1,29 @@
+<?php
+  /**
+   ** setup.php
+   **
+   **  Copyright (c) 1999-2000 The SquirrelMail development team
+   **  Licensed under the GNU GPL. For full terms see the file COPYING.
+   **
+   ** Uses standard plugin format to create a couple of forms to
+   ** enable import/export of CSV files to/from the address book.
+   **/
+
+   function squirrelmail_plugin_init_abook_import_export() {
+      global $squirrelmail_plugin_hooks;
+      $squirrelmail_plugin_hooks["addressbook_bottom"]["abook_import_export"] = "abook_import_export";
+   }
+
+   function plugin_version() {
+      return "0.7";
+   }
+
+   function abook_import_export() {
+      if (defined('SM_PATH'))
+         include_once(SM_PATH . 'plugins/abook_import_export/functions.php');
+      else
+         include_once('../plugins/abook_import_export/functions.php');
+
+      create_plugin_form();
+   }
+?>
