Index: /trunk/pstamp/scripts/pstampparse.pl
===================================================================
--- /trunk/pstamp/scripts/pstampparse.pl	(revision 38159)
+++ /trunk/pstamp/scripts/pstampparse.pl	(revision 38160)
@@ -33,4 +33,7 @@
 my $dest_requires_magic;
 my $dump_params = 0;
+my $new_email;
+
+my %accessLevelCache;
 
 # set this to true to disable update processing
@@ -43,4 +46,5 @@
     'product=s' =>  \$product,
     'label=s'   =>  \$label,
+    'new_email=s' => \$new_email,
     'mode=s'    =>  \$mode,
     'need_magic'=>  \$dest_requires_magic,
@@ -142,7 +146,11 @@
     print STDERR "Note that EMAIL will not be optional\n";
 
+    # if need be we can hack Peter Veres' email in here if label = 'WEB.UP' and req_name like 'Peter_Veres%'
+
 } elsif (!$email) {
     my_die("ERROR: Required parameter EMAIL not found in request file header.\n", $PSTAMP_INVALID_REQUEST) 
 }
+
+
     
 
@@ -158,6 +166,4 @@
     my_die("email not supplied in version $extver request file $request_file_name\n", $PSTAMP_INVALID_REQUEST)
         unless $email;
-
-    # XXX check for "valid" $email
 } else {
     # for version 1 file the action is process and email is not used
@@ -167,4 +173,10 @@
 
 print "Request Header Keywords EXTVER: $extver REQ_NAME: $req_name ACTION: $action EMAIL: $email\n";
+
+if ($new_email) {
+    # this is primarily for ease in testing
+    print "Setting email to command line provided value $new_email\n";
+    $email = $new_email
+}
 
 # check for duplicate request name
@@ -239,5 +251,5 @@
 
 # if the request came through the upload channel, change it to the user's specific label
-# if any is known.
+# if any is known. Do we want to do this for any other channels?
 if ($label and $label eq 'WEB.UP') {
     if ($labelForUser) {
@@ -749,5 +761,6 @@
 
             if ($mjd > $mjd_max) {
-                print STDERR "User is not authorized for stamps from this exposure.\n";
+                print "User is not authorized for stamps from this exposure exp_id $exp_id.\n";
+                print STDERR "User is not authorized for stamps from this exposure exp_id $exp_id.\n";
                 insertFakeJobForRow($row, $job_num, $PSTAMP_NOT_AUTHORIZED, $exp_id);
                 return 1;
@@ -1343,15 +1356,33 @@
     my $adjusted = 0;
 
-    my $MJD_PS1_BEGIN = 54922;    # 2009-04-01
-    my $MJD_PS1_END   = 57082;    # 2015-03-01
-
-    if ($row->{accessLevel} == 1) {
-        # User has access to PS1 data only
-        my $mjd_max_user = $row->{MJD_MAX};
-        if (!$mjd_max_user or $mjd_max_user > $MJD_PS1_END) {
-            $$r_mjd_max = $MJD_PS1_END;
+    my $accessLevel = $row->{accessLevel};
+    my $project = $row->{PROJECT};
+    my $mjd_max_user = $row->{MJD_MAX};
+
+    my $key = "$project.$accessLevel";
+
+    my $levelInfo = $accessLevelCache{$key};
+
+    if (!$levelInfo) {
+        my $cmd = "$pstamptool -listaccesslevel -accessLevel $accessLevel -project_name $project";
+        my $results = runToolAndParse($cmd, $verbose);
+        if (!$results or !$results->[0]) {
+            my_die("failed to find accessLevel info for project: $project level: $accessLevel\n", $PS_EXIT_CONFIG_ERROR);
+        }
+        $levelInfo = $results->[0];
+        $accessLevelCache{$key} = $levelInfo;
+    }
+
+    my $mjd_max_thisLevel = $levelInfo->{mjd_max};
+    if ($mjd_max_thisLevel)  {
+        # This project has a limit for this level
+        # adjust the user supplied limit unless it is less than the maximum
+
+        if (!$mjd_max_user or ($mjd_max_user > $mjd_max_thisLevel)) {
+            $$r_mjd_max = $mjd_max_thisLevel;
             $adjusted = 1;
         }
     }
+
     return $adjusted;
 }
