Otrs

如何在 OTRS 中使用原始發件人日期而不是獲取日期

  • March 22, 2015

當 OTRS 從 IMAP 帳戶提取電子郵件時,它會忘記原始發送日期並將其替換為提取 (!) 日期。

通常這不是問題,但是當您將包含許多電子郵件的現有 IMAP 文件夾導入到OTRS所有日期時,所有日期都會設置為導入數據。

這並不酷,我想知道是否有某種方法可以讓 OTRS 讀取電子郵件標題並使用它來替換錶create_time中的欄位article。我正在考慮使用 postmaster 的過濾器模組(或類似的東西)。

如何讓 OTRS 讀取date電子郵件中的標題並將日期用於create_time?

我找到的解決方案是向 MySQL 添加一個觸發器,如下所示:

article_attachement

CREATE TRIGGER bi_article_attachement_each BEFORE INSERT ON article_attachment
FOR EACH ROW
BEGIN

 DECLARE newdate datetime;
 SET newdate = null;

 SELECT create_time INTO newdate FROM article_plain ap WHERE ap.article_id = new.article_id LIMIT 1;

 IF newdate IS NOT NULL THEN
   SET new.create_time = newdate;
   SET new.change_time = newdate;
 END IF;


END

article_plain

CREATE TRIGGER bi_article_plain_each BEFORE INSERT ON article_plain
FOR EACH ROW
BEGIN
 DECLARE datestr CHAR(40);
 DECLARE newdate DATETIME;
 DECLARE mindate DATETIME;
 DECLARE myticket BIGINT;

 SET datestr = mid(new.body,locate('Date: ',new.body)+6,40);
 SET newdate = coalesce(str_to_date(datestr,'%a, %e %M %Y %k:%i:%s'),str_to_date(datestr,'%e %M %Y %k:%i:%s'),new.create_time);  

 SET new.create_time = newdate;

 UPDATE article a SET a.create_time = newdate WHERE a.id = new.article_id; 

 SELECT a.ticket_id INTO myticket FROM article a WHERE a.id = new.article_id LIMIT 1;
 SELECT least(min(a.create_time),new.create_time) INTO mindate FROM article a WHERE a.ticket_id = myticket;

 UPDATE ticket t
   SET t.create_time = least(t.create_time, mindate)
       , t.create_time_unix = unix_timestamp(least(t.create_time, mindate))
   WHERE t.id = myticket;

END

同一張表,但更新後

CREATE TRIGGER ua_article_plain_each AFTER UPDATE ON article_plain
FOR EACH ROW
BEGIN

 IF old.create_time <> new.create_time THEN BEGIN

   UPDATE article a SET a.create_time = new.create_time, a.change_time = new.create_time WHERE a.id = new.article_id;

 END; END IF;

END

最後觸發ticket

CREATE TRIGGER bu_ticket_each BEFORE UPDATE ON ticket
FOR EACH ROW
BEGIN
 DECLARE newtn varchar(50);
 DECLARE newdate varchar(12);
 DECLARE filter varchar(13);
 SET newdate = date_format(old.create_time,'%Y%m%d%H%i');
 SET filter = concat(newdate,'%');
 SELECT concat(newdate,ifnull(right(concat('0000',right(max(tn),4)+1),4),'0001')) INTO newtn 
   FROM ticket
   WHERE tn LIKE filter;
 SET new.tn = newtn;
END

簡短的回答是:這是不可能的。長答案是:如果你想這樣做,你需要修改 TicketCreate() 方法,因為它目前只會將目前時間作為新工單的創建日期。

引用自:https://serverfault.com/questions/408430