From: Michael M Slusarz Date: Thu, 4 Nov 2010 20:58:33 +0000 (-0600) Subject: sending_charset pref fixes X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=82bccce8fadb4691aafcf803bee94164da573408;p=horde.git sending_charset pref fixes Move from IMP to Horde (Horde_Registry::getEmailCharset() requires it). IMP now correctly honors sending_charset if locked. --- diff --git a/framework/Core/lib/Horde/Registry.php b/framework/Core/lib/Horde/Registry.php index 5d3811615..228ea1cd9 100644 --- a/framework/Core/lib/Horde/Registry.php +++ b/framework/Core/lib/Horde/Registry.php @@ -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; } diff --git a/horde/config/prefs.php.dist b/horde/config/prefs.php.dist index d05891d6b..e5ec93776 100644 --- a/horde/config/prefs.php.dist +++ b/horde/config/prefs.php.dist @@ -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. diff --git a/horde/lib/Prefs/Ui.php b/horde/lib/Prefs/Ui.php index 23da6941b..4e0828027 100644 --- a/horde/lib/Prefs/Ui.php +++ b/horde/lib/Prefs/Ui.php @@ -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'; } diff --git a/imp/compose-mimp.php b/imp/compose-mimp.php index 033ca09f6..5cca1463b 100644 --- a/imp/compose-mimp.php +++ b/imp/compose-mimp.php @@ -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'); diff --git a/imp/compose.php b/imp/compose.php index 0b456b2d7..bf8ec6569 100644 --- a/imp/compose.php +++ b/imp/compose.php @@ -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); } diff --git a/imp/config/prefs.php.dist b/imp/config/prefs.php.dist index d2197ad91..c5f9f4059 100644 --- a/imp/config/prefs.php.dist +++ b/imp/config/prefs.php.dist @@ -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' diff --git a/imp/docs/UPGRADING b/imp/docs/UPGRADING index 29e6d6bf3..9e4bf2292 100644 --- a/imp/docs/UPGRADING +++ b/imp/docs/UPGRADING @@ -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:: diff --git a/imp/lib/Ajax/Application.php b/imp/lib/Ajax/Application.php index 81b4fcce1..404e74713 100644 --- a/imp/lib/Ajax/Application.php +++ b/imp/lib/Ajax/Application.php @@ -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; diff --git a/imp/lib/Compose.php b/imp/lib/Compose.php index 413f47f43..a7e43b49f 100644 --- a/imp/lib/Compose.php +++ b/imp/lib/Compose.php @@ -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: *
+     * 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:
      * 
+     * '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'])) {
diff --git a/imp/lib/Prefs/Ui.php b/imp/lib/Prefs/Ui.php
index 2b2bb0f9f..788566698 100644
--- a/imp/lib/Prefs/Ui.php
+++ b/imp/lib/Prefs/Ui.php
@@ -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':