2006年9月4日月曜日

メール環境改革 - Webメール

WebメールとはWebブラウザでメール送信と受信メールの閲覧ができる機能のことですが、
これには Web サーバが必要ですのでApache2 をインストールします。ついでに SSL 接続も利用することにします。
また、スクリプトエンジンとして PHP を導入します。
以下を実行してください。
なお、'<','>'で囲まれている文字列に関しては'<','>'も含めて適当な文字列に置き換えてください。


# emerge net-www/apache
# cd /etc/apache2/conf/
# vi apache2.conf
ServerName <server name (IP address or FQDN)> ←追加
# vi commonapache2.conf
ServerAdmin <administrator's mail address> ←変更
# vi /etc/conf.d/apache2
APACHE2_OPTS="-D SSL" ←追加
# emerge dev-php/mod_php ←数時間かかるかも知れないので注意
# vi /etc/conf.d/apache2
APACHE2_OPTS="-D SSL -D PHP4" ←変更
# rc-update add apache2 default
# /etc/init.d/apache2 start


システムの準備ができたので Web メールのアプリケーションをインストールします。
SquirrelMail と携帯電話向けに websylpheed 拡張版を利用することにします。
まず、SquirrelMail のインストールのため以下を実行します。


# emerge mail-client/squirrelmail
# cd /var/www/localhost/htdocs/squirrelmail
# ln -s squirrelmail s
# cd config
# ln -s config_default.php config.php


これで https://<サーバ名 or IPアドレス>/s/ からアクセス可能です。
なお、各自ログイン後、[Option]-[Display Preferences]で言語を日本語にする必要があります。
次に websylpheed拡張版 を入れます。
ただし、PHPの標準のインストールではモジュールが足らないので入れなおす必要があります。
以下を実行します。
ただし、前もって "websylpheed-ext_040806-ttanimu_050708.patch" ファイルを作成ください。
内容については補足として後述します。


# ebuild /usr/portage/dev-php/php/php-4.3.8.ebuild unpack
# cd /var/tmp/portage/php-4.3.8/
# touch .compiled
# cd work/php-4.3.8/
# './configure' '--prefix=/usr' '--host=i686-pc-linux-gnu' \
> '--mandir=/usr/share/man' '--infodir=/usr/share/info' \
> '--datadir=/usr/share' '--sysconfdir=/etc' '--localstatedir=/var/lib' \
> '--with-apxs2=/usr/sbin/apxs2' '--with-ndbm=/usr' '--with-db4=/usr' \
> '--with-mcrypt=/usr' '--with-mhash=/usr' '--without-interbase' \
> '--without-ming' '--without-swf' '--without-sybase' '--with-gdbm=/usr' \
> '--without-fdftk' '--without-java' '--without-mcal' \
> '--without-unixODBC' '--without-pgsql' '--without-snmp' \
> '--with-xpm-dir=/usr/X11R6' '--without-gmp' '--without-mssql' \
> '--with-pdflib=/usr' '--without-gd' '--with-png=/usr' \
> '--with-png-dir=/usr' '--with-jpeg=/usr' '--with-jpeg-dir=/usr' \
> '--enable-exif' '--with-tiff=/usr' '--with-tiff-dir=/usr' \
> '--without-mysql' '--with-freetype-dir=/usr' '--with-ttf=/usr' \
> '--with-t1lib=/usr' '--with-gettext' '--with-qtdom=/usr/qt/3' \
> '--with-pspell=/usr' '--with-openssl=/usr' '--with-imap=shared' \
> '--without-ldap' '--with-dom=/usr' '--with-dom-xslt=/usr' \
> '--with-dom-exslt=/usr' '--without-kerberos' '--with-pam' \
> '--disable-memory-limit' '--disable-ipv6' '--without-yaz' \
> '--without-curl' '--disable-dbx' '--with-zlib=/usr' \
> '--with-zlib-dir=/usr' '--with-sablot=/usr' '--enable-xslt' \
> '--with-xslt-sablot' '--with-xmlrpc' '--enable-wddx' '--with-xml' \
> '--enable-mbstring=all' '--enable-mbregex' '--with-bz2=/usr' \
> '--with-crack=/usr' '--with-cdb' '--enable-pcntl' '--enable-bcmath' \
> '--enable-calendar' '--enable-dbase' '--enable-filepro' '--enable-ftp' \
> '--with-mime-magic=/usr/share/misc/file/magic.mime' '--enable-sockets' \
> '--enable-sysvsem' '--enable-sysvshm' '--enable-sysvmsg' '--with-iconv' \
> '--enable-shmop' '--enable-dio' '--enable-yp' '--without-ncurses' \
> '--without-readline' '--enable-inline-optimization' '--enable-track-vars' \
> '--enable-trans-sid' '--enable-versioning' \
> '--with-config-file-path=/etc/php/apache2-php4' '--without-pear'
# ebuild /usr/portage/dev-php/php/php-4.3.8.ebuild merge
# make
# make install
# cd /var/www/localhost/htdocs/
# wget http://www.xyz.gr.jp/~musa/websylpheed/websylpheed-ext_040806.tar.gz
# tar zxf websylpheed-ext_040806.tar.gz
# patch -d websylpheed-ext_040806 < websylpheed-ext_040806-ttanimu_050708.patch
# cp websylpheed-ext_040806 websylpheed
# ln -s websylpheed w
# touch /etc/websylpheed.sess
# chown apache:apache /etc/websylpheed.sess
# chmod 600 /etc/websylpheed.sess
# vi /etc/apache2/conf/apache2.conf
↓ 以下を最後に追加
<Directory /var/www/localhost/htdocs/websylpheed>
php_flag register_globals On
php_flag track_vars On
php_flag magic_quotes_gpc Off

php_flag output_buffering On
php_value output_handler mb_output_handler

php_value mbstring.internal_encoding SJIS
php_value mbstring.http_input auto
php_value mbstring.http_output SJIS
</Directory>
# /etc/init.d/apache2 restart


これで https://<サーバ名 or IPアドレス>/w/ からアクセス可能です。
本編はここまでということで、
次回はメーリングリストの設定でもしておきましょうか。


- 補足 -

さて、websylpheed-ext_040806-ttanimu_050708.patch の内容は下記の通りです。
コピーして1つの空ファイルに貼り付けてください。
パッチの内容は以下の3点です。
websylpheed/common.php
dl('imap.so'); ← 最初の"<?PHP"の次の行に追加
websylpheed/maillist.php
@i18n_convert ← 3箇所あるi18n_convertの前に@を追加
多数のファイル
メール送信時に任意の from ヘッダをつける
本当はパッチファイルごとアップロードできればいいのですが、
このサイトって画像ファイルしかアップロードできないんですよね。
今回初めて気がつきました。
というわけで次行からがファイル内容となります。


diff -c websylpheed-ext_040806/address.php websylpheed-ext_040806-ttanimu_050708/address.php
*** websylpheed-ext_040806/address.php Fri Aug 6 23:04:16 2004
--- websylpheed-ext_040806-ttanimu_050708/address.php Fri Jul 8 12:00:10 2005
***************
*** 6,11 ****
--- 6,12 ----
include "functions.php";
include $db_include;

+ $from2 = urlencode($from);
$to2 = urlencode($to);
$cc2 = urlencode($cc);
$bcc2 = urlencode($bcc);
***************
*** 28,33 ****
--- 29,35 ----
<INPUT type="hidden" name="sess" value="<?=$sess?>">
<INPUT type="hidden" name="mbox" value="<?=$mbox?>">
<INPUT type="hidden" name="top" value="<?=$top?>">
+ <input type="hidden" name="from" value="<?=$from2?>">
<input type="hidden" name="to" value="<?=$to2?>">
<input type="hidden" name="cc" value="<?=$cc2?>">
<input type="hidden" name="bcc" value="<?=$bcc2?>">
***************
*** 40,46 ****
if ( $to == "" ) {
echo '宛先が選択されていません';
} else {
! $header = "From: " . $mail_addr;
$header .= "\nDate: " . date("r");
if ( $cc != "" ) {
$header .= "\nCC: ".$cc;
--- 42,48 ----
if ( $to == "" ) {
echo '宛先が選択されていません';
} else {
! $header = "From: " . $from /*$mail_addr*/;
$header .= "\nDate: " . date("r");
if ( $cc != "" ) {
$header .= "\nCC: ".$cc;
***************
*** 116,121 ****
--- 118,124 ----
<INPUT type="hidden" name="mbox" value="<?=$mbox?>">
<INPUT type="hidden" name="top" value="<?=$top?>">
<INPUT type="hidden" name="submit_flg" value="<?=$submit_flg?>">
+ <INPUT type="hidden" name="from" value="<?=$from2?>">
<INPUT type="hidden" name="to" value="<?=$to2?>">
<INPUT type="hidden" name="cc" value="<?=$cc2?>">
<INPUT type="hidden" name="bcc" value="<?=$bcc2?>">
diff -c websylpheed-ext_040806/common.php websylpheed-ext_040806-ttanimu_050708/common.php
*** websylpheed-ext_040806/common.php Sun Aug 8 13:58:12 2004
--- websylpheed-ext_040806-ttanimu_050708/common.php Thu Jul 7 17:00:12 2005
***************
*** 1,8 ****
<?PHP
/* ログインチェック */
$connstr = '{' . $server . ':' . $port . '}';
$imap = false;
! @$imap = imap_open($connstr, $user_id, $passwd);
if ($imap == false) {
header("Location: index.php");
exit;
--- 1,10 ----
<?PHP
+ dl('imap.so');
+
/* ログインチェック */
$connstr = '{' . $server . ':' . $port . '}';
$imap = false;
! $imap = imap_open($connstr, $user_id, $passwd);
if ($imap == false) {
header("Location: index.php");
exit;
diff -c websylpheed-ext_040806/functions.php websylpheed-ext_040806-ttanimu_050708/functions.php
*** websylpheed-ext_040806/functions.php Fri Aug 6 23:04:20 2004
--- websylpheed-ext_040806-ttanimu_050708/functions.php Fri Jul 8 11:05:06 2005
***************
*** 155,161 ****
}
}
} else {
! $body[] = trim( i18n_convert(imap_body($imap, $msgno, $flg), $internal_encoding, "AUTO"));
}

return array($body, $attach);
--- 155,167 ----
}
}
} else {
! $s = imap_body($imap, $msgno, $flg);
! if($mbody->encoding == 3) {
! $s = imap_base64($s);
! } elseif($mbody->encoding == 4) {
! $s = imap_qprint($s);
! }
! $body[] = trim( i18n_convert($s , $internal_encoding, "AUTO"));
}

return array($body, $attach);
diff -c websylpheed-ext_040806/mail_send.php websylpheed-ext_040806-ttanimu_050708/mail_send.php
*** websylpheed-ext_040806/mail_send.php Fri Aug 6 23:04:20 2004
--- websylpheed-ext_040806-ttanimu_050708/mail_send.php Fri Jul 8 11:56:02 2005
***************
*** 4,9 ****
--- 4,10 ----
include "common.php";
include "functions.php";

+ $from = urldecode($from);
$to = urldecode($to);
$cc = urldecode($cc);
$bcc = urldecode($bcc);
***************
*** 88,93 ****
--- 89,97 ----
新規メール作成
<br><hr>
<form action="address.php" method="post">
+ FROM:<br>
+ <input type="text" size="16" <?=$textmaxlength?> name="from" value="<?=$mail_addr?>"> <br>
+
TO: <?=$to_submit?> <br>
<input type="text" size="16" <?=$textmaxlength?> name="to" value="<?=$to?>"> <br>

diff -c websylpheed-ext_040806/maillist.php websylpheed-ext_040806-ttanimu_050708/maillist.php
*** websylpheed-ext_040806/maillist.php Fri Aug 6 23:45:00 2004
--- websylpheed-ext_040806-ttanimu_050708/maillist.php Wed Sep 22 15:18:12 2004
***************
*** 13,19 ****
if ($mbox == "INBOX") {
$boxName = "受信箱";
} else {
! $boxName = i18n_convert( decode_imap_utf7($mbox), $internal_encoding, 'UTF-8' );
if ($personal_folders != "" ){
$boxName = ereg_replace("^".$personal_folders, "", $boxName );
}
--- 13,19 ----
if ($mbox == "INBOX") {
$boxName = "受信箱";
} else {
! $boxName = @i18n_convert( decode_imap_utf7($mbox), $internal_encoding, 'UTF-8' );
if ($personal_folders != "" ){
$boxName = ereg_replace("^".$personal_folders, "", $boxName );
}
***************
*** 99,105 ****
//if ($subject == "") $subject = "(無題)";
//$subject = zen2han($subject);
//$subject = substr($subject, 0, 20) . " ";
! $subject = zen2han(i18n_convert(i18n_mime_header_decode($header->Subject), $internal_encoding, "AUTO"));
if ($subject == "") $subject = "(無題)";
$subject = substr($subject, 0, 20) . " ";
$subject = htmlSpecialChars($subject);
--- 99,105 ----
//if ($subject == "") $subject = "(無題)";
//$subject = zen2han($subject);
//$subject = substr($subject, 0, 20) . " ";
! $subject = zen2han(@i18n_convert(i18n_mime_header_decode($header->Subject), $internal_encoding, "AUTO"));
if ($subject == "") $subject = "(無題)";
$subject = substr($subject, 0, 20) . " ";
$subject = htmlSpecialChars($subject);
***************
*** 112,118 ****
$from = $header->fromaddress;
}
//$from = zen2han(i18n_mime_htmlSpecialChars($from));
! $from = zen2han(i18n_convert(i18n_mime_header_decode($from), $internal_encoding, "AUTO"));
//$from = ereg_replace("&quot;", "", $from);
$from = ereg_replace("\"", "", $from);
$from = substr($from, 0, 20) . " ";
--- 112,118 ----
$from = $header->fromaddress;
}
//$from = zen2han(i18n_mime_htmlSpecialChars($from));
! $from = zen2han(@i18n_convert(i18n_mime_header_decode($from), $internal_encoding, "AUTO"));
//$from = ereg_replace("&quot;", "", $from);
$from = ereg_replace("\"", "", $from);
$from = substr($from, 0, 20) . " ";
diff -c websylpheed-ext_040806/websylpheed.php websylpheed-ext_040806-ttanimu_050708/websylpheed.php
*** websylpheed-ext_040806/websylpheed.php Fri Aug 6 23:05:06 2004
--- websylpheed-ext_040806-ttanimu_050708/websylpheed.php Fri Jul 8 11:02:36 2005
***************
*** 43,48 ****
--- 43,49 ----
mb_http_output('SJIS');
mb_internal_encoding('SJIS');
ob_start("mb_output_handler");
+ mb_language("Japanese");

extract($_GET);
extract($_POST);
Common subdirectories: websylpheed-ext_040806/ws_check and websylpheed-ext_040806-ttanimu_050708/ws_check

0 件のコメント:

コメントを投稿