Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mailparser cannot be used with Deno #287

Open
davidpanic opened this issue Dec 30, 2020 · 6 comments
Open

Mailparser cannot be used with Deno #287

davidpanic opened this issue Dec 30, 2020 · 6 comments

Comments

@davidpanic
Copy link

Using the latest Deno (v1.6.2) throws this error when requiring mailparser. I think this is related to this issue

Check file:///home/david/code/deno/mailparser_bug/src/index.ts
error: Uncaught TypeError: buffer.hasOwnProperty is not a function
  if (!buffer.hasOwnProperty(key)) continue
              ^
    at Object.<anonymous> (file:///home/david/code/deno/mailparser_bug/node_modules/safer-buffer/safer.js:13:15)
    at Module._compile (module.ts:161:36)
    at Object.Module._extensions..js (module.ts:1084:10)
    at Module.load (module.ts:140:34)
    at Function._load (module.ts:406:14)
    at Module.require (module.ts:126:21)
    at require (module.ts:1133:16)
    at Object.<anonymous> (file:///home/david/code/deno/mailparser_bug/node_modules/mailsplit/node_modules/iconv-lite/lib/index.js:5:14)
    at Module._compile (module.ts:161:36)
    at Object.Module._extensions..js (module.ts:1084:10)

Run with: deno run --unstable --allow-read --allow-env src/index.ts

Code used:

import { createRequire } from "https://deno.land/std@0.82.0/node/module.ts";

const require = createRequire(import.meta.url);
const mailparser = require('mailparser');
@arafatamim
Copy link

arafatamim commented Apr 18, 2021

Maybe you could try this instead https://www.npmjs.com/package/postal-mime

@canac
Copy link

canac commented Jan 2, 2023

Now that Deno has better npm module support, this works for me:

import { MailParser } from 'npm:mailparser';
const parser = new MailParser();

@zuk
Copy link

zuk commented Jan 27, 2023

Is it just me or is MailParser unusably slow with Deno though? I can't quite figure out what's causing the slowdown... it seems to sit somewhere in deno:ext/web/02_timer.js? 🤷

@canac
Copy link

canac commented Jan 27, 2023

I ran into that slowness also. I ended up using a Rust mail parsing library and calling it via WASM and it parses messages in the single digit milliseconds range. Here's my code, but it only extracts a few fields from the email.

@zuk
Copy link

zuk commented Jan 27, 2023

Thanks for that tip @canac . I ended up switching to https://github.com/emailjs/emailjs-mime-parser which seems to be much faster, but took a fair bit of work to get it to produce somethign similar to mailparser's output. I may yet go the same route as you with Rust, but I think this is good enough for now.

I'm really curious if this is a Deno issue though, or if this happens under Node too. I don't have the time to try it out myself, but I couldn't find anyone else complaining about similar performance issues with mailparser under Node.

I really want to ditch Node in favour of Deno, but I'm starting to worry about running into more and more issues like this the further I get.

@andris9
Copy link
Member

andris9 commented Jan 27, 2023

I don’t know much about Deno, but can you run my other email parsing library meant for browsers in Deno? https://github.com/postalsys/postal-mime

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants