Show fix_spelling.html syntax highlighted
% # vim:set syntax=mason:
<%init>
my $user = Apache2::SiteControl->getCurrentUser($r);
my $username = $user->getUsername();
my $error = 0;
my $speller = new Text::Aspell;
$speller->set_option("lang", "en_US");
$speller->set_option("sug-mode", "fast");
$logger->debug($user->getUsername() . ": Fixing spelling.");
# Load the message from the session.
my $composition = new AlphaMail::Message($user, $config);
$composition->load();
my $body = $composition->getBody();
my (@lines, $i, $s, $e, $v, @nearmisses, @fixes, $html, $box, $word);
@lines = split /\r?\n/, $body;
$body = "";
for($i = 0; $i <= $#lines; $i++) {
$v = $lines[$i];
chomp $v;
@fixes = ();
# Find the original mistakes
while(scalar($v =~ m"(\b[a-z][-a-z']*[a-z]\b)"ig)) {
$word = $1;
$s = pos($v) - length($word);
$e = pos($v) - 1;
if(!$speller->check($word)) {
@nearmisses = $speller->suggest($word);
push @fixes, { a => $s, b => $e, word => $word };
}
}
# Fix the line from R to L (using choices from incoming args)
@fixes = sort { $b->{a} <=> $a->{a} } @fixes;
my $text = $v;
for my $fix (@fixes)
{
my $cname = "c_${i}_$fix->{a}_$fix->{b}";
if(!defined($ARGS{$cname})) {
$logger->error($user->getUsername() . ": Missing incoming selection for $cname");
$text = substr($text, 0, $fix->{a}) . $fix->{word} . substr($v, $fix->{b}+1,length($text) - $fix->{b});
next;
} else {
$text = substr($text, 0, $fix->{a}) . $ARGS{$cname} . substr($text, $fix->{b}+1,length($text) - $fix->{b});
}
}
$body .= "$text\n";
}
$composition->setBody($body);
$composition->save();
$m->redirect(build_url("$base/mail/compose.html", { spelling_checked => 1 }));
</%init>
<%once>
use AlphaMail::HTMLHelper qw(build_url);
our $logger = Log::Log4perl->get_logger('alphamail');
our $base = $config->get('base_uri');
</%once>
See more files for this project here