https://github.com/grokify/mime-builder-ruby
Builder for MIME parts
https://github.com/grokify/mime-builder-ruby
Last synced: about 1 year ago
JSON representation
Builder for MIME parts
- Host: GitHub
- URL: https://github.com/grokify/mime-builder-ruby
- Owner: grokify
- License: mit
- Created: 2016-01-23T19:38:54.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2023-02-15T17:22:13.000Z (over 3 years ago)
- Last Synced: 2024-10-12T00:51:27.989Z (over 1 year ago)
- Language: Ruby
- Homepage:
- Size: 34.2 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
MIMEBuilder Ruby
================
[![Gem Version][gem-version-svg]][gem-version-link]
[![Build Status][build-status-svg]][build-status-url]
[![Coverage Status][coverage-status-svg]][coverage-status-link]
[![Code Climate][codeclimate-status-svg]][codeclimate-status-link]
[![Scrutinizer Code Quality][scrutinizer-status-svg]][scrutinizer-status-link]
[![Docs][docs-rubydoc-svg]][docs-rubydoc-link]
[![License][license-svg]][license-link]
## Overview
This library creates MIME parts from limited information. The MIME parts are based on the Ruby `mime` library and are all sub-classes of `MIME::Media`.
## Installation
### Via Bundler
Add `mime_builder` to Gemfile and then run `bundle`:
```sh
$ echo "gem 'mime_builder'" >> Gemfile
$ bundle
```
### Via RubyGems
```sh
$ gem install mime_builder
```
## Usage
### From Filepath
Builds a `MIME::Application` or `MIME::Type` object depending on whether base64 encoding is selected. This reads bytes from filesystem and populates the following MIME headers:
1. `Content-Disposition`
2. `Content-Transfer-Encoding`
3. `Content-Type`
This will optionally delete the following auto-generated header:
1. `Content-Id`
```ruby
builder = MIMEBuilder::Filepath.new '/path/to/file'
mime_part = builder.mime
```
Options:
```ruby
builder = MIMEBuilder::Filepath.new(
'/path/to/file',
base64_encode: true, # base64 encode part
content_id_disable: true, # remove auto-generated Content-Id header
content_type: 'text/plain', # override auto-generated Content-Type
is_attachment: true # add 'attachment' disposition
)
```
### From String
Builds a `MIME::Text` object. This accepts a string and can optionally populate the following headers:
1. `Content-Disposition`
2. `Content-Type`
This will optionally delete the following auto-generated header:
1. `Content-Id`
```ruby
builder = MIMEBuilder::Text.new 'Hi there!'
mime_part = builder.mime
```
Options:
```ruby
builder = MIMEBuilder::Text.new(
'Hi there!',
content_id_disable: true, # remove auto-generated Content-Id header
content_type: 'text/html' # override auto-generated Content-Type
)
```
### From JSON
Builds a `MIME::Text` object. This accepts a string, hash, or array.
This will optionally:
1. delete the following auto-generated `Content-Id`
1. base64 encode the content
```ruby
builder = MIMEBuilder::JSON.new { foo: 'bar' }
mime_part = builder.mime
```
Options:
```ruby
builder = MIMEBuilder::JSON.new(
{ foo: 'bar' },
content_id_disable: true, # remove auto-generated Content-Id header
base64_encode: false # disable default base64 encoding
)
```
## Change Log
See [CHANGELOG.md](CHANGELOG.md)
## Links
Project Repo
* https://github.com/grokify/mime-builder-ruby
MIME Library
* https://rubygems.org/gems/mime
* https://bitbucket.org/pachl/mime/src
## Contributions
Any reports of problems, comments or suggestions are most welcome.
Please report these on [Github](https://github.com/grokify/mime-builder-ruby)
## License
MIMEBuilder is available under an MIT-style license. See [LICENSE.md](LICENSE.md) for details.
MIMEBuilder © 2016-2023 by John Wang
[gem-version-svg]: https://badge.fury.io/rb/mime_builder.svg
[gem-version-link]: http://badge.fury.io/rb/mime_builder
[downloads-svg]: http://ruby-gem-downloads-badge.herokuapp.com/mime_builder
[downloads-link]: https://rubygems.org/gems/mime_builder
[build-status-svg]: https://github.com/grokify/mime-builder-ruby/workflows/ruby%20build/badge.svg?branch=master
[build-status-url]: https://github.com/grokify/mime-builder-ruby/actions
[codacy-svg]: https://api.codacy.com/project/badge/Grade/fa30d602e8ec4eae806bb43430989d65
[codacy-link]: https://www.codacy.com/app/grokify/mime-builder-ruby
[coverage-status-svg]: https://coveralls.io/repos/grokify/mime-builder-ruby/badge.svg?branch=master
[coverage-status-link]: https://coveralls.io/r/grokify/mime-builder-ruby?branch=master
[dependency-status-svg]: https://gemnasium.com/grokify/mime-builder-ruby.svg
[dependency-status-link]: https://gemnasium.com/grokify/mime-builder-ruby
[codeclimate-status-svg]: https://codeclimate.com/github/grokify/mime-builder-ruby/badges/gpa.svg
[codeclimate-status-link]: https://codeclimate.com/github/grokify/mime-builder-ruby
[scrutinizer-status-svg]: https://scrutinizer-ci.com/g/grokify/mime-builder-ruby/badges/quality-score.png?b=master
[scrutinizer-status-link]: https://scrutinizer-ci.com/g/grokify/mime-builder-ruby/?branch=master
[docs-rubydoc-svg]: https://img.shields.io/badge/docs-rubydoc-blue.svg
[docs-rubydoc-link]: http://www.rubydoc.info/gems/mime_builder/
[license-svg]: https://img.shields.io/badge/license-MIT-blue.svg
[license-link]: https://github.com/grokify/mime-builder-ruby/blob/master/LICENSE.md