Commit | Line | Data |
---|---|---|
0337d704 | 1 | <?php |
2 | /*************************************************************************** | |
12262f13 | 3 | * Copyright (C) 2003-2011 Polytechnique.org * |
0337d704 | 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 | ||
da2fff38 SJ |
22 | function select_if_homonym(PlUser $user) |
23 | { | |
4371e993 SJ |
24 | return XDB::fetchOneCell('SELECT email |
25 | FROM email_source_account | |
26 | WHERE uid = {?} AND expire IS NOT NULL', | |
191711d5 | 27 | $user->id()); |
0337d704 | 28 | } |
29 | ||
da2fff38 SJ |
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 | ||
1e33266a | 36 | $mymail = new PlMailer(); |
da2fff38 | 37 | $mymail->setFrom($from); |
0337d704 | 38 | $mymail->addCc($cc); |
da2fff38 SJ |
39 | $mymail->setSubject("Dans 1 semaine, suppression de $email@" . $user->mainEmailDomain()); |
40 | $mymail->setTxtBody($body); | |
191711d5 | 41 | $mymail->sendTo($user); |
0337d704 | 42 | } |
43 | ||
da2fff38 SJ |
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 | ||
1e33266a | 51 | $mymail = new PlMailer(); |
da2fff38 SJ |
52 | $mymail->setFrom($from); |
53 | $mymail->setSubject("Mise en place du robot $email@" . $user->mainEmailDomain()); | |
0337d704 | 54 | $mymail->addCc($cc); |
da2fff38 | 55 | $mymail->setTxtBody($body); |
191711d5 | 56 | $mymail->sendTo($user); |
0337d704 | 57 | } |
58 | ||
da2fff38 SJ |
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 | ||
a7de4ef7 | 111 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
0337d704 | 112 | ?> |