MIMEBuilder Ruby

Gem Version Build Status Coverage Status Code Climate Scrutinizer Code Quality

Downloads Docs License

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
$ bundle

Via RubyGems

$ 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
builder = MIMEBuilder::Filepath.new '/path/to/file'
mime_part = builder.mime

Options:

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
builder = MIMEBuilder::Text.new 'Hi there!' 
mime_part = builder.mime

Options:

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
  2. base64 encode the content
builder = MIMEBuilder::JSON.new { foo: 'bar' }
mime_part = builder.mime

Options:

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

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 by John Wang