Class: Gurgitate::MailHeaders

Inherits:
Headers
  • Object
show all
Defined in:
lib/gurgitate/mail_headers.rb

Overview

A slightly bigger class for all of a message’s headers

Instance Method Summary collapse

Methods inherited from Headers

#[], #[]=, #match, #matches, #to_s

Constructor Details

#initialize(headertext = nil, sender = nil, recipient = nil) ⇒ MailHeaders

Creates a MailHeaders object.

headertext

The text of the message headers.



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
# File 'lib/gurgitate/mail_headers.rb', line 111

def initialize(headertext=nil, sender=nil, recipient=nil)
    @from    = sender
    @to      = recipient
    @headers = Hash.new(nil)

    if Hash === headertext
        @headers_changed = true
        headertext.each_key do |key|

            headername = key.to_s.gsub("_","-")

            header=Header.new(headername, headertext[key])
            @headers[header.name] ||= HeaderBag.new
            @headers[header.name].push(header)
        end
    else
        if headertext
            @unix_from, @headertext = figure_out_from_line headertext
            parse_headers if @headertext

            if sender # then don't believe the mbox separator
                @from = sender
                @unix_from="From "+self.from+" "+Time.new.to_s
            else
                guess_sender
            end
        end
    end
end

Instance Method Details

#fromObject

Who the message is from (the envelope from)



149
150
151
# File 'lib/gurgitate/mail_headers.rb', line 149

def from
    return @from || ""
end

#from=(newfrom) ⇒ Object

Change the envelope from line to whatever you want. This might not be particularly neighborly, but oh well.

newfrom

An email address



156
157
158
159
# File 'lib/gurgitate/mail_headers.rb', line 156

def from=(newfrom) 
    @from=newfrom
    @unix_from="From "+self.from+" "+Time.new.to_s
end

#toObject

Who the message is to (the envelope to)

Yet another bucket of rants. Unix mail sucks.



144
145
146
# File 'lib/gurgitate/mail_headers.rb', line 144

def to
    return @to || @headers["X-Original-To"] || nil
end

#to_mboxObject

Returns the headers properly formatted for an mbox-format email message.



163
164
165
# File 'lib/gurgitate/mail_headers.rb', line 163

def to_mbox
    return @unix_from+"\n"+to_s
end