Skip to content

Instantly share code, notes, and snippets.

@josher19
Created February 14, 2012 07:29
Show Gist options
  • Save josher19/1824504 to your computer and use it in GitHub Desktop.
Save josher19/1824504 to your computer and use it in GitHub Desktop.
/** Convert quoted printable text to plain text using QP.decode. */
QP = QuotedPrintable = {
decode: function (data) { return unescape(data.replace(/=\r?\n/g, "").replace(/=/g, "%")); }
, encode: function (inp) { return this.sliceup( inp.replace(/[^ a-zA-Z0-9:.,<>'";\r\n!-<>-~]/g, function(c) { return escape(c).replace(/%/g, "=") }) ).replace(/ \r?\n/g, "=20\r\n").replace(/\t\r?\n/g, "=09\r\n"); }
, sliceup: function (chunk, sz, sep) { sz=(sz-0)||75; var i, res=[], len = chunk.length/sz; for(i=0; i<len; ++i) res[i]=chunk.slice(i*sz, (i+1)*sz); return res.join(sep || "=\n"); }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment