func getBucket() *s3.Bucket {
	auth := aws.Auth{AccessKey: viper.GetString("key"), SecretKey: viper.GetString("secret")}
	client := s3.New(auth, aws.Region{Name: "gs", S3Endpoint: viper.GetString("endpoint")})
	bucket := client.Bucket(viper.GetString("bucket"))

	return bucket
}
func Archive(data []byte) string {
	if viper.GetBool("compress") {
		data = compress(data)
	}
	filename := viper.GetString("object_prefix") + time.Now().Format(viper.GetString("filename_time_format")) + "_" + utils.RandomString(3)

	transfer(data, filename)

	return filename
}
func transfer(input []byte, filename string) {
	bucket := getBucket()
	param := map[string][]string{
		"Content-Type": {"text/plain"},
		"x-goog-acl":   {"private"},
	}
	err := bucket.PutHeader(filename, input, param, s3.Private)
	if err != nil {
		log.Println("failed to store object: " + filename + " on: " + viper.GetString("bucket"))
		log.Println(err)
	} else {
		log.Println("successfully stored: " + filename + " on: " + viper.GetString("bucket"))
	}
}
func reinject(env smtpd.Envelope) {
	smtp.SendMail(
		viper.GetString("reinject_host"),
		nil,
		env.Sender,
		env.Recipients,
		env.Data,
	)
}
func startServer() {
	iface := viper.GetString("listen_on")
	listener, err := net.Listen("tcp", iface)
	if err != nil {
		log.Printf("could not bind to %s", iface)
		os.Exit(-1)
	} else {
		log.Printf("listening on %s...", iface)
	}
	server.Serve(listener)
}