mail_extract 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -12,31 +12,48 @@ It removes all quoted text and signatures leaving only original text.
12
12
 
13
13
  ### General usage
14
14
 
15
- require 'mail_extract'
15
+ ```ruby
16
+ require 'mail_extract'
16
17
 
17
- body = MailExtract::Parser.new('MESSAGE').body
18
+ body = MailExtract::Parser.new('MESSAGE').body
18
19
 
19
- # or via shortcut
20
- body = MailExtract.new('MESSAGE').body
20
+ # or via shortcut
21
+ body = MailExtract.new('MESSAGE').body
22
+
23
+ # or via another shortcut
24
+ body = MailExtract.parse('MESSAGE')
25
+ ```
21
26
 
22
27
  ### Using with Mail gem
23
28
 
24
- require 'mail'
25
- require 'mail_extract'
26
-
27
- mail = Mail.read_from_string(YOUR_MESSAGE_BODY)
28
-
29
- # find only plain-text parts
30
- if mail.multipart?
31
- part = mail.parts.select { |p| p.content_type =~ /text\/plain/ }.first rescue nil
32
- unless part.nil?
33
- message = part.body.decoded
34
- end
35
- else
36
- message = part.body.decoded
37
- end
38
-
39
- clean_message = MailExtract.new(message).body
29
+ ```ruby
30
+ require 'mail'
31
+ require 'mail_extract'
32
+
33
+ mail = Mail.read_from_string(YOUR_MESSAGE_BODY)
34
+
35
+ # find only plain-text parts
36
+ if mail.multipart?
37
+ part = mail.parts.select { |p| p.content_type =~ /text\/plain/ }.first rescue nil
38
+ unless part.nil?
39
+ message = part.body.decoded
40
+ end
41
+ else
42
+ message = part.body.decoded
43
+ end
44
+
45
+ clean_message = MailExtract.new(message).body
46
+ ```
47
+
48
+ ### Configuration
49
+
50
+ If you need to grab only a head part of the message body you need to specify *:only_head* parameter:
51
+
52
+ ```ruby
53
+ MailExtract.new(message, :only_head => true)
54
+ ```
55
+
56
+ This is extremely useful if you're parsing an email from mobile devices (iphone?) which do not follow the quote pattens.
40
57
 
41
58
  ## Known issues
42
59
 
@@ -5,10 +5,24 @@ module MailExtract
5
5
  class << self
6
6
  # Shortcut to MailExtract::Parser.new
7
7
  #
8
+ # body - Email message contents
9
+ # options - Parser options
10
+ #
8
11
  # @return [MailExtract::Parser]
9
12
  #
10
13
  def new(body, options={})
11
14
  MailExtract::Parser.new(body, options)
12
15
  end
16
+
17
+ # Parse the email message
18
+ #
19
+ # body - Email message contents
20
+ # options - Parser options
21
+ #
22
+ # @return [String]
23
+ #
24
+ def parse(body, options={})
25
+ MailExtract::Parser.new(body, options).body
26
+ end
13
27
  end
14
28
  end
@@ -1,5 +1,5 @@
1
1
  module MailExtract
2
2
  unless defined? ::MailExtract::VERSION
3
- VERSION = "0.1.3".freeze
3
+ VERSION = "0.1.4".freeze
4
4
  end
5
5
  end
@@ -0,0 +1,8 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'MailExtract' do
4
+ it 'parses an email via shortcuts' do
5
+ MailExtract.new(fixture('simple.txt')).body.should == result_fixture('simple.txt')
6
+ MailExtract.parse(fixture('simple.txt')).should == result_fixture('simple.txt')
7
+ end
8
+ end
metadata CHANGED
@@ -1,49 +1,44 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: mail_extract
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.4
4
5
  prerelease:
5
- version: 0.1.3
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Dan Sosedoff
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2011-08-12 00:00:00 -05:00
14
- default_executable:
15
- dependencies:
16
- - !ruby/object:Gem::Dependency
12
+ date: 2011-08-26 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
17
15
  name: rake
18
- prerelease: false
19
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &2161093000 !ruby/object:Gem::Requirement
20
17
  none: false
21
- requirements:
22
- - - ">="
23
- - !ruby/object:Gem::Version
24
- version: "0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
25
22
  type: :development
26
- version_requirements: *id001
27
- - !ruby/object:Gem::Dependency
28
- name: rspec
29
23
  prerelease: false
30
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *2161093000
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ requirement: &2161092340 !ruby/object:Gem::Requirement
31
28
  none: false
32
- requirements:
29
+ requirements:
33
30
  - - ~>
34
- - !ruby/object:Gem::Version
35
- version: "2.6"
31
+ - !ruby/object:Gem::Version
32
+ version: '2.6'
36
33
  type: :development
37
- version_requirements: *id002
34
+ prerelease: false
35
+ version_requirements: *2161092340
38
36
  description: Email body parser that strips out all quotes and signatures.
39
37
  email: dan.sosedoff@gmail.com
40
38
  executables: []
41
-
42
39
  extensions: []
43
-
44
40
  extra_rdoc_files: []
45
-
46
- files:
41
+ files:
47
42
  - .gitignore
48
43
  - .rspec
49
44
  - .travis.yml
@@ -63,37 +58,34 @@ files:
63
58
  - spec/fixtures/simple.txt
64
59
  - spec/fixtures/simple_with_quotes.txt
65
60
  - spec/line_spec.rb
61
+ - spec/mail_extract_spec.rb
66
62
  - spec/parser_spec.rb
67
63
  - spec/spec_helper.rb
68
- has_rdoc: true
69
64
  homepage: https://github.com/sosedoff/mail_extract
70
65
  licenses: []
71
-
72
66
  post_install_message:
73
67
  rdoc_options: []
74
-
75
- require_paths:
68
+ require_paths:
76
69
  - lib
77
- required_ruby_version: !ruby/object:Gem::Requirement
70
+ required_ruby_version: !ruby/object:Gem::Requirement
78
71
  none: false
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: "0"
83
- required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
77
  none: false
85
- requirements:
86
- - - ">="
87
- - !ruby/object:Gem::Version
88
- version: "0"
78
+ requirements:
79
+ - - ! '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
89
82
  requirements: []
90
-
91
83
  rubyforge_project:
92
- rubygems_version: 1.6.2
84
+ rubygems_version: 1.8.6
93
85
  signing_key:
94
86
  specification_version: 3
95
87
  summary: Extracts email message body
96
- test_files:
88
+ test_files:
97
89
  - spec/fixtures/iphone.txt
98
90
  - spec/fixtures/iphone_with_quotes.txt
99
91
  - spec/fixtures/reply_with_quotes.txt
@@ -102,5 +94,6 @@ test_files:
102
94
  - spec/fixtures/simple.txt
103
95
  - spec/fixtures/simple_with_quotes.txt
104
96
  - spec/line_spec.rb
97
+ - spec/mail_extract_spec.rb
105
98
  - spec/parser_spec.rb
106
99
  - spec/spec_helper.rb