[Rt-commit] r17912 - in rt/3.999/branches/merge_to_3.8.2: .

sunnavy at bestpractical.com sunnavy at bestpractical.com
Sun Jan 25 22:40:21 EST 2009


Author: sunnavy
Date: Sun Jan 25 22:40:21 2009
New Revision: 17912

Modified:
   rt/3.999/branches/merge_to_3.8.2/   (props changed)
   rt/3.999/branches/merge_to_3.8.2/sbin/rt-email-dashboards

Log:
 r19036 at sunnavys-mb:  sunnavy | 2009-01-26 11:03:17 +0800
 merged sbin/rt-email-dashboards


Modified: rt/3.999/branches/merge_to_3.8.2/sbin/rt-email-dashboards
==============================================================================
--- rt/3.999/branches/merge_to_3.8.2/sbin/rt-email-dashboards	(original)
+++ rt/3.999/branches/merge_to_3.8.2/sbin/rt-email-dashboards	Sun Jan 25 22:40:21 2009
@@ -143,6 +143,13 @@
             # if weekly, correct day of week?
             if ($subscription->sub_value('frequency') eq 'weekly') {
                 next if $subscription->sub_value('dow') ne $dow;
+                my $counter = $subscription->sub_value('counter') || 0;
+                my $fow       = $subscription->sub_value('Fow') || 1;
+                if ( $counter % $fow ) {
+                    $subscription->set_sub_values( counter => $counter+1 )
+                      unless $opts{'dryrun'};
+                    next;
+                }
             }
 
             # if monthly, correct day of month?
@@ -151,13 +158,24 @@
             }
         }
 
-        eval { send_dashboard($currentuser, $subscription) };
-        error 'Caught exception: ' . $@ if $@;
+        my $email = $subscription->sub_value('recipient')
+                 || $user->email;
+
+        eval { send_dashboard($currentuser, $email, $subscription) };
+        if ( $@ ) {
+            error 'Caught exception: ' . $@;
+        }
+        else {
+            $subscription->set_sub_values(
+                counter => $subscription->sub_value('counter') + 1 )
+              unless $opts{'dryrun'};
+        }
     }
 }
 
 sub send_dashboard {
-    my ($currentuser, $subscription) = @_;
+    my ($currentuser, $email, $subscription) = @_;
+    
 
     my $rows = $subscription->sub_value('rows');
 
@@ -207,7 +225,7 @@
     if ($opts{'dryrun'}) {
         print << "SUMMARY";
     Dashboard: @{[ $dashboard->name ]}
-    User:   @{[ $currentuser->name ]} <@{[ email_of($currentuser) ]}>
+    User:   @{[ $currentuser->name ]} <$email>
 SUMMARY
         return;
     }
@@ -216,7 +234,7 @@
     my $contents = run_component(
         '/Dashboards/Render.html',
         id      => $dashboard->id,
-        Preview => 0,
+        preview => 0,
     );
 
     for (@{ RT->config->get('EmailDashboardRemove') || [] }) {
@@ -230,11 +248,13 @@
         RT->config->get('WebURL') . '/Dashboards/Render.html',
     );
 
-    email_dashboard($currentuser, $dashboard, $subscription, $contents);
+    email_dashboard($currentuser, $email, $dashboard, $subscription, $contents);
+    
 }
 
 sub email_dashboard {
-    my ($currentuser, $dashboard, $subscription, $content) = @_;
+    my ($currentuser, $email, $dashboard, $subscription, $content) = @_;
+    
 
     verbose 'Sending dashboard "%1" to user %2 <%3>',
             $dashboard->name,
@@ -246,20 +266,18 @@
         ucfirst($subscription->sub_value('Frequency')),
         $dashboard->name;
 
-    my $entity = build_email(
-        $content, $from, email_of($currentuser), $subject,
-    );
+    my $entity = build_email($content, $from, $email, $subject);
 
     my $ok = RT::Interface::Email::send_email(
         entity => $entity,
     );
 
     debug "Done sending dashboard to %1 <%2>",
-          $currentuser->name, email_of($currentuser)
+          $currentuser->name, $email
               and return if $ok;
 
     error 'Failed to email dashboard to user %1 <%2>',
-          $currentuser->name, email_of($currentuser);
+          $currentuser->name, $email;
 }
 
 sub build_email {
@@ -276,6 +294,12 @@
             $cid_of{$uri} = time() . $$ . int(rand(1e6));
             my ($data, $filename, $mimetype, $encoding) = get_resource($uri);
 
+            # downgrade non-text strings, because all strings are utf8 by
+            # default, which is wrong for non-text strings.
+            if ( $mimetype !~ m{text/} ) {
+                utf8::downgrade( $data, 1 ) or warning "downgrade $data failed";
+            }
+
             push @parts, MIME::Entity->build(
                 Top          => 0,
                 Data         => $data,
@@ -316,13 +340,6 @@
     return $entity;
 }
 
-sub email_of {
-    my $user = shift;
-    return $user->email if $user->email;
-    return $user->name if $user->name =~ /\S@\S/;
-    return undef;
-}
-
 sub get_from {
     RT->config->get('DashboardAddress') || RT->config->get('OwnerEmail')
 }
@@ -442,6 +459,13 @@
         $mimetype,
         $encoding;
 
+    debug "Resource %1: length=%2 filename='%3' mimetype='%4', encoding='%5'",
+        $uri,
+        length($content),
+        $filename,
+        $mimetype,
+        $encoding;
+
     return ($content, $filename, $mimetype, $encoding);
 }
 


More information about the Rt-commit mailing list