Show check_spelling.html syntax highlighted
% # vim:set syntax=mason:
<%args>
</%args>
<& /mail/header.mhtml, title => "Spell check" &>
<form method="post" action="/mail/fix_spelling.html" enctype="multipart/form-data">
<div class="controls">
<input type="submit" name="spellcheck" value="Fix and return to compose">
</div>
<table class="composition_form">
<tr>
<td class="composition_field_label">
<div class="composition_field_label">
To:
</div>
</td>
<td>
<div class="noneditable">
<% $to |h %>
</div>
</td>
</tr>
<tr>
<td class="composition_field_label">
<div class="composition_field_label">
Cc:
</div>
</td>
<td>
<div class="noneditable">
<% $cc |h %>
</div>
</td>
</tr>
<tr>
<td class="composition_field_label">
<div class="composition_field_label">
Bcc:
</div>
</td>
<td>
<div class="noneditable">
<% $bcc |h %>
</div>
</td>
</tr>
<tr>
<td class="composition_field_label">
<div class="composition_field_label">
Subject:
</div>
</td>
<td>
<div class="noneditable">
<% $subject |h %>
</div>
</td>
</tr>
<tr>
<td colspan="2">
<div class="noneditable">
% for my $l (@lines) {
<% $l %><br>
% }
</div>
</td>
</tr>
</table>
<div class="controls">
<input type="submit" name="spellcheck" value="Fix and return to compose">
% if($forward || @attachments) {
<p>Current attachments:
% if($forward) {
Forwarded message (complete with attachments),
% }
% for(my $i =0; $i < $#attachments+1; $i++) {
<% $attachments[$i] %> (<% $sizes[$i] %> bytes),
% }
% }
</div>
</form>
<& /mail/footer.mhtml &>
<%init>
my $user = Apache::SiteControl->getCurrentUser($r);
my $username = $user->getUsername();
my $logger = Log::Log4perl->get_logger('alphamail');
my $error = 0;
$logger->debug("Beginning a spell check");
# Load the message from the session.
my $composition = load_composition($r, $user);
my $to = $composition->{to};
my $cc = $composition->{cc};
my $bcc = $composition->{bcc};
my $ref = $composition->{"ref"};
my $forward = $composition->{forwardflag};
my $subject = $composition->{subject};
my $message = $composition->{message};
my @attachments = ();
my @sizes = ();
if($composition->{attachments} && $composition->{sizes}) {
@attachments = @{$composition->{attachments}};
@sizes = @{$composition->{sizes}};
}
my (@lines, $i, $s, $e, $v, @nearmisses, @fixes, $html, $box, $word);
@lines = split /\r?\n/, $message;
for($i = 0; $i <= $#lines; $i++) {
$v = $lines[$i];
chomp $v;
@fixes = ();
# Find the mistakes
while(scalar($v =~ m/([-a-z]+)/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, corrections => [ @nearmisses ] };
}
}
# Create the HTML correction selection stuff
@fixes = sort { $b->{a} <=> $a->{a} } @fixes;
my $html = $v;
for my $fix (@fixes)
{
my $box;
my $cname = "c_${i}_$fix->{a}_$fix->{b}";
$box = qq(<select name="$cname">);
$box .= qq(<option value="$fix->{word}">$fix->{word}</option>);
for my $c (@{$fix->{corrections}}) {
$box .= qq(\t<option value="$c">$c</option>);
}
$box .= qq(</select>);
$html = substr($html, 0, $fix->{a}) . $box . substr($html, $fix->{b}+1,length($html) - $fix->{b});
}
$lines[$i] = $html;
}
</%init>
<%once>
use AlphaMail::SessionUtil qw(load_composition clear_composition);
use Text::Aspell;
</%once>
See more files for this project here