@@ -181,8 +181,7 @@ public function run($args = [])
181181 }
182182 // html warning with a button to load the file anyway
183183 else {
184- $ rcmail ->output = new rcmail_html_page ();
185- $ rcmail ->output ->register_inline_warning (
184+ $ inline_warning = $ this ->make_inline_warning (
186185 $ rcmail ->gettext ([
187186 'name ' => 'attachmentvalidationerror ' ,
188187 'vars ' => [
@@ -193,8 +192,7 @@ public function run($args = [])
193192 $ rcmail ->gettext ('showanyway ' ),
194193 $ rcmail ->url (array_merge ($ _GET , ['_nocheck ' => 1 ]))
195194 );
196-
197- $ rcmail ->output ->write ();
195+ $ this ->send_html ('' , $ inline_warning );
198196 }
199197
200198 $ rcmail ->output ->sendExit ();
@@ -223,7 +221,7 @@ public function run($args = [])
223221 // embed.css and blocks loading other css files (though calling
224222 // reset() in write()). Also we don't need all the processing that it
225223 // brings.
226- $ styles_path = $ rcmail ->output ->get_skin_file ('/styles/styles.css ' , $ path , null , true );
224+ $ styles_path = $ rcmail ->output ->get_skin_file ('/styles/styles.css ' );
227225 $ body = html::tag ('html ' , [],
228226 html::tag ('head ' , [], html::tag ('link ' , ['rel ' => 'stylesheet ' , 'href ' => $ styles_path ]))
229227 . html::tag ('body ' , [], $ body )
@@ -233,24 +231,19 @@ public function run($args = [])
233231
234232 // deliver part content
235233 if ($ mimetype == 'text/html ' && empty ($ _GET ['_download ' ])) {
236- $ rcmail ->output = new rcmail_html_page ();
237- $ out = '' ;
238-
239234 // Check if we have enough memory to handle the message in it
240235 // #1487424: we need up to 10x more memory than the body
241236 if (!rcube_utils::mem_check ($ attachment ->size * 10 )) {
242- $ rcmail -> output -> register_inline_warning (
237+ $ inline_warning = $ this -> make_inline_warning (
243238 $ rcmail ->gettext ('messagetoobig ' ),
244239 $ rcmail ->gettext ('download ' ),
245240 $ rcmail ->url (array_merge ($ _GET , ['_download ' => 1 ]))
246241 );
242+ $ this ->send_html ('' , $ inline_warning );
247243 } else {
248244 // render HTML body
249- $ out = $ attachment ->html ();
245+ $ this -> send_html ( $ attachment ->html () );
250246 }
251-
252- $ rcmail ->output ->write ($ out );
253- $ rcmail ->output ->sendExit ();
254247 }
255248
256249 // add filename extension if missing
@@ -355,4 +348,62 @@ public static function message_part_frame($attrib)
355348
356349 return html::iframe ($ attrib );
357350 }
351+
352+ /**
353+ * @param $contents string Content to send as HTTP body
354+ * @param $inline_warning string Something to inject into the beginning of the content
355+ */
356+ protected function send_html ($ contents , $ inline_warning = null ): void
357+ {
358+ $ rcmail = rcmail::get_instance ();
359+ $ rcmail ->output ->reset (true );
360+
361+ // load embed.css from skin folder (if exists)
362+ $ embed_css = $ rcmail ->config ->get ('embed_css_location ' , '/embed.css ' );
363+ if ($ embed_css = $ rcmail ->output ->get_skin_file ($ embed_css )) {
364+ $ rcmail ->output ->include_css ($ embed_css );
365+ } else { // set default styles for warning blocks inside the attachment part frame
366+ $ rcmail ->output ->add_header (html::tag ('style ' , ['type ' => 'text/css ' ],
367+ '.rcmail-inline-message { font-family: sans-serif; border:2px solid #ffdf0e; '
368+ . "background:#fef893; padding:0.6em 1em; margin-bottom:0.6em } \n" .
369+ '.rcmail-inline-buttons { margin-bottom:0 } '
370+ ));
371+ }
372+
373+ if (empty ($ contents )) {
374+ $ contents = '<html><body></body></html> ' ;
375+ }
376+
377+ if ($ inline_warning ) {
378+ $ body_start = 0 ;
379+ if ($ body_pos = strpos ($ contents , '<body ' )) {
380+ $ body_start = strpos ($ contents , '> ' , $ body_pos ) + 1 ;
381+ }
382+
383+ $ contents = substr_replace ($ contents , $ inline_warning , $ body_start , 0 );
384+ }
385+
386+ $ rcmail ->output ->write_blank_slate ($ contents );
387+ $ rcmail ->output ->sendExit ();
388+ }
389+
390+ /**
391+ * @param $text string Text content
392+ * @param $button_label string Text for the optional button to append to the content
393+ * @param $button_url string URL of the button
394+ *
395+ * @return string HTML code as string
396+ */
397+ protected function make_inline_warning ($ text , $ button_label = null , $ button_url = null ): string
398+ {
399+ $ text = html::span (null , $ text );
400+
401+ if ($ button_label ) {
402+ $ onclick = "location.href = ' {$ button_url }' " ;
403+ $ button = html::tag ('button ' , ['onclick ' => $ onclick ], rcube::Q ($ button_label ));
404+ $ text .= html::p (['class ' => 'rcmail-inline-buttons ' ], $ button );
405+ }
406+
407+ return html::div (['class ' => 'rcmail-inline-message rcmail-inline-warning ' ], $ text );
408+ }
358409}
0 commit comments