X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=modules%2Fxnetgrp%2Fmail.inc.php;h=8af7b3d7e7c743e133706d8cedf67d4b538335f6;hb=cfceef1ef8148bef4f7d1319ceabe43096110332;hp=3a51f5e2d983c97115d554290c3f184f37a4df36;hpb=a14159bffdc1ea08c97e6634dc1480619bdc478a;p=platal.git diff --git a/modules/xnetgrp/mail.inc.php b/modules/xnetgrp/mail.inc.php index 3a51f5e..8af7b3d 100644 --- a/modules/xnetgrp/mail.inc.php +++ b/modules/xnetgrp/mail.inc.php @@ -1,6 +1,6 @@ "", u.nom, m.nom) AS nom, - IF(u.prenom <> "", u.prenom, m.prenom) AS prenom, - IF(m.email <> "", m.email, CONCAT(a.alias, "@polytechnique.org")) as email, - IF(m.sexe IS NULL, FIND_IN_SET("femme", u.flags), m.sexe) AS sexe - FROM groupex.membres AS m - LEFT JOIN auth_user_md5 AS u ON (m.uid=u.user_id AND m.uid<50000) - LEFT JOIN aliases AS a ON (a.id=u.user_id and a.type="a_vie") - WHERE asso_id = {?} - AND m.origine IN (' . $membres . ') - AND (m.email <> "" OR u.perms <> "pending")', $globals->asso('id')); - $tos = $res->fetchAllAssoc(); + $uf = new UserFilter(new UFC_Group($globals->asso('id'))); + $tos = $uf->getUsers(); } foreach ($mls as $ml) { - if (list(,$members) = $client->get_members($ml)) { - foreach ($members as $mem) { - list($m, $dom) = explode('@',$mem[1]); - if ($dom == $globals->mail->domain || $dom == $globals->mail->domain2) { - $res = XDB::query('SELECT prenom, nom, FIND_IN_SET("femme", u.flags) AS sexe - FROM auth_user_md5 AS u - INNER JOIN aliases AS a ON u.user_id = a.id - WHERE a.alias = {?}', $m); - if ($person = $res->fetchOneAssoc()) { - $person['email'] = $mem[1]; - $tos[] = $person; - } + // $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 { - $res = XDB::query('SELECT prenom, nom, sexe FROM groupex.membres WHERE email={?}', $mem[1]); - if ($person = $res->fetchOneAssoc()) { - $person['email'] = $mem[1]; - $tos[] = $person; - } else { - $tos[] = array('email' => $mem[1]); - } + $tos[] = $mem[1]; } } } @@ -76,30 +56,36 @@ function get_all_redirects($membres, $exclude, $mls, &$client) // }}} // {{{ _send_xnet_mail -function _send_xnet_mail($user, $body, $mailer, $replyto = null) +function _send_xnet_mail($user, $body, $wiki, $mailer, $replyto = null) { - $cher = isset($user['sexe']) ? ($user['sexe'] ? 'Chère' : 'Cher') : 'Cher(e)'; - $nom = isset($user['nom']) ? $user['nom'] : ""; - $pnom = isset($user['prenom']) ? $user['prenom'] : preg_replace('!@.*!u', '', $user['email']); - $to = isset($user['prenom']) ? "\"{$user['prenom']} {$user['nom']}\" <{$user['email']}>" : $user['email']; - - $text = $body; - $text = preg_replace('!!i', $cher, $text); - $text = preg_replace('!!i', $nom, $text); - $text = preg_replace('!!i', $pnom, $text); - - $mailer->addHeader('To', $to); + if ($user instanceof PlUser) { + $dear = $user->isFemale() ? 'Chère' : 'Cher'; + $lastname = $user->lastName(); + $firstname = $user->firstName(); + } else { + $dear = 'Cher(e)'; + $lastname = ''; + $firstname = $user; + } + + $text = str_ireplace(array('', '', ''), + array($dear, $lastname, $firstname), $body); + $mailer->setTo($user); if ($replyto) { $mailer->addHeader('Reply-To', $replyto); } - $mailer->setTxtBody(wordwrap($text, 72)); + if ($wiki) { + $mailer->setWikiBody($text); + } else { + $mailer->setTxtBody(wordwrap($text, 72)); + } $mailer->send(); } // }}} // {{{ send_xnet_mails -function send_xnet_mails($from, $sujet, $body, $tos, $replyto = null, $attach = null) +function send_xnet_mails($from, $sujet, $body, $wiki, $tos, $replyto = null, $upload = null, $name = null) { global $globals; $sent = array(); @@ -107,16 +93,21 @@ function send_xnet_mails($from, $sujet, $body, $tos, $replyto = null, $attach = $mailer = new PlMailer(); $mailer->setSubject($sujet); $mailer->setFrom($from); - if (is_uploaded_file($attach['tmp_name'])) { - $mailer->addAttachment($attach['tmp_name'], - $attach['type'], - $attach['name']); + if ($upload && $upload->exists()) { + $mailer->addUploadAttachment($upload, $name); } foreach ($tos as $user) { - if ($sent[$user['email']]) continue; - _send_xnet_mail($user, $body, $mailer, $replyto); - $sent[$user['email']] = true; + if ($user instanceof User) { + $email = $user->bestEmail(); + } else { + $email = $user; + } + + if (!isset($sent[$email])) { + _send_xnet_mail($user, $body, $wiki, $mailer, $replyto); + $sent[$email] = true; + } } }