mailfactory 1.3.1 → 1.3.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/mailfactory.rb +32 -10
  2. data/tests/test_mailfactory.rb +24 -1
  3. metadata +45 -38
data/lib/mailfactory.rb CHANGED
@@ -26,7 +26,6 @@
26
26
  # smtp.send_message(mail.to_s(), fromaddress, toaddress)
27
27
  # }
28
28
 
29
- require 'base64'
30
29
  require 'pathname'
31
30
 
32
31
  # try to bring in the mime/types module, make a dummy module if it can't be found
@@ -48,6 +47,8 @@ end
48
47
 
49
48
  # An easy class for creating a mail message
50
49
  class MailFactory
50
+
51
+ VERSION = '1.3.5'
51
52
 
52
53
  def initialize()
53
54
  @headers = Array.new()
@@ -381,7 +382,7 @@ protected
381
382
  # returns a base64 encoded version of the contents of str
382
383
  def file_encode(str)
383
384
  collection = Array.new()
384
- enc = Base64.encode64(str)
385
+ enc = [str].pack('m')
385
386
  # while(enc.length > 60)
386
387
  # collection << enc.slice!(0..59)
387
388
  # end
@@ -393,29 +394,50 @@ protected
393
394
 
394
395
  # Convert the given text into quoted printable format, with an instruction
395
396
  # that the text be eventually interpreted in the given charset.
397
+
396
398
  def quoted_printable_with_instruction(text, charset)
397
- text = [text].pack("M").gsub(/\n/, "\r\n").chomp.gsub(/ /, "_")
399
+ text = quoted_printable_encode_header(text)
398
400
  "=?#{charset}?Q?#{text}?="
399
401
  end
400
402
 
403
+ # rfc2045 compatible. use rfc2047 for headers (such as the Subject line) instead
404
+ def quoted_printable_encode(text)
405
+ [text].pack('M').gsub(/\n/, "\r\n").chomp.gsub(/=$/, '')
406
+ end
401
407
 
402
408
  # Convert the given character to quoted printable format
403
- def quoted_printable_encode(text)
404
- [text].pack("M").gsub(/\n/, "\r\n").chomp
409
+ # see http://tools.ietf.org/html/rfc2047
410
+
411
+ def quoted_printable_encode_header(text)
412
+ text.scan(/./u).map do |char|
413
+ (char[0] < 128 and char[0] != 61) ? # 61 is ascii '='
414
+ char :
415
+ '=%X' % char[0]
416
+ end.join('').
417
+ chomp.
418
+ gsub(/=$/,'').
419
+ gsub('?', '=3F').
420
+ gsub('_', '=5F').
421
+ gsub(/ /, '_')
405
422
  end
406
423
 
407
424
 
408
425
  # A quick-and-dirty regexp for determining whether a string contains any
409
426
  # characters that need escaping.
410
- if !defined?(CHARS_NEEDING_QUOTING)
411
- CHARS_NEEDING_QUOTING = /[\000-\011\013\014\016-\037\177-\377]/
412
- end
427
+ #--
428
+ # Jun18-08: deprecated, since all multipart blocks are marked quoted-printable, quoting is required
429
+
430
+ # if !defined?(CHARS_NEEDING_QUOTING)
431
+ # CHARS_NEEDING_QUOTING = /[\000-\011\013\014\016-\037\177-\377]/
432
+ # end
413
433
 
414
434
 
415
435
  # Quote the given text if it contains any "illegal" characters
416
436
  def quote_if_necessary(text, charset, instruction = false)
437
+ return unless text
417
438
  text = text.dup.force_encoding(Encoding::ASCII_8BIT) if text.respond_to?(:force_encoding)
418
- (text =~ CHARS_NEEDING_QUOTING) ? (instruction ? quoted_printable_with_instruction(text, charset) : quoted_printable_encode(text)) : text
439
+ #(text =~ CHARS_NEEDING_QUOTING) ? (instruction ? quoted_printable_with_instruction(text, charset) : quoted_printable_encode(text)) : text
440
+ instruction ? quoted_printable_with_instruction(text, charset) : quoted_printable_encode(text)
419
441
  end
420
442
 
421
443
 
@@ -436,4 +458,4 @@ protected
436
458
  end
437
459
  end
438
460
 
439
- end
461
+ end
@@ -185,8 +185,31 @@ class TC_MailFactory < Test::Unit::TestCase
185
185
  end
186
186
  end
187
187
 
188
- end
188
+ def test_quoted_printable_with_instruction
189
+ @mail.to="test@test.com"
190
+ @mail.from="test@othertest.com"
191
+ @mail.subject="My email subject has a ? in it and also an = and a _ too... Also some non-quoted junk ()!@\#\{\$\%\}"
192
+ @mail.text = "This is a test message with\na few\n\nlines."
193
+ assert_equal("=?utf-8?Q?My_email_subject_has_a_=3F_in_it_and_also_an_=3D_and_a_=5F_too..._Also_some_non-quoted_junk_()!@\#\{\$\%\}?=", @mail.subject.to_s)
194
+ end
195
+
196
+ def test_utf8_quoted_printable_with_instruction
197
+ @mail.to="test@test.com"
198
+ @mail.from="test@othertest.com"
199
+ @mail.subject="My email subject has a à which is utf8."
200
+ @mail.text = "This is a test message with\na few\n\nlines."
201
+ assert_equal("=?utf-8?Q?My_email_subject_has_a_=C3_which_is_utf8.?=", @mail.subject.to_s)
202
+ end
203
+
204
+ def test_quoted_printable_html
205
+ @mail.to="test@test.com"
206
+ @mail.from="test@othertest.com"
207
+ @mail.subject="some html"
208
+ @mail.html="<a href=\"http://google.com\">click here</a>"
209
+ assert_match('<a href=3D"http://google.com">click here</a>', @mail.to_s)
210
+ end
189
211
 
212
+ end
190
213
 
191
214
  $options = get_options()
192
215
  Test::Unit::UI::Console::TestRunner.run(TC_MailFactory)
metadata CHANGED
@@ -1,54 +1,61 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.4
3
- specification_version: 1
4
2
  name: mailfactory
5
3
  version: !ruby/object:Gem::Version
6
- version: 1.3.1
7
- date: 2008-04-28 00:00:00 +01:00
8
- summary: MailFactory is a pure-ruby MIME mail generator
9
- require_paths:
10
- - lib
11
- email: david@grayskies.net
12
- homepage: http://mailfactory.rubyforge.org
13
- rubyforge_project: mailfactory
14
- description: MailFactory is s simple module for producing RFC compliant mail that can include multiple attachments, multiple body parts, and arbitrary headers
15
- autorequire: mailfactory
16
- default_executable:
17
- bindir: bin
18
- has_rdoc: true
19
- required_ruby_version: !ruby/object:Gem::Version::Requirement
20
- requirements:
21
- - - ">"
22
- - !ruby/object:Gem::Version
23
- version: 0.0.0
24
- version:
4
+ version: 1.3.5
25
5
  platform: ruby
26
- signing_key:
27
- cert_chain:
28
- post_install_message:
29
6
  authors:
30
7
  - David Powers
31
- files:
32
- - ./lib/mailfactory.rb
33
- test_files:
34
- - ./tests/test_mailfactory.rb
35
- rdoc_options: []
36
-
37
- extra_rdoc_files: []
38
-
39
- executables: []
40
-
41
- extensions: []
42
-
43
- requirements: []
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
44
11
 
12
+ date: 2008-06-18 00:00:00 -07:00
13
+ default_executable:
45
14
  dependencies:
46
15
  - !ruby/object:Gem::Dependency
47
16
  name: mime-types
48
17
  version_requirement:
49
- version_requirements: !ruby/object:Gem::Version::Requirement
18
+ version_requirements: !ruby/object:Gem::Requirement
50
19
  requirements:
51
20
  - - ">="
52
21
  - !ruby/object:Gem::Version
53
22
  version: 1.13.1
54
23
  version:
24
+ description: MailFactory is s simple module for producing RFC compliant mail that can include multiple attachments, multiple body parts, and arbitrary headers
25
+ email: david@grayskies.net
26
+ executables: []
27
+
28
+ extensions: []
29
+
30
+ extra_rdoc_files: []
31
+
32
+ files:
33
+ - ./lib/mailfactory.rb
34
+ has_rdoc: true
35
+ homepage: http://mailfactory.rubyforge.org
36
+ post_install_message:
37
+ rdoc_options: []
38
+
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: "0"
46
+ version:
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: "0"
52
+ version:
53
+ requirements: []
54
+
55
+ rubyforge_project: mailfactory
56
+ rubygems_version: 1.1.1
57
+ signing_key:
58
+ specification_version: 2
59
+ summary: MailFactory is a pure-ruby MIME mail generator
60
+ test_files:
61
+ - ./tests/test_mailfactory.rb