Created
September 10, 2021 06:50
-
-
Save peterblazejewicz/be9ccd938f324f3f74d14b6293f6fd34 to your computer and use it in GitHub Desktop.
libmime.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class Libmime { | |
constructor(config: any); | |
config: any; | |
/** | |
* Checks if a value is plaintext string (uses only printable 7bit chars) | |
* | |
* @param {String} value String to be tested | |
* @returns {Boolean} true if it is a plaintext string | |
*/ | |
isPlainText(value: string): boolean; | |
/** | |
* Checks if a multi line string containes lines longer than the selected value. | |
* | |
* Useful when detecting if a mail message needs any processing at all – | |
* if only plaintext characters are used and lines are short, then there is | |
* no need to encode the values in any way. If the value is plaintext but has | |
* longer lines then allowed, then use format=flowed | |
* | |
* @param {Number} lineLength Max line length to check for | |
* @returns {Boolean} Returns true if there is at least one line longer than lineLength chars | |
*/ | |
hasLongerLines(str: any, lineLength: number): boolean; | |
/** | |
* Decodes a string from a format=flowed soft wrapping. | |
* | |
* @param {String} str Plaintext string with format=flowed to decode | |
* @param {Boolean} [delSp] If true, delete leading spaces (delsp=yes) | |
* @return {String} Mime decoded string | |
*/ | |
decodeFlowed(str: string, delSp?: boolean): string; | |
/** | |
* Adds soft line breaks to content marked with format=flowed to | |
* ensure that no line in the message is never longer than lineLength | |
* | |
* @param {String} str Plaintext string that requires wrapping | |
* @param {Number} [lineLength=76] Maximum length of a line | |
* @return {String} String with forced line breaks | |
*/ | |
encodeFlowed(str: string, lineLength?: number): string; | |
/** | |
* Encodes a string or an Buffer to an UTF-8 MIME Word (rfc2047) | |
* | |
* @param {String|Buffer} data String to be encoded | |
* @param {String} mimeWordEncoding='Q' Encoding for the mime word, either Q or B | |
* @param {Number} [maxLength=0] If set, split mime words into several chunks if needed | |
* @return {String} Single or several mime words joined together | |
*/ | |
encodeWord(data: string | Buffer, mimeWordEncoding: string, maxLength?: number): string; | |
/** | |
* Decode a complete mime word encoded string | |
* | |
* @param {String} str Mime word encoded string | |
* @return {String} Decoded unicode string | |
*/ | |
decodeWord(charset: any, encoding: any, str: string): string; | |
/** | |
* Finds word sequences with non ascii text and converts these to mime words | |
* | |
* @param {String|Buffer} data String to be encoded | |
* @param {String} mimeWordEncoding='Q' Encoding for the mime word, either Q or B | |
* @param {Number} [maxLength=0] If set, split mime words into several chunks if needed | |
* @param {String} [fromCharset='UTF-8'] Source sharacter set | |
* @return {String} String with possible mime words | |
*/ | |
encodeWords(data: string | Buffer, mimeWordEncoding: string, maxLength?: number, fromCharset?: string): string; | |
/** | |
* Decode a string that might include one or several mime words | |
* | |
* @param {String} str String including some mime words that will be encoded | |
* @return {String} Decoded unicode string | |
*/ | |
decodeWords(str: string): string; | |
getHex(c: any): string | false; | |
/** | |
* Splits a string by : | |
* The result is not mime word decoded, you need to do your own decoding based | |
* on the rules for the specific header key | |
* | |
* @param {String} headerLine Single header line, might include linebreaks as well if folded | |
* @return {Object} And object of {key, value} | |
*/ | |
decodeHeader(headerLine: string): any; | |
/** | |
* Parses a block of header lines. Does not decode mime words as every | |
* header might have its own rules (eg. formatted email addresses and such) | |
* | |
* @param {String} headers Headers string | |
* @return {Object} An object of headers, where header keys are object keys. NB! Several values with the same key make up an Array | |
*/ | |
decodeHeaders(headers: string): any; | |
/** | |
* Joins parsed header value together as 'value; param1=value1; param2=value2' | |
* PS: We are following RFC 822 for the list of special characters that we need to keep in quotes. | |
* Refer: https://www.w3.org/Protocols/rfc1341/4_Content-Type.html | |
* @param {Object} structured Parsed header value | |
* @return {String} joined header value | |
*/ | |
buildHeaderValue(structured: any): string; | |
/** | |
* Parses a header value with key=value arguments into a structured | |
* object. | |
* | |
* parseHeaderValue('content-type: text/plain; CHARSET='UTF-8'') -> | |
* { | |
* 'value': 'text/plain', | |
* 'params': { | |
* 'charset': 'UTF-8' | |
* } | |
* } | |
* | |
* @param {String} str Header value | |
* @return {Object} Header value as a parsed structure | |
*/ | |
parseHeaderValue(str: string): any; | |
/** | |
* Encodes a string or an Buffer to an UTF-8 Parameter Value Continuation encoding (rfc2231) | |
* Useful for splitting long parameter values. | |
* | |
* For example | |
* title="unicode string" | |
* becomes | |
* title*0*=utf-8''unicode | |
* title*1*=%20string | |
* | |
* @param {String|Buffer} data String to be encoded | |
* @param {Number} [maxLength=50] Max length for generated chunks | |
* @param {String} [fromCharset='UTF-8'] Source sharacter set | |
* @return {Array} A list of encoded keys and headers | |
*/ | |
buildHeaderParam(key: any, data: string | Buffer, maxLength?: number, fromCharset?: string): any[]; | |
/** | |
* Returns file extension for a content type string. If no suitable extensions | |
* are found, 'bin' is used as the default extension | |
* | |
* @param {String} mimeType Content type to be checked for | |
* @return {String} File extension | |
*/ | |
detectExtension(mimeType: string): string; | |
/** | |
* Returns content type for a file extension. If no suitable content types | |
* are found, 'application/octet-stream' is used as the default content type | |
* | |
* @param {String} extension Extension to be checked for | |
* @return {String} File extension | |
*/ | |
detectMimeType(extension: string): string; | |
/** | |
* Folds long lines, useful for folding header lines (afterSpace=false) and | |
* flowed text (afterSpace=true) | |
* | |
* @param {String} str String to be folded | |
* @param {Number} [lineLength=76] Maximum length of a line | |
* @param {Boolean} afterSpace If true, leave a space in th end of a line | |
* @return {String} String with folded lines | |
*/ | |
foldLines(str: string, lineLength?: number, afterSpace: boolean): string; | |
/** | |
* Splits a mime encoded string. Needed for dividing mime words into smaller chunks | |
* | |
* @param {String} str Mime encoded string to be split up | |
* @param {Number} maxlen Maximum length of characters for one part (minimum 12) | |
* @return {Array} Split string | |
*/ | |
splitMimeEncodedString(str: string, maxlen: number): any[]; | |
encodeURICharComponent(chr: any): string; | |
safeEncodeURIComponent(str: any): any; | |
} | |
export declare const config: any; | |
/** | |
* Checks if a value is plaintext string (uses only printable 7bit chars) | |
* | |
* @param {String} value String to be tested | |
* @returns {Boolean} true if it is a plaintext string | |
*/ | |
export declare function isPlainText(value: string): boolean; | |
/** | |
* Checks if a multi line string containes lines longer than the selected value. | |
* | |
* Useful when detecting if a mail message needs any processing at all – | |
* if only plaintext characters are used and lines are short, then there is | |
* no need to encode the values in any way. If the value is plaintext but has | |
* longer lines then allowed, then use format=flowed | |
* | |
* @param {Number} lineLength Max line length to check for | |
* @returns {Boolean} Returns true if there is at least one line longer than lineLength chars | |
*/ | |
export declare function hasLongerLines(str: any, lineLength: number): boolean; | |
/** | |
* Decodes a string from a format=flowed soft wrapping. | |
* | |
* @param {String} str Plaintext string with format=flowed to decode | |
* @param {Boolean} [delSp] If true, delete leading spaces (delsp=yes) | |
* @return {String} Mime decoded string | |
*/ | |
export declare function decodeFlowed(str: string, delSp?: boolean): string; | |
/** | |
* Adds soft line breaks to content marked with format=flowed to | |
* ensure that no line in the message is never longer than lineLength | |
* | |
* @param {String} str Plaintext string that requires wrapping | |
* @param {Number} [lineLength=76] Maximum length of a line | |
* @return {String} String with forced line breaks | |
*/ | |
export declare function encodeFlowed(str: string, lineLength?: number): string; | |
/** | |
* Encodes a string or an Buffer to an UTF-8 MIME Word (rfc2047) | |
* | |
* @param {String|Buffer} data String to be encoded | |
* @param {String} mimeWordEncoding='Q' Encoding for the mime word, either Q or B | |
* @param {Number} [maxLength=0] If set, split mime words into several chunks if needed | |
* @return {String} Single or several mime words joined together | |
*/ | |
export declare function encodeWord(data: string | Buffer, mimeWordEncoding: string, maxLength?: number): string; | |
/** | |
* Decode a complete mime word encoded string | |
* | |
* @param {String} str Mime word encoded string | |
* @return {String} Decoded unicode string | |
*/ | |
export declare function decodeWord(charset: any, encoding: any, str: string): string; | |
/** | |
* Finds word sequences with non ascii text and converts these to mime words | |
* | |
* @param {String|Buffer} data String to be encoded | |
* @param {String} mimeWordEncoding='Q' Encoding for the mime word, either Q or B | |
* @param {Number} [maxLength=0] If set, split mime words into several chunks if needed | |
* @param {String} [fromCharset='UTF-8'] Source sharacter set | |
* @return {String} String with possible mime words | |
*/ | |
export declare function encodeWords(data: string | Buffer, mimeWordEncoding: string, maxLength?: number, fromCharset?: string): string; | |
/** | |
* Decode a string that might include one or several mime words | |
* | |
* @param {String} str String including some mime words that will be encoded | |
* @return {String} Decoded unicode string | |
*/ | |
export declare function decodeWords(str: string): string; | |
export declare function getHex(c: any): string | false; | |
/** | |
* Splits a string by : | |
* The result is not mime word decoded, you need to do your own decoding based | |
* on the rules for the specific header key | |
* | |
* @param {String} headerLine Single header line, might include linebreaks as well if folded | |
* @return {Object} And object of {key, value} | |
*/ | |
export declare function decodeHeader(headerLine: string): any; | |
/** | |
* Parses a block of header lines. Does not decode mime words as every | |
* header might have its own rules (eg. formatted email addresses and such) | |
* | |
* @param {String} headers Headers string | |
* @return {Object} An object of headers, where header keys are object keys. NB! Several values with the same key make up an Array | |
*/ | |
export declare function decodeHeaders(headers: string): any; | |
/** | |
* Joins parsed header value together as 'value; param1=value1; param2=value2' | |
* PS: We are following RFC 822 for the list of special characters that we need to keep in quotes. | |
* Refer: https://www.w3.org/Protocols/rfc1341/4_Content-Type.html | |
* @param {Object} structured Parsed header value | |
* @return {String} joined header value | |
*/ | |
export declare function buildHeaderValue(structured: any): string; | |
/** | |
* Parses a header value with key=value arguments into a structured | |
* object. | |
* | |
* parseHeaderValue('content-type: text/plain; CHARSET='UTF-8'') -> | |
* { | |
* 'value': 'text/plain', | |
* 'params': { | |
* 'charset': 'UTF-8' | |
* } | |
* } | |
* | |
* @param {String} str Header value | |
* @return {Object} Header value as a parsed structure | |
*/ | |
export declare function parseHeaderValue(str: string): any; | |
/** | |
* Encodes a string or an Buffer to an UTF-8 Parameter Value Continuation encoding (rfc2231) | |
* Useful for splitting long parameter values. | |
* | |
* For example | |
* title="unicode string" | |
* becomes | |
* title*0*=utf-8''unicode | |
* title*1*=%20string | |
* | |
* @param {String|Buffer} data String to be encoded | |
* @param {Number} [maxLength=50] Max length for generated chunks | |
* @param {String} [fromCharset='UTF-8'] Source sharacter set | |
* @return {Array} A list of encoded keys and headers | |
*/ | |
export declare function buildHeaderParam(key: any, data: string | Buffer, maxLength?: number, fromCharset?: string): any[]; | |
/** | |
* Returns file extension for a content type string. If no suitable extensions | |
* are found, 'bin' is used as the default extension | |
* | |
* @param {String} mimeType Content type to be checked for | |
* @return {String} File extension | |
*/ | |
export declare function detectExtension(mimeType: string): string; | |
/** | |
* Returns content type for a file extension. If no suitable content types | |
* are found, 'application/octet-stream' is used as the default content type | |
* | |
* @param {String} extension Extension to be checked for | |
* @return {String} File extension | |
*/ | |
export declare function detectMimeType(extension: string): string; | |
/** | |
* Folds long lines, useful for folding header lines (afterSpace=false) and | |
* flowed text (afterSpace=true) | |
* | |
* @param {String} str String to be folded | |
* @param {Number} [lineLength=76] Maximum length of a line | |
* @param {Boolean} afterSpace If true, leave a space in th end of a line | |
* @return {String} String with folded lines | |
*/ | |
export declare function foldLines(str: string, lineLength?: number, afterSpace: boolean): string; | |
/** | |
* Splits a mime encoded string. Needed for dividing mime words into smaller chunks | |
* | |
* @param {String} str Mime encoded string to be split up | |
* @param {Number} maxlen Maximum length of characters for one part (minimum 12) | |
* @return {Array} Split string | |
*/ | |
export declare function splitMimeEncodedString(str: string, maxlen: number): any[]; | |
export declare function encodeURICharComponent(chr: any): string; | |
export declare function safeEncodeURIComponent(str: any): any; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment