Changed to report multiple emails send in the same minute
authorAndrew DeFaria <Andrew@DeFaria.com>
Fri, 20 Oct 2017 06:09:13 +0000 (23:09 -0700)
committerAndrew DeFaria <Andrew@DeFaria.com>
Fri, 20 Oct 2017 06:09:13 +0000 (23:09 -0700)
maps/bin/MAPSDB.pm
maps/bin/MAPSUtil.pm
maps/bin/detail.cgi

index 23911c7..6fa6e9b 100644 (file)
@@ -996,27 +996,17 @@ END
 sub ReturnMessages ($$) {
   my ($userid, $sender) = @_;
 
-  # Note, the left(timestamp,16) chops off the seconds and the group
-  # by effectively squashes two emails received in the same minute to
-  # just one. We get a lot of double emails within the same minute. I
-  # think it's a result of the mailer configuration and it attempting
-  # to resend the message, not that it's the spammer sending just two
-  # emails in under a minute then going away. This will mean we will
-  # see fewer emails listed (essentially dups within one minute are
-  # squashed) yet they still will count towards the number of hits
-  # before we autonullist. We should squash these upon receipt, not
-  # upon report. Maybe latter...
   my $statement = <<"END";
 select
   subject,
-  left(timestamp,16)
+  timestamp
 from
   email
 where
   userid = '$userid' and
   sender = '$sender'
 group by
-  left(timestamp,16) desc
+  timestamp desc
 END
 
   my $sth = $DB->prepare ($statement)
index 0d234d2..2298d77 100644 (file)
@@ -2,7 +2,7 @@
 ################################################################################
 #
 # File:         $RCSfile: MAPSUtil.pm,v $
-# Revision:    $Revision: 1.1 $
+# Revision:     $Revision: 1.1 $
 # Description:  MAPS Utilities
 # Author:       Andrew@DeFaria.com
 # Created:      Fri Nov 29 14:17:21  2002
@@ -28,65 +28,57 @@ use vars qw (@ISA @EXPORT);
   UnixDatetime2SQLDatetime
 );
 
-# Forwards
-sub FormatDate;
-sub FormatTime;
-sub SQLDatetime2UnixDatetime;
-sub SubtractDays;
 sub Today2SQLDatetime;
-sub UnixDatetime2SQLDatetime;
 
 sub FormatDate {
-  my $date = shift;
+  my ($date) = @_;
 
-  return substr ($date, 5, 2)  .
-         "/"                   .
-        substr ($date, 8, 2)   .
-        "/"                    .
-         substr ($date, 0, 4);
+  return substr $date, 5, 2  . '/' .
+         substr $date, 8, 2  . '/' .
+         substr $date, 0, 4;
 } # FormatDate
 
 sub FormatTime {
-  my $time = shift;
+  my ($time) = @_;
 
-  my $hours    = substr $time, 0, 2;
-  my $minutes  = substr $time, 3, 2;
-  my $AmPm     = $hours > 12 ? "Pm" : "Am";
+  my $hours   = substr $time, 0, 2;
+  my $minutes = substr $time, 3, 2;
+  my $seconds = substr $time, 6, 2;
+  my $AmPm    = $hours > 12 ? 'Pm' : 'Am';
 
   $hours = $hours - 12 if $hours > 12;
 
-  return "$hours:$minutes $AmPm";
+  return "$hours:$minutes:$seconds $AmPm";
 } # FormatTime
 
 sub SQLDatetime2UnixDatetime {
-  my $sqldatetime = shift;
+  my ($sqldatetime) = @_;
 
   my %months = (
-    "01" => "Jan",
-    "02" => "Feb",
-    "03" => "Mar",
-    "04" => "Apr",
-    "05" => "May",
-    "06" => "Jun",
-    "07" => "Jul",
-    "08" => "Aug",
-    "09" => "Sep",
-    "10" => "Oct",
-    "11" => "Nov",
-    "12" => "Dec"
+    '01' => 'Jan',
+    '02' => 'Feb',
+    '03' => 'Mar',
+    '04' => 'Apr',
+    '05' => 'May',
+    '06' => 'Jun',
+    '07' => 'Jul',
+    '08' => 'Aug',
+    '09' => 'Sep',
+    '10' => 'Oct',
+    '11' => 'Nov',
+    '12' => 'Dec',
   );
 
   my $year  = substr $sqldatetime, 0, 4;
   my $month = substr $sqldatetime, 5, 2;
   my $day   = substr $sqldatetime, 8, 2;
-  my $time  = FormatTime (substr $sqldatetime, 11);
+  my $time  = FormatTime substr $sqldatetime, 11;
 
   return $months {$month} . " $day, $year \@ $time";
 } # SQLDatetime2UnixDatetime
 
 sub SubtractDays {
-  my $timestamp   = shift;
-  my $nbr_of_days = shift;
+  my ($timestamp,$nbr_of_days) = @_;
 
   my @months = (
     31, # January
@@ -111,11 +103,11 @@ sub SubtractDays {
   my $days = 0;
   my $m    = 1;
 
-  foreach (@months) {
+  for (@months) {
     last if $m >= $month;
     $m++;
     $days += $_;
-  } # foreach
+  } # for
 
   # Subtract $nbr_of_days
   $days += $day - $nbr_of_days;
@@ -146,61 +138,57 @@ sub SubtractDays {
   # Prefix month with 0 if necessary
   $month++;
   if ($month < 10) {
-    $month = "0" . $month;
+    $month = '0' . $month;
   } # if
 
   # Prefix days with  0 if necessary
   if ($days eq 0) { 
-      $days = "01";
+      $days = '01';
   } elsif ($days < 10) {
-    $days = "0" . $days;
+    $days = '0' . $days;
   } # if  
 
-  return $year . "-" . $month . "-" . $days . substr $timestamp, 10;
+  return $year . '-' . $month . '-' . $days . substr $timestamp, 10;
 } # SubtractDays
 
-sub Today2SQLDatetime {
-  return UnixDatetime2SQLDatetime (scalar (localtime));
-} # Today2SQLDatetime
-
 sub UnixDatetime2SQLDatetime {
   my $datetime = shift;
 
   my $orig_datetime = $datetime;
   my %months = (
-    "Jan" => "01",
-    "Feb" => "02",
-    "Mar" => "03",
-    "Apr" => "04",
-    "May" => "05",
-    "Jun" => "06",
-    "Jul" => "07",
-    "Aug" => "08",
-    "Sep" => "09",
-    "Oct" => "10",
-    "Nov" => "11",
-    "Dec" => "12"
+    'Jan' => '01',
+    'Feb' => '02',
+    'Mar' => '03',
+    'Apr' => '04',
+    'May' => '05',
+    'Jun' => '06',
+    'Jul' => '07',
+    'Aug' => '08',
+    'Sep' => '09',
+    'Oct' => '10',
+    'Nov' => '11',
+    'Dec' => '12',
   );
 
   # Some mailers neglect to put the leading day of the week field in.
   # Check for this and compensate.
   my $dow = substr $datetime, 0, 3;
 
-  if ($dow ne "Mon" &&
-      $dow ne "Tue" &&
-      $dow ne "Wed" &&
-      $dow ne "Thu" &&
-      $dow ne "Fri" &&
-      $dow ne "Sat" &&
-      $dow ne "Sun") {
-    $datetime = "XXX, " . $datetime;
+  if ($dow ne 'Mon' &&
+      $dow ne 'Tue' &&
+      $dow ne 'Wed' &&
+      $dow ne 'Thu' &&
+      $dow ne 'Fri' &&
+      $dow ne 'Sat' &&
+      $dow ne 'Sun') {
+    $datetime = 'XXX, ' . $datetime;
   } # if
 
   # Some mailers have day before month. We need to correct this
   my $day = substr $datetime, 5, 2;
 
   if ($day =~ /\d /) {
-    $day = "0" . (substr $day, 0, 1);
+    $day = '0' . (substr $day, 0, 1);
     $datetime = (substr $datetime, 0, 5) . $day . (substr $datetime, 6);
   } # if
 
@@ -209,8 +197,8 @@ sub UnixDatetime2SQLDatetime {
   } # if
 
   # Check for 1 digit date
-  if ((substr $day, 0, 1) eq " ") {
-    $day = "0" . (substr $day, 1, 1);
+  if ((substr $day, 0, 1) eq ' ') {
+    $day = '0' . (substr $day, 1, 1);
     $datetime = (substr $datetime, 0, 8) . $day . (substr $datetime, 10);
   } # if
 
@@ -224,9 +212,9 @@ sub UnixDatetime2SQLDatetime {
   } # if
 
   # Check for 2 digit year. Argh!
-  if (length $year == 2 or (substr $year, 2, 1) eq " ") {
-      $year = "20" . (substr $year, 0, 2);
-      $datetime = (substr $datetime, 0, 12) . "20" . (substr $datetime, 12);
+  if (length $year == 2 or (substr $year, 2, 1) eq ' ') {
+      $year = '20' . (substr $year, 0, 2);
+      $datetime = (substr $datetime, 0, 12) . '20' . (substr $datetime, 12);
   } # if
 
   my $month_name = substr $datetime, 4, 3;
@@ -262,4 +250,8 @@ sub UnixDatetime2SQLDatetime {
   return "$year-$month-$day $time";
 } # UnixDatetime2SQLDatetime
 
+sub Today2SQLDatetime {
+  return UnixDatetime2SQLDatetime scalar localtime;
+} # Today2SQLDatetime
+
 1;
index 7631983..b90f13d 100755 (executable)
@@ -171,6 +171,7 @@ sub PrintTable {
 
   foreach my $sender (ReturnSenders $userid, $type, $next, $lines, $date) {
     my @msgs = ReturnMessages $userid, $sender;
+    my @msgs2 = @msgs;
 
     $next++;
     print
@@ -191,12 +192,12 @@ sub PrintTable {
                    -width       => '100%',
                    -bgcolor     => '#d4d0c8'};
     print
-      td {-class => 'tablelabel',
-          -valign => 'middle',
-          -width  => '40'}, 'Sender:',
-      td {-class  => 'sender',
-          -valign => 'middle'},
-      a {-href    => "mailto:$sender"}, $sender;
+      td {-class   => 'tablelabel',
+          -valign  => 'middle',
+          -width   => '40'}, 'Sender:',
+      td {-class   => 'sender',
+          -valign  => 'middle'},
+        a {-href   => "mailto:$sender?subject=$msgs2[0][0]"}, $sender;
     print
       end_table;