Skip to content
Snippets Groups Projects
Commit da502cc2 authored by Bob Mottram's avatar Bob Mottram
Browse files

Improve html tag removal from email

parent 64fd2605
No related branches found
No related tags found
No related merge requests found
......@@ -1960,17 +1960,51 @@ function remove_ip_addresses_from_email_logs {
cron_add_mins 1 '/usr/bin/exim_log_tidy'
}
function email_extract_headers {
email_headers_script='/usr/bin/email_headers.pl'
if [ ! -f "${email_headers_script}" ]; then
if $INSTALL_PACKAGES libhtml-strip-perl libhtml-parser-perl; then
{ echo '#!/usr/bin/perl';
echo 'use Mail::Header;';
echo "my \$head = Mail::Header->new( \\*STDIN );";
echo "print \$head->as_string();"; } > "${email_headers_script}"
chmod +x "${email_headers_script}"
fi
fi
}
function email_remove_html {
html_remove_script='/usr/bin/remove_html.pl'
email_extract_headers
html_remove_script='/usr/bin/remove_html'
if [ ! -f "${html_remove_script}" ]; then
if $INSTALL_PACKAGES libhtml-strip-perl; then
{ echo '#!/usr/bin/perl';
echo 'use HTML::Strip;';
echo "my \$hs = HTML::Strip->new();";
echo "my \$clean_text = \$hs->parse( <STDIN> );";
echo "\$hs->eof;";
echo "print \$clean_text;"; } > "${html_remove_script}"
chmod +x "${html_remove_script}"
if [ -f "${email_headers_script}" ]; then
if $INSTALL_PACKAGES libhtml-strip-perl libhtml-parser-perl lynx; then
{ echo '#!/bin/bash';
echo "email=\"\$(cat)\"";
echo '';
echo '# accept mail without any html content';
echo "if [[ \"\$email\" != *\"<html\"* ]]; then";
echo " echo \"\$email\"";
echo ' exit 0';
echo 'fi';
echo '';
echo '# accept html mail sent from this system';
echo "from_line=\$(echo \"\$email\" | grep 'From:' | head -n 1)";
echo "if [[ \"\$from_line\" == *\"\$(hostname)\"* ]]; then";
echo " echo \"\$email\"";
echo ' exit 0';
echo 'fi';
echo '';
echo '# remove html from mail';
echo "headers=\$(echo \"\$email\" | $email_headers_script)";
echo "headers_lines=\$(echo \"\$headers\" | wc -l)";
echo "email_body=\$(echo \"\$email\" | tail -n +\${headers_lines})";
echo "echo \"\$headers\"";
echo "echo \"\$email_body\" | lynx -dump -stdin | sed '/=0A/d'"; } > "${html_remove_script}"
chmod +x "${html_remove_script}"
fi
fi
fi
......
......@@ -153,7 +153,7 @@ if [ -d "$PROJECT_DIR" ]; then
android_update_apps yes
populate_keyservers
disable_email_encryption_at_rest
#email_remove_html
email_remove_html
if [ -f /var/log/freedns_@_update.log ]; then
rm /var/log/freedns_@_update.log
fi
......
......@@ -1198,8 +1198,8 @@ function setup_email {
function_check import_email
import_email
#function_check email_remove_html
#email_remove_html
function_check email_remove_html
email_remove_html
}
function setup_web {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment