<commit_before>
Go-Guerrilla SMTPd
====================

An minimalist SMTP server written in Go, made for receiving large volumes of mail.

![Go Guerrilla](https://raw.github.com/flashmob/go-guerrilla/master/GoGuerrilla.png)

### What is Go Guerrilla SMTPd?

It's a small SMTP server written in Go, for the purpose of receiving large volume of email.
Written for GuerrillaMail.com which processes tens of thousands of emails
every hour.

The purpose of this daemon is to grab the email, save it to the database
and disconnect as quickly as possible.

A typical user of this software would probably want to customize the saveMail function for
their own systems.

This server does not attempt to filter HTML, check for spam or do any sender 
verification. These steps should be performed by other programs.
The server does NOT send any email including bounces. This should
be performed by a separate program.


### History and purpose

GoGuerrilla is a port of the original 'Guerrilla' SMTP daemon written in PHP using
an event-driven I/O library (libevent)

https://github.com/flashmob/Guerrilla-SMTPd

It's not a direct port, although the purpose and functionality remains identical.

This Go version was made in order to take advantage of our new server with 8 cores. 
Not that the PHP version was taking much CPU anyway, it always stayed at about 1-5%
despite guzzling down a ton of email every day...

As always, the bottleneck today is the network and secondary storage. It's highly probable
that in the near future, secondary storage will become so fast that the I/O bottleneck
will not be an issue. Prices of Solid State Drives are dropping fast, their speeds are rapidly
increasing. So if the I/O bottleneck would disappear, it will be replaced by a new bottleneck,
the CPU. 

To prepare for the CPU bottleneck, we need to be able to scale our software to multiple cores.
Since PHP runs in a single process, it can only run on a single core. Sure, it would
have been possible to use fork(), but that can get messy and doesn't play well with
libevent. Also, it would have been possible to start an instance for each core and
use a proxy to distribute the traffic to each instance, but that would make the system too
 complicated.

The most alluring aspect of Go are the Goroutines! It makes concurrent programming
easy, clean and fun! Go programs can also take advantage of all your machine's multiple 
cores without much effort that you would otherwise need with forking or managing your
event loop callbacks, etc. Golang solves the C10K problem in a very interesting way
 http://en.wikipedia.org/wiki/C10k_problem

If you do invite GoGuerrilla in to your system, please remember to feed it with lots
of spam - spam is what it likes best!

Getting started
===========================

To build, you will need to install the following Go libs:

	$ go get github.com/ziutek/mymysql/thrsafe
	$ go get github.com/ziutek/mymysql/autorc
	$ go get github.com/ziutek/mymysql/godrv
	$ go get github.com/sloonz/go-iconv
	$ go get github.com/garyburd/redigo/redis

Rename goguerrilla.conf.sample to goguerrilla.conf

Setup the following table:
(The vanilla saveMail function also uses Redis)

	CREATE TABLE IF NOT EXISTS `new_mail` (
	  `mail_id` int(11) NOT NULL auto_increment,
	  `date` datetime NOT NULL,
	  `from` varchar(128) character set latin1 NOT NULL,<commit_msg>Added requirement: github.com/sloonz/go-qprintable<commit_after>
Go-Guerrilla SMTPd
====================

An minimalist SMTP server written in Go, made for receiving large volumes of mail.

![Go Guerrilla](https://raw.github.com/flashmob/go-guerrilla/master/GoGuerrilla.png)

### What is Go Guerrilla SMTPd?

It's a small SMTP server written in Go, for the purpose of receiving large volume of email.
Written for GuerrillaMail.com which processes tens of thousands of emails
every hour.

The purpose of this daemon is to grab the email, save it to the database
and disconnect as quickly as possible.

A typical user of this software would probably want to customize the saveMail function for
their own systems.

This server does not attempt to filter HTML, check for spam or do any sender 
verification. These steps should be performed by other programs.
The server does NOT send any email including bounces. This should
be performed by a separate program.


### History and purpose

GoGuerrilla is a port of the original 'Guerrilla' SMTP daemon written in PHP using
an event-driven I/O library (libevent)

https://github.com/flashmob/Guerrilla-SMTPd

It's not a direct port, although the purpose and functionality remains identical.

This Go version was made in order to take advantage of our new server with 8 cores. 
Not that the PHP version was taking much CPU anyway, it always stayed at about 1-5%
despite guzzling down a ton of email every day...

As always, the bottleneck today is the network and secondary storage. It's highly probable
that in the near future, secondary storage will become so fast that the I/O bottleneck
will not be an issue. Prices of Solid State Drives are dropping fast, their speeds are rapidly
increasing. So if the I/O bottleneck would disappear, it will be replaced by a new bottleneck,
the CPU. 

To prepare for the CPU bottleneck, we need to be able to scale our software to multiple cores.
Since PHP runs in a single process, it can only run on a single core. Sure, it would
have been possible to use fork(), but that can get messy and doesn't play well with
libevent. Also, it would have been possible to start an instance for each core and
use a proxy to distribute the traffic to each instance, but that would make the system too
 complicated.

The most alluring aspect of Go are the Goroutines! It makes concurrent programming
easy, clean and fun! Go programs can also take advantage of all your machine's multiple 
cores without much effort that you would otherwise need with forking or managing your
event loop callbacks, etc. Golang solves the C10K problem in a very interesting way
 http://en.wikipedia.org/wiki/C10k_problem

If you do invite GoGuerrilla in to your system, please remember to feed it with lots
of spam - spam is what it likes best!

Getting started
===========================

To build, you will need to install the following Go libs:

	$ go get github.com/ziutek/mymysql/thrsafe
	$ go get github.com/ziutek/mymysql/autorc
	$ go get github.com/ziutek/mymysql/godrv
	$ go get github.com/sloonz/go-iconv
	$ go get github.com/garyburd/redigo/redis
	$ go get github.com/sloonz/go-qprintable

Rename goguerrilla.conf.sample to goguerrilla.conf

Setup the following table:
(The vanilla saveMail function also uses Redis)

	CREATE TABLE IF NOT EXISTS `new_mail` (
	  `mail_id` int(11) NOT NULL auto_increment,
	  `date` datetime NOT NULL,
	  `from` varchar(128) character set latin1 NOT NULL,
{'fraction_non_alphanumeric': 0.060694912769388654, 'fraction_numerical': 0.0038117578067732006, 'mean_word_length': 4.304821150855365, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3762441', 'n_tokens_mistral': 1962, 'n_tokens_neox': 1841, 'n_words': 1014}