gurgitate-mail 1.10.3 → 1.10.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,113 +0,0 @@
1
- #!/opt/bin/ruby -w
2
-
3
- #------------------------------------------------------------------------
4
- # Handles a complete mail message
5
- #------------------------------------------------------------------------
6
-
7
- require 'gurgitate/mail_headers'
8
-
9
- module Gurgitate
10
-
11
- # A complete mail message.
12
- class Message
13
-
14
- # The headers of the message
15
- attr_reader :headers
16
- # The body of the message
17
- attr_accessor :body
18
-
19
- # Creates a new message from the options hash, and the body of the
20
- # message in a string.
21
- #
22
- # This can actually be invoked in several ways:
23
- #
24
- # Gurgitate::Mailmessage.create "This is the message body",
25
- # :from => "from_address@example.com",
26
- # :to => "to_address@example.com",
27
- # :subject => "This is the message subject"
28
- #
29
- # This results in an email message that, when rendered via to_s, will
30
- # look like this:
31
- #
32
- # From: from_address@example.com
33
- # To: to_address@example.com
34
- # Subject: This is the message subject
35
- #
36
- # This is the message body
37
- #
38
- # If you prefer to do things entirely by options hashes, as some do,
39
- # you can substitute a :body key for the first argument:
40
- #
41
- # Gurgitate::Mailmessage.create(
42
- # :body => "This is the message body",
43
- # :from => "from_address@example.com",
44
- # :to => "to_address@example.com",
45
- # :subject => "This is the message subject"
46
- # )
47
- #
48
- # There are two other special options you can use: :sender and
49
- # :recipient. These are used to specify the sender and recipient of
50
- # email messages, when the message is sent via SMTP.
51
- #
52
- def self.create(*args)
53
- options = body = nil
54
-
55
- if String === args[0]
56
- options = args[1]
57
- body = args[0]
58
- elsif Hash === args[0]
59
- options = args[0]
60
- else
61
- options = {}
62
- end
63
-
64
- message = self.new
65
-
66
- message.instance_eval do
67
- if body
68
- @body=body
69
- end
70
-
71
- @headers = Headers.new(options)
72
- end
73
-
74
- message
75
- end
76
-
77
- # Creates a new Gurgitate message from a pre-existing message.
78
- # This is what is used when gurgitate-mail is used as a mail filter.
79
- #
80
- # ARGUMENTS::
81
- # +text+ :: An RFC822-formatted message.
82
- # +recipient+ :: The recipient of the email message, from the MTA
83
- # +sender+ :: The sender of the email message, also from the MTA
84
- #
85
- # All of its arguments can be nil: if called with no arguments,
86
- # it simply returns an empty email message, which can be populated
87
- # after the fact.
88
- def initialize(text=nil)
89
- if text
90
- (@headertext,@body)=text.split(/\n\n/,2)
91
- @headers=Headers.new(@headertext);
92
- else
93
- @headers = Headers.new
94
- @body = ""
95
- end
96
- end
97
-
98
- # Returns the header +name+, which is, note, a HeaderBag of all
99
- # headers by that name, not just a single header.
100
- #
101
- # If you want the text of the header, then you have to coerce it to a
102
- # string:
103
- #
104
- # header("name").to_s
105
- #
106
- def header(name)
107
- @headers[name].each { |h| h.contents }.join(", ")
108
- end
109
-
110
- # Returns the formatted mail message
111
- def to_s; @headers.to_s + "\n\n" + ( @body || ""); end
112
- end
113
- end