Allow character set for autoreply message to be chosen.
authorJamie Cameron <jcameron@webmin.com>
Wed, 17 Nov 2010 21:58:18 +0000 (13:58 -0800)
committerJamie Cameron <jcameron@webmin.com>
Wed, 17 Nov 2010 21:58:18 +0000 (13:58 -0800)
https://www.virtualmin.com/node/16309

filter/autoreply-file-lib.pl
filter/edit.cgi
filter/edit_auto.cgi
filter/lang/en
filter/save.cgi
filter/save_auto.cgi
sendmail/autoreply.pl

index 8d93248..d31ac65 100755 (executable)
@@ -32,6 +32,9 @@ while(<FILE>) {
        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);
 }
index b06d404..05617c6 100755 (executable)
@@ -216,6 +216,9 @@ print &ui_table_row(
        "<td>".&ui_date_input($etm[3], $etm[4], $etm[5],
                               "dend", "mend", "yend")." ".
             &date_chooser_button("dend", "mend", "yend")."</td> </tr>\n".
+       "<tr> <td><b>$text{'index_charset'}</b></td> ".
+       "<td>".&ui_opt_textbox("charset", $r->{'charset'}, 20,
+                      $text{'default'}." (iso-8859-1)")."</td> </tr>\n".
        "</table>",
        undef, \@tds);
 
index 93ce969..4dc6bcd 100755 (executable)
@@ -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'};
index 097594c..4b5c138 100644 (file)
@@ -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
 
index 0d5f501..bbdcfc9 100755 (executable)
@@ -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)
index 4581274..6dff3fe 100755 (executable)
@@ -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);
                }
index 56a63a8..d67b684 100755 (executable)
@@ -232,15 +232,18 @@ foreach $f (@files) {
 
 # Work out the content type and encoding
 $type = $rbody =~ /<html[^>]*>|<body[^>]*>/i ? "text/html" : "text/plain";
+$cs = $rheader{'Charset'};
+delete($rheader{'Charset'});
 if ($rbody =~ /[\177-\377]/) {
        # High-ascii
        $enc = "quoted-printable";
        $encrbody = &quoted_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