ruby-gmail 0.0.7 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/History.txt CHANGED
@@ -1,3 +1,9 @@
1
+ === 0.0.8 / 2009/12-23
2
+
3
+ * 1 bugfix
4
+
5
+ * Fixed attaching a file to an empty message
6
+
1
7
  === 0.0.7 / 2009-12-23
2
8
 
3
9
  * 1 bugfix
data/lib/gmail.rb CHANGED
@@ -3,7 +3,7 @@ require 'net/smtp'
3
3
  require 'smtp_tls'
4
4
 
5
5
  class Gmail
6
- VERSION = '0.0.7'
6
+ VERSION = '0.0.8'
7
7
 
8
8
  class NoLabel < RuntimeError; end
9
9
 
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(arg=nil)
14
- if arg.is_a?(String)
15
- @raw = arg.gsub(/\r/,'').gsub(/\n/, "\r\n") # normalizes end-of-line characters
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
- attr_writer :encoding
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 content=(raw)
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
- headers['from'].match(/([A-Z0-9._%+-]+@[A-Z0-9._%+-]+\.[A-Z]+)/i)[1]
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
- H�ݷ�>� �т#Y���՘Qw�~5ItW*�H���֮_���n "Ѩ:�����V=�Ma�ҹU� ���'���@�R��v��ҡ����H}�����B����\�WÙ|�o�.;�m�C *���SH�73oMH�[�O�`+��e|{�$�+�e�0o�*S�-%�jD�H��'��Ѿʖv���Џ�����ɝ%g�8F��
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
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-gmail
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Parker
metadata.gz.sig CHANGED
Binary file