/usr/lib/ruby/1.8/gurgitate/header.rb is in gurgitate-mail 1.10.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | module Gurgitate
class IllegalHeader < RuntimeError ; end
# A little class for a single header
class Header
# The name of the header
attr_accessor :name
# The contents of the header
attr_accessor :contents
alias_method :value, :contents
# A recent rash of viruses has forced me to canonicalize
# the capitalization of headers. Sigh.
def capitalize_words(s)
return s.split(/-/).map { |w| w.capitalize }.join("-")
rescue
return s
end
private :capitalize_words
# Creates a Header object.
# header::
# The text of the email-message header
def initialize(*header)
name,contents=nil,nil
if header.length == 1 then
# RFC822 says that a header consists of some (printable,
# non-whitespace) crap, followed by a colon, followed by
# some more (printable, but can include whitespaces)
# crap.
if(header[0] =~ /^[\x21-\x39\x3b-\x7e]+:/) then
(name,contents)=header[0].split(/:\s+/,2)
if(name =~ /:$/ and contents == nil) then
# It looks like someone is using Becky!
name=header[0].gsub(/:$/,"")
contents = ""
end
raise IllegalHeader, "Empty name" \
if (name == "" or name == nil)
contents="" if contents == nil
@@lastname=name
else
raise IllegalHeader, "Bad header syntax: no colon in #{header}"
end
elsif header.length == 2 then
name,contents = *header
end
@name=capitalize_words(name)
@contents=contents
end
# Extended header
def << (text)
@contents += "\n" + text
end
# Matches a header's contents.
# regex::
# The regular expression to match against the header's contents
def matches (regex)
if String === regex
regex = Regexp.new(Regexp.escape(regex))
end
@contents =~ regex
end
alias :=~ :matches
# Returns the header, ready to put into an email message
def to_s
@name+": "+@contents
end
end
end
|