Happy New Year !
[platal.git] / modules / admin / homonyms.inc.php
1 <?php
2 /***************************************************************************
3 * Copyright (C) 2003-2013 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software *
18 * Foundation, Inc., *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
21
22 function select_if_homonym(PlUser $user)
23 {
24 return XDB::fetchOneCell('SELECT email
25 FROM email_source_account
26 WHERE uid = {?} AND expire IS NOT NULL',
27 $user->id());
28 }
29
30 function send_warning_homonym(PlUser $user, $email)
31 {
32 $cc = "validation+homonyme@" . Platal::globals()->mail->domain;
33 $from = "\"Support Polytechnique.org\" <$cc>";
34 $body = Post::has('mailbody') ? Post::t('mailbody') : get_warning_mail_text($user, $email);
35
36 $mymail = new PlMailer();
37 $mymail->setFrom($from);
38 $mymail->addCc($cc);
39 $mymail->setSubject("Dans 1 semaine, suppression de $email@" . $user->mainEmailDomain());
40 $mymail->setTxtBody($body);
41 $mymail->sendTo($user);
42 }
43
44 function send_robot_homonym(PlUser $user, $email)
45 {
46 $cc = "validation+homonyme@" . Platal::globals()->mail->domain;
47 $from = "\"Support Polytechnique.org\" <$cc>";
48 $body = Post::has('mailbody') ? Post::t('mailbody') : get_robot_mail_text($user, $email);
49 $user = User::getSilentWithUID($user->id());
50
51 $mymail = new PlMailer();
52 $mymail->setFrom($from);
53 $mymail->setSubject("Mise en place du robot $email@" . $user->mainEmailDomain());
54 $mymail->addCc($cc);
55 $mymail->setTxtBody($body);
56 $mymail->sendTo($user);
57 }
58
59 function get_warning_mail_text(PlUser $user, $email)
60 {
61 $display_name = $user->displayName();
62 $former_email = $email . '@' . $user->mainEmailDomain();
63 $forlife_email = $user->forlifeEmail();
64
65 return "$display_name,\n\nComme nous t'en avons informé par email il y a "
66 . "quelques temps, pour respecter nos engagements en terme d'adresses "
67 . "email devinables, tu te verras bientôt retirer l'alias $former_email "
68 . "pour ne garder que $forlife_email.\n\nToute personne qui écrira à "
69 . "$former_email recevra la réponse d'un robot qui l'informera que "
70 . "$former_email est ambigu pour des raisons d'homonymie et signalera "
71 . "ton email exact.\n\nCordialement,\n-- \nl'équipe de Polytechnique.org"
72 . "\nLe portail des élèves & anciens élèves de l'École polytechnique";
73 }
74
75 function get_robot_mail_text(PlUser $user, $email)
76 {
77 $display_name = $user->displayName();
78 $former_email = $email . '@' . $user->mainEmailDomain();
79
80 return "$display_name,\n\nComme nous t'en avons informé par email il y a "
81 . "quelques temps, nous t'avons retiré de façon définitive l'adresse "
82 . "$former_email.\n\nToute personne qui écrit à $former_email reçoit "
83 . "la réponse d'un robot qui l'informe que $former_email est ambigu "
84 . "pour des raisons d'homonymie et indique ton email exact.\n\nTu peux "
85 . "faire l'essai toi-même en écrivant à $former_email.\n\nCordialement,"
86 . "\n-- \nl'équipe de Polytechnique.org"
87 . "\nLe portail des élèves & anciens élèves de l'École polytechnique";
88 }
89
90 function fix_homonym(PlUser $user, $email)
91 {
92 XDB::execute('DELETE FROM email_source_account
93 WHERE email = {?} AND type = \'alias\'',
94 $email);
95
96 $hrmid = User::makeHomonymHrmid($email);
97 XDB::execute('INSERT INTO email_source_other (hrmid, email, domain, type, expire)
98 SELECT {?}, {?}, id, \'homonym\', NOW()
99 FROM email_virtual_domains
100 WHERE name = {?}',
101 $hrmid, $email, $user->mainEmailDomain());
102 XDB::execute("INSERT INTO email_redirect_other (hrmid, redirect, type, action)
103 VALUES ({?}, '', 'homonym', 'homonym')",
104 $hrmid);
105
106
107 require_once 'emails.inc.php';
108 fix_bestalias($user);
109 }
110
111 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
112 ?>