-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathMessageBuilderSettings.cs
311 lines (275 loc) · 13 KB
/
MessageBuilderSettings.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
// Smuxi - Smart MUltipleXed Irc
//
// Copyright (c) 2011, 2014 Mirco Bauer <meebey@meebey.net>
//
// Full GPL License: <http://www.gnu.org/licenses/gpl.txt>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
using System;
using System.Text.RegularExpressions;
using System.Collections.Generic;
namespace Smuxi.Engine
{
public class MessageBuilderSettings
{
public class SmartLink
{
public Regex MessagePartPattern { get; set; }
public Type MessagePartType { get; set; }
// what is linked to
public string LinkFormat { get; set; }
// what is displayed
public string TextFormat { get; set; }
public SmartLink(Regex pattern)
{
if (pattern == null) {
throw new ArgumentNullException("pattern");
}
MessagePartPattern = pattern;
MessagePartType = typeof(UrlMessagePartModel);
}
}
static List<SmartLink> BuiltinSmartLinks { get; set; }
public List<SmartLink> SmartLinks { get; private set; }
static MessageBuilderSettings()
{
BuiltinSmartLinks = new List<SmartLink>();
InitBuiltinSmartLinks();
}
public MessageBuilderSettings()
{
// No need to lock BuiltinSmartLinks as List<T> is thread-safe for
// multiple readers as long as there is no writer at the same time.
// BuiltinSmartLinks is only written once before the first instance
// of MessageBuilderSettings is created via the static initializer.
SmartLinks = new List<SmartLink>(BuiltinSmartLinks);
}
static void InitBuiltinSmartLinks()
{
string path_last_chars = @"a-zA-Z0-9#/%&@=\-_+;:~";
string path_chars = path_last_chars + @")(?!.,";
string domainchars = @"[a-z0-9\-]+";
string subdomain = domainchars + @"\.";
string common_tld = @"de|es|im|us|com|net|org|info|biz|gov|name|edu|onion|museum";
string any_tld = @"[a-z]+";
string domain = @"(?:(?:" + subdomain + ")+(?:" + any_tld + ")|localhost)";
string short_number = "[1-9][0-9]{,4}";
string port = ":" + short_number;
string user = "[a-z0-9._%+-]+@";
string domain_port = domain + "(?:" + port + ")?";
string user_domain = user + domain;
string user_domain_port = "(?:" + user + ")?" + domain_port;
string path = @"/(?:["+ path_chars +"]*["+ path_last_chars +"]+)?";
string protocol = @"[a-z][a-z0-9\-+]*://";
string protocol_user_domain_port_path = protocol + user_domain_port + "(?:" + path + ")?";
// facebook attachment
var regex = new Regex(
@"(<[1-9][0-9]* attachments?>) (http://www\.facebook\.com/messages/\?action=read&tid=[0-9a-f]+)",
RegexOptions.Compiled
);
BuiltinSmartLinks.Add(new SmartLink(regex) {
LinkFormat = "{2}",
TextFormat = "{1}",
});
// protocol://user@domain:port/path
regex = new Regex(
protocol_user_domain_port_path,
RegexOptions.IgnoreCase | RegexOptions.Compiled
);
BuiltinSmartLinks.Add(new SmartLink(regex));
// email
regex = new Regex(
@"(?:mailto:)?(" + user_domain + ")",
RegexOptions.IgnoreCase | RegexOptions.Compiled
);
BuiltinSmartLinks.Add(new SmartLink(regex) {
LinkFormat = "mailto:{1}"
});
// addresses without protocol (heuristical)
// include well known TLDs to prevent autogen.sh, configure.ac or
// Gst.Buffer.Unref() from matching
string heuristic_domain = @"(?:(?:" + subdomain + ")+(?:" + common_tld + ")|localhost)";
string heuristic_address = heuristic_domain + "(?:" + path + ")?";
regex = new Regex(heuristic_address, RegexOptions.Compiled);
BuiltinSmartLinks.Add(new SmartLink(regex) {
LinkFormat = "http://{0}"
});
// Smuxi bugtracker
regex = new Regex(@"smuxi#([0-9]+)",
RegexOptions.IgnoreCase | RegexOptions.Compiled);
BuiltinSmartLinks.Add(new SmartLink(regex) {
LinkFormat = "http://www.smuxi.org/issues/show/{1}"
});
// RFCs
regex = new Regex(@"RFC[ -]?([0-9]+) (?:s\.|ss\.|sec\.|sect\.|section) ?([1-9][0-9.]*)",
RegexOptions.IgnoreCase | RegexOptions.Compiled);
BuiltinSmartLinks.Add(new SmartLink(regex) {
LinkFormat = "http://tools.ietf.org/html/rfc{1}#section-{2}"
});
regex = new Regex(@"RFC[ -]?([0-9]+) (?:p\.|pp\.|page) ?(" + short_number + ")",
RegexOptions.IgnoreCase | RegexOptions.Compiled);
BuiltinSmartLinks.Add(new SmartLink(regex) {
LinkFormat = "http://tools.ietf.org/html/rfc{1}#page-{2}"
});
regex = new Regex(@"RFC[ -]?([0-9]+)",
RegexOptions.IgnoreCase | RegexOptions.Compiled);
BuiltinSmartLinks.Add(new SmartLink(regex) {
LinkFormat = "http://www.ietf.org/rfc/rfc{1}.txt"
});
// bugtracker prefixes are taken from:
// http://en.opensuse.org/openSUSE:Packaging_Patches_guidelines#Current_set_of_abbreviations
// boost bugtracker
regex = new Regex(@"boost#([0-9]+)",
RegexOptions.IgnoreCase | RegexOptions.Compiled);
BuiltinSmartLinks.Add(new SmartLink(regex) {
LinkFormat = "https://svn.boost.org/trac/boost/ticket/{1}"
});
// Claws bugtracker
regex = new Regex(@"claws#([0-9]+)",
RegexOptions.IgnoreCase | RegexOptions.Compiled);
BuiltinSmartLinks.Add(new SmartLink(regex) {
LinkFormat = "http://www.thewildbeast.co.uk/claws-mail/bugzilla/show_bug.cgi?id={1}"
});
// CVE list
regex = new Regex(@"CVE-[0-9]{4}-[0-9]{4,}",
RegexOptions.IgnoreCase | RegexOptions.Compiled);
BuiltinSmartLinks.Add(new SmartLink(regex) {
LinkFormat = "http://cve.mitre.org/cgi-bin/cvename.cgi?name={0}"
});
// CPAN bugtracker
regex = new Regex(@"RT#([0-9]+)",
RegexOptions.IgnoreCase | RegexOptions.Compiled);
BuiltinSmartLinks.Add(new SmartLink(regex) {
LinkFormat = "http://rt.cpan.org/Public/Bug/Display.html?id={1}"
});
// Debian bugtracker
regex = new Regex(@"deb#([0-9]+)",
RegexOptions.IgnoreCase | RegexOptions.Compiled);
BuiltinSmartLinks.Add(new SmartLink(regex) {
LinkFormat = "http://bugs.debian.org/{1}"
});
// Debian Security Advisories (DSA)
regex = new Regex(@"DSA-([0-9]{4})(-[0-9]{1,2})?",
RegexOptions.IgnoreCase | RegexOptions.Compiled);
BuiltinSmartLinks.Add(new SmartLink(regex) {
LinkFormat = "http://www.debian.org/security/dsa-{1}"
});
// openSUSE feature tracker
regex = new Regex(@"fate#([0-9]+)",
RegexOptions.IgnoreCase | RegexOptions.Compiled);
BuiltinSmartLinks.Add(new SmartLink(regex) {
LinkFormat = "http://features.opensuse.org/{1}"
});
// freedesktop bugtracker
regex = new Regex(@"fdo#([0-9]+)",
RegexOptions.IgnoreCase | RegexOptions.Compiled);
BuiltinSmartLinks.Add(new SmartLink(regex) {
LinkFormat = "http://bugs.freedesktop.org/{1}"
});
// GNU bugtracker
regex = new Regex(@"gnu#([0-9]+)",
RegexOptions.IgnoreCase | RegexOptions.Compiled);
BuiltinSmartLinks.Add(new SmartLink(regex) {
LinkFormat = "http://debbugs.gnu.org/{1}"
});
// GCC bugtracker
regex = new Regex(@"gcc#([0-9]+)",
RegexOptions.IgnoreCase | RegexOptions.Compiled);
BuiltinSmartLinks.Add(new SmartLink(regex) {
LinkFormat = "http://gcc.gnu.org/bugzilla/show_bug.cgi?id={1}"
});
// GNOME bugtracker
regex = new Regex(@"bgo#([0-9]+)",
RegexOptions.IgnoreCase | RegexOptions.Compiled);
BuiltinSmartLinks.Add(new SmartLink(regex) {
LinkFormat = "http://bugzilla.gnome.org/{1}"
});
// KDE bugtracker
regex = new Regex(@"kde#([0-9]+)",
RegexOptions.IgnoreCase | RegexOptions.Compiled);
BuiltinSmartLinks.Add(new SmartLink(regex) {
LinkFormat = "http://bugs.kde.org/{1}"
});
// kernel bugtracker
regex = new Regex(@"bko#([0-9]+)",
RegexOptions.IgnoreCase | RegexOptions.Compiled);
BuiltinSmartLinks.Add(new SmartLink(regex) {
LinkFormat = "http://bugzilla.kernel.org/show_bug.cgi?id={1}"
});
// launchpad bugtracker
regex = new Regex(@"LP#([0-9]+)",
RegexOptions.IgnoreCase | RegexOptions.Compiled);
BuiltinSmartLinks.Add(new SmartLink(regex) {
LinkFormat = "http://launchpad.net/bugs/{1}"
});
// Mozilla bugtracker
regex = new Regex(@"bmo#([0-9]+)",
RegexOptions.IgnoreCase | RegexOptions.Compiled);
BuiltinSmartLinks.Add(new SmartLink(regex) {
LinkFormat = "http://bugzilla.mozilla.org/{1}"
});
// Novell bugtracker
regex = new Regex(@"bnc#([0-9]+)",
RegexOptions.IgnoreCase | RegexOptions.Compiled);
BuiltinSmartLinks.Add(new SmartLink(regex) {
LinkFormat = "http://bugzilla.novell.com/{1}"
});
// Redhat bugtracker
regex = new Regex(@"rh#([0-9]+)",
RegexOptions.IgnoreCase | RegexOptions.Compiled);
BuiltinSmartLinks.Add(new SmartLink(regex) {
LinkFormat = "http://bugzilla.redhat.com/{1}"
});
// Samba bugtracker
regex = new Regex(@"bso#([0-9]+)",
RegexOptions.IgnoreCase | RegexOptions.Compiled);
BuiltinSmartLinks.Add(new SmartLink(regex) {
LinkFormat = "http://bugzilla.samba.org/show_bug.cgi?id={1}"
});
// sourceforge bugtracker
regex = new Regex(@"sf#([0-9]+)",
RegexOptions.IgnoreCase | RegexOptions.Compiled);
BuiltinSmartLinks.Add(new SmartLink(regex) {
LinkFormat = "http://sf.net/support/tracker.php?aid={1}"
});
// Xfce bugtracker
regex = new Regex(@"bxo#([0-9]+)",
RegexOptions.IgnoreCase | RegexOptions.Compiled);
BuiltinSmartLinks.Add(new SmartLink(regex) {
LinkFormat = "http://bugzilla.xfce.org/show_bug.cgi?id={1}"
});
// Xamarin bugtracker
regex = new Regex(@"bxc#([0-9]+)",
RegexOptions.IgnoreCase | RegexOptions.Compiled);
BuiltinSmartLinks.Add(new SmartLink(regex) {
LinkFormat = "http://bugzilla.xamarin.com/show_bug.cgi?id={1}"
});
// TODO: msgid -> http://mid.gmane.org/{1}
// TODO: ISSN/ISBN
// TODO: Path: / or X:\
// TODO: GPS -> Google Maps
// TODO: IP -> Browser / Whois
// TODO: Domain -> Browser / Whois
// TODO: ISO -> http://www.iso.org/iso/search.htm?qt={1}&published=on
// TODO: ANSI
// TODO: ECMA
// TODO: maybe more on http://ikiwiki.info/shortcuts/
// TODO: JID
}
public void ApplyConfig(UserConfig userConfig)
{
}
}
}