[Rt-commit] rt branch 5.0/dashboard-inline-css created. rt-5.0.3-84-gfaaa782b47
BPS Git Server
git at git.bestpractical.com
Tue Aug 23 18:28:35 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 faaa782b475404ef93301fffc5522fda15254d3c (commit)
- Log -----------------------------------------------------------------
commit faaa782b475404ef93301fffc5522fda15254d3c
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..31c19e7b20 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::Inline 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