Skip to content

infinity.quotedPrintable

Provides Quoted-printable-encoding and decoding functionality for strings, files and streams.

The encoding works character by character on an ISO-8859-1 (Latin-1) basis: a character is encoded as = followed by two uppercase hex digits of its character code (e.g. Ä becomes =C4), and decoding =XX gives the character with the code XX. Characters above U+00FF cannot be represented (only the low byte of the character code is encoded), and UTF-8 encoded data such as =C3=84 is decoded to the two characters Ä, not to Ä. No soft line breaks are inserted when encoding; when decoding, soft line breaks (= at the end of a line or of the data) are removed; an invalid sequence =XY gives XY.

The file and stream functions work on bytes (before 3.11 they produced garbage).

Module: infinity.encoding

Example:

infinity.loadModule('infinity.encoding');

let encodedData = infinity.quotedPrintable.encode('AUO_ÄÜÖ ß-"+&,?.<=>');
console.debug(encodedData);
//AUO=5F=C4=DC=D6 =DF-"+&,?.<=3D>

encodedData = infinity.quotedPrintable.encode('AUO_ÄÜÖ ß-"+&,?.<=>', true);
console.debug(encodedData);
//AUO=5F=C4=DC=D6_=DF-=22+&=2C=3F.=3C=3D=3E

let decodedData = infinity.quotedPrintable.decode(encodedData, true);
console.debug(decodedData);
//AUO_ÄÜÖ ß-"+&,?.<=>

Functions

decode()

Decodes the given string from quoted-printable and returns the results. Every =XX sequence is replaced by the character with the hexadecimal code XX, and soft line breaks (= followed by CR LF) are removed. If = is followed by two characters that are not a hex number, the = is dropped and the two characters are kept.

Signature:

decode( value: string, headerField?: boolean ): string

Parameters:

  • value: string

    The string to decode.

  • headerField: boolean, optional

    If true, the string is decoded as the text of a header field (Q-encoding as in RFC 2047), i.e. _ is decoded to a space as well. Defaults to false.

Return type: string

Example:

infinity.loadModule('infinity.encoding');
let decodedData = infinity.quotedPrintable.decode(encodedData);

decodeFile()

Reads out the contents of the given file, decodes them from quoted-printable and returns the results. The resulting bytes are decoded as UTF-8 if they are valid UTF-8, otherwise as Windows-1252.

Signature:

decodeFile( fileName: string ): string

Parameters:

  • fileName: string

    Filename, relative path (location relative to the folder with the used INFINITY.JS executable file) or absolute path to encoded file.

Return type: string

Example:

infinity.loadModule('infinity.encoding');
let decodedData = infinity.quotedPrintable.decodeFile('encodedData.txt');

decodeFile()

Reads out the contents of the given file, decodes them from quoted-printable and writes the results to a file at the given location. The output file is created or overwritten.

Signature:

decodeFile( inFileName: string, outFileName: string ): void

Parameters:

  • inFileName: string

    Filename, relative path (location relative to the folder with the used INFINITY.JS executable file) or absolute path to encoded file.

  • outFileName: string

    Filename, relative path (location relative to the folder with the used INFINITY.JS executable file) or absolute path to the file which should contain the decoded output.

Example:

infinity.loadModule('infinity.encoding');
infinity.quotedPrintable.decodeFile('encodedData.txt', 'decodedData.txt');

decodeStream()

Reads the contents of the given stream from its current position, decodes them from quoted-printable and writes the results to another given stream at its current position.

Signature:

decodeStream( inStream: infinity.stream, outStream: infinity.stream ): void

Parameters:

Example:

infinity.loadModule('infinity.encoding');
infinity.quotedPrintable.decodeStream(inStream, outStream);

encode()

Encodes the given string with quoted-printable and returns the results. Control characters (including CR and LF), characters from code 127 upwards, = and _ are encoded; all other characters, including spaces, are kept. A string consisting only of . is encoded as =2E.

Signature:

encode( value: string, headerField?: boolean ): string

Parameters:

  • value: string

    The string to encode.

  • headerField: boolean, optional

    If true, the string is encoded for use in a header field (Q-encoding as in RFC 2047): spaces are encoded as _, and the characters ", ,, <, >, ? and \ are encoded as well. The =?charset?Q?...?= wrapper is not added. Defaults to false.

Return type: string

Example:

infinity.loadModule('infinity.encoding');
let encodedData = infinity.quotedPrintable.encode(dataToEncode, true);

encodeFile()

Reads out the contents of the given file, encodes them to quoted-printable and writes the results to a file at the given location. The output file is created or overwritten.

Signature:

encodeFile( inFileName: string, outFileName: string ): void

Parameters:

  • inFileName: string

    Filename, relative path (location relative to the folder with the used INFINITY.JS executable file) or absolute path to the file which has to be encoded.

  • outFileName: string

    Filename, relative path (location relative to the folder with the used INFINITY.JS executable file) or absolute path to the file which should contain the encoded output.

Example:

infinity.loadModule('infinity.encoding');
infinity.quotedPrintable.encodeFile('dataToEncode.txt', 'encodedData.txt');

encodeFile()

Reads out the contents of the given file, encodes them to quoted-printable and returns the results.

Signature:

encodeFile( fileName: string ): string

Parameters:

  • fileName: string

    Filename, relative path (location relative to the folder with the used INFINITY.JS executable file) or absolute path to the file which has to be encoded.

Return type: string

Example:

infinity.loadModule('infinity.encoding');
let encodedData = infinity.quotedPrintable.encodeFile('dataToEncode.txt');

encodeStream()

Reads the contents of the given stream from its current position, encodes them to quoted-printable and writes the results to another given stream at its current position.

Signature:

encodeStream( inStream: infinity.stream, outStream: infinity.stream ): void

Parameters:

Example:

infinity.loadModule('infinity.encoding');
infinity.quotedPrintable.encodeStream(inStream, outStream);