Exemple #1
0
// Read cfgfile or setup defaults.
func setupConfig() {
	// 初始化读取配置文件
	c, err := config.ReadDefault(*cfgfile)
	if err != nil {
		fmt.Println("read config file error: ", *cfgfile, err)
		os.Exit(1)
	}

	// 读取[common]段配置

	AppConfig.webPort, _ = c.Int("common", "webport")
	AppConfig.debug, _ = c.Int("common", "debug")
	AppConfig.logfile, _ = c.String("common", "log")
	AppConfig.reportTo, _ = c.String("common", "reportto")

	AppConfig.redisHost, _ = c.String("redis", "host")
	AppConfig.redisAuth, _ = c.String("redis", "auth")
	AppConfig.redisKeyFix, _ = c.String("redis", "key_prefix")
	AppConfig.redisPort, _ = c.Int("redis", "prt")
	AppConfig.redisDb, _ = c.Int("redis", "db")

	// SMTP
	AppConfig.smtpHost, _ = c.String("smtp", "host")
	AppConfig.smtpUser, _ = c.String("smtp", "user")
	AppConfig.smtpPassword, _ = c.String("smtp", "password")
	AppConfig.smtpPort, _ = c.Int("smtp", "port")
	AppConfig.smtpAuth, _ = c.Bool("smtp", "auth")
	AppConfig.smtpTLS, _ = c.Bool("smtp", "tls")
	AppConfig.smtpDaemon, _ = c.Bool("smtp", "daemon")

}
Exemple #2
0
	"github.com/garyburd/redigo/redis"
	"github.com/jonsen/goconfig/config"
	"io/ioutil"
	"net/http"
	"net/url"
	"os"
	"regexp"
	"strconv"
	"strings"
	"time"
)

var (
	home = os.ExpandEnv("$HOME")

	c, _           = config.ReadDefault(home + "/.trashmailrc")
	host, _        = c.String("default", "host")
	destination, _ = c.String("default", "destination")

	// \\w doesn't work "illegal backslash escape", greedy matching doesn't work "repeated closure"
	// this forced me to produce such a f****d up, and limited expression :/
	// ^ and $ seem to be b0rked aswell m(
	patternOriginalTo = regexp.MustCompile("X-Original-To: ([A-Za-z]+@[A-Za-z]+\\.[A-Za-z]+)")
	patternEmail      = regexp.MustCompile("[A-Za-z]+@" + host)
	patternSubject    = regexp.MustCompile("Subject: ")

	alter = flag.Bool("a", false, "change email headers, not required for condition checking")

	db redis.Conn
)