From 870b4f0f91f4bdc3a98e804611a87d3ff1d5bdd2 Mon Sep 17 00:00:00 2001 From: "Pierre Habouzit (MadCoder" Date: Thu, 28 Apr 2005 14:59:56 +0000 Subject: [PATCH] mail.php git-archimport-id: opensource@polytechnique.org--2005/platal--mainline--0.9--patch-607 --- htdocs.net/groupe/mail.php | 28 +++++++++ include/lists.inc.php | 16 ++--- include/xnet/mail.inc.php | 115 ++++++++++++++++++++++++++++++++++ templates/xnet/groupe/alias-admin.tpl | 4 +- templates/xnet/groupe/mail.tpl | 111 ++++++++++++++++++++++++++++++++ 5 files changed, 264 insertions(+), 10 deletions(-) create mode 100644 htdocs.net/groupe/mail.php create mode 100644 include/xnet/mail.inc.php create mode 100644 templates/xnet/groupe/mail.tpl diff --git a/htdocs.net/groupe/mail.php b/htdocs.net/groupe/mail.php new file mode 100644 index 0000000..f81937a --- /dev/null +++ b/htdocs.net/groupe/mail.php @@ -0,0 +1,28 @@ +asso('mail_domain')); + $page->assign('listes', $client->get_lists()); + + $alias = $globals->xdb->query("SELECT alias FROM virtual WHERE alias LIKE {?} AND type='user' ORDER BY alias", '%@'.$globals->asso("mail_domain")); + $page->assign('alias', $alias->fetchColumn()); + + if (Post::has('send')) { + $from = Post::get('from'); + $sujet = Post::get('sujet'); + $body = Post::get('body'); + + $mls = array_keys(Env::getMixed('ml', array())); + $als = array_keys(Env::getMixed('al', array())); + + require_once 'xnet/mail.inc.php'; + $tos = get_all_redirects(Post::has('membres'), $mls, $als, $client); + send_xnet_mails($from, $sujet, $body, $tos); + $page->kill("Mail envoyé !"); + $page->assign('sent', true); + } + + $page->run(); +?> diff --git a/include/lists.inc.php b/include/lists.inc.php index 8582278..0df70b2 100644 --- a/include/lists.inc.php +++ b/include/lists.inc.php @@ -55,16 +55,16 @@ function list_sort_owners(&$members, $tri_promo = true) { $key = $tri_promo ? $promo : strtoupper($nom{0}); $membres[$key][$nom.$m] = Array('n' => "$prenom $nom", 'l' => $m); } else { - $res = $globals->xdb->query('SELECT prenom, nom FROM groupex.membres WHERE email={?}', $mem); - if (list($prenom, $nom) = $res->fetchOneRow()) { - $key = $tri_promo ? 0 : strtoupper($nom{0}); - $membres[$key][$nom.$m] = Array('n' => "$prenom $nom", 'l' => $m); - } else { - $membres[0][] = Array('l' => $mem); - } + $membres[0][] = Array('l' => $mem); } } else { - $membres[0][] = Array('l' => $mem); + $res = $globals->xdb->query('SELECT prenom, nom FROM groupex.membres WHERE email={?}', $mem); + if (list($prenom, $nom) = $res->fetchOneRow()) { + $key = $tri_promo ? 0 : strtoupper($nom{0}); + $membres[$key][$nom.$m] = Array('n' => "$prenom $nom", 'l' => $m); + } else { + $membres[0][] = Array('l' => $mem); + } } } diff --git a/include/xnet/mail.inc.php b/include/xnet/mail.inc.php new file mode 100644 index 0000000..328b959 --- /dev/null +++ b/include/xnet/mail.inc.php @@ -0,0 +1,115 @@ +xdb->query( + 'SELECT IF(u.nom, 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, + FIND_IN_SET("femme", u.flags) AS sexe + FROM groupex.membres AS m + LEFT JOIN auth_user_md5 AS u ON (m.uid=u.user_id AND m.uid<50000) + INNER JOIN aliases AS a ON (a.id=u.user_id and a.type="a_vie") + WHERE asso_id = {?}', $globals->asso('id')); + $tos = $res->fetchAllAssoc(); + } + + foreach ($mls as $ml) { + if (list(,$members) = $client->get_members($ml)) { + foreach ($members as $mem) { + list($m, $dom) = split('@',$mem[1]); + if ($dom == $globals->mail->domain || $dom == $globals->mail->domain2) { + $res = $globals->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; + } + } else { + $res = $globals->xdb->query('SELECT prenom, nom FROM groupex.membres WHERE email={?}', $mem); + if ($person = $res->fetchOneAssoc()) { + $person['email'] = $mem[1]; + $tos[] = $person; + } else { + $tos[] = array('email' => $mem[1]); + } + } + } + } + } + + return $tos; +} + +// }}} +// {{{ _send_xnet_mail + +function _send_xnet_mail($user, $body, $mailer) +{ + $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('!@.*!', $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); + $mailer->setTxtBody(wordwrap($text, 72)); + $mailer->send(); +} + +// }}} +// {{{ send_xnet_mails + +function send_xnet_mails($from, $sujet, $body, $tos) +{ + $sent = array(); + + $mailer = new HermesMailer(); + $mailer->setSubject($sujet); + $mailer->setFrom($from); + + foreach ($tos as $user) { + if ($sent[$user['email']]) continue; + _send_xnet_mail($user, $body, $mailer); + $sent[$user['email']] = true; + } +} + +// }}} + +// vim:set et sw=4 sts=4 sws=4 foldmethod=marker: +?> diff --git a/templates/xnet/groupe/alias-admin.tpl b/templates/xnet/groupe/alias-admin.tpl index 4af3af8..20b178e 100644 --- a/templates/xnet/groupe/alias-admin.tpl +++ b/templates/xnet/groupe/alias-admin.tpl @@ -22,9 +22,9 @@

Membres de {$smarty.request.liste}

- +
- +
MembresMembres {if $mem->total()} {iterate from=$mem item=m} diff --git a/templates/xnet/groupe/mail.tpl b/templates/xnet/groupe/mail.tpl new file mode 100644 index 0000000..95034b9 --- /dev/null +++ b/templates/xnet/groupe/mail.tpl @@ -0,0 +1,111 @@ +{*************************************************************************** + * Copyright (C) 2003-2004 Polytechnique.org * + * http://opensource.polytechnique.org/ * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., * + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * + ***************************************************************************} + + +

{$asso.nom} : Envoyer un mail

+ +

+Ton message peut être personnalisé : si tu rentres les mots <cher>, <prenom>, +<nom>, ces mots seront remplacés, pour chacun des destinataires, par "cher" accordé au +masculin ou féminin, par son prénom, ou son nom. +

+ +
+ + + + + + + + + + + + + + + + + + {foreach from=$listes item=l} + + + + + {/foreach} + + {* NOT SUPPORTED ATM + {foreach from=$alias item=a} + {assign var=b value=$a|regex_replace:"!@.*!":""} + + + + + {/foreach} + *} + + + + + + + + + + + + + + +
Ecrire un mail :
Expéditeur : + +
Destinataires
+ * membres + + + écrit à tous les membres du groupe (voir membres) +
+ * {$l.list} + + + {$l.addr} + (voir composition) +
+ * {$b} + + + {$a} (voir composition) +
Contenu du mail
+ Sujet : +
+ +
+
+ +{* vim:set et sw=2 sts=2 sws=2: *} -- 2.1.4