-
Notifications
You must be signed in to change notification settings - Fork 21
/
spell.php
119 lines (92 loc) · 3.43 KB
/
spell.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<?php
// +----------------------------------------------------------------+
// | spell.php |
// +----------------------------------------------------------------+
// | Function: Spell check an email message |
// +----------------------------------------------------------------+
// | AtMail Open - Licensed under the Apache 2.0 Open-source License|
// | http://opensource.org/licenses/apache2.0.php |
// +----------------------------------------------------------------+
require_once('header.php');
require_once('Session.php');
require_once('Global.php');
session_start();
$atmail = new AtmailGlobal();
$auth =& $atmail->getAuthObj();
$atmail->status = $auth->getuser($atmail->SessionID);
$atmail->username = $auth->username;
$atmail->pop3host = $auth->pop3host;
// Print the error screen if the account has auth errors, or session timeout.
if ( $atmail->status == 1 ) {
header("Content-type: text/xml; charset: utf-8");
echo "<Error>Athentication Error</Error>";
$atmail->end();
}
if ( $atmail->status == 2 ) {
header("Content-type: text/xml; charset: utf-8");
echo "<Error>Session errror</Error>";
$atmail->end();
}
// Load the account preferences
$atmail->loadprefs();
ob_start();
// Try to use the aspell dictionary for the user's current language
include_once('libs/Atmail/AspellLanguageCodes.php');
$dict = '';
if ($pref["aspell_{$atmail->Language}"])
$dict = $aspellLanguageCodes[$atmail->Language];
ob_end_clean();
//$dict = 'en';
if (empty($dict))
{
$lang = ucfirst($atmail->Language);
header("Content-type: text/xml; charset: utf-8");
echo "<Error>Spellcheck not available for $lang language</Error>\n";
$atmail->end();
}
// only bother requiring if we pass authentication
require_once('spellChecker.php');
$atmail->httpheaders();
$spellChecker = new spellChecker($dict, "$atmail->username@$atmail->pop3host", $pref['use_php_pspell']);
// Add word to our personal dict file
if ( $_REQUEST['add'] )
{
$personal = $_REQUEST['replace'] ? $_REQUEST['replace'] : $_REQUEST['wordreplace'];
// Insert the entry into the database
$spellChecker->addWord($atmail->Account, $personal);
}
if ( $_REQUEST['ignore'] || $_REQUEST['change'] && $_REQUEST['wordreplace'] )
{
// Ignore the word
$spellChecker->ignoreWord($_REQUEST['wordreplace']);
}
// spell check the email
$_REQUEST['emailmessage'] = str_replace(array('<br>', '<BR>', '<br/>', '<BR/>', '</p>', '</P>'), "\n", $_REQUEST['emailmessage']);
// Remove any html entities and tags
$_REQUEST['emailmessage'] = preg_replace('/&\w+;/', '', $_REQUEST['emailmessage']);
$_REQUEST['emailmessage'] = strip_tags($_REQUEST['emailmessage']);
// Remove punctuation such as , ; :
//$_REQUEST['emailmessage'] = preg_replace('/[^a-zA-Z\-]+/', ' ', $_REQUEST['emailmessage']);
foreach (explode("\n", $_REQUEST['emailmessage']) as $line)
{
$words = array_unique(preg_split('/\s+/', $line));
foreach ($words as $word)
{
if (preg_match('/[a-zA-Z]+/', $word))
$spellChecker->check($word);
}
}
if ($spellChecker->haveErrors())
{
$result = $spellChecker->getSuggestions();
if (is_array($result)) {
$var['atmailstyle'] = $atmail->parse("html/$atmail->Language/simple/atmailstyle.css" );
echo $atmail->parse("html/$atmail->Language/$atmail->LoginType/spellcheck.html", $result, $var );
} else {
header("Content-type: text/xml; charset: utf-8");
echo $result;
}
}
$spellChecker->close();
$atmail->end();
?>