Enables @polytechnique.edu adresses for old promotions (Closes #1516)
authorBrice Gelineau <brice.gelineau@polytechnique.org>
Tue, 27 Sep 2011 13:34:07 +0000 (15:34 +0200)
committerBrice Gelineau <brice.gelineau@polytechnique.org>
Tue, 27 Sep 2011 13:35:31 +0000 (15:35 +0200)
Signed-off-by: Brice Gelineau <brice.gelineau@polytechnique.org>
ChangeLog
include/emails.inc.php
modules/admin.php
modules/lists.php
modules/marketing.php
modules/register.php

index 1597f01..9f47e10 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -19,6 +19,7 @@ Bug/Wish:
 
     * Email:
         - #1529: Stores and uses preferences for sending emails from site  -JAC
+        - #1516: Enables @polytechnique.edu adresses for old promotions    -GLN
 
     * Newsletter:
         - #1509: Adds a Reply-To field for newsletters                     -GLN
index 1e32840..bd24d3e 100644 (file)
@@ -298,11 +298,17 @@ function valide_email($str)
 // function isvalid_email_redirection() {{{1
 /** Checks if an email is a suitable redirection.
  * @param $email the email to check
+ * @param $user  the user asking for the redirection
  * @return BOOL
  */
-function isvalid_email_redirection($email)
+function isvalid_email_redirection($email, User $user)
 {
-    return isvalid_email($email) && !preg_match("/@polytechnique\.edu$/", $email) && User::isForeignEmailAddress($email);
+    $valid = isvalid_email($email) && User::isForeignEmailAddress($email);
+    if (!$user->hasProfile() || ($user->profile()->grad_year > date('Y') - 3)) {
+        return $valid && !preg_match("/@polytechnique\.edu$/", $email);
+    } else {
+        return $valid;
+    }
 }
 
 // function ids_from_mails() {{{1
@@ -785,7 +791,7 @@ class Redirect
         if (!isvalid_email($email_stripped)) {
             return ERROR_INVALID_EMAIL;
         }
-        if (!isvalid_email_redirection($email_stripped)) {
+        if (!isvalid_email_redirection($email_stripped, $this->user)) {
             return ERROR_LOOP_EMAIL;
         }
         // We first need to retrieve the value for the antispam filter: it is
index c6a9852..ed0f84a 100644 (file)
@@ -592,7 +592,7 @@ class AdminModule extends PLModule
         $redirect = ($registered ? new Redirect($user) : null);
         if (Post::has('add_fwd')) {
             $email = Post::t('email');
-            if (!isvalid_email_redirection($email)) {
+            if (!isvalid_email_redirection($email, $user)) {
                 $page->trigError("Email non valide: $email");
             } else {
                 $redirect->add_email($email);
index f73598f..546b572 100644 (file)
@@ -618,8 +618,9 @@ class ListsModule extends PLModule
 
                   case 'marketu': case 'markets':
                     require_once 'emails.inc.php';
+                    $user = User::get($uids[$key]);
                     $mail = valide_email($mails[$key]);
-                    if (isvalid_email_redirection($mail)) {
+                    if (isvalid_email_redirection($mail, $user)) {
                         $from = ($action == 'marketu') ? 'user' : 'staff';
                         $market = Marketing::get($uids[$key], $mail);
                         if (!$market) {
index d1d8372..ac5cff5 100644 (file)
@@ -237,7 +237,7 @@ class MarketingModule extends PLModule
         if (Post::has('mail')) {
             $email = valide_email(Post::v('mail'));
         }
-        if (Post::has('valide') && isvalid_email_redirection($email)) {
+        if (Post::has('valide') && isvalid_email_redirection($email, $user)) {
             S::assert_xsrf_token();
 
             // security stuff
@@ -303,7 +303,7 @@ class MarketingModule extends PLModule
             $email = trim(Post::v('mail'));
 
             require_once 'emails.inc.php';
-            if (!isvalid_email_redirection($email)) {
+            if (!isvalid_email_redirection($email, $user)) {
                 $page->trigError('Email invalide&nbsp;!');
             } else {
                 // On cherche les marketings précédents sur cette adresse
index d2825dd..f385466 100644 (file)
@@ -157,9 +157,10 @@ class RegisterModule extends PLModule
                     // Validate the email address format and domain.
                     require_once 'emails.inc.php';
 
+                    $user = User::get($subState->s('uid'));
                     if (!isvalid_email(Post::v('email'))) {
                         $error[] = "Le champ 'Email' n'est pas valide.";
-                    } elseif (!isvalid_email_redirection(Post::v('email'))) {
+                    } elseif (!isvalid_email_redirection(Post::v('email'), $user)) {
                         $error[] = $subState->s('forlife') . ' doit renvoyer vers un email existant '
                                  . 'valide, en particulier, il ne peut pas être renvoyé vers lui-même.';
                     }