From 1d5779b2577453a1000f38fa987bb0eafd3c554f Mon Sep 17 00:00:00 2001
From: alecpl <alec@alec.pl>
Date: Mon, 30 May 2011 12:19:51 -0400
Subject: [PATCH] - Add option to force spellchecking before sending a message (#1485458)

---
 CHANGELOG                               |    1 +
 program/localization/en_US/messages.inc |    1 +
 program/steps/settings/func.inc         |   10 ++++++++++
 program/localization/en_US/labels.inc   |    1 +
 program/localization/pl_PL/labels.inc   |    1 +
 config/main.inc.php.dist                |    3 +++
 program/localization/pl_PL/messages.inc |    1 +
 program/steps/mail/sendmail.inc         |   17 +++++++++++++++++
 program/steps/settings/save_prefs.inc   |    1 +
 9 files changed, 36 insertions(+), 0 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index 15bfd76..4bb90ee 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,6 +1,7 @@
 CHANGELOG Roundcube Webmail
 ===========================
 
+- Added option to force spellchecking before sending a message (#1485458)
 - Fix handling of "<" character in contact data, search fields and folder names (#1487864)
 - Fix saving "<" character in identity name and organization fields (#1487864)
 - Added option to specify to which address book add new contacts
diff --git a/config/main.inc.php.dist b/config/main.inc.php.dist
index ddb1eda..447575f 100644
--- a/config/main.inc.php.dist
+++ b/config/main.inc.php.dist
@@ -703,4 +703,7 @@
 // Note: Use '0' for built-in address book.
 $rcmail_config['default_addressbook'] = null;
 
+// Enables spell checking before sending a message.
+$rcmail_config['spellcheck_before_send'] = false;
+
 // end of config file
diff --git a/program/localization/en_US/labels.inc b/program/localization/en_US/labels.inc
index 3e88d09..45da21c 100644
--- a/program/localization/en_US/labels.inc
+++ b/program/localization/en_US/labels.inc
@@ -413,6 +413,7 @@
 $labels['reqdsn'] = 'Always request a delivery status notification';
 $labels['replysamefolder'] = 'Place replies in the folder of the message being replied to';
 $labels['defaultaddressbook'] = 'Add new contacts to the selected addressbook';
+$labels['spellcheckbeforesend'] = 'Check spelling before sending a message';
 
 $labels['folder']  = 'Folder';
 $labels['folders']  = 'Folders';
diff --git a/program/localization/en_US/messages.inc b/program/localization/en_US/messages.inc
index 7014201..da4b413 100644
--- a/program/localization/en_US/messages.inc
+++ b/program/localization/en_US/messages.inc
@@ -141,5 +141,6 @@
 $messages['folderupdated'] = 'Folder updated successfully';
 $messages['foldercreated'] = 'Folder created successfully';
 $messages['invalidimageformat'] = 'Not a valid image format';
+$messages['mispellingsfound'] = 'Spelling errors detected in the message';
 
 ?>
diff --git a/program/localization/pl_PL/labels.inc b/program/localization/pl_PL/labels.inc
index 652b302..637768e 100644
--- a/program/localization/pl_PL/labels.inc
+++ b/program/localization/pl_PL/labels.inc
@@ -407,5 +407,6 @@
 $labels['otherfolder'] = 'Folder innego użytkownika'; 
 $labels['sharedfolder'] = 'Folder współdzielony';
 $labels['defaultaddressbook'] = 'Nowe kontakty dodawaj do wybranej książki adresowej';
+$labels['spellcheckbeforesend'] = 'Przed wysłaniem wiadomości sprawdzaj pisownię';
 
 ?>
diff --git a/program/localization/pl_PL/messages.inc b/program/localization/pl_PL/messages.inc
index 89a39ec..1d99ffc 100644
--- a/program/localization/pl_PL/messages.inc
+++ b/program/localization/pl_PL/messages.inc
@@ -145,5 +145,6 @@
 $messages['errornoperm'] = 'Nie można wykonać operacji. Brak uprawnień';
 $messages['importconfirmskipped'] = '<b>Pominięto $skipped istniejących wpisów</b>';
 $messages['invalidimageformat'] = 'Niepoprawny format obrazka';
+$messages['mispellingsfound'] = 'Wykryto błędy pisowni w tej wiadomości';
 
 ?>
diff --git a/program/steps/mail/sendmail.inc b/program/steps/mail/sendmail.inc
index a492e93..de971a2 100644
--- a/program/steps/mail/sendmail.inc
+++ b/program/steps/mail/sendmail.inc
@@ -409,6 +409,22 @@
       "\r\n<html><body>\r\n" . $message_body;
   }
 
+  // Check spelling before send
+  if ($CONFIG['spellcheck_before_send'] && $CONFIG['enable_spellcheck']
+    && empty($_SESSION['compose']['spell_checked'])
+  ) {
+    $spellchecker = new rcube_spellchecker();
+    $spell_result = $spellchecker->check($message_body, $isHtml);
+
+    $_SESSION['compose']['spell_checked'] = true;
+
+    if (!$spell_result) {
+      $OUTPUT->show_message('mispellingsfound', 'error');
+      $OUTPUT->command('command', 'spellcheck');
+      $OUTPUT->send('iframe');
+    }
+  }
+
   // generic footer for all messages
   if ($isHtml && !empty($CONFIG['generic_message_footer_html'])) {
       $footer = file_get_contents(realpath($CONFIG['generic_message_footer_html']));
@@ -420,6 +436,7 @@
     if ($isHtml)
       $footer = '<pre>'.$footer.'</pre>';
   }
+
   if ($footer)
     $message_body .= "\r\n" . $footer;
   if ($isHtml)
diff --git a/program/steps/settings/func.inc b/program/steps/settings/func.inc
index 280185e..cf2d591 100644
--- a/program/steps/settings/func.inc
+++ b/program/steps/settings/func.inc
@@ -545,6 +545,16 @@
       );
     }
 
+    if (!isset($no_override['spellcheck_before_send']) && $config['enable_spellcheck']) {
+      $field_id = 'rcmfd_spellcheck_before_send';
+      $input_spellcheck = new html_checkbox(array('name' => '_spellcheck_before_send', 'id' => $field_id, 'value' => 1));
+
+      $blocks['main']['options']['spellcheck_before_send'] = array(
+        'title' => html::label($field_id, Q(rcube_label('spellcheckbeforesend'))),
+        'content' => $input_spellcheck->show($config['spellcheck_before_send']?1:0),
+      );
+    }
+
     if (!isset($no_override['show_sig'])) {
       $field_id = 'rcmfd_show_sig';
       $select_show_sig = new html_select(array('name' => '_show_sig', 'id' => $field_id));
diff --git a/program/steps/settings/save_prefs.inc b/program/steps/settings/save_prefs.inc
index a5ec234..ac1cfb3 100644
--- a/program/steps/settings/save_prefs.inc
+++ b/program/steps/settings/save_prefs.inc
@@ -70,6 +70,7 @@
       'mdn_default'        => isset($_POST['_mdn_default']) ? TRUE : FALSE,
       'dsn_default'        => isset($_POST['_dsn_default']) ? TRUE : FALSE,
       'reply_same_folder'  => isset($_POST['_reply_same_folder']) ? TRUE : FALSE,
+      'spellcheck_before_send' => isset($_POST['_spellcheck_before_send']) ? TRUE : FALSE,
       'show_sig'           => isset($_POST['_show_sig']) ? intval($_POST['_show_sig']) : 1,
       'top_posting'        => !empty($_POST['_top_posting']),
       'strip_existing_sig' => isset($_POST['_strip_existing_sig']),

--
Gitblit v1.9.1