为 iredmail 1.7.1 安装 z-push 2.7.5

环境:Ubunt 24.04,iredmail 1.7.1 ,安装时,勾选了 SOGo 组件,因为需要使用它的 CalDAV 和 CardDAV 服务

步骤:

  1. apt install php-imap php-curl libawl-php php-curl php-xml php-ldap php-soap php-mbstring php-intl # 安装 php 扩展
  2. mkdir /usr/local/lib/z-push/ /var/log/z-push /var/lib/z-push # 创建 z-push 的相关目录
  3. chown www-data:www-data /var/log/z-push /var/lib/z-push # 目录给 web 用户权限
  4. wget https://github.com/Z-Hub/Z-Push/archive/refs/tags/2.7.5.tar.gz # 下载 z-push 文件
  5. cp -a src/* /usr/local/lib/z-push/ # 解压后,将得到的 src 目录里的文件,复制
  6. chown -R www-data:www-data /usr/local/lib/z-push/ # 给 web 用户权限
  7. vi /etc/nginx/templates/sogo.tmpl # 修改 sogo.tmpl 的文件内容,注释或删除原 SOGo 的 Microsoft-Server-ActiveSync 内容,用新的 z-push 替换:

    location ^~ /Microsoft-Server-ActiveSync {
     proxy_pass http://127.0.0.1:20000/SOGo/Microsoft-Server-ActiveSync;
    
     proxy_connect_timeout 3540;
     proxy_send_timeout 3540;
     proxy_read_timeout 3540;
    
     proxy_busy_buffers_size   64k;
     proxy_buffers             8 64k;
     proxy_buffer_size         64k;
    }
    
    location ^~ /SOGo/Microsoft-Server-ActiveSync {
     proxy_pass http://127.0.0.1:20000/SOGo/Microsoft-Server-ActiveSync;
    
     proxy_connect_timeout 3540;
     proxy_send_timeout 3540;
     proxy_read_timeout 3540;
    
     proxy_busy_buffers_size   64k;
     proxy_buffers             8 64k;
     proxy_buffer_size         64k;
    }

    新的:

    location /Microsoft-Server-ActiveSync {
             include /etc/nginx/fastcgi_params;
             fastcgi_param SCRIPT_FILENAME /usr/local/lib/z-push/index.php;
             fastcgi_read_timeout 630;
             include /etc/nginx/templates/fastcgi_php.tmpl;
             client_max_body_size 128M;
     }
     location ~* ^/autodiscover/autodiscover.xml$ {
             include /etc/nginx/fastcgi_params;
             fastcgi_param SCRIPT_FILENAME /usr/local/lib/z-push/autodiscover/autodiscover.php;
             include /etc/nginx/templates/fastcgi_php.tmpl;
    }
  8. systemctl restart nginx # 重启 nginx 服务
  9. vi /etc/php/8.3/fpm/php.ini # 调整 php.ini 的内容,启用 parse_ini_file 函数
  10. systemctl restart php8.3-fpm.service # 重启 php-fpm 服务
  11. vi /usr/local/lib/z-push/config.php # 编辑配置文件,其中两个需要注意的, TIMEZONE 和 BACKEND_PROVIDER 。本例,是分别设置为 上海时区 Asia/Shanghai 和 BackendCombined 即,后端数据存储是 混搭模式
  12. vi /usr/local/lib/z-push/backend/combined/config.php # 编辑混搭模式里的配置文件内容,将其中罗列的类型精简。如本例,只使用 BackendIMAP , BackendCardDAV 和 BackendCalDAV 。同时,要将目录的处理类型指定,避免出现指定不存在的 z 类型

     public static function GetBackendCombinedConfig() {
         //use a function for it because php does not allow
         //assigning variables to the class members (expecting T_STRING)
         return array(
             //the order in which the backends are loaded.
             //login only succeeds if all backend return true on login
             //sending mail: the mail is sent with first backend that is able to send the mail
             'backends' => array(
                 'i' => array(
                     'name' => 'BackendIMAP',
                 ),
                 'd' => array(
                     'name' => 'BackendCardDAV',
                 ),
                 'c' => array(
                     'name' => 'BackendCalDAV',
                 ),
             ),
             'delimiter' => '/',
             //force one type of folder to one backend
             //it must match one of the above defined backends
             'folderbackend' => array(
                 SYNC_FOLDER_TYPE_INBOX => 'i',
                 SYNC_FOLDER_TYPE_DRAFTS => 'i',
                 SYNC_FOLDER_TYPE_WASTEBASKET => 'i',
                 SYNC_FOLDER_TYPE_SENTMAIL => 'i',
                 SYNC_FOLDER_TYPE_OUTBOX => 'i',
                 SYNC_FOLDER_TYPE_TASK => 'c',
                 SYNC_FOLDER_TYPE_APPOINTMENT => 'c',
                 SYNC_FOLDER_TYPE_CONTACT => 'd',
                 SYNC_FOLDER_TYPE_NOTE => 'c',
                 SYNC_FOLDER_TYPE_JOURNAL => 'c',
                 SYNC_FOLDER_TYPE_OTHER => 'i',
                 SYNC_FOLDER_TYPE_UNKNOWN => 'i',
             ),
             //creating a new folder in the root folder should create a folder in one backend
             'rootcreatefolderbackend' => 'i',
         );
     }
  13. vi /usr/local/lib/z-push/backend/imap/config.php # 配置 imap 的连接配置文件内容。本例是将 IMAP_PORT 设置为 993 端口;IMAP_OPTIONS 设置为 /ssl/novalidate-cert ,即使用 SSL 加密连接,不验证证书;IMAP_FOLDER_CONFIGURED 设置为 true
  14. vi /usr/local/lib/z-push/backend/caldav/config.php # 配置 caldav 的连接配置文件内容。CALDAV_SERVER 填写完整的主机名,如 mail.example.com ;CALDAV_PATH 填写 /SOGo/dav/%u/Calendar/ ; CALDAV_PERSONAL 填写 /SOGo/dav/%u/Calendar/personal/ ;CALDAV_SUPPORTS_SYNC 可设置为 true
  15. vi /usr/local/lib/z-push/backend/carddav/config.php # 配置 carddav 的连接配置文件内容。CARDDAV_PATH 设置为 /SOGo/dav/%u/Contacts/ ; CARDDAV_DEFAULT_PATH 设置为 /SOGo/dav/%u/Contacts/personal/ ;注释掉 CARDDAV_GAL_PATH 和 CARDDAV_GAL_MIN_LENGTH 两行
  16. 在浏览器里访问 https://mail.example.com/Microsoft-Server-ActiveSync ,应该会弹框,需入邮箱地址和密码,能成功登录
  17. 在 Nine Mail app 里,使用兼容 Exchange ActiveSync 的账户类型添加,能发邮件、创建日历事件 和 联系人,并且能在 SOGo Webmail 里看到新建的内容
  18. 如有报错,请查看 /var/log/z-push/z-push-error.log 日志内容

参考:

标签: iredmail, z-push

添加新评论