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]]) "%s" % [date.strftime('%Y-%m'), date.strftime('%Y %B')] end def date_format(date) DateTime.iso8601(date).strftime('%a, %d %b %Y %T') 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