function QuotedPrintableEncoder() {
this.MaxLineSize = 76;
this.Encode = QuotedPrintableEncode;
this.EncodeLine = QuotedPrintableEncodeLine;
this.EncodeCharacter = QuotedPrintableEncodeCharacter;
	// Exclamation point through less than, and greater than through tilde
// Tab is not listed here as UnAltered but could be
this.UnAltered = String.fromCharCode(32) + String.fromCharCode(60) + String.fromCharCode(62) + String.fromCharCode(126);
this.UnAlteredEnd = String.fromCharCode(33) + String.fromCharCode(60) + String.fromCharCode(62) + String.fromCharCode(126);
}

function QuotedPrintableEncode(InputText) {
	var re = new RegExp("\r\n","g");
	var SplitText, i, s="";
SplitText = InputText.split(re);
for (i=0; i<SplitText.length; ++i)
	s += this.EncodeLine(SplitText[i]) + "\r\n";
return s;
}

function QuotedPrintableEncodeLine(Text) {
	var SplitText, i, s="", c=256;
if (Text.length == 0)
	return "";
for (i=0; i<Text.length-1; ++i)
	s += this.EncodeCharacter(Text.charCodeAt(i), this.UnAltered);
// Encode last character; if space, encode it
s += this.EncodeCharacter(Text.charCodeAt(Text.length-1), this.UnAlteredEnd);
if (s.length <= this.MaxLineSize)
	return s;
// Split into lines of MaxLineSize characters or less
SplitText = s.slice(0, this.MaxLineSize);
i = this.MaxLineSize;
while (i<s.length) {
	SplitText += "=\r\n"+ s.slice(i, i+this.MaxLineSize);
	i += this.MaxLineSize;
	}
return SplitText;
}

function QuotedPrintableEncodeCharacter(Character, UnAltered) {
	var i, x, Alter=true;
for (i=0; i<UnAltered.length; i+=2)
	if (Character >= UnAltered.charCodeAt(i) && Character <= UnAltered.charCodeAt(i+1))
		Alter=false;
if (!Alter)
	return String.fromCharCode(Character);
x = Character.toString(16).toUpperCase();
return (x.length == 1) ? "=0" + x : "=" + x;
}