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
|
require 'rinku'
require 'erb'
GMANE_FIND = 'http://news.gmane.org/find-root.php?message_id='
MARC_FIND = 'https://marc.info/?i='
helpers do
def list_check
unless [$config['active_lists'], $config['frozen_lists']].flatten.include?(params[:list])
status 404
body "List not found"
return false
end
true
end
def monthint_to_link(monthint)
date = DateTime.parse("%s-%s-01" % [monthint[0..3], monthint[4..5]])
"<a href=\"threads/%s/\">%s</a>" % [date.strftime('%Y-%m'), date.strftime('%Y %B')]
end
def date_format(date)
DateTime.iso8601(date).rfc2822
end
def to_monthint(year, month)
("%i%02i" % [year.to_i, month.to_i]).to_i
end
def to_month(year, month)
date = DateTime.parse("%s-%s-01" % [year, month])
date.strftime('%B %Y')
end
def h(text)
Rack::Utils.escape_html(text)
end
def u(text)
ERB::Util::url_encode(text)
end
def strip_email_domain(str)
str.split(/,\s*/).map do |email|
email.gsub(/@(.*?)(>|$)/) do |s|
if $1 == 'gentoo.org'
"@g.o#{$2}"
elsif $1 == 'lists.gentoo.org'
"@l.g.o#{$2}"
else
"@#{'×' * $1.length}#{$2}"
end
end
end.join(', ')
end
def strip_email(str)
str.split(/,\s*/).map do |email|
email.gsub(/([a-zA-Z0-9._%+-]+)@([a-zA-Z0-9.-]+)\.([a-zA-Z]{2,10})/) do |s|
if $2 == 'gentoo' and $3 == 'org'
"#{$1}@g.o"
elsif $2 == 'lists.gentoo' and $3 == 'org'
"#{$1}@l.g.o"
else
"#{$1}@#{'×' * $2.length}.#{$3}"
end
end
end.join(', ')
end
def linkize(str)
Rinku.auto_link(str, :urls, 'rel="nofollow"')
end
def msgid_to_gmane(msgid)
GMANE_FIND + ERB::Util::url_encode(msgid)
end
def msgid_to_marc(msgid)
# We have to transform the msg-id first
# CAK86ViRgefgrb0qUyjQdYa+6C5BTiNvn8UKZwQsMvcJmY-L0mg@mail.gmail.com
# CAK86ViRgefgrb0qUyjQdYa+6C5BTiNvn8UKZwQsMvcJmY-L0mg () mail ! gmail ! com
# http://marc.info/?i=CAK86ViRgefgrb0qUyjQdYa+6C5BTiNvn8UKZwQsMvcJmY-L0mg%20()%20mail%20!%20gmail%20!%20com
# pan.2009.08.28.00.00.38@cox.net
# http://marc.info/?i=pan.2009.08.28.00.00.38%20()%20cox%20!%20net
local, host = msgid.split('@', 2)
new_msgid = local + ' () ' + host.gsub('.',' ! ')
MARC_FIND + ERB::Util::url_encode(new_msgid)
end
end
|