MIMEBuilder Ruby
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:
$ echo "gem 'mime_builder'" >> Gemfile
$ bundleVia RubyGems
$ gem install mime_builderUsage
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:
Content-DispositionContent-Transfer-EncodingContent-Type
This will optionally delete the following auto-generated header:
Content-Id
builder = MIMEBuilder::Filepath.new '/path/to/file'
mime_part = builder.mimeOptions:
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:
Content-DispositionContent-Type
This will optionally delete the following auto-generated header:
Content-Id
builder = MIMEBuilder::Text.new 'Hi there!'
mime_part = builder.mimeOptions:
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:
- delete the following auto-generated
Content-Id - base64 encode the content
builder = MIMEBuilder::JSON.new { foo: 'bar' }
mime_part = builder.mimeOptions:
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
Links
Project Repo
MIME Library
Contributions
Any reports of problems, comments or suggestions are most welcome.
Please report these on Github
License
MIMEBuilder is available under an MIT-style license. See LICENSE.md for details.
MIMEBuilder © 2016-2023 by John Wang