fetchmail Plugin

  1. 從 GitHub 下載原始碼。
    https://github.com/PF4Public/fetchmail
    
  2. 必須安裝 fetchmail 套件。
    [root@mail ~]# yum install fetchmail
    
  3. 解壓縮至 roundcubemail 插件目錄 plugins。
    [root@mail ~]# cd /usr/share/roundcubemail/plugins/
    [root@mail plugins]# unzip fetchmail-master.zip
    
  4. 解壓縮的目錄為 fetchmail-master 與插件主 php 檔 fetchmail.php 及 class 名稱不同,必須改成 fetchmail
    [root@mail plugins]# ls fetchmail-master
    composer.json        fetchmail.js   localization  skins
    config.inc.php.dist  fetchmail.php  README.md     SQL
    
    [root@mail plugins]# mv fetchmail-master fetchmail
    
  5. roundcubemail 啟動 fetchmail 插件。
    [root@mail plugins]# vim /etc/roundcubemail/config.inc.php
    [root@mail plugins]# grep fetchmail /etc/roundcubemail/config.inc.php
    $config['plugins'] = array('fetchmail',# 'pop3fetcher',
    
  6. 將 fetchmail 插件附的 mysql.initial.sql 匯入 roundcube 資料庫,會產生 fetchmail 資料表供插件存取用。
    [root@mail fetchmail]# mysql -uroot -p roundcube < SQL/mysql.initial.sql 
    Enter password:
    
  7. 下載 fetchmail.pl。
    [root@mail plugins]# cd fetchmail
    [root@mail fetchmail]# wget https://sourceforge.net/p/postfixadmin/code/HEAD\
    /tree/trunk/ADDITIONS/fetchmail.pl?format=raw \
    --no-check-certificate -O fetchmail.pl
    
  8. 修改 fetchmail.pl 程式:使用 mysql 資料庫,確定設定的資料庫、帳號及密碼確實可以登入 mysql 且有存取資料庫的權限。
    [root@mail fetchmail]# diff -uN fetchmail.pl.orig fetchmail.pl
    --- fetchmail.pl.orig   2016-06-06 14:14:55.335002899 +0800
    +++ fetchmail.pl    2016-06-06 14:25:48.907678523 +0800
    @@ -14,17 +14,17 @@
     # database settings
     
     # database backend - uncomment one of these
    -our $db_type = 'Pg';
    -#my $db_type = 'mysql';
    +#our $db_type = 'Pg';
    +my $db_type = 'mysql';
     
     # host name
     our $db_host="127.0.0.1";
     # database name
    -our $db_name="postfix";
    +our $db_name="roundcube";
     # database username
    -our $db_username="mail";
    +our $db_username="roundcube";
     # database password
    -our $db_password="CHANGE_ME!";
    +our $db_password="XXXXXXXXX";
     
     # instead of changing this script, you can put your settings to /etc/mail/postfixadmin/fetchmail.conf
     # just use perl syntax there to fill the variables listed above (without the "our" keyword). Example:
    
  9. 修改 fetchmail.pl 程式:fetchmail 插件存入資料庫的 active 欄位是 0 或 1,不是 t。
    @@ -83,7 +83,7 @@
     if($db_type eq "Pg") {
        $sql_cond = "active = 1 AND date_part('epoch',now())-date_part('epoch',date)";
     } elsif($db_type eq "mysql") {
    -   $sql_cond = "active = 't' AND unix_timestamp(now())-unix_timestamp(date)";
    +   $sql_cond = "active = 1 AND unix_timestamp(now())-unix_timestamp(date)";
     }
     
     $sql = "
    
  10. 修改 fetchmail.pl 程式:fetchmail 插件設定 fetchmail 時存入資料庫的 mailbox 欄位是自動取得 roundcubemail 上的帳號,如果沒有 @momainname 會自動加入 @localhost,但這會造成信件無法無法傳送到 username@localhost,所以。
    @@ -96,6 +96,7 @@
     map{
        my ($id,$mailbox,$src_server,$src_auth,$src_user,$src_password,$src_folder,$fetchall,$keep,$protocol,$mda,$extra_options,$usessl,$sslcertck,$sslcertpath,$sslfingerprint)=@$_;
     
    +   $mailbox.='@'.$ENV{'HOSTNAME'};
        syslog("info","fetch ${src_user}@${src_server} for ${mailbox}");
     
        $cmd="user '${src_user}' there with password '".decode_base64($src_password)."'";
    
  11. 將 fetchmail.pl 設定擁有者及群組都為 mail,且可執行。
    [root@mail fetchmail]# chown mail.mail fetchmail.pl
    [root@mail fetchmail]# chmod 700 fetchmail.pl
    [root@mail fetchmail]# ll fetchmail.pl
    -rwx------. 1 mail mail 3940 Jun  6 14:25 fetchmail.pl
    
  12. 設定每 5 分鐘以 mail 帳號執行 fetchmail.pl,依據 roundcube 資料庫中的資料表 fetchmail 進行收信。
    [root@mail fetchmail]# vim /etc/cron.d/fetchmail 
    [root@mail fetchmail]# cat /etc/cron.d/fetchmail 
    */5 * * * * mail /usr/share/roundcubemail/plugins/fetchmail/fetchmail.pl
    
  13. 增加收取遠端郵件間格最小 3 分鐘。
    [root@mail fetchmail]# diff -uN ../fetchmail-master/fetchmail.php fetchmail.php 
    --- ../fetchmail-master/fetchmail.php	2016-05-16 23:56:37.000000000 +0800
    +++ fetchmail.php	2016-06-06 20:18:35.808930991 +0800
    @@ -239,6 +239,7 @@
    				'id' => $field_id 
    		) );
    		$input_fetchmailpollinterval->add ( array (
    +				'3',
    				'5',
    				'10',
    				'15',
    @@ -247,6 +248,7 @@
    				'30',
    				'60' 
    		), array (
    +				'3',
    				'5',
    				'10',
    				'15',
    
  14. 設定項目標籤欄位太小,以致於整個畫面過高,且設定表格與帳號顯示表格寬度不一致。加大 fetchmail 插件設定界面最大寬度,並讓帳號顯示背景不大於表格寬度,則兩個表格顯示寬度一樣。
    [root@mail fetchmail]# diff -uN ../fetchmail-master/skins/default/fetchmail.css skins/default/fetchmail.css
    --- ../fetchmail-master/skins/default/fetchmail.css	2016-05-16 23:56:37.000000000 +0800
    +++ skins/default/fetchmail.css	2016-06-06 20:16:26.698405723 +0800
    @@ -3,7 +3,7 @@
    	background-color: #F9F9F9;
    	height: 163px;
    	overflow: auto;
    -	width: 450px;
    +	width: 650px;
     }
     
     body.fetch-table {
    @@ -42,7 +42,7 @@
     
     #myprefs {
    	/* border: 1px solid #909090 !important;*/
    -	width: 480px;
    +	width: 680px;
    	padding-top: 12px;
    	padding-left: 12px;
    	padding-bottom: 6px;