exjournal 0.1.0 → 0.1.1

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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
data/lib/exjournal.rb CHANGED
@@ -2,8 +2,18 @@ require 'action_mailer'
2
2
  require 'tmail'
3
3
 
4
4
  module Exjournal
5
+ class << self
6
+ def logger=(l)
7
+ @logger=l
8
+ end
9
+
10
+ def logger
11
+ @logger ||= Logger.new($stderr)
12
+ end
13
+ end
14
+
5
15
  module_function
6
-
16
+
7
17
  # extract the first message/rfc822 attachment from the RFC822 encoded content, and return it as a TMail::Mail
8
18
  # if +headers_only+ is true then message content will be discarded, and only headers processed
9
19
  def extract_journalled_mail(mail, strip_content=true)
@@ -45,9 +55,17 @@ module Exjournal
45
55
  {:name=>address.name, :address=>address.address}
46
56
  end
47
57
 
48
- # parse one or more addresses to hash
58
+ # parse one or more addresses to hash. failures result in a warning logged
49
59
  def parse_addresses(addresses)
50
- [*(addresses||[])].map{|a| parse_address(a)}
60
+ [*(addresses||[])].map do |a|
61
+ begin
62
+ parse_address(a)
63
+ rescue Exception=>e
64
+ logger.warn("failure parsing: #{a}")
65
+ logger.warn(e)
66
+ nil
67
+ end
68
+ end.compact
51
69
  end
52
70
 
53
71
  # turn a TMail::Mail into a has suitable for JSON representation
@@ -85,6 +85,13 @@ Subject: i can't tell you
85
85
  h.should == [{:name=>"foo mcfoo", :address=>"foo@bar.com"},
86
86
  {:name=>"baz mcbaz", :address=>"baz@boo.com"}]
87
87
  end
88
+
89
+ it "should skip unparseable addresses and log a warning" do
90
+ mock(Exjournal.logger).warn(anything).times(2)
91
+ h = Exjournal.parse_addresses(['"foo mcfoo" <foo@bar.com>',
92
+ '"baz mcbaz" <<baz@boo.com>'])
93
+ h.should == [{:name=>"foo mcfoo", :address=>"foo@bar.com"}]
94
+ end
88
95
  end
89
96
 
90
97
  describe "mail_to_hash" do
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: exjournal
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Trampoline Systems Ltd