[Rt-commit] rt branch 5.0/dashboard-inline-css created. rt-5.0.3-86-gd111d362ee

BPS Git Server git at git.bestpractical.com
Thu Aug 25 18:44:21 UTC 2022


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "rt".

The branch, 5.0/dashboard-inline-css has been created
        at  d111d362ee4f793d0537870539a82a7957ad104d (commit)

- Log -----------------------------------------------------------------
commit d111d362ee4f793d0537870539a82a7957ad104d
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Fri Aug 26 01:56:24 2022 +0800

    Add extra css to dashboard emails for limited email web clients
    
    Email web clients(like Gmail and Outlook) don't 100% support "flex"
    layout for now, e.g. it strips out "flex-direction: column", which could
    cause widget title and body to render horizontally instead of
    vertically.
    
    This commit gets around the issue by setting related display to "block"
    instead.

diff --git a/share/html/NoAuth/css/elevator-light/InHeader b/share/html/NoAuth/css/elevator-light/InHeader
index 5d5a738cc5..fe7b565742 100644
--- a/share/html/NoAuth/css/elevator-light/InHeader
+++ b/share/html/NoAuth/css/elevator-light/InHeader
@@ -46,3 +46,6 @@
 %#
 %# END BPS TAGGED BLOCK }}}
 <meta name="viewport" content="width=device-width, initial-scale=1.0">
+% if ( $m->request_path eq '/Dashboards/Render.html' && !$m->request_args->{Preview} ) {
+  <link rel="stylesheet" href="<% RT->Config->Get('WebPath') %>/static/css/elevator-light/mail.css" type="text/css" media="all" />
+% }
diff --git a/share/static/css/elevator-light/mail.css b/share/static/css/elevator-light/mail.css
new file mode 100644
index 0000000000..0fb924ef5b
--- /dev/null
+++ b/share/static/css/elevator-light/mail.css
@@ -0,0 +1,5 @@
+/* Gmail and Outlook web ui remove "flex-direction: column", which breaks
+   the layout of widget title and body. */
+.card {
+  display: block;
+}

commit 4bed2295af72566cda03e88a100696c96fba91c9
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Thu Aug 25 00:32:18 2022 +0800

    Exclude the favion.png link from generated dashboard email
    
    It's not going to load in an email and causes email clients to flag
    "loading external content", which looks spammy.

diff --git a/lib/RT/Dashboard/Mailer.pm b/lib/RT/Dashboard/Mailer.pm
index 03f1325f78..ae642d3905 100644
--- a/lib/RT/Dashboard/Mailer.pm
+++ b/lib/RT/Dashboard/Mailer.pm
@@ -622,6 +622,15 @@ sub BuildEmail {
             );
             # ... and <script>s
             $scrubber->deny('script');
+
+            # ... and the favicon image
+            $scrubber->rules(
+                link => {
+                    href => qr{(?<!favicon\.png)$},
+                    '*'  => 1,
+                },
+            );
+
         }
         return $scrubber;
     }

commit 342cdf55115d0e0e7900a9a9e8cdfa074d3c385f
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Tue Aug 23 13:22:38 2022 -0400

    Add option to inline CSS for dashboard email
    
    In tests with a simple dashboard, converting to inline CSS
    reduces the size of the generated dashboard email from
    ~500k to ~50k. As noted in the docs, the new rendered HTML
    in the email is not 100% the same as the RT version.

diff --git a/etc/RT_Config.pm.in b/etc/RT_Config.pm.in
index bd9c001d28..60dbbf0c96 100644
--- a/etc/RT_Config.pm.in
+++ b/etc/RT_Config.pm.in
@@ -888,6 +888,25 @@ See also L</@LexiconLanguages>.
 
 Set(@EmailDashboardLanguageOrder, qw(_subscription _recipient _subscriber en));
 
+=item C<$EmailDashboardInlineCSS>
+
+To get styling to render in email clients, emailed dashboards have all
+included CSS added to the HTML in C<style> tags. This makes the email
+formatting look very much like the corresponding RT page, but it also
+makes the emails very large. They can be large enough that some email
+servers will trim content because of the size.
+
+To reduce the size of the emails, you can install the optional module
+C<CSS::Inliner> and enable the C<$InlineDashboardCSS> option. When
+enabled, styles will be applied directly to the HTML in the email and
+the large C<style> sections are removed. This significantly reduces
+the size of dashboard emails at the cost of some detail in the styling.
+With this enabled, some parts of the email won't look exactly like RT.
+
+=cut
+
+Set($EmailDashboardInlineCSS, 0);
+
 =back
 
 
diff --git a/lib/RT/Config.pm b/lib/RT/Config.pm
index b659fbc291..0259ff7996 100644
--- a/lib/RT/Config.pm
+++ b/lib/RT/Config.pm
@@ -1894,6 +1894,9 @@ our %META;
     DashboardSubject => {
         Widget => '/Widgets/Form/String',
     },
+    EmailDashboardInlineCSS => {
+        Widget => '/Widgets/Form/Boolean',
+    },
     DefaultErrorMailPrecedence => {
         Widget => '/Widgets/Form/String',
     },
diff --git a/lib/RT/Dashboard/Mailer.pm b/lib/RT/Dashboard/Mailer.pm
index 5eca55a391..03f1325f78 100644
--- a/lib/RT/Dashboard/Mailer.pm
+++ b/lib/RT/Dashboard/Mailer.pm
@@ -530,6 +530,23 @@ sub BuildEmail {
         inline_imports => 1,
     );
 
+    # Inline the CSS if CSS::Inliner is installed and can be loaded
+    if ( RT->Config->Get('EmailDashboardInlineCSS') ) {
+        if ( CSS::Inliner->require ) {
+            # HTML::Query generates a ton of warnings about unsupported
+            # pseudoclasses. Suppress those since they don't help the person
+            # running RT.
+            local $SIG{__WARN__} = sub {};
+
+            my $inliner = CSS::Inliner->new;
+            $inliner->read({ html => $content });
+            $content = $inliner->inlinify();
+        }
+        else {
+            RT->Logger->warn('EmailDashboardInlineCSS is enabled but CSS::Inliner is not installed. Install the optional module CSS::Inliner to use this feature.');
+        }
+    }
+
     my $entity = MIME::Entity->build(
         From    => Encode::encode("UTF-8", $args{From}),
         To      => Encode::encode("UTF-8", $args{To}),

-----------------------------------------------------------------------


hooks/post-receive
-- 
rt


More information about the rt-commit mailing list