mail2frontmatter 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,61 @@
1
+
2
+ Delivered-To: stream@kunalashah.com
3
+ Received: by 10.216.42.73 with SMTP id i51csp1168497web;
4
+ Mon, 12 Jan 2015 16:14:52 -0800 (PST)
5
+ X-Received: by 10.170.120.195 with SMTP id m186mr27431216ykb.27.1421108091508;
6
+ Mon, 12 Jan 2015 16:14:51 -0800 (PST)
7
+ Return-Path: <me@kunalashah.com>
8
+ Received: from mail-yk0-x229.google.com (mail-yk0-x229.google.com. [2607:f8b0:4002:c07::229])
9
+ by mx.google.com with ESMTPS id t25si5238386yhg.25.2015.01.12.16.14.50
10
+ for <stream@kunalashah.com>
11
+ (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
12
+ Mon, 12 Jan 2015 16:14:51 -0800 (PST)
13
+ Received-SPF: none (google.com: me@kunalashah.com does not designate permitted sender hosts) client-ip=2607:f8b0:4002:c07::229;
14
+ Authentication-Results: mx.google.com;
15
+ spf=none (google.com: me@kunalashah.com does not designate permitted sender hosts) smtp.mail=me@kunalashah.com;
16
+ dkim=pass header.i=@kunalashah.com
17
+ Received: by mail-yk0-f169.google.com with SMTP id 79so21939ykr.0
18
+ for <stream@kunalashah.com>; Mon, 12 Jan 2015 16:14:50 -0800 (PST)
19
+ DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
20
+ d=kunalashah.com; s=google;
21
+ h=mime-version:date:message-id:subject:from:to:content-type;
22
+ bh=hya9e//LW4XQ2bkKvEYKS38O0pdjqIhxVUGoAex/w5M=;
23
+ b=fVomZxRYAjkkH3p498EkXyvZiO6Z5WPwEuFzlMyJGTOCFJMzANfJ4vkl8P/LFpzHz4
24
+ Ql2q1s/nbLRdBKANbHNh442okwVIy/shBjFT1uRt0LQ5n0CiIjz5SbE6BSdEnp6eSDtQ
25
+ oQE3yqJnkf/X4yC0If2HawkZ98hjfz2TKDths=
26
+ X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
27
+ d=1e100.net; s=20130820;
28
+ h=x-gm-message-state:mime-version:date:message-id:subject:from:to
29
+ :content-type;
30
+ bh=hya9e//LW4XQ2bkKvEYKS38O0pdjqIhxVUGoAex/w5M=;
31
+ b=iOD7ofc0a5kQhf/lZnJC9kXIXBPzlWH6eKog61pofebqNJfSLZHkw4jC2A9Y19VjuY
32
+ jpb4l247HJC3F1aYWCBeetUeoE/XOblN5A8/jygSXvpCIJTgTOH/Udgz4kxRjae01FOY
33
+ bPxGinme7Nln+MMSGVq/7KGqPYRopTj7zcO0aOsiegQgVqSshml6umHTSJS21QGWDgZS
34
+ XWUMukc4JlcZscLFKP9EEQjvCEPmEI32L0KR/kcvQLcJsz5QAFQfbPhm7tSzPXuuY/1/
35
+ Wot5+1NRK9XFAjXF9X6NUNixNAFzo6qsCM8FUoFgbCjo7+E85VY0Y5lixNLkn5h9rOeB
36
+ 677w==
37
+ X-Gm-Message-State: ALoCoQmw5gttL+2jOT4D8w/7c3QySWp8/TW1ZlM0yazuZFLm5Fmc3/nyHioSBE2ud1EuPPdlKCoo
38
+ MIME-Version: 1.0
39
+ X-Received: by 10.170.95.7 with SMTP id m7mr28078171yka.67.1421108090560; Mon,
40
+ 12 Jan 2015 16:14:50 -0800 (PST)
41
+ Received: by 10.170.205.16 with HTTP; Mon, 12 Jan 2015 16:14:50 -0800 (PST)
42
+ X-Originating-IP: [66.108.230.254]
43
+ Received: by 10.170.205.16 with HTTP; Mon, 12 Jan 2015 16:14:50 -0800 (PST)
44
+ Date: Mon, 12 Jan 2015 19:14:50 -0500
45
+ Message-ID: <CAN-VoWnLrcfGJ6kdEK-Ba2B3ENE6h2OpRMRF91svJVMb3U5fNA@mail.gmail.com>
46
+ Subject: [thoughts] the earth is the best manufacturer we have
47
+ From: Kunal Shah <me@kunalashah.com>
48
+ To: stream@kunalashah.com
49
+ Content-Type: multipart/alternative; boundary=001a113aba9cecfbdc050c7d82bb
50
+
51
+ --001a113aba9cecfbdc050c7d82bb
52
+ Content-Type: text/plain; charset=UTF-8
53
+
54
+ vv
55
+
56
+ --001a113aba9cecfbdc050c7d82bb
57
+ Content-Type: text/html; charset=UTF-8
58
+
59
+ <p dir="ltr">vv</p>
60
+
61
+ --001a113aba9cecfbdc050c7d82bb--
@@ -60,8 +60,8 @@ module Mail2FrontMatter
60
60
  @body = @body.inner_html
61
61
 
62
62
  @metadata = {
63
- from: message[:to].value,
64
- to: message[:from].value,
63
+ from: message[:from].value,
64
+ to: message[:to].value,
65
65
  received: message.date,
66
66
  subject: message.subject,
67
67
  attachments: attachments
@@ -1,23 +1,5 @@
1
1
 
2
2
  # Pre-processes blog data, allows hooks
3
- #
4
- #
5
- # Build a Pre-Processor that accepts two arguments
6
- # metadata, a symbolized hash of metadata extracted from the email
7
- # and body, a Nokogiri parsed representation of the email
8
- #
9
- # modify as necessary and as atomically as possible and return two arguments
10
- #
11
- # example:
12
- #
13
- # module Mail2FrontMatter
14
- # class MyProcessor < PreProcessor
15
- # def self.run(metadata, body)
16
- # metadata[:some_field] = some_transformation_of(metadata[:some_field])
17
- # return metadata, body
18
- # end
19
- # end
20
- # end
21
3
 
22
4
  module Mail2FrontMatter
23
5
  class PreProcessor
@@ -1,3 +1,3 @@
1
1
  module Mail2FrontMatter
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -21,6 +21,8 @@ Gem::Specification.new do |spec|
21
21
  spec.add_dependency "mailman"
22
22
  spec.add_dependency "activesupport"
23
23
 
24
+ spec.add_development_dependency "rspec"
25
+ spec.add_development_dependency "byebug"
24
26
  spec.add_development_dependency "bundler", "~> 1.7"
25
27
  spec.add_development_dependency "rake", "~> 10.0"
26
28
  end
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+ require 'byebug'
3
+
4
+ describe Mail2FrontMatter::Parser, "parsing" do
5
+
6
+ let(:message_one) { Mail::Message.new(File.read(File.join(M2FM_GEM_PATH, 'fixtures', 'attachments.eml'))) }
7
+
8
+ it "should parse HTML email" do
9
+ expect {
10
+ Mail2FrontMatter::Parser.new(message_one)
11
+ }.to_not raise_error
12
+ end
13
+
14
+ it "should return an html body as a string" do
15
+ Mail2FrontMatter::Parser.new(message_one).body.should match(/Charlie<br>/)
16
+ end
17
+
18
+ it "should return have an email metadata hash with a from key" do
19
+ from = Mail2FrontMatter::Parser.new(message_one).metadata[:from]
20
+ from.should eq("Kunal Shah <kunalashokshah@gmail.com>")
21
+ end
22
+
23
+ it "should return have an email metadata hash with a to key" do
24
+ to = Mail2FrontMatter::Parser.new(message_one).metadata[:to]
25
+ to.should eq("stream@kunalashah.com")
26
+ end
27
+
28
+ it "should return have an email metadata hash with a received key" do
29
+ received = Mail2FrontMatter::Parser.new(message_one).metadata[:received]
30
+ received.class.should eq(DateTime)
31
+ end
32
+
33
+ it "should return have an email metadata hash with a subject key" do
34
+ subject = Mail2FrontMatter::Parser.new(message_one).metadata[:subject]
35
+ subject.should eq("295 Abandoned Elevator Shaft")
36
+ end
37
+
38
+ it "should save attachments to disk" do
39
+ attachment_path = Mail2FrontMatter::Parser.new(message_one).metadata[:attachments].first[1][:filepath]
40
+ File.exist?(attachment_path).should eq(true)
41
+ end
42
+
43
+ end
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+ require 'byebug'
3
+
4
+ describe Mail2FrontMatter::PreProcessor, "registration" do
5
+
6
+ let(:invalidly_defined_preprocessor) {
7
+ class MyInvalidProcessor < Mail2FrontMatter::PreProcessor
8
+ # note, instanced not class
9
+ def run(metadata, body)
10
+ # some modification
11
+ return metadata, body
12
+ end
13
+ end
14
+
15
+ return MyInvalidProcessor
16
+ }
17
+
18
+ let(:validly_defined_preprocessor) {
19
+ class MyValidProcessor < Mail2FrontMatter::PreProcessor
20
+ def self.run(metadata, body)
21
+ # some modification
22
+ return metadata, body
23
+ end
24
+ end
25
+
26
+ return MyValidProcessor
27
+ }
28
+
29
+ it "should raise errors for invalid processors" do
30
+ expect {
31
+ invalidly_defined_preprocessor.register({})
32
+ }.to raise_error
33
+ end
34
+
35
+ it "should not raise errors for valid processors" do
36
+ expect {
37
+ validly_defined_preprocessor.register({})
38
+ }.to_not raise_error
39
+ end
40
+
41
+ end
@@ -0,0 +1,5 @@
1
+
2
+ M2FM_GEM_PATH = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ require 'yaml'
5
+ require File.join(M2FM_GEM_PATH, 'lib', 'mail2frontmatter')
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mail2frontmatter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kunal Shah
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-12 00:00:00.000000000 Z
11
+ date: 2015-01-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mailman
@@ -38,6 +38,34 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: byebug
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
41
69
  - !ruby/object:Gem::Dependency
42
70
  name: bundler
43
71
  requirement: !ruby/object:Gem::Requirement
@@ -81,6 +109,9 @@ files:
81
109
  - README.md
82
110
  - Rakefile
83
111
  - bin/mail2frontmatter
112
+ - fixtures/attachments.eml
113
+ - fixtures/attachments_inline.eml
114
+ - fixtures/no_attachments.eml
84
115
  - lib/mail2frontmatter.rb
85
116
  - lib/mail2frontmatter/parser.rb
86
117
  - lib/mail2frontmatter/preprocessor.rb
@@ -88,6 +119,9 @@ files:
88
119
  - lib/mail2frontmatter/watcher.rb
89
120
  - lib/mail2frontmatter/writer.rb
90
121
  - mail2frontmatter.gemspec
122
+ - spec/parser_spec.rb
123
+ - spec/preprocessor_spec.rb
124
+ - spec/spec_helper.rb
91
125
  homepage: https://github.com/whistlerbrk/Mail2FrontMatter
92
126
  licenses:
93
127
  - MIT
@@ -112,4 +146,7 @@ rubygems_version: 2.4.5
112
146
  signing_key:
113
147
  specification_version: 4
114
148
  summary: Email-to-blog parser which creates YAML FrontMatter
115
- test_files: []
149
+ test_files:
150
+ - spec/parser_spec.rb
151
+ - spec/preprocessor_spec.rb
152
+ - spec/spec_helper.rb