星期六, 3月 14, 2015

sendmail + squirrelmail + imap-uw (Connection dropped by IMAP server)

級成 FreeBSD 10.1 版後,因為 mail/openwebmail 配合 port mail/spamassassin 裡的 net-mgmt/p5-NetAddr-IP port 一直都無法安裝完成,所以只好暫時尋找替代的網路信箱程式。發現 squirrelmail 的中文化成度似乎比較好,國內也有很多使用者經驗可以參考,所以決定換裝這個伺服軟體替代。Mailserver 還是以 FreeBSD 裡預設的 sendmail 做服務,對這個套件的設定比較熟,也不用再吃新苦頭。

因為 mail/squirrelmail 需要 IMAP server 配合,所以搭配了 mail/imap-uw 一起工作。imap-uw 的設定在 inetd 裡,修改 pop2/ pop3/ imap 的服務後,在 /etc/rc.conf 裡寫入 inetd_enable="YES",以後開機就會配合開起來。

Squirrelmail 裝好,依照說明完整的設定後,一直無法在瀏覽器上順利開啟服務,網頁總是跑到一半就停止,無法讀取信箱的內容。網頁上顯示錯誤訊息 [ERROR : Connection dropped by IMAP server.]。一直以為問題發生在 IMAP server 上,可是重新安裝、重新設定還是無法解決問題。

進一步檢視了 SquirrelMail 提供的 configtest 檢查頁面裡頭顯示息 [ERROR: You have configured PHP not to allow short tags (short_open_tag=off). This shouldn't be a problem with SquirrelMail or any plugin coded coded according to the SquirrelMail Coding Guidelines, but if you experience problems with PHP code being displayed in some of the pages and changing setting to "on" solves the problem, please file a bug report against the failing plugin. The correct contact information is most likely to be found in the plugin documentation.]。卻也沒有人提供經驗如何修改 short_open_tag=off 的設定。寫了信去尋求 port maintainer 協助也沒有改進的建議。

這問題持續了好久,後來在 MailServerIMAPProblem 頁面裡找到答案,只要把 php.ini 裡頭的 default_socket_timeout 時間給延長就可以了。網頁裡說 例如 600,所以就改 600 (10 分鐘)。

# ee /usr/local/etc/php.ini
default_socket_timeout=600

存檔後重起 Apache 就可以順利進入網路信箱的服務功能。相較於 openwebmail 的開啟速度,squirrelmail 真的是慢太多了。

 MailServerIMAPProblem 裡還有提到另兩個解決的方法,不過沒試過,應該也會有效。

(1) If you want to increase the timeout in SquirrelMail 1.x go to line 444 of functions/imap_general.php and change the last parameter of the fsockopen() call from 15 [seconds] to something larger. Keep in mind that if you increase this, you may also need to increase the "max_execution_time" parameter in your php.ini file.

(2) Instead of the previous fix, you should add the following line at line 445 of functions/imap_general.php so that the stream doesn't time out while fgets() is waiting:

stream_set_timeout($imap_stream,600); // wait max 10 minutes for IMAP request to complete


沒有留言: