ruby-gmail 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +6 -0
- data/lib/gmail.rb +1 -1
- data/lib/mime/entity.rb +19 -12
- data/lib/mime/message.rb +8 -3
- data.tar.gz.sig +2 -1
- metadata +1 -1
- metadata.gz.sig +0 -0
data/History.txt
CHANGED
data/lib/gmail.rb
CHANGED
data/lib/mime/entity.rb
CHANGED
@@ -10,12 +10,14 @@ module MIME
|
|
10
10
|
header_name.gsub(/^(\w)/) {|m| m.capitalize}.gsub(/-(\w)/) {|n| '-' + n[1].chr.capitalize}
|
11
11
|
end
|
12
12
|
class Entity
|
13
|
-
def initialize(
|
14
|
-
if
|
15
|
-
@
|
13
|
+
def initialize(one=nil,two=nil)
|
14
|
+
if one.is_a?(Hash) || two.is_a?(Hash)
|
15
|
+
@headers = one.is_a?(Hash) ? one : two
|
16
|
+
set_content one if one.is_a?(String)
|
17
|
+
@encoding = 'quoted-printable' unless encoding
|
18
|
+
elsif one.is_a?(String)
|
19
|
+
@raw = one.gsub(/\r/,'').gsub(/\n/, "\r\n") # normalizes end-of-line characters
|
16
20
|
from_parsed(IETF::RFC2045.parse_rfc2045_from(@raw))
|
17
|
-
elsif arg.is_a?(Hash)
|
18
|
-
@headers = arg
|
19
21
|
end
|
20
22
|
end
|
21
23
|
|
@@ -72,12 +74,12 @@ module MIME
|
|
72
74
|
# Macro Methods #
|
73
75
|
|
74
76
|
def multipart?
|
75
|
-
!!(headers['content-type'] =~ /multipart\//)
|
77
|
+
!!(headers['content-type'] =~ /multipart\//) if headers['content-type']
|
76
78
|
end
|
77
79
|
def multipart_type
|
78
80
|
if headers['content-type'] =~ /multipart\/(\w+)/
|
79
81
|
$1
|
80
|
-
end
|
82
|
+
end if headers['content-type']
|
81
83
|
end
|
82
84
|
# Auto-generates a boundary if one doesn't yet exist.
|
83
85
|
def multipart_boundary
|
@@ -90,24 +92,28 @@ module MIME
|
|
90
92
|
end
|
91
93
|
end
|
92
94
|
def attachment?
|
93
|
-
headers['content-disposition'] =~ /^attachment(?=;|$)/ || headers['content-disposition'] =~ /^form-data;.* filename=[\"\']?[^\"\']+[\"\']?/
|
95
|
+
headers['content-disposition'] =~ /^attachment(?=;|$)/ || headers['content-disposition'] =~ /^form-data;.* filename=[\"\']?[^\"\']+[\"\']?/ if headers['content-disposition']
|
94
96
|
end
|
95
97
|
alias :file? :attachment?
|
96
98
|
def part_filename
|
97
99
|
# Content-Disposition: attachment; filename="summary.txt"
|
98
100
|
if headers['content-disposition'] =~ /; filename=[\"\']?([^\"\']+)/
|
99
101
|
$1
|
100
|
-
end
|
102
|
+
end if headers['content-disposition']
|
101
103
|
end
|
102
|
-
|
104
|
+
|
103
105
|
def encoding
|
104
106
|
@encoding ||= headers['content-transfer-encoding'] || nil
|
105
107
|
end
|
108
|
+
attr_writer :encoding
|
109
|
+
alias :set_encoding :encoding=
|
110
|
+
|
106
111
|
def find_part(options)
|
107
112
|
find_parts(options).first
|
108
113
|
end
|
109
114
|
def find_parts(options)
|
110
115
|
parts = []
|
116
|
+
return nil unless (options[:content_type] && headers['content-type']) || (options[:content_disposition] && headers['content-disposition'])
|
111
117
|
# Do I match your search?
|
112
118
|
iam = true
|
113
119
|
iam = false if options[:content_type] && headers['content-type'] !~ /^#{options[:content_type]}(?=;|$)/
|
@@ -167,7 +173,7 @@ module MIME
|
|
167
173
|
end
|
168
174
|
|
169
175
|
# You can set new content, and it will be saved in encoded form.
|
170
|
-
def
|
176
|
+
def set_content(raw)
|
171
177
|
@content = raw.is_a?(Array) ? raw :
|
172
178
|
case encoding.to_s.downcase
|
173
179
|
when 'quoted-printable'
|
@@ -178,10 +184,11 @@ module MIME
|
|
178
184
|
raw
|
179
185
|
end
|
180
186
|
end
|
187
|
+
alias :content= :set_content
|
181
188
|
|
182
189
|
private
|
183
190
|
def transfer_to(other)
|
184
|
-
other.instance_variable_set(:@content, @content.dup)
|
191
|
+
other.instance_variable_set(:@content, @content.dup) if @content
|
185
192
|
other.headers.clear
|
186
193
|
other.headers.merge!(Hash[*headers.dup.select {|k,v| k =~ /content/}.flatten])
|
187
194
|
end
|
data/lib/mime/message.rb
CHANGED
@@ -12,7 +12,7 @@ module MIME
|
|
12
12
|
|
13
13
|
def to(addressee=nil)
|
14
14
|
headers['to'] = addressee if addressee
|
15
|
-
headers['to'].match(/([A-Z0-9._%+-]+@[A-Z0-9._%+-]+\.[A-Z]+)/i)[1]
|
15
|
+
headers['to'].match(/([A-Z0-9._%+-]+@[A-Z0-9._%+-]+\.[A-Z]+)/i)[1] if headers['to'].respond_to?(:match)
|
16
16
|
end
|
17
17
|
|
18
18
|
def subject(subj=nil)
|
@@ -20,8 +20,9 @@ module MIME
|
|
20
20
|
headers['subject']
|
21
21
|
end
|
22
22
|
|
23
|
-
def from
|
24
|
-
|
23
|
+
def from(dummy=nil)
|
24
|
+
raise "Can't set FROM address in the message - will be set automatically when the message is sent." if dummy
|
25
|
+
headers['from'].match(/([A-Z0-9._%+-]+@[A-Z0-9._%+-]+\.[A-Z]+)/i)[1] if headers['from'].respond_to?(:match)
|
25
26
|
end
|
26
27
|
|
27
28
|
def attachments
|
@@ -47,6 +48,7 @@ module MIME
|
|
47
48
|
end
|
48
49
|
|
49
50
|
def attach_file(filename)
|
51
|
+
raise ArgumentError, "Currently the <filename> given must be a String (path to a file)." unless filename.is_a?(String)
|
50
52
|
short_filename = filename.match(/([^\\\/]+)$/)[1]
|
51
53
|
|
52
54
|
# Generate the attachment piece
|
@@ -62,12 +64,15 @@ module MIME
|
|
62
64
|
# If already enclosed, all we have to do is add the attachment part
|
63
65
|
(@content ||= []) << attachment
|
64
66
|
else
|
67
|
+
# If there is no content, add a little message about the attachment(s).
|
68
|
+
set_content 'See attachment(s)' if @content.nil?
|
65
69
|
# Generate the new top-level multipart, transferring what is here already into a child object
|
66
70
|
new_content = Entity.new
|
67
71
|
# Whatever it is, since it's not multipart/mixed, transfer it into a child object and add the attachment.
|
68
72
|
transfer_to(new_content)
|
69
73
|
headers.reject! {|k,v| k =~ /content/}
|
70
74
|
headers['content-type'] = 'multipart/mixed'
|
75
|
+
headers.delete 'content-transfer-encoding' # because now it's useless.
|
71
76
|
@content = [new_content, attachment]
|
72
77
|
end
|
73
78
|
|
data.tar.gz.sig
CHANGED
@@ -1 +1,2 @@
|
|
1
|
-
|
1
|
+
�j|,�r�%�B��ZC��B'�6,��r�g�V~�9ï�+�mcL���L��.�#�_�x.&�#LX��!�ȧi×T�_�e2������k�s��-[`�c���G���^J����y3EYY�<��^X q
|
2
|
+
�?D
|
metadata
CHANGED
metadata.gz.sig
CHANGED
Binary file
|