Skip to content

Instantly share code, notes, and snippets.

@webjay
Created February 5, 2015 02:49
Show Gist options
  • Select an option

  • Save webjay/66ec31e2264c62e701ac to your computer and use it in GitHub Desktop.

Select an option

Save webjay/66ec31e2264c62e701ac to your computer and use it in GitHub Desktop.

Revisions

  1. webjay created this gist Feb 5, 2015.
    29 changes: 29 additions & 0 deletions formpart.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    'use strict';

    var mimelib = require('mimelib');

    var EOL = '\r\n';

    module.exports = formpart;

    function escapeQuotation (str) {
    return str.replace(/"/g, '\"');
    }

    function formpart (boundary, name, value) {
    var lines = [
    'Content-Disposition: form-data; name="' + escapeQuotation(name) + '"',
    'Content-Type: text/plain; charset=UTF-8',
    'Content-Transfer-Encoding: quoted-printable'
    ];
    var part = '';
    part += '--' + boundary + EOL;
    lines.forEach(function (line) {
    part += mimelib.foldLine(line);
    part += EOL;
    });
    part += EOL;
    part += mimelib.encodeQuotedPrintable(value);
    part += EOL;
    return part;
    }