# mimelib

> MIME functions to encode/decode e-mails etc.

Latest version **0.3.1** (published 2017-06-05) · EUPL-1.1 license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install mimelib
pnpm add mimelib
yarn add mimelib
bun add mimelib
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.3.1 |
| Published | 2017-06-05 |
| First published | 2011-05-05 |
| Weekly downloads | 0 |
| License | EUPL-1.1 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 84 |
| Author | Andris Reinman |
| Maintainers | andris |
| Keywords | e-mail, mime, email |

## Links

- npm: https://www.npmjs.com/package/mimelib
- Repository: https://github.com/andris9/mimelib
- Homepage: http://github.com/andris9/mimelib
- Issues: https://github.com/andris9/mimelib/issues
- npm.io page: https://npm.io/package/mimelib

## Dependencies (2)

- [encoding](https://npm.io/package/encoding.md) ~0.1.12
- [addressparser](https://npm.io/package/addressparser.md) ~1.0.1

## Alternatives

- [@expo/fingerprint](https://npm.io/package/@expo/fingerprint.md) — 6.2M weekly downloads
- [@azure/monitor-opentelemetry-exporter](https://npm.io/package/@azure/monitor-opentelemetry-exporter.md) — 850.0K weekly downloads
- [@azure/monitor-opentelemetry](https://npm.io/package/@azure/monitor-opentelemetry.md) — 624.0K weekly downloads
- [@posthog/ai](https://npm.io/package/@posthog/ai.md) — 423.3K weekly downloads
- [fakefilter](https://npm.io/package/fakefilter.md) — 63.9K weekly downloads

## Recent versions

- 0.3.1 (latest) — 2017-06-05
- 0.3.0 — 2016-10-12
- 0.2.19 — 2015-02-20
- 0.2.18 — 2014-10-25
- 0.2.17 — 2014-08-07
- 0.2.16 — 2014-05-15
- 0.2.15 — 2014-05-13
- 0.2.14 — 2013-10-30
- 0.2.13 — 2013-10-03
- 0.2.12 — 2013-03-23
- 0.2.11 — 2013-03-22
- 0.2.10 — 2012-12-28
- 0.2.9 — 2012-12-22
- 0.2.8 — 2012-11-30
- 0.2.7 — 2012-09-26
- … 25 more at https://npm.io/package/mimelib/versions

## README

## THIS MODULE IS DEPRECATED

# mimelib

*mimelib* is a collection of useful functions to deal with mime-encoded data.

## Installation

Install with *npm*

    npm install mimelib
    
## Usage

    var mimelib = require("mimelib");

## Reference

### foldLine

Folds a long line according to the RFC 5322 <http://tools.ietf.org/html/rfc5322#section-2.1.1>

    mimelib.foldLine(str [, maxLength][, foldAnywhere][, afterSpace]) -> String
    
  - `str` (String): mime string that might need folding
  - `maxLength` (Number): max length for a line, defaults to 78
  - `foldAnywhere` (Boolean): can fold at any location (ie. in base64)
  - `afterSpace` (Boolean): If `true` fold after the space
 

For example:

    Content-Type: multipart/alternative; boundary="----zzzz----"

will become

    Content-Type: multipart/alternative;
         boundary="----zzzz----"

### encodeMimeWord

Encodes a string into mime encoded word format <http://en.wikipedia.org/wiki/MIME#Encoded-Word>  (see also `decodeMimeWord`)

    mimelib.encodeMimeWord = function(str [, encoding][, charset])

  - `str` (String): String to be encoded
  - `encoding` (String): Encoding Q for quoted printable or B (def.) for base64
  - `charset` (String): Charset to be used
  
For example:

    See on õhin test

Becomes with UTF-8 and Quoted-printable encoding

    =?UTF-8?Q?See_on_=C3=B5hin_test?=
    
### decodeMimeWord

Decodes a string from mime encoded word format (see also `encodeMimeWord`)

    mimelib.decodeMimeWord(str) -> String
    
  - `str` (String): String to be decoded

For example

    mimelib.decodeMimeWord("=?UTF-8?Q?See_on_=C3=B5hin_test?=");

will become

    See on õhin test

### encodeQuotedPrintable

Encodes a string into Quoted-printable format (see also `decodeQuotedPrintable`)

    mimelib.encodeQuotedPrintable(str [, mimeWord][, charset]) -> String
    
  - `str` (String): String to be encoded into Quoted-printable
  - `mimeWord` (Boolean): Deprecated, has no effect, ignore it
  - `charset` (String): Destination charset, defaults to UTF-8

### decodeQuotedPrintable

Decodes a string from Quoted-printable format  (see also `encodeQuotedPrintable`)

    mimelib.decodeQuotedPrintable(str [, mimeWord][, charset]) -> String
    
  - `str` (String): String to be decoded
  - `mimeWord` (Boolean): Deprecated, has no effect, ignore it
  - `charset` (String): Charset to be used, defaults to UTF-8
  
### encodeBase64

Encodes a string into Base64 format. Base64 is mime-word safe (see also `decodeBase64`)

    mimelib.encodeBase64(str [, charset]) -> String
    
  - `str` (String): String to be encoded into Base64
  - `charset` (String): Destination charset, defaults to UTF-8

### decodeBase64

Decodes a string from Base64 format. Base64 is mime-word safe (see also `encodeBase64`)

NB! Always returns UTF-8

    mimelib.decodeBase64(str) -> String

  - `str` (String): String to be decoded from Base64
  - `charset` (String): Source charset, defaults to UTF-8
  
### parseHeaders

Parses header lines into an array of objects (see `parseHeaderLine`)

    mimelib.parseHeaders(headers) -> Array
    
  - `headers` (String): header section of the e-mail

Example:

    var headers = [
        "From: andris@node.ee",
        "To: juulius@node.ee",
        "To: juulius2@node.ee",
        "Content-type: text/html;",
        "    charset=utf-8"
        ].join("\r\n");
    mimelib.parseHeaders(headers);

Results in 

    {"from": [ 'andris@node.ee' ],
     "to": [ 'juulius@node.ee', 'juulius2@node.ee' ],
     "content-type": [ 'text/html;    charset=utf-8' ] }

### parseAddresses

Parses names and addresses from a from, to, cc or bcc line

    mimelib.parseAddresses(addresses) -> Array
    
  - `addresses` (String): string with comma separated e-mail addresses  
  
Example:

    var to = '"Andris Reinman" <andris@node.ee>, juulius@node.ee'
    mimelib.parseAddresses(to);
  
Results in

    [{ address: 'andris@node.ee', name: 'Andris Reinman' },
     { address: 'juulius@node.ee', name: false }]

### parseMimeWords

Parses mime-words into UTF-8 strings

    mimelib.parseMimeWords(str) -> String

  - `str` (String): string to be parsed, if includes any mime words, then these are converted to UTF-8 strings
  
  
For example:

    mimelib.parseMimeWords("Hello: =?UTF-8?Q?See_on_=C3=B5hin_test?=");

Results in

    "Hello: See on õhin test"
    
### parseHeaderLine

Parses a header line to search for additional parameters.

    mimelib.parseHeaderLine(line) -> Object
    
  - `line` (String): a line from a message headers
  
For example:

    mimelib.parseHeaderLine("text/plain; charset=utf-8")imelib

Results in

    {"defaultValue": 'text/plain',
     "charset": 'utf-8' }

### contentTypes

**NB! this feature is deprecated**, use [mime](https://github.com/broofa/node-mime) module instead to detect content types and extensions

`mimelib.contentTypes` is an object to provide content type strings for common
file extensions

    mimelib.contentTypes["xls"]; // "application/vnd.ms-excel"

## iconv support

By default only iconv-lite support is bundled. If you need node-iconv support, you need to add it
as an additional dependency for your project:

    ...,
    "dependencies":{
        "mimelib": "*",
        "iconv": "*"
    },
    ...

## License

mimelib is licensed under the [European Union Public License 1.1](http://ec.europa.eu/idabc/eupl.html).

---
_Source: https://npm.io/package/mimelib · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
