func NewMaildirproxy(srv string) *Maildirproxy { normname := Formatservername(srv) var d maildir.Dir = maildir.Dir(normname) if !exists(normname) { fmt.Printf("creating maildir (%s) \n", normname) err := d.Create() if err != nil { log.Fatal(err) } } m := &Maildirproxy{ Server: srv, Mdir: d, } return m }
func main() { var err error flags() switch strings.ToLower(cfg.Remailer.Loglevel) { case "trace": logInit(os.Stdout, os.Stdout, os.Stdout, os.Stderr) case "info": logInit(ioutil.Discard, os.Stdout, os.Stdout, os.Stderr) case "warn": logInit(ioutil.Discard, ioutil.Discard, os.Stdout, os.Stderr) case "error": logInit(ioutil.Discard, ioutil.Discard, ioutil.Discard, os.Stderr) default: fmt.Fprintf(os.Stderr, "Unknown loglevel: %s\n", cfg.Remailer.Loglevel) } if flag_client { mixprep() } else if flag_stdin { dir := maildir.Dir(cfg.Files.Maildir) newmsg, err := dir.NewDelivery() if err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } stdin, err := ioutil.ReadAll(os.Stdin) if err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } newmsg.Write(stdin) newmsg.Close() } else if flag_remailer { err = loopServer() if err != nil { panic(err) } } else if flag_dummy { injectDummy() } if flag_send { // Flush the outbound pool poolOutboundSend() } }
func (m *MailwatchMod) Init(b *Bot, conn irc.SafeConn) error { conf := b.Config.Search("mod", "mailwatch") dir := conf.Search("dir") channel := conf.Search("channel") if dir != "" { m.dir = maildir.Dir(dir) m.cronjob = cron.New() m.cronjob.AddFunc("@every 1m", func() { //log.Printf("checking mail %s...", m.dir) if newmail, err := m.dir.Unseen(); err != nil { conn.Privmsg(channel, fmt.Sprintf("maildir error: %s, err")) } else { l := len(newmail) if l > 0 { conn.Privmsg(channel, fmt.Sprintf("%d new mail:", l)) for _, k := range newmail { hdr, err := m.dir.Header(k) if err != nil { conn.Privmsg(channel, fmt.Sprintf("maildir header error: %s", err)) } else { conn.Privmsg(channel, fmt.Sprintf("from : %s", hdr.Get("From"))) conn.Privmsg(channel, fmt.Sprintf("subject: %s", hdr.Get("Subject"))) } } } } }) go func() { time.Sleep(10 * time.Second) m.cronjob.Start() }() log.Printf("mailwatch module initialized with dir: %s", dir) } return nil }
func NewCachedMailDir(mdirPath string, db *bolt.DB) (dir CachedMaildir) { mdir := maildir.Dir(mdirPath) bucketName := path.Base(mdirPath) tx, err := db.Begin(true) if err != nil { log.Fatal(err) } _, err = tx.CreateBucketIfNotExists([]byte(bucketName + "_flags")) if err != nil { log.Fatal(err) } tx.Commit() dir = CachedMaildir{dir: &mdir, flagsBucket: bucketName + "_flags"} SynchronizeInfo(dir, db) return }
// processMail reads the Remailer's Maildir and processes the content func processMail(secret *keymgr.Secring) (err error) { dir := maildir.Dir(cfg.Files.Maildir) // Get a list of Maildir keys from the directory keys, err := dir.Unseen() if err != nil { return } newMsgs := len(keys) if newMsgs == 0 { // Nothing to do, move along! return } Trace.Printf( "Reading %d messages from %s\n", newMsgs, cfg.Files.Maildir, ) // Increment inbound Email counter stats.inMail += newMsgs // Fetch headers for each Maildir key var head mail.Header for _, key := range keys { head, err = dir.Header(key) if err != nil { Warn.Printf("%s: Getting headers failed with: %s", key, err) continue } // The Subject determines if the message needs remailer-foo handling subject := strings.TrimSpace(strings.ToLower(head.Get("Subject"))) if strings.HasPrefix(subject, "remailer-") { // It's a remailer-foo request err = remailerFoo(subject, head.Get("From")) if err == nil { // Increments stats counter stats.inRemFoo++ } else { Info.Println(err) } err = dir.Purge(key) if err != nil { Warn.Printf( "Cannot delete remailer-foo mail: %s", err, ) } // Nothing else to do, move on to the next message continue } // It's not a remailer-foo request so assume a remailer message var mailMsg *mail.Message mailMsg, err := dir.Message(key) if err != nil { Warn.Printf( "%s: Reading message failed with: %s", key, err, ) continue } var msg []byte // Convert the armored Yamn message to its byte components msg, err = stripArmor(mailMsg.Body) if err != nil { Info.Println(err) continue } if msg == nil { Warn.Println("Dearmor returned zero bytes") continue } err = decodeMsg(msg, secret) if err != nil { Info.Println(err) } err = dir.Purge(key) if err != nil { Warn.Printf("Cannot delete mail: %s", err) } } // Maildir keys loop return }