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

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

当 OTRS 从 IMAP 帐户提取电子邮件时,它会忘记原始发送日期并将其替换为提取日期 (!)。
通常这不是问题,但当您将包含许多电子邮件的现有 IMAP 文件夹导入时,OTRS所有日期都会设置为导入数据。

这可不是什么好事,我想知道是否有办法让 OTRS 读取电子邮件标题并使用它来替换表create_time中的字段article。我考虑使用邮政局长的过滤器模块(或类似的东西)。

如何让 OTRS 读取date电子邮件中的标题并使用日期为create_time

答案1

简短的回答是:这是不可能的。详细的回答是:如果您想这样做,您需要修改 TicketCreate() 方法,因为它目前只将当前时间作为新票的创建日期。

答案2

我发现的解决方案是向 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

答案3

我遇到了同样的问题。非常感谢您的帮助。这些程序对我来说不起作用,所以我更改了它并使用临时表。

CREATE TABLE `article_plain_date` (
  `article_plain_FK` INT(11) NOT NULL,
  `atricle_ID` INT(11) DEFAULT NULL,
  `ticket_ID` INT(11) DEFAULT NULL,
  `create_date` DATETIME DEFAULT NULL,
  PRIMARY KEY (`article_plain_FK`)
) ENGINE=MYISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

INSERT INTO article_plain_date
SELECT p.id,a.id,t.id,IF(STR_TO_DATE(MID(body,LOCATE('Date: ',body)+6,25),'%a, %e %M %Y %k:%i:%s'),STR_TO_DATE(MID(body,LOCATE('Date: ',body)+6,25),'%a, %e %M %Y %k:%i:%s'),p.create_time) AS create_date  FROM otrs.article_plain p

JOIN article a ON (p.`article_id` = a.id)
JOIN ticket t ON (a.`ticket_id` = t.id);

UPDATE article_plain p
JOIN article_plain_date d ON (p.`article_id` = d.`atricle_ID`)
SET p.`create_time` = d.`create_date`;

UPDATE article a
JOIN article_plain_date d ON (a.id = d.`atricle_ID`)
SET a.`create_time` = d.`create_date`;

UPDATE ticket t
JOIN article_plain_date d ON (t.id = d.`ticket_ID`)
SET t.`create_time` = d.`create_date`, t.`create_time_unix` = UNIX_TIMESTAMP(d.`create_date`);

相关内容