whitelist.js 796 B

123456789101112131415161718192021222324252627282930313233343536
  1. import fs from 'fs';
  2. import * as readline from 'node:readline';
  3. import log from './log.js';
  4. export const isInWhiteList = async (filename, email) => {
  5. if (!email) {
  6. log.warn("isInWhiteList: empty email.");
  7. return false;
  8. }
  9. if (filename) {
  10. const fileStream = fs.createReadStream(filename);
  11. const rl = readline.createInterface({
  12. input: fileStream,
  13. crlfDelay: Infinity
  14. });
  15. // Note: we use the crlfDelay option to recognize all instances of CR LF
  16. // ('\r\n') in input as a single line break.
  17. for await (const line of rl) {
  18. if (email.trim() === line) {
  19. return true;
  20. }
  21. else {
  22. return false;
  23. }
  24. }
  25. return false;
  26. } else {
  27. log.debug('isInWhiteList: no whitelist file defined.')
  28. return true;
  29. }
  30. }