npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

eml-parser-buffer

v1.0.1

Published

eml parser, buffer

Downloads

8

Readme

node-eml-parser-buffer

说明

网址: https://gitee.com/linuxmail/node-eml-parser-buffer/

邮件解析库, 充分考虑字符集问题, 本库作者认为: 有大量的邮件含有8bit文字,而这些文字不是UTF-8编码

特别说明

下划线(_)开头的属性和函数是私有的,不应该使用

接口

// new emlParser 的参数
export interface parserOptions {
    emlData: Buffer;
    debug?: boolean;
}

// 邮件头行,字符串节点
export interface tokenNode {
    data: Buffer;
    charset: string;
}

// 邮件头行的,值和键值对
export interface mimeValueParams {
    value: Buffer;
    params: {
        [key: string]: Buffer;
    };
}

// 邮件头行
export interface mimeLine {
    name: string;
    value: Buffer;
}

// 邮件地址
export interface mimeAddress {
    name: string;
    address: string;
}

// 未解码的邮件地址
export interface mimeAddressDecoder {
    nameBuffer: Buffer;
    address: string;
}

用法

参考, examples/ 例子

const emlParser = require("eml-parser-buffer")

CLASS emlParser

emlData, 是 Buffer, 不能是 String

var options = {
    emlData: fs.readFileSync("somepath") // 应该是 Buffer
}
var parser = new emlParser.emlParser(options)

emlParser 的属性如下:

subject: null | string
from: null | mimeAddress
to: null | mimeAddress[]
cc: null | mimeAddress[]
bcc: null | mimeAddress[]
messageId: null | string
date: null | string
dateUnix: number
sender: null | mimeAddress
replyTo: null | mimeAddress
dispositionNotificationTo: null | mimeAddress
references: null | (string[])
topNode: mimeNode

emlParser 的 get 属性如下:

// 所有的Mime节点
get allNodes(): mimeNode[]
// 所有的可显的正文文本节点
get textNodes()
// 所有优先显示的正文文本节点(优先html)
get alternativeShowNodes()
//所有的附件节点
get attachmentNodes()

emlParser 的方法

// 返回第一个名字是name的邮件头行
getFirstHeaderLine(name: string)

CLASS mimeNode

邮件 Mime 结构的节点类

mimeNode 的属性如下:

parser: emlParser
headerStartPos: number
headerLength: number
headers: mimeLine[]
bodyStartPos: number
bodyLength: number
contentType: string
encoding: string
charset: string
name: string
filename: string
contentId: string
disposition: string
boundary: string
parent: null | mimeNode
childs: null | mimeNode[]

mimeNode 的 get 属性如下:

// 是否内嵌(图片)附件
get isInline()

// 是否是 TNEF 类型附件
get isTnef()

// (如果是 TEXT/* 类型)获取解码并字符集转码后的文本
get textContent(): string 

mimeNode 的方法

// 获取解码后的附件内容
getDecodedBuffer(): Buffer
// 获取名字为name的第一个 Mime 头行
getFirstHeaderLine(name: string): null | mimeLine

其他工具函数

// 解码 rfc2231 规范的文件名/属性值等
function decode2231(data: Buffer, withCharset: boolean): tokenNode[];
// 如上, 并转码为字符串
function decode2231ToString(data: Buffer, withCharset: boolean): string;
// 在一堆params里面, 转码键为name的值并转码为字符串
function decodeParamValueToString(params: { [name: string]: Buffer; }, name: string): string;
// 解析邮件头行
function decodeValue(line: Buffer): tokenNode[];
// 如上, 并转码为字符串
function decodeValueToString(line: Buffer): string;
// 解析邮件头行
function decodeLineToValueAndParams(line: Buffer): mimeValueParams;