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

milter

v2.0.0

Published

bindings for writing postfix milter daemons

Downloads

39

Readme

node-milter

node.js bindings for postfix milters

this addon produces libmilter callbacks in node.js v7.7.4 so that you don't have to be a C programmer to use postfix with libmilter.

when its main function is called, libmilter creates a threaded daemon where each mail session has one unique thread in your program servicing it. this main is therefore sequestered away in a libuv worker to allow node.js to continue to function normally.

your libmilter event callbacks are called from these threads with a context pointer to distinguish them from each other. you must return a code at the end of the event implementation, which tells postfix what to do next, continue, reject, tempfail, etc.

this milter blocks itself during each of those events. it wraps the event into a localized context object and queues that, signals to libuv that it's time to do some node.js work, and goes to sleep until the pthread condition is met. thus multiple libmilter sessions may block on a single stage of the event, but, they are in their own threads so it's mostly ok.

when libuv runs the async worker to service the queue on the other side, we are now back in node.js-land (a scope) and can make js callbacks, wrap event data in js objects, and so on. but it is required that the js callbacks return a decision for postfix immediately, so your js callbacks cannot be async (yet).

QUICKSTART

creating a milter daemon.

milter.start(
  string smtpd_milter_description,
  number flags,
  function(env, f0, f1, f2, f3) negotiate,
  function(env,host,addr) connect,
  function(env,command) unknown,
  function(env,identity) helo,
  function(env,address) mailfrom,
  function(env,address) rcptto,
  function(env) data,
  function(env,name,value) header,
  function(env) eoh,
  function(env,buffer,length) segment,
  function(env) eom,
  function(env) abort,
  function(env) close,
);

other controls are available when creating a milter.

completing a callback.

connect = function (env, host, addr) {
  /* ... */
  env.done(decision);
}

the allowed filter decisions for all callbacks except negotiate.

milter.SMFIS_CONTINUE
milter.SMFIS_REJECT
milter.SMFIS_DISCARD
milter.SMFIS_ACCEPT
milter.SMFIS_TEMPFAIL
milter.SMFIS_NOREPLY
milter.SMFIS_SKIP

negotiate shall return one of these decisions instead. see env.negotiate() for use of the CONTINUE return code.

milter.SMFIS_ALL_OPTS
milter.SMFIS_CONTINUE
milter.SMFIS_REJECT

add a smtpd_milters line to your main.cf that matches your description in milter.start and go to town. the test cases included in the project should show you how.

MILTER STUFF

other envelope methods. access to message modifiers is allowed during the EOM event with these methods.

env.addheader(name, value)
env.chgheader(name, refcount, value)
env.insheader(index, name, value)
env.replacebody(newbody)
env.addrcpt(recipient)
env.addrcpt_par(recipient, args)
env.delrcpt(recipient)
env.chgfrom(envfrom, args)
env.quarantine(reason)
env.progress()

changing the symbol list is allowed during negotiate.

env.setsymlist(stage, macrolist)

because pointers cannot be wrapped in node.js addons, an additional method in the addon implementation that has no analog in libmilter exists to facilitate changing these settings so that the pointers made available to the xxfi_negotiate callback can be changed after node.js returns control to libmilter. call this method BEFORE calling env.done(), also, the values changed by this function are ignored unless env.done() is called with SMFIS_CONTINUE.

env.negotiate(f0, f1, f2, f3)

retrieving a macro is allowed during any event. will return an empty string if the macro doesn't have a value.

env.getsymval(symname)

changing the server's smtp reply is allowed during any event other than connect. i believe this should also exclude negotiate, so i enforce that as well.

env.setreply(rcode, xcode, message)
env.setmlreply(rcode, xcode, lines)

ANOMALIES

libmilter uses globals and is not thread-safe. you cannot use multiprocessing features in node with this addon.

the milter will register in postfix with the name "node-bindings", you already know it's a milter. the name "node-milter" is intended to give the project a sensible npm identity and some github presence, too.

sources implicitly depend on pthreads yet don't use their #include files by name.

  • libmilter explicitly uses pthreads, and libuv is implicitly using them. the code compiles because of this happy coincidence.
  • you can't use this on any non-POSIX platforms yet. but then again, you can't use milters there, either.
  • this cannot be worked around by switching the relevant code over to libuv without also rewriting all of libmilter. i looked. it's not worth it.

node.js buffers are created during the message data event (the client has already send command "DATA", and now a chunk of the message data has arrived) using the i-suspect-is-soon-to-be-deprecated method Buffer::Use(), which should have been named Buffer::New() like the others, by passing (const unsigned char *) as the expected (char *) which is probably stupid. it is unclear to me why there is no Buffer::New() that simply accepts (void *) like all the real POSIX C buffer- manipulating functions. whatever.

some calls probably don't work unless wrapped in setImmediate(), but i don't know why yet.