0

I have build a module that generates a very unique Message-Id, but I've been asked to shorten it, so I wonder how short I can make it, so it is still RFC 2822 valid and will not get caught in spam filters.

I see Python generates one that is about 41 chars long, which seems a bit too short.

Any suggestions?

'use strict';

var crypto = require('crypto');

// inspired by http://www.jwz.org/doc/mid.html#3

module.exports = function (hostname) {
  var hrtime = process.hrtime();
  var microseconds = hrtime[0] * 1000000 + hrtime[1] / 1000;
  var token = crypto.randomBytes(64).toString('hex');
  var b36 = parseInt(token, 16).toString(36);
  var result = '<';
  result += microseconds;
  result += b36;
  result += '@' + hostname;
  result += '>';
  return result;
};
webjay
  • 5,358
  • 9
  • 45
  • 62

1 Answers1

0

Perhaps cuid is suitable for you?

Peter Lyons
  • 142,938
  • 30
  • 279
  • 274