]> pere.pagekite.me Git - homepage.git/blob - linux/otsr-1.1.3-mail-replies.diff
Generated.
[homepage.git] / linux / otsr-1.1.3-mail-replies.diff
1 Patch to add References and In-Reply-To parsing and handling to OTRS.
2
3 Created 2004-01-09 by Petter Reinholdtsen <pere@hungry.com>
4
5 --- Kernel/Config/Defaults.pm.orig 2003-07-13 21:23:21.000000000 +0200
6 +++ Kernel/Config/Defaults.pm 2004-01-09 15:21:43.000000000 +0100
7 @@ -714,6 +714,8 @@
8 'Mailing-List',
9 'X-Loop',
10 'X-No-Loop',
11 + 'References',
12 + 'In-Reply-To',
13 'X-OTRS-Loop',
14 'X-OTRS-Info',
15 'X-OTRS-Priority',
16 --- Kernel/System/PostMaster.pm.orig 2003-06-22 20:37:36.000000000 +0200
17 +++ Kernel/System/PostMaster.pm 2004-01-09 16:57:48.000000000 +0100
18 @@ -221,23 +221,91 @@
19 my $Self = shift;
20 my %Param = @_;
21 my $Subject = $Param{Subject} || '';
22 - if (my $Tn = $Self->{TicketObject}->GetTNByString($Subject)) {
23 - my $TicketID = $Self->{TicketObject}->CheckTicketNr(Tn => $Tn);
24 + my $Tn;
25 + my $TicketID;
26 + if ($Tn = $Self->{TicketObject}->GetTNByString($Subject)) {
27 + $TicketID = $Self->{TicketObject}->CheckTicketNr(Tn => $Tn);
28 if ($Self->{Debug} > 1) {
29 $Self->{LogObject}->Log(
30 Priority => 'debug',
31 Message => "CheckFollowUp: Tn: $Tn found or forward!",
32 );
33 }
34 - if ($TicketID) {
35 - if ($Self->{Debug} > 1) {
36 - $Self->{LogObject}->Log(
37 + } else {
38 + # Based on info from <URL:http://www.jwz.org/doc/threading.html>
39 + my @msgids = ();
40 +
41 + # Extract Message-id(s) from References and In-Reply-to
42 + my $references = $Param{References};
43 + my $inreplyto = $Param{'In-Reply-To'}; # XXX Check capitalisation
44 +
45 + push(@msgids, split(/\s+/, $references)) if ($references);
46 +
47 + if ($inreplyto) {
48 + if ($inreplyto =~ m/(<[^>]+>)/) {
49 + push(@msgids, $1);
50 + } else {
51 + $Self->{LogObject}->Log(
52 + Priority => 'debug',
53 + Message => "CheckFollowUp: Unhandled In-Reply-To: '$inreplyto'",
54 + );
55 + }
56 + }
57 +
58 + # Look up Message-id(s) using Article::ArticleMsgIdLookup
59 + my @ids = ();
60 + my %checked;
61 + my $msgid;
62 + for $msgid (@msgids) {
63 + next if $checked{$msgid};
64 + my @ArticleIDs =
65 + $Self->{TicketObject}->ArticleMsgIdLookup(MessageID => $msgid);
66 + my @TicketIDs;
67 + my $aid;
68 + for $aid (@ArticleIDs) {
69 + my %data =
70 + $Self->{TicketObject}->GetArticle(ArticleID => $aid);
71 + my $tn = $Self->{TicketObject}->GetTNOfId(ID => $data{TicketID});
72 + push(@TicketIDs, $tn);
73 + }
74 + push(@ids, @TicketIDs) if (@TicketIDs);
75 + $checked{$msgid} = 1;
76 + }
77 +
78 + # Reduce list of IDs to unique IDs only
79 + my $id;
80 + my %idhash;
81 + for $id (sort @ids) {
82 + $idhash{$id} = 1;
83 + }
84 + @ids = sort keys %idhash;
85 +
86 + # If the Message-id(s) are already in the database, use their
87 + # ticked-id
88 + if (1 < @ids) {
89 + if ($Self->{Debug} > 1) {
90 + $Self->{LogObject}->Log(
91 + Priority => 'debug',
92 + Message => "CheckFollowUp: Several possible ticket ids",
93 + );
94 + }
95 + }
96 +
97 + # Just pick the first. Not sure how we should handle several
98 + # ticket ids
99 + if (@ids) {
100 + $Tn = $ids[0];
101 + $TicketID = $Self->{TicketObject}->CheckTicketNr(Tn => $Tn);
102 + }
103 + }
104 + if ($TicketID) {
105 + if ($Self->{Debug} > 1) {
106 + $Self->{LogObject}->Log(
107 Priority => 'debug',
108 - Message => "CheckFollowUp: ja, it's a follow up ($Tn/$TicketID)",
109 + Message => "CheckFollowUp: yes, it's a follow up ($Tn/$TicketID)",
110 );
111 - }
112 - return ($Tn, $TicketID);
113 - }
114 + }
115 + return ($Tn, $TicketID);
116 }
117 return;
118 }
119 --- Kernel/System/Ticket/Article.pm.orig 2003-06-19 00:40:35.000000000 +0200
120 +++ Kernel/System/Ticket/Article.pm 2004-01-09 15:21:15.000000000 +0100
121 @@ -621,5 +621,35 @@
122 return %Data;
123 }
124 # --
125 +sub ArticleMsgIdLookup {
126 + my $Self = shift;
127 + my %Param = @_;
128 + my @Index = ();
129 + # --
130 + # check needed stuff
131 + # --
132 + if (!$Param{MessageID}) {
133 + $Self->{LogObject}->Log(Priority => 'error', Message => "Need MessageID!");
134 + return;
135 + }
136 + # --
137 + # sql query
138 + # --
139 + my $SQL = "SELECT id" .
140 + " FROM " .
141 + " article " .
142 + " WHERE " .
143 + " a_message_id = '$Param{MessageID}' " .
144 + " ORDER BY incoming_time";
145 + $Self->{DBObject}->Prepare(SQL => $SQL);
146 + while (my @Row = $Self->{DBObject}->FetchrowArray()) {
147 + push (@Index, $Row[0]);
148 + }
149 + # --
150 + # return data
151 + # --
152 + return @Index;
153 +}
154 +# --
155
156 1;