#!/usr/local/bin/perl
# Display a form for replying to or composing an email
require './mailboxes-lib.pl';
&ReadParse();
&can_user($in{'user'}) || &error($text{'mail_ecannot'});
@uinfo = &get_mail_user($in{'user'});
@uinfo || &error($text{'view_eugone'});
$euser = &urlize($in{'user'});
@folders = &list_user_folders($in{'user'});
$folder = $folders[$in{'folder'}];
if ($in{'new'}) {
# Composing a new email
if (defined($in{'html'})) {
$html_edit = $in{'html'};
}
else {
$html_edit = $config{'html_edit'} == 2 ? 1 : 0;
}
$sig = &get_signature($in{'user'});
if ($html_edit) {
$sig =~ s/\n/
\n/g;
$quote = "
",&text('detach_ok', "$paths[$i]", $sz),"
\n"; } &mail_page_footer("view_mail.cgi?idx=$in{'idx'}&folder=$in{'folder'}&user=$euser", $text{'view_return'}, "list_mail.cgi?folder=$in{'folder'}&user=$euser", $text{'mail_return'}, "", $text{'index_return'}); exit; } elsif ($in{'black'}) { # Add sender to global SpamAssassin blacklist, and tell user &mail_page_header($text{'black_title'}); &foreign_require("spam", "spam-lib.pl"); local $conf = &spam::get_config(); local @from = map { @{$_->{'words'}} } &spam::find("blacklist_from", $conf); local %already = map { $_, 1 } @from; local ($spamfrom) = &address_parts($mail->{'header'}->{'from'}); if ($already{$spamfrom}) { print "",&text('black_already', "$spamfrom"),"
\n"; } else { push(@from, $spamfrom); &spam::save_directives($conf, 'blacklist_from', \@from, 1); &flush_file_lines(); print "",&text('black_done', "$spamfrom"),"
\n"; } &mail_page_footer("list_mail.cgi?folder=$in{'folder'}&user=$euser", $text{'mail_return'}, "", $text{'index_return'}); exit; } elsif ($in{'razor'}) { # Report message to Razor and tell user &mail_page_header($text{'razor_title'}); print "$text{'razor_report'}\n"; print "
"; local $cmd = &spam_report_cmd($in{'user'}); local $temp = &transname(); &send_mail($mail, $temp, 0, 1); &open_execute_command(OUT, "$cmd <$temp 2>&1", 1); local $error; while(\n"; if ($? || $error) { print "$text{'razor_err'}) { print &html_escape($_); $error++ if (/failed/i); } close(OUT); unlink($temp); print "
\n"; } else { if ($config{'spam_del'}) { # Delete message too &lock_folder($folder); &mailbox_delete_mail($folder, $mail); &unlock_folder($folder); print "$text{'razor_deleted'}
\n"; } else { print "$text{'razor_done'}
\n";
}
}
&mail_page_footer("list_mail.cgi?folder=$in{'folder'}&user=$euser", $text{'mail_return'}, "", $text{'index_return'});
exit;
}
if (!@mailforward) {
&parse_mail($mail);
@attach = @{$mail->{'attach'}};
}
if ($in{'strip'}) {
# Remove all non-body attachments
local $newmail = { 'headers' => $mail->{'headers'},
'header' => $mail->{'header'},
'fromline' => $mail->{'fromline'} };
foreach $a (@attach) {
if ($a->{'type'} eq 'text/plain' ||
$a->{'type'} eq 'text') {
$newmail->{'attach'} = [ $a ];
last;
}
}
&lock_folder($folder);
&mailbox_modify_mail($mail, $newmail, $folder);
&unlock_folder($folder);
&redirect("list_mail.cgi?user=$euser&folder=$in{'folder'}");
exit;
}
if ($in{'enew'}) {
# Editing an existing message, so keep same fields
$to = $mail->{'header'}->{'to'};
$rto = $mail->{'header'}->{'reply-to'};
$from = $mail->{'header'}->{'from'};
$cc = $mail->{'header'}->{'cc'};
$ouser = $1 if ($from =~ /^(\S+)\@/);
}
else {
if (!$in{'forward'} && !@mailforward) {
# Replying to a message, so set To: field
$to = $mail->{'header'}->{'reply-to'};
$to = $mail->{'header'}->{'from'} if (!$to);
}
if ($in{'rall'}) {
# If replying to all, add any addresses in the original
# To: or Cc: to our new Cc: address.
$cc = $mail->{'header'}->{'to'};
$cc .= ", ".$mail->{'header'}->{'cc'}
if ($mail->{'header'}->{'cc'});
}
}
# Convert MIMEwords in headers to 8 bit for display
$to = &decode_mimewords($to);
$rto = &decode_mimewords($rto);
$cc = &decode_mimewords($cc);
$bcc = &decode_mimewords($bcc);
# Work out new subject, depending on whether we are replying
# our forwarding a message (or neither)
local $qu = !$in{'enew'} &&
(!$in{'forward'} || !$config{'fwd_mode'});
$subject = &html_escape(&decode_mimewords(
$mail->{'header'}->{'subject'}));
$subject = "Re: ".$subject if ($subject !~ /^Re/i && !$in{'forward'} &&
!@mailforward && !$in{'enew'});
$subject = "Fwd: ".$subject if ($subject !~ /^Fwd/i &&
($in{'forward'} || @mailforward));
# Construct the initial mail text
$sig = &get_signature($in{'user'});
($quote, $html_edit, $body) = "ed_message($mail, $qu, $sig);
if ($in{'forward'} || $in{'enew'}) {
@attach = grep { $_ ne $body } @attach;
}
else {
undef(@attach);
}
# Show header
&mail_page_header(
$in{'forward'} || @mailforward ? $text{'forward_title'} :
$in{'enew'} ? $text{'enew_title'} :
$text{'reply_title'}, undef,
$html_edit ? "onload='xinha_init()'" : "",
&folder_link($in{'user'}, $folder));
}
# Show form start, with upload progress tracker hook
$upid = time().$$;
$onsubmit = &read_parse_mime_javascript($upid, [ map { "attach$_" } (0..10) ]);
print &ui_form_start("send_mail.cgi?id=$upid", "form-data", undef, $onsubmit);
# Output various hidden fields
print &ui_hidden("user", $in{'user'});
print &ui_hidden("ouser", $ouser);
print &ui_hidden("idx", $in{'idx'});
print &ui_hidden("folder", $in{'folder'});
print &ui_hidden("new", $in{'new'});
print &ui_hidden("enew", $in{'enew'});
foreach $s (@sub) {
print &ui_hidden("sub", $s);
}
print &ui_hidden("charset", $main::force_charset);
# Start tabs for from / to / cc / bcc
# Subject is separate
print &ui_table_start($text{'reply_headers'}, "width=100%", 2);
@tds = ( "width=10%", "width=90% nowrap" );
@tabs = ( [ "from", $text{'reply_tabfrom'} ],
[ "to", $text{'reply_tabto'} ],
[ "cc", $text{'reply_tabcc'} ],
[ "bcc", $text{'reply_tabbcc'} ],
[ "options", $text{'reply_taboptions'} ] );
print &ui_table_row(undef, &ui_tabs_start(\@tabs, "tab", "to", 0), 2);
# From address tab
$from ||= &get_user_from_address(\@uinfo);
@froms = split(/\s+/, $access{'from'});
if ($access{'fmode'} == 0) {
# Any email addresss
$frominput = &ui_address_field("from", $from, 1, 0);
}
elsif ($access{'fmode'} == 1) {
# Current username at some domains
local $u = $from || $ouser || $in{'user'};
$u =~ s/\@.*$//;
$frominput = &ui_select("from", $from,
$access{'fromname'} ?
[ map { [ "$access{'fromname'} <$u\@$_>",
"$u\@$_" ] } @froms ] :
[ map { "$u\@$_" } @froms ]);
}
elsif ($access{'fmode'} == 2) {
# Listed from addresses
$frominput = &ui_select("from", $from,
$access{'fromname'} ?
[ map { [ "$access{'fromname'} <$_>", $_ ] }
@froms ] :
\@froms);
}
elsif ($access{'fmode'} == 3) {
# Fixed address in fixed domain
$frominput = "$ouser\@$access{'from'}".
&ui_hidden("from", "$ouser\@$access{'from'}");
}
print &ui_tabs_start_tabletab("tab", "from");
print &ui_table_row($text{'mail_from'}, $frominput, 1, \@tds);
print &ui_tabs_end_tabletab();
# Show To: field
print &ui_tabs_start_tabletab("tab", "to");
print &ui_table_row($text{'mail_to'}, &ui_address_field("to", $to, 0, 1),
1, \@tds);
print &ui_tabs_end_tabletab();
# Show Cc: field
print &ui_tabs_start_tabletab("tab", "cc");
print &ui_table_row($text{'mail_cc'}, &ui_address_field("cc", $cc, 0, 1),
1, \@tds);
print &ui_tabs_end_tabletab();
# Show Bcc: field
$bcc ||= $config{'bcc_to'};
print &ui_tabs_start_tabletab("tab", "bcc");
print &ui_table_row($text{'mail_bcc'}, &ui_address_field("bcc", $bcc, 0, 1),
1, \@tds);
print &ui_tabs_end_tabletab();
# Show tab for options
print &ui_tabs_start_tabletab("tab", "options");
print &ui_table_row($text{'mail_pri'},
&ui_select("pri", "",
[ [ 1, $text{'mail_highest'} ],
[ 2, $text{'mail_high'} ],
[ "", $text{'mail_normal'} ],
[ 4, $text{'mail_low'} ],
[ 5, $text{'mail_lowest'} ] ]), 1, \@tds);
print &ui_tabs_end_tabletab();
print &ui_tabs_end();
# Subject field, outside tabs
print &ui_table_row($text{'mail_subject'},
&ui_textbox("subject", $subject, 40, 0, undef,
"style='width:95%'"), 1, \@tds);
print &ui_table_end();
# Create link for switching to HTML/text mode for new mail
@bodylinks = ( );
if ($in{'new'}) {
if ($html_edit) {
push(@bodylinks, "$text{'reply_html0'}");
}
else {
push(@bodylinks, "$text{'reply_html1'}");
}
}
# Output message body input
print &ui_table_start($text{'reply_body'}, "width=100%", 2, undef,
&ui_links_row(\@bodylinks));
if ($html_edit) {
# Output HTML editor textarea
print <