From 5dba7b2b39f9d519b813458adfa72980da14a6cd Mon Sep 17 00:00:00 2001 From: Jamie Cameron Date: Wed, 17 Nov 2010 13:58:18 -0800 Subject: [PATCH] Allow character set for autoreply message to be chosen. https://www.virtualmin.com/node/16309 --- filter/autoreply-file-lib.pl | 6 ++++++ filter/edit.cgi | 3 +++ filter/edit_auto.cgi | 5 +++++ filter/lang/en | 3 +++ filter/save.cgi | 9 +++++++++ filter/save_auto.cgi | 10 ++++++++++ sendmail/autoreply.pl | 5 ++++- 7 files changed, 40 insertions(+), 1 deletion(-) diff --git a/filter/autoreply-file-lib.pl b/filter/autoreply-file-lib.pl index 8d9324881..d31ac6583 100755 --- a/filter/autoreply-file-lib.pl +++ b/filter/autoreply-file-lib.pl @@ -32,6 +32,9 @@ while() { elsif (/^From:\s*(.*)/) { $simple->{'from'} = $1; } + elsif (/^Charset:\s*(\S+)/) { + $simple->{'charset'} = $1; + } else { push(@lines, $_); } @@ -75,6 +78,9 @@ if ($simple->{'autoreply_end'}) { if ($simple->{'from'}) { &print_tempfile(AUTO, "From: $simple->{'from'}\n"); } +if ($simple->{'charset'}) { + &print_tempfile(AUTO, "Charset: $simple->{'charset'}\n"); + } &print_tempfile(AUTO, $simple->{'autotext'}); &close_tempfile(AUTO); } diff --git a/filter/edit.cgi b/filter/edit.cgi index b06d40414..05617c631 100755 --- a/filter/edit.cgi +++ b/filter/edit.cgi @@ -216,6 +216,9 @@ print &ui_table_row( "".&ui_date_input($etm[3], $etm[4], $etm[5], "dend", "mend", "yend")." ". &date_chooser_button("dend", "mend", "yend")." \n". + " $text{'index_charset'} ". + "".&ui_opt_textbox("charset", $r->{'charset'}, 20, + $text{'default'}." (iso-8859-1)")." \n". "", undef, \@tds); diff --git a/filter/edit_auto.cgi b/filter/edit_auto.cgi index 93ce969f0..4dc6bcda0 100755 --- a/filter/edit_auto.cgi +++ b/filter/edit_auto.cgi @@ -28,6 +28,11 @@ print &ui_table_row($text{'auto_reply'}, &ui_textarea("reply", $filter->{'reply'}->{'autotext'}, 5, 80, undef, $dis)); +# Character set +print &ui_table_row($text{'auto_charset'}, + &ui_opt_textbox("charset", $filter->{'reply'}->{'charset'}, 20, + $text{'default'}." (iso-8859-1)")); + # Period if (!$config{'reply_force'}) { $r = $filter->{'reply'}; diff --git a/filter/lang/en b/filter/lang/en index 097594c1f..4b5c13870 100644 --- a/filter/lang/en +++ b/filter/lang/en @@ -39,6 +39,7 @@ index_noperiod=No minimum index_mins=minutes index_astart=Don't send autoreply before index_aend=Don't send autoreply after +index_charset=Autoreply message character set index_nowebmin=This module is only for use in Usermin. If it is visible in Webmin, the theme you are using is incomplete. edit_title1=Create Filter @@ -81,6 +82,7 @@ save_enewfolder2=Invalid new folder name save_enewfolder3=A folder with the same name already exists save_estart=Invalid autoreply start date save_eend=Invalid autoreply end date +save_echarset=Missing or invalid autoreply character set delete_err=Failed to delete filters delete_enone=None selected @@ -100,6 +102,7 @@ auto_title=Email Automatic Reply auto_header=Automatic email reply options auto_enabled=Automatic response enabled? auto_reply=Reply message +auto_charset=Message character set auto_period=Minimum interval between replies auto_err=Failed to save automatic reply diff --git a/filter/save.cgi b/filter/save.cgi index 0d5f5012e..bbdcfc9b4 100755 --- a/filter/save.cgi +++ b/filter/save.cgi @@ -178,6 +178,15 @@ else { delete($filter->{'reply'}->{'autoreply_'.$p}); } } + # Save character set + if ($in{'charset_def'}) { + delete($filter->{'reply'}->{'charset'}); + } + else { + $in{'charset'} =~ /^[a-z0-9\.\-\_]+$/i || + error($text{'save_echarset'}); + $filter->{'reply'}->{'charset'} = $in{'charset'}; + } } elsif ($in{'amode'} == 7) { # Create a new folder for saving (always in Maildir format) diff --git a/filter/save_auto.cgi b/filter/save_auto.cgi index 458127485..6dff3fedf 100755 --- a/filter/save_auto.cgi +++ b/filter/save_auto.cgi @@ -62,6 +62,16 @@ elsif ($in{'enabled'}) { "$user_module_config_directory/replies"; } + # Save character set + if ($in{'charset_def'}) { + delete($filter->{'reply'}->{'charset'}); + } + else { + $in{'charset'} =~ /^[a-z0-9\.\-\_]+$/i || + error($text{'save_echarset'}); + $filter->{'reply'}->{'charset'} = $in{'charset'}; + } + if ($old) { &modify_filter($filter); } diff --git a/sendmail/autoreply.pl b/sendmail/autoreply.pl index 56a63a8f0..d67b684b6 100755 --- a/sendmail/autoreply.pl +++ b/sendmail/autoreply.pl @@ -232,15 +232,18 @@ foreach $f (@files) { # Work out the content type and encoding $type = $rbody =~ /]*>|]*>/i ? "text/html" : "text/plain"; +$cs = $rheader{'Charset'}; +delete($rheader{'Charset'}); if ($rbody =~ /[\177-\377]/) { # High-ascii $enc = "quoted-printable"; $encrbody = "ed_encode($rbody); - $type .= "; charset=iso-8859-1"; + $type .= "; charset=".($cs || "iso-8859-1"); } else { $enc = undef; $encrbody = $rbody; + $type .= "; charset=$cs" if ($cs); } # run sendmail and feed it the reply