カテゴリー
FreeBSD PHP Squirrelmail

Squirrelmailとphp5.4

FreeBSDのportsにSquirrelmailが入るようになってからずっとports版のSquirrelmailを使っていました。でも、php5.4の環境でインストールしようとするとportsが

/usr/ports/mail/squirrelmail# make configure
===> squirrelmail-1.4.22_3 cannot be installed: doesn't work with lang/php5 port (<span style="color: #ff0000;">doesn't support PHP 5.4</span>).
*** [configure] Error code 1

Stop in /usr/ports/mail/squirrelmail.

と怒ってインストールさせてくれません。仕方が無いのphp 5.3 (php53-*)のportsを入れてやり過ごしてきました。

最近になって、Squirrelmail本家のサイトを見てみると、

ANNOUNCE: PHP 5.4 & 5.5 Compatibility
May 30, 2013 by Paul Lesniewski

PHP 5.4 and PHP 5.5 compatibility fixes are live in our nightly snapshots, and we strongly encourage those who’d like to help test or those who are having problems with version 1.4.22 to download a snapshot and report any problems.

と出てたのでphp 5.4でこのsnapshotはどうなるのか試してみました。

http://snapshots.squirrelmail.org/squirrelmail-20130825_0200-SVN.stable.tar.gz

Squirrelmailのsnapshotをサーバーにダウンロードして、/usr/local/www/squirrelmailに展開します。ports版で使っていた./config/config.phpをそのまま使ってもよかったのですが、今回は新規で設定し直しました。 ./configureで環境に合わせて設定します。

Main Menu

SquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
Main Menu --
1.  Organization Preferences
2.  Server Settings
3.  Folder Defaults
4.  General Options
5.  Themes
6.  Address Books
7.  Message of the Day (MOTD)
8.  Plugins
9.  Database
10. Languages

D.  Set pre-defined settings for specific IMAP servers

C   Turn color on
S   Save data
Q   Quit

Command >>

Command >>1 Organization Preferences

SquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
Organization Preferences
1.  Organization Name      : (組織名)
2.  Organization Logo      : ../images/(ロゴファイル)
3.  Org. Logo Width/Height : (横サイズ/縦サイズ)
4.  Organization Title     : SquirrelMail $version
5.  Signout Page           :
6.  Top Frame              : _top
7.  Provider link          : http://(プロバイダURL)/
8.  Provider name          : (プロバイダ名)

R   Return to Main Menu
C   Turn color on
S   Save data
Q   Quit

Command >>

Command >>2 Server Settings

SquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
Server Settings

General
-------
1.  Domain                 : (自ドメイン名)
2.  Invert Time            : false
3.  Sendmail or SMTP       : SMTP

A.  Update IMAP Settings   : localhost:143 (dovecot)
B.  Update SMTP Settings   : localhost:25

R   Return to Main Menu
C   Turn color on
S   Save data
Q   Quit

Command >>

Command >>3 Folder Defaults

SquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
Folder Defaults
1.  Default Folder Prefix          :
2.  Show Folder Prefix Option      : false
3.  Trash Folder                   : Trash
4.  Sent Folder                    : Sent
5.  Drafts Folder                  : Drafts
6.  By default, move to trash      : true
7.  By default, save sent messages : true
8.  By default, save as draft      : true
9.  List Special Folders First     : true
10. Show Special Folders Color     : true
11. Auto Expunge                   : true
12. Default Sub. of INBOX          : true
13. Show 'Contain Sub.' Option     : false
14. Default Unseen Notify          : 2
15. Default Unseen Type            : 1
16. Auto Create Special Folders    : true
17. Folder Delete Bypasses Trash   : false
18. Enable /NoSelect folder fix    : false

R   Return to Main Menu
C   Turn color on
S   Save data
Q   Quit

Command >>

Command >>4 General Options

SquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
General Options
1.  Data Directory               : /var/spool/squirrelmail/pref/
2.  Attachment Directory         : /var/spool/squirrelmail/attach/
3.  Directory Hash Level         : 0
4.  Default Left Size            : 150
5.  Usernames in Lowercase       : true
6.  Allow use of priority        : true
7.  Hide SM attributions         : false
8.  Allow use of receipts        : true
9.  Allow editing of identity    : true
    Allow editing of name        : true
    Remove username from header  : false
10. Allow server thread sort     : false
11. Allow server-side sorting    : false
12. Allow server charset search  : true
13. Enable UID support           : true
14. PHP session name             : SQMSESSID
15. Location base                :
16. Only secure cookies if poss. : true
17. Disable secure forms         : false
18. Page referal requirement     :
19. Browser rendering mode       : quirks

R   Return to Main Menu
C   Turn color on
S   Save data
Q   Quit

Command >>

Command >>5 Themes

SquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
Themes
1.  Change Themes
Default                                     Plain Blue
Sand Storm                                  Deep Ocean
Slashdot                                    Purple
Forest                                      Ice
Sea Spray                                   Blue Steel
Dark Grey                                   High Contrast
Black Bean Burrito                          Servery
Maize                                       BluesNews
Deep Ocean 2                                Blue Grey
Dompie                                      Methodical
Greenhouse Effect (Changes)                 In The Pink (Changes)
Kind of Blue (Changes)                      Monostochastic (Changes)
Shades of Grey (Changes)                    Spice of Life (Changes)
Spice of Life - Lite (Changes)              Spice of Life - Dark (Changes)
Holiday - Christmas                         Darkness (Changes)
Random (Changes every login)                Midnight
Alien Glow                                  Dark Green
Penguin                                     Minimal BW
Redmond                                     Net Style
Silver Steel                                Simple Green
Wood                                        Bluesome
Simple Green 2                              Simple Purple
Autumn                                      Autumn 2
Blue on Blue                                Classic Blue
Classic Blue 2                              Powder Blue
Techno Blue                                 Turquoise
Solarized Light                             Solarized Dark
2.  CSS File :

R   Return to Main Menu
C   Turn color on
S   Save data
Q   Quit

Command >>

Command >>6 Address Books

SquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
Address Books
1.  Change LDAP Servers
2.  Use Javascript Address Book Search          : false
3.  Global file address book                    :
4.  Allow writing into global file address book : false
5.  Allow listing of global file address book   : true
6.  Allowed address book line length            : 2048

R   Return to Main Menu
C   Turn color on
S   Save data
Q   Quit

Command >>

Command >>7 Message of the Day (MOTD)

SquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
Message of the Day (MOTD)

1   Edit the MOTD

R   Return to Main Menu
C   Turn color on
S   Save data
Q   Quit

Command >>

Command >>8 Plugins

SquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
Plugins
Installed Plugins
1. filters
2. mail_fetch
3. message_details

Available Plugins:
4. administrator
5. bug_report
6. calendar
7. delete_move_next
8. demo
9. fortune
10. info
11. listcommands
12. newmail
13. sent_subfolders
14. spamcop
15. squirrelspell
16. test
17. translate

R   Return to Main Menu
C   Turn color on
S   Save data
Q   Quit

Command >>

Command >>9 Database

SquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
Database
1.  DSN for Address Book   :
2.  Table for Address Book : address

3.  DSN for Preferences    :
4.  Table for Preferences  : userprefs
5.  Field for username     : user
6.  Field for prefs key    : prefkey
7.  Field for prefs value  : prefval

8.  DSN for Global Address Book            :
9.  Table for Global Address Book          : global_abook
10. Allow writing into Global Address Book : false
11. Allow listing of Global Address Book   : false

R   Return to Main Menu
C   Turn color on
S   Save data
Q   Quit

Command >>

Command >>10 Language preferences

SquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
Language preferences
1.  Default Language       : en_US (日本語表記の場合は ja_JP)
2.  Default Charset        : iso-2022-jp
3.  Enable lossy encoding  : false

R   Return to Main Menu
C   Turn color on
S   Save data
Q   Quit

Command >>

Command >>D Set pre-defined settings for specific IMAP servers

SquirrelMail Configuration : Read: config.php
---------------------------------------------------------
While we have been building SquirrelMail, we have discovered some
preferences that work better with some servers that don't work so
well with others.  If you select your IMAP server, this option will
set some pre-defined settings for that server.

Please note that you will still need to go through and make sure
everything is correct.  This does not change everything.  There are
only a few settings that this will change.

Please select your IMAP server:
bincimap    = Binc IMAP server
courier     = Courier IMAP server
cyrus       = Cyrus IMAP server
dovecot     = Dovecot Secure IMAP server
exchange    = Microsoft Exchange IMAP server
hmailserver = hMailServer
macosx      = Mac OS X Mailserver
mercury32   = Mercury/32
uw          = University of Washington's IMAP server
gmail       = IMAP access to Google mail (Gmail) accounts

quit        = Do not change anything
Command >> quit

imap_server_type = dovecot
default_folder_prefix =
trash_folder = Trash
sent_folder = Sent
draft_folder = Drafts
show_prefix_option = false
default_sub_of_inbox = true
show_contain_subfolders_option = false
optional_delimiter = detect
delete_folder = false

Press enter to continue...

以上の設定で結果的に元々の./config/config.phpと新規との違いは

# diff ./config/config.php-ports ./config/config.php
68c68
< $force_username_lowercase = false;
---
> $force_username_lowercase = true;
189a190,193
> $theme[52]['PATH'] = SM_PATH . 'themes/solarized_light.php';
> $theme[52]['NAME'] = 'Solarized Light';
> $theme[53]['PATH'] = SM_PATH . 'themes/solarized_dark.php';
> $theme[53]['NAME'] = 'Solarized Dark';
220a225
> $browser_rendering_mode  = 'quirks';

これだけでした。
httpd.confの設定はこんな感じ。

Alias /webmail "/usr/local/www/squirrelmail"
<Directory /usr/local/www/squirrelmail>
    AllowOverride All
    Options FollowSymLinks ExecCGI Includes
    Allow from All
</Directory>

Apacheを再起動してwebmailとしてアクセスしてみると、

Strict Standards: Non-static method Message::parseStructure() should not be called statically in /usr/local/www/squirrelmail/functions/mime.php on line 36

Strict Standards: Non-static method Message::parseBodyStructure() should not be called statically in /usr/local/www/squirrelmail/class/mime/Message.class.php on line 296

Warning: Cannot modify header information – headers already sent by (output started at /usr/local/www/squirrelmail/functions/mime.php:36) in /usr/local/www/squirrelmail/functions/page_header.php on line 31

こんな感じで新規にメールを開くときにエラー(警告)が出てきて画面が乱れます。調べてみると、php 5.4からより厳格に書式をチェックして警告を出すようになったみたいで、以下のようにphp.iniでエラー表示レベルを変更することでこれらのメッセージを消すことができました。

;   - Show all errors except for notices and coding standards warnings
;
;error_reporting = E_ALL & ~E_NOTICE
error_reporting = E_ALL & ~E_STRICT

; Print out errors (as a part of the output).  For production web sites,
; you're strongly encouraged to turn this feature off, and use error logging

ざっくりですが、日本語で使ってみても大丈夫のようです。以前、php 5.4対応をするという記事で書かれていたhtmlspecialcharsに対する修正内容相当のコードが入っているみたいです。

./functions/strings.php

/**
  * Wrapper for PHP's htmlspecialchars() that
  * attempts to add the correct character encoding
  *
  * @param string $string The string to be converted
  * @param int $flags A bitmask that controls the behavior of htmlspecialchars()
  *                   (See http://php.net/manual/function.htmlspecialchars.php )
  *                   (OPTIONAL; default ENT_COMPAT)
  * @param string $encoding The character encoding to use in the conversion
  *                         (OPTIONAL; default automatic detection)
  * @param boolean $double_encode Whether or not to convert entities that are
  *                               already in the string (only supported in
  *                               PHP 5.2.3+) (OPTIONAL; default TRUE)
  *
  * @return string The converted text
  *
  */
function sm_encode_html_special_chars($string, $flags=ENT_COMPAT,
                                      $encoding=NULL, $double_encode=TRUE)
{
   if (!$encoding)
   {
      global $default_charset;
      if ($default_charset == 'iso-2022-jp')
         $default_charset = 'EUC-JP';
      $encoding = $default_charset;
   }

   if (check_php_version(5, 2, 3))
      return htmlspecialchars($string, $flags, $encoding, $double_encode);

   return htmlspecialchars($string, $flags, $encoding);
}

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です