0.0
Low commit activity in last 3 years
No release in over a year
Helper library to build MIME parts
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

~> 3.4, >= 3.4.1
~> 0.4, >= 0.4.4
~> 1, >= 1.15.0
 Project Readme

MIMEBuilder Ruby

Gem Version Build Status Coverage Status Code Climate Scrutinizer Code Quality

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

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