diff --git a/.gitignore b/.gitignore index 43864f223..a425cf845 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -/node_modules/ +node_modules/ /.idea/ /coverage/ /reports/ diff --git a/src/include/email-bot/.gitignore b/src/include/email-bot/.gitignore new file mode 100644 index 000000000..2f9e77b22 --- /dev/null +++ b/src/include/email-bot/.gitignore @@ -0,0 +1,8 @@ +config/dkim +config/auth_flat_file.ini +config/host_list +config/internalcmd_key +config/me +config/smtp_forward.ini + +environment.json diff --git a/src/include/email-bot/config/log.ini b/src/include/email-bot/config/log.ini new file mode 100644 index 000000000..0187f6ab2 --- /dev/null +++ b/src/include/email-bot/config/log.ini @@ -0,0 +1,11 @@ +[main] + +; level=data, protocol, debug, info, notice, warn, error, crit, alert, emerg +level=info + +; prepend timestamps to log entries? This setting does NOT affect logs emitted +; by logging plugins (like syslog). +timestamps=false + +; format=default, logfmt +format=default diff --git a/src/include/email-bot/config/plugins b/src/include/email-bot/config/plugins new file mode 100644 index 000000000..0a31015b7 --- /dev/null +++ b/src/include/email-bot/config/plugins @@ -0,0 +1,70 @@ +# This file lists plugins that Haraka will run +# +# Plugin ordering often matters, run 'haraka -o -c /path/to/haraka/config' +# to see the order plugins (and their hooks) will run in. +# +# To see a list of all plugins, run 'haraka -l' +# +# To see the help docs for a particular plugin, run 'haraka -h plugin.name' + +status +#process_title +# Log to syslog (see 'haraka -h syslog') +# syslog + +# CONNECT +#toobusy +#karma +#relay +# control which IPs, rDNS hostnames, HELO hostnames, MAIL FROM addresses, and +# RCPT TO address you accept mail from. See 'haraka -h access'. +access +# p0f +# geoip +# asn +# fcrdns +# block mails from known bad hosts (see config/dnsbl.zones for the DNS zones queried) +dnsbl + +# HELO +#early_talker +# see config/helo.checks.ini for configuration +helo.checks + +# see 'haraka -h tls' for config instructions before enabling! +tls +auth/flat_file + +# MAIL FROM +# Only accept mail where the MAIL FROM domain is resolvable to an MX record +#mail_from.is_resolvable +spf + +# RCPT TO +# At least one rcpt_to plugin is REQUIRED for inbound email. The simplest +# plugin is in_host_list, see 'haraka -h rcpt_to.in_host_list' to configure. +#rcpt_to.in_host_list +#qmail-deliverable +#rcpt_to.routes + +# DATA +#bounce +data.headers +#data.uribl +#attachment +#clamd +#spamassassin +#dkim_sign +limit + +# Custom +xxx + +# QUEUE +# Queue mail via smtp - see config/smtp_forward.ini for where your mail goes +# ... + +# Disconnect client if they spew bad SMTP commands at us +max_unrecognized_commands + +#watch diff --git a/src/include/email-bot/config/smtp.ini b/src/include/email-bot/config/smtp.ini new file mode 100644 index 000000000..6216729ca --- /dev/null +++ b/src/include/email-bot/config/smtp.ini @@ -0,0 +1,48 @@ +; port to listen on +;port=2525 + +; address to listen on (default: all IPv6 and IPv4 addresses, port 25) +; use "[::0]:25" to listen on IPv6 and IPv4 (not all OSes) +listen=[::0]:2525 + +; Note you can listen on multiple IPs/ports using commas: +;listen=127.0.0.1:2529,127.0.0.2:2529,127.0.0.3:2530 + +; public IP address (default: none) +; If your machine is behind a NAT, some plugins (SPF, GeoIP) gain features +; if they know the servers public IP. If 'stun' is installed, Haraka will +; try to figure it out. If that doesn't work, set it here. +;public_ip=N.N.N.N + +; Time in seconds to let sockets be idle with no activity +;inactivity_timeout=300 + +; Drop privileges to this user/group +;user=smtp +;group=smtp + +; Don't stop Haraka if plugins fail to compile +;ignore_bad_plugins=0 + +; Run using cluster to fork multiple backend processes +;nodes=cpus + +; Daemonize +;daemonize=true +;daemon_log_file=/var/log/haraka.log +;daemon_pid_file=/var/run/haraka.pid + +; Spooling +; Save memory by spooling large messages to disk +;spool_dir=/var/spool/haraka +; Specify -1 to never spool to disk +; Specify 0 to always spool to disk +; Otherwise specify a size in bytes, once reached the +; message will be spooled to disk to save memory. +;spool_after= + +; Force Shutdown Timeout +; - Haraka tries to close down gracefully, but if everything is shut down +; after this time it will hard close. 30s is usually long enough to +; wait for outbound connections to finish. +;force_shutdown_timeout=30 diff --git a/src/include/email-bot/docs/plugins/xxx.md b/src/include/email-bot/docs/plugins/xxx.md new file mode 100644 index 000000000..9706e8e39 --- /dev/null +++ b/src/include/email-bot/docs/plugins/xxx.md @@ -0,0 +1,9 @@ +xxx +======== + +Describe what your plugin does here. + +Configuration +------------- + +* `config/some_file` - describe what effect this config file has diff --git a/src/include/email-bot/helpers/mail.js b/src/include/email-bot/helpers/mail.js new file mode 100644 index 000000000..53375ad9f --- /dev/null +++ b/src/include/email-bot/helpers/mail.js @@ -0,0 +1,18 @@ +const { simpleParser } = require('mailparser'); + +module.exports.readMailStream = function (stream) { + return new Promise((resolve, reject) => { + const chunks = []; + stream.on('data', (chunk) => { + chunks.push(chunk); + }); + stream.on('end', () => { + simpleParser(Buffer.concat(chunks).toString('utf8'), (error, mail) => { + if (error) { + return reject(error); + } + resolve(mail); + }); + }); + }); +}; diff --git a/src/include/email-bot/plugins/xxx.js b/src/include/email-bot/plugins/xxx.js new file mode 100644 index 000000000..9b651b5a9 --- /dev/null +++ b/src/include/email-bot/plugins/xxx.js @@ -0,0 +1,35 @@ +// const transporter = require('../services/smtp-transport'); +const { readMailStream } = require('../helpers/mail'); + +exports.register = function () { + this.loginfo('Initializing !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! plugin'); + + // this.register_hook('queue', 'queue'); + this.register_hook('mail', 'mail'); +}; + +exports.hook_data = function (next /*, connection */) { + next(); +}; + +exports.mail = function (next, connection /*, params */) { + connection.transaction.uuid; + connection.transaction.mail_from; + connection.transaction.rcpt_to; + connection.transaction.message_stream; + // connection.transaction.notes; + connection.relaying = true; + connection.transaction.parse_body = true; + + readMailStream(connection.transaction.message_stream).then((mail) => { + this.loginfo('!!!!! TEXT: ' + mail.text); + this.loginfo('!!!!! HTML: ' + mail.html); + this.loginfo('!!!!! Date: ' + mail.date); + this.loginfo('!!!!! Subject: ' + mail.subject); + + // todo эти данные надо обработать core/text + // и прислать в ответ обратное письмо что письмо получено и обработано + }); + + next(); +};