sending_charset pref fixes
authorMichael M Slusarz <slusarz@curecanti.org>
Thu, 4 Nov 2010 20:58:33 +0000 (14:58 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Fri, 5 Nov 2010 16:19:10 +0000 (10:19 -0600)
Move from IMP to Horde (Horde_Registry::getEmailCharset() requires it).
IMP now correctly honors sending_charset if locked.

framework/Core/lib/Horde/Registry.php
horde/config/prefs.php.dist
horde/lib/Prefs/Ui.php
imp/compose-mimp.php
imp/compose.php
imp/config/prefs.php.dist
imp/docs/UPGRADING
imp/lib/Ajax/Application.php
imp/lib/Compose.php
imp/lib/Prefs/Ui.php

index 5d38116..228ea1c 100644 (file)
@@ -2081,8 +2081,7 @@ class Horde_Registry
      */
     public function getEmailCharset()
     {
-        $charset = $GLOBALS['prefs']->getValue('sending_charset');
-        if (!empty($charset)) {
+        if ($charset = $GLOBALS['prefs']->getValue('sending_charset')) {
             return $charset;
         }
 
index d05891d..e5ec937 100644 (file)
@@ -298,7 +298,7 @@ $prefGroups['language'] = array(
     'label' => _("Locale and Time"),
     'desc' => _("Set your preferred language, timezone and date preferences."),
     'members' => array(
-        'language', 'timezone', 'twentyFour', 'date_format',
+        'language', 'sending_charset', 'timezone', 'twentyFour', 'date_format',
         'date_format_mini', 'time_format', 'first_week_day'
     )
 );
@@ -312,6 +312,18 @@ $_prefs['language'] = array(
     'desc' => _("Select your preferred language:")
 );
 
+// Select widget for email charsets
+$_prefs['sending_charset'] = array(
+    'value' => '',
+    'advanced' => true,
+    'type' => 'enum',
+    'enum' => array_merge(
+        array('' => _("Default")),
+        $GLOBALS['registry']->nlsconfig['encodings']
+    ),
+    'desc' => _("Default charset for sending e-mail messages:")
+);
+
 // user time zone
 // Timezone list is dynamically built when prefs screen is displayed
 $_prefs['timezone'] = array(
@@ -545,6 +557,8 @@ $_prefs['portal_layout'] = array(
     'value' => 'a:0:{}'
 );
 
+
+
 // *** Remote Servers Preferences ***
 
 $prefGroups['remote'] = array(
@@ -626,6 +640,8 @@ $_prefs['imsp_auth_pass'] = array(
     'desc' => _("Alternate IMSP Password")
 );
 
+
+
 // *** SyncML Preferences ***
 $prefGroups['syncml'] = array(
     'column' => _("Other Information"),
@@ -650,6 +666,8 @@ $_prefs['activesyncmanagement'] = array(
     'type' => 'special'
 );
 
+
+
 // *** Internal Preferences ***
 
 // last time login tasks were run.
index 23da694..4e08280 100644 (file)
@@ -84,9 +84,15 @@ class Horde_Prefs_Ui
      */
     public function prefsInit($ui)
     {
-        global $conf;
+        global $conf, $injector, $prefs, $registry;
 
         switch ($ui->group) {
+        case 'language':
+            if (!$prefs->isLocked('sending_charset')) {
+                asort($registry->nlsconfig['encodings']);
+            }
+            break;
+
         case 'remote':
             Horde::addScriptFile('rpcprefs.js', 'horde');
             $ui->nobuttons = true;
@@ -95,7 +101,7 @@ class Horde_Prefs_Ui
 
         /* Hide appropriate prefGroups. */
         try {
-            $GLOBALS['injector']->getInstance('Horde_Core_Factory_Auth')->create()->hasCapability('update');
+            $injector->getInstance('Horde_Core_Factory_Auth')->create()->hasCapability('update');
         } catch (Horde_Exception $e) {
             $ui->suppressGroups[] = 'forgotpass';
         }
index 033ca09..5cca146 100644 (file)
@@ -282,7 +282,7 @@ case _("Send"):
         );
 
         try {
-            if ($imp_compose->buildAndSendMessage($message, $header, $registry->getEmailCharset(), $options)) {
+            if ($imp_compose->buildAndSendMessage($message, $header, $options)) {
                 $imp_compose->destroy('send');
 
                 $notification->push(_("Message sent successfully."), 'horde.success');
index 0b456b2..bf8ec65 100644 (file)
@@ -128,16 +128,10 @@ try {
 $imp_ui = new IMP_Ui_Compose();
 $stationery = $injector->getInstance('IMP_Compose_Stationery');
 
-/* Set the default charset & encoding.
- * $charset - charset to use when sending messages
- * $encoding - best guessed charset offered to the user as the default value
- *             in the charset dropdown list. */
+/* Set charset defaults. */
 $charset = $prefs->isLocked('sending_charset')
-    ? $registry->getEmailCharset()
+    ? $prefs->getValue('sending_charset')
     : $vars->charset;
-$encoding = empty($charset)
-    ? $registry->getEmailCharset()
-    : $charset;
 
 /* Is this a popup window? */
 $isPopup = ($prefs->getValue('compose_popup') || $vars->popup);
@@ -279,7 +273,7 @@ case 'reply_list':
     }
     $title .= ' ' . $header['subject'];
 
-    $encoding = empty($charset) ? $reply_msg['encoding'] : $charset;
+    $charset = $reply_msg['encoding'];
     break;
 
 case 'forward_attach':
@@ -299,7 +293,7 @@ case 'forward_both':
     $format = $fwd_msg['format'];
     $rtemode = ($rtemode || (!is_null($rtemode) && ($format == 'html')));
     $title = $header['title'];
-    $encoding = empty($charset) ? $fwd_msg['encoding'] : $charset;
+    $charset = $fwd_msg['encoding'];
     break;
 
 case 'redirect_compose':
@@ -416,6 +410,7 @@ case 'send_message':
     }
 
     $options = array(
+        'charset' => $charset,
         'encrypt' => $prefs->isLocked('default_encrypt') ? $prefs->getValue('default_encrypt') : $vars->encrypt_options,
         'html' => $rtemode,
         'identity' => $identity,
@@ -427,7 +422,7 @@ case 'send_message':
     );
 
     try {
-        $sent = $imp_compose->buildAndSendMessage($message, $header, $charset, $options);
+        $sent = $imp_compose->buildAndSendMessage($message, $header, $options);
         $imp_compose->destroy('send');
     } catch (IMP_Compose_Exception $e) {
         $get_sig = false;
@@ -811,8 +806,12 @@ if ($redirect) {
         $t->set('charset_tabindex', ++$tabindex);
         $charset_array = array();
         asort($registry->nlsconfig['encodings']);
-        foreach ($registry->nlsconfig['encodings'] as $charset => $label) {
-            $charset_array[] = array('value' => $charset, 'selected' => (strtolower($charset) == strtolower($encoding)), 'label' => $label);
+        foreach (array_merge(array('' => _("Default")), $registry->nlsconfig['encodings']) as $encoding => $label) {
+            $charset_array[] = array(
+                'label' => $label,
+                'selected' => (strcasecmp($encoding, $charset) === 0),
+                'value' => $encoding
+            );
         }
         $t->set('charset_array', $charset_array);
     }
index d2197ad..c5f9f40 100644 (file)
@@ -423,8 +423,8 @@ $prefGroups['compose'] = array(
         'mailto_handler', 'compose_cc', 'compose_bcc', 'compose_spellcheck',
         'compose_confirm', 'set_priority', 'compose_popup', 'compose_html',
         'compose_html_font_family', 'compose_html_font_size', 'mail_domain',
-        'compose_cursor', 'sending_charset', 'encryptselect',
-        'save_attachments', 'disposition_request_read'
+        'compose_cursor', 'encryptselect', 'save_attachments',
+        'disposition_request_read'
     )
 );
 
@@ -522,15 +522,6 @@ $_prefs['compose_cursor'] = array(
     'desc' => _("Where should the cursor be located in the compose text area by default?")
 );
 
-// Select widget for the possible charsets
-$_prefs['sending_charset'] = array(
-    'value' => '',
-    'advanced' => true,
-    'type' => 'enum',
-    'enum' => array_merge(array('' => _("Default")), $GLOBALS['registry']->nlsconfig['encodings']),
-    'desc' => _("Your default charset for sending messages:")
-);
-
 // Select widget for the 'default_encrypt' preference
 $_prefs['encryptselect'] = array(
     'type' => 'special'
index 29e6d6b..9e4bf22 100644 (file)
@@ -66,7 +66,7 @@ The following configuration options have been removed:
 Preferences
 -----------
 
-The 'time_format' preference has been moved to Horde.
+The 'sending_charset' and 'time_format' preferences have been moved to Horde.
 
 The following preferences are no longer used and may be safely removed from
 your ``config/prefs.php`` file and your preferences backend::
index 81b4fcc..404e747 100644 (file)
@@ -1638,8 +1638,7 @@ class IMP_Ajax_Application extends Horde_Core_Ajax_Application
         );
 
         try {
-            // TODO: Use 'sending_charset'
-            $sent = $imp_compose->buildAndSendMessage($this->_vars->message, $headers, $GLOBALS['registry']->getEmailCharset(), $options);
+            $sent = $imp_compose->buildAndSendMessage($this->_vars->message, $headers, $options);
         } catch (IMP_Compose_Exception $e) {
             $result->success = 0;
 
index 413f47f..a7e43b4 100644 (file)
@@ -177,7 +177,12 @@ class IMP_Compose implements ArrayAccess, Countable, Iterator
                                      $session)
     {
         /* Set up the base message now. */
-        $mime = $this->_createMimeMessage(array(null), $message, $charset, array('html' => $html, 'nofinal' => true, 'noattach' => !$session));
+        $mime = $this->_createMimeMessage(array(null), $message, array(
+            'charset' => $charset,
+            'html' => $html,
+            'noattach' => !$session,
+            'nofinal' => true
+        ));
         $base = $mime['msg'];
         $base->isBasePart(true);
 
@@ -444,9 +449,10 @@ class IMP_Compose implements ArrayAccess, Countable, Iterator
      *
      * @param string $body     The message body.
      * @param array $header    List of message headers.
-     * @param string $charset  The sending charset.
      * @param array $opts      An array of options w/the following keys:
      * <pre>
+     * charset - (string) The charset to use for sending the message.
+     *           DEFAULT: Horde default email charset.
      * encrypt - (integer) A flag whether to encrypt or sign the message.
      *           One of IMP::PGP_ENCRYPT, IMP::PGP_SIGNENC,
      *           IMP::SMIME_ENCRYPT, or IMP::SMIME_SIGNENC.
@@ -468,8 +474,7 @@ class IMP_Compose implements ArrayAccess, Countable, Iterator
      * @throws IMP_Compose_Exception
      * @throws IMP_Exception
      */
-    public function buildAndSendMessage($body, $header, $charset,
-                                        array $opts = array())
+    public function buildAndSendMessage($body, $header, array $opts = array())
     {
         global $conf, $notification, $prefs, $registry;
 
@@ -501,6 +506,7 @@ class IMP_Compose implements ArrayAccess, Countable, Iterator
          * are storing an encrypted message locally. */
         $send_msgs = array();
         $msg_options = array(
+            'charset' => empty($opts['charset']) ? null : $opts['charset'],
             'encrypt' => $encrypt,
             'html' => !empty($opts['html'])
         );
@@ -509,17 +515,17 @@ class IMP_Compose implements ArrayAccess, Countable, Iterator
         if ($prefs->getValue('use_smime') &&
             in_array($encrypt, array(IMP::SMIME_ENCRYPT, IMP::SMIME_SIGNENC))) {
             foreach ($recip['list'] as $val) {
-                $send_msgs[] = $this->_createMimeMessage(array($val), $body, $charset, $msg_options);
+                $send_msgs[] = $this->_createMimeMessage(array($val), $body, $msg_options);
             }
 
             /* Must target the encryption for the sender before saving message
              * in sent-mail. */
-            $save_msg = $this->_createMimeMessage(array($header['from']), $body, $charset, $msg_options);
+            $save_msg = $this->_createMimeMessage(array($header['from']), $body, $msg_options);
         } else {
             /* Can send in clear-text all at once, or PGP can encrypt
              * multiple addresses in the same message. */
             $msg_options['from'] = $barefrom;
-            $send_msgs[] = $save_msg = $this->_createMimeMessage($recip['list'], $body, $charset, $msg_options);
+            $send_msgs[] = $save_msg = $this->_createMimeMessage($recip['list'], $body, $msg_options);
         }
 
         /* Initalize a header object for the outgoing message. */
@@ -1001,9 +1007,10 @@ class IMP_Compose implements ArrayAccess, Countable, Iterator
      *
      * @param array $to        The recipient list.
      * @param string $body     Message body.
-     * @param string $charset  The charset of the message body.
      * @param array $options   Additional options:
      * <pre>
+     * 'charset' - (string) The charset of the message body.
+     *             DEFAULT: Horde default email charset.
      * 'encrypt' - (integer) The encryption flag.
      * 'from' - (string) The outgoing from address - only needed for multiple
      *          PGP encryption.
@@ -1021,9 +1028,12 @@ class IMP_Compose implements ArrayAccess, Countable, Iterator
      * @throws Horde_Exception
      * @throws IMP_Compose_Exception
      */
-    protected function _createMimeMessage($to, $body, $charset,
-                                          $options = array())
+    protected function _createMimeMessage($to, $body, array $options = array())
     {
+        $charset = empty($opts['charset'])
+            ? $GLOBALS['registry']->getEmailCharset()
+            : $opts['charset'];
+
         $body = Horde_String::convertCharset($body, 'UTF-8', $charset);
 
         if (!empty($options['html'])) {
index 2b2bb0f..7885666 100644 (file)
@@ -102,11 +102,6 @@ class IMP_Prefs_Ui
                 $ui->suppress[] = 'compose_html_font_family';
                 $ui->suppress[] = 'compose_html_font_size';
             }
-
-            /* Sort encodings. */
-            if (!$prefs->isLocked('sending_charset')) {
-                asort($registry->nlsconfig['encodings']);
-            }
             break;
 
         case 'delmove':