Return-Path: <W.J.Zwart@NescioLudens.nl>
Received: from murder ([unix socket])
	 by linuxnotes.net (Cyrus v2.2.4) with LMTPA;
	 Mon, 21 Jun 2004 18:38:50 -0400
X-Sieve: CMU Sieve 2.2
Received: by www.linuxnotes.net (Postfix, from userid 1005)
	id A96762A0016; Mon, 21 Jun 2004 18:38:49 -0400 (EDT)
Received: from jelle.nescioludens.nl (ns2.nescioludens.nl [80.127.133.252])
	by www.linuxnotes.net (Postfix) with ESMTP id 34A792A000E
	for <quincy@linuxnotes.net>; Mon, 21 Jun 2004 18:38:47 -0400 (EDT)
Received: from 192.168.2.2 (froukje [192.168.2.2])
	by jelle.nescioludens.nl (8.12.9p2/8.12.9) with ESMTP id i5LMcFab049162
	for <quincy@linuxnotes.net>; Tue, 22 Jun 2004 00:38:20 +0200 (CEST)
	(envelope-from W.J.Zwart@NescioLudens.nl)
Received: from 192.168.2.84
        (SquirrelMail authenticated user willemjaap);
        by 192.168.2.2 with HTTP;
        Tue, 22 Jun 2004 00:38:17 +0200 (CEST)
Message-ID: <64547.192.168.2.84.1087857497.squirrel@192.168.2.84>
In-Reply-To: <1183.141.151.194.130.1086273775.squirrel@linuxnotes.net>
References: <60982.192.168.2.84.1086273383.squirrel@192.168.2.84>
    <1183.141.151.194.130.1086273775.squirrel@linuxnotes.net>
Date: Tue, 22 Jun 2004 00:38:17 +0200 (CEST)
Subject: Re: squirrelmail address book group plugin
From: "Willem Jaap Zwart" <W.J.Zwart@NescioLudens.nl>
To: quincy@linuxnotes.net
User-Agent: SquirrelMail/1.4.3a
X-Mailer: SquirrelMail/1.4.3a
MIME-Version: 1.0
Content-Type: multipart/mixed;boundary="----=_20040622003817_10298"
X-Priority: 3 (Normal)
Importance: Normal
X-Spam-Checker-Version: SpamAssassin 2.63 (2004-01-11) on linuxnotes.net
X-Spam-Level: 
X-Spam-Status: No, hits=0.2 required=5.0 tests=AWL,HTML_MESSAGE,
	HTML_TAG_BALANCE_HTML autolearn=no version=2.63
X-Spam-Pyzor: Reported 0 times.

------=_20040622003817_10298
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 8bit

Hi Jon

Thanks for your mail
I think I've got it basically running
Please find attached a unified diff for patching the 1.4.3a release.

Besides a small change in the abook_group_interface a number of changes were needed in compose and
the Rfc822Header class.
The interface just adds the group name to one of the fields (cc, to, bcc) and the compose and
rfc822 files take care of resolving this name to the group members on delivery.

At least one thing I need to implement additionally: group names should not be allowed to contain
whitespace anymore.

If you have the opportunity to test the diff, please let me know the results

Willem

Jon Nelson said:
> Willem,
>
> That would be really great!  Thank you very much and let me know if you
> need anything.
>
> Jon
>
> Willem Jaap Zwart said:
>> Hello Jon
>>
>> Recently I installed the address book group plugin 0.39c for squirrelmail.
>> Working with it a few improvements came to my mind. The most important is
>> to be able to list in
>> the fields in the form (to, cc, bcc) just the group name and leave the
>> resolving to the email
>> addresses for the processing inside squirrelmail after hitting the send
>> button. Especially when
>> you have a large number of addresses in a group, the listing of all email
>> addresses doesn't fit in
>> the form fields.
>>
>> Before start to code this it seems reasonable to contact you :-)
>> Any ideas/objections?
>>
>> kind regards
>>
>> Willem Jaap
>>
>>
>> <=====>                                <=====>
>> Willem Jaap Zwart             Nescio Ludens BV
>>
>> Minkmaatstraat 33 ** 7514 EA ** Enschede ** NL
>> t: +31-53-4306465 **  **  ** f: +31-53-4306491
>>
>> Email: W.J.Zwart@NescioLudens.nl
>> ----------------------------------------------
>>                       If you love Unix: FreeBSD
>> ----------------------------------------------
>>
>>
>>
>
>
> --
> Trooper Jon S. Nelson, Linux Certified Admin., CCNA
> Pa. State Police, Bureau of Criminal Investigation
> Computer Crimes Unit
> Work: 610.344.4471 Cell/Page: 866.284.1603
> jonelson <at> state <dot> pa <dot> us
>


<=====>                                <=====>
Willem Jaap Zwart             Nescio Ludens BV

Minkmaatstraat 33 ** 7514 EA ** Enschede ** NL
t: +31-53-4306465 **  **  ** f: +31-53-4306491

Email: W.J.Zwart@NescioLudens.nl
----------------------------------------------
                      If you love Unix: FreeBSD
----------------------------------------------
------=_20040622003817_10298
Content-Type: text/x-diff; name="abook_group_resolvelater.diff"
Content-Transfer-Encoding: 8bit
Content-Disposition: attachment; filename="abook_group_resolvelater.diff"

--- src/compose.php.orig	Tue Jun 22 00:29:04 2004
+++ src/compose.php	Mon Jun 21 23:00:15 2004
@@ -31,6 +31,9 @@
 require_once(SM_PATH . 'class/deliver/Deliver.class.php');
 require_once(SM_PATH . 'functions/addressbook.php');
 require_once(SM_PATH . 'functions/forms.php');
+require_once(SM_PATH . 'plugins/abook_group/abook_group_database.php');
+
+
 
 /* --------------------- Get globals ------------------------------------- */
 /** COOKIE VARS */
@@ -613,9 +616,13 @@
         $type1 = $message->type1;
         foreach ($entities as $ent) {
             $unencoded_bodypart = mime_fetch_body($imapConnection, $passed_id, $ent);
+            if (substr($unencoded_bodypart,0,6) == '<html>') {
+              $type1 = 'html';
+            }
             $body_part_entity = $message->getEntity($ent);
             $bodypart = decodeBody($unencoded_bodypart,
             $body_part_entity->header->encoding);
+
             if ($type1 == 'html') {
                 $bodypart = str_replace("\n", ' ', $bodypart);
                 $bodypart = preg_replace(array('/<p>/i','/<br\s*(\/)*>/i'), "\n", $bodypart);
@@ -1353,15 +1360,23 @@
     global $send_to, $send_to_cc, $send_to_bcc, $mailprio, $subject, $body,
            $username, $popuser, $usernamedata, $identity, $data_dir,
            $request_mdn, $request_dr, $default_charset, $color, $useSendmail,
-           $domain, $action, $default_move_to_sent, $move_to_sent;
+           $domain, $action, $default_move_to_sent, $move_to_sent, $addrbook_dsn;
     global $imapServerAddress, $imapPort, $sent_folder, $key;
 
     $rfc822_header = $composeMessage->rfc822_header;
 
     $abook = addressbook_init(false, true);
-    $rfc822_header->to = $rfc822_header->parseAddress($send_to,true, array(), '', $domain, array(&$abook,'lookup'));
-    $rfc822_header->cc = $rfc822_header->parseAddress($send_to_cc,true,array(), '',$domain, array(&$abook,'lookup'));
-    $rfc822_header->bcc = $rfc822_header->parseAddress($send_to_bcc,true, array(), '',$domain, array(&$abook,'lookup'));
+    
+    $myparams = array();
+    $myparams['dsn'] = $addrbook_dsn;
+    $myparams['table'] = 'addressgroups';
+    $myparams['owner'] = $username;
+    
+    $abookGroups = new abook_group_database($myparams);
+    
+    if ($send_to) { $rfc822_header->to = $rfc822_header->parseAddress($send_to,true, array(), '', $domain, array(&$abook,'lookup'), array(&$abookGroups,'list_groupMembers'));}
+    if ($send_to_cc) {$rfc822_header->cc = $rfc822_header->parseAddress($send_to_cc,true,array(), '',$domain, array(&$abook,'lookup'), array(&$abookGroups,'list_groupMembers'));}
+    if ($send_to_bcc) {$rfc822_header->bcc = $rfc822_header->parseAddress($send_to_bcc,true, array(), '',$domain, array(&$abook,'lookup'), array(&$abookGroups,'list_groupMembers'));}
     $rfc822_header->priority = $mailprio;
     $rfc822_header->subject = $subject;
     $special_encoding='';
--- class/mime/Rfc822Header.class.php.orig	Tue Jun 22 00:29:36 2004
+++ class/mime/Rfc822Header.class.php	Mon Jun 21 21:00:58 2004
@@ -393,7 +393,7 @@
      *  That's also the reason that the function became a little bit huge
      */
 
-    function parseAddress($address,$ar=false,$aAddress=array(),$sGroup='',$sHost='',$lookup=false) {
+    function parseAddress($address,$ar=false,$aAddress=array(),$sGroup='',$sHost='',$lookup=false, $grouplookupcallback=false) {
         $aTokens = $this->getAddressTokens($address);
         $sPersonal = $sEmail = $sComment = $sGroup = '';
         $aStack = $aComment = array();
@@ -440,14 +440,17 @@
         }
         /* now do the action again for the last address */
         $aAddress[] = $this->createAddressObject($aStack,$aComment,$sEmail);
+        
         /* try to lookup the addresses in case of invalid email addresses */
         $aProcessedAddress = array();
+        
         foreach ($aAddress as $oAddr) {
           $aAddrBookAddress = array();
           if (!$oAddr->host) {
             $grouplookup = false;
             if ($lookup) {
                  $aAddr = call_user_func_array($lookup,array($oAddr->mailbox));
+
                  if (isset($aAddr['email'])) {
                      if (strpos($aAddr['email'],',')) {
                          $grouplookup = true;
@@ -462,7 +465,36 @@
                              $oAddr->personal = encodeHeader($sPersonal);
                          }
                      }
-                 }
+                 } else {
+                   /*
+                     WJZ 20040621 addressbook lookup did not succeed, try a group lookup
+                   */
+                   $myGroupMembers = call_user_func_array ($grouplookupcallback,array($oAddr->mailbox));
+                   if (count($myGroupMembers) >0) {
+                     /* this was a group */
+                   
+                     /* empty the mailbox name if the group lookup succeeded to avoid treating it as a email address or local account */
+                     $oAddr->mailbox ='';
+                   
+                     /* oGroupMember is a temp object to store the results of the grouplookup */
+                     $oGroupMember = $this->createAddressObject();
+                   
+                     /* traverse the array of group members */
+                     for ($j=0;$j<count($myGroupMembers);$j++){
+                       $aAddr = $myGroupMembers[$j];
+                       $iPosAt = strpos($aAddr['email'], '@');
+                       $oGroupMember->mailbox = substr($aAddr['email'], 0, $iPosAt);
+                       $oGroupMember->host = substr($aAddr['email'], $iPosAt+1);
+                       if (isset($aAddr['name'])) {
+                           $oGroupMember->personal = $aAddr['name'];
+                       } else {
+                           $oGroupMember->personal = encodeHeader($sPersonal);
+                       }
+                       $ar = true; /* force the return of the complete array iso one element */
+                       array_push($aProcessedAddress,$oGroupMember);
+                     }
+                   }
+                }
             }
             if (!$grouplookup && !$oAddr->mailbox) {
                 $oAddr->mailbox = trim($sEmail);
--- plugins/abook_group/abook_group_interface.php.orig	Mon Jun 21 22:37:44 2004
+++ plugins/abook_group/abook_group_interface.php	Mon Jun 21 22:37:53 2004
@@ -149,15 +149,15 @@
 <?php
 for ($i=0;$i<count($myGroups);$i++){
     $groupName = $myGroups[$i]['addressgroup'];
-    $myGroupMembers = $abookGroups->list_groupMembers($groupName);
+    //$myGroupMembers = $abookGroups->list_groupMembers($groupName);
     $to_address = "";
     $cc_address = "";
     $bcc_address = "";
-    for ($j=0;$j<count($myGroupMembers);$j++){
-        $to_address .= "to_address('{$myGroupMembers[$j]['email']}');";
-        $cc_address .= "cc_address('{$myGroupMembers[$j]['email']}');";
-        $bcc_address .= "bcc_address('{$myGroupMembers[$j]['email']}');";
-    }
+    //for ($j=0;$j<count($myGroupMembers);$j++){
+        $to_address .= "to_address('$groupName');";
+        $cc_address .= "cc_address('$groupName');";
+        $bcc_address .= "bcc_address('$groupName');";
+    //}
     
 ?>
 <tr><td><a href="javascript:<?php echo $to_address ?>">To</a> <a href="javascript:<?php echo $cc_address ?>">Cc</a> <a href="javascript:<?php echo $bcc_address ?>">Bcc</a></td><td><?php echo $groupName ?></td></tr>
------=_20040622003817_10298--



