Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
const contentType = text.match(contentTypeReg)[1].trim()
const charset = (text.match(secondChartsetReg) || text.match(charsetReg))[1].trim().replace(/"/g, '')
const transferEncoding = text.match(contentTransferEncodingReg)[1].trim()
const subTextArr = text.split(blankLineReg)
subTextArr.shift()
const contentText = subTextArr.filter(item => (item.trim())).join('')
if (contentType.match(htmlTypeReg)) {
if (transferEncoding === 'base64') {
const buff = Buffer.from(contentText, transferEncoding)
result.bodyHtml = iconv.decode(buff, charset || 'utf-8')
} else if (transferEncoding === 'quoted-printable') {
// 用try包裹是因为发现有邮件写着quoted-printable编码,正文却没有编码。quotedPrintable模块decode没有编码的内容就报错,进入catch
try {
// 编码为quoted-printable且charset为utf8。暂时遇到为utf8的,未看到其他字符集
const quotedHtml = utf8.decode(quotedPrintable.decode(contentText))
result.bodyHtml = quotedHtml
} catch (e) {
result.bodyHtml = contentText
}
} else {
result.bodyHtml = contentText
}
} else if (contentType.match(plainTypeReg)) {
if (transferEncoding === 'base64') {
const buff = Buffer.from(contentText, transferEncoding)
result.bodyText += iconv.decode(buff, charset || 'utf-8')
} else {
try {
// 编码为quoted-printable且charset为utf8。其他字符集用quotedPrintable会报错,进入catch
const quotedText = utf8.decode(quotedPrintable.decode(contentText))
result.bodyText += quotedText
hex = hex.replace(/^(?:00)*/, '');
hex = hex
.split('')
.reverse()
.join('');
const l = hex.length;
for (let i = 0; i < l; i += 2) {
code = parseInt(hex.substr(i, 2), 16);
// if (code !== 0) {
string += String.fromCharCode(code);
// }
}
return utf8.decode(string);
};
exports.decodePacket = function (data, binaryType, utf8decode) {
// String data
if (typeof data == 'string' || data === undefined) {
if (data.charAt(0) == 'b') {
return exports.decodeBase64Packet(data.substr(1), binaryType);
}
var type = data.charAt(0);
if (utf8decode) {
try {
data = utf8.decode(data);
} catch (e) {
return err;
}
}
if (Number(type) != type || !packetslist[type]) {
return err;
}
if (data.length > 1) {
return { type: packetslist[type], data: data.substring(1) };
} else {
return { type: packetslist[type] };
}
}
exports.decodePacket = function (data, binaryType, utf8decode) {
// String data
if (typeof data == 'string' || data === undefined) {
if (data.charAt(0) == 'b') {
return exports.decodeBase64Packet(data.substr(1), binaryType);
}
if (utf8decode) {
try {
data = utf8.decode(data);
} catch (e) {
return err;
}
}
var type = data.charAt(0);
if (Number(type) != type || !packetslist[type]) {
return err;
}
if (data.length > 1) {
return { type: packetslist[type], data: data.substring(1) };
} else {
return { type: packetslist[type] };
}
}
public readString(): string {
// Read string length
const firstByte: number = this.readByte();
let strLength: number = firstByte;
if (firstByte >= 128) {
const secondByte: number = this.readByte();
strLength = (firstByte - 128) + secondByte << 7;
}
// Read string content using length
const rawText = bufferToText(this._data.slice(this.head, this.head + strLength));
const strContent: string = utf8.decode(rawText);
this.head += strLength;
return strContent;
}
const quotedHtml = utf8.decode(quotedPrintable.decode(contentText))
result.bodyHtml = quotedHtml
} catch (e) {
result.bodyHtml = contentText
}
} else {
result.bodyHtml = contentText
}
} else if (contentType.match(plainTypeReg)) {
if (transferEncoding === 'base64') {
const buff = Buffer.from(contentText, transferEncoding)
result.bodyText += iconv.decode(buff, charset || 'utf-8')
} else {
try {
// 编码为quoted-printable且charset为utf8。其他字符集用quotedPrintable会报错,进入catch
const quotedText = utf8.decode(quotedPrintable.decode(contentText))
result.bodyText += quotedText
} catch (e) {
// 不是quoted-printable,那html本身应该是utf-8编码而不是gb18030
result.bodyText += iconv.decode(iconv.encode(contentText, 'gb18030'), 'utf-8')
}
}
}
})
} else if (contentType.match(mixedMultipart) || (contentType.match(relatedMultipart) && textArr.length > 2)) {
exports.decodePacket = function (data, binaryType, utf8decode) {
// String data
if (typeof data == 'string' || data === undefined) {
if (data.charAt(0) == 'b') {
return exports.decodeBase64Packet(data.substr(1), binaryType);
}
var type = data.charAt(0);
if (utf8decode) {
try {
data = utf8.decode(data);
} catch (e) {
return err;
}
}
if (Number(type) != type || !packetslist[type]) {
return err;
}
if (data.length > 1) {
return { type: packetslist[type], data: data.substring(1) };
} else {
return { type: packetslist[type] };
}
}
if( only_expired && ( d.expires >= current_block ) ) continue;
if( only_for_sale && d.price == 0 ) continue;
var ok = true;
if( all_domains_pattern != "" ) {
ok = false;
hex = web3.toHex( d.domain );
if( hex.match( all_domains_pattern ) ) { ok = true }
else
{
ascii = ""
try {
ascii = utf8.decode( toAscii( hex ) )
}
catch( x ) {}
if( ascii.match( all_domains_pattern ) ) { ok = true }
}
}
if( ok )
{
if( all_domains_to_csv )
{
all_domains_csv += "\"" + d.name().replace( "\'", "\'\'").replace( "\"", "\"\"") + "\",";
all_domains_csv += d.name_hex() + ",";
all_domains_csv += d.owner + ",";
all_domains_csv += web3.fromWei( d.price, "ether" ) + ",";
all_domains_csv += d.expires + ",";
all_domains_csv += d.days() + ",";
export function formatPage(row){
let title = tagByPrefixStripped(row.plaintags, 'title:', 'filename:');
let titleCleaned = title.replace(/\.md$/, '');
return {
key: tagByPrefix(row.plaintags, 'id:'),
title: titleCleaned,
contents: utf8.decode(atob(row.unencrypted || '')),
tags: row.plaintags
}
}