Uses user's visibility limitations to display vcards (Closes #1478).
[platal.git] / modules / xnetgrp / mail.inc.php
index 891146a..8af7b3d 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2010 Polytechnique.org                              *
+ *  Copyright (C) 2003-2011 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
@@ -21,7 +21,7 @@
 
 // {{{ get_all_redirects
 
-function get_all_redirects($membres, $mls, &$client)
+function get_all_redirects($membres, $mls, $client)
 {
     global $globals;
 
@@ -34,10 +34,13 @@ function get_all_redirects($membres, $mls, &$client)
     }
 
     foreach ($mls as $ml) {
-        if (list(,$members) = $client->get_members($ml)) {
-            foreach ($members as $mem) {
-                $uf = new UserFilter(new UFC_Mail($mem[1]));
-                $user = $uf->getUsers();
+        // $list_members is a (list_details, members, list_owners) array, where
+        // members is an array of (0 => name, 1 => email) arrays.
+        $list_members = $client->get_members($ml);
+        if ($list_members) {
+            foreach ($list_members[1] as $mem) {
+                $uf = new UserFilter(new UFC_Email($mem[1]));
+                $user = $uf->getUser();
                 if ($user) {
                     $tos[] = $user;
                 } else {
@@ -67,7 +70,7 @@ function _send_xnet_mail($user, $body, $wiki, $mailer, $replyto = null)
 
     $text = str_ireplace(array('<cher>', '<nom>', '<prenom>'),
                          array($dear, $lastname, $firstname), $body);
-    $mailer->addTo($user);
+    $mailer->setTo($user);
     if ($replyto) {
         $mailer->addHeader('Reply-To', $replyto);
     }
@@ -95,16 +98,16 @@ function send_xnet_mails($from, $sujet, $body, $wiki, $tos, $replyto = null, $up
     }
 
     foreach ($tos as $user) {
-        if ($user instanceof $user) {
+        if ($user instanceof User) {
             $email = $user->bestEmail();
         } else {
             $email = $user;
         }
-        if ($sent[$email]) {
-            continue;
+
+        if (!isset($sent[$email])) {
+            _send_xnet_mail($user, $body, $wiki, $mailer, $replyto);
+            $sent[$email] = true;
         }
-        _send_xnet_mail($user, $body, $wiki, $mailer, $replyto);
-        $sent[$email] = true;
     }
 }