接續上篇追蹤 osTicket 信件處理流程的筆記,這次用 Docker 包裝可運行和測試的獨立環境,主要採用 Ubuntu 22.04 與 PHP 8.1,並且規劃方式,建構出備份原始信件的架構,以及可反覆解析信件的流程。
首先是 Dockerfile ,主要設計從 GitHub.com 取出 v1.18.1.zip 並解壓縮 /var/www/osticket-v1.18.1,其餘是安裝相關套件和資料庫的帳號建立等等,最後再把 MySQL, PHP-FPM 和 nginx 運行起來,並預設把 nginx logs 寫到 stdout 觀看:
RUN wget https://github.com/osTicket/osTicket/releases/download/v1.18.1/osTicket-v1.18.1.zip -O /tmp/osticket.zip \&& unzip /tmp/osticket.zip -d /var/www/ \&& mv /var/www/upload /var/www/osticket-v1.18.1 \&& cp /var/www/osticket-v1.18.1/include/ost-sampleconfig.php /var/www/osticket-v1.18.1/include/ost-config.php \&& chown -R www-data:www-data /var/www/osticket-v1.18.1 \&& rm /tmp/osticket.zip...RUN service mysql start && \mysql -e "CREATE USER 'developer'@'%' IDENTIFIED BY '12345678';" && \mysql -e "GRANT ALL PRIVILEGES ON *.* TO 'developer'@'%' WITH GRANT OPTION;" && \mysql -e "CREATE DATABASE osticket_dev CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;" && \mysql -e "GRANT ALL PRIVILEGES ON osticket_dev.* TO 'developer'@'%';" && \mysql -e "FLUSH PRIVILEGES;"...CMD service mysql start && service php8.1-fpm start && service nginx start && tail -f /var/log/nginx/access.log /var/log/nginx/error.log;
接下來更動 include/class.mailfetch.php 檔案,讓他下載信件時,可以存一份在 /tmp 方便後續使用:
@file_put_contents("/tmp/debug-mail.$i", $this->mbox->getRawEmail($i));
最後,弄一隻 api/cron-dev.php 檔案,可以指定 RawMail 的格式路徑,從指定位置讀進來解析信件,如此靠 api/cron-dev.php 就可以輕鬆不斷實驗 MIMEDecode 流程:
# php api/cron-dev.php[INFO] Input: /tmp/debug-mail[INFO] Input File not found# php api/cron-dev.php /tmp/debug-mail.1[INFO] Input: /tmp/debug-mail.1Ticket Object([ht] => Array([ticket_id] => 2[ticket_pid] =>...[lastupdate] => 2024-03-27 21:35:52[created] => 2024-03-27 21:35:52[updated] => 2024-03-27 21:35:52[topic] =>[staff] =>[user] => User Object([ht] => Array([id] => 2[org_id] => 0[default_email_id] => 2[status] => 0[name] => UserName[created] => 2024-03-27 21:35:52[updated] => 2024-03-27 21:35:52[default_email] => UserEmailModel Object([ht] => Array([id] => 2[user_id] => 2[flags] => 0[address] => user@example.com...
沒有留言:
張貼留言