mime_builder 0.0.2 → 0.0.3
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -1
- data/README.md +16 -8
- data/lib/mime_builder/text.rb +27 -1
- data/lib/mime_builder.rb +1 -1
- metadata +12 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4433b3e98a0fa4631cc3a6b2193a2c5e26687a20
|
4
|
+
data.tar.gz: 79d171be6bbf4bf3c4350230a2360d5692fb5371
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f4e135cd2153477e464ee05b307c7b728938b3a6cff006904d5d77437d5ba2d385ca682a6245268cff521beeef244c3b0593fd83204dbd9b167a93d8e2cea069
|
7
|
+
data.tar.gz: 7bee0cfe96986ef80484be8bbb552c537ead6aedeb6018b12bd96bad6ce1d773d15493675154a794acafaa688ba74f3c491fa3016858b798bdf0a05a203c57a2
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,12 @@
|
|
1
1
|
CHANGELOG
|
2
2
|
---------
|
3
|
+
- **2015-05-30**: 0.0.3
|
4
|
+
- Add Text support for arbitrary content types
|
5
|
+
- Add Text support for content disposition
|
6
|
+
- **2016-01-25**: 0.0.2
|
7
|
+
- Improve docs
|
8
|
+
- Add tests
|
3
9
|
- **2016-01-23**: 0.0.1
|
4
|
-
- Initial release
|
10
|
+
- Initial release
|
11
|
+
- Add MIME part builder for files given a filepath
|
12
|
+
- Add MIME part builder for text given a string
|
data/README.md
CHANGED
@@ -19,7 +19,7 @@ This library creates `mime` parts from limited information.
|
|
19
19
|
|
20
20
|
### Via Bundler
|
21
21
|
|
22
|
-
Add
|
22
|
+
Add `mime_builder` to Gemfile and then run `bundle`:
|
23
23
|
|
24
24
|
```sh
|
25
25
|
$ echo "gem 'mime_builder'" >> Gemfile
|
@@ -56,12 +56,10 @@ Options:
|
|
56
56
|
```ruby
|
57
57
|
builder = MIMEBuilder::Filepath(
|
58
58
|
'/path/to/file',
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
:is_attachment => true # add 'attachment' disposition
|
64
|
-
}
|
59
|
+
base64_encode: true, # base64 encode part
|
60
|
+
content_id_disable: true, # remove auto-generated Content-Id header
|
61
|
+
content_type: 'text/plain', # override auto-generated Content-Type
|
62
|
+
is_attachment: true # add 'attachment' disposition
|
65
63
|
)
|
66
64
|
```
|
67
65
|
|
@@ -81,13 +79,23 @@ mime_part = builder.mime
|
|
81
79
|
Options:
|
82
80
|
|
83
81
|
```ruby
|
84
|
-
builder = MIMEBuilder::Text
|
82
|
+
builder = MIMEBuilder::Text(
|
83
|
+
'Hi there!',
|
84
|
+
content_id_disable: true, # remove auto-generated Content-Id header
|
85
|
+
content_type: 'text/html' # override auto-generated Content-Type
|
86
|
+
)
|
85
87
|
```
|
86
88
|
|
87
89
|
## Change Log
|
88
90
|
|
89
91
|
See [CHANGELOG.md](CHANGELOG.md)
|
90
92
|
|
93
|
+
## Links
|
94
|
+
|
95
|
+
Project Repo
|
96
|
+
|
97
|
+
* https://github.com/grokify/mime-builder-ruby
|
98
|
+
|
91
99
|
## Contributions
|
92
100
|
|
93
101
|
Any reports of problems, comments or suggestions are most welcome.
|
data/lib/mime_builder/text.rb
CHANGED
@@ -7,9 +7,35 @@ module MIMEBuilder
|
|
7
7
|
|
8
8
|
def initialize(text, opts = {})
|
9
9
|
@text = text
|
10
|
-
|
10
|
+
|
11
|
+
if opts.key?(:content_type) && opts[:content_type].to_s.length>0
|
12
|
+
content_type = opts[:content_type]
|
13
|
+
if content_type =~ /^text\/([^\/]+)$/i
|
14
|
+
@mime = MIME::Text.new(text, $1.downcase)
|
15
|
+
else
|
16
|
+
raise "Unknown Content Type: " + opts[:content_type].to_s
|
17
|
+
end
|
18
|
+
else
|
19
|
+
@mime = MIME::Text.new(text, 'plain')
|
20
|
+
end
|
21
|
+
|
11
22
|
@mime.headers.delete('Content-Id') \
|
12
23
|
if opts.key?(:content_id_disable) && opts[:content_id_disable]
|
24
|
+
|
25
|
+
set_attachment_content_disposition(opts[:filename], opts[:is_attachment])
|
26
|
+
end
|
27
|
+
|
28
|
+
def set_attachment_content_disposition(filename, is_attachment)
|
29
|
+
@mime.headers.set(
|
30
|
+
'Content-Disposition',
|
31
|
+
get_attachment_content_disposition(filename)
|
32
|
+
) if is_attachment
|
33
|
+
end
|
34
|
+
|
35
|
+
def get_attachment_content_disposition(filename = nil)
|
36
|
+
cd = filename.to_s.length > 0 \
|
37
|
+
? "attachment; filename=\"#{filename}\"" \
|
38
|
+
: 'attachment'
|
13
39
|
end
|
14
40
|
end
|
15
41
|
end
|
data/lib/mime_builder.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mime_builder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Wang
|
@@ -14,28 +14,28 @@ dependencies:
|
|
14
14
|
name: mime
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: mime-types
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '1.25'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.25'
|
41
41
|
description: Helper library to build MIME parts
|
@@ -44,15 +44,15 @@ executables: []
|
|
44
44
|
extensions: []
|
45
45
|
extra_rdoc_files: []
|
46
46
|
files:
|
47
|
-
- lib/mime_builder/file.rb
|
48
|
-
- lib/mime_builder/text.rb
|
49
|
-
- lib/mime_builder.rb
|
50
47
|
- CHANGELOG.md
|
51
48
|
- Gemfile
|
52
49
|
- Gemfile.lock
|
53
50
|
- LICENSE.txt
|
54
|
-
- Rakefile
|
55
51
|
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- lib/mime_builder.rb
|
54
|
+
- lib/mime_builder/file.rb
|
55
|
+
- lib/mime_builder/text.rb
|
56
56
|
- test/test_base.rb
|
57
57
|
- test/test_file.pdf
|
58
58
|
- test/test_file.rb
|
@@ -67,17 +67,17 @@ require_paths:
|
|
67
67
|
- lib
|
68
68
|
required_ruby_version: !ruby/object:Gem::Requirement
|
69
69
|
requirements:
|
70
|
-
- -
|
70
|
+
- - ">="
|
71
71
|
- !ruby/object:Gem::Version
|
72
72
|
version: '0'
|
73
73
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
74
|
requirements:
|
75
|
-
- -
|
75
|
+
- - ">="
|
76
76
|
- !ruby/object:Gem::Version
|
77
77
|
version: '0'
|
78
78
|
requirements: []
|
79
79
|
rubyforge_project:
|
80
|
-
rubygems_version: 2.1
|
80
|
+
rubygems_version: 2.5.1
|
81
81
|
signing_key:
|
82
82
|
specification_version: 4
|
83
83
|
summary: MIME Builder is a helper to build MIME parts
|