Compare commits
No commits in common. "41b78f0b5872a18257efede76e0c78fe76ef4af6" and "96117a64b368d582957ca7158e9c425f8a439f4a" have entirely different histories.
41b78f0b58
...
96117a64b3
|
@ -1,5 +1 @@
|
|||
# Ignore .vagrant folder
|
||||
.vagrant
|
||||
|
||||
# Ignore build result
|
||||
milter-experiment
|
||||
|
|
|
@ -1,40 +0,0 @@
|
|||
# -*- mode: ruby -*-
|
||||
# vi: set ft=ruby :
|
||||
|
||||
Vagrant.configure("2") do |config|
|
||||
config.vm.box = "debian/buster64"
|
||||
|
||||
config.vm.synced_folder "./", "/vagrant", type: "rsync"
|
||||
|
||||
# Export postfix port 25 (guest) to port 2525 (host)
|
||||
# This is useful for throwing swaks and other tools against postfix
|
||||
config.vm.network "forwarded_port", guest: 25, host: 2525
|
||||
|
||||
config.vm.provision "shell", inline: <<-SHELL
|
||||
# Give that vagrant box an apparently good FQDN
|
||||
echo "local-vagrant.example.com" > /etc/hostname
|
||||
echo "local-vagrant.example.com" > /etc/mailname
|
||||
echo "127.0.1.2 local-vagrant.example.com local-vagrant" > /etc/hosts
|
||||
hostnamectl set-hostname local-vagrant.example.com
|
||||
|
||||
# Basic preparations
|
||||
apt-get update
|
||||
|
||||
# Install postfix
|
||||
DEBIAN_FRONTEND=noninteractive apt-get install -y postfix
|
||||
|
||||
# Add milter to configuration
|
||||
postconf smtpd_milters=inet:127.0.0.1:7777
|
||||
postconf non_smtpd_milters=inet:127.0.0.1:7777
|
||||
|
||||
# Enable and launch postfix
|
||||
systemctl enable postfix.service
|
||||
systemctl start postfix.service
|
||||
|
||||
# Install swaks
|
||||
DEBIAN_FRONTEND=noninteractive apt-get install -y swaks
|
||||
|
||||
# That's it
|
||||
echo "That's it. We're set up. Enjoy your test environment."
|
||||
SHELL
|
||||
end
|
18
main.go
18
main.go
|
@ -5,10 +5,13 @@ import (
|
|||
"bytes"
|
||||
"encoding/binary"
|
||||
"encoding/hex"
|
||||
"milter-experiment/logging"
|
||||
"os"
|
||||
)
|
||||
|
||||
import (
|
||||
"milter-experiment/logging"
|
||||
)
|
||||
|
||||
var (
|
||||
// Global logger for application wide logging. Not sure if this is a good pattern yet.
|
||||
logger logging.Logger
|
||||
|
@ -34,24 +37,13 @@ func handleMtaConnection(clientConnection *bufio.ReadWriter) {
|
|||
logger.Errorln(err.Error())
|
||||
}
|
||||
logger.Debugf("Parsed length: %d\n", packetLength)
|
||||
|
||||
// Next up is a character, indicating the milter command
|
||||
logger.Debugf("Parsing command from byte: %X\n", buf[4])
|
||||
command := string(buf[4])
|
||||
logger.Debugf("Parsed packet command: %s\n", command)
|
||||
|
||||
// Last part is data with lenght len-1
|
||||
data := make([]byte, packetLength)
|
||||
data = buf[5 : 5+packetLength-1]
|
||||
logger.Debugf("Hexdump of packet payload read:\n%s", hex.Dump(data))
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
logger = logging.NewLogger(os.Stdout, os.Stderr, logging.DEBUG)
|
||||
err := runServer("127.0.0.1:7777")
|
||||
err := runServer()
|
||||
if err != nil {
|
||||
logger.Errorf("Could not run server: %s\n", err.Error())
|
||||
os.Exit(1)
|
||||
|
|
|
@ -6,8 +6,8 @@ import (
|
|||
"net"
|
||||
)
|
||||
|
||||
func runServer(listenAddr string) error {
|
||||
serverSocket, err := net.Listen("tcp", listenAddr)
|
||||
func runServer() error {
|
||||
serverSocket, err := net.Listen("tcp", "127.0.0.1:7777")
|
||||
if err != nil {
|
||||
myError := fmt.Errorf("could not create listening socket: %s", err.Error())
|
||||
return myError
|
||||
|
|
Loading…
Reference in New Issue