#!/usr/bin/perl # send_mail.cgi # Send off an email message require './mailboxes-lib.pl'; &ReadParse(\%getin, "GET"); &ReadParseMime(undef, \&read_parse_mime_callback, [ $getin{'id'} ], 1); foreach my $k (keys %in) { $in{$k} = join("\0", @{$in{$k}}) if ($k !~ /^attach\d+/); } &can_user($in{'user'}) || &error($text{'mail_ecannot'}); @uinfo = &get_mail_user($in{'user'}); @uinfo || &error($text{'view_eugone'}); # Check inputs @folders = &list_user_folders($in{'user'}); $folder = $folders[$in{'folder'}]; &error_setup($text{'send_err'}); $in{'to'} || &error($text{'send_eto'}); if ($access{'fmode'} == 0) { # Any from address allowed $in{'from'} || &error($text{'send_efrom'}); } elsif ($access{'fmode'} == 1) { # From address must be in an allowed domain, and match username $validfrom = &get_user_from_address(\@uinfo); foreach $f (split(/\s+/, $access{'from'})) { $found++ if ("$in{'user'}\@$f" eq $in{'from'} || "$in{'ouser'}\@$f" eq $in{'from'} || $validfrom eq $in{'from'}); } &error($text{'send_efrom'}) if (!$found); } elsif ($access{'fmode'} == 2) { # From address must be in allowed list foreach $f (split(/\s+/, $access{'from'})) { $found++ if ($f eq $in{'from'}); } &error($text{'send_efrom'}) if (!$found); } elsif ($access{'fmode'} == 3) { $in{'from'} .= "\@$access{'from'}"; } if ($in{'from'} =~ /^(\S+)\@(\S+)$/ && $access{'fromname'}) { $in{'from'} = "$access{'fromname'} <$in{'from'}>"; } @sub = split(/\0/, $in{'sub'}); $subs = join("", map { "&sub=$_" } @sub); # Construct the email $in{'from'} || &error($text{'send_efrom'}); $newmid = &generate_message_id($in{'from'}); %enc = ( 'Charset' => $in{'charset'} ); $mail->{'headers'} = [ [ 'From', &encode_mimewords($in{'from'}, %enc) ], [ 'Subject', &encode_mimewords($in{'subject'}, %enc) ], [ 'To', &encode_mimewords_address($in{'to'}, %enc) ], [ 'Message-Id', $newmid ] ]; if ($in{'cc'}) { push(@{$mail->{'headers'}}, [ 'Cc', &encode_mimewords_address($in{'cc'}, %enc) ]); } if ($in{'bcc'}) { push(@{$mail->{'headers'}}, [ 'Bcc', &encode_mimewords_address($in{'bcc'}, %enc) ]); } &add_mailer_ip_headers($mail->{'headers'}); push(@{$mail->{'headers'}}, [ 'X-Priority', $in{'pri'} ]) if ($in{'pri'}); $in{'body'} =~ s/\r//g; if ($in{'body'} =~ /\S/) { # Perform spell check on body if requested local $plainbody = $in{'html_edit'} ? &html_to_text($in{'body'}) : $in{'body'}; if ($in{'spell'}) { @errs = &spell_check_text($plainbody); if (@errs) { # Spelling errors found! &mail_page_header($text{'compose_title'}, undef, undef, &folder_link($in{'user'}, $folder)); print "<b>$text{'send_espell'}</b><p>\n"; print map { $_."<p>\n" } @errs; &mail_page_footer( "javascript:back()", $text{'reply_return'}, "index.cgi?user=$in{'user'}&folder=$in{'folder'}". "&dom=$in{'dom'}", $text{'mail_return'}); exit; } } local $mt = $in{'html_edit'} ? "text/html" : "text/plain"; if ($in{'charset'}) { $mt .= "; charset=$in{'charset'}"; } if ($in{'body'} =~ /[\177-\377]/) { # Contains 8-bit characters .. need to make quoted-printable $quoted_printable++; @attach = ( { 'headers' => [ [ 'Content-Type', $mt ], [ 'Content-Transfer-Encoding', 'quoted-printable' ] ], 'data' => quoted_encode($in{'body'}) } ); } else { # Plain 7-bit ascii text @attach = ( { 'headers' => [ [ 'Content-Type', $mt ], [ 'Content-Transfer-Encoding', '7bit' ] ], 'data' => $in{'body'} } ); } $bodyattach = $attach[0]; if ($in{'html_edit'}) { # Create an attachment which contains both the HTML and plain # bodies as alternatives local @alts = ( $attach[0] ); local $mt = "text/plain; charset=$charset"; if ($plainbody =~ /[\177-\377]/) { unshift(@alts, { 'headers' => [ [ 'Content-Type', $mt ], [ 'Content-Transfer-Encoding', 'quoted-printable' ] ], 'data' => quoted_encode($plainbody) }); } else { unshift(@alts, { 'headers' => [ [ 'Content-Type', $mt ], [ 'Content-Transfer-Encoding', '7bit' ] ], 'data' => $plainbody }); } # Set content type to multipart/alternative, to tell mail # clients about the optional body local $bound = "altsbound".time(); $attach[0] = { 'headers' => [ [ 'Content-Type', 'multipart/alternative; '. 'boundary="'.$bound.'"' ], [ 'Content-Transfer-Encoding', '7bit' ] ], 'data' => join("", &unparse_mail(\@alts, "\n", $bound)) }; } } $attachsize = 0; for($i=0; defined($in{"attach$i"}); $i++) { # Add uploaded attachment next if (!$in{"attach$i"}); for($j=0; $j<@{$in{"attach$i"}}; $j++) { next if (!$in{"attach${i}"}->[$j]); &test_max_attach(length($in{"attach${i}"}->[$j])); local $filename = $in{"attach${i}_filename"}->[$j]; $filename =~ s/^.*(\\|\/)//; local $type = $in{"attach${i}_content_type"}->[$j]. "; name=\"".$filename."\""; local $disp = "attachment; filename=\"".$filename."\""; push(@attach, { 'data' => $in{"attach${i}"}->[$j], 'headers' => [ [ 'Content-type', $type ], [ 'Content-Disposition', $disp ], [ 'Content-Transfer-Encoding', 'base64' ] ] }); $atotal += length($in{"attach${i}"}->[$j]); } } for($i=0; defined($in{"file$i"}); $i++) { # Add server-side attachment next if (!$in{"file$i"} || !$access{'canattach'}); @uinfo = &get_mail_user($in{'user'}); @uinfo || &error($text{'view_eugone'}); if ($in{"file$i"} !~ /^\//) { $in{"file$i"} = $uinfo[7]."/".$in{"file$i"}; } local @st = stat($in{"file$i"}); &test_max_attach($st[7]); local $data; &switch_to_user($in{'user'}); $data = &read_file_contents($in{"file$i"}); $data || &error(&text('send_efile', $in{"file$i"}, $!)); &switch_user_back(); $in{"file$i"} =~ s/^.*\///; local $type = &guess_mime_type($in{"file$i"}). "; name=\"".$in{"file$i"}."\""; local $disp = "inline; filename=\"".$in{"file$i"}."\""; push(@attach, { 'data' => $data, 'headers' => [ [ 'Content-type', $type ], [ 'Content-Disposition', $disp ], [ 'Content-Transfer-Encoding', 'base64' ] ] }); $atotal += length($data); } @fwd = split(/\0/, $in{'forward'}); if (@fwd) { # Add forwarded attachments @mail = &mailbox_list_mails($in{'idx'}, $in{'idx'}, $folder); $fwdmail = $mail[$in{'idx'}]; &parse_mail($fwdmail); foreach $s (@sub) { # We are looking at a mail within a mail .. local $amail = &extract_mail($fwdmail->{'attach'}->[$s]->{'data'}); &parse_mail($amail); $fwdmail = $amail; } foreach $f (@fwd) { &test_max_attach(length($fwdmail->{'attach'}->[$f]->{'data'})); push(@attach, $fwdmail->{'attach'}->[$f]); $atotal += length($fwdmail->{'attach'}->[$f]->{'data'}); } } @mailfwd = split(/\0/, $in{'mailforward'}); if (@mailfwd) { # Add forwarded emails @mail = &mailbox_list_mails($mailfwd[0], $mailfwd[@mailfwd-1], $folder); foreach $f (@mailfwd) { $fwdmail = $mail[$f]; local $headertext; foreach $h (@{$fwdmail->{'headers'}}) { $headertext .= $h->[0].": ".$h->[1]."\n"; } push(@attach, { 'data' => $headertext."\n".$fwdmail->{'body'}, 'headers' => [ [ 'Content-type', 'message/rfc822' ], [ 'Content-Description', $fwdmail->{'header'}->{'subject'} ] ] }); } } $mail->{'attach'} = \@attach; if ($access{'attach'} >= 0 && $atotal > $access{'attach'}*1024) { &error(&text('send_eattach', $access{'attach'})); } # Check for text-only email $textonly = $config{'no_mime'} && !$quoted_printable && @{$mail->{'attach'}} == 1 && $mail->{'attach'}->[0] eq $bodyattach && !$in{'html_edit'}; # Send it off &send_mail($mail, undef, $textonly, $config{'no_crlf'}); &webmin_log("send", undef, undef, { 'from' => $in{'from'}, 'to' => $in{'to'} }); # Tell the user that email as sent &mail_page_header($text{'send_title'}, undef, undef, &folder_link($in{'user'}, $folder)); @tos = ( split(/,/, $in{'to'}), split(/,/, $in{'cc'}), split(/,/, $in{'bcc'}) ); $tos = join(" , ", map { "<tt>".&html_escape($_)."</tt>" } @tos); print "<p>",&text($in{'draft'} ? 'send_draft' : 'send_ok', $tos),"<p>\n"; if ($in{'idx'} ne '') { &mail_page_footer("view_mail.cgi?idx=$in{'idx'}&folder=$in{'folder'}". "&user=$in{'user'}&dom=$in{'dom'}$subs", $text{'view_return'}, "list_mail.cgi?folder=$in{'folder'}&user=$in{'user'}". "&dom=$in{'dom'}", $text{'mail_return'}, &user_list_link(), $text{'index_return'}); } else { &mail_page_footer("list_mail.cgi?folder=$in{'folder'}&user=$in{'user'}". "&dom=$in{'dom'}", $text{'mail_return'}, &user_list_link(), $text{'index_return'}); } # write_attachment(&attach) sub write_attachment { local ($a) = @_; local ($enc, $rv); foreach $h (@{$a->{'headers'}}) { $rv .= $h->[0].": ".$h->[1]."\r\n"; $enc = $h->[1] if (lc($h->[0]) eq 'content-transfer-encoding'); } $rv .= "\r\n"; if (lc($enc) eq 'base64') { local $encoded = &encode_base64($a->{'data'}); $encoded =~ s/\r//g; $encoded =~ s/\n/\r\n/g; $rv .= $encoded; } else { $a->{'data'} =~ s/\r//g; $a->{'data'} =~ s/\n/\r\n/g; $rv .= $a->{'data'}; if ($a->{'data'} !~ /\n$/) { $rv .= "\r\n"; } } return $rv; } sub test_max_attach { $attachsize += $_[0]; if ($access{'attach'} >= 0 && $attachsize > $access{'attach'}) { &error(&text('send_eattachsize', $access{'attach'})); } }
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
images | Folder | 0755 |
|
|
lang | Folder | 0755 |
|
|
xinha | Folder | 0755 |
|
|
CHANGELOG | File | 5.7 KB | 0644 |
|
Makefile | File | 125 B | 0644 |
|
acl_security.pl | File | 3 KB | 0755 |
|
boxes-lib.pl | File | 80.37 KB | 0755 |
|
cgi_args.pl | File | 520 B | 0755 |
|
config | File | 758 B | 0644 |
|
config.info | File | 4.94 KB | 0644 |
|
config.info.ca | File | 5.79 KB | 0644 |
|
config.info.cs | File | 5.2 KB | 0644 |
|
config.info.de | File | 6.27 KB | 0644 |
|
config.info.el | File | 8.14 KB | 0644 |
|
config.info.fi | File | 0 B | 0644 |
|
config.info.fr | File | 6.43 KB | 0644 |
|
config.info.hu | File | 0 B | 0644 |
|
config.info.it | File | 5.97 KB | 0644 |
|
config.info.ja | File | 5.97 KB | 0644 |
|
config.info.ko | File | 5.29 KB | 0644 |
|
config.info.nl | File | 5.48 KB | 0644 |
|
config.info.no | File | 5.25 KB | 0644 |
|
config.info.pt_BR | File | 0 B | 0644 |
|
config_info.pl | File | 389 B | 0755 |
|
defaultacl | File | 50 B | 0644 |
|
delete_all.cgi | File | 1.25 KB | 0755 |
|
delete_mail.cgi | File | 7 KB | 0755 |
|
detach.cgi | File | 3.19 KB | 0755 |
|
detachall.cgi | File | 1.72 KB | 0755 |
|
find.cgi | File | 731 B | 0755 |
|
folders-lib.pl | File | 103.44 KB | 0755 |
|
index.cgi | File | 2.73 KB | 0755 |
|
list_mail.cgi | File | 5.15 KB | 0755 |
|
log_parser.pl | File | 1.02 KB | 0755 |
|
mail_search.cgi | File | 3.68 KB | 0755 |
|
mailboxes-lib.pl | File | 33.59 KB | 0755 |
|
makelang.pl | File | 1.35 KB | 0755 |
|
module.info | File | 137 B | 0644 |
|
module.info.af | File | 0 B | 0644 |
|
module.info.af.auto | File | 82 B | 0644 |
|
module.info.ar | File | 0 B | 0644 |
|
module.info.ar.auto | File | 145 B | 0644 |
|
module.info.be | File | 0 B | 0644 |
|
module.info.be.auto | File | 185 B | 0644 |
|
module.info.bg | File | 0 B | 0644 |
|
module.info.bg.auto | File | 167 B | 0644 |
|
module.info.ca | File | 97 B | 0644 |
|
module.info.cs | File | 37 B | 0644 |
|
module.info.cs.auto | File | 75 B | 0644 |
|
module.info.da | File | 0 B | 0644 |
|
module.info.da.auto | File | 72 B | 0644 |
|
module.info.de | File | 77 B | 0644 |
|
module.info.el | File | 0 B | 0644 |
|
module.info.el.auto | File | 232 B | 0644 |
|
module.info.es | File | 38 B | 0644 |
|
module.info.es.auto | File | 72 B | 0644 |
|
module.info.eu | File | 0 B | 0644 |
|
module.info.eu.auto | File | 110 B | 0644 |
|
module.info.fa | File | 0 B | 0644 |
|
module.info.fa.auto | File | 141 B | 0644 |
|
module.info.fi | File | 27 B | 0644 |
|
module.info.fi.auto | File | 61 B | 0644 |
|
module.info.fr | File | 40 B | 0644 |
|
module.info.fr.auto | File | 76 B | 0644 |
|
module.info.he | File | 0 B | 0644 |
|
module.info.he.auto | File | 117 B | 0644 |
|
module.info.hr | File | 0 B | 0644 |
|
module.info.hr.auto | File | 108 B | 0644 |
|
module.info.hu | File | 38 B | 0644 |
|
module.info.hu.auto | File | 72 B | 0644 |
|
module.info.it | File | 27 B | 0644 |
|
module.info.it.auto | File | 76 B | 0644 |
|
module.info.ja | File | 39 B | 0644 |
|
module.info.ja.auto | File | 79 B | 0644 |
|
module.info.ko | File | 29 B | 0644 |
|
module.info.ko.auto | File | 65 B | 0644 |
|
module.info.lt | File | 0 B | 0644 |
|
module.info.lt.auto | File | 110 B | 0644 |
|
module.info.lv | File | 0 B | 0644 |
|
module.info.lv.auto | File | 85 B | 0644 |
|
module.info.ms | File | 73 B | 0644 |
|
module.info.mt | File | 0 B | 0644 |
|
module.info.mt.auto | File | 81 B | 0644 |
|
module.info.nl | File | 30 B | 0644 |
|
module.info.nl.auto | File | 57 B | 0644 |
|
module.info.no | File | 27 B | 0644 |
|
module.info.no.auto | File | 47 B | 0644 |
|
module.info.pl | File | 38 B | 0644 |
|
module.info.pl.auto | File | 67 B | 0644 |
|
module.info.pt | File | 0 B | 0644 |
|
module.info.pt.auto | File | 94 B | 0644 |
|
module.info.pt_BR | File | 34 B | 0644 |
|
module.info.pt_BR.auto | File | 65 B | 0644 |
|
module.info.ro | File | 0 B | 0644 |
|
module.info.ro.auto | File | 116 B | 0644 |
|
module.info.ru | File | 63 B | 0644 |
|
module.info.ru.auto | File | 99 B | 0644 |
|
module.info.sk | File | 0 B | 0644 |
|
module.info.sk.auto | File | 120 B | 0644 |
|
module.info.sl | File | 0 B | 0644 |
|
module.info.sl.auto | File | 97 B | 0644 |
|
module.info.sv | File | 0 B | 0644 |
|
module.info.sv.auto | File | 78 B | 0644 |
|
module.info.th | File | 0 B | 0644 |
|
module.info.th.auto | File | 154 B | 0644 |
|
module.info.tr | File | 104 B | 0644 |
|
module.info.uk | File | 0 B | 0644 |
|
module.info.uk.auto | File | 193 B | 0644 |
|
module.info.ur | File | 0 B | 0644 |
|
module.info.ur.auto | File | 117 B | 0644 |
|
module.info.vi | File | 0 B | 0644 |
|
module.info.vi.auto | File | 99 B | 0644 |
|
module.info.zh | File | 0 B | 0644 |
|
module.info.zh.auto | File | 79 B | 0644 |
|
module.info.zh_TW | File | 33 B | 0644 |
|
module.info.zh_TW.auto | File | 55 B | 0644 |
|
prefs.info | File | 225 B | 0644 |
|
reply_mail.cgi | File | 15.96 KB | 0755 |
|
safeacl | File | 32 B | 0644 |
|
search_form.cgi | File | 1.86 KB | 0755 |
|
send_mail.cgi | File | 9.56 KB | 0755 |
|
slideshow.cgi | File | 1.63 KB | 0755 |
|
useradmin_update.pl | File | 2.33 KB | 0755 |
|
view_mail.cgi | File | 10.44 KB | 0755 |
|